aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRob Landley <rob@landley.net>2007-06-01 13:41:24 -0400
committerRob Landley <rob@landley.net>2007-06-01 13:41:24 -0400
commitb841cd2f8c1b378c1e8d73f5915662b8e79aac80 (patch)
treeaac4b1a71e3aa7614ce5b9e4c94bf415fbf91053
parent9fdf465b913ee35a17cf8d9758292afb0cac8a9f (diff)
downloadtoybox-b841cd2f8c1b378c1e8d73f5915662b8e79aac80.tar.gz
Allow applets with optarg string NULL to use toy.optargs[].
-rw-r--r--main.c5
-rw-r--r--toys/toysh.c6
2 files changed, 6 insertions, 5 deletions
diff --git a/main.c b/main.c
index 56d6eb37..3a50f395 100644
--- a/main.c
+++ b/main.c
@@ -58,18 +58,19 @@ void toy_init(struct toy_list *which, char *argv[])
toys.argv = argv;
toys.exitval = 1;
if (which->options) get_optflags();
+ else toys.optargs = argv+1;
}
// Run a toy.
void toy_exec(char *argv[])
{
struct toy_list *which;
-
+
which = toy_find(argv[0]);
if (!which) return;
toy_init(which, argv);
-
+
exit(toys.which->toy_main());
}
diff --git a/toys/toysh.c b/toys/toysh.c
index ef061bde..a42d361a 100644
--- a/toys/toysh.c
+++ b/toys/toysh.c
@@ -184,14 +184,14 @@ static void handle(char *command)
int cd_main(void)
{
- char *dest = toys.argv[1] ? toys.argv[1]: getenv("HOME");
+ char *dest = *toys.optargs ? *toys.optargs : getenv("HOME");
if (chdir(dest)) error_exit("chdir %s",dest);
return 0;
}
int exit_main(void)
{
- exit(toys.argv[1] ? atoi(toys.argv[1]) : 0);
+ exit(*toys.optargs ? atoi(*toys.optargs) : 0);
}
int toysh_main(void)
@@ -203,7 +203,7 @@ int toysh_main(void)
if (CFG_TOYSH_TTY) {
if (isatty(0)) toys.optflags |= 1;
}
- f = toys.argv[1] ? xfopen(toys.argv[1], "r") : NULL;
+ f = *toys.optargs ? xfopen(*toys.optargs, "r") : NULL;
if (command) handle(command);
else {
unsigned cmdlen=0;