b75cabe017cabdc701753fa1f6707496d79e6d2d
[openwrt/staging/stintel.git] / scripts / config / nconf.c
1 // SPDX-License-Identifier: GPL-2.0-only
2 /*
3 * Copyright (C) 2008 Nir Tzachar <nir.tzachar@gmail.com>
4 *
5 * Derived from menuconfig.
6 */
7 #ifndef _GNU_SOURCE
8 #define _GNU_SOURCE
9 #endif
10 #include <string.h>
11 #include <strings.h>
12 #include <stdlib.h>
13
14 #include "lkc.h"
15 #include "nconf.h"
16 #include <ctype.h>
17
18 static const char nconf_global_help[] =
19 "Help windows\n"
20 "------------\n"
21 "o Global help: Unless in a data entry window, pressing <F1> will give \n"
22 " you the global help window, which you are just reading.\n"
23 "\n"
24 "o A short version of the global help is available by pressing <F3>.\n"
25 "\n"
26 "o Local help: To get help related to the current menu entry, use any\n"
27 " of <?> <h>, or if in a data entry window then press <F1>.\n"
28 "\n"
29 "\n"
30 "OpenWrt config is based on Kernel kconfig\n"
31 "so ipkg packages are referred here as modules.\n"
32 "\n"
33 "Menu entries\n"
34 "------------\n"
35 "This interface lets you select features and parameters for the build.\n"
36 "Features can either be built-in, modularized, or removed.\n"
37 "Parameters must be entered as text or decimal or hexadecimal numbers.\n"
38 "\n"
39 "Menu entries beginning with following braces represent features that\n"
40 " [ ] can be built in or removed\n"
41 " < > can be built in, modularized or removed\n"
42 " { } can be built in or modularized, are selected by another feature\n"
43 " - - are selected by another feature\n"
44 " XXX cannot be selected. Symbol Info <F2> tells you why.\n"
45 "*, M or whitespace inside braces means to build in, build as a module\n"
46 "or to exclude the feature respectively.\n"
47 "\n"
48 "To change any of these features, highlight it with the movement keys\n"
49 "listed below and press <y> to build it in, <m> to make it a module or\n"
50 "<n> to remove it. You may press the <Space> key to cycle through the\n"
51 "available options.\n"
52 "\n"
53 "A trailing \"--->\" designates a submenu, a trailing \"----\" an\n"
54 "empty submenu.\n"
55 "\n"
56 "Menu navigation keys\n"
57 "----------------------------------------------------------------------\n"
58 "Linewise up <Up>\n"
59 "Linewise down <Down>\n"
60 "Pagewise up <Page Up>\n"
61 "Pagewise down <Page Down>\n"
62 "First entry <Home>\n"
63 "Last entry <End>\n"
64 "Enter a submenu <Right> <Enter>\n"
65 "Go back to parent menu <Left> <Esc> <F5>\n"
66 "Close a help window <Enter> <Esc> <F5>\n"
67 "Close entry window, apply <Enter>\n"
68 "Close entry window, forget <Esc> <F5>\n"
69 "Start incremental, case-insensitive search for STRING in menu entries,\n"
70 " no regex support, STRING is displayed in upper left corner\n"
71 " </>STRING\n"
72 " Remove last character <Backspace>\n"
73 " Jump to next hit <Down>\n"
74 " Jump to previous hit <Up>\n"
75 "Exit menu search mode </> <Esc>\n"
76 "Search for configuration variables with or without leading CONFIG_\n"
77 " <F8>RegExpr<Enter>\n"
78 "Verbose search help <F8><F1>\n"
79 "----------------------------------------------------------------------\n"
80 "\n"
81 "Unless in a data entry window, key <1> may be used instead of <F1>,\n"
82 "<2> instead of <F2>, etc.\n"
83 "\n"
84 "\n"
85 "Radiolist (Choice list)\n"
86 "-----------------------\n"
87 "Use the movement keys listed above to select the option you wish to set\n"
88 "and press <Space>.\n"
89 "\n"
90 "\n"
91 "Data entry\n"
92 "----------\n"
93 "Enter the requested information and press <Enter>. Hexadecimal values\n"
94 "may be entered without the \"0x\" prefix.\n"
95 "\n"
96 "\n"
97 "Text Box (Help Window)\n"
98 "----------------------\n"
99 "Use movement keys as listed in table above.\n"
100 "\n"
101 "Press any of <Enter> <Esc> <q> <F5> <F9> to exit.\n"
102 "\n"
103 "\n"
104 "Alternate configuration files\n"
105 "-----------------------------\n"
106 "nconfig supports switching between different configurations.\n"
107 "Press <F6> to save your current configuration. Press <F7> and enter\n"
108 "a file name to load a previously saved configuration.\n"
109 "\n"
110 "\n"
111 "Terminal configuration\n"
112 "----------------------\n"
113 "If you use nconfig in a xterm window, make sure your TERM environment\n"
114 "variable specifies a terminal configuration which supports at least\n"
115 "16 colors. Otherwise nconfig will look rather bad.\n"
116 "\n"
117 "If the \"stty size\" command reports the current terminalsize correctly,\n"
118 "nconfig will adapt to sizes larger than the traditional 80x25 \"standard\"\n"
119 "and display longer menus properly.\n"
120 "\n"
121 "\n"
122 "Single menu mode\n"
123 "----------------\n"
124 "If you prefer to have all of the menu entries listed in a single menu,\n"
125 "rather than the default multimenu hierarchy, run nconfig with\n"
126 "NCONFIG_MODE environment variable set to single_menu. Example:\n"
127 "\n"
128 "make NCONFIG_MODE=single_menu nconfig\n"
129 "\n"
130 "<Enter> will then unfold the appropriate category, or fold it if it\n"
131 "is already unfolded. Folded menu entries will be designated by a\n"
132 "leading \"++>\" and unfolded entries by a leading \"-->\".\n"
133 "\n"
134 "Note that this mode can eventually be a little more CPU expensive than\n"
135 "the default mode, especially with a larger number of unfolded submenus.\n"
136 "\n",
137 menu_no_f_instructions[] =
138 "Legend: [*] built-in [ ] excluded <M> module < > module capable.\n"
139 "Submenus are designated by a trailing \"--->\", empty ones by \"----\".\n"
140 "\n"
141 "Use the following keys to navigate the menus:\n"
142 "Move up or down with <Up> and <Down>.\n"
143 "Enter a submenu with <Enter> or <Right>.\n"
144 "Exit a submenu to its parent menu with <Esc> or <Left>.\n"
145 "Pressing <y> includes, <n> excludes, <m> modularizes features.\n"
146 "Pressing <Space> cycles through the available options.\n"
147 "To search for menu entries press </>.\n"
148 "<Esc> always leaves the current window.\n"
149 "\n"
150 "You do not have function keys support.\n"
151 "Press <1> instead of <F1>, <2> instead of <F2>, etc.\n"
152 "For verbose global help use key <1>.\n"
153 "For help related to the current menu entry press <?> or <h>.\n",
154 menu_instructions[] =
155 "Legend: [*] built-in [ ] excluded <M> module < > module capable.\n"
156 "Submenus are designated by a trailing \"--->\", empty ones by \"----\".\n"
157 "\n"
158 "Use the following keys to navigate the menus:\n"
159 "Move up or down with <Up> or <Down>.\n"
160 "Enter a submenu with <Enter> or <Right>.\n"
161 "Exit a submenu to its parent menu with <Esc> or <Left>.\n"
162 "Pressing <y> includes, <n> excludes, <m> modularizes features.\n"
163 "Pressing <Space> cycles through the available options.\n"
164 "To search for menu entries press </>.\n"
165 "<Esc> always leaves the current window.\n"
166 "\n"
167 "Pressing <1> may be used instead of <F1>, <2> instead of <F2>, etc.\n"
168 "For verbose global help press <F1>.\n"
169 "For help related to the current menu entry press <?> or <h>.\n",
170 radiolist_instructions[] =
171 "Press <Up>, <Down>, <Home> or <End> to navigate a radiolist, select\n"
172 "with <Space>.\n"
173 "For help related to the current entry press <?> or <h>.\n"
174 "For global help press <F1>.\n",
175 inputbox_instructions_int[] =
176 "Please enter a decimal value.\n"
177 "Fractions will not be accepted.\n"
178 "Press <Enter> to apply, <Esc> to cancel.",
179 inputbox_instructions_hex[] =
180 "Please enter a hexadecimal value.\n"
181 "Press <Enter> to apply, <Esc> to cancel.",
182 inputbox_instructions_string[] =
183 "Please enter a string value.\n"
184 "Press <Enter> to apply, <Esc> to cancel.",
185 setmod_text[] =
186 "This feature depends on another feature which has been configured as a\n"
187 "module. As a result, the current feature will be built as a module too.",
188 load_config_text[] =
189 "Enter the name of the configuration file you wish to load.\n"
190 "Accept the name shown to restore the configuration you last\n"
191 "retrieved. Leave empty to abort.",
192 load_config_help[] =
193 "For various reasons, one may wish to keep several different\n"
194 "configurations available on a single machine.\n"
195 "\n"
196 "If you have saved a previous configuration in a file other than the\n"
197 "default one, entering its name here will allow you to load and modify\n"
198 "that configuration.\n"
199 "\n"
200 "Leave empty to abort.\n",
201 save_config_text[] =
202 "Enter a filename to which this configuration should be saved\n"
203 "as an alternate. Leave empty to abort.",
204 save_config_help[] =
205 "For various reasons, one may wish to keep several different\n"
206 "configurations available on a single machine.\n"
207 "\n"
208 "Entering a file name here will allow you to later retrieve, modify\n"
209 "and use the current configuration as an alternate to whatever\n"
210 "configuration options you have selected at that time.\n"
211 "\n"
212 "Leave empty to abort.\n",
213 search_help[] =
214 "Search for symbols (configuration variable names CONFIG_*) and display\n"
215 "their relations. Regular expressions are supported.\n"
216 "Example: Search for \"^FOO\".\n"
217 "Result:\n"
218 "-----------------------------------------------------------------\n"
219 "Symbol: FOO [ = m]\n"
220 "Prompt: Foo bus is used to drive the bar HW\n"
221 "Defined at drivers/pci/Kconfig:47\n"
222 "Depends on: X86_LOCAL_APIC && X86_IO_APIC || IA64\n"
223 "Location:\n"
224 " -> Bus options (PCI, PCMCIA, EISA, ISA)\n"
225 " -> PCI support (PCI [ = y])\n"
226 " -> PCI access mode (<choice> [ = y])\n"
227 "Selects: LIBCRC32\n"
228 "Selected by: BAR\n"
229 "-----------------------------------------------------------------\n"
230 "o The line 'Prompt:' shows the text displayed for this symbol in\n"
231 " the menu hierarchy.\n"
232 "o The 'Defined at' line tells at what file / line number the symbol is\n"
233 " defined.\n"
234 "o The 'Depends on:' line lists symbols that need to be defined for\n"
235 " this symbol to be visible and selectable in the menu.\n"
236 "o The 'Location:' lines tell, where in the menu structure this symbol\n"
237 " is located. A location followed by a [ = y] indicates that this is\n"
238 " a selectable menu item, and the current value is displayed inside\n"
239 " brackets.\n"
240 "o The 'Selects:' line tells, what symbol will be automatically selected\n"
241 " if this symbol is selected (y or m).\n"
242 "o The 'Selected by' line tells what symbol has selected this symbol.\n"
243 "\n"
244 "Only relevant lines are shown.\n"
245 "\n\n"
246 "Search examples:\n"
247 "USB => find all symbols containing USB\n"
248 "^USB => find all symbols starting with USB\n"
249 "USB$ => find all symbols ending with USB\n"
250 "\n";
251
252 struct mitem {
253 char str[256];
254 char tag;
255 void *usrptr;
256 int is_visible;
257 };
258
259 #define MAX_MENU_ITEMS 4096
260 static int show_all_items;
261 static int indent;
262 static struct menu *current_menu;
263 static int child_count;
264 static int single_menu_mode;
265 /* the window in which all information appears */
266 static WINDOW *main_window;
267 /* the largest size of the menu window */
268 static int mwin_max_lines;
269 static int mwin_max_cols;
270 /* the window in which we show option buttons */
271 static MENU *curses_menu;
272 static ITEM *curses_menu_items[MAX_MENU_ITEMS];
273 static struct mitem k_menu_items[MAX_MENU_ITEMS];
274 static unsigned int items_num;
275 static int global_exit;
276 /* the currently selected button */
277 static const char *current_instructions = menu_instructions;
278
279 static char *dialog_input_result;
280 static int dialog_input_result_len;
281
282 static void conf(struct menu *menu);
283 static void conf_choice(struct menu *menu);
284 static void conf_string(struct menu *menu);
285 static void conf_load(void);
286 static void conf_save(void);
287 static void show_help(struct menu *menu);
288 static int do_exit(void);
289 static void setup_windows(void);
290 static void search_conf(void);
291
292 typedef void (*function_key_handler_t)(int *key, struct menu *menu);
293 static void handle_f1(int *key, struct menu *current_item);
294 static void handle_f2(int *key, struct menu *current_item);
295 static void handle_f3(int *key, struct menu *current_item);
296 static void handle_f4(int *key, struct menu *current_item);
297 static void handle_f5(int *key, struct menu *current_item);
298 static void handle_f6(int *key, struct menu *current_item);
299 static void handle_f7(int *key, struct menu *current_item);
300 static void handle_f8(int *key, struct menu *current_item);
301 static void handle_f9(int *key, struct menu *current_item);
302
303 struct function_keys {
304 const char *key_str;
305 const char *func;
306 function_key key;
307 function_key_handler_t handler;
308 };
309
310 static const int function_keys_num = 9;
311 static struct function_keys function_keys[] = {
312 {
313 .key_str = "F1",
314 .func = "Help",
315 .key = F_HELP,
316 .handler = handle_f1,
317 },
318 {
319 .key_str = "F2",
320 .func = "SymInfo",
321 .key = F_SYMBOL,
322 .handler = handle_f2,
323 },
324 {
325 .key_str = "F3",
326 .func = "Help 2",
327 .key = F_INSTS,
328 .handler = handle_f3,
329 },
330 {
331 .key_str = "F4",
332 .func = "ShowAll",
333 .key = F_CONF,
334 .handler = handle_f4,
335 },
336 {
337 .key_str = "F5",
338 .func = "Back",
339 .key = F_BACK,
340 .handler = handle_f5,
341 },
342 {
343 .key_str = "F6",
344 .func = "Save",
345 .key = F_SAVE,
346 .handler = handle_f6,
347 },
348 {
349 .key_str = "F7",
350 .func = "Load",
351 .key = F_LOAD,
352 .handler = handle_f7,
353 },
354 {
355 .key_str = "F8",
356 .func = "SymSearch",
357 .key = F_SEARCH,
358 .handler = handle_f8,
359 },
360 {
361 .key_str = "F9",
362 .func = "Exit",
363 .key = F_EXIT,
364 .handler = handle_f9,
365 },
366 };
367
368 static void print_function_line(void)
369 {
370 int i;
371 int offset = 1;
372 const int skip = 1;
373 int lines = getmaxy(stdscr);
374
375 for (i = 0; i < function_keys_num; i++) {
376 wattrset(main_window, attr_function_highlight);
377 mvwprintw(main_window, lines-3, offset,
378 "%s",
379 function_keys[i].key_str);
380 wattrset(main_window, attr_function_text);
381 offset += strlen(function_keys[i].key_str);
382 mvwprintw(main_window, lines-3,
383 offset, "%s",
384 function_keys[i].func);
385 offset += strlen(function_keys[i].func) + skip;
386 }
387 wattrset(main_window, attr_normal);
388 }
389
390 /* help */
391 static void handle_f1(int *key, struct menu *current_item)
392 {
393 show_scroll_win(main_window,
394 "Global help", nconf_global_help);
395 return;
396 }
397
398 /* symbole help */
399 static void handle_f2(int *key, struct menu *current_item)
400 {
401 show_help(current_item);
402 return;
403 }
404
405 /* instructions */
406 static void handle_f3(int *key, struct menu *current_item)
407 {
408 show_scroll_win(main_window,
409 "Short help",
410 current_instructions);
411 return;
412 }
413
414 /* config */
415 static void handle_f4(int *key, struct menu *current_item)
416 {
417 int res = btn_dialog(main_window,
418 "Show all symbols?",
419 2,
420 " <Show All> ",
421 "<Don't show all>");
422 if (res == 0)
423 show_all_items = 1;
424 else if (res == 1)
425 show_all_items = 0;
426
427 return;
428 }
429
430 /* back */
431 static void handle_f5(int *key, struct menu *current_item)
432 {
433 *key = KEY_LEFT;
434 return;
435 }
436
437 /* save */
438 static void handle_f6(int *key, struct menu *current_item)
439 {
440 conf_save();
441 return;
442 }
443
444 /* load */
445 static void handle_f7(int *key, struct menu *current_item)
446 {
447 conf_load();
448 return;
449 }
450
451 /* search */
452 static void handle_f8(int *key, struct menu *current_item)
453 {
454 search_conf();
455 return;
456 }
457
458 /* exit */
459 static void handle_f9(int *key, struct menu *current_item)
460 {
461 do_exit();
462 return;
463 }
464
465 /* return != 0 to indicate the key was handles */
466 static int process_special_keys(int *key, struct menu *menu)
467 {
468 int i;
469
470 if (*key == KEY_RESIZE) {
471 setup_windows();
472 return 1;
473 }
474
475 for (i = 0; i < function_keys_num; i++) {
476 if (*key == KEY_F(function_keys[i].key) ||
477 *key == '0' + function_keys[i].key){
478 function_keys[i].handler(key, menu);
479 return 1;
480 }
481 }
482
483 return 0;
484 }
485
486 static void clean_items(void)
487 {
488 int i;
489 for (i = 0; curses_menu_items[i]; i++)
490 free_item(curses_menu_items[i]);
491 bzero(curses_menu_items, sizeof(curses_menu_items));
492 bzero(k_menu_items, sizeof(k_menu_items));
493 items_num = 0;
494 }
495
496 typedef enum {MATCH_TINKER_PATTERN_UP, MATCH_TINKER_PATTERN_DOWN,
497 FIND_NEXT_MATCH_DOWN, FIND_NEXT_MATCH_UP} match_f;
498
499 /* return the index of the matched item, or -1 if no such item exists */
500 static int get_mext_match(const char *match_str, match_f flag)
501 {
502 int match_start, index;
503
504 /* Do not search if the menu is empty (i.e. items_num == 0) */
505 match_start = item_index(current_item(curses_menu));
506 if (match_start == ERR)
507 return -1;
508
509 if (flag == FIND_NEXT_MATCH_DOWN)
510 ++match_start;
511 else if (flag == FIND_NEXT_MATCH_UP)
512 --match_start;
513
514 match_start = (match_start + items_num) % items_num;
515 index = match_start;
516 while (true) {
517 char *str = k_menu_items[index].str;
518 if (strcasestr(str, match_str) != NULL)
519 return index;
520 if (flag == FIND_NEXT_MATCH_UP ||
521 flag == MATCH_TINKER_PATTERN_UP)
522 --index;
523 else
524 ++index;
525 index = (index + items_num) % items_num;
526 if (index == match_start)
527 return -1;
528 }
529 }
530
531 /* Make a new item. */
532 static void item_make(struct menu *menu, char tag, const char *fmt, ...)
533 {
534 va_list ap;
535
536 if (items_num > MAX_MENU_ITEMS-1)
537 return;
538
539 bzero(&k_menu_items[items_num], sizeof(k_menu_items[0]));
540 k_menu_items[items_num].tag = tag;
541 k_menu_items[items_num].usrptr = menu;
542 if (menu != NULL)
543 k_menu_items[items_num].is_visible =
544 menu_is_visible(menu);
545 else
546 k_menu_items[items_num].is_visible = 1;
547
548 va_start(ap, fmt);
549 vsnprintf(k_menu_items[items_num].str,
550 sizeof(k_menu_items[items_num].str),
551 fmt, ap);
552 va_end(ap);
553
554 if (!k_menu_items[items_num].is_visible)
555 memcpy(k_menu_items[items_num].str, "XXX", 3);
556
557 curses_menu_items[items_num] = new_item(
558 k_menu_items[items_num].str,
559 k_menu_items[items_num].str);
560 set_item_userptr(curses_menu_items[items_num],
561 &k_menu_items[items_num]);
562 /*
563 if (!k_menu_items[items_num].is_visible)
564 item_opts_off(curses_menu_items[items_num], O_SELECTABLE);
565 */
566
567 items_num++;
568 curses_menu_items[items_num] = NULL;
569 }
570
571 /* very hackish. adds a string to the last item added */
572 static void item_add_str(const char *fmt, ...)
573 {
574 va_list ap;
575 int index = items_num-1;
576 char new_str[256];
577 char tmp_str[256];
578
579 if (index < 0)
580 return;
581
582 va_start(ap, fmt);
583 vsnprintf(new_str, sizeof(new_str), fmt, ap);
584 va_end(ap);
585 snprintf(tmp_str, sizeof(tmp_str), "%s%s",
586 k_menu_items[index].str, new_str);
587 strncpy(k_menu_items[index].str,
588 tmp_str,
589 sizeof(k_menu_items[index].str));
590
591 free_item(curses_menu_items[index]);
592 curses_menu_items[index] = new_item(
593 k_menu_items[index].str,
594 k_menu_items[index].str);
595 set_item_userptr(curses_menu_items[index],
596 &k_menu_items[index]);
597 }
598
599 /* get the tag of the currently selected item */
600 static char item_tag(void)
601 {
602 ITEM *cur;
603 struct mitem *mcur;
604
605 cur = current_item(curses_menu);
606 if (cur == NULL)
607 return 0;
608 mcur = (struct mitem *) item_userptr(cur);
609 return mcur->tag;
610 }
611
612 static int curses_item_index(void)
613 {
614 return item_index(current_item(curses_menu));
615 }
616
617 static void *item_data(void)
618 {
619 ITEM *cur;
620 struct mitem *mcur;
621
622 cur = current_item(curses_menu);
623 if (!cur)
624 return NULL;
625 mcur = (struct mitem *) item_userptr(cur);
626 return mcur->usrptr;
627
628 }
629
630 static int item_is_tag(char tag)
631 {
632 return item_tag() == tag;
633 }
634
635 static char filename[PATH_MAX+1];
636 static char menu_backtitle[PATH_MAX+128];
637 static void set_config_filename(const char *config_filename)
638 {
639 snprintf(menu_backtitle, sizeof(menu_backtitle), "%s - %s",
640 config_filename, rootmenu.prompt->text);
641
642 snprintf(filename, sizeof(filename), "%s", config_filename);
643 }
644
645 /* return = 0 means we are successful.
646 * -1 means go on doing what you were doing
647 */
648 static int do_exit(void)
649 {
650 int res;
651 if (!conf_get_changed()) {
652 global_exit = 1;
653 return 0;
654 }
655 res = btn_dialog(main_window,
656 "Do you wish to save your new configuration?\n"
657 "<ESC> to cancel and resume nconfig.",
658 2,
659 " <save> ",
660 "<don't save>");
661 if (res == KEY_EXIT) {
662 global_exit = 0;
663 return -1;
664 }
665
666 /* if we got here, the user really wants to exit */
667 switch (res) {
668 case 0:
669 res = conf_write(filename);
670 if (res)
671 btn_dialog(
672 main_window,
673 "Error during writing of configuration.\n"
674 "Your configuration changes were NOT saved.",
675 1,
676 "<OK>");
677 conf_write_autoconf(0);
678 break;
679 default:
680 btn_dialog(
681 main_window,
682 "Your configuration changes were NOT saved.",
683 1,
684 "<OK>");
685 break;
686 }
687 global_exit = 1;
688 return 0;
689 }
690
691
692 static void search_conf(void)
693 {
694 struct symbol **sym_arr;
695 struct gstr res;
696 struct gstr title;
697 char *dialog_input;
698 int dres;
699
700 title = str_new();
701 str_printf( &title, "Enter (sub)string or regexp to search for "
702 "(with or without \"%s\")", CONFIG_);
703
704 again:
705 dres = dialog_inputbox(main_window,
706 "Search Configuration Parameter",
707 str_get(&title),
708 "", &dialog_input_result, &dialog_input_result_len);
709 switch (dres) {
710 case 0:
711 break;
712 case 1:
713 show_scroll_win(main_window,
714 "Search Configuration", search_help);
715 goto again;
716 default:
717 str_free(&title);
718 return;
719 }
720
721 /* strip the prefix if necessary */
722 dialog_input = dialog_input_result;
723 if (strncasecmp(dialog_input_result, CONFIG_, strlen(CONFIG_)) == 0)
724 dialog_input += strlen(CONFIG_);
725
726 sym_arr = sym_re_search(dialog_input);
727 res = get_relations_str(sym_arr, NULL);
728 free(sym_arr);
729 show_scroll_win(main_window,
730 "Search Results", str_get(&res));
731 str_free(&res);
732 str_free(&title);
733 }
734
735
736 static void build_conf(struct menu *menu)
737 {
738 struct symbol *sym;
739 struct property *prop;
740 struct menu *child;
741 int type, tmp, doint = 2;
742 tristate val;
743 char ch;
744
745 if (!menu || (!show_all_items && !menu_is_visible(menu)))
746 return;
747
748 sym = menu->sym;
749 prop = menu->prompt;
750 if (!sym) {
751 if (prop && menu != current_menu) {
752 const char *prompt = menu_get_prompt(menu);
753 enum prop_type ptype;
754 ptype = menu->prompt ? menu->prompt->type : P_UNKNOWN;
755 switch (ptype) {
756 case P_MENU:
757 child_count++;
758 if (single_menu_mode) {
759 item_make(menu, 'm',
760 "%s%*c%s",
761 menu->data ? "-->" : "++>",
762 indent + 1, ' ', prompt);
763 } else
764 item_make(menu, 'm',
765 " %*c%s %s",
766 indent + 1, ' ', prompt,
767 menu_is_empty(menu) ? "----" : "--->");
768
769 if (single_menu_mode && menu->data)
770 goto conf_childs;
771 return;
772 case P_COMMENT:
773 if (prompt) {
774 child_count++;
775 item_make(menu, ':',
776 " %*c*** %s ***",
777 indent + 1, ' ',
778 prompt);
779 }
780 break;
781 default:
782 if (prompt) {
783 child_count++;
784 item_make(menu, ':', "---%*c%s",
785 indent + 1, ' ',
786 prompt);
787 }
788 }
789 } else
790 doint = 0;
791 goto conf_childs;
792 }
793
794 type = sym_get_type(sym);
795 if (sym_is_choice(sym)) {
796 struct symbol *def_sym = sym_get_choice_value(sym);
797 struct menu *def_menu = NULL;
798
799 child_count++;
800 for (child = menu->list; child; child = child->next) {
801 if (menu_is_visible(child) && child->sym == def_sym)
802 def_menu = child;
803 }
804
805 val = sym_get_tristate_value(sym);
806 if (sym_is_changeable(sym)) {
807 switch (type) {
808 case S_BOOLEAN:
809 item_make(menu, 't', "[%c]",
810 val == no ? ' ' : '*');
811 break;
812 case S_TRISTATE:
813 switch (val) {
814 case yes:
815 ch = '*';
816 break;
817 case mod:
818 ch = 'M';
819 break;
820 default:
821 ch = ' ';
822 break;
823 }
824 item_make(menu, 't', "<%c>", ch);
825 break;
826 }
827 } else {
828 item_make(menu, def_menu ? 't' : ':', " ");
829 }
830
831 item_add_str("%*c%s", indent + 1,
832 ' ', menu_get_prompt(menu));
833 if (val == yes) {
834 if (def_menu) {
835 item_add_str(" (%s)",
836 menu_get_prompt(def_menu));
837 item_add_str(" --->");
838 if (def_menu->list) {
839 indent += 2;
840 build_conf(def_menu);
841 indent -= 2;
842 }
843 }
844 return;
845 }
846 } else {
847 if (menu == current_menu) {
848 item_make(menu, ':',
849 "---%*c%s", indent + 1,
850 ' ', menu_get_prompt(menu));
851 goto conf_childs;
852 }
853 child_count++;
854 val = sym_get_tristate_value(sym);
855 if (sym_is_choice_value(sym) && val == yes) {
856 item_make(menu, ':', " ");
857 } else {
858 switch (type) {
859 case S_BOOLEAN:
860 if (sym_is_changeable(sym))
861 item_make(menu, 't', "[%c]",
862 val == no ? ' ' : '*');
863 else
864 item_make(menu, 't', "-%c-",
865 val == no ? ' ' : '*');
866 break;
867 case S_TRISTATE:
868 switch (val) {
869 case yes:
870 ch = '*';
871 break;
872 case mod:
873 ch = 'M';
874 break;
875 default:
876 ch = ' ';
877 break;
878 }
879 if (sym_is_changeable(sym)) {
880 if (sym->rev_dep.tri == mod)
881 item_make(menu,
882 't', "{%c}", ch);
883 else
884 item_make(menu,
885 't', "<%c>", ch);
886 } else
887 item_make(menu, 't', "-%c-", ch);
888 break;
889 default:
890 tmp = 2 + strlen(sym_get_string_value(sym));
891 item_make(menu, 's', " (%s)",
892 sym_get_string_value(sym));
893 tmp = indent - tmp + 4;
894 if (tmp < 0)
895 tmp = 0;
896 item_add_str("%*c%s%s", tmp, ' ',
897 menu_get_prompt(menu),
898 (sym_has_value(sym) ||
899 !sym_is_changeable(sym)) ? "" :
900 " (NEW)");
901 goto conf_childs;
902 }
903 }
904 item_add_str("%*c%s%s", indent + 1, ' ',
905 menu_get_prompt(menu),
906 (sym_has_value(sym) || !sym_is_changeable(sym)) ?
907 "" : " (NEW)");
908 if (menu->prompt && menu->prompt->type == P_MENU) {
909 item_add_str(" %s", menu_is_empty(menu) ? "----" : "--->");
910 return;
911 }
912 }
913
914 conf_childs:
915 indent += doint;
916 for (child = menu->list; child; child = child->next)
917 build_conf(child);
918 indent -= doint;
919 }
920
921 static void reset_menu(void)
922 {
923 unpost_menu(curses_menu);
924 clean_items();
925 }
926
927 /* adjust the menu to show this item.
928 * prefer not to scroll the menu if possible*/
929 static void center_item(int selected_index, int *last_top_row)
930 {
931 int toprow;
932
933 set_top_row(curses_menu, *last_top_row);
934 toprow = top_row(curses_menu);
935 if (selected_index < toprow ||
936 selected_index >= toprow+mwin_max_lines) {
937 toprow = max(selected_index-mwin_max_lines/2, 0);
938 if (toprow >= item_count(curses_menu)-mwin_max_lines)
939 toprow = item_count(curses_menu)-mwin_max_lines;
940 set_top_row(curses_menu, toprow);
941 }
942 set_current_item(curses_menu,
943 curses_menu_items[selected_index]);
944 *last_top_row = toprow;
945 post_menu(curses_menu);
946 refresh_all_windows(main_window);
947 }
948
949 /* this function assumes reset_menu has been called before */
950 static void show_menu(const char *prompt, const char *instructions,
951 int selected_index, int *last_top_row)
952 {
953 int maxx, maxy;
954 WINDOW *menu_window;
955
956 current_instructions = instructions;
957
958 clear();
959 print_in_middle(stdscr, 1, getmaxx(stdscr),
960 menu_backtitle,
961 attr_main_heading);
962
963 wattrset(main_window, attr_main_menu_box);
964 box(main_window, 0, 0);
965 wattrset(main_window, attr_main_menu_heading);
966 mvwprintw(main_window, 0, 3, " %s ", prompt);
967 wattrset(main_window, attr_normal);
968
969 set_menu_items(curses_menu, curses_menu_items);
970
971 /* position the menu at the middle of the screen */
972 scale_menu(curses_menu, &maxy, &maxx);
973 maxx = min(maxx, mwin_max_cols-2);
974 maxy = mwin_max_lines;
975 menu_window = derwin(main_window,
976 maxy,
977 maxx,
978 2,
979 (mwin_max_cols-maxx)/2);
980 keypad(menu_window, TRUE);
981 set_menu_win(curses_menu, menu_window);
982 set_menu_sub(curses_menu, menu_window);
983
984 /* must reassert this after changing items, otherwise returns to a
985 * default of 16
986 */
987 set_menu_format(curses_menu, maxy, 1);
988 center_item(selected_index, last_top_row);
989 set_menu_format(curses_menu, maxy, 1);
990
991 print_function_line();
992
993 /* Post the menu */
994 post_menu(curses_menu);
995 refresh_all_windows(main_window);
996 }
997
998 static void adj_match_dir(match_f *match_direction)
999 {
1000 if (*match_direction == FIND_NEXT_MATCH_DOWN)
1001 *match_direction =
1002 MATCH_TINKER_PATTERN_DOWN;
1003 else if (*match_direction == FIND_NEXT_MATCH_UP)
1004 *match_direction =
1005 MATCH_TINKER_PATTERN_UP;
1006 /* else, do no change.. */
1007 }
1008
1009 struct match_state
1010 {
1011 int in_search;
1012 match_f match_direction;
1013 char pattern[256];
1014 };
1015
1016 /* Return 0 means I have handled the key. In such a case, ans should hold the
1017 * item to center, or -1 otherwise.
1018 * Else return -1 .
1019 */
1020 static int do_match(int key, struct match_state *state, int *ans)
1021 {
1022 char c = (char) key;
1023 int terminate_search = 0;
1024 *ans = -1;
1025 if (key == '/' || (state->in_search && key == 27)) {
1026 move(0, 0);
1027 refresh();
1028 clrtoeol();
1029 state->in_search = 1-state->in_search;
1030 bzero(state->pattern, sizeof(state->pattern));
1031 state->match_direction = MATCH_TINKER_PATTERN_DOWN;
1032 return 0;
1033 } else if (!state->in_search)
1034 return 1;
1035
1036 if (isalnum(c) || isgraph(c) || c == ' ') {
1037 state->pattern[strlen(state->pattern)] = c;
1038 state->pattern[strlen(state->pattern)] = '\0';
1039 adj_match_dir(&state->match_direction);
1040 *ans = get_mext_match(state->pattern,
1041 state->match_direction);
1042 } else if (key == KEY_DOWN) {
1043 state->match_direction = FIND_NEXT_MATCH_DOWN;
1044 *ans = get_mext_match(state->pattern,
1045 state->match_direction);
1046 } else if (key == KEY_UP) {
1047 state->match_direction = FIND_NEXT_MATCH_UP;
1048 *ans = get_mext_match(state->pattern,
1049 state->match_direction);
1050 } else if (key == KEY_BACKSPACE || key == 8 || key == 127) {
1051 state->pattern[strlen(state->pattern)-1] = '\0';
1052 adj_match_dir(&state->match_direction);
1053 } else
1054 terminate_search = 1;
1055
1056 if (terminate_search) {
1057 state->in_search = 0;
1058 bzero(state->pattern, sizeof(state->pattern));
1059 move(0, 0);
1060 refresh();
1061 clrtoeol();
1062 return -1;
1063 }
1064 return 0;
1065 }
1066
1067 static void conf(struct menu *menu)
1068 {
1069 struct menu *submenu = NULL;
1070 struct symbol *sym;
1071 int res;
1072 int current_index = 0;
1073 int last_top_row = 0;
1074 struct match_state match_state = {
1075 .in_search = 0,
1076 .match_direction = MATCH_TINKER_PATTERN_DOWN,
1077 .pattern = "",
1078 };
1079
1080 while (!global_exit) {
1081 reset_menu();
1082 current_menu = menu;
1083 build_conf(menu);
1084 if (!child_count)
1085 break;
1086
1087 show_menu(menu_get_prompt(menu), menu_instructions,
1088 current_index, &last_top_row);
1089 keypad((menu_win(curses_menu)), TRUE);
1090 while (!global_exit) {
1091 if (match_state.in_search) {
1092 mvprintw(0, 0,
1093 "searching: %s", match_state.pattern);
1094 clrtoeol();
1095 }
1096 refresh_all_windows(main_window);
1097 res = wgetch(menu_win(curses_menu));
1098 if (!res)
1099 break;
1100 if (do_match(res, &match_state, &current_index) == 0) {
1101 if (current_index != -1)
1102 center_item(current_index,
1103 &last_top_row);
1104 continue;
1105 }
1106 if (process_special_keys(&res,
1107 (struct menu *) item_data()))
1108 break;
1109 switch (res) {
1110 case KEY_DOWN:
1111 menu_driver(curses_menu, REQ_DOWN_ITEM);
1112 break;
1113 case KEY_UP:
1114 menu_driver(curses_menu, REQ_UP_ITEM);
1115 break;
1116 case KEY_NPAGE:
1117 menu_driver(curses_menu, REQ_SCR_DPAGE);
1118 break;
1119 case KEY_PPAGE:
1120 menu_driver(curses_menu, REQ_SCR_UPAGE);
1121 break;
1122 case KEY_HOME:
1123 menu_driver(curses_menu, REQ_FIRST_ITEM);
1124 break;
1125 case KEY_END:
1126 menu_driver(curses_menu, REQ_LAST_ITEM);
1127 break;
1128 case 'h':
1129 case '?':
1130 show_help((struct menu *) item_data());
1131 break;
1132 }
1133 if (res == 10 || res == 27 ||
1134 res == 32 || res == 'n' || res == 'y' ||
1135 res == KEY_LEFT || res == KEY_RIGHT ||
1136 res == 'm')
1137 break;
1138 refresh_all_windows(main_window);
1139 }
1140
1141 refresh_all_windows(main_window);
1142 /* if ESC or left*/
1143 if (res == 27 || (menu != &rootmenu && res == KEY_LEFT))
1144 break;
1145
1146 /* remember location in the menu */
1147 last_top_row = top_row(curses_menu);
1148 current_index = curses_item_index();
1149
1150 if (!item_tag())
1151 continue;
1152
1153 submenu = (struct menu *) item_data();
1154 if (!submenu || !menu_is_visible(submenu))
1155 continue;
1156 sym = submenu->sym;
1157
1158 switch (res) {
1159 case ' ':
1160 if (item_is_tag('t'))
1161 sym_toggle_tristate_value(sym);
1162 else if (item_is_tag('m'))
1163 conf(submenu);
1164 break;
1165 case KEY_RIGHT:
1166 case 10: /* ENTER WAS PRESSED */
1167 switch (item_tag()) {
1168 case 'm':
1169 if (single_menu_mode)
1170 submenu->data =
1171 (void *) (long) !submenu->data;
1172 else
1173 conf(submenu);
1174 break;
1175 case 't':
1176 if (sym_is_choice(sym) &&
1177 sym_get_tristate_value(sym) == yes)
1178 conf_choice(submenu);
1179 else if (submenu->prompt &&
1180 submenu->prompt->type == P_MENU)
1181 conf(submenu);
1182 else if (res == 10)
1183 sym_toggle_tristate_value(sym);
1184 break;
1185 case 's':
1186 conf_string(submenu);
1187 break;
1188 }
1189 break;
1190 case 'y':
1191 if (item_is_tag('t')) {
1192 if (sym_set_tristate_value(sym, yes))
1193 break;
1194 if (sym_set_tristate_value(sym, mod))
1195 btn_dialog(main_window, setmod_text, 0);
1196 }
1197 break;
1198 case 'n':
1199 if (item_is_tag('t'))
1200 sym_set_tristate_value(sym, no);
1201 break;
1202 case 'm':
1203 if (item_is_tag('t'))
1204 sym_set_tristate_value(sym, mod);
1205 break;
1206 }
1207 }
1208 }
1209
1210 static void conf_message_callback(const char *s)
1211 {
1212 btn_dialog(main_window, s, 1, "<OK>");
1213 }
1214
1215 static void show_help(struct menu *menu)
1216 {
1217 struct gstr help;
1218
1219 if (!menu)
1220 return;
1221
1222 help = str_new();
1223 menu_get_ext_help(menu, &help);
1224 show_scroll_win(main_window, menu_get_prompt(menu), str_get(&help));
1225 str_free(&help);
1226 }
1227
1228 static void conf_choice(struct menu *menu)
1229 {
1230 const char *prompt = menu_get_prompt(menu);
1231 struct menu *child = NULL;
1232 struct symbol *active;
1233 struct property *prop;
1234 int selected_index = 0;
1235 int last_top_row = 0;
1236 int res, i = 0;
1237 struct match_state match_state = {
1238 .in_search = 0,
1239 .match_direction = MATCH_TINKER_PATTERN_DOWN,
1240 .pattern = "",
1241 };
1242
1243 active = sym_get_choice_value(menu->sym);
1244 /* this is mostly duplicated from the conf() function. */
1245 while (!global_exit) {
1246 reset_menu();
1247
1248 for (i = 0, child = menu->list; child; child = child->next) {
1249 if (!show_all_items && !menu_is_visible(child))
1250 continue;
1251
1252 if (child->sym == sym_get_choice_value(menu->sym))
1253 item_make(child, ':', "<X> %s",
1254 menu_get_prompt(child));
1255 else if (child->sym)
1256 item_make(child, ':', " %s",
1257 menu_get_prompt(child));
1258 else
1259 item_make(child, ':', "*** %s ***",
1260 menu_get_prompt(child));
1261
1262 if (child->sym == active){
1263 last_top_row = top_row(curses_menu);
1264 selected_index = i;
1265 }
1266 i++;
1267 }
1268 show_menu(prompt ? prompt : "Choice Menu",
1269 radiolist_instructions,
1270 selected_index,
1271 &last_top_row);
1272 while (!global_exit) {
1273 if (match_state.in_search) {
1274 mvprintw(0, 0, "searching: %s",
1275 match_state.pattern);
1276 clrtoeol();
1277 }
1278 refresh_all_windows(main_window);
1279 res = wgetch(menu_win(curses_menu));
1280 if (!res)
1281 break;
1282 if (do_match(res, &match_state, &selected_index) == 0) {
1283 if (selected_index != -1)
1284 center_item(selected_index,
1285 &last_top_row);
1286 continue;
1287 }
1288 if (process_special_keys(
1289 &res,
1290 (struct menu *) item_data()))
1291 break;
1292 switch (res) {
1293 case KEY_DOWN:
1294 menu_driver(curses_menu, REQ_DOWN_ITEM);
1295 break;
1296 case KEY_UP:
1297 menu_driver(curses_menu, REQ_UP_ITEM);
1298 break;
1299 case KEY_NPAGE:
1300 menu_driver(curses_menu, REQ_SCR_DPAGE);
1301 break;
1302 case KEY_PPAGE:
1303 menu_driver(curses_menu, REQ_SCR_UPAGE);
1304 break;
1305 case KEY_HOME:
1306 menu_driver(curses_menu, REQ_FIRST_ITEM);
1307 break;
1308 case KEY_END:
1309 menu_driver(curses_menu, REQ_LAST_ITEM);
1310 break;
1311 case 'h':
1312 case '?':
1313 show_help((struct menu *) item_data());
1314 break;
1315 }
1316 if (res == 10 || res == 27 || res == ' ' ||
1317 res == KEY_LEFT){
1318 break;
1319 }
1320 refresh_all_windows(main_window);
1321 }
1322 /* if ESC or left */
1323 if (res == 27 || res == KEY_LEFT)
1324 break;
1325
1326 child = item_data();
1327 if (!child || !menu_is_visible(child) || !child->sym)
1328 continue;
1329 switch (res) {
1330 case ' ':
1331 case 10:
1332 case KEY_RIGHT:
1333 if (sym_get_tristate_value(child->sym) != yes) {
1334 for_all_properties(menu->sym, prop, P_RESET) {
1335 if (expr_calc_value(prop->visible.expr) == no)
1336 continue;
1337
1338 conf_reset(S_DEF_USER);
1339 break;
1340 }
1341 }
1342 sym_set_tristate_value(child->sym, yes);
1343 return;
1344 case 'h':
1345 case '?':
1346 show_help(child);
1347 active = child->sym;
1348 break;
1349 case KEY_EXIT:
1350 return;
1351 }
1352 }
1353 }
1354
1355 static void conf_string(struct menu *menu)
1356 {
1357 const char *prompt = menu_get_prompt(menu);
1358
1359 while (1) {
1360 int res;
1361 const char *heading;
1362
1363 switch (sym_get_type(menu->sym)) {
1364 case S_INT:
1365 heading = inputbox_instructions_int;
1366 break;
1367 case S_HEX:
1368 heading = inputbox_instructions_hex;
1369 break;
1370 case S_STRING:
1371 heading = inputbox_instructions_string;
1372 break;
1373 default:
1374 heading = "Internal nconf error!";
1375 }
1376 res = dialog_inputbox(main_window,
1377 prompt ? prompt : "Main Menu",
1378 heading,
1379 sym_get_string_value(menu->sym),
1380 &dialog_input_result,
1381 &dialog_input_result_len);
1382 switch (res) {
1383 case 0:
1384 if (sym_set_string_value(menu->sym,
1385 dialog_input_result))
1386 return;
1387 btn_dialog(main_window,
1388 "You have made an invalid entry.", 0);
1389 break;
1390 case 1:
1391 show_help(menu);
1392 break;
1393 case KEY_EXIT:
1394 return;
1395 }
1396 }
1397 }
1398
1399 static void conf_load(void)
1400 {
1401 while (1) {
1402 int res;
1403 res = dialog_inputbox(main_window,
1404 NULL, load_config_text,
1405 filename,
1406 &dialog_input_result,
1407 &dialog_input_result_len);
1408 switch (res) {
1409 case 0:
1410 if (!dialog_input_result[0])
1411 return;
1412 if (!conf_read(dialog_input_result)) {
1413 set_config_filename(dialog_input_result);
1414 conf_set_changed(true);
1415 return;
1416 }
1417 btn_dialog(main_window, "File does not exist!", 0);
1418 break;
1419 case 1:
1420 show_scroll_win(main_window,
1421 "Load Alternate Configuration",
1422 load_config_help);
1423 break;
1424 case KEY_EXIT:
1425 return;
1426 }
1427 }
1428 }
1429
1430 static void conf_save(void)
1431 {
1432 while (1) {
1433 int res;
1434 res = dialog_inputbox(main_window,
1435 NULL, save_config_text,
1436 filename,
1437 &dialog_input_result,
1438 &dialog_input_result_len);
1439 switch (res) {
1440 case 0:
1441 if (!dialog_input_result[0])
1442 return;
1443 res = conf_write(dialog_input_result);
1444 if (!res) {
1445 set_config_filename(dialog_input_result);
1446 return;
1447 }
1448 btn_dialog(main_window, "Can't create file!",
1449 1, "<OK>");
1450 break;
1451 case 1:
1452 show_scroll_win(main_window,
1453 "Save Alternate Configuration",
1454 save_config_help);
1455 break;
1456 case KEY_EXIT:
1457 return;
1458 }
1459 }
1460 }
1461
1462 static void setup_windows(void)
1463 {
1464 int lines, columns;
1465
1466 getmaxyx(stdscr, lines, columns);
1467
1468 if (main_window != NULL)
1469 delwin(main_window);
1470
1471 /* set up the menu and menu window */
1472 main_window = newwin(lines-2, columns-2, 2, 1);
1473 keypad(main_window, TRUE);
1474 mwin_max_lines = lines-7;
1475 mwin_max_cols = columns-6;
1476
1477 /* panels order is from bottom to top */
1478 new_panel(main_window);
1479 }
1480
1481 int main(int ac, char **av)
1482 {
1483 int lines, columns;
1484 char *mode;
1485
1486 if (ac > 1 && strcmp(av[1], "-s") == 0) {
1487 /* Silence conf_read() until the real callback is set up */
1488 conf_set_message_callback(NULL);
1489 av++;
1490 }
1491 conf_parse(av[1]);
1492 conf_read(NULL);
1493
1494 mode = getenv("NCONFIG_MODE");
1495 if (mode) {
1496 if (!strcasecmp(mode, "single_menu"))
1497 single_menu_mode = 1;
1498 }
1499
1500 /* Initialize curses */
1501 initscr();
1502 /* set color theme */
1503 set_colors();
1504
1505 cbreak();
1506 noecho();
1507 keypad(stdscr, TRUE);
1508 curs_set(0);
1509
1510 getmaxyx(stdscr, lines, columns);
1511 if (columns < 75 || lines < 20) {
1512 endwin();
1513 printf("Your terminal should have at "
1514 "least 20 lines and 75 columns\n");
1515 return 1;
1516 }
1517
1518 notimeout(stdscr, FALSE);
1519 #if NCURSES_REENTRANT
1520 set_escdelay(1);
1521 #else
1522 ESCDELAY = 1;
1523 #endif
1524
1525 /* set btns menu */
1526 curses_menu = new_menu(curses_menu_items);
1527 menu_opts_off(curses_menu, O_SHOWDESC);
1528 menu_opts_on(curses_menu, O_SHOWMATCH);
1529 menu_opts_on(curses_menu, O_ONEVALUE);
1530 menu_opts_on(curses_menu, O_NONCYCLIC);
1531 menu_opts_on(curses_menu, O_IGNORECASE);
1532 set_menu_mark(curses_menu, " ");
1533 set_menu_fore(curses_menu, attr_main_menu_fore);
1534 set_menu_back(curses_menu, attr_main_menu_back);
1535 set_menu_grey(curses_menu, attr_main_menu_grey);
1536
1537 set_config_filename(conf_get_configname());
1538 setup_windows();
1539
1540 /* check for KEY_FUNC(1) */
1541 if (has_key(KEY_F(1)) == FALSE) {
1542 show_scroll_win(main_window,
1543 "Instructions",
1544 menu_no_f_instructions);
1545 }
1546
1547 conf_set_message_callback(conf_message_callback);
1548 /* do the work */
1549 while (!global_exit) {
1550 conf(&rootmenu);
1551 if (!global_exit && do_exit() == 0)
1552 break;
1553 }
1554 /* ok, we are done */
1555 unpost_menu(curses_menu);
1556 free_menu(curses_menu);
1557 delwin(main_window);
1558 clear();
1559 refresh();
1560 endwin();
1561 return 0;
1562 }