diff options
author | Erik Troan <ewt@redhat.com> | 1999-08-07 15:16:40 +0000 |
---|---|---|
committer | Erik Troan <ewt@redhat.com> | 1999-08-07 15:16:40 +0000 |
commit | 7b690aac4eef34ded00dd45df4e9c45ab212dcbb (patch) | |
tree | ddb423ae1eb8a226007b50d726985f6089872c9a /loader/devices.c | |
parent | 9fdc751ef4e832224ec1060792bede16b4b7d0ee (diff) | |
download | anaconda-7b690aac4eef34ded00dd45df4e9c45ab212dcbb.tar.gz anaconda-7b690aac4eef34ded00dd45df4e9c45ab212dcbb.tar.xz anaconda-7b690aac4eef34ded00dd45df4e9c45ab212dcbb.zip |
*** empty log message ***
Diffstat (limited to 'loader/devices.c')
-rw-r--r-- | loader/devices.c | 179 |
1 files changed, 179 insertions, 0 deletions
diff --git a/loader/devices.c b/loader/devices.c new file mode 100644 index 000000000..1d0c0d219 --- /dev/null +++ b/loader/devices.c @@ -0,0 +1,179 @@ +#include <alloca.h> +#include <ctype.h> +#include <newt.h> +#include <stdlib.h> +#include <stdio.h> +#include <string.h> + +#include "../isys/isys.h" +#include "lang.h" +#include "loader.h" +#include "modules.h" + +static int getModuleArgs(struct moduleInfo * mod, char *** argPtr) { + struct newtWinEntry * entries; + int i; + int numArgs; + char ** values; + char * chptr, * end; + int misc = -1; + char ** args; + int argc; + int rc; + + entries = alloca(sizeof(*entries) * (mod->numArgs + 2)); + values = alloca(sizeof(*values) * (mod->numArgs + 2)); + + for (i = 0; i < mod->numArgs; i++) { + entries[i].text = mod->args[i].description; + if (mod->args[i].arg) { + values[i] = malloc(strlen(mod->args[i].arg) + 2); + strcpy(values[i], mod->args[i].arg); + strcat(values[i], "="); + } else { + values[i] = NULL; + } + entries[i].value = values + i; + entries[i].flags = NEWT_FLAG_SCROLL; + } + + numArgs = i; + + if (!(mod->flags & MI_FLAG_NOMISCARGS)) { + values[i] = NULL; + entries[i].text = _("Miscellaneous"); + entries[i].value = values + i; + entries[i].flags = NEWT_FLAG_SCROLL; + misc = i; + i++; + } + + entries[i].text = (void *) entries[i].value = NULL; + + rc = newtWinEntries(_("Module Parameters"), _("This module can take " + "parameters which affects its operation. If you don't " + "know what parameters to supply, just skip this " + "screen by pressing the \"Ok\" button now."), + 40, 5, 15, 20, entries, _("Ok"), _("Back"), NULL); + + if (rc == 2) { + for (i = 0; i < numArgs; i++) + if (values[i]) free(values[i]); + return LOADER_BACK; + } + + /* we keep args big enough for the args we know about, plus a NULL */ + + args = malloc(sizeof(*args) * (numArgs + 1)); + argc = 0; + + for (i = 0; i < numArgs; i++) { + if (values[i] && *values[i]) { + chptr = values[i] + strlen(values[i]) - 1; + while (isspace(*chptr)) chptr--; + if (*chptr != '=') + args[argc++] = values[i]; + } + } + + if (misc >= 0 && values[misc]) { + chptr = values[misc]; + i = 1; + while (*chptr) { + if (isspace(*chptr)) i++; + chptr++; + } + + args = realloc(args, sizeof(*args) * (argc + i + 1)); + chptr = values[misc]; + while (*chptr) { + while (*chptr && isspace(*chptr)) chptr++; + if (!*chptr) break; + + end = chptr; + while (!isspace(*end) && *end) end++; + args[argc] = malloc(end - chptr + 1); + memcpy(args[argc], chptr, end - chptr); + args[argc][end - chptr] = '\0'; + argc++; + chptr = end; + } + + free(values[misc]); + } + + args[argc] = NULL; + *argPtr = args; + + return 0; + +} + +static struct moduleInfo * pickModule(moduleInfoSet modInfo, + enum driverMajor type, + moduleList modLoaded, + struct moduleInfo * suggestion) { + char ** devNames; + int * modules; + int numModules = 0, i, rc; + + devNames = alloca(sizeof(*devNames) * (modInfo->numModules + 1)); + modules = alloca(sizeof(*modules) * modInfo->numModules); + + for (i = 0; i < modInfo->numModules; i++) { + if (modInfo->moduleList[i].major == type && + !mlModuleInList(modInfo->moduleList[i].moduleName, modLoaded)) { + modules[numModules] = i; + devNames[numModules++] = modInfo->moduleList[i].description; + } + } + + devNames[numModules] = NULL; + + i = 0; + rc = newtWinMenu(_("Load module"), _("Which driver should I try?"), + 20, 0, 10, 6, devNames, &i, _("Ok"), _("Back"), NULL); + + if (rc == 2) return NULL; + + return modInfo->moduleList + modules[i]; +} + +int devDeviceMenu(enum driverMajor type, moduleInfoSet modInfo, + moduleList modLoaded, moduleDeps modDeps, int flags) { + struct moduleInfo * mod = NULL; + enum { S_MODULE, S_ARGS, S_DONE } stage = S_MODULE; + int rc; + char ** args = NULL, ** arg; + + while (stage != S_DONE) { + switch (stage) { + case S_MODULE: + mod = pickModule(modInfo, type, modLoaded, mod); + if (!mod) return LOADER_BACK; + stage = S_ARGS; + break; + + case S_ARGS: + if (mod->numArgs) { + rc = getModuleArgs(mod, &args); + if (rc) { + stage = S_MODULE; + break; + } + } + stage = S_DONE; + break; + + case S_DONE: + } + } + + mlLoadModule(mod->moduleName, modLoaded, modDeps, FL_TESTING(flags)); + + for (arg = args; *arg; arg++) + free(*arg); + free(args); + + return 0; +} |