dispatch.c revision 15788
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$
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 struct _word {
41    char *name;
42    int (*handler)(dialogMenuItem *self);
43} resWords[] = {
44    { "configAnonFTP",		configAnonFTP		},
45    { "configApache",		configApache		},
46    { "configGated",		configGated		},
47    { "configNFSServer",	configNFSServer		},
48    { "configSamba",		configSamba		},
49    { "configPackages",		configPackages		},
50    { "diskPartitionEditor",	diskPartitionEditor	},
51    { "diskPartitionWrite",	diskPartitionWrite	},
52    { "diskLabelEditor",	diskLabelEditor		},
53    { "diskLabelCommit",	diskLabelCommit		},
54    { "distReset",		distReset		},
55    { "distSetDeveloper",	distSetDeveloper	},
56    { "distSetXDeveloper",	distSetXDeveloper	},
57    { "distSetKernDeveloper",	distSetKernDeveloper	},
58    { "distSetUser",		distSetUser		},
59    { "distSetXUser",		distSetXUser		},
60    { "distSetMinimum",		distSetMinimum		},
61    { "distSetEverything",	distSetEverything	},
62    { "distSetDES",		distSetDES		},
63    { "distSetSrc",		distSetSrc		},
64    { "distSetXF86",		distSetXF86		},
65    { "distExtractAll",		distExtractAll		},
66    { "docBrowser",		docBrowser		},
67    { "docShowDocument",	docShowDocument		},
68    { "installCommit",		installCommit		},
69    { "installExpress",		installExpress		},
70    { "installUpgrade",		installUpgrade		},
71    { "installFixup",		installFixup		},
72    { "installFilesystems",	installFilesystems	},
73    { "mediaSetCDROM",		mediaSetCDROM		},
74    { "mediaSetFloppy",		mediaSetFloppy		},
75    { "mediaSetDOS",		mediaSetDOS		},
76    { "mediaSetTape",		mediaSetTape		},
77    { "mediaSetFTP",		mediaSetFTP		},
78    { "mediaSetFTPActive",	mediaSetFTPActive	},
79    { "mediaSetFTPPassive",	mediaSetFTPPassive	},
80    { "mediaSetUFS",		mediaSetUFS		},
81    { "mediaSetNFS",		mediaSetNFS		},
82    { "mediaSetFtpUserPass",	mediaSetFtpUserPass	},
83    { "mediaSetCPIOVerbosity",	mediaSetCPIOVerbosity	},
84    { "mediaGetType",		mediaGetType		},
85    { NULL, NULL },
86};
87
88static int
89call_possible_resword(char *name, dialogMenuItem *value, int *status)
90{
91    int i, rval;
92
93    rval = 0;
94    for (i = 0; resWords[i].name; i++) {
95	if (!strcmp(name, resWords[i].name)) {
96	    *status = resWords[i].handler(value);
97	    rval = 1;
98	    break;
99	}
100    }
101    return rval;
102}
103
104/* For a given string, call it or spit out an undefined command diagnostic */
105int
106dispatchCommand(char *str)
107{
108    int i;
109
110    if (!str || !*str) {
111	msgConfirm("Null or zero-length string passed to dispatchCommand");
112	return DITEM_FAILURE;
113    }
114    else if (index(str, '=')) {
115	variable_set(str);
116	return DITEM_SUCCESS;
117    }
118    else if (!call_possible_resword(str, NULL, &i)) {
119	msgConfirm("No such command: %s", str);
120	return DITEM_FAILURE;
121    }
122    else if (DITEM_STATUS(i) != DITEM_SUCCESS)
123	msgConfirm("Command `%s' returned an error status.");
124    return i;
125}
126