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 * $FreeBSD: src/release/sysinstall/dmenu.c,v 1.44 2000/03/08 14:20:26 jkh Exp $
8 * $DragonFly: src/release/sysinstall/Attic/dmenu.c,v 1.2 2003/06/17 04:27:21 dillon Exp $
11 * Jordan Hubbard. All rights reserved.
13 * Redistribution and use in source and binary forms, with or without
14 * modification, are permitted provided that the following conditions
16 * 1. Redistributions of source code must retain the above copyright
17 * notice, this list of conditions and the following disclaimer,
18 * verbatim and that no modifications are made prior to this
20 * 2. Redistributions in binary form must reproduce the above copyright
21 * notice, this list of conditions and the following disclaimer in the
22 * documentation and/or other materials provided with the distribution.
24 * THIS SOFTWARE IS PROVIDED BY JORDAN HUBBARD ``AS IS'' AND
25 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
26 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
27 * ARE DISCLAIMED. IN NO EVENT SHALL JORDAN HUBBARD OR HIS PETS BE LIABLE
28 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
29 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
30 * OR SERVICES; LOSS OF USE, DATA, LIFE OR PROFITS; OR BUSINESS INTERRUPTION)
31 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
32 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
33 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
38 #include "sysinstall.h"
43 static Boolean exited;
46 dmenuDisplayFile(dialogMenuItem *tmp)
48 systemDisplayHelp((char *)tmp->data);
53 dmenuSubmenu(dialogMenuItem *tmp)
55 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)
75 WINDOW *w = savescr();
78 use_helpline("Select OK to dismiss this dialog");
79 dialog_prgbox(tmp->title, (char *)tmp->data, 22, 76, 1, 1);
85 dmenuExit(dialogMenuItem *tmp)
88 return DITEM_LEAVE_MENU;
92 dmenuSetVariable(dialogMenuItem *tmp)
94 variable_set((char *)tmp->data, *((char *)tmp->data) != '_');
99 dmenuSetVariables(dialogMenuItem *tmp)
102 char *copy = strdup((char *)tmp->data);
104 for (cp1 = copy; cp1 != NULL;) {
105 cp2 = index(cp1, ',');
106 if (cp2 != NULL) *cp2++ = '\0';
107 variable_set(cp1, *cp1 != '_');
111 return DITEM_SUCCESS;
115 dmenuSetKmapVariable(dialogMenuItem *tmp)
120 variable_set((char *)tmp->data, TRUE);
121 lang = variable_get(VAR_KEYMAP);
124 err = loadKeymap(lang);
126 msgConfirm("No appropriate keyboard map found, sorry.");
128 msgConfirm("Error installing keyboard map, errno = %d.", errno);
130 return DITEM_SUCCESS;
134 dmenuToggleVariable(dialogMenuItem *tmp)
139 if (!(var = strdup((char *)tmp->data))) {
140 msgConfirm("Incorrect data field for `%s'!", tmp->title);
141 return DITEM_FAILURE;
143 if (!(cp = index(var, '='))) {
144 msgConfirm("Data field for %s is not in var=value format!", tmp->title);
145 return DITEM_FAILURE;
147 status = variable_check(var);
149 variable_set2(var, status ? "NO" : "YES", *var != '_');
151 return DITEM_SUCCESS;
155 dmenuISetVariable(dialogMenuItem *tmp)
159 if (!(var = (char *)tmp->data)) {
160 msgConfirm("Incorrect data field for `%s'!", tmp->title);
161 return DITEM_FAILURE;
163 ans = msgGetInput(variable_get(var), tmp->title, 1);
165 return DITEM_FAILURE;
169 variable_set2(var, ans, *var != '_');
170 return DITEM_SUCCESS;
174 dmenuSetFlag(dialogMenuItem *tmp)
176 if (*((unsigned int *)tmp->data) & tmp->aux)
177 *((unsigned int *)tmp->data) &= ~tmp->aux;
179 *((unsigned int *)tmp->data) |= tmp->aux;
180 return DITEM_SUCCESS;
184 dmenuSetValue(dialogMenuItem *tmp)
186 *((unsigned int *)tmp->data) = tmp->aux;
187 return DITEM_SUCCESS;
190 /* Traverse menu but give user no control over positioning */
192 dmenuOpenSimple(DMenu *menu, Boolean buttons)
194 int choice, scroll, curr, max;
196 choice = scroll = curr = max = 0;
197 return dmenuOpen(menu, &choice, &scroll, &curr, &max, buttons);
200 /* Work functions for the state hook */
202 dmenuFlagCheck(dialogMenuItem *item)
204 return (*((unsigned int *)item->data) & item->aux);
208 dmenuVarCheck(dialogMenuItem *item)
212 w = (char *)item->aux;
214 w = (char *)item->data;
215 return variable_check(w);
219 dmenuVarsCheck(dialogMenuItem *item)
225 w = (char *)item->aux;
227 w = (char *)item->data;
234 for (cp1 = copy; cp1 != NULL;) {
236 cp2 = index(cp1, ',');
239 res = res && variable_check(cp1);
247 dmenuRadioCheck(dialogMenuItem *item)
249 return (*((unsigned int *)item->data) == item->aux);
253 menu_height(DMenu *menu, int n)
260 max += StatusLine - 24;
261 for (t = menu->prompt; *t; t++) {
265 return n > max ? max : n;
268 /* Traverse over an internal menu */
270 dmenuOpen(DMenu *menu, int *choice, int *scroll, int *curr, int *max, Boolean buttons)
273 dialogMenuItem *items;
278 /* Count up all the items */
279 for (n = 0; items[n].title; n++);
282 char buf[FILENAME_MAX];
283 WINDOW *w = savescr();
285 /* Any helpful hints, put 'em up! */
286 use_helpline(menu->helpline);
287 use_helpfile(systemHelpFile(menu->helpfile, buf));
288 dialog_clear_norefresh();
289 /* Pop up that dialog! */
290 if (menu->type & DMENU_NORMAL_TYPE)
291 rval = dialog_menu((u_char *)menu->title, (u_char *)menu->prompt, -1, -1,
292 menu_height(menu, n), -n, items, (char *)buttons, choice, scroll);
294 else if (menu->type & DMENU_RADIO_TYPE)
295 rval = dialog_radiolist((u_char *)menu->title, (u_char *)menu->prompt, -1, -1,
296 menu_height(menu, n), -n, items, (char *)buttons);
298 else if (menu->type & DMENU_CHECKLIST_TYPE)
299 rval = dialog_checklist((u_char *)menu->title, (u_char *)menu->prompt, -1, -1,
300 menu_height(menu, n), -n, items, (char *)buttons);
302 msgFatal("Menu: `%s' is of an unknown type\n", menu->title);
312 else if (menu->type & DMENU_SELECTION_RETURNS) {