Done things, couldn't test yet.
This commit is contained in:
parent
746f97f061
commit
6ef5df8d7c
2
Makefile
2
Makefile
|
@ -185,7 +185,7 @@ define make-installbinary-rule
|
|||
|
||||
uninstall-$1 uninstall-$1.exe: $(CHECKCFG) uninstall-doc-$1
|
||||
$(call rmsg,Uninstalling $1)
|
||||
$(call qcmd,$(RM) "$(IBINDIR)/$1"{,.exe})
|
||||
$(call qcmd,$(RM) "$(IBINDIR)/$1" "$(IBINDIR)/$1.exe")
|
||||
endef
|
||||
$(foreach bin,$(BINARIES),\
|
||||
$(eval $(call make-installbinary-rule,$(bin))))
|
||||
|
|
|
@ -65,6 +65,11 @@ static const char help_main[] =
|
|||
" --no-exit Does not terminate connection when action is completed.\n"
|
||||
" --no-init Does not initialize connection (should only be used\n"
|
||||
" when --no-exit was used last time p7 was called).\n"
|
||||
" --use <settings> Use the following serial settings (when used with `--com`).\n"
|
||||
" For example, \"9600N2\" represents 9600 bauds, no parity,\n"
|
||||
" and two stop bits. (E for even parity, O for odd parity)\n"
|
||||
" --set <settings> Set the following serial settings (when used with `--com`).\n"
|
||||
" The string has the same format than for `--use`.\n"
|
||||
"\n"
|
||||
"Type \"" QUOTE(BIN) " <subcommand> --help\" for some help about the subcommand.\n"
|
||||
"Report bugs to " QUOTE(MAINTAINER) ".";
|
||||
|
@ -171,6 +176,52 @@ FOOT;
|
|||
return (0); \
|
||||
}
|
||||
|
||||
/**
|
||||
* make_settings:
|
||||
* Make settings from a string.
|
||||
*
|
||||
* @arg fmt the format string.
|
||||
* @arg settings the settings to set.
|
||||
* @return if there was an error (0 if ok).
|
||||
*/
|
||||
|
||||
static int make_settings(const char *argname,
|
||||
const char *fmt, p7_streamsettings_t *settings)
|
||||
{
|
||||
/* extract data from the string */
|
||||
unsigned int speed; char par; int stop;
|
||||
if (sscanf(fmt, "%u%c%d", &speed, &par, &stop) < 3
|
||||
|| (par != 'N' && par != 'E' && par != 'O')
|
||||
|| (stop != 1 && stop != 2)) {
|
||||
log("%s: invalid format, expected <speed,parity,stop bits>, e.g. "
|
||||
"9600N2 or 115200O1!\n", argname);
|
||||
return (1);
|
||||
}
|
||||
|
||||
/* get the speed */
|
||||
switch (speed) {
|
||||
case 9600: speed = P7_B9600; break;
|
||||
case 19200: speed = P7_B19200; break;
|
||||
case 38400: speed = P7_B38400; break;
|
||||
case 57600: speed = P7_B57600; break;
|
||||
case 115200: speed = P7_B115200; break;
|
||||
default:
|
||||
log("%s: %u is not a valid speed!\n", argname, speed);
|
||||
return (1);
|
||||
}
|
||||
|
||||
/* set the settings */
|
||||
p7_initcomm(settings);
|
||||
settings->speed = speed;
|
||||
settings->flags &= ~(P7_TWOSTOPBITS | P7_PARMASK);
|
||||
settings->flags |= --stop ? P7_TWOSTOPBITS : P7_ONESTOPBIT;
|
||||
settings->flags |= par == 'N' ? P7_PARDIS :
|
||||
par == 'E' ? P7_PARENB | P7_PAREVEN : P7_PARENB | P7_PARODD;
|
||||
|
||||
/* no error! */
|
||||
return (0);
|
||||
}
|
||||
|
||||
/**
|
||||
* parse_args:
|
||||
* Args parsing main function.
|
||||
|
@ -200,18 +251,22 @@ int parse_args(int ac, char **av, args_t *args)
|
|||
/* define options */
|
||||
char short_options[] = "hvfo:d:t:#";
|
||||
struct option long_options[] = {
|
||||
{"help", no_argument, NULL, 'h'},
|
||||
{"version", no_argument, NULL, 'v'},
|
||||
{"com", required_argument, NULL, 'c'},
|
||||
{"storage", required_argument, NULL, 's'},
|
||||
{"force", no_argument, NULL, 'f'},
|
||||
{"output", required_argument, NULL, 'o'},
|
||||
{"help", no_argument, NULL, 'h'},
|
||||
{"version", no_argument, NULL, 'v'},
|
||||
{"com", required_argument, NULL, 'c'},
|
||||
{"storage", required_argument, NULL, 's'},
|
||||
{"force", no_argument, NULL, 'f'},
|
||||
{"output", required_argument, NULL, 'o'},
|
||||
{"directory", required_argument, NULL, 'd'},
|
||||
{"to", required_argument, NULL, 't'},
|
||||
{"no-init", no_argument, NULL, 'i'},
|
||||
{"no-start", no_argument, NULL, 'i'},
|
||||
{"no-exit", no_argument, NULL, 'e'},
|
||||
{"no-term", no_argument, NULL, 'e'},
|
||||
{"to", required_argument, NULL, 't'},
|
||||
{"no-init", no_argument, NULL, 'i'},
|
||||
{"no-start", no_argument, NULL, 'i'},
|
||||
{"no-exit", no_argument, NULL, 'e'},
|
||||
{"no-term", no_argument, NULL, 'e'},
|
||||
{"set", required_argument, NULL, 'S'},
|
||||
{"use", required_argument, NULL, 'U'},
|
||||
|
||||
/* sentinel */
|
||||
{NULL, 0, NULL, 0}
|
||||
};
|
||||
|
||||
|
@ -219,6 +274,7 @@ int parse_args(int ac, char **av, args_t *args)
|
|||
int c; opterr = 0;
|
||||
int help = 0;
|
||||
const char *s_out = NULL, *s_dir = NULL, *s_todir = NULL;
|
||||
const char *s_use = NULL, *s_set = NULL;
|
||||
while ((c = getopt_long(ac, av, short_options, long_options, NULL)) != -1) {
|
||||
switch (c) {
|
||||
/* help */
|
||||
|
@ -246,6 +302,10 @@ int parse_args(int ac, char **av, args_t *args)
|
|||
/* force no exit */
|
||||
case 'e': args->initflags &= ~P7_TERM; break;
|
||||
|
||||
/* use and set settings */
|
||||
case 'U': s_use = optarg; break;
|
||||
case 'S': s_set = optarg; break;
|
||||
|
||||
/* in case of error */
|
||||
case '?':
|
||||
if (optopt == 'o')
|
||||
|
@ -349,6 +409,18 @@ int parse_args(int ac, char **av, args_t *args)
|
|||
noerror = 1;
|
||||
if (!noerror) return (0);
|
||||
|
||||
/* serial settings */
|
||||
if (s_set) {
|
||||
if (args->com) args->set = &args->_set;
|
||||
if (make_settings("--set", s_set, &args->_set))
|
||||
return (0);
|
||||
}
|
||||
if (s_use) {
|
||||
if (args->com) args->use = &args->_use;
|
||||
if (make_settings("--use", s_use, &args->_use))
|
||||
return (0);
|
||||
}
|
||||
|
||||
/* check local path */
|
||||
if (args->localpath) {
|
||||
if (fpmode[0] == 'w' && !strcmp(args->localpath, "-"))
|
||||
|
|
|
@ -194,7 +194,8 @@ int main(int ac, char **av)
|
|||
|
||||
/* Initialize libp7 and communication */
|
||||
p7_handle_t *handle = NULL; int err;
|
||||
if (args.com) err = p7_cominit(&handle, args.initflags, args.com, NULL);
|
||||
if (args.com) err = p7_cominit(&handle, args.initflags,
|
||||
args.com, args.use);
|
||||
else err = p7_init(&handle, args.initflags);
|
||||
if (err) {
|
||||
/* display error */
|
||||
|
@ -214,6 +215,12 @@ int main(int ac, char **av)
|
|||
return (1);
|
||||
}
|
||||
|
||||
/* Change speed, and things */
|
||||
if (args.set) {
|
||||
err = p7_setlink(handle, args.set);
|
||||
if (err) goto fail;
|
||||
}
|
||||
|
||||
/* Check according to menu */
|
||||
switch (args.menu) {
|
||||
case mn_send:
|
||||
|
@ -270,41 +277,47 @@ int main(int ac, char **av)
|
|||
}
|
||||
|
||||
/* put error */
|
||||
if (err && err != p7_error_denied_overwrite) {
|
||||
if (sendfile_display_initialized)
|
||||
puts("\b\b\b\b\b\bError !");
|
||||
|
||||
/* close the file */
|
||||
if (args.local) fclose(args.local);
|
||||
if (args.menu == mn_get && args.local != stdout)
|
||||
remove(args.localpath);
|
||||
|
||||
/* put the error string */
|
||||
switch (err) {
|
||||
case p7_error_fullmem: log(error_nospace); break;
|
||||
case p7_error_empty: log(error_empty); break;
|
||||
case p7_error_notfound: log(error_noexists); break;
|
||||
case p7_error_nocalc: log(error_disconnected); break;
|
||||
case p7_error_unsupported: log(error_unsupported); break;
|
||||
case p7_error_unsupported_device:
|
||||
log(error_unsupported_device, args.storage); break;
|
||||
default: log(error_unplanned, p7_strerror(err));
|
||||
}
|
||||
|
||||
/* that doesn't mean you shouldn't exit, heh. */
|
||||
p7_exit(handle);
|
||||
|
||||
/* return that an error has occured */
|
||||
return (1);
|
||||
}
|
||||
if (err && err != p7_error_denied_overwrite)
|
||||
goto fail;
|
||||
|
||||
if (sendfile_display_initialized)
|
||||
puts("\b\b\b\b\b\bTransfer complete.");
|
||||
if (args.local) fclose(args.local);
|
||||
if (args.local && args.local != stdout) fclose(args.local);
|
||||
|
||||
/* terminate communication and de-initialize libp7 */
|
||||
p7_exit(handle);
|
||||
p7_exit(handle); handle = NULL;
|
||||
|
||||
/* Then we're good */
|
||||
return (0);
|
||||
fail:
|
||||
if (sendfile_display_initialized)
|
||||
puts("\b\b\b\b\b\bError !");
|
||||
|
||||
/* close the file */
|
||||
if (args.local && args.local != stdout) fclose(args.local);
|
||||
if (args.menu == mn_get && args.local != stdout)
|
||||
remove(args.localpath);
|
||||
|
||||
/* put the error string */
|
||||
switch (err) {
|
||||
case p7_error_fullmem:
|
||||
log(error_nospace); break;
|
||||
case p7_error_empty:
|
||||
log(error_empty); break;
|
||||
case p7_error_notfound:
|
||||
log(error_noexists); break;
|
||||
case p7_error_nocalc:
|
||||
log(error_disconnected); break;
|
||||
case p7_error_unsupported:
|
||||
log(error_unsupported); break;
|
||||
case p7_error_unsupported_device:
|
||||
log(error_unsupported_device, args.storage); break;
|
||||
default: log(error_unplanned, p7_strerror(err));
|
||||
}
|
||||
|
||||
/* that doesn't mean you shouldn't exit, heh. */
|
||||
p7_exit(handle); handle = NULL;
|
||||
|
||||
/* then go away */
|
||||
return (1);
|
||||
}
|
||||
|
|
|
@ -33,8 +33,12 @@ typedef enum {
|
|||
/* Arguments */
|
||||
typedef struct {
|
||||
/* basic things */
|
||||
menu_t menu;
|
||||
int nicedisp;
|
||||
menu_t menu; int nicedisp;
|
||||
|
||||
/* libp7 settings */
|
||||
unsigned int initflags;
|
||||
p7_streamsettings_t *use, _use;
|
||||
p7_streamsettings_t *set, _set;
|
||||
|
||||
/* for file transferring menus */
|
||||
const char *dirname, *filename;
|
||||
|
@ -43,9 +47,7 @@ typedef struct {
|
|||
int force;
|
||||
|
||||
/* other options */
|
||||
unsigned int initflags;
|
||||
const char *com;
|
||||
const char *storage;
|
||||
const char *com, *storage;
|
||||
} args_t;
|
||||
|
||||
/* Parsing function */
|
||||
|
|
Reference in New Issue