1*525a267eSThomas Cort.\" $NetBSD: menuc.1,v 1.30 2012/03/06 16:55:18 mbalmer Exp $ 2*525a267eSThomas Cort.\" 3*525a267eSThomas Cort.\" Copyright 1997 Piermont Information Systems Inc. 4*525a267eSThomas Cort.\" All rights reserved. 5*525a267eSThomas Cort.\" 6*525a267eSThomas Cort.\" Written by Philip A. Nelson for Piermont Information Systems Inc. 7*525a267eSThomas Cort.\" 8*525a267eSThomas Cort.\" Redistribution and use in source and binary forms, with or without 9*525a267eSThomas Cort.\" modification, are permitted provided that the following conditions 10*525a267eSThomas Cort.\" are met: 11*525a267eSThomas Cort.\" 1. Redistributions of source code must retain the above copyright 12*525a267eSThomas Cort.\" notice, this list of conditions and the following disclaimer. 13*525a267eSThomas Cort.\" 2. Redistributions in binary form must reproduce the above copyright 14*525a267eSThomas Cort.\" notice, this list of conditions and the following disclaimer in the 15*525a267eSThomas Cort.\" documentation and/or other materials provided with the distribution. 16*525a267eSThomas Cort.\" 3. The name of Piermont Information Systems Inc. may not be used to endorse 17*525a267eSThomas Cort.\" or promote products derived from this software without specific prior 18*525a267eSThomas Cort.\" written permission. 19*525a267eSThomas Cort.\" 20*525a267eSThomas Cort.\" THIS SOFTWARE IS PROVIDED BY PIERMONT INFORMATION SYSTEMS INC. ``AS IS'' 21*525a267eSThomas Cort.\" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 22*525a267eSThomas Cort.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 23*525a267eSThomas Cort.\" ARE DISCLAIMED. IN NO EVENT SHALL PIERMONT INFORMATION SYSTEMS INC. BE 24*525a267eSThomas Cort.\" LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 25*525a267eSThomas Cort.\" CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 26*525a267eSThomas Cort.\" SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 27*525a267eSThomas Cort.\" INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 28*525a267eSThomas Cort.\" CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 29*525a267eSThomas Cort.\" ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF 30*525a267eSThomas Cort.\" THE POSSIBILITY OF SUCH DAMAGE. 31*525a267eSThomas Cort.\" 32*525a267eSThomas Cort.Dd August 2, 2004 33*525a267eSThomas Cort.Dt MENUC 1 34*525a267eSThomas Cort.Os 35*525a267eSThomas Cort.Sh NAME 36*525a267eSThomas Cort.Nm menuc 37*525a267eSThomas Cort.Nd menu compiler 38*525a267eSThomas Cort.Sh SYNOPSIS 39*525a267eSThomas Cort.Nm 40*525a267eSThomas Cort.Op Fl o Ar name 41*525a267eSThomas Cort.Ar file 42*525a267eSThomas Cort.Sh DESCRIPTION 43*525a267eSThomas CortThis implements a curses based menu system. 44*525a267eSThomas CortA source file that describes menus, their options, and how to process 45*525a267eSThomas Cortthe options is given to 46*525a267eSThomas Cort.Nm 47*525a267eSThomas Cortand produces both a .c and a .h file that implement the menu system. 48*525a267eSThomas CortThe standard base name of the files is 49*525a267eSThomas Cort.Pa menu_defs . 50*525a267eSThomas CortThe 51*525a267eSThomas Cort.Fl o Ar name 52*525a267eSThomas Cortcan be used to specify a different base name. 53*525a267eSThomas Cort.Sh ENVIRONMENT 54*525a267eSThomas Cort.Bl -tag -width MENUDEF 55*525a267eSThomas Cort.It Ev MENUDEF 56*525a267eSThomas CortCan be set to point to a different set of definition files for 57*525a267eSThomas Cort.Nm . 58*525a267eSThomas CortThe current location defaults to 59*525a267eSThomas Cort.Pa /usr/share/misc . 60*525a267eSThomas Cort.El 61*525a267eSThomas Cort.Sh MENU DESCRIPTIONS 62*525a267eSThomas CortThe input 63*525a267eSThomas Cort.Ar file 64*525a267eSThomas Cortdefines static menus and options for processing those menus. 65*525a267eSThomas CortIt also contains comments, initial C code that is required to provide 66*525a267eSThomas Cortfor definitions and other code necessary for the menu system, and an 67*525a267eSThomas Cortoption declaration if dynamic menus are requested. 68*525a267eSThomas Cort.Pp 69*525a267eSThomas CortComments may appear anywhere in the input 70*525a267eSThomas Cort.Ar file 71*525a267eSThomas Cortand are like a space in the input. 72*525a267eSThomas CortThey are like C comments starting with 73*525a267eSThomas Cort.Em /* 74*525a267eSThomas Cortand ending with 75*525a267eSThomas Cort.Em */ . 76*525a267eSThomas CortThey are unlike C comments in that they may be nested. 77*525a267eSThomas CortA comment does not end until a matching end comment is found. 78*525a267eSThomas Cort.Pp 79*525a267eSThomas CortIn many places, C code is included in the definition 80*525a267eSThomas Cort.Ar file . 81*525a267eSThomas CortAll C code is passed verbatim to the C output file. 82*525a267eSThomas Cort.Nm 83*525a267eSThomas Cortcomments do not start in C code and comments in the C code are 84*525a267eSThomas Cortpassed verbatim to the output. 85*525a267eSThomas CortThe C comments are not recognized by 86*525a267eSThomas Cort.Nm . 87*525a267eSThomas CortIn all cases, C code starts with a left brace 88*525a267eSThomas Cort.Pq Em \&{ 89*525a267eSThomas Cortand ends with the matching right brace 90*525a267eSThomas Cort.Pq Em \&} . 91*525a267eSThomas CortIt is important to recognize that in code segments, any brace 92*525a267eSThomas Cortwill be counted, even if it is in a C comment inside the code. 93*525a267eSThomas Cort.Pp 94*525a267eSThomas CortThe 95*525a267eSThomas Cort.Ar file 96*525a267eSThomas Cortcontains an initial (and optional) code block followed by any 97*525a267eSThomas Cortnumber of menu definition elements in any order. 98*525a267eSThomas CortThe initial code block usually contains includes of header files used by 99*525a267eSThomas Cortcode in the menu code blocks later in the 100*525a267eSThomas Cort.Ar file . 101*525a267eSThomas CortIf 102*525a267eSThomas Cort.Dv USER_MENU_INIT 103*525a267eSThomas Cortis #defined, then it will be evaluated before the 104*525a267eSThomas Cortrest of the menu is initialised, if it evaluates to a non-zero value 105*525a267eSThomas Cortthen the initialisation will fail. 106*525a267eSThomas CortThe file is free format, so the actual formatting of the input 107*525a267eSThomas Cort.Ar file 108*525a267eSThomas Cortis to the taste of the programmer. 109*525a267eSThomas Cort.Pp 110*525a267eSThomas CortAll other C code that will appear in an 111*525a267eSThomas Cort.Em action . 112*525a267eSThomas CortThis will be specified as 113*525a267eSThomas Cort.Aq Em action 114*525a267eSThomas Cortin later text. 115*525a267eSThomas CortSuch an action will appear as: 116*525a267eSThomas Cort.Dl action \*[Lt]opt_endwin\*[Gt] \*[Lt]code\*[Gt] 117*525a267eSThomas Cortin the 118*525a267eSThomas Cort.Ar file . 119*525a267eSThomas CortThe 120*525a267eSThomas Cort.Aq Em opt_endwin , 121*525a267eSThomas Cortif present is: 122*525a267eSThomas Cort.Dl ( endwin ) 123*525a267eSThomas Cortand specifies that the curses 124*525a267eSThomas Cort.Fn endwin 125*525a267eSThomas Cortfunction should be called before executing the code and 126*525a267eSThomas Cortthen reinstating the current curses window after the 127*525a267eSThomas Cortcode has been run. 128*525a267eSThomas CortThe 129*525a267eSThomas Cort.Aq Em code 130*525a267eSThomas Cortis as described above. 131*525a267eSThomas Cort.Pp 132*525a267eSThomas CortThere are four kinds of menu definition elements. 133*525a267eSThomas CortThe first one just declares whether the programmer wants dynamic menus 134*525a267eSThomas Cortavailable. 135*525a267eSThomas CortThe default is static menus only. 136*525a267eSThomas CortThe static menus are the ones defined by the menu definitions and do not 137*525a267eSThomas Cortchange at run time. 138*525a267eSThomas CortThe dynamic menus provide the programmer with a method to create and 139*525a267eSThomas Cortmodify menus during the running of the program. 140*525a267eSThomas CortTo include dynamic menus, one needs only add the declaration: 141*525a267eSThomas Cort.Dl allow dynamic menus ; 142*525a267eSThomas CortThe semicolon is required to terminate this declaration. 143*525a267eSThomas CortThis declaration may appear anywhere in the 144*525a267eSThomas Cort.Ar file , 145*525a267eSThomas Cortbut usually appears before any menus are defined. 146*525a267eSThomas Cort.Pp 147*525a267eSThomas CortThe next element is a code block to execute if the curses 148*525a267eSThomas Cortscreen can not be successfully initialized. 149*525a267eSThomas CortThe declaration 150*525a267eSThomas Cort.Dl error code ; 151*525a267eSThomas Corttells the menu system to execute the associated code block 152*525a267eSThomas Cortif the initialization fails. 153*525a267eSThomas CortIf no code is provided, a default code block is used that prints 154*525a267eSThomas Cort.Dl Could not initialize curses. 155*525a267eSThomas Cortand exits. 156*525a267eSThomas CortThis element may appear anywhere in the 157*525a267eSThomas Cort.Ar file 158*525a267eSThomas Cortbut usually appears before any menus are defined. 159*525a267eSThomas Cort.Pp 160*525a267eSThomas CortThe next element defines default options for menus. 161*525a267eSThomas CortEach menu is built from a list of options. 162*525a267eSThomas CortThese options include the location of the upper left corner of the menu, 163*525a267eSThomas Cortwhether there is a "box" drawn around the menu, whether the menu is 164*525a267eSThomas Cortscrollable, the menu's title, whether shortcut letters are 165*525a267eSThomas Cortallowed, whether a standard exit option should be included 166*525a267eSThomas Cortin the menu and text associated with the standard exit option. 167*525a267eSThomas CortThe general format is: 168*525a267eSThomas Cort.Dl default \*[Lt]comma separated option list\*[Gt] ; 169*525a267eSThomas Cort.Pp 170*525a267eSThomas CortThe supported options are: 171*525a267eSThomas Cort.Bl -tag -width ".Ic exitstring Va text" 172*525a267eSThomas Cort.It Ic x = Va startx 173*525a267eSThomas CortThe column number of the upper left corner of the menu window. 174*525a267eSThomas CortIf 175*525a267eSThomas Cort.Va startx 176*525a267eSThomas Cortis -1 the menu will be centered horizontally. 177*525a267eSThomas Cort.It Ic y = Va starty 178*525a267eSThomas CortThe row number of the upper left corner of the menu window. 179*525a267eSThomas CortIf 180*525a267eSThomas Cort.Va starty 181*525a267eSThomas Cortis negative then the menu will be placed below any message text, but 182*525a267eSThomas Cortin at least row 183*525a267eSThomas Cort.Va -starty . 184*525a267eSThomas Cort.It Ic h = Va height 185*525a267eSThomas CortSpecifies the number of menu entries to be displayed. 186*525a267eSThomas CortIf zero, the height will be based on the number of entries. 187*525a267eSThomas Cort.It Ic h = Va width 188*525a267eSThomas CortSpecifies the width of the menu window. 189*525a267eSThomas CortIf zero, the width will be that of the longest menu text line. 190*525a267eSThomas Cort.It Ic title Va text 191*525a267eSThomas CortThe specified 192*525a267eSThomas Cort.Va text 193*525a267eSThomas Cortwill be displayed at the top of the menu window (inside any box). 194*525a267eSThomas Cort.It Ic box 195*525a267eSThomas CortIf specified, draw a box around the menu. 196*525a267eSThomas Cort.It Ic clear 197*525a267eSThomas CortIf specified, clear the window before performing the 198*525a267eSThomas Cort.Va action . 199*525a267eSThomas Cort.It Ic exit 200*525a267eSThomas CortIf specified add an addition option to exit the menu. 201*525a267eSThomas Cort.It Ic exitstring Va text 202*525a267eSThomas CortThe menu label for the 203*525a267eSThomas Cort.Va exit 204*525a267eSThomas Cortoption. 205*525a267eSThomas CortIf not specified defaults to "exit". 206*525a267eSThomas Cort.It Ic default exit 207*525a267eSThomas CortIf specified, place the cursor on the 208*525a267eSThomas Cort.Va exit 209*525a267eSThomas Cortline of the menu, instead of the top line. 210*525a267eSThomas Cort.It Ic shortcut 211*525a267eSThomas CortIf specified, add alphabetic tags to each menu line. 212*525a267eSThomas Cort.It Ic scrollable 213*525a267eSThomas CortIf specified, and the menu has more lines than will fit in its window, then 214*525a267eSThomas Cortonly part of the menu will be displayed and the 215*525a267eSThomas Cort.Sq \*[Lt] 216*525a267eSThomas Cortand 217*525a267eSThomas Cort.Sq \*[Gt] 218*525a267eSThomas Cortkeys will scroll the displayed menu lines. 219*525a267eSThomas Cort.It Ic always scroll 220*525a267eSThomas CortIf specified, allow for the scroll message line even if the menu doesn't 221*525a267eSThomas Cortappear to have too many lines. 222*525a267eSThomas CortUseful for dynamic menus, when the number of entries isn't known when the 223*525a267eSThomas Cortmenu window is created.. 224*525a267eSThomas Cort.It Ic sub menu 225*525a267eSThomas CortIf specified, the screen contents that the menu window overwrites are saved 226*525a267eSThomas Cortand restored when the menu exits. 227*525a267eSThomas Cort.El 228*525a267eSThomas CortThe 229*525a267eSThomas Cort.Ic box , clear , exit , default exit , shortcut , scrollable , always scroll , 230*525a267eSThomas Cortand 231*525a267eSThomas Cort.Ic sub menu 232*525a267eSThomas Cortoptions can be preceded by 233*525a267eSThomas Cort.Ic no 234*525a267eSThomas Cortin order to negate a default. 235*525a267eSThomas Cort.Pp 236*525a267eSThomas CortThe 237*525a267eSThomas Cort.Va text 238*525a267eSThomas Cortarguments can be either a quoted text string or a name #defined to something 239*525a267eSThomas Cortsuitable for initialising a const char * field. 240*525a267eSThomas Cort.Pp 241*525a267eSThomas CortThe default declaration may appear multiple times. 242*525a267eSThomas CortEach time, it sets the default values for menu definitions that follow 243*525a267eSThomas Cortin the 244*525a267eSThomas Cort.Ar file . 245*525a267eSThomas CortIn each menu definition, any or all of these default definitions 246*525a267eSThomas Cortmay be overridden for that menu. 247*525a267eSThomas Cort.Pp 248*525a267eSThomas CortThe final element is the actual static menu definitions. 249*525a267eSThomas CortThe format and order for a menu definition is: 250*525a267eSThomas Cort.Bd -ragged -offset indent 251*525a267eSThomas Cortmenu \*[Lt]name\*[Gt] \*[Lt]options\*[Gt] ; 252*525a267eSThomas Cort \*[Lt]display action\*[Gt] 253*525a267eSThomas Cort \*[Lt]menu items\*[Gt] 254*525a267eSThomas Cort \*[Lt]exit action\*[Gt] 255*525a267eSThomas Cort \*[Lt]help text\*[Gt] 256*525a267eSThomas Cort.Ed 257*525a267eSThomas Cort.Pp 258*525a267eSThomas CortNames are unquoted strings of alpha-numeric and underscore 259*525a267eSThomas Cortcharacters. 260*525a267eSThomas CortThey must start with an alpha character. 261*525a267eSThomas CortIn C source, a menu named 262*525a267eSThomas Cort.Dq foo 263*525a267eSThomas Cortis appears as 264*525a267eSThomas Cort.Dq MENU_foo . 265*525a267eSThomas Cort(Capitalization is important.) 266*525a267eSThomas CortThis is important, because the menu is displayed and processed by 267*525a267eSThomas Cortcalling the function 268*525a267eSThomas Cort.Dl process_menu (MENU_foo, arg) ; 269*525a267eSThomas Cort.Pp 270*525a267eSThomas CortThe options are a comma separated list of options as in the 271*525a267eSThomas Cort.Dq default 272*525a267eSThomas Cortdeclaration. 273*525a267eSThomas CortThese override the options from the most recent default declaration. 274*525a267eSThomas Cort.Pp 275*525a267eSThomas CortThe display action is optional and provides C code to 276*525a267eSThomas Cortexecute at each and every time the menu is displayed for processing. 277*525a267eSThomas CortIf it is included, the format is: 278*525a267eSThomas Cort.Dl display \*[Lt]action\*[Gt] ; 279*525a267eSThomas Cort.Pp 280*525a267eSThomas CortThe bulk of the menu definition is the specification 281*525a267eSThomas Cortof the menu items. 282*525a267eSThomas CortThe general format of a menu item is: 283*525a267eSThomas Cort.Dl option \*[Lt]string\*[Gt], \*[Lt]element_list\*[Gt] ; 284*525a267eSThomas CortThe 285*525a267eSThomas Cort.Aq Em string 286*525a267eSThomas Cortis the text displayed for the menu item, this must be a quoted string 287*525a267eSThomas Cortor a name #defined to something that will initialise a const char * field. 288*525a267eSThomas CortThere may be an arbitrary number of these items. 289*525a267eSThomas Cort(If there are shortcuts in the menu, a practical limit 290*525a267eSThomas Cortof 51 should be recognized. 291*525a267eSThomas CortIt produces shortcuts a to w, y, z, and A to Z. 292*525a267eSThomas Cortx is the shortcut for the exit item.) 293*525a267eSThomas Cort.Pp 294*525a267eSThomas CortThe 295*525a267eSThomas Cort.Aq Em element_list 296*525a267eSThomas Cortis a comma separated list of what to do when the item is selected. 297*525a267eSThomas CortThey may appear in any order. 298*525a267eSThomas Cort.Pp 299*525a267eSThomas CortThe first element processed when a menu item 300*525a267eSThomas Cortis selected is the associated action. 301*525a267eSThomas CortThe next element to be processed is the sub or next menu option. 302*525a267eSThomas CortThey are declared as: 303*525a267eSThomas Cort.Dl next menu \*[Lt]name\*[Gt] 304*525a267eSThomas Cort.Dl sub menu \*[Lt]name\*[Gt] 305*525a267eSThomas CortThe difference between these two is that a sub 306*525a267eSThomas Cortmenu will return to the current menu when exited. 307*525a267eSThomas CortThe next menu will just replace the current 308*525a267eSThomas Cortmenu and when exited, will return to where the 309*525a267eSThomas Cortcurrent menu would have gone. 310*525a267eSThomas CortOnly one of menu element may be used for each menu item. 311*525a267eSThomas CortFinally, after processing both the action and a sub menu, 312*525a267eSThomas Cortthe current menu will be exited if the element 313*525a267eSThomas Cort.Dl exit 314*525a267eSThomas Cortis specified. 315*525a267eSThomas Cort.Em Note : 316*525a267eSThomas CortIf 317*525a267eSThomas Cort.Em exit 318*525a267eSThomas Cortis specified, next menu will not work because 319*525a267eSThomas Cortthe menu system will exit the 320*525a267eSThomas Cort.Em current 321*525a267eSThomas Cortmenu, even if current has been set by 322*525a267eSThomas Cort.Em next menu . 323*525a267eSThomas Cort.Pp 324*525a267eSThomas CortAfter all menu items, the final two menu definition 325*525a267eSThomas Cortelements may appear. 326*525a267eSThomas CortThe exit action is optional and provides C code to 327*525a267eSThomas Cortexecute in the process of exiting a menu. 328*525a267eSThomas CortIf it is included, the format is: 329*525a267eSThomas Cort.Dl exit \*[Lt]action\*[Gt] ; 330*525a267eSThomas Cort.Pp 331*525a267eSThomas CortThe final part of the menu definition is the optional 332*525a267eSThomas Corthelp string. 333*525a267eSThomas CortThe format is: 334*525a267eSThomas Cort.Dl help \*[Lt]text\*[Gt] ; 335*525a267eSThomas CortThis text is displayed in a full page 336*525a267eSThomas Corthelp window if the question mark is typed. 337*525a267eSThomas CortThe actual help text starts with a left brace 338*525a267eSThomas Cort.Pq Em \&{ 339*525a267eSThomas Cortand ends with the matching right brace 340*525a267eSThomas Cort.Pq Em \&} . 341*525a267eSThomas CortThe braces are not included in the 342*525a267eSThomas Corthelp string, but all other characters between 343*525a267eSThomas Cortthem are included. 344*525a267eSThomas CortNewlines in the code translate to newlines in the help text. 345*525a267eSThomas CortAlternatively, the name of a const char * variable may be given. 346*525a267eSThomas Cort.Sh DYNAMIC MENUS 347*525a267eSThomas CortIf requested, 348*525a267eSThomas Cort.Nm 349*525a267eSThomas Cortsupports dynamic menus by allowing the user to create new 350*525a267eSThomas Cortmenus. 351*525a267eSThomas CortThe related definitions for using dynamic menus are: 352*525a267eSThomas Cort.Bd -literal 353*525a267eSThomas Cortstruct menudesc; 354*525a267eSThomas Cort 355*525a267eSThomas Corttypedef 356*525a267eSThomas Cortstruct menu_ent { 357*525a267eSThomas Cort const char *opt_name; 358*525a267eSThomas Cort int opt_menu; 359*525a267eSThomas Cort int opt_flags; 360*525a267eSThomas Cort int (*opt_action)(struct menudesc *, void *); 361*525a267eSThomas Cort} menu_ent ; 362*525a267eSThomas Cort 363*525a267eSThomas Cort/* For opt_menu */ 364*525a267eSThomas Cort#define OPT_NOMENU -1 365*525a267eSThomas Cort 366*525a267eSThomas Cort/* For opt_flags */ 367*525a267eSThomas Cort#define OPT_SUB 1 368*525a267eSThomas Cort#define OPT_ENDWIN 2 369*525a267eSThomas Cort#define OPT_EXIT 4 370*525a267eSThomas Cort 371*525a267eSThomas Corttypedef 372*525a267eSThomas Cortstruct menudesc { 373*525a267eSThomas Cort const char *title; 374*525a267eSThomas Cort int y, x; 375*525a267eSThomas Cort int h, w; 376*525a267eSThomas Cort int mopt; 377*525a267eSThomas Cort int numopts; 378*525a267eSThomas Cort int cursel; 379*525a267eSThomas Cort int topline; 380*525a267eSThomas Cort menu_ent *opts; 381*525a267eSThomas Cort WINDOW *mw; 382*525a267eSThomas Cort WINDOW *sv_mw; 383*525a267eSThomas Cort const char *helpstr; 384*525a267eSThomas Cort const char *exitstr; 385*525a267eSThomas Cort void (*post_act)(struct menudesc *, void *); 386*525a267eSThomas Cort void (*exit_act)(struct menudesc *, void *); 387*525a267eSThomas Cort void (*draw_line)(struct menudesc *, int, void *); 388*525a267eSThomas Cort} menudesc ; 389*525a267eSThomas Cort 390*525a267eSThomas Cort/* defines for mopt field. */ 391*525a267eSThomas Cort#define MC_NOEXITOPT 1 392*525a267eSThomas Cort#define MC_NOBOX 2 393*525a267eSThomas Cort#define MC_SCROLL 4 394*525a267eSThomas Cort#define MC_NOSHORTCUT 8 395*525a267eSThomas Cort#define MC_NOCLEAR 16 396*525a267eSThomas Cort#define MC_DFLTEXIT 32 397*525a267eSThomas Cort#define MC_ALWAYS_SCROLL 64 398*525a267eSThomas Cort#define MC_SUBMENU 128 399*525a267eSThomas Cort 400*525a267eSThomas Cortint new_menu(const char *title, menu_ent *opts, int numopts, 401*525a267eSThomas Cort int x, int y, int h, int w, int mopt, 402*525a267eSThomas Cort void (*post_act)(struct menudesc *, void *), 403*525a267eSThomas Cort void (*draw_line)(struct menudesc *, int, void *), 404*525a267eSThomas Cort void (*exit_act)(struct menudesc *, void *), 405*525a267eSThomas Cort const char *help, const char *exitstr); 406*525a267eSThomas Cort 407*525a267eSThomas Cortvoid free_menu (int menu_no); 408*525a267eSThomas Cort.Ed 409*525a267eSThomas Cort.Pp 410*525a267eSThomas CortThe 411*525a267eSThomas Cort.Ar title 412*525a267eSThomas Cortis the title displayed at the top of the menu. 413*525a267eSThomas CortThe 414*525a267eSThomas Cort.Ar opts 415*525a267eSThomas Cortis an array of menu entry definitions that has 416*525a267eSThomas Cort.Ar numopts 417*525a267eSThomas Cortelements. 418*525a267eSThomas CortThe programmer must build this array and 419*525a267eSThomas Cortfill in all of the fields before processing calling 420*525a267eSThomas Cort.Fn process_menu 421*525a267eSThomas Cortfor the new menu. 422*525a267eSThomas CortThe fields of the 423*525a267eSThomas Cort.Ar opts 424*525a267eSThomas Cortmay change at any time. 425*525a267eSThomas CortFor example, 426*525a267eSThomas Cort.Em opt_name 427*525a267eSThomas Cortmay change as a result of selecting that option. 428*525a267eSThomas CortWhen the menu is redisplayed, the new text is printed. 429*525a267eSThomas CortArguments, 430*525a267eSThomas Cort.Ar x , y , h , 431*525a267eSThomas Cortand 432*525a267eSThomas Cort.Ar w 433*525a267eSThomas Cortare the same as the options in the menu description. 434*525a267eSThomas Cort.Ar mopt 435*525a267eSThomas Cortis the boolean options. 436*525a267eSThomas CortNote, box, clear, exit and shortcuts are enabled by default. 437*525a267eSThomas CortYou need to add option flags to turn them off or turn on scrollable menus. 438*525a267eSThomas CortThe options 439*525a267eSThomas Cort.Ar post_act , 440*525a267eSThomas Cortand 441*525a267eSThomas Cort.Ar exit_act 442*525a267eSThomas Cortare function pointers to the display action and the exit action. 443*525a267eSThomas CortIf they are 444*525a267eSThomas Cort.Dv NULL , 445*525a267eSThomas Cortno call will be made. 446*525a267eSThomas Cort.Ar draw_line 447*525a267eSThomas Cortwill be called to display the menu line if the corresponding opt_name 448*525a267eSThomas Cortfield is 449*525a267eSThomas Cort.Dv NULL . 450*525a267eSThomas Cort.Ar help 451*525a267eSThomas Cortis the text to display in a help screen. 452*525a267eSThomas CortAnd finally, 453*525a267eSThomas Cort.Ar exitstr 454*525a267eSThomas Cortis the text for the 'exit' line of the menu. 455*525a267eSThomas CortIf 456*525a267eSThomas Cort.Dv NULL , 457*525a267eSThomas Cort"Exit" is used. 458*525a267eSThomas CortA 459*525a267eSThomas Cort.Dv NULL 460*525a267eSThomas Corthelp pointer will disable the help feature for the menu. 461*525a267eSThomas Cort.Sh FILES 462*525a267eSThomas Cort.Bl -item 463*525a267eSThomas Cort.It 464*525a267eSThomas Cort.Pa /usr/share/misc/menu_sys.def 465*525a267eSThomas Cort.El 466*525a267eSThomas Cort.Sh EXAMPLES 467*525a267eSThomas CortThe following is a simple menu definition file. 468*525a267eSThomas CortIt is complete in that the output of 469*525a267eSThomas Cort.Nm 470*525a267eSThomas Cortmay be compiled into a complete program. 471*525a267eSThomas CortFor example, if the following was in a file called 472*525a267eSThomas Cort.Pa example.mc , 473*525a267eSThomas Cortan executable program could be produced by the following commands. 474*525a267eSThomas Cort.Bd -literal -offset indent 475*525a267eSThomas Cortmenuc -o example example.mc 476*525a267eSThomas Cortcc -o example example.c -lcurses 477*525a267eSThomas Cort.Ed 478*525a267eSThomas CortA much more complete example is available with the source 479*525a267eSThomas Cortdistribution in a subdirectory called 480*525a267eSThomas Cort.Em testm . 481*525a267eSThomas Cort.Bd -literal 482*525a267eSThomas Cort/* This is an example menu definition file for menuc. */ 483*525a267eSThomas Cort 484*525a267eSThomas Cort{ 485*525a267eSThomas Cort#include \*[Lt]stdio.h\*[Gt] 486*525a267eSThomas Cort#include \*[Lt]unistd.h\*[Gt] 487*525a267eSThomas Cort 488*525a267eSThomas Cort/* Main program! This is often in a different file. */ 489*525a267eSThomas Cortint 490*525a267eSThomas Cortmain() 491*525a267eSThomas Cort { 492*525a267eSThomas Cort process_menu (MENU_main, NULL); 493*525a267eSThomas Cort endwin(); 494*525a267eSThomas Cort return 0; 495*525a267eSThomas Cort } 496*525a267eSThomas Cort 497*525a267eSThomas Cort/* Example initialize function! */ 498*525a267eSThomas Cortvoid 499*525a267eSThomas Cortinit_main() 500*525a267eSThomas Cort { 501*525a267eSThomas Cort } 502*525a267eSThomas Cort} 503*525a267eSThomas Cort 504*525a267eSThomas Cortdefault x=20, y=10, box, scrollable, exit; 505*525a267eSThomas Cort 506*525a267eSThomas Corterror action { 507*525a267eSThomas Cort fprintf (stderr, "Example Menu: Could not initialize curses."); 508*525a267eSThomas Cort exit(1); 509*525a267eSThomas Cort}; 510*525a267eSThomas Cort 511*525a267eSThomas Cortmenu main, title "Main Menu", no exit, no shortcut; 512*525a267eSThomas Cort display action { init_main(); }; 513*525a267eSThomas Cort option "Option 1", 514*525a267eSThomas Cort action (endwin) { 515*525a267eSThomas Cort printf ("That was option 1!"); 516*525a267eSThomas Cort sleep(3); 517*525a267eSThomas Cort }; 518*525a267eSThomas Cort option "Sub Menu", sub menu othermenu; 519*525a267eSThomas Cort option "Next Menu", next menu othermenu; 520*525a267eSThomas Cort option "Quit", exit; 521*525a267eSThomas Cort help { 522*525a267eSThomas CortThis is a simple help screen for an example menu definition file. 523*525a267eSThomas Cort}; 524*525a267eSThomas Cort 525*525a267eSThomas Cortmenu othermenu, title "Sub/Next Menu", x=5, y=5, no box; 526*525a267eSThomas Cort option "Do Nothing!", action { }; 527*525a267eSThomas Cort.Ed 528*525a267eSThomas Cort.Sh SEE ALSO 529*525a267eSThomas Cort.Xr msgc 1 530*525a267eSThomas Cort.Sh AUTHORS 531*525a267eSThomas Cort.An Philip A. Nelson 532*525a267eSThomas Cortfor Piermont Information Systems Inc. 533*525a267eSThomas CortInitial ideas for this were developed and implemented in Pascal at the 534*525a267eSThomas CortLeiden University, Netherlands, in the summer of 1980. 535*525a267eSThomas Cort.Sh BUGS 536*525a267eSThomas CortBoth 537*525a267eSThomas Cort.Nm 538*525a267eSThomas Cortand 539*525a267eSThomas Cort.Nm msgc 540*525a267eSThomas Cortare probably only used by 541*525a267eSThomas Cort.Nm sysinst . 542*525a267eSThomas CortThe features of both have been tailored for 543*525a267eSThomas Cort.Nm sysinst , 544*525a267eSThomas Cortand further changes are likely to occur. 545