Commit 2982de6993e6d9944f2215d7cb9b558b465a0c99
Committed by
Sam Ravnborg
1 parent
350b5b7638
Exists in
master
and in
7 other branches
kconfig/menuconfig: lxdialog is now built-in
lxdialog was previously called as an external program causing screen to flicker when used. With this patch lxdialog is now built-in. It is loosly based om previous work by: Petr Baudis <pasky@ucw.cz> Following is a list of changes: o Moved build of dialog routings to kconfig Makefile o menubox + checklist uses a new item list to hold all menu items o in util.c implmented helper function to deal with item list o menubox now uses parameters to save scroll state (avoids temp file) o textbox now get text to be displayed as parameter and not a file o make sure to properly delete subwin's before main windows o killed unused files: lxdialog.c msgbox.c o modified return value for ESC to match direct calling o in a few places the code has been adjusted to 80 char wide o in textbox a small refactoring was made to make code remotely readable o in mconf removed all unused stuff (functions/variables) Following is a list of know short comings: a) pressing ESC twice will be interpreted as two ESC presses b) resize does not work. menuconfig needs to be restarted to be adjusted Signed-off-by: Sam Ravnborg <sam@ravnborg.org>
Showing 12 changed files with 502 additions and 1019 deletions Side-by-side Diff
- scripts/kconfig/Makefile
- scripts/kconfig/lxdialog/Makefile
- scripts/kconfig/lxdialog/checklist.c
- scripts/kconfig/lxdialog/dialog.h
- scripts/kconfig/lxdialog/inputbox.c
- scripts/kconfig/lxdialog/lxdialog.c
- scripts/kconfig/lxdialog/menubox.c
- scripts/kconfig/lxdialog/msgbox.c
- scripts/kconfig/lxdialog/textbox.c
- scripts/kconfig/lxdialog/util.c
- scripts/kconfig/lxdialog/yesno.c
- scripts/kconfig/mconf.c
scripts/kconfig/Makefile
... | ... | @@ -11,7 +11,6 @@ |
11 | 11 | $< arch/$(ARCH)/Kconfig |
12 | 12 | |
13 | 13 | menuconfig: $(obj)/mconf |
14 | - $(Q)$(MAKE) $(build)=scripts/kconfig/lxdialog | |
15 | 14 | $< arch/$(ARCH)/Kconfig |
16 | 15 | |
17 | 16 | config: $(obj)/conf |
... | ... | @@ -81,6 +80,23 @@ |
81 | 80 | @echo ' allyesconfig - New config where all options are accepted with yes' |
82 | 81 | @echo ' allnoconfig - New config where all options are answered with no' |
83 | 82 | |
83 | +# lxdialog stuff | |
84 | +check-lxdialog := $(srctree)/$(src)/lxdialog/check-lxdialog.sh | |
85 | + | |
86 | +# Use reursively expanded variables so we do not call gcc unless | |
87 | +# we really need to do so. (Do not call gcc as part of make mrproper) | |
88 | +HOST_EXTRACFLAGS = $(shell $(CONFIG_SHELL) $(check-lxdialog) -ccflags) | |
89 | +HOST_LOADLIBES = $(shell $(CONFIG_SHELL) $(check-lxdialog) -ldflags $(HOSTCC)) | |
90 | + | |
91 | +HOST_EXTRACFLAGS += -DLOCALE | |
92 | + | |
93 | +PHONY += $(obj)/dochecklxdialog | |
94 | +$(obj)/dochecklxdialog: | |
95 | + $(Q)$(CONFIG_SHELL) $(check-lxdialog) -check $(HOSTCC) $(HOST_LOADLIBES) | |
96 | + | |
97 | +always := dochecklxdialog | |
98 | + | |
99 | + | |
84 | 100 | # =========================================================================== |
85 | 101 | # Shared Makefile for the various kconfig executables: |
86 | 102 | # conf: Used for defconfig, oldconfig and related targets |
87 | 103 | |
... | ... | @@ -92,9 +108,12 @@ |
92 | 108 | # Based on GTK which needs to be installed to compile it |
93 | 109 | # object files used by all kconfig flavours |
94 | 110 | |
111 | +lxdialog := lxdialog/checklist.o lxdialog/util.o lxdialog/inputbox.o | |
112 | +lxdialog += lxdialog/textbox.o lxdialog/yesno.o lxdialog/menubox.o | |
113 | + | |
95 | 114 | hostprogs-y := conf mconf qconf gconf kxgettext |
96 | 115 | conf-objs := conf.o zconf.tab.o |
97 | -mconf-objs := mconf.o zconf.tab.o | |
116 | +mconf-objs := mconf.o zconf.tab.o $(lxdialog) | |
98 | 117 | kxgettext-objs := kxgettext.o zconf.tab.o |
99 | 118 | |
100 | 119 | ifeq ($(MAKECMDGOALS),xconfig) |
scripts/kconfig/lxdialog/Makefile
1 | -# Makefile to build lxdialog package | |
2 | -# | |
3 | - | |
4 | -check-lxdialog := $(srctree)/$(src)/check-lxdialog.sh | |
5 | - | |
6 | -# Use reursively expanded variables so we do not call gcc unless | |
7 | -# we really need to do so. (Do not call gcc as part of make mrproper) | |
8 | -HOST_EXTRACFLAGS = $(shell $(CONFIG_SHELL) $(check-lxdialog) -ccflags) | |
9 | -HOST_LOADLIBES = $(shell $(CONFIG_SHELL) $(check-lxdialog) -ldflags $(HOSTCC)) | |
10 | - | |
11 | -HOST_EXTRACFLAGS += -DLOCALE | |
12 | - | |
13 | -PHONY += dochecklxdialog | |
14 | -$(obj)/dochecklxdialog: | |
15 | - $(Q)$(CONFIG_SHELL) $(check-lxdialog) -check $(HOSTCC) $(HOST_LOADLIBES) | |
16 | - | |
17 | -hostprogs-y := lxdialog | |
18 | -always := $(hostprogs-y) dochecklxdialog | |
19 | - | |
20 | -lxdialog-objs := checklist.o menubox.o textbox.o yesno.o inputbox.o \ | |
21 | - util.o lxdialog.o msgbox.o |
scripts/kconfig/lxdialog/checklist.c
... | ... | @@ -28,8 +28,7 @@ |
28 | 28 | /* |
29 | 29 | * Print list item |
30 | 30 | */ |
31 | -static void print_item(WINDOW * win, const char *item, int status, int choice, | |
32 | - int selected) | |
31 | +static void print_item(WINDOW * win, int choice, int selected) | |
33 | 32 | { |
34 | 33 | int i; |
35 | 34 | |
36 | 35 | |
37 | 36 | |
... | ... | @@ -42,12 +41,12 @@ |
42 | 41 | wmove(win, choice, check_x); |
43 | 42 | wattrset(win, selected ? dlg.check_selected.atr |
44 | 43 | : dlg.check.atr); |
45 | - wprintw(win, "(%c)", status ? 'X' : ' '); | |
44 | + wprintw(win, "(%c)", item_is_tag('X') ? 'X' : ' '); | |
46 | 45 | |
47 | 46 | wattrset(win, selected ? dlg.tag_selected.atr : dlg.tag.atr); |
48 | - mvwaddch(win, choice, item_x, item[0]); | |
47 | + mvwaddch(win, choice, item_x, item_str()[0]); | |
49 | 48 | wattrset(win, selected ? dlg.item_selected.atr : dlg.item.atr); |
50 | - waddstr(win, (char *)item + 1); | |
49 | + waddstr(win, (char *)item_str() + 1); | |
51 | 50 | if (selected) { |
52 | 51 | wmove(win, choice, check_x + 1); |
53 | 52 | wrefresh(win); |
54 | 53 | |
55 | 54 | |
56 | 55 | |
57 | 56 | |
... | ... | @@ -110,33 +109,24 @@ |
110 | 109 | * in the style of radiolist (only one option turned on at a time). |
111 | 110 | */ |
112 | 111 | int dialog_checklist(const char *title, const char *prompt, int height, |
113 | - int width, int list_height, int item_no, | |
114 | - const char *const *items) | |
112 | + int width, int list_height) | |
115 | 113 | { |
116 | 114 | int i, x, y, box_x, box_y; |
117 | - int key = 0, button = 0, choice = 0, scroll = 0, max_choice, *status; | |
115 | + int key = 0, button = 0, choice = 0, scroll = 0, max_choice; | |
118 | 116 | WINDOW *dialog, *list; |
119 | 117 | |
120 | - /* Allocate space for storing item on/off status */ | |
121 | - if ((status = malloc(sizeof(int) * item_no)) == NULL) { | |
122 | - endwin(); | |
123 | - fprintf(stderr, | |
124 | - "\nCan't allocate memory in dialog_checklist().\n"); | |
125 | - exit(-1); | |
118 | + /* which item to highlight */ | |
119 | + item_foreach() { | |
120 | + if (item_is_tag('X')) | |
121 | + choice = item_n(); | |
122 | + if (item_is_selected()) { | |
123 | + choice = item_n(); | |
124 | + break; | |
125 | + } | |
126 | 126 | } |
127 | 127 | |
128 | - /* Initializes status */ | |
129 | - for (i = 0; i < item_no; i++) { | |
130 | - status[i] = !strcasecmp(items[i * 3 + 2], "on"); | |
131 | - if ((!choice && status[i]) | |
132 | - || !strcasecmp(items[i * 3 + 2], "selected")) | |
133 | - choice = i + 1; | |
134 | - } | |
135 | - if (choice) | |
136 | - choice--; | |
128 | + max_choice = MIN(list_height, item_count()); | |
137 | 129 | |
138 | - max_choice = MIN(list_height, item_no); | |
139 | - | |
140 | 130 | /* center dialog box on screen */ |
141 | 131 | x = (COLS - width) / 2; |
142 | 132 | y = (LINES - height) / 2; |
... | ... | @@ -176,8 +166,8 @@ |
176 | 166 | |
177 | 167 | /* Find length of longest item in order to center checklist */ |
178 | 168 | check_x = 0; |
179 | - for (i = 0; i < item_no; i++) | |
180 | - check_x = MAX(check_x, +strlen(items[i * 3 + 1]) + 4); | |
169 | + item_foreach() | |
170 | + check_x = MAX(check_x, strlen(item_str()) + 4); | |
181 | 171 | |
182 | 172 | check_x = (list_width - check_x) / 2; |
183 | 173 | item_x = check_x + 4; |
184 | 174 | |
185 | 175 | |
... | ... | @@ -189,14 +179,11 @@ |
189 | 179 | |
190 | 180 | /* Print the list */ |
191 | 181 | for (i = 0; i < max_choice; i++) { |
192 | - if (i != choice) | |
193 | - print_item(list, items[(scroll + i) * 3 + 1], | |
194 | - status[i + scroll], i, 0); | |
182 | + item_set(scroll + i); | |
183 | + print_item(list, i, i == choice); | |
195 | 184 | } |
196 | - print_item(list, items[(scroll + choice) * 3 + 1], | |
197 | - status[choice + scroll], choice, 1); | |
198 | 185 | |
199 | - print_arrows(dialog, choice, item_no, scroll, | |
186 | + print_arrows(dialog, choice, item_count(), scroll, | |
200 | 187 | box_y, box_x + check_x + 5, list_height); |
201 | 188 | |
202 | 189 | print_buttons(dialog, height, width, 0); |
203 | 190 | |
... | ... | @@ -208,10 +195,11 @@ |
208 | 195 | while (key != ESC) { |
209 | 196 | key = wgetch(dialog); |
210 | 197 | |
211 | - for (i = 0; i < max_choice; i++) | |
212 | - if (toupper(key) == | |
213 | - toupper(items[(scroll + i) * 3 + 1][0])) | |
198 | + for (i = 0; i < max_choice; i++) { | |
199 | + item_set(i + scroll); | |
200 | + if (toupper(key) == toupper(item_str()[0])) | |
214 | 201 | break; |
202 | + } | |
215 | 203 | |
216 | 204 | if (i < max_choice || key == KEY_UP || key == KEY_DOWN || |
217 | 205 | key == '+' || key == '-') { |
218 | 206 | |
... | ... | @@ -222,15 +210,16 @@ |
222 | 210 | /* Scroll list down */ |
223 | 211 | if (list_height > 1) { |
224 | 212 | /* De-highlight current first item */ |
225 | - print_item(list, items[scroll * 3 + 1], | |
226 | - status[scroll], 0, FALSE); | |
213 | + item_set(scroll); | |
214 | + print_item(list, 0, FALSE); | |
227 | 215 | scrollok(list, TRUE); |
228 | 216 | wscrl(list, -1); |
229 | 217 | scrollok(list, FALSE); |
230 | 218 | } |
231 | 219 | scroll--; |
232 | - print_item(list, items[scroll * 3 + 1], status[scroll], 0, TRUE); | |
233 | - print_arrows(dialog, choice, item_no, | |
220 | + item_set(scroll); | |
221 | + print_item(list, 0, TRUE); | |
222 | + print_arrows(dialog, choice, item_count(), | |
234 | 223 | scroll, box_y, box_x + check_x + 5, list_height); |
235 | 224 | |
236 | 225 | wnoutrefresh(dialog); |
237 | 226 | |
238 | 227 | |
239 | 228 | |
... | ... | @@ -241,23 +230,24 @@ |
241 | 230 | i = choice - 1; |
242 | 231 | } else if (key == KEY_DOWN || key == '+') { |
243 | 232 | if (choice == max_choice - 1) { |
244 | - if (scroll + choice >= item_no - 1) | |
233 | + if (scroll + choice >= item_count() - 1) | |
245 | 234 | continue; |
246 | 235 | /* Scroll list up */ |
247 | 236 | if (list_height > 1) { |
248 | 237 | /* De-highlight current last item before scrolling up */ |
249 | - print_item(list, items[(scroll + max_choice - 1) * 3 + 1], | |
250 | - status[scroll + max_choice - 1], | |
251 | - max_choice - 1, FALSE); | |
238 | + item_set(scroll + max_choice - 1); | |
239 | + print_item(list, | |
240 | + max_choice - 1, | |
241 | + FALSE); | |
252 | 242 | scrollok(list, TRUE); |
253 | 243 | wscrl(list, 1); |
254 | 244 | scrollok(list, FALSE); |
255 | 245 | } |
256 | 246 | scroll++; |
257 | - print_item(list, items[(scroll + max_choice - 1) * 3 + 1], | |
258 | - status[scroll + max_choice - 1], max_choice - 1, TRUE); | |
247 | + item_set(scroll + max_choice - 1); | |
248 | + print_item(list, max_choice - 1, TRUE); | |
259 | 249 | |
260 | - print_arrows(dialog, choice, item_no, | |
250 | + print_arrows(dialog, choice, item_count(), | |
261 | 251 | scroll, box_y, box_x + check_x + 5, list_height); |
262 | 252 | |
263 | 253 | wnoutrefresh(dialog); |
264 | 254 | |
... | ... | @@ -269,12 +259,12 @@ |
269 | 259 | } |
270 | 260 | if (i != choice) { |
271 | 261 | /* De-highlight current item */ |
272 | - print_item(list, items[(scroll + choice) * 3 + 1], | |
273 | - status[scroll + choice], choice, FALSE); | |
262 | + item_set(scroll + choice); | |
263 | + print_item(list, choice, FALSE); | |
274 | 264 | /* Highlight new item */ |
275 | 265 | choice = i; |
276 | - print_item(list, items[(scroll + choice) * 3 + 1], | |
277 | - status[scroll + choice], choice, TRUE); | |
266 | + item_set(scroll + choice); | |
267 | + print_item(list, choice, TRUE); | |
278 | 268 | wnoutrefresh(dialog); |
279 | 269 | wrefresh(list); |
280 | 270 | } |
281 | 271 | |
... | ... | @@ -284,10 +274,19 @@ |
284 | 274 | case 'H': |
285 | 275 | case 'h': |
286 | 276 | case '?': |
287 | - fprintf(stderr, "%s", items[(scroll + choice) * 3]); | |
277 | + button = 1; | |
278 | + /* fall-through */ | |
279 | + case 'S': | |
280 | + case 's': | |
281 | + case ' ': | |
282 | + case '\n': | |
283 | + item_foreach() | |
284 | + item_set_selected(0); | |
285 | + item_set(scroll + choice); | |
286 | + item_set_selected(1); | |
287 | + delwin(list); | |
288 | 288 | delwin(dialog); |
289 | - free(status); | |
290 | - return 1; | |
289 | + return button; | |
291 | 290 | case TAB: |
292 | 291 | case KEY_LEFT: |
293 | 292 | case KEY_RIGHT: |
... | ... | @@ -297,30 +296,6 @@ |
297 | 296 | print_buttons(dialog, height, width, button); |
298 | 297 | wrefresh(dialog); |
299 | 298 | break; |
300 | - case 'S': | |
301 | - case 's': | |
302 | - case ' ': | |
303 | - case '\n': | |
304 | - if (!button) { | |
305 | - if (!status[scroll + choice]) { | |
306 | - for (i = 0; i < item_no; i++) | |
307 | - status[i] = 0; | |
308 | - status[scroll + choice] = 1; | |
309 | - for (i = 0; i < max_choice; i++) | |
310 | - print_item(list, items[(scroll + i) * 3 + 1], | |
311 | - status[scroll + i], i, i == choice); | |
312 | - } | |
313 | - wnoutrefresh(dialog); | |
314 | - wrefresh(list); | |
315 | - | |
316 | - for (i = 0; i < item_no; i++) | |
317 | - if (status[i]) | |
318 | - fprintf(stderr, "%s", items[i * 3]); | |
319 | - } else | |
320 | - fprintf(stderr, "%s", items[(scroll + choice) * 3]); | |
321 | - delwin(dialog); | |
322 | - free(status); | |
323 | - return button; | |
324 | 299 | case 'X': |
325 | 300 | case 'x': |
326 | 301 | key = ESC; |
327 | 302 | |
... | ... | @@ -331,9 +306,8 @@ |
331 | 306 | /* Now, update everything... */ |
332 | 307 | doupdate(); |
333 | 308 | } |
334 | - | |
309 | + delwin(list); | |
335 | 310 | delwin(dialog); |
336 | - free(status); | |
337 | - return -1; /* ESC pressed */ | |
311 | + return 255; /* ESC pressed */ | |
338 | 312 | } |
scripts/kconfig/lxdialog/dialog.h
... | ... | @@ -133,11 +133,55 @@ |
133 | 133 | * Global variables |
134 | 134 | */ |
135 | 135 | extern struct dialog_info dlg; |
136 | +extern char dialog_input_result[]; | |
136 | 137 | |
137 | 138 | /* |
138 | 139 | * Function prototypes |
139 | 140 | */ |
140 | -void init_dialog(void); | |
141 | + | |
142 | +/* item list as used by checklist and menubox */ | |
143 | +void item_reset(void); | |
144 | +void item_make(const char *fmt, ...); | |
145 | +void item_add_str(const char *fmt, ...); | |
146 | +void item_set_tag(char tag); | |
147 | +void item_set_data(void *p); | |
148 | +void item_set_selected(int val); | |
149 | +int item_activate_selected(void); | |
150 | +void *item_data(void); | |
151 | +char item_tag(void); | |
152 | + | |
153 | +/* item list manipulation for lxdialog use */ | |
154 | +#define MAXITEMSTR 200 | |
155 | +struct dialog_item { | |
156 | + char str[MAXITEMSTR]; /* promtp displayed */ | |
157 | + char tag; | |
158 | + void *data; /* pointer to menu item - used by menubox+checklist */ | |
159 | + int selected; /* Set to 1 by dialog_*() function if selected. */ | |
160 | +}; | |
161 | + | |
162 | +/* list of lialog_items */ | |
163 | +struct dialog_list { | |
164 | + struct dialog_item node; | |
165 | + struct dialog_list *next; | |
166 | +}; | |
167 | + | |
168 | +extern struct dialog_list *item_cur; | |
169 | +extern struct dialog_list item_nil; | |
170 | +extern struct dialog_list *item_head; | |
171 | + | |
172 | +int item_count(void); | |
173 | +void item_set(int n); | |
174 | +int item_n(void); | |
175 | +const char *item_str(void); | |
176 | +int item_is_selected(void); | |
177 | +int item_is_tag(char tag); | |
178 | +#define item_foreach() \ | |
179 | + for (item_cur = item_head ? item_head: item_cur; \ | |
180 | + item_cur && (item_cur != &item_nil); item_cur = item_cur->next) | |
181 | + | |
182 | + | |
183 | +void init_dialog(const char *backtitle); | |
184 | +void reset_dialog(void); | |
141 | 185 | void end_dialog(void); |
142 | 186 | void attr_clear(WINDOW * win, int height, int width, chtype attr); |
143 | 187 | void dialog_clear(void); |
144 | 188 | |
... | ... | @@ -154,11 +198,9 @@ |
154 | 198 | int width, int pause); |
155 | 199 | int dialog_textbox(const char *title, const char *file, int height, int width); |
156 | 200 | int dialog_menu(const char *title, const char *prompt, int height, int width, |
157 | - int menu_height, const char *choice, int item_no, | |
158 | - const char *const *items); | |
201 | + int menu_height, const void *selected, int *s_scroll); | |
159 | 202 | int dialog_checklist(const char *title, const char *prompt, int height, |
160 | - int width, int list_height, int item_no, | |
161 | - const char *const *items); | |
203 | + int width, int list_height); | |
162 | 204 | extern char dialog_input_result[]; |
163 | 205 | int dialog_inputbox(const char *title, const char *prompt, int height, |
164 | 206 | int width, const char *init); |
scripts/kconfig/lxdialog/inputbox.c
scripts/kconfig/lxdialog/lxdialog.c
1 | -/* | |
2 | - * dialog - Display simple dialog boxes from shell scripts | |
3 | - * | |
4 | - * ORIGINAL AUTHOR: Savio Lam (lam836@cs.cuhk.hk) | |
5 | - * MODIFIED FOR LINUX KERNEL CONFIG BY: William Roadcap (roadcap@cfw.com) | |
6 | - * | |
7 | - * This program is free software; you can redistribute it and/or | |
8 | - * modify it under the terms of the GNU General Public License | |
9 | - * as published by the Free Software Foundation; either version 2 | |
10 | - * of the License, or (at your option) any later version. | |
11 | - * | |
12 | - * This program is distributed in the hope that it will be useful, | |
13 | - * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
14 | - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
15 | - * GNU General Public License for more details. | |
16 | - * | |
17 | - * You should have received a copy of the GNU General Public License | |
18 | - * along with this program; if not, write to the Free Software | |
19 | - * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. | |
20 | - */ | |
21 | - | |
22 | -#include "dialog.h" | |
23 | - | |
24 | -static void Usage(const char *name); | |
25 | - | |
26 | -typedef int (jumperFn) (const char *title, int argc, const char *const *argv); | |
27 | - | |
28 | -struct Mode { | |
29 | - char *name; | |
30 | - int argmin, argmax, argmod; | |
31 | - jumperFn *jumper; | |
32 | -}; | |
33 | - | |
34 | -jumperFn j_menu, j_radiolist, j_yesno, j_textbox, j_inputbox; | |
35 | -jumperFn j_msgbox, j_infobox; | |
36 | - | |
37 | -static struct Mode modes[] = { | |
38 | - {"--menu", 9, 0, 3, j_menu}, | |
39 | - {"--radiolist", 9, 0, 3, j_radiolist}, | |
40 | - {"--yesno", 5, 5, 1, j_yesno}, | |
41 | - {"--textbox", 5, 5, 1, j_textbox}, | |
42 | - {"--inputbox", 5, 6, 1, j_inputbox}, | |
43 | - {"--msgbox", 5, 5, 1, j_msgbox}, | |
44 | - {"--infobox", 5, 5, 1, j_infobox}, | |
45 | - {NULL, 0, 0, 0, NULL} | |
46 | -}; | |
47 | - | |
48 | -static struct Mode *modePtr; | |
49 | - | |
50 | -#ifdef LOCALE | |
51 | -#include <locale.h> | |
52 | -#endif | |
53 | - | |
54 | -int main(int argc, const char *const *argv) | |
55 | -{ | |
56 | - int offset = 0, opt_clear = 0, end_common_opts = 0, retval; | |
57 | - const char *title = NULL; | |
58 | - | |
59 | -#ifdef LOCALE | |
60 | - (void)setlocale(LC_ALL, ""); | |
61 | -#endif | |
62 | - | |
63 | -#ifdef TRACE | |
64 | - trace(TRACE_CALLS | TRACE_UPDATE); | |
65 | -#endif | |
66 | - if (argc < 2) { | |
67 | - Usage(argv[0]); | |
68 | - exit(-1); | |
69 | - } | |
70 | - | |
71 | - while (offset < argc - 1 && !end_common_opts) { /* Common options */ | |
72 | - if (!strcmp(argv[offset + 1], "--title")) { | |
73 | - if (argc - offset < 3 || title != NULL) { | |
74 | - Usage(argv[0]); | |
75 | - exit(-1); | |
76 | - } else { | |
77 | - title = argv[offset + 2]; | |
78 | - offset += 2; | |
79 | - } | |
80 | - } else if (!strcmp(argv[offset + 1], "--backtitle")) { | |
81 | - if (dlg.backtitle != NULL) { | |
82 | - Usage(argv[0]); | |
83 | - exit(-1); | |
84 | - } else { | |
85 | - dlg.backtitle = argv[offset + 2]; | |
86 | - offset += 2; | |
87 | - } | |
88 | - } else if (!strcmp(argv[offset + 1], "--clear")) { | |
89 | - if (opt_clear) { /* Hey, "--clear" can't appear twice! */ | |
90 | - Usage(argv[0]); | |
91 | - exit(-1); | |
92 | - } else if (argc == 2) { /* we only want to clear the screen */ | |
93 | - init_dialog(); | |
94 | - refresh(); /* init_dialog() will clear the screen for us */ | |
95 | - end_dialog(); | |
96 | - return 0; | |
97 | - } else { | |
98 | - opt_clear = 1; | |
99 | - offset++; | |
100 | - } | |
101 | - } else /* no more common options */ | |
102 | - end_common_opts = 1; | |
103 | - } | |
104 | - | |
105 | - if (argc - 1 == offset) { /* no more options */ | |
106 | - Usage(argv[0]); | |
107 | - exit(-1); | |
108 | - } | |
109 | - /* use a table to look for the requested mode, to avoid code duplication */ | |
110 | - | |
111 | - for (modePtr = modes; modePtr->name; modePtr++) /* look for the mode */ | |
112 | - if (!strcmp(argv[offset + 1], modePtr->name)) | |
113 | - break; | |
114 | - | |
115 | - if (!modePtr->name) | |
116 | - Usage(argv[0]); | |
117 | - if (argc - offset < modePtr->argmin) | |
118 | - Usage(argv[0]); | |
119 | - if (modePtr->argmax && argc - offset > modePtr->argmax) | |
120 | - Usage(argv[0]); | |
121 | - | |
122 | - init_dialog(); | |
123 | - retval = (*(modePtr->jumper)) (title, argc - offset, argv + offset); | |
124 | - | |
125 | - if (opt_clear) { /* clear screen before exit */ | |
126 | - attr_clear(stdscr, LINES, COLS, dlg.screen.atr); | |
127 | - refresh(); | |
128 | - } | |
129 | - end_dialog(); | |
130 | - | |
131 | - exit(retval); | |
132 | -} | |
133 | - | |
134 | -/* | |
135 | - * Print program usage | |
136 | - */ | |
137 | -static void Usage(const char *name) | |
138 | -{ | |
139 | - fprintf(stderr, "\ | |
140 | -\ndialog, by Savio Lam (lam836@cs.cuhk.hk).\ | |
141 | -\n patched by Stuart Herbert (S.Herbert@shef.ac.uk)\ | |
142 | -\n modified/gutted for use as a Linux kernel config tool by \ | |
143 | -\n William Roadcap (roadcapw@cfw.com)\ | |
144 | -\n\ | |
145 | -\n* Display dialog boxes from shell scripts *\ | |
146 | -\n\ | |
147 | -\nUsage: %s --clear\ | |
148 | -\n %s [--title <title>] [--backtitle <backtitle>] --clear <Box options>\ | |
149 | -\n\ | |
150 | -\nBox options:\ | |
151 | -\n\ | |
152 | -\n --menu <text> <height> <width> <menu height> <tag1> <item1>...\ | |
153 | -\n --radiolist <text> <height> <width> <list height> <tag1> <item1> <status1>...\ | |
154 | -\n --textbox <file> <height> <width>\ | |
155 | -\n --inputbox <text> <height> <width> [<init>]\ | |
156 | -\n --yesno <text> <height> <width>\ | |
157 | -\n", name, name); | |
158 | - exit(-1); | |
159 | -} | |
160 | - | |
161 | -/* | |
162 | - * These are the program jumpers | |
163 | - */ | |
164 | - | |
165 | -int j_menu(const char *t, int ac, const char *const *av) | |
166 | -{ | |
167 | - return dialog_menu(t, av[2], atoi(av[3]), atoi(av[4]), | |
168 | - atoi(av[5]), av[6], (ac - 6) / 2, av + 7); | |
169 | -} | |
170 | - | |
171 | -int j_radiolist(const char *t, int ac, const char *const *av) | |
172 | -{ | |
173 | - return dialog_checklist(t, av[2], atoi(av[3]), atoi(av[4]), | |
174 | - atoi(av[5]), (ac - 6) / 3, av + 6); | |
175 | -} | |
176 | - | |
177 | -int j_textbox(const char *t, int ac, const char *const *av) | |
178 | -{ | |
179 | - return dialog_textbox(t, av[2], atoi(av[3]), atoi(av[4])); | |
180 | -} | |
181 | - | |
182 | -int j_yesno(const char *t, int ac, const char *const *av) | |
183 | -{ | |
184 | - return dialog_yesno(t, av[2], atoi(av[3]), atoi(av[4])); | |
185 | -} | |
186 | - | |
187 | -int j_inputbox(const char *t, int ac, const char *const *av) | |
188 | -{ | |
189 | - int ret = dialog_inputbox(t, av[2], atoi(av[3]), atoi(av[4]), | |
190 | - ac == 6 ? av[5] : (char *)NULL); | |
191 | - if (ret == 0) | |
192 | - fprintf(stderr, dialog_input_result); | |
193 | - return ret; | |
194 | -} | |
195 | - | |
196 | -int j_msgbox(const char *t, int ac, const char *const *av) | |
197 | -{ | |
198 | - return dialog_msgbox(t, av[2], atoi(av[3]), atoi(av[4]), 1); | |
199 | -} | |
200 | - | |
201 | -int j_infobox(const char *t, int ac, const char *const *av) | |
202 | -{ | |
203 | - return dialog_msgbox(t, av[2], atoi(av[3]), atoi(av[4]), 0); | |
204 | -} |
scripts/kconfig/lxdialog/menubox.c
... | ... | @@ -99,10 +99,10 @@ |
99 | 99 | wrefresh(win); |
100 | 100 | } |
101 | 101 | |
102 | -#define print_item(index, choice, selected) \ | |
103 | -do {\ | |
104 | - int hotkey = (items[(index) * 2][0] != ':'); \ | |
105 | - do_print_item(menu, items[(index) * 2 + 1], choice, selected, hotkey); \ | |
102 | +#define print_item(index, choice, selected) \ | |
103 | +do { \ | |
104 | + item_set(index); \ | |
105 | + do_print_item(menu, item_str(), choice, selected, !item_is_tag(':')); \ | |
106 | 106 | } while (0) |
107 | 107 | |
108 | 108 | /* |
109 | 109 | |
110 | 110 | |
... | ... | @@ -180,16 +180,14 @@ |
180 | 180 | * Display a menu for choosing among a number of options |
181 | 181 | */ |
182 | 182 | int dialog_menu(const char *title, const char *prompt, int height, int width, |
183 | - int menu_height, const char *current, int item_no, | |
184 | - const char *const *items) | |
183 | + int menu_height, const void *selected, int *s_scroll) | |
185 | 184 | { |
186 | 185 | int i, j, x, y, box_x, box_y; |
187 | 186 | int key = 0, button = 0, scroll = 0, choice = 0; |
188 | 187 | int first_item = 0, max_choice; |
189 | 188 | WINDOW *dialog, *menu; |
190 | - FILE *f; | |
191 | 189 | |
192 | - max_choice = MIN(menu_height, item_no); | |
190 | + max_choice = MIN(menu_height, item_count()); | |
193 | 191 | |
194 | 192 | /* center dialog box on screen */ |
195 | 193 | x = (COLS - width) / 2; |
196 | 194 | |
... | ... | @@ -231,28 +229,21 @@ |
231 | 229 | item_x = (menu_width - 70) / 2; |
232 | 230 | |
233 | 231 | /* Set choice to default item */ |
234 | - for (i = 0; i < item_no; i++) | |
235 | - if (strcmp(current, items[i * 2]) == 0) | |
236 | - choice = i; | |
237 | - | |
238 | - /* get the scroll info from the temp file */ | |
239 | - if ((f = fopen("lxdialog.scrltmp", "r")) != NULL) { | |
240 | - if ((fscanf(f, "%d\n", &scroll) == 1) && (scroll <= choice) && | |
241 | - (scroll + max_choice > choice) && (scroll >= 0) && | |
242 | - (scroll + max_choice <= item_no)) { | |
243 | - first_item = scroll; | |
244 | - choice = choice - scroll; | |
245 | - fclose(f); | |
246 | - } else { | |
247 | - scroll = 0; | |
248 | - remove("lxdialog.scrltmp"); | |
249 | - fclose(f); | |
250 | - f = NULL; | |
251 | - } | |
232 | + item_foreach() | |
233 | + if (selected && (selected == item_data())) | |
234 | + choice = item_n(); | |
235 | + /* get the saved scroll info */ | |
236 | + scroll = *s_scroll; | |
237 | + if ((scroll <= choice) && (scroll + max_choice > choice) && | |
238 | + (scroll >= 0) && (scroll + max_choice <= item_count())) { | |
239 | + first_item = scroll; | |
240 | + choice = choice - scroll; | |
241 | + } else { | |
242 | + scroll = 0; | |
252 | 243 | } |
253 | - if ((choice >= max_choice) || (f == NULL && choice >= max_choice / 2)) { | |
254 | - if (choice >= item_no - max_choice / 2) | |
255 | - scroll = first_item = item_no - max_choice; | |
244 | + if ((choice >= max_choice)) { | |
245 | + if (choice >= item_count() - max_choice / 2) | |
246 | + scroll = first_item = item_count() - max_choice; | |
256 | 247 | else |
257 | 248 | scroll = first_item = choice - max_choice / 2; |
258 | 249 | choice = choice - scroll; |
... | ... | @@ -265,7 +256,7 @@ |
265 | 256 | |
266 | 257 | wnoutrefresh(menu); |
267 | 258 | |
268 | - print_arrows(dialog, item_no, scroll, | |
259 | + print_arrows(dialog, item_count(), scroll, | |
269 | 260 | box_y, box_x + item_x + 1, menu_height); |
270 | 261 | |
271 | 262 | print_buttons(dialog, height, width, 0); |
272 | 263 | |
... | ... | @@ -282,14 +273,16 @@ |
282 | 273 | i = max_choice; |
283 | 274 | else { |
284 | 275 | for (i = choice + 1; i < max_choice; i++) { |
285 | - j = first_alpha(items[(scroll + i) * 2 + 1], "YyNnMmHh"); | |
286 | - if (key == tolower(items[(scroll + i) * 2 + 1][j])) | |
276 | + item_set(scroll + i); | |
277 | + j = first_alpha(item_str(), "YyNnMmHh"); | |
278 | + if (key == tolower(item_str()[j])) | |
287 | 279 | break; |
288 | 280 | } |
289 | 281 | if (i == max_choice) |
290 | 282 | for (i = 0; i < max_choice; i++) { |
291 | - j = first_alpha(items [(scroll + i) * 2 + 1], "YyNnMmHh"); | |
292 | - if (key == tolower(items[(scroll + i) * 2 + 1][j])) | |
283 | + item_set(scroll + i); | |
284 | + j = first_alpha(item_str(), "YyNnMmHh"); | |
285 | + if (key == tolower(item_str()[j])) | |
293 | 286 | break; |
294 | 287 | } |
295 | 288 | } |
... | ... | @@ -314,7 +307,7 @@ |
314 | 307 | print_item(scroll+choice, choice, FALSE); |
315 | 308 | |
316 | 309 | if ((choice > max_choice - 3) && |
317 | - (scroll + max_choice < item_no)) { | |
310 | + (scroll + max_choice < item_count())) { | |
318 | 311 | /* Scroll menu up */ |
319 | 312 | do_scroll(menu, &scroll, 1); |
320 | 313 | |
... | ... | @@ -337,7 +330,7 @@ |
337 | 330 | |
338 | 331 | } else if (key == KEY_NPAGE) { |
339 | 332 | for (i = 0; (i < max_choice); i++) { |
340 | - if (scroll + max_choice < item_no) { | |
333 | + if (scroll + max_choice < item_count()) { | |
341 | 334 | do_scroll(menu, &scroll, 1); |
342 | 335 | print_item(scroll+max_choice-1, |
343 | 336 | max_choice - 1, FALSE); |
... | ... | @@ -351,7 +344,7 @@ |
351 | 344 | |
352 | 345 | print_item(scroll + choice, choice, TRUE); |
353 | 346 | |
354 | - print_arrows(dialog, item_no, scroll, | |
347 | + print_arrows(dialog, item_count(), scroll, | |
355 | 348 | box_y, box_x + item_x + 1, menu_height); |
356 | 349 | |
357 | 350 | wnoutrefresh(dialog); |
358 | 351 | |
... | ... | @@ -377,12 +370,11 @@ |
377 | 370 | case 'm': |
378 | 371 | case '/': |
379 | 372 | /* save scroll info */ |
380 | - if ((f = fopen("lxdialog.scrltmp", "w")) != NULL) { | |
381 | - fprintf(f, "%d\n", scroll); | |
382 | - fclose(f); | |
383 | - } | |
373 | + *s_scroll = scroll; | |
374 | + delwin(menu); | |
384 | 375 | delwin(dialog); |
385 | - fprintf(stderr, "%s\n", items[(scroll + choice) * 2]); | |
376 | + item_set(scroll + choice); | |
377 | + item_set_selected(1); | |
386 | 378 | switch (key) { |
387 | 379 | case 's': |
388 | 380 | return 3; |
389 | 381 | |
... | ... | @@ -402,17 +394,11 @@ |
402 | 394 | case '?': |
403 | 395 | button = 2; |
404 | 396 | case '\n': |
397 | + *s_scroll = scroll; | |
398 | + delwin(menu); | |
405 | 399 | delwin(dialog); |
406 | - if (button == 2) | |
407 | - fprintf(stderr, "%s \"%s\"\n", | |
408 | - items[(scroll + choice) * 2], | |
409 | - items[(scroll + choice) * 2 + 1] + | |
410 | - first_alpha(items [(scroll + choice) * 2 + 1], "")); | |
411 | - else | |
412 | - fprintf(stderr, "%s\n", | |
413 | - items[(scroll + choice) * 2]); | |
414 | - | |
415 | - remove("lxdialog.scrltmp"); | |
400 | + item_set(scroll + choice); | |
401 | + item_set_selected(1); | |
416 | 402 | return button; |
417 | 403 | case 'e': |
418 | 404 | case 'x': |
419 | 405 | |
... | ... | @@ -421,9 +407,8 @@ |
421 | 407 | break; |
422 | 408 | } |
423 | 409 | } |
424 | - | |
410 | + delwin(menu); | |
425 | 411 | delwin(dialog); |
426 | - remove("lxdialog.scrltmp"); | |
427 | - return -1; /* ESC pressed */ | |
412 | + return 255; /* ESC pressed */ | |
428 | 413 | } |
scripts/kconfig/lxdialog/msgbox.c
1 | -/* | |
2 | - * msgbox.c -- implements the message box and info box | |
3 | - * | |
4 | - * ORIGINAL AUTHOR: Savio Lam (lam836@cs.cuhk.hk) | |
5 | - * MODIFIED FOR LINUX KERNEL CONFIG BY: William Roadcap (roadcapw@cfw.com) | |
6 | - * | |
7 | - * This program is free software; you can redistribute it and/or | |
8 | - * modify it under the terms of the GNU General Public License | |
9 | - * as published by the Free Software Foundation; either version 2 | |
10 | - * of the License, or (at your option) any later version. | |
11 | - * | |
12 | - * This program is distributed in the hope that it will be useful, | |
13 | - * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
14 | - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
15 | - * GNU General Public License for more details. | |
16 | - * | |
17 | - * You should have received a copy of the GNU General Public License | |
18 | - * along with this program; if not, write to the Free Software | |
19 | - * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. | |
20 | - */ | |
21 | - | |
22 | -#include "dialog.h" | |
23 | - | |
24 | -/* | |
25 | - * Display a message box. Program will pause and display an "OK" button | |
26 | - * if the parameter 'pause' is non-zero. | |
27 | - */ | |
28 | -int dialog_msgbox(const char *title, const char *prompt, int height, int width, | |
29 | - int pause) | |
30 | -{ | |
31 | - int i, x, y, key = 0; | |
32 | - WINDOW *dialog; | |
33 | - | |
34 | - /* center dialog box on screen */ | |
35 | - x = (COLS - width) / 2; | |
36 | - y = (LINES - height) / 2; | |
37 | - | |
38 | - draw_shadow(stdscr, y, x, height, width); | |
39 | - | |
40 | - dialog = newwin(height, width, y, x); | |
41 | - keypad(dialog, TRUE); | |
42 | - | |
43 | - draw_box(dialog, 0, 0, height, width, | |
44 | - dlg.dialog.atr, dlg.border.atr); | |
45 | - | |
46 | - print_title(dialog, title, width); | |
47 | - | |
48 | - wattrset(dialog, dlg.dialog.atr); | |
49 | - print_autowrap(dialog, prompt, width - 2, 1, 2); | |
50 | - | |
51 | - if (pause) { | |
52 | - wattrset(dialog, dlg.border.atr); | |
53 | - mvwaddch(dialog, height - 3, 0, ACS_LTEE); | |
54 | - for (i = 0; i < width - 2; i++) | |
55 | - waddch(dialog, ACS_HLINE); | |
56 | - wattrset(dialog, dlg.dialog.atr); | |
57 | - waddch(dialog, ACS_RTEE); | |
58 | - | |
59 | - print_button(dialog, " Ok ", height - 2, width / 2 - 4, TRUE); | |
60 | - | |
61 | - wrefresh(dialog); | |
62 | - while (key != ESC && key != '\n' && key != ' ' && | |
63 | - key != 'O' && key != 'o' && key != 'X' && key != 'x') | |
64 | - key = wgetch(dialog); | |
65 | - } else { | |
66 | - key = '\n'; | |
67 | - wrefresh(dialog); | |
68 | - } | |
69 | - | |
70 | - delwin(dialog); | |
71 | - return key == ESC ? -1 : 0; | |
72 | -} |
scripts/kconfig/lxdialog/textbox.c
... | ... | @@ -27,55 +27,28 @@ |
27 | 27 | static char *get_line(void); |
28 | 28 | static void print_position(WINDOW * win, int height, int width); |
29 | 29 | |
30 | -static int hscroll, fd, file_size, bytes_read; | |
31 | -static int begin_reached = 1, end_reached, page_length; | |
32 | -static char *buf, *page; | |
30 | +static int hscroll; | |
31 | +static int begin_reached, end_reached, page_length; | |
32 | +static const char *buf; | |
33 | +static const char *page; | |
33 | 34 | |
34 | 35 | /* |
35 | 36 | * Display text from a file in a dialog box. |
36 | 37 | */ |
37 | -int dialog_textbox(const char *title, const char *file, int height, int width) | |
38 | +int dialog_textbox(const char *title, const char *tbuf, int height, int width) | |
38 | 39 | { |
39 | - int i, x, y, cur_x, cur_y, fpos, key = 0; | |
40 | + int i, x, y, cur_x, cur_y, key = 0; | |
41 | + int texth, textw; | |
40 | 42 | int passed_end; |
41 | - char search_term[MAX_LEN + 1]; | |
42 | 43 | WINDOW *dialog, *text; |
43 | 44 | |
44 | - search_term[0] = '\0'; /* no search term entered yet */ | |
45 | + begin_reached = 1; | |
46 | + end_reached = 0; | |
47 | + page_length = 0; | |
48 | + hscroll = 0; | |
49 | + buf = tbuf; | |
50 | + page = buf; /* page is pointer to start of page to be displayed */ | |
45 | 51 | |
46 | - /* Open input file for reading */ | |
47 | - if ((fd = open(file, O_RDONLY)) == -1) { | |
48 | - endwin(); | |
49 | - fprintf(stderr, "\nCan't open input file in dialog_textbox().\n"); | |
50 | - exit(-1); | |
51 | - } | |
52 | - /* Get file size. Actually, 'file_size' is the real file size - 1, | |
53 | - since it's only the last byte offset from the beginning */ | |
54 | - if ((file_size = lseek(fd, 0, SEEK_END)) == -1) { | |
55 | - endwin(); | |
56 | - fprintf(stderr, "\nError getting file size in dialog_textbox().\n"); | |
57 | - exit(-1); | |
58 | - } | |
59 | - /* Restore file pointer to beginning of file after getting file size */ | |
60 | - if (lseek(fd, 0, SEEK_SET) == -1) { | |
61 | - endwin(); | |
62 | - fprintf(stderr, "\nError moving file pointer in dialog_textbox().\n"); | |
63 | - exit(-1); | |
64 | - } | |
65 | - /* Allocate space for read buffer */ | |
66 | - if ((buf = malloc(BUF_SIZE + 1)) == NULL) { | |
67 | - endwin(); | |
68 | - fprintf(stderr, "\nCan't allocate memory in dialog_textbox().\n"); | |
69 | - exit(-1); | |
70 | - } | |
71 | - if ((bytes_read = read(fd, buf, BUF_SIZE)) == -1) { | |
72 | - endwin(); | |
73 | - fprintf(stderr, "\nError reading file in dialog_textbox().\n"); | |
74 | - exit(-1); | |
75 | - } | |
76 | - buf[bytes_read] = '\0'; /* mark end of valid data */ | |
77 | - page = buf; /* page is pointer to start of page to be displayed */ | |
78 | - | |
79 | 52 | /* center dialog box on screen */ |
80 | 53 | x = (COLS - width) / 2; |
81 | 54 | y = (LINES - height) / 2; |
... | ... | @@ -86,7 +59,9 @@ |
86 | 59 | keypad(dialog, TRUE); |
87 | 60 | |
88 | 61 | /* Create window for text region, used for scrolling text */ |
89 | - text = subwin(dialog, height - 4, width - 2, y + 1, x + 1); | |
62 | + texth = height - 4; | |
63 | + textw = width - 2; | |
64 | + text = subwin(dialog, texth, textw, y + 1, x + 1); | |
90 | 65 | wattrset(text, dlg.dialog.atr); |
91 | 66 | wbkgdset(text, dlg.dialog.atr & A_COLOR); |
92 | 67 | |
... | ... | @@ -111,8 +86,8 @@ |
111 | 86 | getyx(dialog, cur_y, cur_x); /* Save cursor position */ |
112 | 87 | |
113 | 88 | /* Print first page of text */ |
114 | - attr_clear(text, height - 4, width - 2, dlg.dialog.atr); | |
115 | - print_page(text, height - 4, width - 2); | |
89 | + attr_clear(text, texth, textw, dlg.dialog.atr); | |
90 | + print_page(text, texth, textw); | |
116 | 91 | print_position(dialog, height, width); |
117 | 92 | wmove(dialog, cur_y, cur_x); /* Restore cursor position */ |
118 | 93 | wrefresh(dialog); |
119 | 94 | |
120 | 95 | |
121 | 96 | |
... | ... | @@ -124,37 +99,15 @@ |
124 | 99 | case 'e': |
125 | 100 | case 'X': |
126 | 101 | case 'x': |
102 | + delwin(text); | |
127 | 103 | delwin(dialog); |
128 | - free(buf); | |
129 | - close(fd); | |
130 | 104 | return 0; |
131 | 105 | case 'g': /* First page */ |
132 | 106 | case KEY_HOME: |
133 | 107 | if (!begin_reached) { |
134 | 108 | begin_reached = 1; |
135 | - /* First page not in buffer? */ | |
136 | - if ((fpos = lseek(fd, 0, SEEK_CUR)) == -1) { | |
137 | - endwin(); | |
138 | - fprintf(stderr, "\nError moving file pointer in dialog_textbox().\n"); | |
139 | - exit(-1); | |
140 | - } | |
141 | - if (fpos > bytes_read) { /* Yes, we have to read it in */ | |
142 | - if (lseek(fd, 0, SEEK_SET) == -1) { | |
143 | - endwin(); | |
144 | - fprintf(stderr, "\nError moving file pointer in " | |
145 | - "dialog_textbox().\n"); | |
146 | - exit(-1); | |
147 | - } | |
148 | - if ((bytes_read = | |
149 | - read(fd, buf, BUF_SIZE)) == -1) { | |
150 | - endwin(); | |
151 | - fprintf(stderr, "\nError reading file in dialog_textbox().\n"); | |
152 | - exit(-1); | |
153 | - } | |
154 | - buf[bytes_read] = '\0'; | |
155 | - } | |
156 | 109 | page = buf; |
157 | - print_page(text, height - 4, width - 2); | |
110 | + print_page(text, texth, textw); | |
158 | 111 | print_position(dialog, height, width); |
159 | 112 | wmove(dialog, cur_y, cur_x); /* Restore cursor position */ |
160 | 113 | wrefresh(dialog); |
... | ... | @@ -164,29 +117,10 @@ |
164 | 117 | case KEY_END: |
165 | 118 | |
166 | 119 | end_reached = 1; |
167 | - /* Last page not in buffer? */ | |
168 | - if ((fpos = lseek(fd, 0, SEEK_CUR)) == -1) { | |
169 | - endwin(); | |
170 | - fprintf(stderr, "\nError moving file pointer in dialog_textbox().\n"); | |
171 | - exit(-1); | |
172 | - } | |
173 | - if (fpos < file_size) { /* Yes, we have to read it in */ | |
174 | - if (lseek(fd, -BUF_SIZE, SEEK_END) == -1) { | |
175 | - endwin(); | |
176 | - fprintf(stderr, "\nError moving file pointer in dialog_textbox().\n"); | |
177 | - exit(-1); | |
178 | - } | |
179 | - if ((bytes_read = | |
180 | - read(fd, buf, BUF_SIZE)) == -1) { | |
181 | - endwin(); | |
182 | - fprintf(stderr, "\nError reading file in dialog_textbox().\n"); | |
183 | - exit(-1); | |
184 | - } | |
185 | - buf[bytes_read] = '\0'; | |
186 | - } | |
187 | - page = buf + bytes_read; | |
188 | - back_lines(height - 4); | |
189 | - print_page(text, height - 4, width - 2); | |
120 | + /* point to last char in buf */ | |
121 | + page = buf + strlen(buf); | |
122 | + back_lines(texth); | |
123 | + print_page(text, texth, textw); | |
190 | 124 | print_position(dialog, height, width); |
191 | 125 | wmove(dialog, cur_y, cur_x); /* Restore cursor position */ |
192 | 126 | wrefresh(dialog); |
193 | 127 | |
194 | 128 | |
... | ... | @@ -197,20 +131,22 @@ |
197 | 131 | if (!begin_reached) { |
198 | 132 | back_lines(page_length + 1); |
199 | 133 | |
200 | - /* We don't call print_page() here but use scrolling to ensure | |
201 | - faster screen update. However, 'end_reached' and | |
202 | - 'page_length' should still be updated, and 'page' should | |
203 | - point to start of next page. This is done by calling | |
204 | - get_line() in the following 'for' loop. */ | |
134 | + /* We don't call print_page() here but use | |
135 | + * scrolling to ensure faster screen update. | |
136 | + * However, 'end_reached' and 'page_length' | |
137 | + * should still be updated, and 'page' should | |
138 | + * point to start of next page. This is done | |
139 | + * by calling get_line() in the following | |
140 | + * 'for' loop. */ | |
205 | 141 | scrollok(text, TRUE); |
206 | 142 | wscrl(text, -1); /* Scroll text region down one line */ |
207 | 143 | scrollok(text, FALSE); |
208 | 144 | page_length = 0; |
209 | 145 | passed_end = 0; |
210 | - for (i = 0; i < height - 4; i++) { | |
146 | + for (i = 0; i < texth; i++) { | |
211 | 147 | if (!i) { |
212 | 148 | /* print first line of page */ |
213 | - print_line(text, 0, width - 2); | |
149 | + print_line(text, 0, textw); | |
214 | 150 | wnoutrefresh(text); |
215 | 151 | } else |
216 | 152 | /* Called to update 'end_reached' and 'page' */ |
... | ... | @@ -231,8 +167,8 @@ |
231 | 167 | case KEY_PPAGE: |
232 | 168 | if (begin_reached) |
233 | 169 | break; |
234 | - back_lines(page_length + height - 4); | |
235 | - print_page(text, height - 4, width - 2); | |
170 | + back_lines(page_length + texth); | |
171 | + print_page(text, texth, textw); | |
236 | 172 | print_position(dialog, height, width); |
237 | 173 | wmove(dialog, cur_y, cur_x); |
238 | 174 | wrefresh(dialog); |
... | ... | @@ -245,7 +181,7 @@ |
245 | 181 | scrollok(text, TRUE); |
246 | 182 | scroll(text); /* Scroll text region up one line */ |
247 | 183 | scrollok(text, FALSE); |
248 | - print_line(text, height - 5, width - 2); | |
184 | + print_line(text, texth - 1, textw); | |
249 | 185 | wnoutrefresh(text); |
250 | 186 | print_position(dialog, height, width); |
251 | 187 | wmove(dialog, cur_y, cur_x); /* Restore cursor position */ |
... | ... | @@ -258,7 +194,7 @@ |
258 | 194 | break; |
259 | 195 | |
260 | 196 | begin_reached = 0; |
261 | - print_page(text, height - 4, width - 2); | |
197 | + print_page(text, texth, textw); | |
262 | 198 | print_position(dialog, height, width); |
263 | 199 | wmove(dialog, cur_y, cur_x); |
264 | 200 | wrefresh(dialog); |
... | ... | @@ -276,7 +212,7 @@ |
276 | 212 | hscroll--; |
277 | 213 | /* Reprint current page to scroll horizontally */ |
278 | 214 | back_lines(page_length); |
279 | - print_page(text, height - 4, width - 2); | |
215 | + print_page(text, texth, textw); | |
280 | 216 | wmove(dialog, cur_y, cur_x); |
281 | 217 | wrefresh(dialog); |
282 | 218 | break; |
... | ... | @@ -288,7 +224,7 @@ |
288 | 224 | hscroll++; |
289 | 225 | /* Reprint current page to scroll horizontally */ |
290 | 226 | back_lines(page_length); |
291 | - print_page(text, height - 4, width - 2); | |
227 | + print_page(text, texth, textw); | |
292 | 228 | wmove(dialog, cur_y, cur_x); |
293 | 229 | wrefresh(dialog); |
294 | 230 | break; |
295 | 231 | |
296 | 232 | |
297 | 233 | |
298 | 234 | |
299 | 235 | |
300 | 236 | |
301 | 237 | |
302 | 238 | |
303 | 239 | |
... | ... | @@ -296,123 +232,42 @@ |
296 | 232 | break; |
297 | 233 | } |
298 | 234 | } |
299 | - | |
235 | + delwin(text); | |
300 | 236 | delwin(dialog); |
301 | - free(buf); | |
302 | - close(fd); | |
303 | - return -1; /* ESC pressed */ | |
237 | + return 255; /* ESC pressed */ | |
304 | 238 | } |
305 | 239 | |
306 | 240 | /* |
307 | - * Go back 'n' lines in text file. Called by dialog_textbox(). | |
241 | + * Go back 'n' lines in text. Called by dialog_textbox(). | |
308 | 242 | * 'page' will be updated to point to the desired line in 'buf'. |
309 | 243 | */ |
310 | 244 | static void back_lines(int n) |
311 | 245 | { |
312 | - int i, fpos; | |
246 | + int i; | |
313 | 247 | |
314 | 248 | begin_reached = 0; |
315 | - /* We have to distinguish between end_reached and !end_reached | |
316 | - since at end of file, the line is not ended by a '\n'. | |
317 | - The code inside 'if' basically does a '--page' to move one | |
318 | - character backward so as to skip '\n' of the previous line */ | |
319 | - if (!end_reached) { | |
320 | - /* Either beginning of buffer or beginning of file reached? */ | |
321 | - if (page == buf) { | |
322 | - if ((fpos = lseek(fd, 0, SEEK_CUR)) == -1) { | |
323 | - endwin(); | |
324 | - fprintf(stderr, "\nError moving file pointer in " | |
325 | - "back_lines().\n"); | |
326 | - exit(-1); | |
249 | + /* Go back 'n' lines */ | |
250 | + for (i = 0; i < n; i++) { | |
251 | + if (*page == '\0') { | |
252 | + if (end_reached) { | |
253 | + end_reached = 0; | |
254 | + continue; | |
327 | 255 | } |
328 | - if (fpos > bytes_read) { /* Not beginning of file yet */ | |
329 | - /* We've reached beginning of buffer, but not beginning of | |
330 | - file yet, so read previous part of file into buffer. | |
331 | - Note that we only move backward for BUF_SIZE/2 bytes, | |
332 | - but not BUF_SIZE bytes to avoid re-reading again in | |
333 | - print_page() later */ | |
334 | - /* Really possible to move backward BUF_SIZE/2 bytes? */ | |
335 | - if (fpos < BUF_SIZE / 2 + bytes_read) { | |
336 | - /* No, move less then */ | |
337 | - if (lseek(fd, 0, SEEK_SET) == -1) { | |
338 | - endwin(); | |
339 | - fprintf(stderr, "\nError moving file pointer in " | |
340 | - "back_lines().\n"); | |
341 | - exit(-1); | |
342 | - } | |
343 | - page = buf + fpos - bytes_read; | |
344 | - } else { /* Move backward BUF_SIZE/2 bytes */ | |
345 | - if (lseek (fd, -(BUF_SIZE / 2 + bytes_read), SEEK_CUR) == -1) { | |
346 | - endwin(); | |
347 | - fprintf(stderr, "\nError moving file pointer " | |
348 | - "in back_lines().\n"); | |
349 | - exit(-1); | |
350 | - } | |
351 | - page = buf + BUF_SIZE / 2; | |
352 | - } | |
353 | - if ((bytes_read = | |
354 | - read(fd, buf, BUF_SIZE)) == -1) { | |
355 | - endwin(); | |
356 | - fprintf(stderr, "\nError reading file in back_lines().\n"); | |
357 | - exit(-1); | |
358 | - } | |
359 | - buf[bytes_read] = '\0'; | |
360 | - } else { /* Beginning of file reached */ | |
361 | - begin_reached = 1; | |
362 | - return; | |
363 | - } | |
364 | 256 | } |
365 | - if (*(--page) != '\n') { /* '--page' here */ | |
366 | - /* Something's wrong... */ | |
367 | - endwin(); | |
368 | - fprintf(stderr, "\nInternal error in back_lines().\n"); | |
369 | - exit(-1); | |
257 | + if (page == buf) { | |
258 | + begin_reached = 1; | |
259 | + return; | |
370 | 260 | } |
371 | - } | |
372 | - /* Go back 'n' lines */ | |
373 | - for (i = 0; i < n; i++) | |
261 | + page--; | |
374 | 262 | do { |
375 | 263 | if (page == buf) { |
376 | - if ((fpos = lseek(fd, 0, SEEK_CUR)) == -1) { | |
377 | - endwin(); | |
378 | - fprintf(stderr, "\nError moving file pointer in back_lines().\n"); | |
379 | - exit(-1); | |
380 | - } | |
381 | - if (fpos > bytes_read) { | |
382 | - /* Really possible to move backward BUF_SIZE/2 bytes? */ | |
383 | - if (fpos < BUF_SIZE / 2 + bytes_read) { | |
384 | - /* No, move less then */ | |
385 | - if (lseek(fd, 0, SEEK_SET) == -1) { | |
386 | - endwin(); | |
387 | - fprintf(stderr, "\nError moving file pointer " | |
388 | - "in back_lines().\n"); | |
389 | - exit(-1); | |
390 | - } | |
391 | - page = buf + fpos - bytes_read; | |
392 | - } else { /* Move backward BUF_SIZE/2 bytes */ | |
393 | - if (lseek (fd, -(BUF_SIZE / 2 + bytes_read), SEEK_CUR) == -1) { | |
394 | - endwin(); | |
395 | - fprintf(stderr, "\nError moving file pointer" | |
396 | - " in back_lines().\n"); | |
397 | - exit(-1); | |
398 | - } | |
399 | - page = buf + BUF_SIZE / 2; | |
400 | - } | |
401 | - if ((bytes_read = | |
402 | - read(fd, buf, BUF_SIZE)) == -1) { | |
403 | - endwin(); | |
404 | - fprintf(stderr, "\nError reading file in " | |
405 | - "back_lines().\n"); | |
406 | - exit(-1); | |
407 | - } | |
408 | - buf[bytes_read] = '\0'; | |
409 | - } else { /* Beginning of file reached */ | |
410 | - begin_reached = 1; | |
411 | - return; | |
412 | - } | |
264 | + begin_reached = 1; | |
265 | + return; | |
413 | 266 | } |
414 | - } while (*(--page) != '\n'); | |
415 | - page++; | |
267 | + page--; | |
268 | + } while (*page != '\n'); | |
269 | + page++; | |
270 | + } | |
416 | 271 | } |
417 | 272 | |
418 | 273 | /* |
419 | 274 | |
... | ... | @@ -467,33 +322,14 @@ |
467 | 322 | */ |
468 | 323 | static char *get_line(void) |
469 | 324 | { |
470 | - int i = 0, fpos; | |
325 | + int i = 0; | |
471 | 326 | static char line[MAX_LEN + 1]; |
472 | 327 | |
473 | 328 | end_reached = 0; |
474 | 329 | while (*page != '\n') { |
475 | 330 | if (*page == '\0') { |
476 | - /* Either end of file or end of buffer reached */ | |
477 | - if ((fpos = lseek(fd, 0, SEEK_CUR)) == -1) { | |
478 | - endwin(); | |
479 | - fprintf(stderr, "\nError moving file pointer in " | |
480 | - "get_line().\n"); | |
481 | - exit(-1); | |
482 | - } | |
483 | - if (fpos < file_size) { /* Not end of file yet */ | |
484 | - /* We've reached end of buffer, but not end of file yet, | |
485 | - so read next part of file into buffer */ | |
486 | - if ((bytes_read = | |
487 | - read(fd, buf, BUF_SIZE)) == -1) { | |
488 | - endwin(); | |
489 | - fprintf(stderr, "\nError reading file in get_line().\n"); | |
490 | - exit(-1); | |
491 | - } | |
492 | - buf[bytes_read] = '\0'; | |
493 | - page = buf; | |
494 | - } else { | |
495 | - if (!end_reached) | |
496 | - end_reached = 1; | |
331 | + if (!end_reached) { | |
332 | + end_reached = 1; | |
497 | 333 | break; |
498 | 334 | } |
499 | 335 | } else if (i < MAX_LEN) |
500 | 336 | |
501 | 337 | |
... | ... | @@ -518,17 +354,11 @@ |
518 | 354 | */ |
519 | 355 | static void print_position(WINDOW * win, int height, int width) |
520 | 356 | { |
521 | - int fpos, percent; | |
357 | + int percent; | |
522 | 358 | |
523 | - if ((fpos = lseek(fd, 0, SEEK_CUR)) == -1) { | |
524 | - endwin(); | |
525 | - fprintf(stderr, "\nError moving file pointer in print_position().\n"); | |
526 | - exit(-1); | |
527 | - } | |
528 | 359 | wattrset(win, dlg.position_indicator.atr); |
529 | 360 | wbkgdset(win, dlg.position_indicator.atr & A_COLOR); |
530 | - percent = !file_size ? | |
531 | - 100 : ((fpos - bytes_read + page - buf) * 100) / file_size; | |
361 | + percent = (page - buf) * 100 / strlen(buf); | |
532 | 362 | wmove(win, height - 3, width - 9); |
533 | 363 | wprintw(win, "(%3d%%)", percent); |
534 | 364 | } |
scripts/kconfig/lxdialog/util.c
... | ... | @@ -268,13 +268,18 @@ |
268 | 268 | /* |
269 | 269 | * Do some initialization for dialog |
270 | 270 | */ |
271 | -void init_dialog(void) | |
271 | +void init_dialog(const char *backtitle) | |
272 | 272 | { |
273 | + dlg.backtitle = backtitle; | |
274 | + color_setup(getenv("MENUCONFIG_COLOR")); | |
275 | +} | |
276 | + | |
277 | +void reset_dialog(void) | |
278 | +{ | |
273 | 279 | initscr(); /* Init curses */ |
274 | 280 | keypad(stdscr, TRUE); |
275 | 281 | cbreak(); |
276 | 282 | noecho(); |
277 | - color_setup(getenv("MENUCONFIG_COLOR")); | |
278 | 283 | dialog_clear(); |
279 | 284 | } |
280 | 285 | |
... | ... | @@ -470,5 +475,130 @@ |
470 | 475 | } |
471 | 476 | |
472 | 477 | return 0; |
478 | +} | |
479 | + | |
480 | +struct dialog_list *item_cur; | |
481 | +struct dialog_list item_nil; | |
482 | +struct dialog_list *item_head; | |
483 | + | |
484 | +void item_reset(void) | |
485 | +{ | |
486 | + struct dialog_list *p, *next; | |
487 | + | |
488 | + for (p = item_head; p; p = next) { | |
489 | + next = p->next; | |
490 | + free(p); | |
491 | + } | |
492 | + item_head = NULL; | |
493 | + item_cur = &item_nil; | |
494 | +} | |
495 | + | |
496 | +void item_make(const char *fmt, ...) | |
497 | +{ | |
498 | + va_list ap; | |
499 | + struct dialog_list *p = malloc(sizeof(*p)); | |
500 | + | |
501 | + if (item_head) | |
502 | + item_cur->next = p; | |
503 | + else | |
504 | + item_head = p; | |
505 | + item_cur = p; | |
506 | + memset(p, 0, sizeof(*p)); | |
507 | + | |
508 | + va_start(ap, fmt); | |
509 | + vsnprintf(item_cur->node.str, sizeof(item_cur->node.str), fmt, ap); | |
510 | + va_end(ap); | |
511 | +} | |
512 | + | |
513 | +void item_add_str(const char *fmt, ...) | |
514 | +{ | |
515 | + va_list ap; | |
516 | + size_t avail; | |
517 | + | |
518 | + avail = sizeof(item_cur->node.str) - strlen(item_cur->node.str); | |
519 | + | |
520 | + va_start(ap, fmt); | |
521 | + vsnprintf(item_cur->node.str + strlen(item_cur->node.str), | |
522 | + avail, fmt, ap); | |
523 | + item_cur->node.str[sizeof(item_cur->node.str) - 1] = '\0'; | |
524 | + va_end(ap); | |
525 | +} | |
526 | + | |
527 | +void item_set_tag(char tag) | |
528 | +{ | |
529 | + item_cur->node.tag = tag; | |
530 | +} | |
531 | +void item_set_data(void *ptr) | |
532 | +{ | |
533 | + item_cur->node.data = ptr; | |
534 | +} | |
535 | + | |
536 | +void item_set_selected(int val) | |
537 | +{ | |
538 | + item_cur->node.selected = val; | |
539 | +} | |
540 | + | |
541 | +int item_activate_selected(void) | |
542 | +{ | |
543 | + item_foreach() | |
544 | + if (item_is_selected()) | |
545 | + return 1; | |
546 | + return 0; | |
547 | +} | |
548 | + | |
549 | +void *item_data(void) | |
550 | +{ | |
551 | + return item_cur->node.data; | |
552 | +} | |
553 | + | |
554 | +char item_tag(void) | |
555 | +{ | |
556 | + return item_cur->node.tag; | |
557 | +} | |
558 | + | |
559 | +int item_count(void) | |
560 | +{ | |
561 | + int n = 0; | |
562 | + struct dialog_list *p; | |
563 | + | |
564 | + for (p = item_head; p; p = p->next) | |
565 | + n++; | |
566 | + return n; | |
567 | +} | |
568 | + | |
569 | +void item_set(int n) | |
570 | +{ | |
571 | + int i = 0; | |
572 | + item_foreach() | |
573 | + if (i++ == n) | |
574 | + return; | |
575 | +} | |
576 | + | |
577 | +int item_n(void) | |
578 | +{ | |
579 | + int n = 0; | |
580 | + struct dialog_list *p; | |
581 | + | |
582 | + for (p = item_head; p; p = p->next) { | |
583 | + if (p == item_cur) | |
584 | + return n; | |
585 | + n++; | |
586 | + } | |
587 | + return 0; | |
588 | +} | |
589 | + | |
590 | +const char *item_str(void) | |
591 | +{ | |
592 | + return item_cur->node.str; | |
593 | +} | |
594 | + | |
595 | +int item_is_selected(void) | |
596 | +{ | |
597 | + return (item_cur->node.selected != 0); | |
598 | +} | |
599 | + | |
600 | +int item_is_tag(char tag) | |
601 | +{ | |
602 | + return (item_cur->node.tag == tag); | |
473 | 603 | } |
scripts/kconfig/lxdialog/yesno.c
scripts/kconfig/mconf.c
... | ... | @@ -24,6 +24,7 @@ |
24 | 24 | |
25 | 25 | #define LKC_DIRECT_LINK |
26 | 26 | #include "lkc.h" |
27 | +#include "lxdialog/dialog.h" | |
27 | 28 | |
28 | 29 | static char menu_backtitle[128]; |
29 | 30 | static const char mconf_readme[] = N_( |
30 | 31 | |
31 | 32 | |
... | ... | @@ -270,16 +271,12 @@ |
270 | 271 | " USB$ => find all CONFIG_ symbols ending with USB\n" |
271 | 272 | "\n"); |
272 | 273 | |
273 | -static char buf[4096], *bufptr = buf; | |
274 | -static char input_buf[4096]; | |
275 | 274 | static char filename[PATH_MAX+1] = ".config"; |
276 | -static char *args[1024], **argptr = args; | |
277 | 275 | static int indent; |
278 | 276 | static struct termios ios_org; |
279 | 277 | static int rows = 0, cols = 0; |
280 | 278 | static struct menu *current_menu; |
281 | 279 | static int child_count; |
282 | -static int do_resize; | |
283 | 280 | static int single_menu_mode; |
284 | 281 | |
285 | 282 | static void conf(struct menu *menu); |
286 | 283 | |
... | ... | @@ -290,13 +287,7 @@ |
290 | 287 | static void show_textbox(const char *title, const char *text, int r, int c); |
291 | 288 | static void show_helptext(const char *title, const char *text); |
292 | 289 | static void show_help(struct menu *menu); |
293 | -static void show_file(const char *filename, const char *title, int r, int c); | |
294 | 290 | |
295 | -static void cprint_init(void); | |
296 | -static int cprint1(const char *fmt, ...); | |
297 | -static void cprint_done(void); | |
298 | -static int cprint(const char *fmt, ...); | |
299 | - | |
300 | 291 | static void init_wsize(void) |
301 | 292 | { |
302 | 293 | struct winsize ws; |
... | ... | @@ -332,54 +323,6 @@ |
332 | 323 | cols -= 5; |
333 | 324 | } |
334 | 325 | |
335 | -static void cprint_init(void) | |
336 | -{ | |
337 | - bufptr = buf; | |
338 | - argptr = args; | |
339 | - memset(args, 0, sizeof(args)); | |
340 | - indent = 0; | |
341 | - child_count = 0; | |
342 | - cprint("./scripts/kconfig/lxdialog/lxdialog"); | |
343 | - cprint("--backtitle"); | |
344 | - cprint(menu_backtitle); | |
345 | -} | |
346 | - | |
347 | -static int cprint1(const char *fmt, ...) | |
348 | -{ | |
349 | - va_list ap; | |
350 | - int res; | |
351 | - | |
352 | - if (!*argptr) | |
353 | - *argptr = bufptr; | |
354 | - va_start(ap, fmt); | |
355 | - res = vsprintf(bufptr, fmt, ap); | |
356 | - va_end(ap); | |
357 | - bufptr += res; | |
358 | - | |
359 | - return res; | |
360 | -} | |
361 | - | |
362 | -static void cprint_done(void) | |
363 | -{ | |
364 | - *bufptr++ = 0; | |
365 | - argptr++; | |
366 | -} | |
367 | - | |
368 | -static int cprint(const char *fmt, ...) | |
369 | -{ | |
370 | - va_list ap; | |
371 | - int res; | |
372 | - | |
373 | - *argptr++ = bufptr; | |
374 | - va_start(ap, fmt); | |
375 | - res = vsprintf(bufptr, fmt, ap); | |
376 | - va_end(ap); | |
377 | - bufptr += res; | |
378 | - *bufptr++ = 0; | |
379 | - | |
380 | - return res; | |
381 | -} | |
382 | - | |
383 | 326 | static void get_prompt_str(struct gstr *r, struct property *prop) |
384 | 327 | { |
385 | 328 | int i, j; |
386 | 329 | |
387 | 330 | |
388 | 331 | |
... | ... | @@ -452,108 +395,17 @@ |
452 | 395 | return res; |
453 | 396 | } |
454 | 397 | |
455 | -pid_t pid; | |
456 | - | |
457 | -static void winch_handler(int sig) | |
458 | -{ | |
459 | - if (!do_resize) { | |
460 | - kill(pid, SIGINT); | |
461 | - do_resize = 1; | |
462 | - } | |
463 | -} | |
464 | - | |
465 | -static int exec_conf(void) | |
466 | -{ | |
467 | - int pipefd[2], stat, size; | |
468 | - struct sigaction sa; | |
469 | - sigset_t sset, osset; | |
470 | - | |
471 | - sigemptyset(&sset); | |
472 | - sigaddset(&sset, SIGINT); | |
473 | - sigprocmask(SIG_BLOCK, &sset, &osset); | |
474 | - | |
475 | - signal(SIGINT, SIG_DFL); | |
476 | - | |
477 | - sa.sa_handler = winch_handler; | |
478 | - sigemptyset(&sa.sa_mask); | |
479 | - sa.sa_flags = SA_RESTART; | |
480 | - sigaction(SIGWINCH, &sa, NULL); | |
481 | - | |
482 | - *argptr++ = NULL; | |
483 | - | |
484 | - pipe(pipefd); | |
485 | - pid = fork(); | |
486 | - if (pid == 0) { | |
487 | - sigprocmask(SIG_SETMASK, &osset, NULL); | |
488 | - dup2(pipefd[1], 2); | |
489 | - close(pipefd[0]); | |
490 | - close(pipefd[1]); | |
491 | - execv(args[0], args); | |
492 | - _exit(EXIT_FAILURE); | |
493 | - } | |
494 | - | |
495 | - close(pipefd[1]); | |
496 | - bufptr = input_buf; | |
497 | - while (1) { | |
498 | - size = input_buf + sizeof(input_buf) - bufptr; | |
499 | - size = read(pipefd[0], bufptr, size); | |
500 | - if (size <= 0) { | |
501 | - if (size < 0) { | |
502 | - if (errno == EINTR || errno == EAGAIN) | |
503 | - continue; | |
504 | - perror("read"); | |
505 | - } | |
506 | - break; | |
507 | - } | |
508 | - bufptr += size; | |
509 | - } | |
510 | - *bufptr++ = 0; | |
511 | - close(pipefd[0]); | |
512 | - waitpid(pid, &stat, 0); | |
513 | - | |
514 | - if (do_resize) { | |
515 | - init_wsize(); | |
516 | - do_resize = 0; | |
517 | - sigprocmask(SIG_SETMASK, &osset, NULL); | |
518 | - return -1; | |
519 | - } | |
520 | - if (WIFSIGNALED(stat)) { | |
521 | - printf("\finterrupted(%d)\n", WTERMSIG(stat)); | |
522 | - exit(1); | |
523 | - } | |
524 | -#if 0 | |
525 | - printf("\fexit state: %d\nexit data: '%s'\n", WEXITSTATUS(stat), input_buf); | |
526 | - sleep(1); | |
527 | -#endif | |
528 | - sigpending(&sset); | |
529 | - if (sigismember(&sset, SIGINT)) { | |
530 | - printf("\finterrupted\n"); | |
531 | - exit(1); | |
532 | - } | |
533 | - sigprocmask(SIG_SETMASK, &osset, NULL); | |
534 | - | |
535 | - return WEXITSTATUS(stat); | |
536 | -} | |
537 | - | |
538 | 398 | static void search_conf(void) |
539 | 399 | { |
540 | 400 | struct symbol **sym_arr; |
541 | - int stat; | |
542 | 401 | struct gstr res; |
543 | - | |
402 | + int dres; | |
544 | 403 | again: |
545 | - cprint_init(); | |
546 | - cprint("--title"); | |
547 | - cprint(_("Search Configuration Parameter")); | |
548 | - cprint("--inputbox"); | |
549 | - cprint(_("Enter CONFIG_ (sub)string to search for (omit CONFIG_)")); | |
550 | - cprint("10"); | |
551 | - cprint("75"); | |
552 | - cprint(""); | |
553 | - stat = exec_conf(); | |
554 | - if (stat < 0) | |
555 | - goto again; | |
556 | - switch (stat) { | |
404 | + reset_dialog(); | |
405 | + dres = dialog_inputbox(_("Search Configuration Parameter"), | |
406 | + _("Enter CONFIG_ (sub)string to search for (omit CONFIG_)"), | |
407 | + 10, 75, ""); | |
408 | + switch (dres) { | |
557 | 409 | case 0: |
558 | 410 | break; |
559 | 411 | case 1: |
... | ... | @@ -563,7 +415,7 @@ |
563 | 415 | return; |
564 | 416 | } |
565 | 417 | |
566 | - sym_arr = sym_re_search(input_buf); | |
418 | + sym_arr = sym_re_search(dialog_input_result); | |
567 | 419 | res = get_relations_str(sym_arr); |
568 | 420 | free(sym_arr); |
569 | 421 | show_textbox(_("Search Results"), str_get(&res), 0, 0); |
570 | 422 | |
571 | 423 | |
572 | 424 | |
573 | 425 | |
... | ... | @@ -590,24 +442,24 @@ |
590 | 442 | switch (prop->type) { |
591 | 443 | case P_MENU: |
592 | 444 | child_count++; |
593 | - cprint("m%p", menu); | |
594 | - | |
595 | 445 | if (single_menu_mode) { |
596 | - cprint1("%s%*c%s", | |
597 | - menu->data ? "-->" : "++>", | |
598 | - indent + 1, ' ', prompt); | |
446 | + item_make("%s%*c%s", | |
447 | + menu->data ? "-->" : "++>", | |
448 | + indent + 1, ' ', prompt); | |
599 | 449 | } else |
600 | - cprint1(" %*c%s --->", indent + 1, ' ', prompt); | |
450 | + item_make(" %*c%s --->", indent + 1, ' ', prompt); | |
601 | 451 | |
602 | - cprint_done(); | |
452 | + item_set_tag('m'); | |
453 | + item_set_data(menu); | |
603 | 454 | if (single_menu_mode && menu->data) |
604 | 455 | goto conf_childs; |
605 | 456 | return; |
606 | 457 | default: |
607 | 458 | if (prompt) { |
608 | 459 | child_count++; |
609 | - cprint(":%p", menu); | |
610 | - cprint("---%*c%s", indent + 1, ' ', prompt); | |
460 | + item_make("---%*c%s", indent + 1, ' ', prompt); | |
461 | + item_set_tag(':'); | |
462 | + item_set_data(menu); | |
611 | 463 | } |
612 | 464 | } |
613 | 465 | } else |
614 | 466 | |
... | ... | @@ -628,10 +480,9 @@ |
628 | 480 | |
629 | 481 | val = sym_get_tristate_value(sym); |
630 | 482 | if (sym_is_changable(sym)) { |
631 | - cprint("t%p", menu); | |
632 | 483 | switch (type) { |
633 | 484 | case S_BOOLEAN: |
634 | - cprint1("[%c]", val == no ? ' ' : '*'); | |
485 | + item_make("[%c]", val == no ? ' ' : '*'); | |
635 | 486 | break; |
636 | 487 | case S_TRISTATE: |
637 | 488 | switch (val) { |
638 | 489 | |
639 | 490 | |
640 | 491 | |
641 | 492 | |
642 | 493 | |
643 | 494 | |
644 | 495 | |
645 | 496 | |
646 | 497 | |
647 | 498 | |
648 | 499 | |
649 | 500 | |
650 | 501 | |
651 | 502 | |
652 | 503 | |
653 | 504 | |
654 | 505 | |
655 | 506 | |
656 | 507 | |
... | ... | @@ -639,84 +490,87 @@ |
639 | 490 | case mod: ch = 'M'; break; |
640 | 491 | default: ch = ' '; break; |
641 | 492 | } |
642 | - cprint1("<%c>", ch); | |
493 | + item_make("<%c>", ch); | |
643 | 494 | break; |
644 | 495 | } |
496 | + item_set_tag('t'); | |
497 | + item_set_data(menu); | |
645 | 498 | } else { |
646 | - cprint("%c%p", def_menu ? 't' : ':', menu); | |
647 | - cprint1(" "); | |
499 | + item_make(" "); | |
500 | + item_set_tag(def_menu ? 't' : ':'); | |
501 | + item_set_data(menu); | |
648 | 502 | } |
649 | 503 | |
650 | - cprint1("%*c%s", indent + 1, ' ', menu_get_prompt(menu)); | |
504 | + item_add_str("%*c%s", indent + 1, ' ', menu_get_prompt(menu)); | |
651 | 505 | if (val == yes) { |
652 | 506 | if (def_menu) { |
653 | - cprint1(" (%s)", menu_get_prompt(def_menu)); | |
654 | - cprint1(" --->"); | |
655 | - cprint_done(); | |
507 | + item_add_str(" (%s)", menu_get_prompt(def_menu)); | |
508 | + item_add_str(" --->"); | |
656 | 509 | if (def_menu->list) { |
657 | 510 | indent += 2; |
658 | 511 | build_conf(def_menu); |
659 | 512 | indent -= 2; |
660 | 513 | } |
661 | - } else | |
662 | - cprint_done(); | |
514 | + } | |
663 | 515 | return; |
664 | 516 | } |
665 | - cprint_done(); | |
666 | 517 | } else { |
667 | 518 | if (menu == current_menu) { |
668 | - cprint(":%p", menu); | |
669 | - cprint("---%*c%s", indent + 1, ' ', menu_get_prompt(menu)); | |
519 | + item_make("---%*c%s", indent + 1, ' ', menu_get_prompt(menu)); | |
520 | + item_set_tag(':'); | |
521 | + item_set_data(menu); | |
670 | 522 | goto conf_childs; |
671 | 523 | } |
672 | 524 | child_count++; |
673 | 525 | val = sym_get_tristate_value(sym); |
674 | 526 | if (sym_is_choice_value(sym) && val == yes) { |
675 | - cprint(":%p", menu); | |
676 | - cprint1(" "); | |
527 | + item_make(" "); | |
528 | + item_set_tag(':'); | |
529 | + item_set_data(menu); | |
677 | 530 | } else { |
678 | 531 | switch (type) { |
679 | 532 | case S_BOOLEAN: |
680 | - cprint("t%p", menu); | |
681 | 533 | if (sym_is_changable(sym)) |
682 | - cprint1("[%c]", val == no ? ' ' : '*'); | |
534 | + item_make("[%c]", val == no ? ' ' : '*'); | |
683 | 535 | else |
684 | - cprint1("---"); | |
536 | + item_make("---"); | |
537 | + item_set_tag('t'); | |
538 | + item_set_data(menu); | |
685 | 539 | break; |
686 | 540 | case S_TRISTATE: |
687 | - cprint("t%p", menu); | |
688 | 541 | switch (val) { |
689 | 542 | case yes: ch = '*'; break; |
690 | 543 | case mod: ch = 'M'; break; |
691 | 544 | default: ch = ' '; break; |
692 | 545 | } |
693 | 546 | if (sym_is_changable(sym)) |
694 | - cprint1("<%c>", ch); | |
547 | + item_make("<%c>", ch); | |
695 | 548 | else |
696 | - cprint1("---"); | |
549 | + item_make("---"); | |
550 | + item_set_tag('t'); | |
551 | + item_set_data(menu); | |
697 | 552 | break; |
698 | 553 | default: |
699 | - cprint("s%p", menu); | |
700 | - tmp = cprint1("(%s)", sym_get_string_value(sym)); | |
554 | + tmp = 2 + strlen(sym_get_string_value(sym)); /* () = 2 */ | |
555 | + item_make("(%s)", sym_get_string_value(sym)); | |
701 | 556 | tmp = indent - tmp + 4; |
702 | 557 | if (tmp < 0) |
703 | 558 | tmp = 0; |
704 | - cprint1("%*c%s%s", tmp, ' ', menu_get_prompt(menu), | |
705 | - (sym_has_value(sym) || !sym_is_changable(sym)) ? | |
706 | - "" : " (NEW)"); | |
707 | - cprint_done(); | |
559 | + item_add_str("%*c%s%s", tmp, ' ', menu_get_prompt(menu), | |
560 | + (sym_has_value(sym) || !sym_is_changable(sym)) ? | |
561 | + "" : " (NEW)"); | |
562 | + item_set_tag('s'); | |
563 | + item_set_data(menu); | |
708 | 564 | goto conf_childs; |
709 | 565 | } |
710 | 566 | } |
711 | - cprint1("%*c%s%s", indent + 1, ' ', menu_get_prompt(menu), | |
712 | - (sym_has_value(sym) || !sym_is_changable(sym)) ? | |
713 | - "" : " (NEW)"); | |
567 | + item_add_str("%*c%s%s", indent + 1, ' ', menu_get_prompt(menu), | |
568 | + (sym_has_value(sym) || !sym_is_changable(sym)) ? | |
569 | + "" : " (NEW)"); | |
714 | 570 | if (menu->prompt->type == P_MENU) { |
715 | - cprint1(" --->"); | |
716 | - cprint_done(); | |
571 | + item_add_str(" --->"); | |
717 | 572 | return; |
718 | 573 | } |
719 | - cprint_done(); | |
720 | 574 | } |
721 | 575 | |
722 | 576 | conf_childs: |
723 | 577 | |
724 | 578 | |
725 | 579 | |
726 | 580 | |
727 | 581 | |
728 | 582 | |
729 | 583 | |
730 | 584 | |
731 | 585 | |
... | ... | @@ -731,59 +585,43 @@ |
731 | 585 | struct menu *submenu; |
732 | 586 | const char *prompt = menu_get_prompt(menu); |
733 | 587 | struct symbol *sym; |
734 | - char active_entry[40]; | |
735 | - int stat, type, i; | |
588 | + struct menu *active_menu = NULL; | |
589 | + int res; | |
590 | + int s_scroll = 0; | |
736 | 591 | |
737 | - unlink("lxdialog.scrltmp"); | |
738 | - active_entry[0] = 0; | |
739 | 592 | while (1) { |
740 | - cprint_init(); | |
741 | - cprint("--title"); | |
742 | - cprint("%s", prompt ? prompt : _("Main Menu")); | |
743 | - cprint("--menu"); | |
744 | - cprint(_(menu_instructions)); | |
745 | - cprint("%d", rows); | |
746 | - cprint("%d", cols); | |
747 | - cprint("%d", rows - 10); | |
748 | - cprint("%s", active_entry); | |
593 | + item_reset(); | |
749 | 594 | current_menu = menu; |
750 | 595 | build_conf(menu); |
751 | 596 | if (!child_count) |
752 | 597 | break; |
753 | 598 | if (menu == &rootmenu) { |
754 | - cprint(":"); | |
755 | - cprint("--- "); | |
756 | - cprint("L"); | |
757 | - cprint(_(" Load an Alternate Configuration File")); | |
758 | - cprint("S"); | |
759 | - cprint(_(" Save Configuration to an Alternate File")); | |
599 | + item_make("--- "); | |
600 | + item_set_tag(':'); | |
601 | + item_make(_(" Load an Alternate Configuration File")); | |
602 | + item_set_tag('L'); | |
603 | + item_make(_(" Save an Alternate Configuration File")); | |
604 | + item_set_tag('S'); | |
760 | 605 | } |
761 | - stat = exec_conf(); | |
762 | - if (stat < 0) | |
763 | - continue; | |
764 | - | |
765 | - if (stat == 1 || stat == 255) | |
606 | + reset_dialog(); | |
607 | + res = dialog_menu(prompt ? prompt : _("Main Menu"), | |
608 | + _(menu_instructions), | |
609 | + rows, cols, rows - 10, | |
610 | + active_menu, &s_scroll); | |
611 | + if (res == 1 || res == 255) | |
766 | 612 | break; |
767 | - | |
768 | - type = input_buf[0]; | |
769 | - if (!type) | |
613 | + if (!item_activate_selected()) | |
770 | 614 | continue; |
615 | + if (!item_tag()) | |
616 | + continue; | |
771 | 617 | |
772 | - for (i = 0; input_buf[i] && !isspace(input_buf[i]); i++) | |
773 | - ; | |
774 | - if (i >= sizeof(active_entry)) | |
775 | - i = sizeof(active_entry) - 1; | |
776 | - input_buf[i] = 0; | |
777 | - strcpy(active_entry, input_buf); | |
618 | + submenu = item_data(); | |
619 | + active_menu = item_data(); | |
620 | + sym = submenu->sym; | |
778 | 621 | |
779 | - sym = NULL; | |
780 | - submenu = NULL; | |
781 | - if (sscanf(input_buf + 1, "%p", &submenu) == 1) | |
782 | - sym = submenu->sym; | |
783 | - | |
784 | - switch (stat) { | |
622 | + switch (res) { | |
785 | 623 | case 0: |
786 | - switch (type) { | |
624 | + switch (item_tag()) { | |
787 | 625 | case 'm': |
788 | 626 | if (single_menu_mode) |
789 | 627 | submenu->data = (void *) (long) !submenu->data; |
... | ... | @@ -814,7 +652,7 @@ |
814 | 652 | show_helptext("README", _(mconf_readme)); |
815 | 653 | break; |
816 | 654 | case 3: |
817 | - if (type == 't') { | |
655 | + if (item_is_tag('t')) { | |
818 | 656 | if (sym_set_tristate_value(sym, yes)) |
819 | 657 | break; |
820 | 658 | if (sym_set_tristate_value(sym, mod)) |
821 | 659 | |
822 | 660 | |
823 | 661 | |
... | ... | @@ -822,17 +660,17 @@ |
822 | 660 | } |
823 | 661 | break; |
824 | 662 | case 4: |
825 | - if (type == 't') | |
663 | + if (item_is_tag('t')) | |
826 | 664 | sym_set_tristate_value(sym, no); |
827 | 665 | break; |
828 | 666 | case 5: |
829 | - if (type == 't') | |
667 | + if (item_is_tag('t')) | |
830 | 668 | sym_set_tristate_value(sym, mod); |
831 | 669 | break; |
832 | 670 | case 6: |
833 | - if (type == 't') | |
671 | + if (item_is_tag('t')) | |
834 | 672 | sym_toggle_tristate_value(sym); |
835 | - else if (type == 'm') | |
673 | + else if (item_is_tag('m')) | |
836 | 674 | conf(submenu); |
837 | 675 | break; |
838 | 676 | case 7: |
... | ... | @@ -844,13 +682,8 @@ |
844 | 682 | |
845 | 683 | static void show_textbox(const char *title, const char *text, int r, int c) |
846 | 684 | { |
847 | - int fd; | |
848 | - | |
849 | - fd = creat(".help.tmp", 0777); | |
850 | - write(fd, text, strlen(text)); | |
851 | - close(fd); | |
852 | - show_file(".help.tmp", title, r, c); | |
853 | - unlink(".help.tmp"); | |
685 | + reset_dialog(); | |
686 | + dialog_textbox(title, text, r ? r : rows, c ? c : cols); | |
854 | 687 | } |
855 | 688 | |
856 | 689 | static void show_helptext(const char *title, const char *text) |
857 | 690 | |
858 | 691 | |
859 | 692 | |
860 | 693 | |
861 | 694 | |
862 | 695 | |
863 | 696 | |
... | ... | @@ -878,62 +711,44 @@ |
878 | 711 | str_free(&help); |
879 | 712 | } |
880 | 713 | |
881 | -static void show_file(const char *filename, const char *title, int r, int c) | |
882 | -{ | |
883 | - do { | |
884 | - cprint_init(); | |
885 | - if (title) { | |
886 | - cprint("--title"); | |
887 | - cprint("%s", title); | |
888 | - } | |
889 | - cprint("--textbox"); | |
890 | - cprint("%s", filename); | |
891 | - cprint("%d", r ? r : rows); | |
892 | - cprint("%d", c ? c : cols); | |
893 | - } while (exec_conf() < 0); | |
894 | -} | |
895 | - | |
896 | 714 | static void conf_choice(struct menu *menu) |
897 | 715 | { |
898 | 716 | const char *prompt = menu_get_prompt(menu); |
899 | 717 | struct menu *child; |
900 | 718 | struct symbol *active; |
901 | - int stat; | |
902 | 719 | |
903 | 720 | active = sym_get_choice_value(menu->sym); |
904 | 721 | while (1) { |
905 | - cprint_init(); | |
906 | - cprint("--title"); | |
907 | - cprint("%s", prompt ? prompt : _("Main Menu")); | |
908 | - cprint("--radiolist"); | |
909 | - cprint(_(radiolist_instructions)); | |
910 | - cprint("15"); | |
911 | - cprint("70"); | |
912 | - cprint("6"); | |
722 | + int res; | |
723 | + int selected; | |
724 | + item_reset(); | |
913 | 725 | |
914 | 726 | current_menu = menu; |
915 | 727 | for (child = menu->list; child; child = child->next) { |
916 | 728 | if (!menu_is_visible(child)) |
917 | 729 | continue; |
918 | - cprint("%p", child); | |
919 | - cprint("%s", menu_get_prompt(child)); | |
730 | + item_make("%s", menu_get_prompt(child)); | |
731 | + item_set_data(child); | |
732 | + if (child->sym == active) | |
733 | + item_set_selected(1); | |
920 | 734 | if (child->sym == sym_get_choice_value(menu->sym)) |
921 | - cprint("ON"); | |
922 | - else if (child->sym == active) | |
923 | - cprint("SELECTED"); | |
924 | - else | |
925 | - cprint("OFF"); | |
735 | + item_set_tag('X'); | |
926 | 736 | } |
927 | - | |
928 | - stat = exec_conf(); | |
929 | - switch (stat) { | |
737 | + reset_dialog(); | |
738 | + res = dialog_checklist(prompt ? prompt : _("Main Menu"), | |
739 | + _(radiolist_instructions), | |
740 | + 15, 70, 6); | |
741 | + selected = item_activate_selected(); | |
742 | + switch (res) { | |
930 | 743 | case 0: |
931 | - if (sscanf(input_buf, "%p", &child) != 1) | |
932 | - break; | |
933 | - sym_set_tristate_value(child->sym, yes); | |
744 | + if (selected) { | |
745 | + child = item_data(); | |
746 | + sym_set_tristate_value(child->sym, yes); | |
747 | + } | |
934 | 748 | return; |
935 | 749 | case 1: |
936 | - if (sscanf(input_buf, "%p", &child) == 1) { | |
750 | + if (selected) { | |
751 | + child = item_data(); | |
937 | 752 | show_help(child); |
938 | 753 | active = child->sym; |
939 | 754 | } else |
940 | 755 | |
941 | 756 | |
942 | 757 | |
943 | 758 | |
944 | 759 | |
945 | 760 | |
946 | 761 | |
... | ... | @@ -948,33 +763,31 @@ |
948 | 763 | static void conf_string(struct menu *menu) |
949 | 764 | { |
950 | 765 | const char *prompt = menu_get_prompt(menu); |
951 | - int stat; | |
952 | 766 | |
953 | 767 | while (1) { |
954 | - cprint_init(); | |
955 | - cprint("--title"); | |
956 | - cprint("%s", prompt ? prompt : _("Main Menu")); | |
957 | - cprint("--inputbox"); | |
768 | + int res; | |
769 | + char *heading; | |
770 | + | |
958 | 771 | switch (sym_get_type(menu->sym)) { |
959 | 772 | case S_INT: |
960 | - cprint(_(inputbox_instructions_int)); | |
773 | + heading = _(inputbox_instructions_int); | |
961 | 774 | break; |
962 | 775 | case S_HEX: |
963 | - cprint(_(inputbox_instructions_hex)); | |
776 | + heading = _(inputbox_instructions_hex); | |
964 | 777 | break; |
965 | 778 | case S_STRING: |
966 | - cprint(_(inputbox_instructions_string)); | |
779 | + heading = _(inputbox_instructions_string); | |
967 | 780 | break; |
968 | 781 | default: |
969 | - /* panic? */; | |
782 | + heading = "Internal mconf error!"; | |
970 | 783 | } |
971 | - cprint("10"); | |
972 | - cprint("75"); | |
973 | - cprint("%s", sym_get_string_value(menu->sym)); | |
974 | - stat = exec_conf(); | |
975 | - switch (stat) { | |
784 | + reset_dialog(); | |
785 | + res = dialog_inputbox(prompt ? prompt : _("Main Menu"), | |
786 | + heading, 10, 75, | |
787 | + sym_get_string_value(menu->sym)); | |
788 | + switch (res) { | |
976 | 789 | case 0: |
977 | - if (sym_set_string_value(menu->sym, input_buf)) | |
790 | + if (sym_set_string_value(menu->sym, dialog_input_result)) | |
978 | 791 | return; |
979 | 792 | show_textbox(NULL, _("You have made an invalid entry."), 5, 43); |
980 | 793 | break; |
981 | 794 | |
982 | 795 | |
983 | 796 | |
... | ... | @@ -989,21 +802,17 @@ |
989 | 802 | |
990 | 803 | static void conf_load(void) |
991 | 804 | { |
992 | - int stat; | |
993 | 805 | |
994 | 806 | while (1) { |
995 | - cprint_init(); | |
996 | - cprint("--inputbox"); | |
997 | - cprint(load_config_text); | |
998 | - cprint("11"); | |
999 | - cprint("55"); | |
1000 | - cprint("%s", filename); | |
1001 | - stat = exec_conf(); | |
1002 | - switch(stat) { | |
807 | + int res; | |
808 | + reset_dialog(); | |
809 | + res = dialog_inputbox(NULL, load_config_text, | |
810 | + 11, 55, filename); | |
811 | + switch(res) { | |
1003 | 812 | case 0: |
1004 | - if (!input_buf[0]) | |
813 | + if (!dialog_input_result[0]) | |
1005 | 814 | return; |
1006 | - if (!conf_read(input_buf)) | |
815 | + if (!conf_read(dialog_input_result)) | |
1007 | 816 | return; |
1008 | 817 | show_textbox(NULL, _("File does not exist!"), 5, 38); |
1009 | 818 | break; |
1010 | 819 | |
1011 | 820 | |
1012 | 821 | |
... | ... | @@ -1018,21 +827,16 @@ |
1018 | 827 | |
1019 | 828 | static void conf_save(void) |
1020 | 829 | { |
1021 | - int stat; | |
1022 | - | |
1023 | 830 | while (1) { |
1024 | - cprint_init(); | |
1025 | - cprint("--inputbox"); | |
1026 | - cprint(save_config_text); | |
1027 | - cprint("11"); | |
1028 | - cprint("55"); | |
1029 | - cprint("%s", filename); | |
1030 | - stat = exec_conf(); | |
1031 | - switch(stat) { | |
831 | + int res; | |
832 | + reset_dialog(); | |
833 | + res = dialog_inputbox(NULL, save_config_text, | |
834 | + 11, 55, filename); | |
835 | + switch(res) { | |
1032 | 836 | case 0: |
1033 | - if (!input_buf[0]) | |
837 | + if (!dialog_input_result[0]) | |
1034 | 838 | return; |
1035 | - if (!conf_write(input_buf)) | |
839 | + if (!conf_write(dialog_input_result)) | |
1036 | 840 | return; |
1037 | 841 | show_textbox(NULL, _("Can't create file! Probably a nonexistent directory."), 5, 60); |
1038 | 842 | break; |
1039 | 843 | |
... | ... | @@ -1048,15 +852,13 @@ |
1048 | 852 | static void conf_cleanup(void) |
1049 | 853 | { |
1050 | 854 | tcsetattr(1, TCSAFLUSH, &ios_org); |
1051 | - unlink(".help.tmp"); | |
1052 | - unlink("lxdialog.scrltmp"); | |
1053 | 855 | } |
1054 | 856 | |
1055 | 857 | int main(int ac, char **av) |
1056 | 858 | { |
1057 | 859 | struct symbol *sym; |
1058 | 860 | char *mode; |
1059 | - int stat; | |
861 | + int res; | |
1060 | 862 | |
1061 | 863 | setlocale(LC_ALL, ""); |
1062 | 864 | bindtextdomain(PACKAGE, LOCALEDIR); |
1063 | 865 | |
... | ... | @@ -1079,18 +881,16 @@ |
1079 | 881 | tcgetattr(1, &ios_org); |
1080 | 882 | atexit(conf_cleanup); |
1081 | 883 | init_wsize(); |
884 | + reset_dialog(); | |
885 | + init_dialog(menu_backtitle); | |
1082 | 886 | conf(&rootmenu); |
1083 | - | |
1084 | - do { | |
1085 | - cprint_init(); | |
1086 | - cprint("--yesno"); | |
1087 | - cprint(_("Do you wish to save your new kernel configuration?")); | |
1088 | - cprint("5"); | |
1089 | - cprint("60"); | |
1090 | - stat = exec_conf(); | |
1091 | - } while (stat < 0); | |
1092 | - | |
1093 | - if (stat == 0) { | |
887 | + reset_dialog(); | |
888 | + res = dialog_yesno(NULL, | |
889 | + _("Do you wish to save your " | |
890 | + "new kernel configuration?"), | |
891 | + 5, 60); | |
892 | + end_dialog(); | |
893 | + if (res == 0) { | |
1094 | 894 | if (conf_write(NULL)) { |
1095 | 895 | fprintf(stderr, _("\n\n" |
1096 | 896 | "Error during writing of the kernel configuration.\n" |