kirkwood: refresh kernel config
[openwrt/openwrt.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 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 (void) wattrset(main_window, attributes[FUNCTION_HIGHLIGHT]);
377 mvwprintw(main_window, lines-3, offset,
378 "%s",
379 function_keys[i].key_str);
380 (void) wattrset(main_window, attributes[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 (void) wattrset(main_window, attributes[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 = item_index(current_item(curses_menu));
503 int index;
504
505 if (flag == FIND_NEXT_MATCH_DOWN)
506 ++match_start;
507 else if (flag == FIND_NEXT_MATCH_UP)
508 --match_start;
509
510 index = match_start;
511 index = (index + items_num) % items_num;
512 while (true) {
513 char *str = k_menu_items[index].str;
514 if (strcasestr(str, match_str) != NULL)
515 return index;
516 if (flag == FIND_NEXT_MATCH_UP ||
517 flag == MATCH_TINKER_PATTERN_UP)
518 --index;
519 else
520 ++index;
521 index = (index + items_num) % items_num;
522 if (index == match_start)
523 return -1;
524 }
525 }
526
527 /* Make a new item. */
528 static void item_make(struct menu *menu, char tag, const char *fmt, ...)
529 {
530 va_list ap;
531
532 if (items_num > MAX_MENU_ITEMS-1)
533 return;
534
535 bzero(&k_menu_items[items_num], sizeof(k_menu_items[0]));
536 k_menu_items[items_num].tag = tag;
537 k_menu_items[items_num].usrptr = menu;
538 if (menu != NULL)
539 k_menu_items[items_num].is_visible =
540 menu_is_visible(menu);
541 else
542 k_menu_items[items_num].is_visible = 1;
543
544 va_start(ap, fmt);
545 vsnprintf(k_menu_items[items_num].str,
546 sizeof(k_menu_items[items_num].str),
547 fmt, ap);
548 va_end(ap);
549
550 if (!k_menu_items[items_num].is_visible)
551 memcpy(k_menu_items[items_num].str, "XXX", 3);
552
553 curses_menu_items[items_num] = new_item(
554 k_menu_items[items_num].str,
555 k_menu_items[items_num].str);
556 set_item_userptr(curses_menu_items[items_num],
557 &k_menu_items[items_num]);
558 /*
559 if (!k_menu_items[items_num].is_visible)
560 item_opts_off(curses_menu_items[items_num], O_SELECTABLE);
561 */
562
563 items_num++;
564 curses_menu_items[items_num] = NULL;
565 }
566
567 /* very hackish. adds a string to the last item added */
568 static void item_add_str(const char *fmt, ...)
569 {
570 va_list ap;
571 int index = items_num-1;
572 char new_str[256];
573 char tmp_str[256];
574
575 if (index < 0)
576 return;
577
578 va_start(ap, fmt);
579 vsnprintf(new_str, sizeof(new_str), fmt, ap);
580 va_end(ap);
581 snprintf(tmp_str, sizeof(tmp_str), "%s%s",
582 k_menu_items[index].str, new_str);
583 strncpy(k_menu_items[index].str,
584 tmp_str,
585 sizeof(k_menu_items[index].str));
586
587 free_item(curses_menu_items[index]);
588 curses_menu_items[index] = new_item(
589 k_menu_items[index].str,
590 k_menu_items[index].str);
591 set_item_userptr(curses_menu_items[index],
592 &k_menu_items[index]);
593 }
594
595 /* get the tag of the currently selected item */
596 static char item_tag(void)
597 {
598 ITEM *cur;
599 struct mitem *mcur;
600
601 cur = current_item(curses_menu);
602 if (cur == NULL)
603 return 0;
604 mcur = (struct mitem *) item_userptr(cur);
605 return mcur->tag;
606 }
607
608 static int curses_item_index(void)
609 {
610 return item_index(current_item(curses_menu));
611 }
612
613 static void *item_data(void)
614 {
615 ITEM *cur;
616 struct mitem *mcur;
617
618 cur = current_item(curses_menu);
619 if (!cur)
620 return NULL;
621 mcur = (struct mitem *) item_userptr(cur);
622 return mcur->usrptr;
623
624 }
625
626 static int item_is_tag(char tag)
627 {
628 return item_tag() == tag;
629 }
630
631 static char filename[PATH_MAX+1];
632 static char menu_backtitle[PATH_MAX+128];
633 static const char *set_config_filename(const char *config_filename)
634 {
635 int size;
636
637 size = snprintf(menu_backtitle, sizeof(menu_backtitle),
638 "%s - %s", config_filename, rootmenu.prompt->text);
639 if (size >= sizeof(menu_backtitle))
640 menu_backtitle[sizeof(menu_backtitle)-1] = '\0';
641
642 size = snprintf(filename, sizeof(filename), "%s", config_filename);
643 if (size >= sizeof(filename))
644 filename[sizeof(filename)-1] = '\0';
645 return menu_backtitle;
646 }
647
648 /* return = 0 means we are successful.
649 * -1 means go on doing what you were doing
650 */
651 static int do_exit(void)
652 {
653 int res;
654 if (!conf_get_changed()) {
655 global_exit = 1;
656 return 0;
657 }
658 res = btn_dialog(main_window,
659 "Do you wish to save your new configuration?\n"
660 "<ESC> to cancel and resume nconfig.",
661 2,
662 " <save> ",
663 "<don't save>");
664 if (res == KEY_EXIT) {
665 global_exit = 0;
666 return -1;
667 }
668
669 /* if we got here, the user really wants to exit */
670 switch (res) {
671 case 0:
672 res = conf_write(filename);
673 if (res)
674 btn_dialog(
675 main_window,
676 "Error during writing of configuration.\n"
677 "Your configuration changes were NOT saved.",
678 1,
679 "<OK>");
680 conf_write_autoconf(0);
681 break;
682 default:
683 btn_dialog(
684 main_window,
685 "Your configuration changes were NOT saved.",
686 1,
687 "<OK>");
688 break;
689 }
690 global_exit = 1;
691 return 0;
692 }
693
694
695 static void search_conf(void)
696 {
697 struct symbol **sym_arr;
698 struct gstr res;
699 struct gstr title;
700 char *dialog_input;
701 int dres;
702
703 title = str_new();
704 str_printf( &title, "Enter (sub)string or regexp to search for "
705 "(with or without \"%s\")", CONFIG_);
706
707 again:
708 dres = dialog_inputbox(main_window,
709 "Search Configuration Parameter",
710 str_get(&title),
711 "", &dialog_input_result, &dialog_input_result_len);
712 switch (dres) {
713 case 0:
714 break;
715 case 1:
716 show_scroll_win(main_window,
717 "Search Configuration", search_help);
718 goto again;
719 default:
720 str_free(&title);
721 return;
722 }
723
724 /* strip the prefix if necessary */
725 dialog_input = dialog_input_result;
726 if (strncasecmp(dialog_input_result, CONFIG_, strlen(CONFIG_)) == 0)
727 dialog_input += strlen(CONFIG_);
728
729 sym_arr = sym_re_search(dialog_input);
730 res = get_relations_str(sym_arr, NULL);
731 free(sym_arr);
732 show_scroll_win(main_window,
733 "Search Results", str_get(&res));
734 str_free(&res);
735 str_free(&title);
736 }
737
738
739 static void build_conf(struct menu *menu)
740 {
741 struct symbol *sym;
742 struct property *prop;
743 struct menu *child;
744 int type, tmp, doint = 2;
745 tristate val;
746 char ch;
747
748 if (!menu || (!show_all_items && !menu_is_visible(menu)))
749 return;
750
751 sym = menu->sym;
752 prop = menu->prompt;
753 if (!sym) {
754 if (prop && menu != current_menu) {
755 const char *prompt = menu_get_prompt(menu);
756 enum prop_type ptype;
757 ptype = menu->prompt ? menu->prompt->type : P_UNKNOWN;
758 switch (ptype) {
759 case P_MENU:
760 child_count++;
761 prompt = prompt;
762 if (single_menu_mode) {
763 item_make(menu, 'm',
764 "%s%*c%s",
765 menu->data ? "-->" : "++>",
766 indent + 1, ' ', prompt);
767 } else
768 item_make(menu, 'm',
769 " %*c%s %s",
770 indent + 1, ' ', prompt,
771 menu_is_empty(menu) ? "----" : "--->");
772
773 if (single_menu_mode && menu->data)
774 goto conf_childs;
775 return;
776 case P_COMMENT:
777 if (prompt) {
778 child_count++;
779 item_make(menu, ':',
780 " %*c*** %s ***",
781 indent + 1, ' ',
782 prompt);
783 }
784 break;
785 default:
786 if (prompt) {
787 child_count++;
788 item_make(menu, ':', "---%*c%s",
789 indent + 1, ' ',
790 prompt);
791 }
792 }
793 } else
794 doint = 0;
795 goto conf_childs;
796 }
797
798 type = sym_get_type(sym);
799 if (sym_is_choice(sym)) {
800 struct symbol *def_sym = sym_get_choice_value(sym);
801 struct menu *def_menu = NULL;
802
803 child_count++;
804 for (child = menu->list; child; child = child->next) {
805 if (menu_is_visible(child) && child->sym == def_sym)
806 def_menu = child;
807 }
808
809 val = sym_get_tristate_value(sym);
810 if (sym_is_changeable(sym)) {
811 switch (type) {
812 case S_BOOLEAN:
813 item_make(menu, 't', "[%c]",
814 val == no ? ' ' : '*');
815 break;
816 case S_TRISTATE:
817 switch (val) {
818 case yes:
819 ch = '*';
820 break;
821 case mod:
822 ch = 'M';
823 break;
824 default:
825 ch = ' ';
826 break;
827 }
828 item_make(menu, 't', "<%c>", ch);
829 break;
830 }
831 } else {
832 item_make(menu, def_menu ? 't' : ':', " ");
833 }
834
835 item_add_str("%*c%s", indent + 1,
836 ' ', menu_get_prompt(menu));
837 if (val == yes) {
838 if (def_menu) {
839 item_add_str(" (%s)",
840 menu_get_prompt(def_menu));
841 item_add_str(" --->");
842 if (def_menu->list) {
843 indent += 2;
844 build_conf(def_menu);
845 indent -= 2;
846 }
847 }
848 return;
849 }
850 } else {
851 if (menu == current_menu) {
852 item_make(menu, ':',
853 "---%*c%s", indent + 1,
854 ' ', menu_get_prompt(menu));
855 goto conf_childs;
856 }
857 child_count++;
858 val = sym_get_tristate_value(sym);
859 if (sym_is_choice_value(sym) && val == yes) {
860 item_make(menu, ':', " ");
861 } else {
862 switch (type) {
863 case S_BOOLEAN:
864 if (sym_is_changeable(sym))
865 item_make(menu, 't', "[%c]",
866 val == no ? ' ' : '*');
867 else
868 item_make(menu, 't', "-%c-",
869 val == no ? ' ' : '*');
870 break;
871 case S_TRISTATE:
872 switch (val) {
873 case yes:
874 ch = '*';
875 break;
876 case mod:
877 ch = 'M';
878 break;
879 default:
880 ch = ' ';
881 break;
882 }
883 if (sym_is_changeable(sym)) {
884 if (sym->rev_dep.tri == mod)
885 item_make(menu,
886 't', "{%c}", ch);
887 else
888 item_make(menu,
889 't', "<%c>", ch);
890 } else
891 item_make(menu, 't', "-%c-", ch);
892 break;
893 default:
894 tmp = 2 + strlen(sym_get_string_value(sym));
895 item_make(menu, 's', " (%s)",
896 sym_get_string_value(sym));
897 tmp = indent - tmp + 4;
898 if (tmp < 0)
899 tmp = 0;
900 item_add_str("%*c%s%s", tmp, ' ',
901 menu_get_prompt(menu),
902 (sym_has_value(sym) ||
903 !sym_is_changeable(sym)) ? "" :
904 " (NEW)");
905 goto conf_childs;
906 }
907 }
908 item_add_str("%*c%s%s", indent + 1, ' ',
909 menu_get_prompt(menu),
910 (sym_has_value(sym) || !sym_is_changeable(sym)) ?
911 "" : " (NEW)");
912 if (menu->prompt && menu->prompt->type == P_MENU) {
913 item_add_str(" %s", menu_is_empty(menu) ? "----" : "--->");
914 return;
915 }
916 }
917
918 conf_childs:
919 indent += doint;
920 for (child = menu->list; child; child = child->next)
921 build_conf(child);
922 indent -= doint;
923 }
924
925 static void reset_menu(void)
926 {
927 unpost_menu(curses_menu);
928 clean_items();
929 }
930
931 /* adjust the menu to show this item.
932 * prefer not to scroll the menu if possible*/
933 static void center_item(int selected_index, int *last_top_row)
934 {
935 int toprow;
936
937 set_top_row(curses_menu, *last_top_row);
938 toprow = top_row(curses_menu);
939 if (selected_index < toprow ||
940 selected_index >= toprow+mwin_max_lines) {
941 toprow = max(selected_index-mwin_max_lines/2, 0);
942 if (toprow >= item_count(curses_menu)-mwin_max_lines)
943 toprow = item_count(curses_menu)-mwin_max_lines;
944 set_top_row(curses_menu, toprow);
945 }
946 set_current_item(curses_menu,
947 curses_menu_items[selected_index]);
948 *last_top_row = toprow;
949 post_menu(curses_menu);
950 refresh_all_windows(main_window);
951 }
952
953 /* this function assumes reset_menu has been called before */
954 static void show_menu(const char *prompt, const char *instructions,
955 int selected_index, int *last_top_row)
956 {
957 int maxx, maxy;
958 WINDOW *menu_window;
959
960 current_instructions = instructions;
961
962 clear();
963 (void) wattrset(main_window, attributes[NORMAL]);
964 print_in_middle(stdscr, 1, 0, getmaxx(stdscr),
965 menu_backtitle,
966 attributes[MAIN_HEADING]);
967
968 (void) wattrset(main_window, attributes[MAIN_MENU_BOX]);
969 box(main_window, 0, 0);
970 (void) wattrset(main_window, attributes[MAIN_MENU_HEADING]);
971 mvwprintw(main_window, 0, 3, " %s ", prompt);
972 (void) wattrset(main_window, attributes[NORMAL]);
973
974 set_menu_items(curses_menu, curses_menu_items);
975
976 /* position the menu at the middle of the screen */
977 scale_menu(curses_menu, &maxy, &maxx);
978 maxx = min(maxx, mwin_max_cols-2);
979 maxy = mwin_max_lines;
980 menu_window = derwin(main_window,
981 maxy,
982 maxx,
983 2,
984 (mwin_max_cols-maxx)/2);
985 keypad(menu_window, TRUE);
986 set_menu_win(curses_menu, menu_window);
987 set_menu_sub(curses_menu, menu_window);
988
989 /* must reassert this after changing items, otherwise returns to a
990 * default of 16
991 */
992 set_menu_format(curses_menu, maxy, 1);
993 center_item(selected_index, last_top_row);
994 set_menu_format(curses_menu, maxy, 1);
995
996 print_function_line();
997
998 /* Post the menu */
999 post_menu(curses_menu);
1000 refresh_all_windows(main_window);
1001 }
1002
1003 static void adj_match_dir(match_f *match_direction)
1004 {
1005 if (*match_direction == FIND_NEXT_MATCH_DOWN)
1006 *match_direction =
1007 MATCH_TINKER_PATTERN_DOWN;
1008 else if (*match_direction == FIND_NEXT_MATCH_UP)
1009 *match_direction =
1010 MATCH_TINKER_PATTERN_UP;
1011 /* else, do no change.. */
1012 }
1013
1014 struct match_state
1015 {
1016 int in_search;
1017 match_f match_direction;
1018 char pattern[256];
1019 };
1020
1021 /* Return 0 means I have handled the key. In such a case, ans should hold the
1022 * item to center, or -1 otherwise.
1023 * Else return -1 .
1024 */
1025 static int do_match(int key, struct match_state *state, int *ans)
1026 {
1027 char c = (char) key;
1028 int terminate_search = 0;
1029 *ans = -1;
1030 if (key == '/' || (state->in_search && key == 27)) {
1031 move(0, 0);
1032 refresh();
1033 clrtoeol();
1034 state->in_search = 1-state->in_search;
1035 bzero(state->pattern, sizeof(state->pattern));
1036 state->match_direction = MATCH_TINKER_PATTERN_DOWN;
1037 return 0;
1038 } else if (!state->in_search)
1039 return 1;
1040
1041 if (isalnum(c) || isgraph(c) || c == ' ') {
1042 state->pattern[strlen(state->pattern)] = c;
1043 state->pattern[strlen(state->pattern)] = '\0';
1044 adj_match_dir(&state->match_direction);
1045 *ans = get_mext_match(state->pattern,
1046 state->match_direction);
1047 } else if (key == KEY_DOWN) {
1048 state->match_direction = FIND_NEXT_MATCH_DOWN;
1049 *ans = get_mext_match(state->pattern,
1050 state->match_direction);
1051 } else if (key == KEY_UP) {
1052 state->match_direction = FIND_NEXT_MATCH_UP;
1053 *ans = get_mext_match(state->pattern,
1054 state->match_direction);
1055 } else if (key == KEY_BACKSPACE || key == 8 || key == 127) {
1056 state->pattern[strlen(state->pattern)-1] = '\0';
1057 adj_match_dir(&state->match_direction);
1058 } else
1059 terminate_search = 1;
1060
1061 if (terminate_search) {
1062 state->in_search = 0;
1063 bzero(state->pattern, sizeof(state->pattern));
1064 move(0, 0);
1065 refresh();
1066 clrtoeol();
1067 return -1;
1068 }
1069 return 0;
1070 }
1071
1072 static void conf(struct menu *menu)
1073 {
1074 struct menu *submenu = NULL;
1075 const char *prompt = menu_get_prompt(menu);
1076 struct symbol *sym;
1077 int res;
1078 int current_index = 0;
1079 int last_top_row = 0;
1080 struct match_state match_state = {
1081 .in_search = 0,
1082 .match_direction = MATCH_TINKER_PATTERN_DOWN,
1083 .pattern = "",
1084 };
1085
1086 while (!global_exit) {
1087 reset_menu();
1088 current_menu = menu;
1089 build_conf(menu);
1090 if (!child_count)
1091 break;
1092
1093 show_menu(prompt ? prompt : "Main Menu",
1094 menu_instructions,
1095 current_index, &last_top_row);
1096 keypad((menu_win(curses_menu)), TRUE);
1097 while (!global_exit) {
1098 if (match_state.in_search) {
1099 mvprintw(0, 0,
1100 "searching: %s", match_state.pattern);
1101 clrtoeol();
1102 }
1103 refresh_all_windows(main_window);
1104 res = wgetch(menu_win(curses_menu));
1105 if (!res)
1106 break;
1107 if (do_match(res, &match_state, &current_index) == 0) {
1108 if (current_index != -1)
1109 center_item(current_index,
1110 &last_top_row);
1111 continue;
1112 }
1113 if (process_special_keys(&res,
1114 (struct menu *) item_data()))
1115 break;
1116 switch (res) {
1117 case KEY_DOWN:
1118 menu_driver(curses_menu, REQ_DOWN_ITEM);
1119 break;
1120 case KEY_UP:
1121 menu_driver(curses_menu, REQ_UP_ITEM);
1122 break;
1123 case KEY_NPAGE:
1124 menu_driver(curses_menu, REQ_SCR_DPAGE);
1125 break;
1126 case KEY_PPAGE:
1127 menu_driver(curses_menu, REQ_SCR_UPAGE);
1128 break;
1129 case KEY_HOME:
1130 menu_driver(curses_menu, REQ_FIRST_ITEM);
1131 break;
1132 case KEY_END:
1133 menu_driver(curses_menu, REQ_LAST_ITEM);
1134 break;
1135 case 'h':
1136 case '?':
1137 show_help((struct menu *) item_data());
1138 break;
1139 }
1140 if (res == 10 || res == 27 ||
1141 res == 32 || res == 'n' || res == 'y' ||
1142 res == KEY_LEFT || res == KEY_RIGHT ||
1143 res == 'm')
1144 break;
1145 refresh_all_windows(main_window);
1146 }
1147
1148 refresh_all_windows(main_window);
1149 /* if ESC or left*/
1150 if (res == 27 || (menu != &rootmenu && res == KEY_LEFT))
1151 break;
1152
1153 /* remember location in the menu */
1154 last_top_row = top_row(curses_menu);
1155 current_index = curses_item_index();
1156
1157 if (!item_tag())
1158 continue;
1159
1160 submenu = (struct menu *) item_data();
1161 if (!submenu || !menu_is_visible(submenu))
1162 continue;
1163 sym = submenu->sym;
1164
1165 switch (res) {
1166 case ' ':
1167 if (item_is_tag('t'))
1168 sym_toggle_tristate_value(sym);
1169 else if (item_is_tag('m'))
1170 conf(submenu);
1171 break;
1172 case KEY_RIGHT:
1173 case 10: /* ENTER WAS PRESSED */
1174 switch (item_tag()) {
1175 case 'm':
1176 if (single_menu_mode)
1177 submenu->data =
1178 (void *) (long) !submenu->data;
1179 else
1180 conf(submenu);
1181 break;
1182 case 't':
1183 if (sym_is_choice(sym) &&
1184 sym_get_tristate_value(sym) == yes)
1185 conf_choice(submenu);
1186 else if (submenu->prompt &&
1187 submenu->prompt->type == P_MENU)
1188 conf(submenu);
1189 else if (res == 10)
1190 sym_toggle_tristate_value(sym);
1191 break;
1192 case 's':
1193 conf_string(submenu);
1194 break;
1195 }
1196 break;
1197 case 'y':
1198 if (item_is_tag('t')) {
1199 if (sym_set_tristate_value(sym, yes))
1200 break;
1201 if (sym_set_tristate_value(sym, mod))
1202 btn_dialog(main_window, setmod_text, 0);
1203 }
1204 break;
1205 case 'n':
1206 if (item_is_tag('t'))
1207 sym_set_tristate_value(sym, no);
1208 break;
1209 case 'm':
1210 if (item_is_tag('t'))
1211 sym_set_tristate_value(sym, mod);
1212 break;
1213 }
1214 }
1215 }
1216
1217 static void conf_message_callback(const char *s)
1218 {
1219 btn_dialog(main_window, s, 1, "<OK>");
1220 }
1221
1222 static void show_help(struct menu *menu)
1223 {
1224 struct gstr help;
1225
1226 if (!menu)
1227 return;
1228
1229 help = str_new();
1230 menu_get_ext_help(menu, &help);
1231 show_scroll_win(main_window, menu_get_prompt(menu), str_get(&help));
1232 str_free(&help);
1233 }
1234
1235 static void conf_choice(struct menu *menu)
1236 {
1237 const char *prompt = menu_get_prompt(menu);
1238 struct menu *child = NULL;
1239 struct symbol *active;
1240 struct property *prop;
1241 int selected_index = 0;
1242 int last_top_row = 0;
1243 int res, i = 0;
1244 struct match_state match_state = {
1245 .in_search = 0,
1246 .match_direction = MATCH_TINKER_PATTERN_DOWN,
1247 .pattern = "",
1248 };
1249
1250 active = sym_get_choice_value(menu->sym);
1251 /* this is mostly duplicated from the conf() function. */
1252 while (!global_exit) {
1253 reset_menu();
1254
1255 for (i = 0, child = menu->list; child; child = child->next) {
1256 if (!show_all_items && !menu_is_visible(child))
1257 continue;
1258
1259 if (child->sym == sym_get_choice_value(menu->sym))
1260 item_make(child, ':', "<X> %s",
1261 menu_get_prompt(child));
1262 else if (child->sym)
1263 item_make(child, ':', " %s",
1264 menu_get_prompt(child));
1265 else
1266 item_make(child, ':', "*** %s ***",
1267 menu_get_prompt(child));
1268
1269 if (child->sym == active){
1270 last_top_row = top_row(curses_menu);
1271 selected_index = i;
1272 }
1273 i++;
1274 }
1275 show_menu(prompt ? prompt : "Choice Menu",
1276 radiolist_instructions,
1277 selected_index,
1278 &last_top_row);
1279 while (!global_exit) {
1280 if (match_state.in_search) {
1281 mvprintw(0, 0, "searching: %s",
1282 match_state.pattern);
1283 clrtoeol();
1284 }
1285 refresh_all_windows(main_window);
1286 res = wgetch(menu_win(curses_menu));
1287 if (!res)
1288 break;
1289 if (do_match(res, &match_state, &selected_index) == 0) {
1290 if (selected_index != -1)
1291 center_item(selected_index,
1292 &last_top_row);
1293 continue;
1294 }
1295 if (process_special_keys(
1296 &res,
1297 (struct menu *) item_data()))
1298 break;
1299 switch (res) {
1300 case KEY_DOWN:
1301 menu_driver(curses_menu, REQ_DOWN_ITEM);
1302 break;
1303 case KEY_UP:
1304 menu_driver(curses_menu, REQ_UP_ITEM);
1305 break;
1306 case KEY_NPAGE:
1307 menu_driver(curses_menu, REQ_SCR_DPAGE);
1308 break;
1309 case KEY_PPAGE:
1310 menu_driver(curses_menu, REQ_SCR_UPAGE);
1311 break;
1312 case KEY_HOME:
1313 menu_driver(curses_menu, REQ_FIRST_ITEM);
1314 break;
1315 case KEY_END:
1316 menu_driver(curses_menu, REQ_LAST_ITEM);
1317 break;
1318 case 'h':
1319 case '?':
1320 show_help((struct menu *) item_data());
1321 break;
1322 }
1323 if (res == 10 || res == 27 || res == ' ' ||
1324 res == KEY_LEFT){
1325 break;
1326 }
1327 refresh_all_windows(main_window);
1328 }
1329 /* if ESC or left */
1330 if (res == 27 || res == KEY_LEFT)
1331 break;
1332
1333 child = item_data();
1334 if (!child || !menu_is_visible(child) || !child->sym)
1335 continue;
1336 switch (res) {
1337 case ' ':
1338 case 10:
1339 case KEY_RIGHT:
1340 if (sym_get_tristate_value(child->sym) != yes) {
1341 for_all_properties(menu->sym, prop, P_RESET) {
1342 if (expr_calc_value(prop->visible.expr) == no)
1343 continue;
1344
1345 conf_reset(S_DEF_USER);
1346 break;
1347 }
1348 }
1349 sym_set_tristate_value(child->sym, yes);
1350 return;
1351 case 'h':
1352 case '?':
1353 show_help(child);
1354 active = child->sym;
1355 break;
1356 case KEY_EXIT:
1357 return;
1358 }
1359 }
1360 }
1361
1362 static void conf_string(struct menu *menu)
1363 {
1364 const char *prompt = menu_get_prompt(menu);
1365
1366 while (1) {
1367 int res;
1368 const char *heading;
1369
1370 switch (sym_get_type(menu->sym)) {
1371 case S_INT:
1372 heading = inputbox_instructions_int;
1373 break;
1374 case S_HEX:
1375 heading = inputbox_instructions_hex;
1376 break;
1377 case S_STRING:
1378 heading = inputbox_instructions_string;
1379 break;
1380 default:
1381 heading = "Internal nconf error!";
1382 }
1383 res = dialog_inputbox(main_window,
1384 prompt ? prompt : "Main Menu",
1385 heading,
1386 sym_get_string_value(menu->sym),
1387 &dialog_input_result,
1388 &dialog_input_result_len);
1389 switch (res) {
1390 case 0:
1391 if (sym_set_string_value(menu->sym,
1392 dialog_input_result))
1393 return;
1394 btn_dialog(main_window,
1395 "You have made an invalid entry.", 0);
1396 break;
1397 case 1:
1398 show_help(menu);
1399 break;
1400 case KEY_EXIT:
1401 return;
1402 }
1403 }
1404 }
1405
1406 static void conf_load(void)
1407 {
1408 while (1) {
1409 int res;
1410 res = dialog_inputbox(main_window,
1411 NULL, load_config_text,
1412 filename,
1413 &dialog_input_result,
1414 &dialog_input_result_len);
1415 switch (res) {
1416 case 0:
1417 if (!dialog_input_result[0])
1418 return;
1419 if (!conf_read(dialog_input_result)) {
1420 set_config_filename(dialog_input_result);
1421 sym_set_change_count(1);
1422 return;
1423 }
1424 btn_dialog(main_window, "File does not exist!", 0);
1425 break;
1426 case 1:
1427 show_scroll_win(main_window,
1428 "Load Alternate Configuration",
1429 load_config_help);
1430 break;
1431 case KEY_EXIT:
1432 return;
1433 }
1434 }
1435 }
1436
1437 static void conf_save(void)
1438 {
1439 while (1) {
1440 int res;
1441 res = dialog_inputbox(main_window,
1442 NULL, save_config_text,
1443 filename,
1444 &dialog_input_result,
1445 &dialog_input_result_len);
1446 switch (res) {
1447 case 0:
1448 if (!dialog_input_result[0])
1449 return;
1450 res = conf_write(dialog_input_result);
1451 if (!res) {
1452 set_config_filename(dialog_input_result);
1453 return;
1454 }
1455 btn_dialog(main_window, "Can't create file!",
1456 1, "<OK>");
1457 break;
1458 case 1:
1459 show_scroll_win(main_window,
1460 "Save Alternate Configuration",
1461 save_config_help);
1462 break;
1463 case KEY_EXIT:
1464 return;
1465 }
1466 }
1467 }
1468
1469 static void setup_windows(void)
1470 {
1471 int lines, columns;
1472
1473 getmaxyx(stdscr, lines, columns);
1474
1475 if (main_window != NULL)
1476 delwin(main_window);
1477
1478 /* set up the menu and menu window */
1479 main_window = newwin(lines-2, columns-2, 2, 1);
1480 keypad(main_window, TRUE);
1481 mwin_max_lines = lines-7;
1482 mwin_max_cols = columns-6;
1483
1484 /* panels order is from bottom to top */
1485 new_panel(main_window);
1486 }
1487
1488 int main(int ac, char **av)
1489 {
1490 int lines, columns;
1491 char *mode;
1492
1493 if (ac > 1 && strcmp(av[1], "-s") == 0) {
1494 /* Silence conf_read() until the real callback is set up */
1495 conf_set_message_callback(NULL);
1496 av++;
1497 }
1498 conf_parse(av[1]);
1499 conf_read(NULL);
1500
1501 mode = getenv("NCONFIG_MODE");
1502 if (mode) {
1503 if (!strcasecmp(mode, "single_menu"))
1504 single_menu_mode = 1;
1505 }
1506
1507 /* Initialize curses */
1508 initscr();
1509 /* set color theme */
1510 set_colors();
1511
1512 cbreak();
1513 noecho();
1514 keypad(stdscr, TRUE);
1515 curs_set(0);
1516
1517 getmaxyx(stdscr, lines, columns);
1518 if (columns < 75 || lines < 20) {
1519 endwin();
1520 printf("Your terminal should have at "
1521 "least 20 lines and 75 columns\n");
1522 return 1;
1523 }
1524
1525 notimeout(stdscr, FALSE);
1526 #if NCURSES_REENTRANT
1527 set_escdelay(1);
1528 #else
1529 ESCDELAY = 1;
1530 #endif
1531
1532 /* set btns menu */
1533 curses_menu = new_menu(curses_menu_items);
1534 menu_opts_off(curses_menu, O_SHOWDESC);
1535 menu_opts_on(curses_menu, O_SHOWMATCH);
1536 menu_opts_on(curses_menu, O_ONEVALUE);
1537 menu_opts_on(curses_menu, O_NONCYCLIC);
1538 menu_opts_on(curses_menu, O_IGNORECASE);
1539 set_menu_mark(curses_menu, " ");
1540 set_menu_fore(curses_menu, attributes[MAIN_MENU_FORE]);
1541 set_menu_back(curses_menu, attributes[MAIN_MENU_BACK]);
1542 set_menu_grey(curses_menu, attributes[MAIN_MENU_GREY]);
1543
1544 set_config_filename(conf_get_configname());
1545 setup_windows();
1546
1547 /* check for KEY_FUNC(1) */
1548 if (has_key(KEY_F(1)) == FALSE) {
1549 show_scroll_win(main_window,
1550 "Instructions",
1551 menu_no_f_instructions);
1552 }
1553
1554 conf_set_message_callback(conf_message_callback);
1555 /* do the work */
1556 while (!global_exit) {
1557 conf(&rootmenu);
1558 if (!global_exit && do_exit() == 0)
1559 break;
1560 }
1561 /* ok, we are done */
1562 unpost_menu(curses_menu);
1563 free_menu(curses_menu);
1564 delwin(main_window);
1565 clear();
1566 refresh();
1567 endwin();
1568 return 0;
1569 }