diff options
Diffstat (limited to 'scripts/kconfig')
-rw-r--r-- | scripts/kconfig/Makefile | 23 | ||||
-rw-r--r-- | scripts/kconfig/lxdialog/Makefile | 21 | ||||
-rw-r--r-- | scripts/kconfig/lxdialog/checklist.c | 136 | ||||
-rw-r--r-- | scripts/kconfig/lxdialog/dialog.h | 52 | ||||
-rw-r--r-- | scripts/kconfig/lxdialog/inputbox.c | 2 | ||||
-rw-r--r-- | scripts/kconfig/lxdialog/lxdialog.c | 204 | ||||
-rw-r--r-- | scripts/kconfig/lxdialog/menubox.c | 95 | ||||
-rw-r--r-- | scripts/kconfig/lxdialog/msgbox.c | 72 | ||||
-rw-r--r-- | scripts/kconfig/lxdialog/textbox.c | 298 | ||||
-rw-r--r-- | scripts/kconfig/lxdialog/util.c | 134 | ||||
-rw-r--r-- | scripts/kconfig/lxdialog/yesno.c | 2 | ||||
-rw-r--r-- | scripts/kconfig/mconf.c | 482 |
12 files changed, 502 insertions, 1019 deletions
diff --git a/scripts/kconfig/Makefile b/scripts/kconfig/Makefile index a90d3cc76bfa..b2928f039c17 100644 --- a/scripts/kconfig/Makefile +++ b/scripts/kconfig/Makefile | |||
@@ -11,7 +11,6 @@ gconfig: $(obj)/gconf | |||
11 | $< arch/$(ARCH)/Kconfig | 11 | $< arch/$(ARCH)/Kconfig |
12 | 12 | ||
13 | menuconfig: $(obj)/mconf | 13 | menuconfig: $(obj)/mconf |
14 | $(Q)$(MAKE) $(build)=scripts/kconfig/lxdialog | ||
15 | $< arch/$(ARCH)/Kconfig | 14 | $< arch/$(ARCH)/Kconfig |
16 | 15 | ||
17 | config: $(obj)/conf | 16 | config: $(obj)/conf |
@@ -81,6 +80,23 @@ help: | |||
81 | @echo ' allyesconfig - New config where all options are accepted with yes' | 80 | @echo ' allyesconfig - New config where all options are accepted with yes' |
82 | @echo ' allnoconfig - New config where all options are answered with no' | 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 | # Shared Makefile for the various kconfig executables: | 101 | # Shared Makefile for the various kconfig executables: |
86 | # conf: Used for defconfig, oldconfig and related targets | 102 | # conf: Used for defconfig, oldconfig and related targets |
@@ -92,9 +108,12 @@ help: | |||
92 | # Based on GTK which needs to be installed to compile it | 108 | # Based on GTK which needs to be installed to compile it |
93 | # object files used by all kconfig flavours | 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 | hostprogs-y := conf mconf qconf gconf kxgettext | 114 | hostprogs-y := conf mconf qconf gconf kxgettext |
96 | conf-objs := conf.o zconf.tab.o | 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 | kxgettext-objs := kxgettext.o zconf.tab.o | 117 | kxgettext-objs := kxgettext.o zconf.tab.o |
99 | 118 | ||
100 | ifeq ($(MAKECMDGOALS),xconfig) | 119 | ifeq ($(MAKECMDGOALS),xconfig) |
diff --git a/scripts/kconfig/lxdialog/Makefile b/scripts/kconfig/lxdialog/Makefile deleted file mode 100644 index a8b026326247..000000000000 --- a/scripts/kconfig/lxdialog/Makefile +++ /dev/null | |||
@@ -1,21 +0,0 @@ | |||
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 | ||
diff --git a/scripts/kconfig/lxdialog/checklist.c b/scripts/kconfig/lxdialog/checklist.c index b90e888a2bc0..282511020bcb 100644 --- a/scripts/kconfig/lxdialog/checklist.c +++ b/scripts/kconfig/lxdialog/checklist.c | |||
@@ -28,8 +28,7 @@ static int list_width, check_x, item_x; | |||
28 | /* | 28 | /* |
29 | * Print list item | 29 | * Print list item |
30 | */ | 30 | */ |
31 | static void print_item(WINDOW * win, const char *item, int status, int choice, | 31 | static void print_item(WINDOW * win, int choice, int selected) |
32 | int selected) | ||
33 | { | 32 | { |
34 | int i; | 33 | int i; |
35 | 34 | ||
@@ -42,12 +41,12 @@ static void print_item(WINDOW * win, const char *item, int status, int choice, | |||
42 | wmove(win, choice, check_x); | 41 | wmove(win, choice, check_x); |
43 | wattrset(win, selected ? dlg.check_selected.atr | 42 | wattrset(win, selected ? dlg.check_selected.atr |
44 | : dlg.check.atr); | 43 | : dlg.check.atr); |
45 | wprintw(win, "(%c)", status ? 'X' : ' '); | 44 | wprintw(win, "(%c)", item_is_tag('X') ? 'X' : ' '); |
46 | 45 | ||
47 | wattrset(win, selected ? dlg.tag_selected.atr : dlg.tag.atr); | 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 | wattrset(win, selected ? dlg.item_selected.atr : dlg.item.atr); | 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 | if (selected) { | 50 | if (selected) { |
52 | wmove(win, choice, check_x + 1); | 51 | wmove(win, choice, check_x + 1); |
53 | wrefresh(win); | 52 | wrefresh(win); |
@@ -110,32 +109,23 @@ static void print_buttons(WINDOW * dialog, int height, int width, int selected) | |||
110 | * in the style of radiolist (only one option turned on at a time). | 109 | * in the style of radiolist (only one option turned on at a time). |
111 | */ | 110 | */ |
112 | int dialog_checklist(const char *title, const char *prompt, int height, | 111 | int dialog_checklist(const char *title, const char *prompt, int height, |
113 | int width, int list_height, int item_no, | 112 | int width, int list_height) |
114 | const char *const *items) | ||
115 | { | 113 | { |
116 | int i, x, y, box_x, box_y; | 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 | WINDOW *dialog, *list; | 116 | WINDOW *dialog, *list; |
119 | 117 | ||
120 | /* Allocate space for storing item on/off status */ | 118 | /* which item to highlight */ |
121 | if ((status = malloc(sizeof(int) * item_no)) == NULL) { | 119 | item_foreach() { |
122 | endwin(); | 120 | if (item_is_tag('X')) |
123 | fprintf(stderr, | 121 | choice = item_n(); |
124 | "\nCan't allocate memory in dialog_checklist().\n"); | 122 | if (item_is_selected()) { |
125 | exit(-1); | 123 | choice = item_n(); |
126 | } | 124 | break; |
127 | 125 | } | |
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 | } | 126 | } |
135 | if (choice) | ||
136 | choice--; | ||
137 | 127 | ||
138 | max_choice = MIN(list_height, item_no); | 128 | max_choice = MIN(list_height, item_count()); |
139 | 129 | ||
140 | /* center dialog box on screen */ | 130 | /* center dialog box on screen */ |
141 | x = (COLS - width) / 2; | 131 | x = (COLS - width) / 2; |
@@ -176,8 +166,8 @@ int dialog_checklist(const char *title, const char *prompt, int height, | |||
176 | 166 | ||
177 | /* Find length of longest item in order to center checklist */ | 167 | /* Find length of longest item in order to center checklist */ |
178 | check_x = 0; | 168 | check_x = 0; |
179 | for (i = 0; i < item_no; i++) | 169 | item_foreach() |
180 | check_x = MAX(check_x, +strlen(items[i * 3 + 1]) + 4); | 170 | check_x = MAX(check_x, strlen(item_str()) + 4); |
181 | 171 | ||
182 | check_x = (list_width - check_x) / 2; | 172 | check_x = (list_width - check_x) / 2; |
183 | item_x = check_x + 4; | 173 | item_x = check_x + 4; |
@@ -189,14 +179,11 @@ int dialog_checklist(const char *title, const char *prompt, int height, | |||
189 | 179 | ||
190 | /* Print the list */ | 180 | /* Print the list */ |
191 | for (i = 0; i < max_choice; i++) { | 181 | for (i = 0; i < max_choice; i++) { |
192 | if (i != choice) | 182 | item_set(scroll + i); |
193 | print_item(list, items[(scroll + i) * 3 + 1], | 183 | print_item(list, i, i == choice); |
194 | status[i + scroll], i, 0); | ||
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 | box_y, box_x + check_x + 5, list_height); | 187 | box_y, box_x + check_x + 5, list_height); |
201 | 188 | ||
202 | print_buttons(dialog, height, width, 0); | 189 | print_buttons(dialog, height, width, 0); |
@@ -208,10 +195,11 @@ int dialog_checklist(const char *title, const char *prompt, int height, | |||
208 | while (key != ESC) { | 195 | while (key != ESC) { |
209 | key = wgetch(dialog); | 196 | key = wgetch(dialog); |
210 | 197 | ||
211 | for (i = 0; i < max_choice; i++) | 198 | for (i = 0; i < max_choice; i++) { |
212 | if (toupper(key) == | 199 | item_set(i + scroll); |
213 | toupper(items[(scroll + i) * 3 + 1][0])) | 200 | if (toupper(key) == toupper(item_str()[0])) |
214 | break; | 201 | break; |
202 | } | ||
215 | 203 | ||
216 | if (i < max_choice || key == KEY_UP || key == KEY_DOWN || | 204 | if (i < max_choice || key == KEY_UP || key == KEY_DOWN || |
217 | key == '+' || key == '-') { | 205 | key == '+' || key == '-') { |
@@ -222,15 +210,16 @@ int dialog_checklist(const char *title, const char *prompt, int height, | |||
222 | /* Scroll list down */ | 210 | /* Scroll list down */ |
223 | if (list_height > 1) { | 211 | if (list_height > 1) { |
224 | /* De-highlight current first item */ | 212 | /* De-highlight current first item */ |
225 | print_item(list, items[scroll * 3 + 1], | 213 | item_set(scroll); |
226 | status[scroll], 0, FALSE); | 214 | print_item(list, 0, FALSE); |
227 | scrollok(list, TRUE); | 215 | scrollok(list, TRUE); |
228 | wscrl(list, -1); | 216 | wscrl(list, -1); |
229 | scrollok(list, FALSE); | 217 | scrollok(list, FALSE); |
230 | } | 218 | } |
231 | scroll--; | 219 | scroll--; |
232 | print_item(list, items[scroll * 3 + 1], status[scroll], 0, TRUE); | 220 | item_set(scroll); |
233 | print_arrows(dialog, choice, item_no, | 221 | print_item(list, 0, TRUE); |
222 | print_arrows(dialog, choice, item_count(), | ||
234 | scroll, box_y, box_x + check_x + 5, list_height); | 223 | scroll, box_y, box_x + check_x + 5, list_height); |
235 | 224 | ||
236 | wnoutrefresh(dialog); | 225 | wnoutrefresh(dialog); |
@@ -241,23 +230,24 @@ int dialog_checklist(const char *title, const char *prompt, int height, | |||
241 | i = choice - 1; | 230 | i = choice - 1; |
242 | } else if (key == KEY_DOWN || key == '+') { | 231 | } else if (key == KEY_DOWN || key == '+') { |
243 | if (choice == max_choice - 1) { | 232 | if (choice == max_choice - 1) { |
244 | if (scroll + choice >= item_no - 1) | 233 | if (scroll + choice >= item_count() - 1) |
245 | continue; | 234 | continue; |
246 | /* Scroll list up */ | 235 | /* Scroll list up */ |
247 | if (list_height > 1) { | 236 | if (list_height > 1) { |
248 | /* De-highlight current last item before scrolling up */ | 237 | /* De-highlight current last item before scrolling up */ |
249 | print_item(list, items[(scroll + max_choice - 1) * 3 + 1], | 238 | item_set(scroll + max_choice - 1); |
250 | status[scroll + max_choice - 1], | 239 | print_item(list, |
251 | max_choice - 1, FALSE); | 240 | max_choice - 1, |
241 | FALSE); | ||
252 | scrollok(list, TRUE); | 242 | scrollok(list, TRUE); |
253 | wscrl(list, 1); | 243 | wscrl(list, 1); |
254 | scrollok(list, FALSE); | 244 | scrollok(list, FALSE); |
255 | } | 245 | } |
256 | scroll++; | 246 | scroll++; |
257 | print_item(list, items[(scroll + max_choice - 1) * 3 + 1], | 247 | item_set(scroll + max_choice - 1); |
258 | status[scroll + max_choice - 1], max_choice - 1, TRUE); | 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 | scroll, box_y, box_x + check_x + 5, list_height); | 251 | scroll, box_y, box_x + check_x + 5, list_height); |
262 | 252 | ||
263 | wnoutrefresh(dialog); | 253 | wnoutrefresh(dialog); |
@@ -269,12 +259,12 @@ int dialog_checklist(const char *title, const char *prompt, int height, | |||
269 | } | 259 | } |
270 | if (i != choice) { | 260 | if (i != choice) { |
271 | /* De-highlight current item */ | 261 | /* De-highlight current item */ |
272 | print_item(list, items[(scroll + choice) * 3 + 1], | 262 | item_set(scroll + choice); |
273 | status[scroll + choice], choice, FALSE); | 263 | print_item(list, choice, FALSE); |
274 | /* Highlight new item */ | 264 | /* Highlight new item */ |
275 | choice = i; | 265 | choice = i; |
276 | print_item(list, items[(scroll + choice) * 3 + 1], | 266 | item_set(scroll + choice); |
277 | status[scroll + choice], choice, TRUE); | 267 | print_item(list, choice, TRUE); |
278 | wnoutrefresh(dialog); | 268 | wnoutrefresh(dialog); |
279 | wrefresh(list); | 269 | wrefresh(list); |
280 | } | 270 | } |
@@ -284,10 +274,19 @@ int dialog_checklist(const char *title, const char *prompt, int height, | |||
284 | case 'H': | 274 | case 'H': |
285 | case 'h': | 275 | case 'h': |
286 | case '?': | 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 | delwin(dialog); | 288 | delwin(dialog); |
289 | free(status); | 289 | return button; |
290 | return 1; | ||
291 | case TAB: | 290 | case TAB: |
292 | case KEY_LEFT: | 291 | case KEY_LEFT: |
293 | case KEY_RIGHT: | 292 | case KEY_RIGHT: |
@@ -297,30 +296,6 @@ int dialog_checklist(const char *title, const char *prompt, int height, | |||
297 | print_buttons(dialog, height, width, button); | 296 | print_buttons(dialog, height, width, button); |
298 | wrefresh(dialog); | 297 | wrefresh(dialog); |
299 | break; | 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 | case 'X': | 299 | case 'X': |
325 | case 'x': | 300 | case 'x': |
326 | key = ESC; | 301 | key = ESC; |
@@ -331,8 +306,7 @@ int dialog_checklist(const char *title, const char *prompt, int height, | |||
331 | /* Now, update everything... */ | 306 | /* Now, update everything... */ |
332 | doupdate(); | 307 | doupdate(); |
333 | } | 308 | } |
334 | 309 | delwin(list); | |
335 | delwin(dialog); | 310 | delwin(dialog); |
336 | free(status); | 311 | return 255; /* ESC pressed */ |
337 | return -1; /* ESC pressed */ | ||
338 | } | 312 | } |
diff --git a/scripts/kconfig/lxdialog/dialog.h b/scripts/kconfig/lxdialog/dialog.h index 2f4c19d710b2..065ded0a449f 100644 --- a/scripts/kconfig/lxdialog/dialog.h +++ b/scripts/kconfig/lxdialog/dialog.h | |||
@@ -133,11 +133,55 @@ struct dialog_info { | |||
133 | * Global variables | 133 | * Global variables |
134 | */ | 134 | */ |
135 | extern struct dialog_info dlg; | 135 | extern struct dialog_info dlg; |
136 | extern char dialog_input_result[]; | ||
136 | 137 | ||
137 | /* | 138 | /* |
138 | * Function prototypes | 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 | void end_dialog(void); | 185 | void end_dialog(void); |
142 | void attr_clear(WINDOW * win, int height, int width, chtype attr); | 186 | void attr_clear(WINDOW * win, int height, int width, chtype attr); |
143 | void dialog_clear(void); | 187 | void dialog_clear(void); |
@@ -154,11 +198,9 @@ int dialog_msgbox(const char *title, const char *prompt, int height, | |||
154 | int width, int pause); | 198 | int width, int pause); |
155 | int dialog_textbox(const char *title, const char *file, int height, int width); | 199 | int dialog_textbox(const char *title, const char *file, int height, int width); |
156 | int dialog_menu(const char *title, const char *prompt, int height, int width, | 200 | int dialog_menu(const char *title, const char *prompt, int height, int width, |
157 | int menu_height, const char *choice, int item_no, | 201 | int menu_height, const void *selected, int *s_scroll); |
158 | const char *const *items); | ||
159 | int dialog_checklist(const char *title, const char *prompt, int height, | 202 | int dialog_checklist(const char *title, const char *prompt, int height, |
160 | int width, int list_height, int item_no, | 203 | int width, int list_height); |
161 | const char *const *items); | ||
162 | extern char dialog_input_result[]; | 204 | extern char dialog_input_result[]; |
163 | int dialog_inputbox(const char *title, const char *prompt, int height, | 205 | int dialog_inputbox(const char *title, const char *prompt, int height, |
164 | int width, const char *init); | 206 | int width, const char *init); |
diff --git a/scripts/kconfig/lxdialog/inputbox.c b/scripts/kconfig/lxdialog/inputbox.c index f75b51f8e636..9c53098d6b74 100644 --- a/scripts/kconfig/lxdialog/inputbox.c +++ b/scripts/kconfig/lxdialog/inputbox.c | |||
@@ -222,5 +222,5 @@ int dialog_inputbox(const char *title, const char *prompt, int height, int width | |||
222 | } | 222 | } |
223 | 223 | ||
224 | delwin(dialog); | 224 | delwin(dialog); |
225 | return -1; /* ESC pressed */ | 225 | return 255; /* ESC pressed */ |
226 | } | 226 | } |
diff --git a/scripts/kconfig/lxdialog/lxdialog.c b/scripts/kconfig/lxdialog/lxdialog.c deleted file mode 100644 index c264e024309e..000000000000 --- a/scripts/kconfig/lxdialog/lxdialog.c +++ /dev/null | |||
@@ -1,204 +0,0 @@ | |||
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 | } | ||
diff --git a/scripts/kconfig/lxdialog/menubox.c b/scripts/kconfig/lxdialog/menubox.c index ff991db827bd..f39ae29f4fcc 100644 --- a/scripts/kconfig/lxdialog/menubox.c +++ b/scripts/kconfig/lxdialog/menubox.c | |||
@@ -99,10 +99,10 @@ static void do_print_item(WINDOW * win, const char *item, int choice, | |||
99 | wrefresh(win); | 99 | wrefresh(win); |
100 | } | 100 | } |
101 | 101 | ||
102 | #define print_item(index, choice, selected) \ | 102 | #define print_item(index, choice, selected) \ |
103 | do {\ | 103 | do { \ |
104 | int hotkey = (items[(index) * 2][0] != ':'); \ | 104 | item_set(index); \ |
105 | do_print_item(menu, items[(index) * 2 + 1], choice, selected, hotkey); \ | 105 | do_print_item(menu, item_str(), choice, selected, !item_is_tag(':')); \ |
106 | } while (0) | 106 | } while (0) |
107 | 107 | ||
108 | /* | 108 | /* |
@@ -180,16 +180,14 @@ static void do_scroll(WINDOW *win, int *scroll, int n) | |||
180 | * Display a menu for choosing among a number of options | 180 | * Display a menu for choosing among a number of options |
181 | */ | 181 | */ |
182 | int dialog_menu(const char *title, const char *prompt, int height, int width, | 182 | int dialog_menu(const char *title, const char *prompt, int height, int width, |
183 | int menu_height, const char *current, int item_no, | 183 | int menu_height, const void *selected, int *s_scroll) |
184 | const char *const *items) | ||
185 | { | 184 | { |
186 | int i, j, x, y, box_x, box_y; | 185 | int i, j, x, y, box_x, box_y; |
187 | int key = 0, button = 0, scroll = 0, choice = 0; | 186 | int key = 0, button = 0, scroll = 0, choice = 0; |
188 | int first_item = 0, max_choice; | 187 | int first_item = 0, max_choice; |
189 | WINDOW *dialog, *menu; | 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 | /* center dialog box on screen */ | 192 | /* center dialog box on screen */ |
195 | x = (COLS - width) / 2; | 193 | x = (COLS - width) / 2; |
@@ -231,28 +229,21 @@ int dialog_menu(const char *title, const char *prompt, int height, int width, | |||
231 | item_x = (menu_width - 70) / 2; | 229 | item_x = (menu_width - 70) / 2; |
232 | 230 | ||
233 | /* Set choice to default item */ | 231 | /* Set choice to default item */ |
234 | for (i = 0; i < item_no; i++) | 232 | item_foreach() |
235 | if (strcmp(current, items[i * 2]) == 0) | 233 | if (selected && (selected == item_data())) |
236 | choice = i; | 234 | choice = item_n(); |
237 | 235 | /* get the saved scroll info */ | |
238 | /* get the scroll info from the temp file */ | 236 | scroll = *s_scroll; |
239 | if ((f = fopen("lxdialog.scrltmp", "r")) != NULL) { | 237 | if ((scroll <= choice) && (scroll + max_choice > choice) && |
240 | if ((fscanf(f, "%d\n", &scroll) == 1) && (scroll <= choice) && | 238 | (scroll >= 0) && (scroll + max_choice <= item_count())) { |
241 | (scroll + max_choice > choice) && (scroll >= 0) && | 239 | first_item = scroll; |
242 | (scroll + max_choice <= item_no)) { | 240 | choice = choice - scroll; |
243 | first_item = scroll; | 241 | } else { |
244 | choice = choice - scroll; | 242 | scroll = 0; |
245 | fclose(f); | ||
246 | } else { | ||
247 | scroll = 0; | ||
248 | remove("lxdialog.scrltmp"); | ||
249 | fclose(f); | ||
250 | f = NULL; | ||
251 | } | ||
252 | } | 243 | } |
253 | if ((choice >= max_choice) || (f == NULL && choice >= max_choice / 2)) { | 244 | if ((choice >= max_choice)) { |
254 | if (choice >= item_no - max_choice / 2) | 245 | if (choice >= item_count() - max_choice / 2) |
255 | scroll = first_item = item_no - max_choice; | 246 | scroll = first_item = item_count() - max_choice; |
256 | else | 247 | else |
257 | scroll = first_item = choice - max_choice / 2; | 248 | scroll = first_item = choice - max_choice / 2; |
258 | choice = choice - scroll; | 249 | choice = choice - scroll; |
@@ -265,7 +256,7 @@ int dialog_menu(const char *title, const char *prompt, int height, int width, | |||
265 | 256 | ||
266 | wnoutrefresh(menu); | 257 | wnoutrefresh(menu); |
267 | 258 | ||
268 | print_arrows(dialog, item_no, scroll, | 259 | print_arrows(dialog, item_count(), scroll, |
269 | box_y, box_x + item_x + 1, menu_height); | 260 | box_y, box_x + item_x + 1, menu_height); |
270 | 261 | ||
271 | print_buttons(dialog, height, width, 0); | 262 | print_buttons(dialog, height, width, 0); |
@@ -282,14 +273,16 @@ int dialog_menu(const char *title, const char *prompt, int height, int width, | |||
282 | i = max_choice; | 273 | i = max_choice; |
283 | else { | 274 | else { |
284 | for (i = choice + 1; i < max_choice; i++) { | 275 | for (i = choice + 1; i < max_choice; i++) { |
285 | j = first_alpha(items[(scroll + i) * 2 + 1], "YyNnMmHh"); | 276 | item_set(scroll + i); |
286 | if (key == tolower(items[(scroll + i) * 2 + 1][j])) | 277 | j = first_alpha(item_str(), "YyNnMmHh"); |
278 | if (key == tolower(item_str()[j])) | ||
287 | break; | 279 | break; |
288 | } | 280 | } |
289 | if (i == max_choice) | 281 | if (i == max_choice) |
290 | for (i = 0; i < max_choice; i++) { | 282 | for (i = 0; i < max_choice; i++) { |
291 | j = first_alpha(items [(scroll + i) * 2 + 1], "YyNnMmHh"); | 283 | item_set(scroll + i); |
292 | if (key == tolower(items[(scroll + i) * 2 + 1][j])) | 284 | j = first_alpha(item_str(), "YyNnMmHh"); |
285 | if (key == tolower(item_str()[j])) | ||
293 | break; | 286 | break; |
294 | } | 287 | } |
295 | } | 288 | } |
@@ -314,7 +307,7 @@ int dialog_menu(const char *title, const char *prompt, int height, int width, | |||
314 | print_item(scroll+choice, choice, FALSE); | 307 | print_item(scroll+choice, choice, FALSE); |
315 | 308 | ||
316 | if ((choice > max_choice - 3) && | 309 | if ((choice > max_choice - 3) && |
317 | (scroll + max_choice < item_no)) { | 310 | (scroll + max_choice < item_count())) { |
318 | /* Scroll menu up */ | 311 | /* Scroll menu up */ |
319 | do_scroll(menu, &scroll, 1); | 312 | do_scroll(menu, &scroll, 1); |
320 | 313 | ||
@@ -337,7 +330,7 @@ int dialog_menu(const char *title, const char *prompt, int height, int width, | |||
337 | 330 | ||
338 | } else if (key == KEY_NPAGE) { | 331 | } else if (key == KEY_NPAGE) { |
339 | for (i = 0; (i < max_choice); i++) { | 332 | for (i = 0; (i < max_choice); i++) { |
340 | if (scroll + max_choice < item_no) { | 333 | if (scroll + max_choice < item_count()) { |
341 | do_scroll(menu, &scroll, 1); | 334 | do_scroll(menu, &scroll, 1); |
342 | print_item(scroll+max_choice-1, | 335 | print_item(scroll+max_choice-1, |
343 | max_choice - 1, FALSE); | 336 | max_choice - 1, FALSE); |
@@ -351,7 +344,7 @@ int dialog_menu(const char *title, const char *prompt, int height, int width, | |||
351 | 344 | ||
352 | print_item(scroll + choice, choice, TRUE); | 345 | print_item(scroll + choice, choice, TRUE); |
353 | 346 | ||
354 | print_arrows(dialog, item_no, scroll, | 347 | print_arrows(dialog, item_count(), scroll, |
355 | box_y, box_x + item_x + 1, menu_height); | 348 | box_y, box_x + item_x + 1, menu_height); |
356 | 349 | ||
357 | wnoutrefresh(dialog); | 350 | wnoutrefresh(dialog); |
@@ -377,12 +370,11 @@ int dialog_menu(const char *title, const char *prompt, int height, int width, | |||
377 | case 'm': | 370 | case 'm': |
378 | case '/': | 371 | case '/': |
379 | /* save scroll info */ | 372 | /* save scroll info */ |
380 | if ((f = fopen("lxdialog.scrltmp", "w")) != NULL) { | 373 | *s_scroll = scroll; |
381 | fprintf(f, "%d\n", scroll); | 374 | delwin(menu); |
382 | fclose(f); | ||
383 | } | ||
384 | delwin(dialog); | 375 | delwin(dialog); |
385 | fprintf(stderr, "%s\n", items[(scroll + choice) * 2]); | 376 | item_set(scroll + choice); |
377 | item_set_selected(1); | ||
386 | switch (key) { | 378 | switch (key) { |
387 | case 's': | 379 | case 's': |
388 | return 3; | 380 | return 3; |
@@ -402,17 +394,11 @@ int dialog_menu(const char *title, const char *prompt, int height, int width, | |||
402 | case '?': | 394 | case '?': |
403 | button = 2; | 395 | button = 2; |
404 | case '\n': | 396 | case '\n': |
397 | *s_scroll = scroll; | ||
398 | delwin(menu); | ||
405 | delwin(dialog); | 399 | delwin(dialog); |
406 | if (button == 2) | 400 | item_set(scroll + choice); |
407 | fprintf(stderr, "%s \"%s\"\n", | 401 | item_set_selected(1); |
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"); | ||
416 | return button; | 402 | return button; |
417 | case 'e': | 403 | case 'e': |
418 | case 'x': | 404 | case 'x': |
@@ -421,8 +407,7 @@ int dialog_menu(const char *title, const char *prompt, int height, int width, | |||
421 | break; | 407 | break; |
422 | } | 408 | } |
423 | } | 409 | } |
424 | 410 | delwin(menu); | |
425 | delwin(dialog); | 411 | delwin(dialog); |
426 | remove("lxdialog.scrltmp"); | 412 | return 255; /* ESC pressed */ |
427 | return -1; /* ESC pressed */ | ||
428 | } | 413 | } |
diff --git a/scripts/kconfig/lxdialog/msgbox.c b/scripts/kconfig/lxdialog/msgbox.c deleted file mode 100644 index 236759ff3f4e..000000000000 --- a/scripts/kconfig/lxdialog/msgbox.c +++ /dev/null | |||
@@ -1,72 +0,0 @@ | |||
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 | } | ||
diff --git a/scripts/kconfig/lxdialog/textbox.c b/scripts/kconfig/lxdialog/textbox.c index 336793b03954..86b0770b0387 100644 --- a/scripts/kconfig/lxdialog/textbox.c +++ b/scripts/kconfig/lxdialog/textbox.c | |||
@@ -27,54 +27,27 @@ static void print_line(WINDOW * win, int row, int width); | |||
27 | static char *get_line(void); | 27 | static char *get_line(void); |
28 | static void print_position(WINDOW * win, int height, int width); | 28 | static void print_position(WINDOW * win, int height, int width); |
29 | 29 | ||
30 | static int hscroll, fd, file_size, bytes_read; | 30 | static int hscroll; |
31 | static int begin_reached = 1, end_reached, page_length; | 31 | static int begin_reached, end_reached, page_length; |
32 | static char *buf, *page; | 32 | static const char *buf; |
33 | static const char *page; | ||
33 | 34 | ||
34 | /* | 35 | /* |
35 | * Display text from a file in a dialog box. | 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 | int passed_end; | 42 | int passed_end; |
41 | char search_term[MAX_LEN + 1]; | ||
42 | WINDOW *dialog, *text; | 43 | WINDOW *dialog, *text; |
43 | 44 | ||
44 | search_term[0] = '\0'; /* no search term entered yet */ | 45 | begin_reached = 1; |
45 | 46 | end_reached = 0; | |
46 | /* Open input file for reading */ | 47 | page_length = 0; |
47 | if ((fd = open(file, O_RDONLY)) == -1) { | 48 | hscroll = 0; |
48 | endwin(); | 49 | buf = tbuf; |
49 | fprintf(stderr, "\nCan't open input file in dialog_textbox().\n"); | 50 | page = buf; /* page is pointer to start of page to be displayed */ |
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 | 51 | ||
79 | /* center dialog box on screen */ | 52 | /* center dialog box on screen */ |
80 | x = (COLS - width) / 2; | 53 | x = (COLS - width) / 2; |
@@ -86,7 +59,9 @@ int dialog_textbox(const char *title, const char *file, int height, int width) | |||
86 | keypad(dialog, TRUE); | 59 | keypad(dialog, TRUE); |
87 | 60 | ||
88 | /* Create window for text region, used for scrolling text */ | 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 | wattrset(text, dlg.dialog.atr); | 65 | wattrset(text, dlg.dialog.atr); |
91 | wbkgdset(text, dlg.dialog.atr & A_COLOR); | 66 | wbkgdset(text, dlg.dialog.atr & A_COLOR); |
92 | 67 | ||
@@ -111,8 +86,8 @@ int dialog_textbox(const char *title, const char *file, int height, int width) | |||
111 | getyx(dialog, cur_y, cur_x); /* Save cursor position */ | 86 | getyx(dialog, cur_y, cur_x); /* Save cursor position */ |
112 | 87 | ||
113 | /* Print first page of text */ | 88 | /* Print first page of text */ |
114 | attr_clear(text, height - 4, width - 2, dlg.dialog.atr); | 89 | attr_clear(text, texth, textw, dlg.dialog.atr); |
115 | print_page(text, height - 4, width - 2); | 90 | print_page(text, texth, textw); |
116 | print_position(dialog, height, width); | 91 | print_position(dialog, height, width); |
117 | wmove(dialog, cur_y, cur_x); /* Restore cursor position */ | 92 | wmove(dialog, cur_y, cur_x); /* Restore cursor position */ |
118 | wrefresh(dialog); | 93 | wrefresh(dialog); |
@@ -124,37 +99,15 @@ int dialog_textbox(const char *title, const char *file, int height, int width) | |||
124 | case 'e': | 99 | case 'e': |
125 | case 'X': | 100 | case 'X': |
126 | case 'x': | 101 | case 'x': |
102 | delwin(text); | ||
127 | delwin(dialog); | 103 | delwin(dialog); |
128 | free(buf); | ||
129 | close(fd); | ||
130 | return 0; | 104 | return 0; |
131 | case 'g': /* First page */ | 105 | case 'g': /* First page */ |
132 | case KEY_HOME: | 106 | case KEY_HOME: |
133 | if (!begin_reached) { | 107 | if (!begin_reached) { |
134 | begin_reached = 1; | 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 | page = buf; | 109 | page = buf; |
157 | print_page(text, height - 4, width - 2); | 110 | print_page(text, texth, textw); |
158 | print_position(dialog, height, width); | 111 | print_position(dialog, height, width); |
159 | wmove(dialog, cur_y, cur_x); /* Restore cursor position */ | 112 | wmove(dialog, cur_y, cur_x); /* Restore cursor position */ |
160 | wrefresh(dialog); | 113 | wrefresh(dialog); |
@@ -164,29 +117,10 @@ int dialog_textbox(const char *title, const char *file, int height, int width) | |||
164 | case KEY_END: | 117 | case KEY_END: |
165 | 118 | ||
166 | end_reached = 1; | 119 | end_reached = 1; |
167 | /* Last page not in buffer? */ | 120 | /* point to last char in buf */ |
168 | if ((fpos = lseek(fd, 0, SEEK_CUR)) == -1) { | 121 | page = buf + strlen(buf); |
169 | endwin(); | 122 | back_lines(texth); |
170 | fprintf(stderr, "\nError moving file pointer in dialog_textbox().\n"); | 123 | print_page(text, texth, textw); |
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); | ||
190 | print_position(dialog, height, width); | 124 | print_position(dialog, height, width); |
191 | wmove(dialog, cur_y, cur_x); /* Restore cursor position */ | 125 | wmove(dialog, cur_y, cur_x); /* Restore cursor position */ |
192 | wrefresh(dialog); | 126 | wrefresh(dialog); |
@@ -197,20 +131,22 @@ int dialog_textbox(const char *title, const char *file, int height, int width) | |||
197 | if (!begin_reached) { | 131 | if (!begin_reached) { |
198 | back_lines(page_length + 1); | 132 | back_lines(page_length + 1); |
199 | 133 | ||
200 | /* We don't call print_page() here but use scrolling to ensure | 134 | /* We don't call print_page() here but use |
201 | faster screen update. However, 'end_reached' and | 135 | * scrolling to ensure faster screen update. |
202 | 'page_length' should still be updated, and 'page' should | 136 | * However, 'end_reached' and 'page_length' |
203 | point to start of next page. This is done by calling | 137 | * should still be updated, and 'page' should |
204 | get_line() in the following 'for' loop. */ | 138 | * point to start of next page. This is done |
139 | * by calling get_line() in the following | ||
140 | * 'for' loop. */ | ||
205 | scrollok(text, TRUE); | 141 | scrollok(text, TRUE); |
206 | wscrl(text, -1); /* Scroll text region down one line */ | 142 | wscrl(text, -1); /* Scroll text region down one line */ |
207 | scrollok(text, FALSE); | 143 | scrollok(text, FALSE); |
208 | page_length = 0; | 144 | page_length = 0; |
209 | passed_end = 0; | 145 | passed_end = 0; |
210 | for (i = 0; i < height - 4; i++) { | 146 | for (i = 0; i < texth; i++) { |
211 | if (!i) { | 147 | if (!i) { |
212 | /* print first line of page */ | 148 | /* print first line of page */ |
213 | print_line(text, 0, width - 2); | 149 | print_line(text, 0, textw); |
214 | wnoutrefresh(text); | 150 | wnoutrefresh(text); |
215 | } else | 151 | } else |
216 | /* Called to update 'end_reached' and 'page' */ | 152 | /* Called to update 'end_reached' and 'page' */ |
@@ -231,8 +167,8 @@ int dialog_textbox(const char *title, const char *file, int height, int width) | |||
231 | case KEY_PPAGE: | 167 | case KEY_PPAGE: |
232 | if (begin_reached) | 168 | if (begin_reached) |
233 | break; | 169 | break; |
234 | back_lines(page_length + height - 4); | 170 | back_lines(page_length + texth); |
235 | print_page(text, height - 4, width - 2); | 171 | print_page(text, texth, textw); |
236 | print_position(dialog, height, width); | 172 | print_position(dialog, height, width); |
237 | wmove(dialog, cur_y, cur_x); | 173 | wmove(dialog, cur_y, cur_x); |
238 | wrefresh(dialog); | 174 | wrefresh(dialog); |
@@ -245,7 +181,7 @@ int dialog_textbox(const char *title, const char *file, int height, int width) | |||
245 | scrollok(text, TRUE); | 181 | scrollok(text, TRUE); |
246 | scroll(text); /* Scroll text region up one line */ | 182 | scroll(text); /* Scroll text region up one line */ |
247 | scrollok(text, FALSE); | 183 | scrollok(text, FALSE); |
248 | print_line(text, height - 5, width - 2); | 184 | print_line(text, texth - 1, textw); |
249 | wnoutrefresh(text); | 185 | wnoutrefresh(text); |
250 | print_position(dialog, height, width); | 186 | print_position(dialog, height, width); |
251 | wmove(dialog, cur_y, cur_x); /* Restore cursor position */ | 187 | wmove(dialog, cur_y, cur_x); /* Restore cursor position */ |
@@ -258,7 +194,7 @@ int dialog_textbox(const char *title, const char *file, int height, int width) | |||
258 | break; | 194 | break; |
259 | 195 | ||
260 | begin_reached = 0; | 196 | begin_reached = 0; |
261 | print_page(text, height - 4, width - 2); | 197 | print_page(text, texth, textw); |
262 | print_position(dialog, height, width); | 198 | print_position(dialog, height, width); |
263 | wmove(dialog, cur_y, cur_x); | 199 | wmove(dialog, cur_y, cur_x); |
264 | wrefresh(dialog); | 200 | wrefresh(dialog); |
@@ -276,7 +212,7 @@ int dialog_textbox(const char *title, const char *file, int height, int width) | |||
276 | hscroll--; | 212 | hscroll--; |
277 | /* Reprint current page to scroll horizontally */ | 213 | /* Reprint current page to scroll horizontally */ |
278 | back_lines(page_length); | 214 | back_lines(page_length); |
279 | print_page(text, height - 4, width - 2); | 215 | print_page(text, texth, textw); |
280 | wmove(dialog, cur_y, cur_x); | 216 | wmove(dialog, cur_y, cur_x); |
281 | wrefresh(dialog); | 217 | wrefresh(dialog); |
282 | break; | 218 | break; |
@@ -288,7 +224,7 @@ int dialog_textbox(const char *title, const char *file, int height, int width) | |||
288 | hscroll++; | 224 | hscroll++; |
289 | /* Reprint current page to scroll horizontally */ | 225 | /* Reprint current page to scroll horizontally */ |
290 | back_lines(page_length); | 226 | back_lines(page_length); |
291 | print_page(text, height - 4, width - 2); | 227 | print_page(text, texth, textw); |
292 | wmove(dialog, cur_y, cur_x); | 228 | wmove(dialog, cur_y, cur_x); |
293 | wrefresh(dialog); | 229 | wrefresh(dialog); |
294 | break; | 230 | break; |
@@ -296,123 +232,42 @@ int dialog_textbox(const char *title, const char *file, int height, int width) | |||
296 | break; | 232 | break; |
297 | } | 233 | } |
298 | } | 234 | } |
299 | 235 | delwin(text); | |
300 | delwin(dialog); | 236 | delwin(dialog); |
301 | free(buf); | 237 | return 255; /* ESC pressed */ |
302 | close(fd); | ||
303 | return -1; /* 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 | * 'page' will be updated to point to the desired line in 'buf'. | 242 | * 'page' will be updated to point to the desired line in 'buf'. |
309 | */ | 243 | */ |
310 | static void back_lines(int n) | 244 | static void back_lines(int n) |
311 | { | 245 | { |
312 | int i, fpos; | 246 | int i; |
313 | 247 | ||
314 | begin_reached = 0; | 248 | begin_reached = 0; |
315 | /* We have to distinguish between end_reached and !end_reached | 249 | /* Go back 'n' lines */ |
316 | since at end of file, the line is not ended by a '\n'. | 250 | for (i = 0; i < n; i++) { |
317 | The code inside 'if' basically does a '--page' to move one | 251 | if (*page == '\0') { |
318 | character backward so as to skip '\n' of the previous line */ | 252 | if (end_reached) { |
319 | if (!end_reached) { | 253 | end_reached = 0; |
320 | /* Either beginning of buffer or beginning of file reached? */ | 254 | continue; |
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); | ||
327 | } | ||
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 | } | 255 | } |
364 | } | 256 | } |
365 | if (*(--page) != '\n') { /* '--page' here */ | 257 | if (page == buf) { |
366 | /* Something's wrong... */ | 258 | begin_reached = 1; |
367 | endwin(); | 259 | return; |
368 | fprintf(stderr, "\nInternal error in back_lines().\n"); | ||
369 | exit(-1); | ||
370 | } | 260 | } |
371 | } | 261 | page--; |
372 | /* Go back 'n' lines */ | ||
373 | for (i = 0; i < n; i++) | ||
374 | do { | 262 | do { |
375 | if (page == buf) { | 263 | if (page == buf) { |
376 | if ((fpos = lseek(fd, 0, SEEK_CUR)) == -1) { | 264 | begin_reached = 1; |
377 | endwin(); | 265 | return; |
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 | } | ||
413 | } | 266 | } |
414 | } while (*(--page) != '\n'); | 267 | page--; |
415 | page++; | 268 | } while (*page != '\n'); |
269 | page++; | ||
270 | } | ||
416 | } | 271 | } |
417 | 272 | ||
418 | /* | 273 | /* |
@@ -467,33 +322,14 @@ static void print_line(WINDOW * win, int row, int width) | |||
467 | */ | 322 | */ |
468 | static char *get_line(void) | 323 | static char *get_line(void) |
469 | { | 324 | { |
470 | int i = 0, fpos; | 325 | int i = 0; |
471 | static char line[MAX_LEN + 1]; | 326 | static char line[MAX_LEN + 1]; |
472 | 327 | ||
473 | end_reached = 0; | 328 | end_reached = 0; |
474 | while (*page != '\n') { | 329 | while (*page != '\n') { |
475 | if (*page == '\0') { | 330 | if (*page == '\0') { |
476 | /* Either end of file or end of buffer reached */ | 331 | if (!end_reached) { |
477 | if ((fpos = lseek(fd, 0, SEEK_CUR)) == -1) { | 332 | end_reached = 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; | ||
497 | break; | 333 | break; |
498 | } | 334 | } |
499 | } else if (i < MAX_LEN) | 335 | } else if (i < MAX_LEN) |
@@ -518,17 +354,11 @@ static char *get_line(void) | |||
518 | */ | 354 | */ |
519 | static void print_position(WINDOW * win, int height, int width) | 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 | wattrset(win, dlg.position_indicator.atr); | 359 | wattrset(win, dlg.position_indicator.atr); |
529 | wbkgdset(win, dlg.position_indicator.atr & A_COLOR); | 360 | wbkgdset(win, dlg.position_indicator.atr & A_COLOR); |
530 | percent = !file_size ? | 361 | percent = (page - buf) * 100 / strlen(buf); |
531 | 100 : ((fpos - bytes_read + page - buf) * 100) / file_size; | ||
532 | wmove(win, height - 3, width - 9); | 362 | wmove(win, height - 3, width - 9); |
533 | wprintw(win, "(%3d%%)", percent); | 363 | wprintw(win, "(%3d%%)", percent); |
534 | } | 364 | } |
diff --git a/scripts/kconfig/lxdialog/util.c b/scripts/kconfig/lxdialog/util.c index e73a36df93b4..0b3118df50df 100644 --- a/scripts/kconfig/lxdialog/util.c +++ b/scripts/kconfig/lxdialog/util.c | |||
@@ -268,13 +268,18 @@ void dialog_clear(void) | |||
268 | /* | 268 | /* |
269 | * Do some initialization for dialog | 269 | * Do some initialization for dialog |
270 | */ | 270 | */ |
271 | void init_dialog(void) | 271 | void init_dialog(const char *backtitle) |
272 | { | ||
273 | dlg.backtitle = backtitle; | ||
274 | color_setup(getenv("MENUCONFIG_COLOR")); | ||
275 | } | ||
276 | |||
277 | void reset_dialog(void) | ||
272 | { | 278 | { |
273 | initscr(); /* Init curses */ | 279 | initscr(); /* Init curses */ |
274 | keypad(stdscr, TRUE); | 280 | keypad(stdscr, TRUE); |
275 | cbreak(); | 281 | cbreak(); |
276 | noecho(); | 282 | noecho(); |
277 | color_setup(getenv("MENUCONFIG_COLOR")); | ||
278 | dialog_clear(); | 283 | dialog_clear(); |
279 | } | 284 | } |
280 | 285 | ||
@@ -471,3 +476,128 @@ int first_alpha(const char *string, const char *exempt) | |||
471 | 476 | ||
472 | return 0; | 477 | return 0; |
473 | } | 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); | ||
603 | } | ||
diff --git a/scripts/kconfig/lxdialog/yesno.c b/scripts/kconfig/lxdialog/yesno.c index e938037c8020..9fc24492c52f 100644 --- a/scripts/kconfig/lxdialog/yesno.c +++ b/scripts/kconfig/lxdialog/yesno.c | |||
@@ -99,5 +99,5 @@ int dialog_yesno(const char *title, const char *prompt, int height, int width) | |||
99 | } | 99 | } |
100 | 100 | ||
101 | delwin(dialog); | 101 | delwin(dialog); |
102 | return -1; /* ESC pressed */ | 102 | return 255; /* ESC pressed */ |
103 | } | 103 | } |
diff --git a/scripts/kconfig/mconf.c b/scripts/kconfig/mconf.c index 59926739d169..b1ad9a00ab19 100644 --- a/scripts/kconfig/mconf.c +++ b/scripts/kconfig/mconf.c | |||
@@ -24,6 +24,7 @@ | |||
24 | 24 | ||
25 | #define LKC_DIRECT_LINK | 25 | #define LKC_DIRECT_LINK |
26 | #include "lkc.h" | 26 | #include "lkc.h" |
27 | #include "lxdialog/dialog.h" | ||
27 | 28 | ||
28 | static char menu_backtitle[128]; | 29 | static char menu_backtitle[128]; |
29 | static const char mconf_readme[] = N_( | 30 | static const char mconf_readme[] = N_( |
@@ -270,16 +271,12 @@ search_help[] = N_( | |||
270 | " USB$ => find all CONFIG_ symbols ending with USB\n" | 271 | " USB$ => find all CONFIG_ symbols ending with USB\n" |
271 | "\n"); | 272 | "\n"); |
272 | 273 | ||
273 | static char buf[4096], *bufptr = buf; | ||
274 | static char input_buf[4096]; | ||
275 | static char filename[PATH_MAX+1] = ".config"; | 274 | static char filename[PATH_MAX+1] = ".config"; |
276 | static char *args[1024], **argptr = args; | ||
277 | static int indent; | 275 | static int indent; |
278 | static struct termios ios_org; | 276 | static struct termios ios_org; |
279 | static int rows = 0, cols = 0; | 277 | static int rows = 0, cols = 0; |
280 | static struct menu *current_menu; | 278 | static struct menu *current_menu; |
281 | static int child_count; | 279 | static int child_count; |
282 | static int do_resize; | ||
283 | static int single_menu_mode; | 280 | static int single_menu_mode; |
284 | 281 | ||
285 | static void conf(struct menu *menu); | 282 | static void conf(struct menu *menu); |
@@ -290,12 +287,6 @@ static void conf_save(void); | |||
290 | static void show_textbox(const char *title, const char *text, int r, int c); | 287 | static void show_textbox(const char *title, const char *text, int r, int c); |
291 | static void show_helptext(const char *title, const char *text); | 288 | static void show_helptext(const char *title, const char *text); |
292 | static void show_help(struct menu *menu); | 289 | static void show_help(struct menu *menu); |
293 | static void show_file(const char *filename, const char *title, int r, int c); | ||
294 | |||
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 | 290 | ||
300 | static void init_wsize(void) | 291 | static void init_wsize(void) |
301 | { | 292 | { |
@@ -332,54 +323,6 @@ static void init_wsize(void) | |||
332 | cols -= 5; | 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 | static void get_prompt_str(struct gstr *r, struct property *prop) | 326 | static void get_prompt_str(struct gstr *r, struct property *prop) |
384 | { | 327 | { |
385 | int i, j; | 328 | int i, j; |
@@ -452,108 +395,17 @@ static struct gstr get_relations_str(struct symbol **sym_arr) | |||
452 | return res; | 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 | static void search_conf(void) | 398 | static void search_conf(void) |
539 | { | 399 | { |
540 | struct symbol **sym_arr; | 400 | struct symbol **sym_arr; |
541 | int stat; | ||
542 | struct gstr res; | 401 | struct gstr res; |
543 | 402 | int dres; | |
544 | again: | 403 | again: |
545 | cprint_init(); | 404 | reset_dialog(); |
546 | cprint("--title"); | 405 | dres = dialog_inputbox(_("Search Configuration Parameter"), |
547 | cprint(_("Search Configuration Parameter")); | 406 | _("Enter CONFIG_ (sub)string to search for (omit CONFIG_)"), |
548 | cprint("--inputbox"); | 407 | 10, 75, ""); |
549 | cprint(_("Enter CONFIG_ (sub)string to search for (omit CONFIG_)")); | 408 | switch (dres) { |
550 | cprint("10"); | ||
551 | cprint("75"); | ||
552 | cprint(""); | ||
553 | stat = exec_conf(); | ||
554 | if (stat < 0) | ||
555 | goto again; | ||
556 | switch (stat) { | ||
557 | case 0: | 409 | case 0: |
558 | break; | 410 | break; |
559 | case 1: | 411 | case 1: |
@@ -563,7 +415,7 @@ again: | |||
563 | return; | 415 | return; |
564 | } | 416 | } |
565 | 417 | ||
566 | sym_arr = sym_re_search(input_buf); | 418 | sym_arr = sym_re_search(dialog_input_result); |
567 | res = get_relations_str(sym_arr); | 419 | res = get_relations_str(sym_arr); |
568 | free(sym_arr); | 420 | free(sym_arr); |
569 | show_textbox(_("Search Results"), str_get(&res), 0, 0); | 421 | show_textbox(_("Search Results"), str_get(&res), 0, 0); |
@@ -590,24 +442,24 @@ static void build_conf(struct menu *menu) | |||
590 | switch (prop->type) { | 442 | switch (prop->type) { |
591 | case P_MENU: | 443 | case P_MENU: |
592 | child_count++; | 444 | child_count++; |
593 | cprint("m%p", menu); | ||
594 | |||
595 | if (single_menu_mode) { | 445 | if (single_menu_mode) { |
596 | cprint1("%s%*c%s", | 446 | item_make("%s%*c%s", |
597 | menu->data ? "-->" : "++>", | 447 | menu->data ? "-->" : "++>", |
598 | indent + 1, ' ', prompt); | 448 | indent + 1, ' ', prompt); |
599 | } else | 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 | if (single_menu_mode && menu->data) | 454 | if (single_menu_mode && menu->data) |
604 | goto conf_childs; | 455 | goto conf_childs; |
605 | return; | 456 | return; |
606 | default: | 457 | default: |
607 | if (prompt) { | 458 | if (prompt) { |
608 | child_count++; | 459 | child_count++; |
609 | cprint(":%p", menu); | 460 | item_make("---%*c%s", indent + 1, ' ', prompt); |
610 | cprint("---%*c%s", indent + 1, ' ', prompt); | 461 | item_set_tag(':'); |
462 | item_set_data(menu); | ||
611 | } | 463 | } |
612 | } | 464 | } |
613 | } else | 465 | } else |
@@ -628,10 +480,9 @@ static void build_conf(struct menu *menu) | |||
628 | 480 | ||
629 | val = sym_get_tristate_value(sym); | 481 | val = sym_get_tristate_value(sym); |
630 | if (sym_is_changable(sym)) { | 482 | if (sym_is_changable(sym)) { |
631 | cprint("t%p", menu); | ||
632 | switch (type) { | 483 | switch (type) { |
633 | case S_BOOLEAN: | 484 | case S_BOOLEAN: |
634 | cprint1("[%c]", val == no ? ' ' : '*'); | 485 | item_make("[%c]", val == no ? ' ' : '*'); |
635 | break; | 486 | break; |
636 | case S_TRISTATE: | 487 | case S_TRISTATE: |
637 | switch (val) { | 488 | switch (val) { |
@@ -639,84 +490,87 @@ static void build_conf(struct menu *menu) | |||
639 | case mod: ch = 'M'; break; | 490 | case mod: ch = 'M'; break; |
640 | default: ch = ' '; break; | 491 | default: ch = ' '; break; |
641 | } | 492 | } |
642 | cprint1("<%c>", ch); | 493 | item_make("<%c>", ch); |
643 | break; | 494 | break; |
644 | } | 495 | } |
496 | item_set_tag('t'); | ||
497 | item_set_data(menu); | ||
645 | } else { | 498 | } else { |
646 | cprint("%c%p", def_menu ? 't' : ':', menu); | 499 | item_make(" "); |
647 | cprint1(" "); | 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 | if (val == yes) { | 505 | if (val == yes) { |
652 | if (def_menu) { | 506 | if (def_menu) { |
653 | cprint1(" (%s)", menu_get_prompt(def_menu)); | 507 | item_add_str(" (%s)", menu_get_prompt(def_menu)); |
654 | cprint1(" --->"); | 508 | item_add_str(" --->"); |
655 | cprint_done(); | ||
656 | if (def_menu->list) { | 509 | if (def_menu->list) { |
657 | indent += 2; | 510 | indent += 2; |
658 | build_conf(def_menu); | 511 | build_conf(def_menu); |
659 | indent -= 2; | 512 | indent -= 2; |
660 | } | 513 | } |
661 | } else | 514 | } |
662 | cprint_done(); | ||
663 | return; | 515 | return; |
664 | } | 516 | } |
665 | cprint_done(); | ||
666 | } else { | 517 | } else { |
667 | if (menu == current_menu) { | 518 | if (menu == current_menu) { |
668 | cprint(":%p", menu); | 519 | item_make("---%*c%s", indent + 1, ' ', menu_get_prompt(menu)); |
669 | cprint("---%*c%s", indent + 1, ' ', menu_get_prompt(menu)); | 520 | item_set_tag(':'); |
521 | item_set_data(menu); | ||
670 | goto conf_childs; | 522 | goto conf_childs; |
671 | } | 523 | } |
672 | child_count++; | 524 | child_count++; |
673 | val = sym_get_tristate_value(sym); | 525 | val = sym_get_tristate_value(sym); |
674 | if (sym_is_choice_value(sym) && val == yes) { | 526 | if (sym_is_choice_value(sym) && val == yes) { |
675 | cprint(":%p", menu); | 527 | item_make(" "); |
676 | cprint1(" "); | 528 | item_set_tag(':'); |
529 | item_set_data(menu); | ||
677 | } else { | 530 | } else { |
678 | switch (type) { | 531 | switch (type) { |
679 | case S_BOOLEAN: | 532 | case S_BOOLEAN: |
680 | cprint("t%p", menu); | ||
681 | if (sym_is_changable(sym)) | 533 | if (sym_is_changable(sym)) |
682 | cprint1("[%c]", val == no ? ' ' : '*'); | 534 | item_make("[%c]", val == no ? ' ' : '*'); |
683 | else | 535 | else |
684 | cprint1("---"); | 536 | item_make("---"); |
537 | item_set_tag('t'); | ||
538 | item_set_data(menu); | ||
685 | break; | 539 | break; |
686 | case S_TRISTATE: | 540 | case S_TRISTATE: |
687 | cprint("t%p", menu); | ||
688 | switch (val) { | 541 | switch (val) { |
689 | case yes: ch = '*'; break; | 542 | case yes: ch = '*'; break; |
690 | case mod: ch = 'M'; break; | 543 | case mod: ch = 'M'; break; |
691 | default: ch = ' '; break; | 544 | default: ch = ' '; break; |
692 | } | 545 | } |
693 | if (sym_is_changable(sym)) | 546 | if (sym_is_changable(sym)) |
694 | cprint1("<%c>", ch); | 547 | item_make("<%c>", ch); |
695 | else | 548 | else |
696 | cprint1("---"); | 549 | item_make("---"); |
550 | item_set_tag('t'); | ||
551 | item_set_data(menu); | ||
697 | break; | 552 | break; |
698 | default: | 553 | default: |
699 | cprint("s%p", menu); | 554 | tmp = 2 + strlen(sym_get_string_value(sym)); /* () = 2 */ |
700 | tmp = cprint1("(%s)", sym_get_string_value(sym)); | 555 | item_make("(%s)", sym_get_string_value(sym)); |
701 | tmp = indent - tmp + 4; | 556 | tmp = indent - tmp + 4; |
702 | if (tmp < 0) | 557 | if (tmp < 0) |
703 | tmp = 0; | 558 | tmp = 0; |
704 | cprint1("%*c%s%s", tmp, ' ', menu_get_prompt(menu), | 559 | item_add_str("%*c%s%s", tmp, ' ', menu_get_prompt(menu), |
705 | (sym_has_value(sym) || !sym_is_changable(sym)) ? | 560 | (sym_has_value(sym) || !sym_is_changable(sym)) ? |
706 | "" : " (NEW)"); | 561 | "" : " (NEW)"); |
707 | cprint_done(); | 562 | item_set_tag('s'); |
563 | item_set_data(menu); | ||
708 | goto conf_childs; | 564 | goto conf_childs; |
709 | } | 565 | } |
710 | } | 566 | } |
711 | cprint1("%*c%s%s", indent + 1, ' ', menu_get_prompt(menu), | 567 | item_add_str("%*c%s%s", indent + 1, ' ', menu_get_prompt(menu), |
712 | (sym_has_value(sym) || !sym_is_changable(sym)) ? | 568 | (sym_has_value(sym) || !sym_is_changable(sym)) ? |
713 | "" : " (NEW)"); | 569 | "" : " (NEW)"); |
714 | if (menu->prompt->type == P_MENU) { | 570 | if (menu->prompt->type == P_MENU) { |
715 | cprint1(" --->"); | 571 | item_add_str(" --->"); |
716 | cprint_done(); | ||
717 | return; | 572 | return; |
718 | } | 573 | } |
719 | cprint_done(); | ||
720 | } | 574 | } |
721 | 575 | ||
722 | conf_childs: | 576 | conf_childs: |
@@ -731,59 +585,43 @@ static void conf(struct menu *menu) | |||
731 | struct menu *submenu; | 585 | struct menu *submenu; |
732 | const char *prompt = menu_get_prompt(menu); | 586 | const char *prompt = menu_get_prompt(menu); |
733 | struct symbol *sym; | 587 | struct symbol *sym; |
734 | char active_entry[40]; | 588 | struct menu *active_menu = NULL; |
735 | int stat, type, i; | 589 | int res; |
590 | int s_scroll = 0; | ||
736 | 591 | ||
737 | unlink("lxdialog.scrltmp"); | ||
738 | active_entry[0] = 0; | ||
739 | while (1) { | 592 | while (1) { |
740 | cprint_init(); | 593 | item_reset(); |
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); | ||
749 | current_menu = menu; | 594 | current_menu = menu; |
750 | build_conf(menu); | 595 | build_conf(menu); |
751 | if (!child_count) | 596 | if (!child_count) |
752 | break; | 597 | break; |
753 | if (menu == &rootmenu) { | 598 | if (menu == &rootmenu) { |
754 | cprint(":"); | 599 | item_make("--- "); |
755 | cprint("--- "); | 600 | item_set_tag(':'); |
756 | cprint("L"); | 601 | item_make(_(" Load an Alternate Configuration File")); |
757 | cprint(_(" Load an Alternate Configuration File")); | 602 | item_set_tag('L'); |
758 | cprint("S"); | 603 | item_make(_(" Save an Alternate Configuration File")); |
759 | cprint(_(" Save Configuration to an Alternate File")); | 604 | item_set_tag('S'); |
760 | } | 605 | } |
761 | stat = exec_conf(); | 606 | reset_dialog(); |
762 | if (stat < 0) | 607 | res = dialog_menu(prompt ? prompt : _("Main Menu"), |
763 | continue; | 608 | _(menu_instructions), |
764 | 609 | rows, cols, rows - 10, | |
765 | if (stat == 1 || stat == 255) | 610 | active_menu, &s_scroll); |
611 | if (res == 1 || res == 255) | ||
766 | break; | 612 | break; |
767 | 613 | if (!item_activate_selected()) | |
768 | type = input_buf[0]; | 614 | continue; |
769 | if (!type) | 615 | if (!item_tag()) |
770 | continue; | 616 | continue; |
771 | 617 | ||
772 | for (i = 0; input_buf[i] && !isspace(input_buf[i]); i++) | 618 | submenu = item_data(); |
773 | ; | 619 | active_menu = item_data(); |
774 | if (i >= sizeof(active_entry)) | 620 | sym = submenu->sym; |
775 | i = sizeof(active_entry) - 1; | ||
776 | input_buf[i] = 0; | ||
777 | strcpy(active_entry, input_buf); | ||
778 | |||
779 | sym = NULL; | ||
780 | submenu = NULL; | ||
781 | if (sscanf(input_buf + 1, "%p", &submenu) == 1) | ||
782 | sym = submenu->sym; | ||
783 | 621 | ||
784 | switch (stat) { | 622 | switch (res) { |
785 | case 0: | 623 | case 0: |
786 | switch (type) { | 624 | switch (item_tag()) { |
787 | case 'm': | 625 | case 'm': |
788 | if (single_menu_mode) | 626 | if (single_menu_mode) |
789 | submenu->data = (void *) (long) !submenu->data; | 627 | submenu->data = (void *) (long) !submenu->data; |
@@ -814,7 +652,7 @@ static void conf(struct menu *menu) | |||
814 | show_helptext("README", _(mconf_readme)); | 652 | show_helptext("README", _(mconf_readme)); |
815 | break; | 653 | break; |
816 | case 3: | 654 | case 3: |
817 | if (type == 't') { | 655 | if (item_is_tag('t')) { |
818 | if (sym_set_tristate_value(sym, yes)) | 656 | if (sym_set_tristate_value(sym, yes)) |
819 | break; | 657 | break; |
820 | if (sym_set_tristate_value(sym, mod)) | 658 | if (sym_set_tristate_value(sym, mod)) |
@@ -822,17 +660,17 @@ static void conf(struct menu *menu) | |||
822 | } | 660 | } |
823 | break; | 661 | break; |
824 | case 4: | 662 | case 4: |
825 | if (type == 't') | 663 | if (item_is_tag('t')) |
826 | sym_set_tristate_value(sym, no); | 664 | sym_set_tristate_value(sym, no); |
827 | break; | 665 | break; |
828 | case 5: | 666 | case 5: |
829 | if (type == 't') | 667 | if (item_is_tag('t')) |
830 | sym_set_tristate_value(sym, mod); | 668 | sym_set_tristate_value(sym, mod); |
831 | break; | 669 | break; |
832 | case 6: | 670 | case 6: |
833 | if (type == 't') | 671 | if (item_is_tag('t')) |
834 | sym_toggle_tristate_value(sym); | 672 | sym_toggle_tristate_value(sym); |
835 | else if (type == 'm') | 673 | else if (item_is_tag('m')) |
836 | conf(submenu); | 674 | conf(submenu); |
837 | break; | 675 | break; |
838 | case 7: | 676 | case 7: |
@@ -844,13 +682,8 @@ static void conf(struct menu *menu) | |||
844 | 682 | ||
845 | static void show_textbox(const char *title, const char *text, int r, int c) | 683 | static void show_textbox(const char *title, const char *text, int r, int c) |
846 | { | 684 | { |
847 | int fd; | 685 | reset_dialog(); |
848 | 686 | dialog_textbox(title, text, r ? r : rows, c ? c : cols); | |
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"); | ||
854 | } | 687 | } |
855 | 688 | ||
856 | static void show_helptext(const char *title, const char *text) | 689 | static void show_helptext(const char *title, const char *text) |
@@ -878,62 +711,44 @@ static void show_help(struct menu *menu) | |||
878 | str_free(&help); | 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 | static void conf_choice(struct menu *menu) | 714 | static void conf_choice(struct menu *menu) |
897 | { | 715 | { |
898 | const char *prompt = menu_get_prompt(menu); | 716 | const char *prompt = menu_get_prompt(menu); |
899 | struct menu *child; | 717 | struct menu *child; |
900 | struct symbol *active; | 718 | struct symbol *active; |
901 | int stat; | ||
902 | 719 | ||
903 | active = sym_get_choice_value(menu->sym); | 720 | active = sym_get_choice_value(menu->sym); |
904 | while (1) { | 721 | while (1) { |
905 | cprint_init(); | 722 | int res; |
906 | cprint("--title"); | 723 | int selected; |
907 | cprint("%s", prompt ? prompt : _("Main Menu")); | 724 | item_reset(); |
908 | cprint("--radiolist"); | ||
909 | cprint(_(radiolist_instructions)); | ||
910 | cprint("15"); | ||
911 | cprint("70"); | ||
912 | cprint("6"); | ||
913 | 725 | ||
914 | current_menu = menu; | 726 | current_menu = menu; |
915 | for (child = menu->list; child; child = child->next) { | 727 | for (child = menu->list; child; child = child->next) { |
916 | if (!menu_is_visible(child)) | 728 | if (!menu_is_visible(child)) |
917 | continue; | 729 | continue; |
918 | cprint("%p", child); | 730 | item_make("%s", menu_get_prompt(child)); |
919 | cprint("%s", menu_get_prompt(child)); | 731 | item_set_data(child); |
732 | if (child->sym == active) | ||
733 | item_set_selected(1); | ||
920 | if (child->sym == sym_get_choice_value(menu->sym)) | 734 | if (child->sym == sym_get_choice_value(menu->sym)) |
921 | cprint("ON"); | 735 | item_set_tag('X'); |
922 | else if (child->sym == active) | ||
923 | cprint("SELECTED"); | ||
924 | else | ||
925 | cprint("OFF"); | ||
926 | } | 736 | } |
927 | 737 | reset_dialog(); | |
928 | stat = exec_conf(); | 738 | res = dialog_checklist(prompt ? prompt : _("Main Menu"), |
929 | switch (stat) { | 739 | _(radiolist_instructions), |
740 | 15, 70, 6); | ||
741 | selected = item_activate_selected(); | ||
742 | switch (res) { | ||
930 | case 0: | 743 | case 0: |
931 | if (sscanf(input_buf, "%p", &child) != 1) | 744 | if (selected) { |
932 | break; | 745 | child = item_data(); |
933 | sym_set_tristate_value(child->sym, yes); | 746 | sym_set_tristate_value(child->sym, yes); |
747 | } | ||
934 | return; | 748 | return; |
935 | case 1: | 749 | case 1: |
936 | if (sscanf(input_buf, "%p", &child) == 1) { | 750 | if (selected) { |
751 | child = item_data(); | ||
937 | show_help(child); | 752 | show_help(child); |
938 | active = child->sym; | 753 | active = child->sym; |
939 | } else | 754 | } else |
@@ -948,33 +763,31 @@ static void conf_choice(struct menu *menu) | |||
948 | static void conf_string(struct menu *menu) | 763 | static void conf_string(struct menu *menu) |
949 | { | 764 | { |
950 | const char *prompt = menu_get_prompt(menu); | 765 | const char *prompt = menu_get_prompt(menu); |
951 | int stat; | ||
952 | 766 | ||
953 | while (1) { | 767 | while (1) { |
954 | cprint_init(); | 768 | int res; |
955 | cprint("--title"); | 769 | char *heading; |
956 | cprint("%s", prompt ? prompt : _("Main Menu")); | 770 | |
957 | cprint("--inputbox"); | ||
958 | switch (sym_get_type(menu->sym)) { | 771 | switch (sym_get_type(menu->sym)) { |
959 | case S_INT: | 772 | case S_INT: |
960 | cprint(_(inputbox_instructions_int)); | 773 | heading = _(inputbox_instructions_int); |
961 | break; | 774 | break; |
962 | case S_HEX: | 775 | case S_HEX: |
963 | cprint(_(inputbox_instructions_hex)); | 776 | heading = _(inputbox_instructions_hex); |
964 | break; | 777 | break; |
965 | case S_STRING: | 778 | case S_STRING: |
966 | cprint(_(inputbox_instructions_string)); | 779 | heading = _(inputbox_instructions_string); |
967 | break; | 780 | break; |
968 | default: | 781 | default: |
969 | /* panic? */; | 782 | heading = "Internal mconf error!"; |
970 | } | 783 | } |
971 | cprint("10"); | 784 | reset_dialog(); |
972 | cprint("75"); | 785 | res = dialog_inputbox(prompt ? prompt : _("Main Menu"), |
973 | cprint("%s", sym_get_string_value(menu->sym)); | 786 | heading, 10, 75, |
974 | stat = exec_conf(); | 787 | sym_get_string_value(menu->sym)); |
975 | switch (stat) { | 788 | switch (res) { |
976 | case 0: | 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 | return; | 791 | return; |
979 | show_textbox(NULL, _("You have made an invalid entry."), 5, 43); | 792 | show_textbox(NULL, _("You have made an invalid entry."), 5, 43); |
980 | break; | 793 | break; |
@@ -989,21 +802,17 @@ static void conf_string(struct menu *menu) | |||
989 | 802 | ||
990 | static void conf_load(void) | 803 | static void conf_load(void) |
991 | { | 804 | { |
992 | int stat; | ||
993 | 805 | ||
994 | while (1) { | 806 | while (1) { |
995 | cprint_init(); | 807 | int res; |
996 | cprint("--inputbox"); | 808 | reset_dialog(); |
997 | cprint(load_config_text); | 809 | res = dialog_inputbox(NULL, load_config_text, |
998 | cprint("11"); | 810 | 11, 55, filename); |
999 | cprint("55"); | 811 | switch(res) { |
1000 | cprint("%s", filename); | ||
1001 | stat = exec_conf(); | ||
1002 | switch(stat) { | ||
1003 | case 0: | 812 | case 0: |
1004 | if (!input_buf[0]) | 813 | if (!dialog_input_result[0]) |
1005 | return; | 814 | return; |
1006 | if (!conf_read(input_buf)) | 815 | if (!conf_read(dialog_input_result)) |
1007 | return; | 816 | return; |
1008 | show_textbox(NULL, _("File does not exist!"), 5, 38); | 817 | show_textbox(NULL, _("File does not exist!"), 5, 38); |
1009 | break; | 818 | break; |
@@ -1018,21 +827,16 @@ static void conf_load(void) | |||
1018 | 827 | ||
1019 | static void conf_save(void) | 828 | static void conf_save(void) |
1020 | { | 829 | { |
1021 | int stat; | ||
1022 | |||
1023 | while (1) { | 830 | while (1) { |
1024 | cprint_init(); | 831 | int res; |
1025 | cprint("--inputbox"); | 832 | reset_dialog(); |
1026 | cprint(save_config_text); | 833 | res = dialog_inputbox(NULL, save_config_text, |
1027 | cprint("11"); | 834 | 11, 55, filename); |
1028 | cprint("55"); | 835 | switch(res) { |
1029 | cprint("%s", filename); | ||
1030 | stat = exec_conf(); | ||
1031 | switch(stat) { | ||
1032 | case 0: | 836 | case 0: |
1033 | if (!input_buf[0]) | 837 | if (!dialog_input_result[0]) |
1034 | return; | 838 | return; |
1035 | if (!conf_write(input_buf)) | 839 | if (!conf_write(dialog_input_result)) |
1036 | return; | 840 | return; |
1037 | show_textbox(NULL, _("Can't create file! Probably a nonexistent directory."), 5, 60); | 841 | show_textbox(NULL, _("Can't create file! Probably a nonexistent directory."), 5, 60); |
1038 | break; | 842 | break; |
@@ -1048,15 +852,13 @@ static void conf_save(void) | |||
1048 | static void conf_cleanup(void) | 852 | static void conf_cleanup(void) |
1049 | { | 853 | { |
1050 | tcsetattr(1, TCSAFLUSH, &ios_org); | 854 | tcsetattr(1, TCSAFLUSH, &ios_org); |
1051 | unlink(".help.tmp"); | ||
1052 | unlink("lxdialog.scrltmp"); | ||
1053 | } | 855 | } |
1054 | 856 | ||
1055 | int main(int ac, char **av) | 857 | int main(int ac, char **av) |
1056 | { | 858 | { |
1057 | struct symbol *sym; | 859 | struct symbol *sym; |
1058 | char *mode; | 860 | char *mode; |
1059 | int stat; | 861 | int res; |
1060 | 862 | ||
1061 | setlocale(LC_ALL, ""); | 863 | setlocale(LC_ALL, ""); |
1062 | bindtextdomain(PACKAGE, LOCALEDIR); | 864 | bindtextdomain(PACKAGE, LOCALEDIR); |
@@ -1079,18 +881,16 @@ int main(int ac, char **av) | |||
1079 | tcgetattr(1, &ios_org); | 881 | tcgetattr(1, &ios_org); |
1080 | atexit(conf_cleanup); | 882 | atexit(conf_cleanup); |
1081 | init_wsize(); | 883 | init_wsize(); |
884 | reset_dialog(); | ||
885 | init_dialog(menu_backtitle); | ||
1082 | conf(&rootmenu); | 886 | conf(&rootmenu); |
1083 | 887 | reset_dialog(); | |
1084 | do { | 888 | res = dialog_yesno(NULL, |
1085 | cprint_init(); | 889 | _("Do you wish to save your " |
1086 | cprint("--yesno"); | 890 | "new kernel configuration?"), |
1087 | cprint(_("Do you wish to save your new kernel configuration?")); | 891 | 5, 60); |
1088 | cprint("5"); | 892 | end_dialog(); |
1089 | cprint("60"); | 893 | if (res == 0) { |
1090 | stat = exec_conf(); | ||
1091 | } while (stat < 0); | ||
1092 | |||
1093 | if (stat == 0) { | ||
1094 | if (conf_write(NULL)) { | 894 | if (conf_write(NULL)) { |
1095 | fprintf(stderr, _("\n\n" | 895 | fprintf(stderr, _("\n\n" |
1096 | "Error during writing of the kernel configuration.\n" | 896 | "Error during writing of the kernel configuration.\n" |