summaryrefslogtreecommitdiffstats
path: root/cpukit/libmisc/shell/shell.c
diff options
context:
space:
mode:
authorJoel Sherrill <joel.sherrill@OARcorp.com>2008-03-07 20:09:36 +0000
committerJoel Sherrill <joel.sherrill@OARcorp.com>2008-03-07 20:09:36 +0000
commit85659eeeb61570697044d6dc6617a8c6edb84049 (patch)
treef7767fddb777574a1fa22490a7ba2244edf553f4 /cpukit/libmisc/shell/shell.c
parent2008-03-07 Joel Sherrill <joel.sherrill@OARcorp.com> (diff)
downloadrtems-85659eeeb61570697044d6dc6617a8c6edb84049.tar.bz2
2008-03-07 Joel Sherrill <joel.sherrill@oarcorp.com>
* 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.
Diffstat (limited to 'cpukit/libmisc/shell/shell.c')
-rw-r--r--cpukit/libmisc/shell/shell.c30
1 files changed, 20 insertions, 10 deletions
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<size-1) {
line[col++] = c;
- if (out) fputc(c,out);
+ if (doEcho) fputc(c,out);
} else {
- if (out) fputc('\a',out);
+ if (doEcho) fputc('\a',out);
}
} else {
- if (out)
+ if (doEcho)
if (c=='\a') fputc('\a',out);
}
break;