Deleted Added
sdiff udiff text old ( 15091 ) new ( 15242 )
full compact
1/*
2 * The new sysinstall program.
3 *
4 * This is probably the last attempt in the `sysinstall' line, the next
5 * generation being slated for what's essentially a complete rewrite.
6 *
7 * $Id: dmenu.c,v 1.14 1996/03/02 07:31:51 jkh Exp $
8 *
9 * Copyright (c) 1995
10 * Jordan Hubbard. All rights reserved.
11 *
12 * Redistribution and use in source and binary forms, with or without
13 * modification, are permitted provided that the following conditions
14 * are met:
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
18 * point in the file.
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.
22 * 3. All advertising materials mentioning features or use of this software
23 * must display the following acknowledgement:
24 * This product includes software developed by Jordan Hubbard
25 * for the FreeBSD Project.
26 * 4. The name of Jordan Hubbard or the FreeBSD project may not be used to
27 * endorse or promote products derived from this software without specific
28 * prior written permission.
29 *
30 * THIS SOFTWARE IS PROVIDED BY JORDAN HUBBARD ``AS IS'' AND
31 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
32 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
33 * ARE DISCLAIMED. IN NO EVENT SHALL JORDAN HUBBARD OR HIS PETS BE LIABLE
34 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
35 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
36 * OR SERVICES; LOSS OF USE, DATA, LIFE OR PROFITS; OR BUSINESS INTERRUPTION)
37 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
38 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
39 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
40 * SUCH DAMAGE.
41 *
42 */
43
44#include "sysinstall.h"
45#include <sys/types.h>
46
47#define MAX_MENU 15
48
49static Boolean cancelled;
50
51int
52dmenuDisplayFile(dialogMenuItem *tmp)
53{
54 systemDisplayHelp((char *)tmp->data);
55 return RET_SUCCESS;
56}
57
58int
59dmenuSubmenu(dialogMenuItem *tmp)
60{
61 dialog_clear();
62 return dmenuOpenSimple((DMenu *)tmp->data);
63}
64
65int
66dmenuSystemCommand(dialogMenuItem *tmp)
67{
68 int i;
69
70 i = systemExecute((char *)tmp->data) ? RET_FAIL : RET_SUCCESS;
71 dialog_clear();
72 return i;
73}
74
75int
76dmenuSystemCommandBox(dialogMenuItem *tmp)
77{
78 use_helpfile(NULL);
79 use_helpline("Select OK to dismiss this dialog");
80 dialog_prgbox(tmp->title, (char *)tmp->data, 22, 76, 1, 1);
81 dialog_clear();
82 return RET_SUCCESS;
83}
84
85int
86dmenuCancel(dialogMenuItem *tmp)
87{
88 cancelled = TRUE;
89 return RET_SUCCESS;
90}
91
92int
93dmenuSetVariable(dialogMenuItem *tmp)
94{
95 variable_set((char *)tmp->data);
96 msgInfo("Set %s", tmp->data);
97 return RET_SUCCESS;
98}
99
100int
101dmenuSetFlag(dialogMenuItem *tmp)
102{
103 *((unsigned int *)tmp->data) |= tmp->aux;
104 return RET_SUCCESS;
105}
106
107int
108dmenuSetValue(dialogMenuItem *tmp)
109{
110 *((unsigned int *)tmp->data) = tmp->aux;
111 return RET_SUCCESS;
112}
113
114/* Traverse menu but give user no control over positioning */
115Boolean
116dmenuOpenSimple(DMenu *menu)
117{
118 int choice, scroll, curr, max;
119
120 choice = scroll = curr = max = 0;
121 dialog_clear();
122 return dmenuOpen(menu, &choice, &scroll, &curr, &max);
123}
124
125/* Work functions for the state hook */
126int
127dmenuFlagCheck(dialogMenuItem *item)
128{
129 return (*((unsigned int *)item->data) & item->aux);
130}
131
132int
133dmenuVarCheck(dialogMenuItem *item)
134{
135 char *w, *cp, *cp2, tmp[256];
136
137 w = (char *)item->aux;
138 if (!w)
139 w = (char *)item->data;
140 if (!w)
141 return FALSE;
142 strncpy(tmp, w, 256);
143 if ((cp = index(tmp, '=')) != NULL) {
144 *(cp++) = '\0';
145 cp2 = getenv(tmp);
146 if (cp2)
147 return !strcmp(cp, cp2);
148 else
149 return FALSE;
150 }
151 else
152 return (int)getenv(tmp);
153}
154
155int
156dmenuRadioCheck(dialogMenuItem *item)
157{
158 return (*((unsigned int *)item->data) == item->aux);
159}
160
161static int
162menu_height(DMenu *menu, int n)
163{
164 int max;
165 char *t;
166
167 for (t = menu->title, max = MAX_MENU; *t; t++) {
168 if (*t == '\n')
169 --max;
170 }
171 return n > max ? max : n;
172}
173
174/* Traverse over an internal menu */
175Boolean
176dmenuOpen(DMenu *menu, int *choice, int *scroll, int *curr, int *max)
177{
178 int n, rval = 0;
179
180 /* Count up all the items */
181 for (n = 0; menu->items[n].title; n++);
182
183 while (1) {
184 char buf[FILENAME_MAX];
185
186 /* Any helpful hints, put 'em up! */
187 use_helpline(menu->helpline);
188 use_helpfile(systemHelpFile(menu->helpfile, buf));
189
190 /* Pop up that dialog! */
191 if (menu->type == DMENU_NORMAL_TYPE)
192 rval = dialog_menu((u_char *)menu->title, (u_char *)menu->prompt, -1, -1,
193 menu_height(menu, n), -n, menu->items, NULL, choice, scroll);
194
195 else if (menu->type == DMENU_RADIO_TYPE)
196 rval = dialog_radiolist((u_char *)menu->title, (u_char *)menu->prompt, -1, -1,
197 menu_height(menu, n), -n, menu->items, NULL);
198
199 else if (menu->type == DMENU_CHECKLIST_TYPE)
200 rval = dialog_checklist((u_char *)menu->title, (u_char *)menu->prompt, -1, -1,
201 menu_height(menu, n), -n, menu->items, NULL);
202
203 /* This seems to be the only technique that works for getting the display to look right */
204 dialog_clear();
205 if (rval)
206 return FALSE;
207 else if (cancelled) {
208 cancelled = FALSE;
209 return TRUE;
210 }
211 }
212}