2 * The new sysinstall program.
4 * This is probably the last attempt in the `sysinstall' line, the next
5 * generation being slated for what's essentially a complete rewrite.
10 * Jordan Hubbard. All rights reserved.
12 * Redistribution and use in source and binary forms, with or without
13 * modification, are permitted provided that the following conditions
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
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.
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
37 #include "sysinstall.h"
42 static Boolean exited;
45 dmenuDisplayFile(dialogMenuItem *tmp)
47 systemDisplayHelp((char *)tmp->data);
52 dmenuSubmenu(dialogMenuItem *tmp)
54 return (dmenuOpenSimple((DMenu *)(tmp->data), FALSE) ? DITEM_SUCCESS : DITEM_FAILURE);
58 dmenuSystemCommand(dialogMenuItem *self)
60 WINDOW *w = NULL; /* Keep lint happy */
62 /* If aux is set, the command is known not to produce any screen-spoiling output */
65 systemExecute((char *)self->data);
72 dmenuSystemCommandBox(dialogMenuItem *tmp)
74 WINDOW *w = savescr();
77 use_helpline("Select OK to dismiss this dialog");
78 dialog_prgbox(tmp->title, (char *)tmp->data, 22, 76, 1, 1);
84 dmenuExit(dialogMenuItem *tmp)
87 return DITEM_LEAVE_MENU;
91 dmenuSetVariable(dialogMenuItem *tmp)
93 variable_set((char *)tmp->data, *((char *)tmp->data) != '_');
98 dmenuSetVariables(dialogMenuItem *tmp)
101 char *copy = strdup((char *)tmp->data);
103 for (cp1 = copy; cp1 != NULL;) {
104 cp2 = index(cp1, ',');
105 if (cp2 != NULL) *cp2++ = '\0';
106 variable_set(cp1, *cp1 != '_');
110 return DITEM_SUCCESS;
114 dmenuSetKmapVariable(dialogMenuItem *tmp)
119 variable_set((char *)tmp->data, TRUE);
120 lang = variable_get(VAR_KEYMAP);
123 err = loadKeymap(lang);
125 msgConfirm("No appropriate keyboard map found, sorry.");
127 msgConfirm("Error installing keyboard map, errno = %d.", errno);
129 return DITEM_SUCCESS;
133 dmenuToggleVariable(dialogMenuItem *tmp)
138 if (!(var = strdup((char *)tmp->data))) {
139 msgConfirm("Incorrect data field for `%s'!", tmp->title);
140 return DITEM_FAILURE;
142 if (!(cp = index(var, '='))) {
143 msgConfirm("Data field for %s is not in var=value format!", tmp->title);
144 return DITEM_FAILURE;
146 status = variable_check(var);
148 variable_set2(var, status ? "NO" : "YES", *var != '_');
150 return DITEM_SUCCESS;
154 dmenuISetVariable(dialogMenuItem *tmp)
158 if (!(var = (char *)tmp->data)) {
159 msgConfirm("Incorrect data field for `%s'!", tmp->title);
160 return DITEM_FAILURE;
162 ans = msgGetInput(variable_get(var), tmp->title, 1);
164 return DITEM_FAILURE;
168 variable_set2(var, ans, *var != '_');
169 return DITEM_SUCCESS;
173 dmenuSetFlag(dialogMenuItem *tmp)
175 if (*((unsigned int *)tmp->data) & tmp->aux)
176 *((unsigned int *)tmp->data) &= ~tmp->aux;
178 *((unsigned int *)tmp->data) |= tmp->aux;
179 return DITEM_SUCCESS;
183 dmenuSetValue(dialogMenuItem *tmp)
185 *((unsigned int *)tmp->data) = tmp->aux;
186 return DITEM_SUCCESS;
189 /* Traverse menu but give user no control over positioning */
191 dmenuOpenSimple(DMenu *menu, Boolean buttons)
193 int choice, scroll, curr, max;
195 choice = scroll = curr = max = 0;
196 return dmenuOpen(menu, &choice, &scroll, &curr, &max, buttons);
199 /* Work functions for the state hook */
201 dmenuFlagCheck(dialogMenuItem *item)
203 return (*((unsigned int *)item->data) & item->aux);
207 dmenuVarCheck(dialogMenuItem *item)
211 w = (char *)item->aux;
213 w = (char *)item->data;
214 return variable_check(w);
218 dmenuVarsCheck(dialogMenuItem *item)
224 w = (char *)item->aux;
226 w = (char *)item->data;
233 for (cp1 = copy; cp1 != NULL;) {
235 cp2 = index(cp1, ',');
238 res = res && variable_check(cp1);
246 dmenuRadioCheck(dialogMenuItem *item)
248 return (*((unsigned int *)item->data) == item->aux);
252 menu_height(DMenu *menu, int n)
259 max += StatusLine - 24;
260 for (t = menu->prompt; *t; t++) {
264 return n > max ? max : n;
267 /* Traverse over an internal menu */
269 dmenuOpen(DMenu *menu, int *choice, int *scroll, int *curr, int *max, Boolean buttons)
272 dialogMenuItem *items;
277 /* Count up all the items */
278 for (n = 0; items[n].title; n++);
281 char buf[FILENAME_MAX];
282 WINDOW *w = savescr();
284 /* Any helpful hints, put 'em up! */
285 use_helpline(menu->helpline);
286 use_helpfile(systemHelpFile(menu->helpfile, buf));
287 dialog_clear_norefresh();
288 /* Pop up that dialog! */
289 if (menu->type & DMENU_NORMAL_TYPE)
290 rval = dialog_menu((u_char *)menu->title, (u_char *)menu->prompt,
291 -1, -1, menu_height(menu, n), -n, items,
292 (char *)(uintptr_t)buttons, choice, scroll);
294 else if (menu->type & DMENU_RADIO_TYPE)
295 rval = dialog_radiolist((u_char *)menu->title,
296 (u_char *)menu->prompt, -1, -1, menu_height(menu, n), -n,
297 items, (char *)(uintptr_t)buttons);
299 else if (menu->type & DMENU_CHECKLIST_TYPE)
300 rval = dialog_checklist((u_char *)menu->title,
301 (u_char *)menu->prompt, -1, -1, menu_height(menu, n), -n,
302 items, (char *)(uintptr_t)buttons);
304 msgFatal("Menu: `%s' is of an unknown type\n", menu->title);
314 else if (menu->type & DMENU_SELECTION_RETURNS) {