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

Added the --exit command-line option

Exit picocom immediatelly after opening and configuring the serial
port. Do *not* read *anything* from the standard input or from the
serial port. If an init string is also given, picocom exits imediatelly
after sending (writing) the init string to the serial port. Again,
nothing is read from the standard input, or from the serial port. The
ouput map, the local echo option, and the local-echo map are observed
when sending the init string. The **--exit** option, overrides
the **--exit-after** option.
This commit is contained in:
Nick Patavalis
2017-12-16 10:51:34 +02:00
parent 423c93fe5e
commit e9385b0ece
2 changed files with 48 additions and 15 deletions

View File

@ -332,6 +332,21 @@ Picocom accepts the following command-line options.
zero bytes from the standard input causes picocom to exit, after
the contents of its output queue have been transmitted.
**--exit** | **-X**
: Exit picocom immediatelly after opening and configuring the
serial port. Do *not* read *anything* from the standard input or
from the serial port. When exiting the **--noreset** option is
observed as usual. With **--exit** and **--noreset** picocom can
be used as a crude replacement of **stty(1)**. If an init string
is also given (see **--initstring** option), picocom exits
imediatelly after sending (writing) the init string to the serial
port. Again, nothing is read from the standard input, or from the
serial port. The ouput map (see **--omap**), the local echo
option (see **--echo**), and the local-echo map (see **--emap**)
are observed when sending the init string. The **--exit** option,
overrides the **--exit-after** option. (Default: Disabled)
**--quiet** | **-q**
: Forces picocom to be quiet. Suppresses the output of the initial

View File

@ -193,6 +193,7 @@ struct {
char *log_filename;
char *initstring;
int exit_after;
int exit;
int lower_rts;
int lower_dtr;
int quiet;
@ -218,6 +219,7 @@ struct {
.log_filename = NULL,
.initstring = NULL,
.exit_after = -1,
.exit = 0,
.lower_rts = 0,
.lower_dtr = 0,
.quiet = 0
@ -1117,7 +1119,10 @@ loop(void)
int stdin_closed;
state = ST_TRANSPARENT;
stdin_closed = 0;
if ( ! opts.exit )
stdin_closed = 0;
else
stdin_closed = 1;
while ( ! sig_exit ) {
struct timeval tv, *ptv;
@ -1126,7 +1131,7 @@ loop(void)
FD_ZERO(&rdset);
FD_ZERO(&wrset);
if ( ! stdin_closed ) FD_SET(STI, &rdset);
FD_SET(tty_fd, &rdset);
if ( ! opts.exit ) FD_SET(tty_fd, &rdset);
if ( tty_q.len ) {
FD_SET(tty_fd, &wrset);
} else {
@ -1352,6 +1357,7 @@ show_usage(char *name)
printf(" --lo<g>file <filename>\n");
printf(" --inits<t>ring <s>\n");
printf(" --e<x>it-after <msec>\n");
printf(" --e<X>it\n");
printf(" --lower-rts\n");
printf(" --lower-dtr\n");
printf(" --<h>elp\n");
@ -1398,6 +1404,7 @@ parse_args(int argc, char *argv[])
{"logfile", required_argument, 0, 'g'},
{"initstring", required_argument, 0, 't'},
{"exit-after", required_argument, 0, 'x'},
{"exit", no_argument, 0, 'X'},
{"lower-rts", no_argument, 0, 'R'},
{"lower-dtr", no_argument, 0, 'D'},
{"quiet", no_argument, 0, 'q'},
@ -1415,7 +1422,7 @@ parse_args(int argc, char *argv[])
/* no default error messages printed. */
opterr = 0;
c = getopt_long(argc, argv, "hirlcqv:s:r:e:f:b:y:d:p:g:t:x:",
c = getopt_long(argc, argv, "hirlcqXv:s:r:e:f:b:y:d:p:g:t:x:",
longOptions, &optionIndex);
if (c < 0)
@ -1573,6 +1580,9 @@ parse_args(int argc, char *argv[])
break;
}
break;
case 'X':
opts.exit = 1;
break;
case 'q':
opts.quiet = 1;
break;
@ -1591,6 +1601,9 @@ parse_args(int argc, char *argv[])
}
} /* while */
/* --exit overrides --exit-after */
if ( opts.exit ) opts.exit_after = -1;
if ( (argc - optind) < 1) {
fprintf(stderr, "No port given\n");
fprintf(stderr, "Run with '--help'.\n");
@ -1642,6 +1655,7 @@ parse_args(int argc, char *argv[])
} else {
printf("exit_after is : %d ms\n", opts.exit_after);
}
printf("exit is : %s\n", opts.exit ? "yes" : "no");
printf("\n");
#endif /* of NO_HELP */
}
@ -1725,19 +1739,23 @@ main(int argc, char *argv[])
set_tty_write_sz(term_get_baudrate(tty_fd, NULL));
if ( isatty(STI) ) {
r = term_add(STI);
if ( r < 0 )
fatal("failed to add I/O device: %s",
term_strerror(term_errno, errno));
term_set_raw(STI);
r = term_apply(STI, 0);
if ( r < 0 )
fatal("failed to set I/O device to raw mode: %s",
term_strerror(term_errno, errno));
if ( ! opts.exit ) {
if ( isatty(STI) ) {
r = term_add(STI);
if ( r < 0 )
fatal("failed to add I/O device: %s",
term_strerror(term_errno, errno));
term_set_raw(STI);
r = term_apply(STI, 0);
if ( r < 0 )
fatal("failed to set I/O device to raw mode: %s",
term_strerror(term_errno, errno));
} else {
fd_pinfof(opts.quiet,
"!! STDIN is not a TTY !! Continue anyway...\r\n");
}
} else {
fd_pinfof(opts.quiet,
"!! STDIN is not a TTY !! Continuing anyway...\r\n");
close(STI);
}
#ifdef LINENOISE