diff options
author | Rob Landley <rob@landley.net> | 2007-10-19 19:12:48 -0500 |
---|---|---|
committer | Rob Landley <rob@landley.net> | 2007-10-19 19:12:48 -0500 |
commit | 503d0f5b52fe2eafd6523ce785d6c9f73b46329b (patch) | |
tree | 56cb31659ccba53ebb86f55d96c47e361bd1c043 | |
parent | 9abf13622b76eec96f5846298bbf012cdb8bc678 (diff) | |
download | toybox-503d0f5b52fe2eafd6523ce785d6c9f73b46329b.tar.gz |
Get toysh.c to start using the option parsing logic, and some minor cleanup.
-rw-r--r-- | toys/toylist.h | 11 | ||||
-rw-r--r-- | toys/toysh.c | 10 |
2 files changed, 15 insertions, 6 deletions
diff --git a/toys/toylist.h b/toys/toylist.h index deeb6204..3c3b316a 100644 --- a/toys/toylist.h +++ b/toys/toylist.h @@ -18,6 +18,9 @@ struct df_data { long units; }; +// Still to go: "E:jJ:L:m:O:" +#define MKE2FS_OPTSTRING "<1>2g:Fnqm#N#i#b#" + struct mke2fs_data { // Command line arguments. long blocksize; @@ -55,12 +58,16 @@ struct touch_data { long length; }; -// "E:jJ:L:m:O:" -#define MKE2FS_OPTSTRING "<1>2Fnqm#N#i#b#" +struct toysh_data { + char *command; +}; extern union toy_union { struct df_data df; struct mke2fs_data mke2fs; + struct sleep_data sleep; + struct touch_data touch; + struct toysh_data toysh; } toy; #define TOYFLAG_USR (1<<0) diff --git a/toys/toysh.c b/toys/toysh.c index a42d361a..f7d86ab9 100644 --- a/toys/toysh.c +++ b/toys/toysh.c @@ -14,6 +14,8 @@ #include "toys.h" +#define TT toy.toysh + // A single executable, its arguments, and other information we know about it. #define TOYSH_FLAG_EXIT 1 #define TOYSH_FLAG_SUSPEND 2 @@ -196,7 +198,6 @@ int exit_main(void) int toysh_main(void) { - char *command=NULL; FILE *f; // Set up signal handlers and grab control of this tty. @@ -204,15 +205,16 @@ int toysh_main(void) if (isatty(0)) toys.optflags |= 1; } f = *toys.optargs ? xfopen(*toys.optargs, "r") : NULL; - if (command) handle(command); + if (TT.command) handle(TT.command); else { - unsigned cmdlen=0; + unsigned cmdlen = 0; for (;;) { + char *command = 0; if (!f) putchar('$'); if (1 > getline(&command, &cmdlen, f ? : stdin)) break; handle(command); + free(command); } - if (CFG_TOYBOX_FREE) free(command); } return 1; |