1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
|
#include <alloca.h>
#include <ctype.h>
#include <newt.h>
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include "devices.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,
char ** moduleName) {
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:
}
}
rc = mlLoadModule(mod->moduleName, modLoaded, modDeps, args,
FL_TESTING(flags));
for (arg = args; *arg; arg++)
free(*arg);
free(args);
if (!rc && moduleName)
*moduleName = mod->moduleName;
return rc;
}
|