dispatch.c revision 19385
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.5 1996/10/01 12:13:10 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 struct _word { 41 char *name; 42 int (*handler)(dialogMenuItem *self); 43} resWords[] = { 44 { "configAnonFTP", configAnonFTP }, 45 { "configApache", configApache }, 46 { "configRouter", configRouter }, 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 { "optionsEditor", optionsEditor }, 86 { NULL, NULL }, 87}; 88 89static int 90call_possible_resword(char *name, dialogMenuItem *value, int *status) 91{ 92 int i, rval; 93 94 rval = 0; 95 for (i = 0; resWords[i].name; i++) { 96 if (!strcmp(name, resWords[i].name)) { 97 *status = resWords[i].handler(value); 98 rval = 1; 99 break; 100 } 101 } 102 return rval; 103} 104 105/* For a given string, call it or spit out an undefined command diagnostic */ 106int 107dispatchCommand(char *str) 108{ 109 int i; 110 char *cp; 111 112 if (!str || !*str) { 113 msgConfirm("Null or zero-length string passed to dispatchCommand"); 114 return DITEM_FAILURE; 115 } 116 /* A command might be a pathname if it's encoded in argv[0], as we also support */ 117 if (index(str, '=')) { 118 variable_set(str); 119 return DITEM_SUCCESS; 120 } 121 else if ((cp = index(str, '/')) != NULL) 122 str = cp + 1; 123 if (!call_possible_resword(str, NULL, &i)) { 124 msgConfirm("No such command: %s", str); 125 return DITEM_FAILURE; 126 } 127 return i; 128} 129