menu_sys.def revision 1.22 1 /* $NetBSD: menu_sys.def,v 1.22 2000/04/22 21:34:25 thorpej Exp $ */
2
3 /*
4 * Copyright 1997 Piermont Information Systems Inc.
5 * All rights reserved.
6 *
7 * Written by Philip A. Nelson for Piermont Information Systems Inc.
8 *
9 * Redistribution and use in source and binary forms, with or without
10 * modification, are permitted provided that the following conditions
11 * are met:
12 * 1. Redistributions of source code must retain the above copyright
13 * notice, this list of conditions and the following disclaimer.
14 * 2. Redistributions in binary form must reproduce the above copyright
15 * notice, this list of conditions and the following disclaimer in the
16 * documentation and/or other materials provided with the distribution.
17 * 3. All advertising materials mentioning features or use of this software
18 * must display the following acknowledgement:
19 * This product includes software develooped for the NetBSD Project by
20 * Piermont Information Systems Inc.
21 * 4. The name of Piermont Information Systems Inc. may not be used to endorse
22 * or promote products derived from this software without specific prior
23 * written permission.
24 *
25 * THIS SOFTWARE IS PROVIDED BY PIERMONT INFORMATION SYSTEMS INC. ``AS IS''
26 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
27 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
28 * ARE DISCLAIMED. IN NO EVENT SHALL PIERMONT INFORMATION SYSTEMS INC. BE
29 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
30 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
31 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
32 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
33 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
34 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
35 * THE POSSIBILITY OF SUCH DAMAGE.
36 *
37 */
38
39 /* menu_sys.defs -- Menu system standard routines. */
40
41 #include <string.h>
42 #include <ctype.h>
43
44 #define REQ_EXECUTE 1000
45 #define REQ_NEXT_ITEM 1001
46 #define REQ_PREV_ITEM 1002
47 #define REQ_REDISPLAY 1003
48 #define REQ_SCROLLDOWN 1004
49 #define REQ_SCROLLUP 1005
50 #define REQ_HELP 1006
51
52 /* Multiple key support */
53 #define KEYSEQ_FIRST 256
54 #define KEYSEQ_DOWN_ARROW 256
55 #define KEYSEQ_UP_ARROW 257
56 #define KEYSEQ_LEFT_ARROW 258
57 #define KEYSEQ_RIGHT_ARROW 259
58 #define KEYSEQ_PAGE_DOWN 260
59 #define KEYSEQ_PAGE_UP 261
60
61 struct keyseq {
62 char *termcap_name;
63 char *chars;
64 int numchars;
65 int keyseq_val;
66 struct keyseq *next;
67 };
68
69 /* keypad and other definitions */
70 struct keyseq _mc_key_seq[] = {
71 /* Cludge for xterm ... */
72 { NULL, "\033[B", 0, KEYSEQ_DOWN_ARROW, NULL },
73 { NULL, "\033[D", 0, KEYSEQ_LEFT_ARROW, NULL },
74 { NULL, "\033[C", 0, KEYSEQ_RIGHT_ARROW, NULL },
75 { NULL, "\033[A", 0, KEYSEQ_UP_ARROW, NULL },
76 /* Termcap defined */
77 { "kd", NULL, 0, KEYSEQ_DOWN_ARROW, NULL },
78 { "kl", NULL, 0, KEYSEQ_LEFT_ARROW, NULL },
79 { "kr", NULL, 0, KEYSEQ_RIGHT_ARROW, NULL },
80 { "ku", NULL, 0, KEYSEQ_UP_ARROW, NULL },
81 { "kf", NULL, 0, KEYSEQ_PAGE_DOWN, NULL }, /* scroll forward */
82 { "kN", NULL, 0, KEYSEQ_PAGE_DOWN, NULL }, /* next page */
83 { "kP", NULL, 0, KEYSEQ_PAGE_UP, NULL }, /* scroll backward */
84 { "kR", NULL, 0, KEYSEQ_PAGE_UP, NULL }, /* prev page */
85 /* other definitions */
86 { NULL, "\033v", 0, KEYSEQ_PAGE_UP, NULL }, /* ESC-v */
87 { NULL, "\026", 0, KEYSEQ_PAGE_DOWN, NULL }, /* CTL-v */
88 };
89
90 int _mc_num_key_seq = sizeof(_mc_key_seq) / sizeof(struct keyseq);
91 struct keyseq *pad_list = NULL;
92 static char str_area [512];
93 static char *str_ptr = str_area;
94
95 /* Macros */
96 #define MAX(x,y) ((x)>(y)?(x):(y))
97 #define MIN(x,y) ((x)<(y)?(x):(y))
98
99 /* Initialization state. */
100 static int __menu_init = 0;
101 int __m_endwin = 0;
102 static int max_lines = 0, max_cols = 0;
103 static char *scrolltext = " <: page up, >: page down";
104
105 static menudesc *menus = menu_def;
106
107 #ifdef DYNAMIC_MENUS
108 static int num_menus = 0;
109 static int num_avail = 0;
110 #define DYN_INIT_NUM 32
111 #endif
112
113 /* prototypes for in here! */
114 static void ins_keyseq (struct keyseq **seq, struct keyseq *ins);
115 static void init_keyseq (void);
116 static void init_menu (struct menudesc *m);
117 static char opt_ch (int op_no);
118 static void post_menu (struct menudesc *m);
119 static void process_help (struct menudesc *m, int num);
120 static void process_req (struct menudesc *m, int num, int req);
121 static void mbeep (void);
122 static int menucmd (WINDOW *w);
123
124 #ifndef NULL
125 #define NULL (void *)0
126 #endif
127
128 /* menu system processing routines */
129
130 static void mbeep (void)
131 {
132 fprintf (stderr,"\a");
133 }
134
135 static void ins_keyseq (struct keyseq **seq, struct keyseq *ins)
136 {
137 if (*seq == NULL) {
138 ins->next = NULL;
139 *seq = ins;
140 } else if (ins->numchars <= (*seq)->numchars) {
141 ins->next = *seq;
142 *seq = ins;
143 } else
144 ins_keyseq (&(*seq)->next, ins);
145 }
146
147 static void init_keyseq (void)
148 {
149 /*
150 * XXX XXX XXX THIS SHOULD BE NUKED FROM ORBIT! DO THIS
151 * XXX XXX XXX WITH NORMAL CURSES FACILITIES!
152 */
153 extern struct tinfo *_cursesi_genbuf;
154
155 int i;
156
157 for (i=0; i<_mc_num_key_seq; i++) {
158 if (_mc_key_seq[i].termcap_name)
159 _mc_key_seq[i].chars =
160 t_getstr (_cursesi_genbuf,
161 _mc_key_seq[i].termcap_name,
162 &str_ptr, NULL);
163 if (_mc_key_seq[i].chars != NULL &&
164 (_mc_key_seq[i].numchars = strlen(_mc_key_seq[i].chars))
165 > 0)
166 ins_keyseq (&pad_list,&_mc_key_seq[i]);
167 }
168 }
169
170 static int mgetch(WINDOW *w)
171 {
172 static char buf[20];
173 static int num = 0;
174 struct keyseq *list = pad_list;
175 int i, ret;
176
177 /* key pad processing */
178 while (list) {
179 for (i=0; i< list->numchars; i++) {
180 if (i >= num)
181 buf[num++] = wgetch(w);
182 if (buf[i] != list->chars[i])
183 break;
184 }
185 if (i == list->numchars) {
186 num = 0;
187 return list->keyseq_val;
188 }
189 list = list->next;
190 }
191
192 ret = buf[0];
193 for (i = 0; i < strlen(buf); i++)
194 buf[i] = buf[i+1];
195 num--;
196 return ret;
197 }
198
199 static int menucmd (WINDOW *w)
200 {
201 int ch;
202
203 while (TRUE) {
204 ch = mgetch(w);
205
206 switch (ch) {
207 case '\n':
208 return REQ_EXECUTE;
209 case '\016': /* Contnrol-P */
210 case KEYSEQ_DOWN_ARROW:
211 return REQ_NEXT_ITEM;
212 case '\020': /* Control-N */
213 case KEYSEQ_UP_ARROW:
214 return REQ_PREV_ITEM;
215 case '\014': /* Control-L */
216 return REQ_REDISPLAY;
217 case '<':
218 case '\010': /* Control-H (backspace) */
219 case KEYSEQ_PAGE_UP:
220 return REQ_SCROLLUP;
221 case '>':
222 case ' ':
223 case KEYSEQ_PAGE_DOWN:
224 return REQ_SCROLLDOWN;
225 case '?':
226 return REQ_HELP;
227 }
228
229 if (isalpha(ch))
230 return (ch);
231
232 mbeep();
233 wrefresh(w);
234 }
235 }
236
237 static void init_menu (struct menudesc *m)
238 {
239 int wmax;
240 int hadd, wadd, exithadd;
241 int i;
242
243 hadd = ((m->mopt & MC_NOBOX) ? 0 : 2);
244 wadd = ((m->mopt & MC_NOBOX) ? 2 : 4);
245
246 hadd += strlen(m->title) != 0 ? 2 : 0;
247 exithadd = ((m->mopt & MC_NOEXITOPT) ? 0 : 1);
248
249 wmax = strlen(m->title);
250
251 /* Calculate h? h == number of visible options. */
252 if (m->h == 0) {
253 m->h = m->numopts + exithadd;
254 if (m->h + m->y + hadd >= max_lines && (m->mopt & MC_SCROLL))
255 m->h = max_lines - m->y - hadd ;
256 }
257
258 /* Check window heights and set scrolling */
259 if (m->h < m->numopts + exithadd) {
260 if (!(m->mopt & MC_SCROLL) || m->h < 3) {
261 endwin();
262 (void) fprintf (stderr,
263 "Window too short for menu \"%s\"\n",
264 m->title);
265 exit(1);
266 }
267 } else
268 m->mopt &= ~MC_SCROLL;
269
270 /* check for screen fit */
271 if (m->y + m->h + hadd > max_lines) {
272 endwin();
273 (void) fprintf (stderr,
274 "Screen too short for menu \"%s\"\n", m->title);
275 exit(1);
276
277 }
278
279 /* Calculate w? */
280 if (m->w == 0) {
281 if (m->mopt & MC_SCROLL)
282 wmax = MAX(wmax,strlen(scrolltext));
283 for (i=0; i < m->numopts; i++ )
284 wmax = MAX(wmax,strlen(m->opts[i].opt_name)+3);
285 m->w = wmax;
286 }
287
288 /* check and adjust for screen fit */
289 if (m->w + wadd > max_cols) {
290 endwin();
291 (void) fprintf (stderr,
292 "Screen too narrow for menu \"%s\"\n", m->title);
293 exit(1);
294
295 }
296 if (m->x == -1)
297 m->x = (max_cols - (m->w + wadd)) / 2; /* center */
298 else if (m->x + m->w + wadd > max_cols)
299 m->x = max_cols - (m->w + wadd);
300
301 /* Get the windows. */
302 m->mw = newwin(m->h+hadd, m->w+wadd, m->y, m->x);
303
304 if (m->mw == NULL) {
305 endwin();
306 (void) fprintf (stderr,
307 "Could not create window for menu \"%s\"\n", m->title);
308 exit(1);
309 }
310 }
311
312 static char opt_ch (int op_no)
313 {
314 char c;
315 if (op_no < 25) {
316 c = 'a' + op_no;
317 if (c >= 'x') c++;
318 } else
319 c = 'A' + op_no - 25;
320 return (char) c;
321 }
322
323 static void post_menu (struct menudesc *m)
324 {
325 int i;
326 int hasbox, cury, maxy, selrow, lastopt;
327 int tadd;
328 char optstr[5];
329
330 if (m->mopt & MC_NOBOX) {
331 cury = 0;
332 maxy = m->h;
333 hasbox = 0;
334 } else {
335 cury = 1;
336 maxy = m->h+1;
337 hasbox = 1;
338 }
339
340 /* Clear the window */
341 wclear (m->mw);
342
343 tadd = strlen(m->title) ? 2 : 0;
344
345 if (tadd) {
346 mvwaddstr(m->mw, cury, cury, " ");
347 mvwaddstr(m->mw, cury, cury + 1, m->title);
348 cury += 2;
349 maxy += 2;
350 }
351
352 /* Set defaults, calculate lastopt. */
353 selrow = -1;
354 if (m->mopt & MC_SCROLL) {
355 lastopt = MIN(m->numopts, m->topline+m->h-1);
356 maxy -= 1;
357 } else
358 lastopt = m->numopts;
359
360 for (i=m->topline; i<lastopt; i++, cury++) {
361 if (m->cursel == i) {
362 mvwaddstr (m->mw, cury, hasbox, ">");
363 wstandout(m->mw);
364 selrow = cury;
365 } else
366 mvwaddstr (m->mw, cury, hasbox, " ");
367 (void) sprintf (optstr, "%c: ", opt_ch(i));
368 waddstr (m->mw, optstr);
369 waddstr (m->mw, m->opts[i].opt_name);
370 if (m->cursel == i)
371 wstandend(m->mw);
372 }
373
374 /* Add the exit option. */
375 if (!(m->mopt & MC_NOEXITOPT) && cury < maxy) {
376 if (m->cursel >= m->numopts) {
377 mvwaddstr (m->mw, cury, hasbox, ">");
378 wstandout(m->mw);
379 selrow = cury;
380 } else
381 mvwaddstr (m->mw, cury, hasbox, " ");
382 waddstr (m->mw, "x: ");
383 waddstr (m->mw, m->exitstr);
384 if (m->cursel >= m->numopts)
385 wstandend(m->mw);
386 cury++;
387 }
388
389 /* Add the scroll line */
390 if (m->mopt & MC_SCROLL) {
391 mvwaddstr (m->mw, cury, hasbox, scrolltext);
392 if (selrow < 0)
393 selrow = cury;
394 }
395
396 /* Add the box. */
397 if (!(m->mopt & MC_NOBOX))
398 box(m->mw, '*', '*');
399
400 wmove(m->mw, selrow, hasbox);
401 }
402
403 static void process_help (struct menudesc *m, int num)
404 {
405 char *help = m->helpstr;
406 int lineoff = 0;
407 int curoff = 0;
408 int again;
409 int winin;
410
411 /* Is there help? */
412 if (!help) {
413 mbeep();
414 return;
415 }
416
417 /* Display the help information. */
418 do {
419 if (lineoff < curoff) {
420 help = m->helpstr;
421 curoff = 0;
422 }
423 while (*help && curoff < lineoff) {
424 if (*help == '\n')
425 curoff++;
426 help++;
427 }
428
429 wclear(stdscr);
430 mvwaddstr (stdscr, 0, 0,
431 "Help: exit: x, page up: u <, page down: d >");
432 mvwaddstr (stdscr, 2, 0, help);
433 wmove (stdscr, 1, 0);
434 wrefresh(stdscr);
435
436 do {
437 winin = mgetch(stdscr);
438 if (winin < KEYSEQ_FIRST)
439 winin = tolower(winin);
440 again = 0;
441 switch (winin) {
442 case '<':
443 case 'u':
444 case KEYSEQ_UP_ARROW:
445 case KEYSEQ_LEFT_ARROW:
446 case KEYSEQ_PAGE_UP:
447 if (lineoff)
448 lineoff -= max_lines - 2;
449 else
450 again = 1;
451 break;
452 case '>':
453 case 'd':
454 case KEYSEQ_DOWN_ARROW:
455 case KEYSEQ_RIGHT_ARROW:
456 case KEYSEQ_PAGE_DOWN:
457 if (*help)
458 lineoff += max_lines - 2;
459 else
460 again = 1;
461 break;
462 case 'q':
463 break;
464 case 'x':
465 winin = 'q';
466 break;
467 default:
468 again = 1;
469 }
470 if (again)
471 mbeep();
472 } while (again);
473 } while (winin != 'q');
474
475 /* Restore current menu */
476 wclear(stdscr);
477 wrefresh(stdscr);
478 if (m->post_act)
479 (*m->post_act)();
480 }
481
482 static void process_req (struct menudesc *m, int num, int req)
483 {
484 int ch;
485 int hasexit = (m->mopt & MC_NOEXITOPT ? 0 : 1 );
486 int refresh = 0;
487 int scroll_sel = 0;
488
489 if (req == REQ_EXECUTE)
490 return;
491
492 else if (req == REQ_NEXT_ITEM) {
493 if (m->cursel < m->numopts + hasexit - 1) {
494 m->cursel++;
495 scroll_sel = 1;
496 refresh = 1;
497 if (m->mopt & MC_SCROLL &&
498 m->cursel >= m->topline + m->h -1 )
499 m->topline += 1;
500 } else
501 mbeep();
502
503 } else if (req == REQ_PREV_ITEM) {
504 if (m->cursel > 0) {
505 m->cursel--;
506 scroll_sel = 1;
507 refresh = 1;
508 if (m->cursel < m->topline )
509 m->topline -= 1;
510 } else
511 mbeep();
512
513 } else if (req == REQ_REDISPLAY) {
514 wclear(stdscr);
515 wrefresh(stdscr);
516 if (m->post_act)
517 (*m->post_act)();
518 refresh = 1;
519
520 } else if (req == REQ_HELP) {
521 process_help (m, num);
522 refresh = 1;
523
524 } else if (req == REQ_SCROLLUP) {
525 if (!(m->mopt & MC_SCROLL))
526 mbeep();
527 else if (m->topline == 0)
528 mbeep();
529 else {
530 m->topline = MAX(0,m->topline-m->h+1);
531 wclear (m->mw);
532 refresh = 1;
533 }
534
535 } else if (req == REQ_SCROLLDOWN) {
536 if (!(m->mopt & MC_SCROLL))
537 mbeep();
538 else if (m->topline + m->h - 1 >= m->numopts + hasexit)
539 mbeep();
540 else {
541 m->topline = MIN(m->topline+m->h-1,
542 m->numopts+hasexit-m->h+1);
543 wclear (m->mw);
544 refresh = 1;
545 }
546
547 } else {
548 ch = req;
549 if (ch == 'x' && hasexit) {
550 m->cursel = m->numopts;
551 scroll_sel = 1;
552 refresh = 1;
553 } else {
554 if (ch > 'z')
555 ch = 255;
556 if (ch >= 'a') {
557 if (ch > 'x') ch--;
558 ch = ch - 'a';
559 } else
560 ch = 25 + ch - 'A';
561 if (ch < 0 || ch >= m->numopts)
562 mbeep();
563 else {
564 m->cursel = ch;
565 scroll_sel = 1;
566 refresh = 1;
567 }
568 }
569 }
570
571 if (m->mopt & MC_SCROLL && scroll_sel) {
572 while (m->cursel >= m->topline + m->h -1 )
573 m->topline = MIN(m->topline+m->h-1,
574 m->numopts+hasexit-m->h+1);
575 while (m->cursel < m->topline)
576 m->topline = MAX(0,m->topline-m->h+1);
577 }
578
579 if (refresh) {
580 post_menu (m);
581 wrefresh (m->mw);
582 }
583 }
584
585 int menu_init (void)
586 {
587
588 if (__menu_init)
589 return 0;
590
591 if (initscr() == NULL)
592 return 1;
593
594 cbreak();
595 noecho();
596 max_lines = getmaxy(stdscr);
597 max_cols = getmaxx(stdscr);
598 init_keyseq();
599 #ifdef DYNAMIC_MENUS
600 num_menus = DYN_INIT_NUM;
601 while (num_menus < DYN_MENU_START)
602 num_menus *= 2;
603 menus = (menudesc *) malloc(sizeof(menudesc)*num_menus);
604 if (menus == NULL)
605 return 2;
606 (void) memset ((void *)menus, 0, sizeof(menudesc)*num_menus);
607 (void) memcpy ((void *)menus, (void *)menu_def,
608 sizeof(menudesc)*DYN_MENU_START);
609 num_avail = num_menus - DYN_MENU_START;
610 #endif
611
612 __menu_init = 1;
613 return (0);
614 }
615
616 void process_menu (int num)
617 {
618 int sel = 0;
619 int req, done;
620 int last_num;
621
622 struct menudesc *m;
623
624 m = &menus[num];
625
626 done = FALSE;
627
628 /* Initialize? */
629 if (menu_init()) {
630 __menu_initerror();
631 return;
632 }
633
634 if (__m_endwin) {
635 wclear(stdscr);
636 wrefresh(stdscr);
637 __m_endwin = 0;
638 }
639 if (m->mw == NULL)
640 init_menu (m);
641
642 /* Always preselect option 0 and display from 0! */
643 m->cursel = 0;
644 m->topline = 0;
645
646 while (!done) {
647 last_num = num;
648 if (__m_endwin) {
649 wclear(stdscr);
650 wrefresh(stdscr);
651 __m_endwin = 0;
652 }
653 /* Process the display action */
654 if (m->post_act)
655 (*m->post_act)();
656 post_menu (m);
657 wrefresh (m->mw);
658
659 while ((req = menucmd (m->mw)) != REQ_EXECUTE)
660 process_req (m, num, req);
661
662 sel = m->cursel;
663 wclear (m->mw);
664 wrefresh (m->mw);
665
666 /* Process the items */
667 if (sel < m->numopts) {
668 if (m->opts[sel].opt_flags & OPT_ENDWIN) {
669 endwin();
670 __m_endwin = 1;
671 }
672 if (m->opts[sel].opt_action)
673 done = (*m->opts[sel].opt_action)();
674 if (m->opts[sel].opt_menu != -1) {
675 if (m->opts[sel].opt_flags & OPT_SUB)
676 process_menu (m->opts[sel].opt_menu);
677 else
678 num = m->opts[sel].opt_menu;
679 }
680
681 if (m->opts[sel].opt_flags & OPT_EXIT)
682 done = TRUE;
683
684 } else
685 done = TRUE;
686
687 /* Reselect m just in case */
688 if (num != last_num) {
689 m = &menus[num];
690
691 /* Initialize? */
692 if (m->mw == NULL)
693 init_menu (m);
694 if (m->post_act)
695 (*m->post_act)();
696 }
697 }
698
699 /* Process the exit action */
700 if (m->exit_act)
701 (*m->exit_act)();
702 }
703
704 /* Control L is end of standard routines, remaining only for dynamic. */
706
707 /* Beginning of routines for dynamic menus. */
708
709 /* local prototypes */
710 static int double_menus (void);
711
712 static int double_menus (void)
713 {
714 menudesc *temp;
715
716 temp = (menudesc *) malloc(sizeof(menudesc)*num_menus*2);
717 if (temp == NULL)
718 return 0;
719 (void) memset ((void *)temp, 0,
720 sizeof(menudesc)*num_menus*2);
721 (void) memcpy ((void *)temp, (void *)menus,
722 sizeof(menudesc)*num_menus);
723 free (menus);
724 menus = temp;
725 num_avail = num_menus;
726 num_menus *= 2;
727
728 return 1;
729 }
730
731 int new_menu (char * title, menu_ent * opts, int numopts,
732 int x, int y, int h, int w, int mopt,
733 void (*post_act)(void), void (*exit_act), char * help)
734 {
735 int ix;
736
737 /* Check for free menu entry. */
738 if (num_avail == 0)
739 if (!double_menus ())
740 return -1;
741
742 /* Find free menu entry. */
743 for (ix = DYN_MENU_START; ix < num_menus && menus[ix].mopt & MC_VALID;
744 ix++) /* do nothing */;
745
746 /* if ix == num_menus ... panic */
747
748 /* Set Entries */
749 menus[ix].title = title;
750 menus[ix].opts = opts;
751 menus[ix].numopts = numopts;
752 menus[ix].x = x;
753 menus[ix].y = y;
754 menus[ix].h = h;
755 menus[ix].w = w;
756 menus[ix].mopt = mopt | MC_VALID;
757 menus[ix].post_act = post_act;
758 menus[ix].exit_act = exit_act;
759 menus[ix].helpstr = help;
760 menus[ix].exitstr = "Exit";
761
762 init_menu (&menus[ix]);
763
764 return ix;
765 }
766
767 void free_menu (int menu_no)
768 {
769 if (menu_no < num_menus) {
770 menus[menu_no].mopt &= ~MC_VALID;
771 if (menus[menu_no].mw != NULL)
772 delwin (menus[menu_no].mw);
773 }
774 }
775