aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorEric Andersen <andersen@codepoet.org>2000-07-10 18:47:24 +0000
committerEric Andersen <andersen@codepoet.org>2000-07-10 18:47:24 +0000
commit34e1941c32cd9366d4ada22c3ab3e42b9c986a2b (patch)
tree20b4408b7124d03b3b35759ecabec0eaf89f5cf2
parent0b4551faf520e44a9a0bf2ac72b3dcd6a145a0a1 (diff)
downloadbusybox-w32-34e1941c32cd9366d4ada22c3ab3e42b9c986a2b.tar.gz
busybox-w32-34e1941c32cd9366d4ada22c3ab3e42b9c986a2b.tar.bz2
busybox-w32-34e1941c32cd9366d4ada22c3ab3e42b9c986a2b.zip
Function name cleanup.
-Erik
-rw-r--r--lash.c86
-rw-r--r--sh.c86
-rw-r--r--shell/lash.c86
3 files changed, 135 insertions, 123 deletions
diff --git a/lash.c b/lash.c
index 7203ba38f..60d67e9e8 100644
--- a/lash.c
+++ b/lash.c
@@ -89,19 +89,21 @@ struct builtInCommand {
89 int (*function) (struct job *, struct jobSet * jobList); /* function ptr */ 89 int (*function) (struct job *, struct jobSet * jobList); /* function ptr */
90}; 90};
91 91
92/* Some function prototypes */ 92/* function prototypes for builtins */
93static int shell_cd(struct job *cmd, struct jobSet *junk); 93static int builtin_cd(struct job *cmd, struct jobSet *junk);
94static int shell_env(struct job *dummy, struct jobSet *junk); 94static int builtin_env(struct job *dummy, struct jobSet *junk);
95static int shell_exit(struct job *cmd, struct jobSet *junk); 95static int builtin_exit(struct job *cmd, struct jobSet *junk);
96static int shell_fg_bg(struct job *cmd, struct jobSet *jobList); 96static int builtin_fg_bg(struct job *cmd, struct jobSet *jobList);
97static int shell_help(struct job *cmd, struct jobSet *junk); 97static int builtin_help(struct job *cmd, struct jobSet *junk);
98static int shell_jobs(struct job *dummy, struct jobSet *jobList); 98static int builtin_jobs(struct job *dummy, struct jobSet *jobList);
99static int shell_pwd(struct job *dummy, struct jobSet *junk); 99static int builtin_pwd(struct job *dummy, struct jobSet *junk);
100static int shell_export(struct job *cmd, struct jobSet *junk); 100static int builtin_export(struct job *cmd, struct jobSet *junk);
101static int shell_source(struct job *cmd, struct jobSet *jobList); 101static int builtin_source(struct job *cmd, struct jobSet *jobList);
102static int shell_unset(struct job *cmd, struct jobSet *junk); 102static int builtin_unset(struct job *cmd, struct jobSet *junk);
103static int shell_read(struct job *cmd, struct jobSet *junk); 103static int builtin_read(struct job *cmd, struct jobSet *junk);
104 104
105
106/* function prototypes for shell stuff */
105static void checkJobs(struct jobSet *jobList); 107static void checkJobs(struct jobSet *jobList);
106static int getCommand(FILE * source, char *command); 108static int getCommand(FILE * source, char *command);
107static int parseCommand(char **commandPtr, struct job *job, int *isBg); 109static int parseCommand(char **commandPtr, struct job *job, int *isBg);
@@ -112,23 +114,23 @@ static int busy_loop(FILE * input);
112 114
113/* Table of built-in functions */ 115/* Table of built-in functions */
114static struct builtInCommand bltins[] = { 116static struct builtInCommand bltins[] = {
115 {"bg", "Resume a job in the background", "bg [%%job]", shell_fg_bg}, 117 {"bg", "Resume a job in the background", "bg [%%job]", builtin_fg_bg},
116 {"cd", "Change working directory", "cd [dir]", shell_cd}, 118 {"cd", "Change working directory", "cd [dir]", builtin_cd},
117 {"exit", "Exit from shell()", "exit", shell_exit}, 119 {"exit", "Exit from shell()", "exit", builtin_exit},
118 {"fg", "Bring job into the foreground", "fg [%%job]", shell_fg_bg}, 120 {"fg", "Bring job into the foreground", "fg [%%job]", builtin_fg_bg},
119 {"jobs", "Lists the active jobs", "jobs", shell_jobs}, 121 {"jobs", "Lists the active jobs", "jobs", builtin_jobs},
120 {"export", "Set environment variable", "export [VAR=value]", shell_export}, 122 {"export", "Set environment variable", "export [VAR=value]", builtin_export},
121 {"unset", "Unset environment variable", "unset VAR", shell_unset}, 123 {"unset", "Unset environment variable", "unset VAR", builtin_unset},
122 {"read", "Input environment variable", "read [VAR]", shell_read}, 124 {"read", "Input environment variable", "read [VAR]", builtin_read},
123 {NULL, NULL, NULL, NULL} 125 {NULL, NULL, NULL, NULL}
124}; 126};
125 127
126/* Table of built-in functions */ 128/* Table of built-in functions */
127static struct builtInCommand bltins_forking[] = { 129static struct builtInCommand bltins_forking[] = {
128 {"env", "Print all environment variables", "env", shell_env}, 130 {"env", "Print all environment variables", "env", builtin_env},
129 {"pwd", "Print current directory", "pwd", shell_pwd}, 131 {"pwd", "Print current directory", "pwd", builtin_pwd},
130 {".", "Source-in and run commands in a file", ". filename", shell_source}, 132 {".", "Source-in and run commands in a file", ". filename", builtin_source},
131 {"help", "List shell built-in commands", "help", shell_help}, 133 {"help", "List shell built-in commands", "help", builtin_help},
132 {NULL, NULL, NULL, NULL} 134 {NULL, NULL, NULL, NULL}
133}; 135};
134 136
@@ -157,7 +159,7 @@ void win_changed(int sig)
157 159
158 160
159/* built-in 'cd <path>' handler */ 161/* built-in 'cd <path>' handler */
160static int shell_cd(struct job *cmd, struct jobSet *junk) 162static int builtin_cd(struct job *cmd, struct jobSet *junk)
161{ 163{
162 char *newdir; 164 char *newdir;
163 165
@@ -175,7 +177,7 @@ static int shell_cd(struct job *cmd, struct jobSet *junk)
175} 177}
176 178
177/* built-in 'env' handler */ 179/* built-in 'env' handler */
178static int shell_env(struct job *dummy, struct jobSet *junk) 180static int builtin_env(struct job *dummy, struct jobSet *junk)
179{ 181{
180 char **e; 182 char **e;
181 183
@@ -186,7 +188,7 @@ static int shell_env(struct job *dummy, struct jobSet *junk)
186} 188}
187 189
188/* built-in 'exit' handler */ 190/* built-in 'exit' handler */
189static int shell_exit(struct job *cmd, struct jobSet *junk) 191static int builtin_exit(struct job *cmd, struct jobSet *junk)
190{ 192{
191 if (!cmd->progs[0].argv[1] == 1) 193 if (!cmd->progs[0].argv[1] == 1)
192 exit TRUE; 194 exit TRUE;
@@ -195,7 +197,7 @@ static int shell_exit(struct job *cmd, struct jobSet *junk)
195} 197}
196 198
197/* built-in 'fg' and 'bg' handler */ 199/* built-in 'fg' and 'bg' handler */
198static int shell_fg_bg(struct job *cmd, struct jobSet *jobList) 200static int builtin_fg_bg(struct job *cmd, struct jobSet *jobList)
199{ 201{
200 int i, jobNum; 202 int i, jobNum;
201 struct job *job=NULL; 203 struct job *job=NULL;
@@ -246,7 +248,7 @@ static int shell_fg_bg(struct job *cmd, struct jobSet *jobList)
246} 248}
247 249
248/* built-in 'help' handler */ 250/* built-in 'help' handler */
249static int shell_help(struct job *cmd, struct jobSet *junk) 251static int builtin_help(struct job *cmd, struct jobSet *junk)
250{ 252{
251 struct builtInCommand *x; 253 struct builtInCommand *x;
252 254
@@ -263,7 +265,7 @@ static int shell_help(struct job *cmd, struct jobSet *junk)
263} 265}
264 266
265/* built-in 'jobs' handler */ 267/* built-in 'jobs' handler */
266static int shell_jobs(struct job *dummy, struct jobSet *jobList) 268static int builtin_jobs(struct job *dummy, struct jobSet *jobList)
267{ 269{
268 struct job *job; 270 struct job *job;
269 char *statusString; 271 char *statusString;
@@ -281,7 +283,7 @@ static int shell_jobs(struct job *dummy, struct jobSet *jobList)
281 283
282 284
283/* built-in 'pwd' handler */ 285/* built-in 'pwd' handler */
284static int shell_pwd(struct job *dummy, struct jobSet *junk) 286static int builtin_pwd(struct job *dummy, struct jobSet *junk)
285{ 287{
286 getcwd(cwd, sizeof(cwd)); 288 getcwd(cwd, sizeof(cwd));
287 fprintf(stdout, "%s\n", cwd); 289 fprintf(stdout, "%s\n", cwd);
@@ -289,12 +291,12 @@ static int shell_pwd(struct job *dummy, struct jobSet *junk)
289} 291}
290 292
291/* built-in 'export VAR=value' handler */ 293/* built-in 'export VAR=value' handler */
292static int shell_export(struct job *cmd, struct jobSet *junk) 294static int builtin_export(struct job *cmd, struct jobSet *junk)
293{ 295{
294 int res; 296 int res;
295 297
296 if (!cmd->progs[0].argv[1] == 1) { 298 if (!cmd->progs[0].argv[1] == 1) {
297 return (shell_env(cmd, junk)); 299 return (builtin_env(cmd, junk));
298 } 300 }
299 res = putenv(cmd->progs[0].argv[1]); 301 res = putenv(cmd->progs[0].argv[1]);
300 if (res) 302 if (res)
@@ -303,7 +305,7 @@ static int shell_export(struct job *cmd, struct jobSet *junk)
303} 305}
304 306
305/* built-in 'read VAR' handler */ 307/* built-in 'read VAR' handler */
306static int shell_read(struct job *cmd, struct jobSet *junk) 308static int builtin_read(struct job *cmd, struct jobSet *junk)
307{ 309{
308 int res = 0, len, newlen; 310 int res = 0, len, newlen;
309 char *s; 311 char *s;
@@ -337,7 +339,7 @@ static int shell_read(struct job *cmd, struct jobSet *junk)
337} 339}
338 340
339/* Built-in '.' handler (read-in and execute commands from file) */ 341/* Built-in '.' handler (read-in and execute commands from file) */
340static int shell_source(struct job *cmd, struct jobSet *junk) 342static int builtin_source(struct job *cmd, struct jobSet *junk)
341{ 343{
342 FILE *input; 344 FILE *input;
343 int status; 345 int status;
@@ -358,7 +360,7 @@ static int shell_source(struct job *cmd, struct jobSet *junk)
358} 360}
359 361
360/* built-in 'unset VAR' handler */ 362/* built-in 'unset VAR' handler */
361static int shell_unset(struct job *cmd, struct jobSet *junk) 363static int builtin_unset(struct job *cmd, struct jobSet *junk)
362{ 364{
363 if (!cmd->progs[0].argv[1] == 1) { 365 if (!cmd->progs[0].argv[1] == 1) {
364 fprintf(stdout, "unset: parameter required.\n"); 366 fprintf(stdout, "unset: parameter required.\n");
@@ -803,7 +805,7 @@ static int runCommand(struct job newJob, struct jobSet *jobList, int inBg)
803 nextout = 1; 805 nextout = 1;
804 } 806 }
805 807
806 /* Match any built-ins here */ 808 /* Check if the command matches any non-forking builtins */
807 for (x = bltins; x->cmd; x++) { 809 for (x = bltins; x->cmd; x++) {
808 if (!strcmp(newJob.progs[i].argv[0], x->cmd)) { 810 if (!strcmp(newJob.progs[i].argv[0], x->cmd)) {
809 return (x->function(&newJob, jobList)); 811 return (x->function(&newJob, jobList));
@@ -826,14 +828,16 @@ static int runCommand(struct job newJob, struct jobSet *jobList, int inBg)
826 /* explicit redirections override pipes */ 828 /* explicit redirections override pipes */
827 setupRedirections(newJob.progs + i); 829 setupRedirections(newJob.progs + i);
828 830
829 /* Match any built-ins here */ 831 /* Check if the command matches any of the other builtins */
830 for (x = bltins_forking; x->cmd; x++) { 832 for (x = bltins_forking; x->cmd; x++) {
831 if (!strcmp(newJob.progs[i].argv[0], x->cmd)) { 833 if (!strcmp(newJob.progs[i].argv[0], x->cmd)) {
832 exit (x->function(&newJob, jobList)); 834 exit (x->function(&newJob, jobList));
833 } 835 }
834 } 836 }
835#ifdef BB_FEATURE_SH_STANDALONE_SHELL 837#ifdef BB_FEATURE_SH_STANDALONE_SHELL
836 /* Handle busybox internals here */ 838 /* Check if the command matches any busybox internal commands here */
839 /* TODO: Add matching when paths are appended (i.e. 'cat' currently
840 * works, but '/bin/cat' doesn't ) */
837 while (a->name != 0) { 841 while (a->name != 0) {
838 if (strcmp(newJob.progs[i].argv[0], a->name) == 0) { 842 if (strcmp(newJob.progs[i].argv[0], a->name) == 0) {
839 int argc; 843 int argc;
@@ -1050,7 +1054,7 @@ int shell_main(int argc, char **argv)
1050#endif 1054#endif
1051 1055
1052 //if (argv[0] && argv[0][0] == '-') { 1056 //if (argv[0] && argv[0][0] == '-') {
1053 // shell_source("/etc/profile"); 1057 // builtin_source("/etc/profile");
1054 //} 1058 //}
1055 1059
1056 if (argc < 2) { 1060 if (argc < 2) {
diff --git a/sh.c b/sh.c
index 7203ba38f..60d67e9e8 100644
--- a/sh.c
+++ b/sh.c
@@ -89,19 +89,21 @@ struct builtInCommand {
89 int (*function) (struct job *, struct jobSet * jobList); /* function ptr */ 89 int (*function) (struct job *, struct jobSet * jobList); /* function ptr */
90}; 90};
91 91
92/* Some function prototypes */ 92/* function prototypes for builtins */
93static int shell_cd(struct job *cmd, struct jobSet *junk); 93static int builtin_cd(struct job *cmd, struct jobSet *junk);
94static int shell_env(struct job *dummy, struct jobSet *junk); 94static int builtin_env(struct job *dummy, struct jobSet *junk);
95static int shell_exit(struct job *cmd, struct jobSet *junk); 95static int builtin_exit(struct job *cmd, struct jobSet *junk);
96static int shell_fg_bg(struct job *cmd, struct jobSet *jobList); 96static int builtin_fg_bg(struct job *cmd, struct jobSet *jobList);
97static int shell_help(struct job *cmd, struct jobSet *junk); 97static int builtin_help(struct job *cmd, struct jobSet *junk);
98static int shell_jobs(struct job *dummy, struct jobSet *jobList); 98static int builtin_jobs(struct job *dummy, struct jobSet *jobList);
99static int shell_pwd(struct job *dummy, struct jobSet *junk); 99static int builtin_pwd(struct job *dummy, struct jobSet *junk);
100static int shell_export(struct job *cmd, struct jobSet *junk); 100static int builtin_export(struct job *cmd, struct jobSet *junk);
101static int shell_source(struct job *cmd, struct jobSet *jobList); 101static int builtin_source(struct job *cmd, struct jobSet *jobList);
102static int shell_unset(struct job *cmd, struct jobSet *junk); 102static int builtin_unset(struct job *cmd, struct jobSet *junk);
103static int shell_read(struct job *cmd, struct jobSet *junk); 103static int builtin_read(struct job *cmd, struct jobSet *junk);
104 104
105
106/* function prototypes for shell stuff */
105static void checkJobs(struct jobSet *jobList); 107static void checkJobs(struct jobSet *jobList);
106static int getCommand(FILE * source, char *command); 108static int getCommand(FILE * source, char *command);
107static int parseCommand(char **commandPtr, struct job *job, int *isBg); 109static int parseCommand(char **commandPtr, struct job *job, int *isBg);
@@ -112,23 +114,23 @@ static int busy_loop(FILE * input);
112 114
113/* Table of built-in functions */ 115/* Table of built-in functions */
114static struct builtInCommand bltins[] = { 116static struct builtInCommand bltins[] = {
115 {"bg", "Resume a job in the background", "bg [%%job]", shell_fg_bg}, 117 {"bg", "Resume a job in the background", "bg [%%job]", builtin_fg_bg},
116 {"cd", "Change working directory", "cd [dir]", shell_cd}, 118 {"cd", "Change working directory", "cd [dir]", builtin_cd},
117 {"exit", "Exit from shell()", "exit", shell_exit}, 119 {"exit", "Exit from shell()", "exit", builtin_exit},
118 {"fg", "Bring job into the foreground", "fg [%%job]", shell_fg_bg}, 120 {"fg", "Bring job into the foreground", "fg [%%job]", builtin_fg_bg},
119 {"jobs", "Lists the active jobs", "jobs", shell_jobs}, 121 {"jobs", "Lists the active jobs", "jobs", builtin_jobs},
120 {"export", "Set environment variable", "export [VAR=value]", shell_export}, 122 {"export", "Set environment variable", "export [VAR=value]", builtin_export},
121 {"unset", "Unset environment variable", "unset VAR", shell_unset}, 123 {"unset", "Unset environment variable", "unset VAR", builtin_unset},
122 {"read", "Input environment variable", "read [VAR]", shell_read}, 124 {"read", "Input environment variable", "read [VAR]", builtin_read},
123 {NULL, NULL, NULL, NULL} 125 {NULL, NULL, NULL, NULL}
124}; 126};
125 127
126/* Table of built-in functions */ 128/* Table of built-in functions */
127static struct builtInCommand bltins_forking[] = { 129static struct builtInCommand bltins_forking[] = {
128 {"env", "Print all environment variables", "env", shell_env}, 130 {"env", "Print all environment variables", "env", builtin_env},
129 {"pwd", "Print current directory", "pwd", shell_pwd}, 131 {"pwd", "Print current directory", "pwd", builtin_pwd},
130 {".", "Source-in and run commands in a file", ". filename", shell_source}, 132 {".", "Source-in and run commands in a file", ". filename", builtin_source},
131 {"help", "List shell built-in commands", "help", shell_help}, 133 {"help", "List shell built-in commands", "help", builtin_help},
132 {NULL, NULL, NULL, NULL} 134 {NULL, NULL, NULL, NULL}
133}; 135};
134 136
@@ -157,7 +159,7 @@ void win_changed(int sig)
157 159
158 160
159/* built-in 'cd <path>' handler */ 161/* built-in 'cd <path>' handler */
160static int shell_cd(struct job *cmd, struct jobSet *junk) 162static int builtin_cd(struct job *cmd, struct jobSet *junk)
161{ 163{
162 char *newdir; 164 char *newdir;
163 165
@@ -175,7 +177,7 @@ static int shell_cd(struct job *cmd, struct jobSet *junk)
175} 177}
176 178
177/* built-in 'env' handler */ 179/* built-in 'env' handler */
178static int shell_env(struct job *dummy, struct jobSet *junk) 180static int builtin_env(struct job *dummy, struct jobSet *junk)
179{ 181{
180 char **e; 182 char **e;
181 183
@@ -186,7 +188,7 @@ static int shell_env(struct job *dummy, struct jobSet *junk)
186} 188}
187 189
188/* built-in 'exit' handler */ 190/* built-in 'exit' handler */
189static int shell_exit(struct job *cmd, struct jobSet *junk) 191static int builtin_exit(struct job *cmd, struct jobSet *junk)
190{ 192{
191 if (!cmd->progs[0].argv[1] == 1) 193 if (!cmd->progs[0].argv[1] == 1)
192 exit TRUE; 194 exit TRUE;
@@ -195,7 +197,7 @@ static int shell_exit(struct job *cmd, struct jobSet *junk)
195} 197}
196 198
197/* built-in 'fg' and 'bg' handler */ 199/* built-in 'fg' and 'bg' handler */
198static int shell_fg_bg(struct job *cmd, struct jobSet *jobList) 200static int builtin_fg_bg(struct job *cmd, struct jobSet *jobList)
199{ 201{
200 int i, jobNum; 202 int i, jobNum;
201 struct job *job=NULL; 203 struct job *job=NULL;
@@ -246,7 +248,7 @@ static int shell_fg_bg(struct job *cmd, struct jobSet *jobList)
246} 248}
247 249
248/* built-in 'help' handler */ 250/* built-in 'help' handler */
249static int shell_help(struct job *cmd, struct jobSet *junk) 251static int builtin_help(struct job *cmd, struct jobSet *junk)
250{ 252{
251 struct builtInCommand *x; 253 struct builtInCommand *x;
252 254
@@ -263,7 +265,7 @@ static int shell_help(struct job *cmd, struct jobSet *junk)
263} 265}
264 266
265/* built-in 'jobs' handler */ 267/* built-in 'jobs' handler */
266static int shell_jobs(struct job *dummy, struct jobSet *jobList) 268static int builtin_jobs(struct job *dummy, struct jobSet *jobList)
267{ 269{
268 struct job *job; 270 struct job *job;
269 char *statusString; 271 char *statusString;
@@ -281,7 +283,7 @@ static int shell_jobs(struct job *dummy, struct jobSet *jobList)
281 283
282 284
283/* built-in 'pwd' handler */ 285/* built-in 'pwd' handler */
284static int shell_pwd(struct job *dummy, struct jobSet *junk) 286static int builtin_pwd(struct job *dummy, struct jobSet *junk)
285{ 287{
286 getcwd(cwd, sizeof(cwd)); 288 getcwd(cwd, sizeof(cwd));
287 fprintf(stdout, "%s\n", cwd); 289 fprintf(stdout, "%s\n", cwd);
@@ -289,12 +291,12 @@ static int shell_pwd(struct job *dummy, struct jobSet *junk)
289} 291}
290 292
291/* built-in 'export VAR=value' handler */ 293/* built-in 'export VAR=value' handler */
292static int shell_export(struct job *cmd, struct jobSet *junk) 294static int builtin_export(struct job *cmd, struct jobSet *junk)
293{ 295{
294 int res; 296 int res;
295 297
296 if (!cmd->progs[0].argv[1] == 1) { 298 if (!cmd->progs[0].argv[1] == 1) {
297 return (shell_env(cmd, junk)); 299 return (builtin_env(cmd, junk));
298 } 300 }
299 res = putenv(cmd->progs[0].argv[1]); 301 res = putenv(cmd->progs[0].argv[1]);
300 if (res) 302 if (res)
@@ -303,7 +305,7 @@ static int shell_export(struct job *cmd, struct jobSet *junk)
303} 305}
304 306
305/* built-in 'read VAR' handler */ 307/* built-in 'read VAR' handler */
306static int shell_read(struct job *cmd, struct jobSet *junk) 308static int builtin_read(struct job *cmd, struct jobSet *junk)
307{ 309{
308 int res = 0, len, newlen; 310 int res = 0, len, newlen;
309 char *s; 311 char *s;
@@ -337,7 +339,7 @@ static int shell_read(struct job *cmd, struct jobSet *junk)
337} 339}
338 340
339/* Built-in '.' handler (read-in and execute commands from file) */ 341/* Built-in '.' handler (read-in and execute commands from file) */
340static int shell_source(struct job *cmd, struct jobSet *junk) 342static int builtin_source(struct job *cmd, struct jobSet *junk)
341{ 343{
342 FILE *input; 344 FILE *input;
343 int status; 345 int status;
@@ -358,7 +360,7 @@ static int shell_source(struct job *cmd, struct jobSet *junk)
358} 360}
359 361
360/* built-in 'unset VAR' handler */ 362/* built-in 'unset VAR' handler */
361static int shell_unset(struct job *cmd, struct jobSet *junk) 363static int builtin_unset(struct job *cmd, struct jobSet *junk)
362{ 364{
363 if (!cmd->progs[0].argv[1] == 1) { 365 if (!cmd->progs[0].argv[1] == 1) {
364 fprintf(stdout, "unset: parameter required.\n"); 366 fprintf(stdout, "unset: parameter required.\n");
@@ -803,7 +805,7 @@ static int runCommand(struct job newJob, struct jobSet *jobList, int inBg)
803 nextout = 1; 805 nextout = 1;
804 } 806 }
805 807
806 /* Match any built-ins here */ 808 /* Check if the command matches any non-forking builtins */
807 for (x = bltins; x->cmd; x++) { 809 for (x = bltins; x->cmd; x++) {
808 if (!strcmp(newJob.progs[i].argv[0], x->cmd)) { 810 if (!strcmp(newJob.progs[i].argv[0], x->cmd)) {
809 return (x->function(&newJob, jobList)); 811 return (x->function(&newJob, jobList));
@@ -826,14 +828,16 @@ static int runCommand(struct job newJob, struct jobSet *jobList, int inBg)
826 /* explicit redirections override pipes */ 828 /* explicit redirections override pipes */
827 setupRedirections(newJob.progs + i); 829 setupRedirections(newJob.progs + i);
828 830
829 /* Match any built-ins here */ 831 /* Check if the command matches any of the other builtins */
830 for (x = bltins_forking; x->cmd; x++) { 832 for (x = bltins_forking; x->cmd; x++) {
831 if (!strcmp(newJob.progs[i].argv[0], x->cmd)) { 833 if (!strcmp(newJob.progs[i].argv[0], x->cmd)) {
832 exit (x->function(&newJob, jobList)); 834 exit (x->function(&newJob, jobList));
833 } 835 }
834 } 836 }
835#ifdef BB_FEATURE_SH_STANDALONE_SHELL 837#ifdef BB_FEATURE_SH_STANDALONE_SHELL
836 /* Handle busybox internals here */ 838 /* Check if the command matches any busybox internal commands here */
839 /* TODO: Add matching when paths are appended (i.e. 'cat' currently
840 * works, but '/bin/cat' doesn't ) */
837 while (a->name != 0) { 841 while (a->name != 0) {
838 if (strcmp(newJob.progs[i].argv[0], a->name) == 0) { 842 if (strcmp(newJob.progs[i].argv[0], a->name) == 0) {
839 int argc; 843 int argc;
@@ -1050,7 +1054,7 @@ int shell_main(int argc, char **argv)
1050#endif 1054#endif
1051 1055
1052 //if (argv[0] && argv[0][0] == '-') { 1056 //if (argv[0] && argv[0][0] == '-') {
1053 // shell_source("/etc/profile"); 1057 // builtin_source("/etc/profile");
1054 //} 1058 //}
1055 1059
1056 if (argc < 2) { 1060 if (argc < 2) {
diff --git a/shell/lash.c b/shell/lash.c
index 7203ba38f..60d67e9e8 100644
--- a/shell/lash.c
+++ b/shell/lash.c
@@ -89,19 +89,21 @@ struct builtInCommand {
89 int (*function) (struct job *, struct jobSet * jobList); /* function ptr */ 89 int (*function) (struct job *, struct jobSet * jobList); /* function ptr */
90}; 90};
91 91
92/* Some function prototypes */ 92/* function prototypes for builtins */
93static int shell_cd(struct job *cmd, struct jobSet *junk); 93static int builtin_cd(struct job *cmd, struct jobSet *junk);
94static int shell_env(struct job *dummy, struct jobSet *junk); 94static int builtin_env(struct job *dummy, struct jobSet *junk);
95static int shell_exit(struct job *cmd, struct jobSet *junk); 95static int builtin_exit(struct job *cmd, struct jobSet *junk);
96static int shell_fg_bg(struct job *cmd, struct jobSet *jobList); 96static int builtin_fg_bg(struct job *cmd, struct jobSet *jobList);
97static int shell_help(struct job *cmd, struct jobSet *junk); 97static int builtin_help(struct job *cmd, struct jobSet *junk);
98static int shell_jobs(struct job *dummy, struct jobSet *jobList); 98static int builtin_jobs(struct job *dummy, struct jobSet *jobList);
99static int shell_pwd(struct job *dummy, struct jobSet *junk); 99static int builtin_pwd(struct job *dummy, struct jobSet *junk);
100static int shell_export(struct job *cmd, struct jobSet *junk); 100static int builtin_export(struct job *cmd, struct jobSet *junk);
101static int shell_source(struct job *cmd, struct jobSet *jobList); 101static int builtin_source(struct job *cmd, struct jobSet *jobList);
102static int shell_unset(struct job *cmd, struct jobSet *junk); 102static int builtin_unset(struct job *cmd, struct jobSet *junk);
103static int shell_read(struct job *cmd, struct jobSet *junk); 103static int builtin_read(struct job *cmd, struct jobSet *junk);
104 104
105
106/* function prototypes for shell stuff */
105static void checkJobs(struct jobSet *jobList); 107static void checkJobs(struct jobSet *jobList);
106static int getCommand(FILE * source, char *command); 108static int getCommand(FILE * source, char *command);
107static int parseCommand(char **commandPtr, struct job *job, int *isBg); 109static int parseCommand(char **commandPtr, struct job *job, int *isBg);
@@ -112,23 +114,23 @@ static int busy_loop(FILE * input);
112 114
113/* Table of built-in functions */ 115/* Table of built-in functions */
114static struct builtInCommand bltins[] = { 116static struct builtInCommand bltins[] = {
115 {"bg", "Resume a job in the background", "bg [%%job]", shell_fg_bg}, 117 {"bg", "Resume a job in the background", "bg [%%job]", builtin_fg_bg},
116 {"cd", "Change working directory", "cd [dir]", shell_cd}, 118 {"cd", "Change working directory", "cd [dir]", builtin_cd},
117 {"exit", "Exit from shell()", "exit", shell_exit}, 119 {"exit", "Exit from shell()", "exit", builtin_exit},
118 {"fg", "Bring job into the foreground", "fg [%%job]", shell_fg_bg}, 120 {"fg", "Bring job into the foreground", "fg [%%job]", builtin_fg_bg},
119 {"jobs", "Lists the active jobs", "jobs", shell_jobs}, 121 {"jobs", "Lists the active jobs", "jobs", builtin_jobs},
120 {"export", "Set environment variable", "export [VAR=value]", shell_export}, 122 {"export", "Set environment variable", "export [VAR=value]", builtin_export},
121 {"unset", "Unset environment variable", "unset VAR", shell_unset}, 123 {"unset", "Unset environment variable", "unset VAR", builtin_unset},
122 {"read", "Input environment variable", "read [VAR]", shell_read}, 124 {"read", "Input environment variable", "read [VAR]", builtin_read},
123 {NULL, NULL, NULL, NULL} 125 {NULL, NULL, NULL, NULL}
124}; 126};
125 127
126/* Table of built-in functions */ 128/* Table of built-in functions */
127static struct builtInCommand bltins_forking[] = { 129static struct builtInCommand bltins_forking[] = {
128 {"env", "Print all environment variables", "env", shell_env}, 130 {"env", "Print all environment variables", "env", builtin_env},
129 {"pwd", "Print current directory", "pwd", shell_pwd}, 131 {"pwd", "Print current directory", "pwd", builtin_pwd},
130 {".", "Source-in and run commands in a file", ". filename", shell_source}, 132 {".", "Source-in and run commands in a file", ". filename", builtin_source},
131 {"help", "List shell built-in commands", "help", shell_help}, 133 {"help", "List shell built-in commands", "help", builtin_help},
132 {NULL, NULL, NULL, NULL} 134 {NULL, NULL, NULL, NULL}
133}; 135};
134 136
@@ -157,7 +159,7 @@ void win_changed(int sig)
157 159
158 160
159/* built-in 'cd <path>' handler */ 161/* built-in 'cd <path>' handler */
160static int shell_cd(struct job *cmd, struct jobSet *junk) 162static int builtin_cd(struct job *cmd, struct jobSet *junk)
161{ 163{
162 char *newdir; 164 char *newdir;
163 165
@@ -175,7 +177,7 @@ static int shell_cd(struct job *cmd, struct jobSet *junk)
175} 177}
176 178
177/* built-in 'env' handler */ 179/* built-in 'env' handler */
178static int shell_env(struct job *dummy, struct jobSet *junk) 180static int builtin_env(struct job *dummy, struct jobSet *junk)
179{ 181{
180 char **e; 182 char **e;
181 183
@@ -186,7 +188,7 @@ static int shell_env(struct job *dummy, struct jobSet *junk)
186} 188}
187 189
188/* built-in 'exit' handler */ 190/* built-in 'exit' handler */
189static int shell_exit(struct job *cmd, struct jobSet *junk) 191static int builtin_exit(struct job *cmd, struct jobSet *junk)
190{ 192{
191 if (!cmd->progs[0].argv[1] == 1) 193 if (!cmd->progs[0].argv[1] == 1)
192 exit TRUE; 194 exit TRUE;
@@ -195,7 +197,7 @@ static int shell_exit(struct job *cmd, struct jobSet *junk)
195} 197}
196 198
197/* built-in 'fg' and 'bg' handler */ 199/* built-in 'fg' and 'bg' handler */
198static int shell_fg_bg(struct job *cmd, struct jobSet *jobList) 200static int builtin_fg_bg(struct job *cmd, struct jobSet *jobList)
199{ 201{
200 int i, jobNum; 202 int i, jobNum;
201 struct job *job=NULL; 203 struct job *job=NULL;
@@ -246,7 +248,7 @@ static int shell_fg_bg(struct job *cmd, struct jobSet *jobList)
246} 248}
247 249
248/* built-in 'help' handler */ 250/* built-in 'help' handler */
249static int shell_help(struct job *cmd, struct jobSet *junk) 251static int builtin_help(struct job *cmd, struct jobSet *junk)
250{ 252{
251 struct builtInCommand *x; 253 struct builtInCommand *x;
252 254
@@ -263,7 +265,7 @@ static int shell_help(struct job *cmd, struct jobSet *junk)
263} 265}
264 266
265/* built-in 'jobs' handler */ 267/* built-in 'jobs' handler */
266static int shell_jobs(struct job *dummy, struct jobSet *jobList) 268static int builtin_jobs(struct job *dummy, struct jobSet *jobList)
267{ 269{
268 struct job *job; 270 struct job *job;
269 char *statusString; 271 char *statusString;
@@ -281,7 +283,7 @@ static int shell_jobs(struct job *dummy, struct jobSet *jobList)
281 283
282 284
283/* built-in 'pwd' handler */ 285/* built-in 'pwd' handler */
284static int shell_pwd(struct job *dummy, struct jobSet *junk) 286static int builtin_pwd(struct job *dummy, struct jobSet *junk)
285{ 287{
286 getcwd(cwd, sizeof(cwd)); 288 getcwd(cwd, sizeof(cwd));
287 fprintf(stdout, "%s\n", cwd); 289 fprintf(stdout, "%s\n", cwd);
@@ -289,12 +291,12 @@ static int shell_pwd(struct job *dummy, struct jobSet *junk)
289} 291}
290 292
291/* built-in 'export VAR=value' handler */ 293/* built-in 'export VAR=value' handler */
292static int shell_export(struct job *cmd, struct jobSet *junk) 294static int builtin_export(struct job *cmd, struct jobSet *junk)
293{ 295{
294 int res; 296 int res;
295 297
296 if (!cmd->progs[0].argv[1] == 1) { 298 if (!cmd->progs[0].argv[1] == 1) {
297 return (shell_env(cmd, junk)); 299 return (builtin_env(cmd, junk));
298 } 300 }
299 res = putenv(cmd->progs[0].argv[1]); 301 res = putenv(cmd->progs[0].argv[1]);
300 if (res) 302 if (res)
@@ -303,7 +305,7 @@ static int shell_export(struct job *cmd, struct jobSet *junk)
303} 305}
304 306
305/* built-in 'read VAR' handler */ 307/* built-in 'read VAR' handler */
306static int shell_read(struct job *cmd, struct jobSet *junk) 308static int builtin_read(struct job *cmd, struct jobSet *junk)
307{ 309{
308 int res = 0, len, newlen; 310 int res = 0, len, newlen;
309 char *s; 311 char *s;
@@ -337,7 +339,7 @@ static int shell_read(struct job *cmd, struct jobSet *junk)
337} 339}
338 340
339/* Built-in '.' handler (read-in and execute commands from file) */ 341/* Built-in '.' handler (read-in and execute commands from file) */
340static int shell_source(struct job *cmd, struct jobSet *junk) 342static int builtin_source(struct job *cmd, struct jobSet *junk)
341{ 343{
342 FILE *input; 344 FILE *input;
343 int status; 345 int status;
@@ -358,7 +360,7 @@ static int shell_source(struct job *cmd, struct jobSet *junk)
358} 360}
359 361
360/* built-in 'unset VAR' handler */ 362/* built-in 'unset VAR' handler */
361static int shell_unset(struct job *cmd, struct jobSet *junk) 363static int builtin_unset(struct job *cmd, struct jobSet *junk)
362{ 364{
363 if (!cmd->progs[0].argv[1] == 1) { 365 if (!cmd->progs[0].argv[1] == 1) {
364 fprintf(stdout, "unset: parameter required.\n"); 366 fprintf(stdout, "unset: parameter required.\n");
@@ -803,7 +805,7 @@ static int runCommand(struct job newJob, struct jobSet *jobList, int inBg)
803 nextout = 1; 805 nextout = 1;
804 } 806 }
805 807
806 /* Match any built-ins here */ 808 /* Check if the command matches any non-forking builtins */
807 for (x = bltins; x->cmd; x++) { 809 for (x = bltins; x->cmd; x++) {
808 if (!strcmp(newJob.progs[i].argv[0], x->cmd)) { 810 if (!strcmp(newJob.progs[i].argv[0], x->cmd)) {
809 return (x->function(&newJob, jobList)); 811 return (x->function(&newJob, jobList));
@@ -826,14 +828,16 @@ static int runCommand(struct job newJob, struct jobSet *jobList, int inBg)
826 /* explicit redirections override pipes */ 828 /* explicit redirections override pipes */
827 setupRedirections(newJob.progs + i); 829 setupRedirections(newJob.progs + i);
828 830
829 /* Match any built-ins here */ 831 /* Check if the command matches any of the other builtins */
830 for (x = bltins_forking; x->cmd; x++) { 832 for (x = bltins_forking; x->cmd; x++) {
831 if (!strcmp(newJob.progs[i].argv[0], x->cmd)) { 833 if (!strcmp(newJob.progs[i].argv[0], x->cmd)) {
832 exit (x->function(&newJob, jobList)); 834 exit (x->function(&newJob, jobList));
833 } 835 }
834 } 836 }
835#ifdef BB_FEATURE_SH_STANDALONE_SHELL 837#ifdef BB_FEATURE_SH_STANDALONE_SHELL
836 /* Handle busybox internals here */ 838 /* Check if the command matches any busybox internal commands here */
839 /* TODO: Add matching when paths are appended (i.e. 'cat' currently
840 * works, but '/bin/cat' doesn't ) */
837 while (a->name != 0) { 841 while (a->name != 0) {
838 if (strcmp(newJob.progs[i].argv[0], a->name) == 0) { 842 if (strcmp(newJob.progs[i].argv[0], a->name) == 0) {
839 int argc; 843 int argc;
@@ -1050,7 +1054,7 @@ int shell_main(int argc, char **argv)
1050#endif 1054#endif
1051 1055
1052 //if (argv[0] && argv[0][0] == '-') { 1056 //if (argv[0] && argv[0][0] == '-') {
1053 // shell_source("/etc/profile"); 1057 // builtin_source("/etc/profile");
1054 //} 1058 //}
1055 1059
1056 if (argc < 2) { 1060 if (argc < 2) {