dispatch.c revision 26572
1/*
2 * The new sysinstall program.
3 *
4 * This is probably the last program in the `sysinstall' line - the next
5 * generation being essentially a complete rewrite.
6 *
7 * $Id: dispatch.c,v 1.14 1997/06/05 09:47:56 jkh Exp $
8 *
9 * Copyright (c) 1995
10 *	Jordan Hubbard.  All rights reserved.
11 *
12 * Redistribution and use in source and binary forms, with or without
13 * modification, are permitted provided that the following conditions
14 * are met:
15 * 1. Redistributions of source code must retain the above copyright
16 *    notice, this list of conditions and the following disclaimer,
17 *    verbatim and that no modifications are made prior to this
18 *    point in the file.
19 * 2. Redistributions in binary form must reproduce the above copyright
20 *    notice, this list of conditions and the following disclaimer in the
21 *    documentation and/or other materials provided with the distribution.
22 *
23 * THIS SOFTWARE IS PROVIDED BY JORDAN HUBBARD ``AS IS'' AND
24 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
25 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
26 * ARE DISCLAIMED.  IN NO EVENT SHALL JORDAN HUBBARD OR HIS PETS BE LIABLE
27 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
28 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
29 * OR SERVICES; LOSS OF USE, DATA, LIFE OR PROFITS; OR BUSINESS INTERRUPTION)
30 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
31 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
32 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
33 * SUCH DAMAGE.
34 *
35 */
36
37#include "sysinstall.h"
38#include <ctype.h>
39
40static int _shutdown(dialogMenuItem *unused);
41
42static struct _word {
43    char *name;
44    int (*handler)(dialogMenuItem *self);
45} resWords[] = {
46    { "configAnonFTP",		configAnonFTP		},
47    { "configRouter",		configRouter		},
48    { "configNFSServer",	configNFSServer		},
49    { "configSamba",		configSamba		},
50    { "configNTP",		configNTP		},
51    { "configPCNFSD",		configPCNFSD		},
52    { "configNFSServer",	configNFSServer		},
53    { "configPackages",		configPackages		},
54    { "configRegister",		configRegister		},
55    { "configRouter",		configRouter		},
56    { "configUsers",		configUsers		},
57    { "configXFree86",		configXFree86		},
58    { "diskPartitionEditor",	diskPartitionEditor	},
59    { "diskPartitionWrite",	diskPartitionWrite	},
60    { "diskLabelEditor",	diskLabelEditor		},
61    { "diskLabelCommit",	diskLabelCommit		},
62    { "distReset",		distReset		},
63    { "distSetCustom",		distSetDeveloper	},
64    { "distSetDeveloper",	distSetDeveloper	},
65    { "distSetXDeveloper",	distSetXDeveloper	},
66    { "distSetKernDeveloper",	distSetKernDeveloper	},
67    { "distSetUser",		distSetUser		},
68    { "distSetXUser",		distSetXUser		},
69    { "distSetMinimum",		distSetMinimum		},
70    { "distSetEverything",	distSetEverything	},
71    { "distSetDES",		distSetDES		},
72    { "distSetSrc",		distSetSrc		},
73    { "distSetXF86",		distSetXF86		},
74    { "distExtractAll",		distExtractAll		},
75    { "docBrowser",		docBrowser		},
76    { "docShowDocument",	docShowDocument		},
77    { "installCommit",		installCommit		},
78    { "installExpress",		installExpress		},
79    { "installNovice",		installNovice		},
80    { "installUpgrade",		installUpgrade		},
81    { "installFixup",		installFixup		},
82    { "installFixitHoloShell",	installFixitHoloShell	},
83    { "installFixitCDROM",	installFixitCDROM	},
84    { "installFixitFloppy",	installFixitFloppy	},
85    { "installFilesystems",	installFilesystems	},
86    { "installVarDefaults",	installVarDefaults	},
87    { "mediaSetCDROM",		mediaSetCDROM		},
88    { "mediaSetFloppy",		mediaSetFloppy		},
89    { "mediaSetDOS",		mediaSetDOS		},
90    { "mediaSetTape",		mediaSetTape		},
91    { "mediaSetFTP",		mediaSetFTP		},
92    { "mediaSetFTPActive",	mediaSetFTPActive	},
93    { "mediaSetFTPPassive",	mediaSetFTPPassive	},
94    { "mediaSetUFS",		mediaSetUFS		},
95    { "mediaSetNFS",		mediaSetNFS		},
96    { "mediaSetFTPUserPass",	mediaSetFTPUserPass	},
97    { "mediaSetCPIOVerbosity",	mediaSetCPIOVerbosity	},
98    { "mediaGetType",		mediaGetType		},
99    { "optionsEditor",		optionsEditor		},
100    { "register",		configRegister		},	/* Alias */
101    { "addGroup",		userAddGroup		},
102    { "addUser",		userAddUser		},
103    { "shutdown",		_shutdown 		},
104    { NULL, NULL },
105};
106
107static int
108call_possible_resword(char *name, dialogMenuItem *value, int *status)
109{
110    int i, rval;
111
112    rval = 0;
113    for (i = 0; resWords[i].name; i++) {
114	if (!strcmp(name, resWords[i].name)) {
115	    *status = resWords[i].handler(value);
116	    rval = 1;
117	    break;
118	}
119    }
120    return rval;
121}
122
123/* Just convenience */
124static int _shutdown(dialogMenuItem *unused)
125{
126    systemShutdown(0);
127    return DITEM_FAILURE;
128}
129
130/* For a given string, call it or spit out an undefined command diagnostic */
131int
132dispatchCommand(char *str)
133{
134    int i;
135    char *cp;
136
137    if (!str || !*str) {
138	msgConfirm("Null or zero-length string passed to dispatchCommand");
139	return DITEM_FAILURE;
140    }
141    /* If it's got a newline, trim it */
142    if ((cp = index(str, '\n')) != NULL)
143	*cp = '\0';
144
145    /* If it's got a `=' sign in there, assume it's a variable setting */
146    if (index(str, '=')) {
147	if (isDebug())
148	    msgDebug("dispatch: setting variable `%s'\n", str);
149	variable_set(str);
150	i = DITEM_SUCCESS;
151    }
152    else {
153	/* A command might be a pathname if it's encoded in argv[0], which we also support */
154	if ((cp = rindex(str, '/')) != NULL)
155	    str = cp + 1;
156	if (isDebug())
157	    msgDebug("dispatch: calling resword `%s'\n", str);
158	if (!call_possible_resword(str, NULL, &i)) {
159	    msgNotify("Warning: No such command ``%s''", str);
160	    i = DITEM_FAILURE;
161	}
162    }
163    return i;
164}
165