1
0
mirror of https://github.com/UzixLS/picocom.git synced 2025-07-19 07:21:18 +03:00

Allow multiple non-option argunments, use last

Allow more than one non-option arguments. Use the last one as the port
name, ignore others.

Rationale. Allow easily setting a default port using an alias or
script. The port can then be overriden by a subsequent argument. E.g.

  alias picocom='picocom -b 115200 /dev/ttyS0'

  picocom               <-- call with default port
  picocom /dev/ttyUSB0  <-- override default
This commit is contained in:
Nick Patavalis
2018-02-08 17:01:23 +02:00
parent 9d5cc80c47
commit 8707801496

View File

@ -1932,20 +1932,12 @@ parse_args(int argc, char *argv[])
fprintf(stderr, "Run with '--help'.\n");
exit(EXIT_FAILURE);
}
opts.port = strdup(argv[optind++]);
opts.port = strdup(argv[argc-1]);
if ( ! opts.port ) {
fprintf(stderr, "Out of memory\n");
exit(EXIT_FAILURE);
}
if ( argc != optind ) {
fprintf(stderr, "Unexpected non-option arguments: ");
while (argc != optind)
fprintf(stderr, "%s ", argv[optind++]);
fprintf(stderr, "\n");
exit(EXIT_FAILURE);
}
if ( opts.quiet )
return;