Orange Pi5 kernel

Deprecated Linux kernel 5.10.110 for OrangePi 5/5B/5+ boards

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