aboutsummaryrefslogtreecommitdiff
path: root/shell
diff options
context:
space:
mode:
authorandersen <andersen@69ca8d6d-28ef-0310-b511-8ec308f3f277>2001-05-02 02:09:36 +0000
committerandersen <andersen@69ca8d6d-28ef-0310-b511-8ec308f3f277>2001-05-02 02:09:36 +0000
commit7b1a2b9d026823684c138acf1167058d204463d2 (patch)
treee86880faf6b980466bf99ebd01400349ad8573a4 /shell
parent80bae69d1f26fe7ee76101814497bf317804e73b (diff)
downloadbusybox-w32-7b1a2b9d026823684c138acf1167058d204463d2.tar.gz
busybox-w32-7b1a2b9d026823684c138acf1167058d204463d2.tar.bz2
busybox-w32-7b1a2b9d026823684c138acf1167058d204463d2.zip
Another update from Larry:
Makes hush return code equal to that of the last command executed. Fixes the mode where input comes from a file. git-svn-id: svn://busybox.net/trunk/busybox@2509 69ca8d6d-28ef-0310-b511-8ec308f3f277
Diffstat (limited to 'shell')
-rw-r--r--shell/hush.c36
1 files changed, 19 insertions, 17 deletions
diff --git a/shell/hush.c b/shell/hush.c
index 8ef1e2731..2e65f0b6d 100644
--- a/shell/hush.c
+++ b/shell/hush.c
@@ -445,7 +445,7 @@ static int builtin_exec(struct child_prog *child)
445static int builtin_exit(struct child_prog *child) 445static int builtin_exit(struct child_prog *child)
446{ 446{
447 if (child->argv[1] == NULL) 447 if (child->argv[1] == NULL)
448 exit(EXIT_SUCCESS); 448 exit(last_return_code);
449 exit (atoi(child->argv[1])); 449 exit (atoi(child->argv[1]));
450} 450}
451 451
@@ -814,17 +814,14 @@ static int file_get(struct in_str *i)
814 if (i->__promptme && interactive && i->file == stdin) { 814 if (i->__promptme && interactive && i->file == stdin) {
815 get_user_input(i); 815 get_user_input(i);
816 i->promptmode=2; 816 i->promptmode=2;
817 i->__promptme = 0;
818 if (i->p && *i->p) {
819 ch=*i->p++;
820 }
817 } else { 821 } else {
818 static char buffer; 822 ch = fgetc(i->file);
819 buffer = fgetc(i->file);
820 i->p = &buffer;
821 } 823 }
822 824
823 i->__promptme = 0;
824
825 if (i->p && *i->p) {
826 ch=*i->p++;
827 }
828 debug_printf("b_getch: got a %d\n", ch); 825 debug_printf("b_getch: got a %d\n", ch);
829 } 826 }
830 if (ch == '\n') i->__promptme=1; 827 if (ch == '\n') i->__promptme=1;
@@ -839,9 +836,10 @@ static int file_peek(struct in_str *i)
839 if (i->p && *i->p) { 836 if (i->p && *i->p) {
840 return *i->p; 837 return *i->p;
841 } else { 838 } else {
842 static char buffer; 839 static char buffer[2];
843 buffer = fgetc(i->file); 840 buffer[0] = fgetc(i->file);
844 i->p = &buffer; 841 buffer[1] = '\0';
842 i->p = buffer;
845 debug_printf("b_peek: got a %d\n", *i->p); 843 debug_printf("b_peek: got a %d\n", *i->p);
846 return *i->p; 844 return *i->p;
847 } 845 }
@@ -2081,6 +2079,8 @@ int shell_main(int argc, char **argv)
2081 int opt; 2079 int opt;
2082 FILE *input; 2080 FILE *input;
2083 2081
2082 last_return_code=EXIT_SUCCESS;
2083
2084 /* XXX what should these be while sourcing /etc/profile? */ 2084 /* XXX what should these be while sourcing /etc/profile? */
2085 global_argc = argc; 2085 global_argc = argc;
2086 global_argv = argv; 2086 global_argv = argv;
@@ -2110,7 +2110,7 @@ int shell_main(int argc, char **argv)
2110 global_argv = argv+optind; 2110 global_argv = argv+optind;
2111 global_argc = argc-optind; 2111 global_argc = argc-optind;
2112 opt = parse_string_outer(optarg); 2112 opt = parse_string_outer(optarg);
2113 exit(opt); 2113 goto final_return;
2114 } 2114 }
2115 break; 2115 break;
2116 case 'i': 2116 case 'i':
@@ -2136,13 +2136,14 @@ int shell_main(int argc, char **argv)
2136 isatty(fileno(stdin)) && isatty(fileno(stdout))) { 2136 isatty(fileno(stdin)) && isatty(fileno(stdout))) {
2137 interactive++; 2137 interactive++;
2138 } 2138 }
2139 2139
2140 debug_printf("\ninteractive=%d\n", interactive);
2140 if (interactive) { 2141 if (interactive) {
2141 /* Looks like they want an interactive shell */ 2142 /* Looks like they want an interactive shell */
2142 fprintf(stdout, "\nhush -- the humble shell v0.01 (testing)\n\n"); 2143 fprintf(stdout, "\nhush -- the humble shell v0.01 (testing)\n\n");
2143 exit(parse_file_outer(stdin)); 2144 opt=parse_file_outer(stdin);
2145 goto final_return;
2144 } 2146 }
2145 debug_printf("\ninteractive=%d\n", interactive);
2146 2147
2147 debug_printf("\nrunning script '%s'\n", argv[optind]); 2148 debug_printf("\nrunning script '%s'\n", argv[optind]);
2148 global_argv = argv+optind; 2149 global_argv = argv+optind;
@@ -2154,5 +2155,6 @@ int shell_main(int argc, char **argv)
2154 fclose(input.file); 2155 fclose(input.file);
2155#endif 2156#endif
2156 2157
2157 return(opt); 2158final_return:
2159 return(opt?opt:last_return_code);
2158} 2160}