From 85659eeeb61570697044d6dc6617a8c6edb84049 Mon Sep 17 00:00:00 2001 From: Joel Sherrill Date: Fri, 7 Mar 2008 20:09:36 +0000 Subject: 2008-03-07 Joel Sherrill * libmisc/shell/main_cp.c, libmisc/shell/main_netstats.c, libmisc/shell/shell_script.c: Add memset() of getopt_data to ensure it is zeroed out each time we use getopt_r(). * libmisc/shell/shell.c: Do not echo commands if input is not a tty. This makes the scripts behave more like UNIX scripts. --- cpukit/libmisc/shell/shell.c | 30 ++++++++++++++++++++---------- 1 file changed, 20 insertions(+), 10 deletions(-) (limited to 'cpukit/libmisc/shell/shell.c') diff --git a/cpukit/libmisc/shell/shell.c b/cpukit/libmisc/shell/shell.c index 264742a246..e503739f94 100644 --- a/cpukit/libmisc/shell/shell.c +++ b/cpukit/libmisc/shell/shell.c @@ -79,13 +79,23 @@ rtems_shell_env_t *rtems_shell_init_env( /* * Get a line of user input with modest features */ -int rtems_shell_scanline(char * line,int size,FILE * in,FILE * out) { - int c,col; +int rtems_shell_scanline( + char *line, + int size, + FILE *in, + FILE *out +) +{ + int c; + int col; + int doEcho; + + doEcho = (out && isatty(fileno(in))); col = 0; if (*line) { col = strlen(line); - if (out) fprintf(out,"%s",line); + if (doEcho) fprintf(out,"%s",line); } tcdrain(fileno(in)); if (out) @@ -100,38 +110,38 @@ int rtems_shell_scanline(char * line,int size,FILE * in,FILE * out) { case EOF: return 0; case '\f': - if (out) + if (doEcho) fputc('\f',out); case 0x03:/*Control-C*/ line[0] = 0; case '\n': case '\r': - if (out) + if (doEcho) fputc('\n',out); return 1; case 127: case '\b': if (col) { - if (out) { + if (doEcho) { fputc('\b',out); fputc(' ',out); fputc('\b',out); } col--; } else { - if (out) fputc('\a',out); + if (doEcho) fputc('\a',out); } break; default: if (!iscntrl(c)) { if (col