diff options
author | jkh <jkh@FreeBSD.org> | 1997-01-16 10:24:09 +0000 |
---|---|---|
committer | jkh <jkh@FreeBSD.org> | 1997-01-16 10:24:09 +0000 |
commit | b5a526ab91ac8dc6d5b040394aa64dfa85a3a940 (patch) | |
tree | a8aea9644ebcfb3ee879869a388959c83e0bee35 /release/sysinstall/dispatch.c | |
parent | 4a4bd14c4c5a8bd3eadd89f2fefc58ca8315b44d (diff) | |
download | FreeBSD-src-b5a526ab91ac8dc6d5b040394aa64dfa85a3a940.zip FreeBSD-src-b5a526ab91ac8dc6d5b040394aa64dfa85a3a940.tar.gz |
Clean up a long-standing bug in the scripting code. You could set variables,
but you couldn't call functions! Now you can do both.
Guard against whitespace pollution in variable names.
Diffstat (limited to 'release/sysinstall/dispatch.c')
-rw-r--r-- | release/sysinstall/dispatch.c | 28 |
1 files changed, 22 insertions, 6 deletions
diff --git a/release/sysinstall/dispatch.c b/release/sysinstall/dispatch.c index a41a724..75f1a52 100644 --- a/release/sysinstall/dispatch.c +++ b/release/sysinstall/dispatch.c @@ -37,6 +37,8 @@ #include "sysinstall.h" #include <ctype.h> +static int _shutdown(dialogMenuItem *unused); + static struct _word { char *name; int (*handler)(dialogMenuItem *self); @@ -85,6 +87,7 @@ static struct _word { { "optionsEditor", optionsEditor }, { "addGroup", userAddGroup }, { "addUser", userAddUser }, + { "shutdown", _shutdown }, { NULL, NULL }, }; @@ -104,6 +107,13 @@ call_possible_resword(char *name, dialogMenuItem *value, int *status) return rval; } +/* Just convenience */ +static int _shutdown(dialogMenuItem *unused) +{ + systemShutdown(0); + return DITEM_FAILURE; +} + /* For a given string, call it or spit out an undefined command diagnostic */ int dispatchCommand(char *str) @@ -115,16 +125,22 @@ dispatchCommand(char *str) msgConfirm("Null or zero-length string passed to dispatchCommand"); return DITEM_FAILURE; } + /* If it's got a newline, trim it */ + if ((cp = index(str, '\n')) != NULL) + *cp = '\0'; + /* A command might be a pathname if it's encoded in argv[0], as we also support */ if (index(str, '=')) { variable_set(str); - return DITEM_SUCCESS; + i = DITEM_SUCCESS; } - else if ((cp = index(str, '/')) != NULL) - str = cp + 1; - if (!call_possible_resword(str, NULL, &i)) { - msgConfirm("No such command: %s", str); - return DITEM_FAILURE; + else { + if ((cp = index(str, '/')) != NULL) + str = cp + 1; + if (!call_possible_resword(str, NULL, &i)) { + msgConfirm("No such command: %s", str); + i = DITEM_FAILURE; + } } return i; } |