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.
7 * $Id: dmenu.c,v 1.39 1999/02/05 22:25:13 jkh Exp $
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);
48 return DITEM_SUCCESS | DITEM_RESTORE;
52 dmenuSubmenu(dialogMenuItem *tmp)
54 return (dmenuOpenSimple((DMenu *)(tmp->data), FALSE) ? DITEM_SUCCESS : DITEM_FAILURE) |
59 dmenuSystemCommand(dialogMenuItem *self)
61 WINDOW *w = NULL; /* Keep lint happy */
63 /* If aux is set, the command is known not to produce any screen-spoiling output */
66 systemExecute((char *)self->data);
73 dmenuSystemCommandBox(dialogMenuItem *tmp)
76 use_helpline("Select OK to dismiss this dialog");
77 dialog_prgbox(tmp->title, (char *)tmp->data, 22, 76, 1, 1);
78 return DITEM_SUCCESS | DITEM_RESTORE;
82 dmenuExit(dialogMenuItem *tmp)
85 return DITEM_LEAVE_MENU;
89 dmenuSetVariable(dialogMenuItem *tmp)
91 variable_set((char *)tmp->data, *((char *)tmp->data) != '_');
96 dmenuSetVariables(dialogMenuItem *tmp)
99 char *copy = strdup((char *)tmp->data);
101 for (cp1 = copy; cp1 != NULL;) {
102 cp2 = index(cp1, ',');
103 if (cp2 != NULL) *cp2++ = '\0';
104 variable_set(cp1, *cp1 != '_');
108 return DITEM_SUCCESS;
112 dmenuSetKmapVariable(dialogMenuItem *tmp)
117 variable_set((char *)tmp->data, 1);
118 lang = variable_get(VAR_KEYMAP);
121 err = loadKeymap(lang);
123 msgConfirm("No appropriate keyboard map found, sorry.");
125 msgConfirm("Error installing keyboard map, errno = %d.", errno);
127 return DITEM_SUCCESS;
131 dmenuToggleVariable(dialogMenuItem *tmp)
135 if (!(var = (char *)tmp->data)) {
136 msgConfirm("Incorrect data field for `%s'!", tmp->title);
137 return DITEM_FAILURE;
139 if (!variable_check(var))
140 variable_set(var, *var != '_');
143 return DITEM_SUCCESS;
147 dmenuISetVariable(dialogMenuItem *tmp)
150 WINDOW *w = NULL; /* Keep lint happy */
152 if (!(var = (char *)tmp->data)) {
153 msgConfirm("Incorrect data field for `%s'!", tmp->title);
154 return DITEM_FAILURE;
157 ans = msgGetInput(variable_get(var), tmp->title, 1);
160 return DITEM_FAILURE;
164 variable_set2(var, ans, *var != '_');
165 return DITEM_SUCCESS;
169 dmenuSetFlag(dialogMenuItem *tmp)
171 if (*((unsigned int *)tmp->data) & tmp->aux)
172 *((unsigned int *)tmp->data) &= ~tmp->aux;
174 *((unsigned int *)tmp->data) |= tmp->aux;
175 return DITEM_SUCCESS;
179 dmenuSetValue(dialogMenuItem *tmp)
181 *((unsigned int *)tmp->data) = tmp->aux;
182 return DITEM_SUCCESS;
185 /* Traverse menu but give user no control over positioning */
187 dmenuOpenSimple(DMenu *menu, Boolean buttons)
189 int choice, scroll, curr, max;
191 choice = scroll = curr = max = 0;
192 return dmenuOpen(menu, &choice, &scroll, &curr, &max, buttons);
195 /* Work functions for the state hook */
197 dmenuFlagCheck(dialogMenuItem *item)
199 return (*((unsigned int *)item->data) & item->aux);
203 dmenuVarCheck(dialogMenuItem *item)
207 w = (char *)item->aux;
209 w = (char *)item->data;
210 return variable_check(w);
214 dmenuVarsCheck(dialogMenuItem *item)
220 w = (char *)item->aux;
222 w = (char *)item->data;
229 for (cp1 = copy; cp1 != NULL;) {
231 cp2 = index(cp1, ',');
234 res = res && variable_check(cp1);
242 dmenuRadioCheck(dialogMenuItem *item)
244 return (*((unsigned int *)item->data) == item->aux);
248 menu_height(DMenu *menu, int n)
255 max += StatusLine - 24;
256 for (t = menu->prompt; *t; t++) {
260 return n > max ? max : n;
263 /* Traverse over an internal menu */
265 dmenuOpen(DMenu *menu, int *choice, int *scroll, int *curr, int *max, Boolean buttons)
268 dialogMenuItem *items;
273 /* Count up all the items */
274 for (n = 0; items[n].title; n++);
277 char buf[FILENAME_MAX];
279 /* Any helpful hints, put 'em up! */
280 use_helpline(menu->helpline);
281 use_helpfile(systemHelpFile(menu->helpfile, buf));
283 /* Pop up that dialog! */
284 dialog_clear_norefresh();
285 if (menu->type & DMENU_NORMAL_TYPE)
286 rval = dialog_menu((u_char *)menu->title, (u_char *)menu->prompt, -1, -1,
287 menu_height(menu, n), -n, items, (char *)buttons, choice, scroll);
289 else if (menu->type & DMENU_RADIO_TYPE)
290 rval = dialog_radiolist((u_char *)menu->title, (u_char *)menu->prompt, -1, -1,
291 menu_height(menu, n), -n, items, (char *)buttons);
293 else if (menu->type & DMENU_CHECKLIST_TYPE)
294 rval = dialog_checklist((u_char *)menu->title, (u_char *)menu->prompt, -1, -1,
295 menu_height(menu, n), -n, items, (char *)buttons);
297 msgFatal("Menu: `%s' is of an unknown type\n", menu->title);
298 clearok(stdscr, TRUE);
305 else if (menu->type & DMENU_SELECTION_RETURNS)