dispatch.c revision 21764
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 * $FreeBSD: head/usr.sbin/sade/dispatch.c 21764 1997-01-16 10:24:09Z jkh $
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    { "configApache",		configApache		},
48    { "configRouter",		configRouter		},
49    { "configNFSServer",	configNFSServer		},
50    { "configSamba",		configSamba		},
51    { "configPackages",		configPackages		},
52    { "diskPartitionEditor",	diskPartitionEditor	},
53    { "diskPartitionWrite",	diskPartitionWrite	},
54    { "diskLabelEditor",	diskLabelEditor		},
55    { "diskLabelCommit",	diskLabelCommit		},
56    { "distReset",		distReset		},
57    { "distSetDeveloper",	distSetDeveloper	},
58    { "distSetXDeveloper",	distSetXDeveloper	},
59    { "distSetKernDeveloper",	distSetKernDeveloper	},
60    { "distSetUser",		distSetUser		},
61    { "distSetXUser",		distSetXUser		},
62    { "distSetMinimum",		distSetMinimum		},
63    { "distSetEverything",	distSetEverything	},
64    { "distSetDES",		distSetDES		},
65    { "distSetSrc",		distSetSrc		},
66    { "distSetXF86",		distSetXF86		},
67    { "distExtractAll",		distExtractAll		},
68    { "docBrowser",		docBrowser		},
69    { "docShowDocument",	docShowDocument		},
70    { "installCommit",		installCommit		},
71    { "installExpress",		installExpress		},
72    { "installUpgrade",		installUpgrade		},
73    { "installFixup",		installFixup		},
74    { "installFilesystems",	installFilesystems	},
75    { "mediaSetCDROM",		mediaSetCDROM		},
76    { "mediaSetFloppy",		mediaSetFloppy		},
77    { "mediaSetDOS",		mediaSetDOS		},
78    { "mediaSetTape",		mediaSetTape		},
79    { "mediaSetFTP",		mediaSetFTP		},
80    { "mediaSetFTPActive",	mediaSetFTPActive	},
81    { "mediaSetFTPPassive",	mediaSetFTPPassive	},
82    { "mediaSetUFS",		mediaSetUFS		},
83    { "mediaSetNFS",		mediaSetNFS		},
84    { "mediaSetFTPUserPass",	mediaSetFTPUserPass	},
85    { "mediaSetCPIOVerbosity",	mediaSetCPIOVerbosity	},
86    { "mediaGetType",		mediaGetType		},
87    { "optionsEditor",		optionsEditor		},
88    { "addGroup",		userAddGroup		},
89    { "addUser",		userAddUser		},
90    { "shutdown",		_shutdown 		},
91    { NULL, NULL },
92};
93
94static int
95call_possible_resword(char *name, dialogMenuItem *value, int *status)
96{
97    int i, rval;
98
99    rval = 0;
100    for (i = 0; resWords[i].name; i++) {
101	if (!strcmp(name, resWords[i].name)) {
102	    *status = resWords[i].handler(value);
103	    rval = 1;
104	    break;
105	}
106    }
107    return rval;
108}
109
110/* Just convenience */
111static int _shutdown(dialogMenuItem *unused)
112{
113    systemShutdown(0);
114    return DITEM_FAILURE;
115}
116
117/* For a given string, call it or spit out an undefined command diagnostic */
118int
119dispatchCommand(char *str)
120{
121    int i;
122    char *cp;
123
124    if (!str || !*str) {
125	msgConfirm("Null or zero-length string passed to dispatchCommand");
126	return DITEM_FAILURE;
127    }
128    /* If it's got a newline, trim it */
129    if ((cp = index(str, '\n')) != NULL)
130	*cp = '\0';
131
132    /* A command might be a pathname if it's encoded in argv[0], as we also support */
133    if (index(str, '=')) {
134	variable_set(str);
135	i = DITEM_SUCCESS;
136    }
137    else {
138	if ((cp = index(str, '/')) != NULL)
139	    str = cp + 1;
140	if (!call_possible_resword(str, NULL, &i)) {
141	    msgConfirm("No such command: %s", str);
142	    i = DITEM_FAILURE;
143	}
144    }
145    return i;
146}
147