X-Git-Url: https://git.librecmc.org/?a=blobdiff_plain;f=shell%2Fbbsh.c;h=02e60508fb2032fd4f382c168d65ea901d3d3605;hb=b68979aefa0efb519e6af02deba082e6b4180043;hp=05ae1637e8bb0ff29fcca2d413c41654654f2f96;hpb=9213a9e0f2d8fd638ecd02e2628d96dd5c7d233e;p=oweals%2Fbusybox.git diff --git a/shell/bbsh.c b/shell/bbsh.c index 05ae1637e..02e60508f 100644 --- a/shell/bbsh.c +++ b/shell/bbsh.c @@ -36,7 +36,7 @@ echo `echo hello#comment " woot` and more */ -#include +#include "libbb.h" // A single executable, its arguments, and other information we know about it. #define BBSH_FLAG_EXIT 1 @@ -68,7 +68,7 @@ struct pipeline { static void free_list(void *list, void (*freeit)(void *data)) { - while(list) { + while (list) { void **next = (void **)list; void *list_next = *next; freeit(list); @@ -90,7 +90,7 @@ static char *parse_word(char *start, struct command **cmd) // Grab next word. (Add dequote and envvar logic here) end = start; - while (*end && !isspace(*end)) end++; + end = skip_non_whitespace(end); (*cmd)->argv[(*cmd)->argc++] = xstrndup(start, end-start); // Allocate more space if there's no room for NULL terminator. @@ -119,7 +119,7 @@ static char *parse_pipeline(char *cmdline, struct pipeline *line) char *end; // Skip leading whitespace and detect end of line. - while (isspace(*start)) start++; + start = skip_whitespace(start); if (!*start || *start=='#') { if (ENABLE_BBSH_JOBCTL) line->cmdlinelen = start-cmdline; return 0; @@ -159,13 +159,13 @@ static int run_pipeline(struct pipeline *line) // Handle local commands. This is totally fake and plastic. if (cmd->argc==2 && !strcmp(cmd->argv[0],"cd")) chdir(cmd->argv[1]); - else if(!strcmp(cmd->argv[0],"exit")) + else if (!strcmp(cmd->argv[0],"exit")) exit(cmd->argc>1 ? atoi(cmd->argv[1]) : 0); else { int status; pid_t pid=fork(); - if(!pid) { - run_applet_by_name(cmd->argv[0],cmd->argc,cmd->argv); + if (!pid) { + run_applet_and_exit(cmd->argv[0],cmd->argc,cmd->argv); execvp(cmd->argv[0],cmd->argv); printf("No %s",cmd->argv[0]); exit(1); @@ -179,7 +179,7 @@ static void free_cmd(void *data) { struct command *cmd=(struct command *)data; - while(cmd->argc) free(cmd->argv[--cmd->argc]); + while (cmd->argc) free(cmd->argv[--cmd->argc]); } @@ -198,20 +198,21 @@ static void handle(char *command) } } -int bbsh_main(int argc, char *argv[]) +int bbsh_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE; +int bbsh_main(int argc, char **argv) { char *command=NULL; FILE *f; - bb_getopt_ulflags(argc, argv, "c:", &command); + getopt32(argv, "c:", &command); f = argv[optind] ? xfopen(argv[optind],"r") : NULL; if (command) handle(command); else { unsigned cmdlen=0; for (;;) { - if(!f) putchar('$'); - if(1 > getline(&command, &cmdlen,f ? : stdin)) break; + if (!f) putchar('$'); + if (1 > getline(&command, &cmdlen,f ? : stdin)) break; handle(command); }