diff --git a/src/p7/args.c b/src/p7/args.c index d51dc6e..0eca83c 100644 --- a/src/p7/args.c +++ b/src/p7/args.c @@ -70,6 +70,7 @@ static const char help_main[] = " and two stop bits. (E for even parity, O for odd parity)\n" " --set Set the following serial settings (when used with `--com`).\n" " The string has the same format than for `--use`.\n" +" --reset Reset the default communication settings (9600N2).\n" "\n" "Type \"" QUOTE(BIN) " --help\" for some help about the subcommand.\n" "Report bugs to " QUOTE(MAINTAINER) "."; @@ -264,6 +265,7 @@ int parse_args(int ac, char **av, args_t *args) {"no-exit", no_argument, NULL, 'e'}, {"no-term", no_argument, NULL, 'e'}, {"set", required_argument, NULL, 'S'}, + {"reset", no_argument, NULL, 'R'}, {"use", required_argument, NULL, 'U'}, /* sentinel */ @@ -272,7 +274,7 @@ int parse_args(int ac, char **av, args_t *args) /* get all options */ int c; opterr = 0; - int help = 0; + int help = 0, rst = 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) { @@ -305,6 +307,7 @@ int parse_args(int ac, char **av, args_t *args) /* use and set settings */ case 'U': s_use = optarg; break; case 'S': s_set = optarg; break; + case 'R': rst = 1; break; /* in case of error */ case '?': @@ -409,18 +412,23 @@ 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); - } + /* use serial settings */ if (s_use) { if (args->com) args->use = &args->_use; if (make_settings("--use", s_use, &args->_use)) return (0); } + /* set serial settings */ + if (rst) + args->do_the_set = 1; + else if (s_set) { + args->do_the_set = 1; + if (args->com) args->set = &args->_set; + if (make_settings("--set", s_set, &args->_set)) + return (0); + } + /* check local path */ if (args->localpath) { if (fpmode[0] == 'w' && !strcmp(args->localpath, "-")) diff --git a/src/p7/main.c b/src/p7/main.c index 9ed697e..17b901c 100644 --- a/src/p7/main.c +++ b/src/p7/main.c @@ -216,7 +216,7 @@ int main(int ac, char **av) } /* Change speed, and things */ - if (args.set) { + if (args.do_the_set) { err = p7_setlink(handle, args.set); if (err) goto fail; } diff --git a/src/p7/main.h b/src/p7/main.h index fb39ec6..23c5b4e 100644 --- a/src/p7/main.h +++ b/src/p7/main.h @@ -39,6 +39,7 @@ typedef struct { unsigned int initflags; p7_streamsettings_t *use, _use; p7_streamsettings_t *set, _set; + int do_the_set; /* for file transferring menus */ const char *dirname, *filename;