5 * Jordan Hubbard. All rights reserved.
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
10 * 1. Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer,
12 * verbatim and that no modifications are made prior to this
14 * 2. Redistributions in binary form must reproduce the above copyright
15 * notice, this list of conditions and the following disclaimer in the
16 * documentation and/or other materials provided with the distribution.
18 * THIS SOFTWARE IS PROVIDED BY JORDAN HUBBARD ``AS IS'' AND
19 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
20 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
21 * ARE DISCLAIMED. IN NO EVENT SHALL JORDAN HUBBARD OR HIS PETS BE LIABLE
22 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
23 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
24 * OR SERVICES; LOSS OF USE, DATA, LIFE OR PROFITS; OR BUSINESS INTERRUPTION)
25 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
26 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
27 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
35 #include <sys/signal.h>
36 #include <sys/fcntl.h>
40 static int dispatch_systemExecute(dialogMenuItem *unused);
41 static int dispatch_msgConfirm(dialogMenuItem *unused);
45 int (*handler)(dialogMenuItem *self);
48 { "diskPartitionEditor", diskPartitionEditor },
50 { "diskPartitionWrite", diskPartitionWrite },
51 { "diskLabelEditor", diskLabelEditor },
52 { "diskLabelCommit", diskLabelCommit },
53 { "msgConfirm", dispatch_msgConfirm },
54 { "system", dispatch_systemExecute },
55 { "dumpVariables", dump_variables },
60 * Helper routines for buffering data.
62 * We read an entire configuration into memory before executing it
63 * so that we are truely standalone and can do things like nuke the
64 * file or disk we're working on.
67 typedef struct command_buffer_ {
77 dispatch_systemExecute(dialogMenuItem *unused)
79 char *cmd = variable_get(VAR_COMMAND);
82 return systemExecute(cmd) ? DITEM_FAILURE : DITEM_SUCCESS;
84 msgDebug("_systemExecute: No command passed in `command' variable.\n");
89 dispatch_msgConfirm(dialogMenuItem *unused)
91 char *msg = variable_get(VAR_COMMAND);
94 msgConfirm("%s", msg);
98 msgDebug("_msgConfirm: No message passed in `command' variable.\n");
103 call_possible_resword(char *name, dialogMenuItem *value, int *status)
108 for (i = 0; resWords[i].name; i++) {
109 if (!strcmp(name, resWords[i].name)) {
110 *status = resWords[i].handler(value);
118 /* For a given string, call it or spit out an undefined command diagnostic */
120 dispatchCommand(char *str)
126 msgConfirm("Null or zero-length string passed to dispatchCommand");
127 return DITEM_FAILURE;
129 /* If it's got a newline, trim it */
130 if ((cp = index(str, '\n')) != NULL)
133 /* If it's got a `=' sign in there, assume it's a variable setting */
134 if (index(str, '=')) {
136 msgDebug("dispatch: setting variable `%s'\n", str);
137 variable_set(str, 0);
141 /* A command might be a pathname if it's encoded in argv[0], which
143 if ((cp = rindex(str, '/')) != NULL)
146 msgDebug("dispatch: calling resword `%s'\n", str);
147 if (!call_possible_resword(str, NULL, &i)) {
148 msgNotify("Warning: No such command ``%s''", str);
152 * Allow a user to prefix a command with "noError" to cause
153 * us to ignore any errors for that one command.
155 if (i != DITEM_SUCCESS && variable_get(VAR_NO_ERROR))
157 variable_unset(VAR_NO_ERROR);