dispatch.c revision 26764
1278332Semaste/* 2278332Semaste * The new sysinstall program. 3278332Semaste * 4278332Semaste * This is probably the last program in the `sysinstall' line - the next 5278332Semaste * generation being essentially a complete rewrite. 6278332Semaste * 7278332Semaste * $Id: dispatch.c,v 1.17 1997/06/13 17:55:32 jkh Exp $ 8278332Semaste * 9278332Semaste * Copyright (c) 1995 10278332Semaste * Jordan Hubbard. All rights reserved. 11278332Semaste * 12278332Semaste * Redistribution and use in source and binary forms, with or without 13278332Semaste * modification, are permitted provided that the following conditions 14278332Semaste * are met: 15278332Semaste * 1. Redistributions of source code must retain the above copyright 16278332Semaste * notice, this list of conditions and the following disclaimer, 17321369Sdim * verbatim and that no modifications are made prior to this 18321369Sdim * point in the file. 19278332Semaste * 2. Redistributions in binary form must reproduce the above copyright 20278332Semaste * notice, this list of conditions and the following disclaimer in the 21278332Semaste * documentation and/or other materials provided with the distribution. 22278332Semaste * 23278332Semaste * THIS SOFTWARE IS PROVIDED BY JORDAN HUBBARD ``AS IS'' AND 24314564Sdim * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 25314564Sdim * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 26314564Sdim * ARE DISCLAIMED. IN NO EVENT SHALL JORDAN HUBBARD OR HIS PETS BE LIABLE 27314564Sdim * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 28314564Sdim * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 29314564Sdim * OR SERVICES; LOSS OF USE, DATA, LIFE OR PROFITS; OR BUSINESS INTERRUPTION) 30278332Semaste * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 31314564Sdim * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 32314564Sdim * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 33314564Sdim * SUCH DAMAGE. 34314564Sdim * 35314564Sdim */ 36314564Sdim 37278332Semaste#include "sysinstall.h" 38278332Semaste#include <ctype.h> 39321369Sdim 40321369Sdimstatic int _shutdown(dialogMenuItem *unused); 41321369Sdim 42314564Sdimstatic struct _word { 43314564Sdim char *name; 44314564Sdim int (*handler)(dialogMenuItem *self); 45314564Sdim} resWords[] = { 46278332Semaste { "configAnonFTP", configAnonFTP }, 47314564Sdim { "configRouter", configRouter }, 48314564Sdim { "configNFSServer", configNFSServer }, 49314564Sdim { "configSamba", configSamba }, 50314564Sdim { "configNTP", configNTP }, 51314564Sdim { "configPCNFSD", configPCNFSD }, 52314564Sdim { "configNFSServer", configNFSServer }, 53314564Sdim { "configPackages", configPackages }, 54314564Sdim { "configRegister", configRegister }, 55314564Sdim { "configRouter", configRouter }, 56314564Sdim { "configUsers", configUsers }, 57314564Sdim { "configXEnvironment", configXEnvironment }, 58278332Semaste { "diskPartitionEditor", diskPartitionEditor }, 59314564Sdim { "diskPartitionWrite", diskPartitionWrite }, 60314564Sdim { "diskLabelEditor", diskLabelEditor }, 61314564Sdim { "diskLabelCommit", diskLabelCommit }, 62314564Sdim { "distReset", distReset }, 63314564Sdim { "distSetCustom", distSetCustom }, 64278332Semaste { "distSetDeveloper", distSetDeveloper }, 65278332Semaste { "distSetXDeveloper", distSetXDeveloper }, 66314564Sdim { "distSetKernDeveloper", distSetKernDeveloper }, 67314564Sdim { "distSetUser", distSetUser }, 68278332Semaste { "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 { "packageAdd", packageAdd }, 102 { "addGroup", userAddGroup }, 103 { "addUser", userAddUser }, 104 { "shutdown", _shutdown }, 105 { NULL, NULL }, 106}; 107 108static int 109call_possible_resword(char *name, dialogMenuItem *value, int *status) 110{ 111 int i, rval; 112 113 rval = 0; 114 for (i = 0; resWords[i].name; i++) { 115 if (!strcmp(name, resWords[i].name)) { 116 *status = resWords[i].handler(value); 117 rval = 1; 118 break; 119 } 120 } 121 return rval; 122} 123 124/* Just convenience */ 125static int _shutdown(dialogMenuItem *unused) 126{ 127 systemShutdown(0); 128 return DITEM_FAILURE; 129} 130 131/* For a given string, call it or spit out an undefined command diagnostic */ 132int 133dispatchCommand(char *str) 134{ 135 int i; 136 char *cp; 137 138 if (!str || !*str) { 139 msgConfirm("Null or zero-length string passed to dispatchCommand"); 140 return DITEM_FAILURE; 141 } 142 /* If it's got a newline, trim it */ 143 if ((cp = index(str, '\n')) != NULL) 144 *cp = '\0'; 145 146 /* If it's got a `=' sign in there, assume it's a variable setting */ 147 if (index(str, '=')) { 148 if (isDebug()) 149 msgDebug("dispatch: setting variable `%s'\n", str); 150 variable_set(str); 151 i = DITEM_SUCCESS; 152 } 153 else { 154 /* A command might be a pathname if it's encoded in argv[0], which we also support */ 155 if ((cp = rindex(str, '/')) != NULL) 156 str = cp + 1; 157 if (isDebug()) 158 msgDebug("dispatch: calling resword `%s'\n", str); 159 if (!call_possible_resword(str, NULL, &i)) { 160 msgNotify("Warning: No such command ``%s''", str); 161 i = DITEM_FAILURE; 162 } 163 } 164 return i; 165} 166