Update internal.h to conditionally include asm/string.h
[oweals/busybox.git] / lash.c
diff --git a/lash.c b/lash.c
index 05dab925442a96660c6c60e24f3e155bfeb6f7be..56d94258cdf6331ed3312958488b1473f7ec497f 100644 (file)
--- a/lash.c
+++ b/lash.c
@@ -113,13 +113,18 @@ static int busy_loop(FILE * input);
 static struct builtInCommand bltins[] = {
        {"bg", "Resume a job in the background", "bg [%%job]", shell_fg_bg},
        {"cd", "Change working directory", "cd [dir]", shell_cd},
-       {"env", "Print all environment variables", "env", shell_env},
        {"exit", "Exit from shell()", "exit", shell_exit},
        {"fg", "Bring job into the foreground", "fg [%%job]", shell_fg_bg},
        {"jobs", "Lists the active jobs", "jobs", shell_jobs},
-       {"pwd", "Print current directory", "pwd", shell_pwd},
        {"export", "Set environment variable", "export [VAR=value]", shell_export},
        {"unset", "Unset environment variable", "unset VAR", shell_unset},
+       {NULL, NULL, NULL, NULL}
+};
+
+/* Table of built-in functions */
+static struct builtInCommand bltins_forking[] = {
+       {"env", "Print all environment variables", "env", shell_env},
+       {"pwd", "Print current directory", "pwd", shell_pwd},
        {".", "Source-in and run commands in a file", ". filename", shell_source},
        {"help", "List shell built-in commands", "help", shell_help},
        {NULL, NULL, NULL, NULL}
@@ -183,8 +188,7 @@ static int shell_exit(struct job *cmd, struct jobSet *junk)
        if (!cmd->progs[0].argv[1] == 1)
                exit TRUE;
 
-       else
-               exit(atoi(cmd->progs[0].argv[1]));
+       return(atoi(cmd->progs[0].argv[1]));
 }
 
 /* built-in 'fg' and 'bg' handler */
@@ -247,6 +251,9 @@ static int shell_help(struct job *cmd, struct jobSet *junk)
        for (x = bltins; x->cmd; x++) {
                fprintf(stdout, "%s\t%s\n", x->cmd, x->descr);
        }
+       for (x = bltins_forking; x->cmd; x++) {
+               fprintf(stdout, "%s\t%s\n", x->cmd, x->descr);
+       }
        fprintf(stdout, "\n\n");
        return TRUE;
 }
@@ -743,6 +750,13 @@ static int runCommand(struct job newJob, struct jobSet *jobList, int inBg)
                        nextout = 1;
                }
 
+               /* Match any built-ins here */
+               for (x = bltins; x->cmd; x++) {
+                       if (!strcmp(newJob.progs[i].argv[0], x->cmd)) {
+                               return (x->function(&newJob, jobList));
+                       }
+               }
+
                if (!(newJob.progs[i].pid = fork())) {
                        signal(SIGTTOU, SIG_DFL);
 
@@ -760,7 +774,7 @@ static int runCommand(struct job newJob, struct jobSet *jobList, int inBg)
                        setupRedirections(newJob.progs + i);
 
                        /* Match any built-ins here */
-                       for (x = bltins; x->cmd; x++) {
+                       for (x = bltins_forking; x->cmd; x++) {
                                if (!strcmp(newJob.progs[i].argv[0], x->cmd)) {
                                        exit (x->function(&newJob, jobList));
                                }
@@ -771,7 +785,7 @@ static int runCommand(struct job newJob, struct jobSet *jobList, int inBg)
                                if (strcmp(newJob.progs[i].argv[0], a->name) == 0) {
                                        int argc;
                                        char** argv=newJob.progs[i].argv;
-                                       for(argc=0;*argv!=NULL, argv++, argc++);
+                                       for(argc=0;*argv!=NULL; argv++, argc++);
                                        exit((*(a->main)) (argc, newJob.progs[i].argv));
                                }
                                a++;