comparison main.c @ 3:266a462ed18c

Next drop of toysh, plus more infratructure.
author landley@driftwood
date Wed, 18 Oct 2006 18:38:16 -0400
parents 67b517913e56
children fc9c0503d5e2
comparison
equal deleted inserted replaced
2:67b517913e56 3:266a462ed18c
15 {"toybox", toybox_main, 0}, 15 {"toybox", toybox_main, 0},
16 // The rest of these are alphabetical, for binary search. 16 // The rest of these are alphabetical, for binary search.
17 {"cd", cd_main, TOYFLAG_NOFORK}, 17 {"cd", cd_main, TOYFLAG_NOFORK},
18 {"df", df_main, TOYFLAG_USR|TOYFLAG_SBIN}, 18 {"df", df_main, TOYFLAG_USR|TOYFLAG_SBIN},
19 {"exit", exit_main, TOYFLAG_NOFORK}, 19 {"exit", exit_main, TOYFLAG_NOFORK},
20 {"sh", toysh_main, TOYFLAG_BIN},
20 {"toysh", toysh_main, TOYFLAG_BIN} 21 {"toysh", toysh_main, TOYFLAG_BIN}
21 }; 22 };
22 23
23 #define TOY_LIST_LEN (sizeof(toy_list)/sizeof(struct toy_list)) 24 #define TOY_LIST_LEN (sizeof(toy_list)/sizeof(struct toy_list))
24 25
49 if (result<0) top=--middle; 50 if (result<0) top=--middle;
50 else bottom = ++middle; 51 else bottom = ++middle;
51 } 52 }
52 } 53 }
53 54
55 void toy_init(struct toy_list *which, char *argv[])
56 {
57 // Free old toys contents here?
58
59 toys.which = which;
60 toys.argv = argv;
61 for (toys.argc = 0; argv[toys.argc]; toys.argc++);
62 toys.exitval = 1;
63 }
64
54 // Run a toy. 65 // Run a toy.
55 void toy_exec(char *argv[]) 66 void toy_exec(char *argv[])
56 { 67 {
57 struct toy_list *which; 68 struct toy_list *which;
58 69
59 which = toy_find(argv[0]); 70 which = toy_find(argv[0]);
60 if (!which) return; 71 if (!which) return;
61 72
62 // Free old toys contents here? 73 toy_init(which, argv);
63
64 toys.which = which;
65 toys.argv = argv;
66 for (toys.argc = 0; argv[toys.argc]; toys.argc++);
67 toys.exitval = 1;
68 74
69 exit(toys.which->toy_main()); 75 exit(toys.which->toy_main());
70 } 76 }
71 77
72 int toybox_main(void) 78 int toybox_main(void)