static int builtin_exit(struct child_prog *child)
{
if (child->argv[1] == NULL)
- exit(EXIT_SUCCESS);
+ exit(last_return_code);
exit (atoi(child->argv[1]));
}
if (i->__promptme && interactive && i->file == stdin) {
get_user_input(i);
i->promptmode=2;
+ i->__promptme = 0;
+ if (i->p && *i->p) {
+ ch=*i->p++;
+ }
} else {
- static char buffer;
- buffer = fgetc(i->file);
- i->p = &buffer;
+ ch = fgetc(i->file);
}
- i->__promptme = 0;
-
- if (i->p && *i->p) {
- ch=*i->p++;
- }
debug_printf("b_getch: got a %d\n", ch);
}
if (ch == '\n') i->__promptme=1;
if (i->p && *i->p) {
return *i->p;
} else {
- static char buffer;
- buffer = fgetc(i->file);
- i->p = &buffer;
+ static char buffer[2];
+ buffer[0] = fgetc(i->file);
+ buffer[1] = '\0';
+ i->p = buffer;
debug_printf("b_peek: got a %d\n", *i->p);
return *i->p;
}
int opt;
FILE *input;
+ last_return_code=EXIT_SUCCESS;
+
/* XXX what should these be while sourcing /etc/profile? */
global_argc = argc;
global_argv = argv;
global_argv = argv+optind;
global_argc = argc-optind;
opt = parse_string_outer(optarg);
- exit(opt);
+ goto final_return;
}
break;
case 'i':
isatty(fileno(stdin)) && isatty(fileno(stdout))) {
interactive++;
}
-
+
+ debug_printf("\ninteractive=%d\n", interactive);
if (interactive) {
/* Looks like they want an interactive shell */
fprintf(stdout, "\nhush -- the humble shell v0.01 (testing)\n\n");
- exit(parse_file_outer(stdin));
+ opt=parse_file_outer(stdin);
+ goto final_return;
}
- debug_printf("\ninteractive=%d\n", interactive);
debug_printf("\nrunning script '%s'\n", argv[optind]);
global_argv = argv+optind;
fclose(input.file);
#endif
- return(opt);
+final_return:
+ return(opt?opt:last_return_code);
}
static int builtin_exit(struct child_prog *child)
{
if (child->argv[1] == NULL)
- exit(EXIT_SUCCESS);
+ exit(last_return_code);
exit (atoi(child->argv[1]));
}
if (i->__promptme && interactive && i->file == stdin) {
get_user_input(i);
i->promptmode=2;
+ i->__promptme = 0;
+ if (i->p && *i->p) {
+ ch=*i->p++;
+ }
} else {
- static char buffer;
- buffer = fgetc(i->file);
- i->p = &buffer;
+ ch = fgetc(i->file);
}
- i->__promptme = 0;
-
- if (i->p && *i->p) {
- ch=*i->p++;
- }
debug_printf("b_getch: got a %d\n", ch);
}
if (ch == '\n') i->__promptme=1;
if (i->p && *i->p) {
return *i->p;
} else {
- static char buffer;
- buffer = fgetc(i->file);
- i->p = &buffer;
+ static char buffer[2];
+ buffer[0] = fgetc(i->file);
+ buffer[1] = '\0';
+ i->p = buffer;
debug_printf("b_peek: got a %d\n", *i->p);
return *i->p;
}
int opt;
FILE *input;
+ last_return_code=EXIT_SUCCESS;
+
/* XXX what should these be while sourcing /etc/profile? */
global_argc = argc;
global_argv = argv;
global_argv = argv+optind;
global_argc = argc-optind;
opt = parse_string_outer(optarg);
- exit(opt);
+ goto final_return;
}
break;
case 'i':
isatty(fileno(stdin)) && isatty(fileno(stdout))) {
interactive++;
}
-
+
+ debug_printf("\ninteractive=%d\n", interactive);
if (interactive) {
/* Looks like they want an interactive shell */
fprintf(stdout, "\nhush -- the humble shell v0.01 (testing)\n\n");
- exit(parse_file_outer(stdin));
+ opt=parse_file_outer(stdin);
+ goto final_return;
}
- debug_printf("\ninteractive=%d\n", interactive);
debug_printf("\nrunning script '%s'\n", argv[optind]);
global_argv = argv+optind;
fclose(input.file);
#endif
- return(opt);
+final_return:
+ return(opt?opt:last_return_code);
}