2003-07-07 16:20:56 +04:00
|
|
|
|
/* $NetBSD: menu_sys.def,v 1.43 2003/07/07 12:20:56 dsl Exp $ */
|
1997-09-26 21:54:09 +04:00
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* Copyright 1997 Piermont Information Systems Inc.
|
|
|
|
|
* All rights reserved.
|
|
|
|
|
*
|
|
|
|
|
* Written by Philip A. Nelson for Piermont Information Systems Inc.
|
|
|
|
|
*
|
|
|
|
|
* Redistribution and use in source and binary forms, with or without
|
|
|
|
|
* modification, are permitted provided that the following conditions
|
|
|
|
|
* are met:
|
|
|
|
|
* 1. Redistributions of source code must retain the above copyright
|
|
|
|
|
* notice, this list of conditions and the following disclaimer.
|
|
|
|
|
* 2. Redistributions in binary form must reproduce the above copyright
|
|
|
|
|
* notice, this list of conditions and the following disclaimer in the
|
|
|
|
|
* documentation and/or other materials provided with the distribution.
|
|
|
|
|
* 3. All advertising materials mentioning features or use of this software
|
|
|
|
|
* must display the following acknowledgement:
|
|
|
|
|
* This product includes software develooped for the NetBSD Project by
|
|
|
|
|
* Piermont Information Systems Inc.
|
|
|
|
|
* 4. The name of Piermont Information Systems Inc. may not be used to endorse
|
|
|
|
|
* or promote products derived from this software without specific prior
|
|
|
|
|
* written permission.
|
|
|
|
|
*
|
|
|
|
|
* THIS SOFTWARE IS PROVIDED BY PIERMONT INFORMATION SYSTEMS INC. ``AS IS''
|
|
|
|
|
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
|
|
|
|
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
|
|
|
|
* ARE DISCLAIMED. IN NO EVENT SHALL PIERMONT INFORMATION SYSTEMS INC. BE
|
|
|
|
|
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
|
|
|
|
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
|
|
|
|
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
|
|
|
|
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
|
|
|
|
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
|
|
|
|
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
|
|
|
|
|
* THE POSSIBILITY OF SUCH DAMAGE.
|
|
|
|
|
*
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
/* menu_sys.defs -- Menu system standard routines. */
|
|
|
|
|
|
|
|
|
|
#include <string.h>
|
|
|
|
|
#include <ctype.h>
|
|
|
|
|
|
1997-11-14 19:31:45 +03:00
|
|
|
|
#define REQ_EXECUTE 1000
|
|
|
|
|
#define REQ_NEXT_ITEM 1001
|
|
|
|
|
#define REQ_PREV_ITEM 1002
|
|
|
|
|
#define REQ_REDISPLAY 1003
|
1998-06-29 12:46:37 +04:00
|
|
|
|
#define REQ_SCROLLDOWN 1004
|
|
|
|
|
#define REQ_SCROLLUP 1005
|
|
|
|
|
#define REQ_HELP 1006
|
|
|
|
|
|
|
|
|
|
/* Macros */
|
1997-09-26 21:54:09 +04:00
|
|
|
|
#define MAX(x,y) ((x)>(y)?(x):(y))
|
1998-06-25 13:58:57 +04:00
|
|
|
|
#define MIN(x,y) ((x)<(y)?(x):(y))
|
1997-09-26 21:54:09 +04:00
|
|
|
|
|
|
|
|
|
/* Initialization state. */
|
|
|
|
|
static int __menu_init = 0;
|
|
|
|
|
int __m_endwin = 0;
|
1999-06-19 10:38:49 +04:00
|
|
|
|
static int max_lines = 0, max_cols = 0;
|
1998-06-25 13:58:57 +04:00
|
|
|
|
static char *scrolltext = " <: page up, >: page down";
|
1997-09-26 21:54:09 +04:00
|
|
|
|
|
1998-07-16 11:08:26 +04:00
|
|
|
|
static menudesc *menus = menu_def;
|
|
|
|
|
|
|
|
|
|
#ifdef DYNAMIC_MENUS
|
|
|
|
|
static int num_menus = 0;
|
|
|
|
|
#define DYN_INIT_NUM 32
|
|
|
|
|
#endif
|
|
|
|
|
|
1997-09-26 21:54:09 +04:00
|
|
|
|
/* prototypes for in here! */
|
2003-06-09 22:48:40 +04:00
|
|
|
|
static void init_menu(menudesc *m);
|
2003-07-07 16:20:56 +04:00
|
|
|
|
static char opt_ch(menudesc *m, int op_no);
|
|
|
|
|
static void draw_menu(menudesc *m, void *arg);
|
2003-06-09 22:48:40 +04:00
|
|
|
|
static void process_help(menudesc *m, int num);
|
|
|
|
|
static void process_req(menudesc *m, void *arg, int num, int req);
|
2003-06-03 12:49:53 +04:00
|
|
|
|
static int menucmd(WINDOW *w);
|
1997-09-26 21:54:09 +04:00
|
|
|
|
|
|
|
|
|
#ifndef NULL
|
2003-06-03 12:49:53 +04:00
|
|
|
|
#define NULL 0
|
1997-09-26 21:54:09 +04:00
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
/* menu system processing routines */
|
2001-12-06 19:38:30 +03:00
|
|
|
|
#define mbeep() (void)fputc('\a', stderr)
|
1997-09-26 21:54:09 +04:00
|
|
|
|
|
2000-08-15 05:01:41 +04:00
|
|
|
|
static int
|
2003-06-03 01:19:35 +04:00
|
|
|
|
menucmd(WINDOW *w)
|
1997-09-26 21:54:09 +04:00
|
|
|
|
{
|
|
|
|
|
int ch;
|
|
|
|
|
|
|
|
|
|
while (TRUE) {
|
2002-04-04 18:11:23 +04:00
|
|
|
|
ch = wgetch(w);
|
1997-09-26 21:54:09 +04:00
|
|
|
|
|
|
|
|
|
switch (ch) {
|
|
|
|
|
case '\n':
|
|
|
|
|
return REQ_EXECUTE;
|
2003-05-07 20:39:45 +04:00
|
|
|
|
case '\016': /* Control-P */
|
2002-04-04 18:11:23 +04:00
|
|
|
|
case KEY_DOWN:
|
1997-09-26 21:54:09 +04:00
|
|
|
|
return REQ_NEXT_ITEM;
|
1998-07-01 11:46:02 +04:00
|
|
|
|
case '\020': /* Control-N */
|
2002-04-04 18:11:23 +04:00
|
|
|
|
case KEY_UP:
|
1997-09-26 21:54:09 +04:00
|
|
|
|
return REQ_PREV_ITEM;
|
1998-07-01 11:46:02 +04:00
|
|
|
|
case '\014': /* Control-L */
|
2003-06-03 12:49:53 +04:00
|
|
|
|
return REQ_REDISPLAY;
|
1998-06-29 12:46:37 +04:00
|
|
|
|
case '<':
|
1998-07-01 11:46:02 +04:00
|
|
|
|
case '\010': /* Control-H (backspace) */
|
2002-04-04 18:11:23 +04:00
|
|
|
|
case KEY_PPAGE:
|
2003-05-07 20:39:45 +04:00
|
|
|
|
case KEY_LEFT:
|
1998-06-29 12:46:37 +04:00
|
|
|
|
return REQ_SCROLLUP;
|
2003-05-07 20:39:45 +04:00
|
|
|
|
case '\026': /* Control-V */
|
1998-06-29 12:46:37 +04:00
|
|
|
|
case '>':
|
1998-07-01 11:46:02 +04:00
|
|
|
|
case ' ':
|
2002-04-04 18:11:23 +04:00
|
|
|
|
case KEY_NPAGE:
|
2003-05-07 20:39:45 +04:00
|
|
|
|
case KEY_RIGHT:
|
1998-06-29 12:46:37 +04:00
|
|
|
|
return REQ_SCROLLDOWN;
|
|
|
|
|
case '?':
|
|
|
|
|
return REQ_HELP;
|
2002-04-04 18:11:23 +04:00
|
|
|
|
case '\033': /* esc-v is scroll down */
|
|
|
|
|
ch = wgetch(w);
|
|
|
|
|
if (ch == 'v')
|
|
|
|
|
return REQ_SCROLLUP;
|
|
|
|
|
else
|
|
|
|
|
ch = 0; /* zap char so we beep */
|
1997-09-26 21:54:09 +04:00
|
|
|
|
}
|
|
|
|
|
|
1998-06-29 12:46:37 +04:00
|
|
|
|
if (isalpha(ch))
|
2003-06-03 12:49:53 +04:00
|
|
|
|
return ch;
|
1997-09-26 21:54:09 +04:00
|
|
|
|
|
|
|
|
|
mbeep();
|
|
|
|
|
wrefresh(w);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2000-08-15 05:01:41 +04:00
|
|
|
|
static void
|
2003-06-09 22:48:40 +04:00
|
|
|
|
init_menu(menudesc *m)
|
1997-09-26 21:54:09 +04:00
|
|
|
|
{
|
1999-06-20 05:20:14 +04:00
|
|
|
|
int wmax;
|
|
|
|
|
int hadd, wadd, exithadd;
|
1998-07-16 11:08:26 +04:00
|
|
|
|
int i;
|
2003-06-10 21:19:04 +04:00
|
|
|
|
const char *title;
|
1997-09-26 21:54:09 +04:00
|
|
|
|
|
1999-06-20 05:20:14 +04:00
|
|
|
|
hadd = ((m->mopt & MC_NOBOX) ? 0 : 2);
|
|
|
|
|
wadd = ((m->mopt & MC_NOBOX) ? 2 : 4);
|
|
|
|
|
|
2003-06-10 21:19:04 +04:00
|
|
|
|
if (m->title && *(title = MSG_XLAT(m->title)) != 0) {
|
|
|
|
|
wmax = strlen(title);
|
|
|
|
|
hadd += 2;
|
|
|
|
|
} else {
|
|
|
|
|
m->title = NULL;
|
|
|
|
|
title = "untitled";
|
|
|
|
|
wmax = 0;
|
|
|
|
|
}
|
1999-06-20 05:20:14 +04:00
|
|
|
|
exithadd = ((m->mopt & MC_NOEXITOPT) ? 0 : 1);
|
|
|
|
|
|
1997-09-26 21:54:09 +04:00
|
|
|
|
|
1998-06-25 13:58:57 +04:00
|
|
|
|
/* Calculate h? h == number of visible options. */
|
2003-06-04 23:07:39 +04:00
|
|
|
|
if (m->h == 0)
|
1999-06-20 05:20:14 +04:00
|
|
|
|
m->h = m->numopts + exithadd;
|
2003-06-04 23:07:39 +04:00
|
|
|
|
m->h = MIN(m->h, max_lines - m->y - hadd);
|
1998-06-25 13:58:57 +04:00
|
|
|
|
|
1999-06-20 05:20:14 +04:00
|
|
|
|
if (m->h < m->numopts + exithadd) {
|
1998-07-16 11:08:26 +04:00
|
|
|
|
if (!(m->mopt & MC_SCROLL) || m->h < 3) {
|
1998-06-25 13:58:57 +04:00
|
|
|
|
endwin();
|
2003-06-03 01:19:35 +04:00
|
|
|
|
(void)fprintf(stderr,
|
1999-06-19 10:38:49 +04:00
|
|
|
|
"Window too short for menu \"%s\"\n",
|
2003-06-10 21:19:04 +04:00
|
|
|
|
title);
|
1998-06-25 13:58:57 +04:00
|
|
|
|
exit(1);
|
|
|
|
|
}
|
2003-06-04 23:07:39 +04:00
|
|
|
|
hadd++;
|
|
|
|
|
m->h--;
|
1998-06-25 13:58:57 +04:00
|
|
|
|
} else
|
1998-07-16 11:08:26 +04:00
|
|
|
|
m->mopt &= ~MC_SCROLL;
|
2003-06-04 23:07:39 +04:00
|
|
|
|
#if 0
|
1998-06-29 12:46:37 +04:00
|
|
|
|
/* check for screen fit */
|
1999-06-20 05:20:14 +04:00
|
|
|
|
if (m->y + m->h + hadd > max_lines) {
|
1998-06-29 12:46:37 +04:00
|
|
|
|
endwin();
|
2003-06-03 01:19:35 +04:00
|
|
|
|
(void)fprintf(stderr,
|
2003-06-04 23:07:39 +04:00
|
|
|
|
"Screen too short (%d + %d + %d > %d) for menu \"%s\"\n",
|
2003-06-10 21:19:04 +04:00
|
|
|
|
m->y, m->h, hadd, max_lines, title);
|
1998-06-29 12:46:37 +04:00
|
|
|
|
exit(1);
|
|
|
|
|
|
|
|
|
|
}
|
2003-06-04 23:07:39 +04:00
|
|
|
|
#endif
|
1998-06-29 12:46:37 +04:00
|
|
|
|
|
1997-09-26 21:54:09 +04:00
|
|
|
|
/* Calculate w? */
|
|
|
|
|
if (m->w == 0) {
|
1998-07-16 11:08:26 +04:00
|
|
|
|
if (m->mopt & MC_SCROLL)
|
1999-06-20 05:20:14 +04:00
|
|
|
|
wmax = MAX(wmax,strlen(scrolltext));
|
2003-06-03 01:19:35 +04:00
|
|
|
|
for (i = 0; i < m->numopts; i++)
|
2003-06-10 21:19:04 +04:00
|
|
|
|
wmax = MAX(wmax, strlen(MSG_XLAT(m->opts[i].opt_name)) + 3);
|
1999-06-20 05:20:14 +04:00
|
|
|
|
m->w = wmax;
|
1997-09-26 21:54:09 +04:00
|
|
|
|
}
|
|
|
|
|
|
1999-06-19 10:38:49 +04:00
|
|
|
|
/* check and adjust for screen fit */
|
1999-06-20 05:20:14 +04:00
|
|
|
|
if (m->w + wadd > max_cols) {
|
1999-06-19 10:38:49 +04:00
|
|
|
|
endwin();
|
2003-06-03 01:19:35 +04:00
|
|
|
|
(void)fprintf(stderr,
|
2003-06-10 21:19:04 +04:00
|
|
|
|
"Screen too narrow for menu \"%s\"\n", title);
|
1999-06-19 10:38:49 +04:00
|
|
|
|
exit(1);
|
|
|
|
|
|
|
|
|
|
}
|
1999-06-20 09:41:45 +04:00
|
|
|
|
if (m->x == -1)
|
|
|
|
|
m->x = (max_cols - (m->w + wadd)) / 2; /* center */
|
|
|
|
|
else if (m->x + m->w + wadd > max_cols)
|
1999-06-20 05:20:14 +04:00
|
|
|
|
m->x = max_cols - (m->w + wadd);
|
1999-06-19 10:38:49 +04:00
|
|
|
|
|
1997-09-26 21:54:09 +04:00
|
|
|
|
/* Get the windows. */
|
2003-06-03 12:49:53 +04:00
|
|
|
|
m->mw = newwin(m->h + hadd, m->w + wadd, m->y, m->x);
|
1997-09-26 21:54:09 +04:00
|
|
|
|
|
|
|
|
|
if (m->mw == NULL) {
|
|
|
|
|
endwin();
|
2003-06-03 01:19:35 +04:00
|
|
|
|
(void)fprintf(stderr,
|
2003-06-28 02:06:14 +04:00
|
|
|
|
"Could not create window (%d + %d, %d + %d, %d, %d) for menu \"%s\"\n",
|
|
|
|
|
m->h, hadd, m->w, wadd, m->y, m->x, title);
|
1997-09-26 21:54:09 +04:00
|
|
|
|
exit(1);
|
2001-11-17 04:12:47 +03:00
|
|
|
|
}
|
2003-06-04 23:07:39 +04:00
|
|
|
|
keypad(m->mw, TRUE); /* enable multi-key assembling for win */
|
2001-11-17 04:12:47 +03:00
|
|
|
|
|
|
|
|
|
/* XXX is it even worth doing this right? */
|
|
|
|
|
if (has_colors()) {
|
|
|
|
|
wbkgd(m->mw, COLOR_PAIR(1));
|
|
|
|
|
wattrset(m->mw, COLOR_PAIR(1));
|
|
|
|
|
}
|
1997-09-26 21:54:09 +04:00
|
|
|
|
}
|
|
|
|
|
|
2000-08-15 05:01:41 +04:00
|
|
|
|
static char
|
2003-07-07 16:20:56 +04:00
|
|
|
|
opt_ch(menudesc *m, int op_no)
|
1998-07-16 11:08:26 +04:00
|
|
|
|
{
|
|
|
|
|
char c;
|
2003-07-07 16:20:56 +04:00
|
|
|
|
|
|
|
|
|
if (op_no == m->numopts)
|
|
|
|
|
return 'x';
|
|
|
|
|
|
1998-07-16 11:08:26 +04:00
|
|
|
|
if (op_no < 25) {
|
|
|
|
|
c = 'a' + op_no;
|
2003-06-03 01:19:35 +04:00
|
|
|
|
if (c >= 'x')
|
|
|
|
|
c++;
|
1998-07-16 11:08:26 +04:00
|
|
|
|
} else
|
|
|
|
|
c = 'A' + op_no - 25;
|
2003-06-03 01:19:35 +04:00
|
|
|
|
return c;
|
1998-07-16 11:08:26 +04:00
|
|
|
|
}
|
|
|
|
|
|
2000-08-15 05:01:41 +04:00
|
|
|
|
static void
|
2003-07-07 16:20:56 +04:00
|
|
|
|
draw_menu_line(menudesc *m, int opt, int cury, void *arg, const char *text)
|
2003-06-03 12:49:53 +04:00
|
|
|
|
{
|
|
|
|
|
int hasbox = m->mopt & MC_NOBOX ? 0 : 1;
|
|
|
|
|
|
2003-07-07 16:20:56 +04:00
|
|
|
|
if (m->cursel == opt) {
|
2003-06-03 12:49:53 +04:00
|
|
|
|
mvwaddstr(m->mw, cury, hasbox, ">");
|
|
|
|
|
wstandout(m->mw);
|
|
|
|
|
} else
|
|
|
|
|
mvwaddstr(m->mw, cury, hasbox, " ");
|
|
|
|
|
if (!(m->mopt & MC_NOSHORTCUT))
|
2003-07-07 16:20:56 +04:00
|
|
|
|
wprintw(m->mw, "%c: ", opt_ch(m, opt));
|
|
|
|
|
|
|
|
|
|
if (!text && m->draw_line)
|
|
|
|
|
m->draw_line(m, opt, arg);
|
|
|
|
|
else
|
|
|
|
|
waddstr(m->mw, MSG_XLAT(text));
|
|
|
|
|
if (m->cursel == opt)
|
2003-06-03 12:49:53 +04:00
|
|
|
|
wstandend(m->mw);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
2003-07-07 16:20:56 +04:00
|
|
|
|
draw_menu(menudesc *m, void *arg)
|
1997-09-26 21:54:09 +04:00
|
|
|
|
{
|
2003-06-04 23:07:39 +04:00
|
|
|
|
int opt;
|
2003-06-03 12:49:53 +04:00
|
|
|
|
int hasbox, cury, maxy;
|
1997-09-26 21:54:09 +04:00
|
|
|
|
int tadd;
|
|
|
|
|
|
1998-07-16 11:08:26 +04:00
|
|
|
|
if (m->mopt & MC_NOBOX) {
|
1997-09-26 21:54:09 +04:00
|
|
|
|
cury = 0;
|
1998-06-25 13:58:57 +04:00
|
|
|
|
maxy = m->h;
|
1997-09-26 21:54:09 +04:00
|
|
|
|
hasbox = 0;
|
|
|
|
|
} else {
|
|
|
|
|
cury = 1;
|
2003-06-03 01:19:35 +04:00
|
|
|
|
maxy = m->h + 1;
|
1997-09-26 21:54:09 +04:00
|
|
|
|
hasbox = 1;
|
|
|
|
|
}
|
|
|
|
|
|
1998-06-29 12:46:37 +04:00
|
|
|
|
/* Clear the window */
|
2003-06-03 01:19:35 +04:00
|
|
|
|
wclear(m->mw);
|
1998-06-29 12:46:37 +04:00
|
|
|
|
|
2003-06-10 21:19:04 +04:00
|
|
|
|
if (m->title) {
|
2003-06-03 12:49:53 +04:00
|
|
|
|
mvwaddstr(m->mw, hasbox, hasbox, " ");
|
2003-07-07 16:20:56 +04:00
|
|
|
|
waddstr(m->mw, MSG_XLAT(m->title));
|
2003-06-10 21:19:04 +04:00
|
|
|
|
tadd = 2;
|
2003-06-03 12:49:53 +04:00
|
|
|
|
cury += tadd;
|
|
|
|
|
maxy += tadd;
|
2003-06-10 21:19:04 +04:00
|
|
|
|
} else
|
|
|
|
|
tadd = 0;
|
1997-09-26 21:54:09 +04:00
|
|
|
|
|
2003-06-09 22:48:40 +04:00
|
|
|
|
if (m->cursel == -1) {
|
|
|
|
|
m->cursel = m->numopts;
|
|
|
|
|
if (m->h <= m->numopts)
|
|
|
|
|
m->topline = m->numopts + 1 - m->h;
|
|
|
|
|
}
|
|
|
|
|
|
2003-06-04 23:07:39 +04:00
|
|
|
|
for (opt = m->topline; opt < m->numopts; opt++) {
|
2003-06-03 12:49:53 +04:00
|
|
|
|
if (cury >= maxy)
|
|
|
|
|
break;
|
2003-07-07 16:20:56 +04:00
|
|
|
|
draw_menu_line(m, opt, cury++, arg, m->opts[opt].opt_name);
|
1997-09-26 21:54:09 +04:00
|
|
|
|
}
|
1998-06-25 13:58:57 +04:00
|
|
|
|
|
|
|
|
|
/* Add the exit option. */
|
2003-06-04 23:07:39 +04:00
|
|
|
|
if (!(m->mopt & MC_NOEXITOPT)) {
|
|
|
|
|
if (cury < maxy)
|
2003-07-07 16:20:56 +04:00
|
|
|
|
draw_menu_line(m, m->numopts, cury++, arg, m->exitstr);
|
2003-06-04 23:07:39 +04:00
|
|
|
|
else
|
|
|
|
|
opt = 0;
|
|
|
|
|
}
|
1998-06-25 13:58:57 +04:00
|
|
|
|
|
|
|
|
|
/* Add the scroll line */
|
2003-06-04 23:07:39 +04:00
|
|
|
|
if (opt != m->numopts || m->topline != 0)
|
2003-06-03 01:19:35 +04:00
|
|
|
|
mvwaddstr(m->mw, cury, hasbox, scrolltext);
|
1998-06-25 13:58:57 +04:00
|
|
|
|
|
|
|
|
|
/* Add the box. */
|
1998-07-16 11:08:26 +04:00
|
|
|
|
if (!(m->mopt & MC_NOBOX))
|
2001-11-17 04:12:47 +03:00
|
|
|
|
box(m->mw, 0, 0);
|
1997-09-26 21:54:09 +04:00
|
|
|
|
|
2003-06-03 12:49:53 +04:00
|
|
|
|
wmove(m->mw, tadd + hasbox + m->cursel - m->topline, hasbox);
|
|
|
|
|
wrefresh(m->mw);
|
1997-09-26 21:54:09 +04:00
|
|
|
|
}
|
|
|
|
|
|
2000-08-15 05:01:41 +04:00
|
|
|
|
static void
|
2003-01-10 23:00:50 +03:00
|
|
|
|
/*ARGSUSED*/
|
2003-06-09 22:48:40 +04:00
|
|
|
|
process_help(menudesc *m, int num)
|
1998-06-24 10:46:23 +04:00
|
|
|
|
{
|
2003-05-09 14:24:50 +04:00
|
|
|
|
const char *help = m->helpstr;
|
1998-06-25 13:58:57 +04:00
|
|
|
|
int lineoff = 0;
|
1998-06-24 10:46:23 +04:00
|
|
|
|
int curoff = 0;
|
|
|
|
|
int again;
|
1998-06-25 13:58:57 +04:00
|
|
|
|
int winin;
|
1998-06-24 10:46:23 +04:00
|
|
|
|
|
1998-06-24 18:44:52 +04:00
|
|
|
|
/* Is there help? */
|
|
|
|
|
if (!help) {
|
|
|
|
|
mbeep();
|
|
|
|
|
return;
|
|
|
|
|
}
|
2003-06-10 21:19:04 +04:00
|
|
|
|
help = MSG_XLAT(help);
|
1998-06-24 18:44:52 +04:00
|
|
|
|
|
|
|
|
|
/* Display the help information. */
|
1998-06-25 13:58:57 +04:00
|
|
|
|
do {
|
1998-06-24 10:46:23 +04:00
|
|
|
|
if (lineoff < curoff) {
|
2003-06-10 21:19:04 +04:00
|
|
|
|
help = MSG_XLAT(m->helpstr);
|
1998-06-24 10:46:23 +04:00
|
|
|
|
curoff = 0;
|
|
|
|
|
}
|
|
|
|
|
while (*help && curoff < lineoff) {
|
|
|
|
|
if (*help == '\n')
|
|
|
|
|
curoff++;
|
|
|
|
|
help++;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
wclear(stdscr);
|
2003-06-03 01:19:35 +04:00
|
|
|
|
mvwaddstr(stdscr, 0, 0,
|
1998-06-29 12:46:37 +04:00
|
|
|
|
"Help: exit: x, page up: u <, page down: d >");
|
2003-06-03 01:19:35 +04:00
|
|
|
|
mvwaddstr(stdscr, 2, 0, help);
|
|
|
|
|
wmove(stdscr, 1, 0);
|
2003-06-03 12:49:53 +04:00
|
|
|
|
wrefresh(stdscr);
|
1998-06-24 10:46:23 +04:00
|
|
|
|
|
|
|
|
|
do {
|
2002-04-04 18:11:23 +04:00
|
|
|
|
winin = wgetch(stdscr);
|
|
|
|
|
if (winin < KEY_MIN)
|
1998-06-29 12:46:37 +04:00
|
|
|
|
winin = tolower(winin);
|
1998-06-24 10:46:23 +04:00
|
|
|
|
again = 0;
|
|
|
|
|
switch (winin) {
|
|
|
|
|
case '<':
|
|
|
|
|
case 'u':
|
2002-04-04 18:11:23 +04:00
|
|
|
|
case KEY_UP:
|
|
|
|
|
case KEY_LEFT:
|
|
|
|
|
case KEY_PPAGE:
|
1998-06-24 10:46:23 +04:00
|
|
|
|
if (lineoff)
|
|
|
|
|
lineoff -= max_lines - 2;
|
1998-06-25 13:58:57 +04:00
|
|
|
|
else
|
|
|
|
|
again = 1;
|
1998-06-24 10:46:23 +04:00
|
|
|
|
break;
|
|
|
|
|
case '>':
|
|
|
|
|
case 'd':
|
2002-04-04 18:11:23 +04:00
|
|
|
|
case KEY_DOWN:
|
|
|
|
|
case KEY_RIGHT:
|
|
|
|
|
case KEY_NPAGE:
|
1998-06-24 10:46:23 +04:00
|
|
|
|
if (*help)
|
|
|
|
|
lineoff += max_lines - 2;
|
1998-06-25 13:58:57 +04:00
|
|
|
|
else
|
|
|
|
|
again = 1;
|
1998-06-24 10:46:23 +04:00
|
|
|
|
break;
|
|
|
|
|
case 'q':
|
|
|
|
|
break;
|
1998-06-30 10:57:57 +04:00
|
|
|
|
case 'x':
|
|
|
|
|
winin = 'q';
|
|
|
|
|
break;
|
1998-06-24 10:46:23 +04:00
|
|
|
|
default:
|
|
|
|
|
again = 1;
|
|
|
|
|
}
|
1998-06-29 12:46:37 +04:00
|
|
|
|
if (again)
|
|
|
|
|
mbeep();
|
1998-06-24 10:46:23 +04:00
|
|
|
|
} while (again);
|
|
|
|
|
} while (winin != 'q');
|
|
|
|
|
}
|
|
|
|
|
|
2000-08-15 05:01:41 +04:00
|
|
|
|
static void
|
2003-06-09 22:48:40 +04:00
|
|
|
|
process_req(menudesc *m, void *arg, int num, int req)
|
1997-09-26 21:54:09 +04:00
|
|
|
|
{
|
|
|
|
|
int ch;
|
2003-06-03 01:19:35 +04:00
|
|
|
|
int hasexit = (m->mopt & MC_NOEXITOPT ? 0 : 1);
|
1997-09-26 21:54:09 +04:00
|
|
|
|
|
2003-06-03 01:19:35 +04:00
|
|
|
|
switch(req) {
|
|
|
|
|
|
|
|
|
|
case REQ_EXECUTE:
|
1997-09-26 21:54:09 +04:00
|
|
|
|
return;
|
1998-06-25 13:58:57 +04:00
|
|
|
|
|
2003-06-03 01:19:35 +04:00
|
|
|
|
case REQ_NEXT_ITEM:
|
2003-06-17 00:57:43 +04:00
|
|
|
|
ch = m->cursel;
|
|
|
|
|
for (;;) {
|
|
|
|
|
ch++;
|
|
|
|
|
if (ch >= m->numopts + hasexit) {
|
|
|
|
|
mbeep();
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
if (hasexit && ch == m->numopts)
|
|
|
|
|
break;
|
2003-07-07 16:20:56 +04:00
|
|
|
|
if (!(m->opts[ch].opt_flags & OPT_IGNORE))
|
2003-06-17 00:57:43 +04:00
|
|
|
|
break;
|
2003-06-03 01:19:35 +04:00
|
|
|
|
}
|
2003-06-17 00:57:43 +04:00
|
|
|
|
m->cursel = ch;
|
2003-06-03 12:49:53 +04:00
|
|
|
|
if (m->mopt & MC_SCROLL && m->cursel >= m->topline + m->h)
|
2003-06-17 00:57:43 +04:00
|
|
|
|
m->topline = m->cursel - m->h + 1;
|
2003-06-03 01:19:35 +04:00
|
|
|
|
break;
|
1998-06-25 13:58:57 +04:00
|
|
|
|
|
2003-06-03 01:19:35 +04:00
|
|
|
|
case REQ_PREV_ITEM:
|
2003-06-17 00:57:43 +04:00
|
|
|
|
ch = m->cursel;
|
|
|
|
|
for (;;) {
|
|
|
|
|
if (ch <= 0) {
|
|
|
|
|
mbeep();
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
ch--;
|
2003-07-07 16:20:56 +04:00
|
|
|
|
if (!(m->opts[ch].opt_flags & OPT_IGNORE))
|
2003-06-17 00:57:43 +04:00
|
|
|
|
break;
|
2003-06-03 01:19:35 +04:00
|
|
|
|
}
|
2003-06-17 00:57:43 +04:00
|
|
|
|
m->cursel = ch;
|
2003-06-03 01:19:35 +04:00
|
|
|
|
if (m->cursel < m->topline)
|
2003-06-17 00:57:43 +04:00
|
|
|
|
m->topline = m->cursel;
|
2003-06-03 01:19:35 +04:00
|
|
|
|
break;
|
1997-11-14 19:31:45 +03:00
|
|
|
|
|
2003-06-09 22:48:40 +04:00
|
|
|
|
case REQ_HELP:
|
|
|
|
|
process_help(m, num);
|
|
|
|
|
/* FALLTHROUGH */
|
|
|
|
|
|
2003-06-03 01:19:35 +04:00
|
|
|
|
case REQ_REDISPLAY:
|
1997-11-14 19:31:45 +03:00
|
|
|
|
wclear(stdscr);
|
|
|
|
|
wrefresh(stdscr);
|
1998-07-16 11:08:26 +04:00
|
|
|
|
if (m->post_act)
|
2003-06-09 22:48:40 +04:00
|
|
|
|
(*m->post_act)(m, arg);
|
2003-06-03 01:19:35 +04:00
|
|
|
|
break;
|
1998-06-25 13:58:57 +04:00
|
|
|
|
|
2003-06-03 01:19:35 +04:00
|
|
|
|
case REQ_SCROLLUP:
|
|
|
|
|
if (m->cursel == 0) {
|
1998-06-25 13:58:57 +04:00
|
|
|
|
mbeep();
|
2003-06-03 01:19:35 +04:00
|
|
|
|
return;
|
1998-06-25 13:58:57 +04:00
|
|
|
|
}
|
2003-06-03 12:49:53 +04:00
|
|
|
|
m->topline = MAX(0, m->topline - m->h);
|
|
|
|
|
m->cursel = MAX(0, m->cursel - m->h);
|
2003-06-03 01:19:35 +04:00
|
|
|
|
wclear(m->mw);
|
|
|
|
|
break;
|
1998-06-25 13:58:57 +04:00
|
|
|
|
|
2003-06-03 01:19:35 +04:00
|
|
|
|
case REQ_SCROLLDOWN:
|
|
|
|
|
if (m->cursel >= m->numopts + hasexit - 1) {
|
1998-06-25 13:58:57 +04:00
|
|
|
|
mbeep();
|
2003-06-03 01:19:35 +04:00
|
|
|
|
return;
|
1998-06-25 13:58:57 +04:00
|
|
|
|
}
|
2003-06-03 12:49:53 +04:00
|
|
|
|
m->topline = MIN(m->topline + m->h,
|
2003-06-04 23:07:39 +04:00
|
|
|
|
MAX(m->numopts + hasexit - m->h, 0));
|
2003-06-03 12:49:53 +04:00
|
|
|
|
m->cursel = MIN(m->numopts + hasexit - 1, m->cursel + m->h);
|
2003-06-03 01:19:35 +04:00
|
|
|
|
wclear(m->mw);
|
|
|
|
|
break;
|
1998-06-25 13:58:57 +04:00
|
|
|
|
|
2003-06-03 01:19:35 +04:00
|
|
|
|
default:
|
1998-06-29 12:46:37 +04:00
|
|
|
|
ch = req;
|
1998-06-25 13:58:57 +04:00
|
|
|
|
if (ch == 'x' && hasexit) {
|
1997-09-26 21:54:09 +04:00
|
|
|
|
m->cursel = m->numopts;
|
2003-06-03 01:19:35 +04:00
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
if (m->mopt & MC_NOSHORTCUT) {
|
|
|
|
|
mbeep();
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
if (ch > 'z')
|
|
|
|
|
ch = 255;
|
|
|
|
|
if (ch >= 'a') {
|
|
|
|
|
if (ch > 'x')
|
|
|
|
|
ch--;
|
|
|
|
|
ch = ch - 'a';
|
|
|
|
|
} else
|
|
|
|
|
ch = 25 + ch - 'A';
|
|
|
|
|
if (ch < 0 || ch >= m->numopts) {
|
|
|
|
|
mbeep();
|
|
|
|
|
return;
|
|
|
|
|
}
|
2003-07-07 16:20:56 +04:00
|
|
|
|
if (m->opts[ch].opt_flags & OPT_IGNORE) {
|
2003-06-17 00:57:43 +04:00
|
|
|
|
mbeep();
|
|
|
|
|
return;
|
|
|
|
|
}
|
2003-06-03 01:19:35 +04:00
|
|
|
|
m->cursel = ch;
|
1997-09-26 21:54:09 +04:00
|
|
|
|
}
|
1998-06-29 12:46:37 +04:00
|
|
|
|
|
2003-06-03 12:49:53 +04:00
|
|
|
|
while (m->cursel >= m->topline + m->h)
|
|
|
|
|
m->topline = MIN(m->topline + m->h,
|
|
|
|
|
m->numopts + hasexit - m->h);
|
|
|
|
|
while (m->cursel < m->topline)
|
|
|
|
|
m->topline = MAX(0, m->topline - m->h);
|
1998-06-29 12:46:37 +04:00
|
|
|
|
|
2003-07-07 16:20:56 +04:00
|
|
|
|
draw_menu(m, arg);
|
1997-09-26 21:54:09 +04:00
|
|
|
|
}
|
|
|
|
|
|
2000-08-15 05:01:41 +04:00
|
|
|
|
int
|
2003-06-03 01:19:35 +04:00
|
|
|
|
menu_init(void)
|
1999-06-19 10:38:49 +04:00
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
if (__menu_init)
|
|
|
|
|
return 0;
|
|
|
|
|
|
2003-05-08 20:20:56 +04:00
|
|
|
|
#ifdef USER_MENU_INIT
|
|
|
|
|
if (USER_MENU_INIT)
|
|
|
|
|
return 1;
|
|
|
|
|
#endif
|
|
|
|
|
|
1999-06-19 10:38:49 +04:00
|
|
|
|
if (initscr() == NULL)
|
|
|
|
|
return 1;
|
|
|
|
|
|
|
|
|
|
cbreak();
|
|
|
|
|
noecho();
|
2001-11-17 04:12:47 +03:00
|
|
|
|
|
|
|
|
|
/* XXX Should be configurable but it almost isn't worth it. */
|
|
|
|
|
if (has_colors()) {
|
|
|
|
|
start_color();
|
|
|
|
|
init_pair(1, COLOR_WHITE, COLOR_BLUE);
|
|
|
|
|
bkgd(COLOR_PAIR(1));
|
|
|
|
|
attrset(COLOR_PAIR(1));
|
|
|
|
|
}
|
|
|
|
|
|
1999-06-19 10:38:49 +04:00
|
|
|
|
max_lines = getmaxy(stdscr);
|
|
|
|
|
max_cols = getmaxx(stdscr);
|
2002-04-04 18:11:23 +04:00
|
|
|
|
keypad(stdscr, TRUE);
|
1999-06-19 10:38:49 +04:00
|
|
|
|
#ifdef DYNAMIC_MENUS
|
|
|
|
|
num_menus = DYN_INIT_NUM;
|
|
|
|
|
while (num_menus < DYN_MENU_START)
|
|
|
|
|
num_menus *= 2;
|
2003-06-03 01:19:35 +04:00
|
|
|
|
menus = malloc(sizeof(menudesc) * num_menus);
|
1999-06-19 10:38:49 +04:00
|
|
|
|
if (menus == NULL)
|
|
|
|
|
return 2;
|
2003-06-03 01:19:35 +04:00
|
|
|
|
(void)memset(menus, 0, sizeof(menudesc) * num_menus);
|
2003-06-03 12:49:53 +04:00
|
|
|
|
(void)memcpy(menus, menu_def, sizeof(menudesc) * DYN_MENU_START);
|
1999-06-19 10:38:49 +04:00
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
__menu_init = 1;
|
2003-06-03 12:49:53 +04:00
|
|
|
|
return 0;
|
1999-06-19 10:38:49 +04:00
|
|
|
|
}
|
|
|
|
|
|
2000-08-15 05:01:41 +04:00
|
|
|
|
void
|
2003-06-03 15:51:56 +04:00
|
|
|
|
process_menu(int num, void *arg)
|
1997-09-26 21:54:09 +04:00
|
|
|
|
{
|
|
|
|
|
int sel = 0;
|
|
|
|
|
int req, done;
|
|
|
|
|
int last_num;
|
2003-06-03 15:51:56 +04:00
|
|
|
|
menu_ent *opt;
|
1997-09-26 21:54:09 +04:00
|
|
|
|
|
2003-06-09 22:48:40 +04:00
|
|
|
|
menudesc *m;
|
1998-07-16 11:08:26 +04:00
|
|
|
|
|
|
|
|
|
m = &menus[num];
|
1997-09-26 21:54:09 +04:00
|
|
|
|
|
|
|
|
|
done = FALSE;
|
|
|
|
|
|
|
|
|
|
/* Initialize? */
|
1999-06-19 10:38:49 +04:00
|
|
|
|
if (menu_init()) {
|
|
|
|
|
__menu_initerror();
|
|
|
|
|
return;
|
1997-09-26 21:54:09 +04:00
|
|
|
|
}
|
1999-06-19 10:38:49 +04:00
|
|
|
|
|
1997-09-26 21:54:09 +04:00
|
|
|
|
if (__m_endwin) {
|
1998-06-25 13:58:57 +04:00
|
|
|
|
wclear(stdscr);
|
1997-09-26 21:54:09 +04:00
|
|
|
|
wrefresh(stdscr);
|
|
|
|
|
__m_endwin = 0;
|
|
|
|
|
}
|
|
|
|
|
if (m->mw == NULL)
|
2003-06-03 12:49:53 +04:00
|
|
|
|
init_menu(m);
|
1997-09-26 21:54:09 +04:00
|
|
|
|
|
2003-06-09 22:48:40 +04:00
|
|
|
|
/* Default to select option 0 and display from 0 */
|
1998-06-25 13:58:57 +04:00
|
|
|
|
m->topline = 0;
|
2003-06-09 22:48:40 +04:00
|
|
|
|
if ((m->mopt & (MC_DFLTEXIT | MC_NOEXITOPT)) == MC_DFLTEXIT)
|
|
|
|
|
m->cursel = -1;
|
|
|
|
|
else
|
|
|
|
|
m->cursel = 0;
|
1997-09-26 21:54:09 +04:00
|
|
|
|
|
|
|
|
|
while (!done) {
|
|
|
|
|
last_num = num;
|
|
|
|
|
if (__m_endwin) {
|
|
|
|
|
wclear(stdscr);
|
|
|
|
|
wrefresh(stdscr);
|
|
|
|
|
__m_endwin = 0;
|
|
|
|
|
}
|
|
|
|
|
/* Process the display action */
|
1998-07-16 11:08:26 +04:00
|
|
|
|
if (m->post_act)
|
2003-06-09 22:48:40 +04:00
|
|
|
|
(*m->post_act)(m, arg);
|
2003-07-07 16:20:56 +04:00
|
|
|
|
draw_menu(m, arg);
|
1997-09-26 21:54:09 +04:00
|
|
|
|
|
2003-06-03 12:49:53 +04:00
|
|
|
|
while ((req = menucmd(m->mw)) != REQ_EXECUTE)
|
2003-06-09 22:48:40 +04:00
|
|
|
|
process_req(m, arg, num, req);
|
1997-09-26 21:54:09 +04:00
|
|
|
|
|
|
|
|
|
sel = m->cursel;
|
2003-06-04 23:07:39 +04:00
|
|
|
|
if (!(m->mopt & MC_NOCLEAR)) {
|
|
|
|
|
wclear(m->mw);
|
|
|
|
|
wrefresh(m->mw);
|
|
|
|
|
}
|
1997-09-26 21:54:09 +04:00
|
|
|
|
|
|
|
|
|
/* Process the items */
|
1998-07-16 11:08:26 +04:00
|
|
|
|
if (sel < m->numopts) {
|
2003-06-03 15:51:56 +04:00
|
|
|
|
opt = &m->opts[sel];
|
2003-07-07 16:20:56 +04:00
|
|
|
|
if (opt->opt_flags & OPT_IGNORE)
|
|
|
|
|
continue;
|
2003-06-03 15:51:56 +04:00
|
|
|
|
if (opt->opt_flags & OPT_ENDWIN) {
|
1998-07-16 11:08:26 +04:00
|
|
|
|
endwin();
|
|
|
|
|
__m_endwin = 1;
|
|
|
|
|
}
|
2003-06-03 15:51:56 +04:00
|
|
|
|
if (opt->opt_action)
|
|
|
|
|
done = (*opt->opt_action)(m, opt, arg);
|
|
|
|
|
if (opt->opt_menu != -1) {
|
|
|
|
|
if (opt->opt_flags & OPT_SUB)
|
|
|
|
|
process_menu(opt->opt_menu, arg);
|
1998-07-16 11:08:26 +04:00
|
|
|
|
else
|
2003-06-03 15:51:56 +04:00
|
|
|
|
num = opt->opt_menu;
|
1998-07-16 11:08:26 +04:00
|
|
|
|
}
|
1998-07-23 21:56:00 +04:00
|
|
|
|
|
2003-06-03 15:51:56 +04:00
|
|
|
|
if (opt->opt_flags & OPT_EXIT)
|
1998-07-23 21:56:00 +04:00
|
|
|
|
done = TRUE;
|
|
|
|
|
|
1998-07-16 11:08:26 +04:00
|
|
|
|
} else
|
1997-09-26 21:54:09 +04:00
|
|
|
|
done = TRUE;
|
|
|
|
|
|
|
|
|
|
/* Reselect m just in case */
|
|
|
|
|
if (num != last_num) {
|
|
|
|
|
m = &menus[num];
|
1998-07-16 11:08:26 +04:00
|
|
|
|
|
1997-09-26 21:54:09 +04:00
|
|
|
|
/* Initialize? */
|
|
|
|
|
if (m->mw == NULL)
|
2003-06-03 12:49:53 +04:00
|
|
|
|
init_menu(m);
|
1998-07-16 11:08:26 +04:00
|
|
|
|
if (m->post_act)
|
2003-06-09 22:48:40 +04:00
|
|
|
|
(*m->post_act)(m,arg);
|
1997-09-26 21:54:09 +04:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2003-06-04 23:07:39 +04:00
|
|
|
|
if (m->mopt & MC_NOCLEAR) {
|
|
|
|
|
wclear(m->mw);
|
|
|
|
|
wrefresh(m->mw);
|
|
|
|
|
}
|
|
|
|
|
|
1997-09-26 21:54:09 +04:00
|
|
|
|
/* Process the exit action */
|
1998-07-16 11:08:26 +04:00
|
|
|
|
if (m->exit_act)
|
2003-06-09 22:48:40 +04:00
|
|
|
|
(*m->exit_act)(m, arg);
|
1997-09-26 21:54:09 +04:00
|
|
|
|
}
|
1998-06-25 13:58:57 +04:00
|
|
|
|
|
1998-07-03 19:20:30 +04:00
|
|
|
|
/* Control L is end of standard routines, remaining only for dynamic. */
|
|
|
|
|
|
|
|
|
|
/* Beginning of routines for dynamic menus. */
|
|
|
|
|
|
2000-08-15 06:09:11 +04:00
|
|
|
|
static int
|
2003-06-03 01:19:35 +04:00
|
|
|
|
double_menus(void)
|
1998-07-16 11:08:26 +04:00
|
|
|
|
{
|
|
|
|
|
menudesc *temp;
|
2003-06-09 22:48:40 +04:00
|
|
|
|
int sz = sizeof(menudesc) * num_menus;
|
1998-07-16 11:08:26 +04:00
|
|
|
|
|
2003-06-09 22:48:40 +04:00
|
|
|
|
temp = realloc(menus, sz * 2);
|
1998-07-16 11:08:26 +04:00
|
|
|
|
if (temp == NULL)
|
|
|
|
|
return 0;
|
2003-06-09 22:48:40 +04:00
|
|
|
|
(void)memset(temp + num_menus, 0, sz);
|
1998-07-16 11:08:26 +04:00
|
|
|
|
menus = temp;
|
|
|
|
|
num_menus *= 2;
|
|
|
|
|
|
|
|
|
|
return 1;
|
|
|
|
|
}
|
1998-07-03 19:20:30 +04:00
|
|
|
|
|
2000-08-15 05:01:41 +04:00
|
|
|
|
int
|
2003-06-04 23:07:39 +04:00
|
|
|
|
new_menu(const char *title, menu_ent *opts, int numopts,
|
2000-08-15 06:09:11 +04:00
|
|
|
|
int x, int y, int h, int w, int mopt,
|
2003-06-09 22:48:40 +04:00
|
|
|
|
void (*post_act)(menudesc *, void *),
|
2003-07-07 16:20:56 +04:00
|
|
|
|
void (*draw_line)(menudesc *, int, void *),
|
2003-06-09 22:48:40 +04:00
|
|
|
|
void (*exit_act)(menudesc *, void *),
|
2003-06-04 23:07:39 +04:00
|
|
|
|
const char * help, const char *exit)
|
1998-07-16 11:08:26 +04:00
|
|
|
|
{
|
|
|
|
|
int ix;
|
2003-06-09 22:48:40 +04:00
|
|
|
|
menudesc *m;
|
1998-07-16 11:08:26 +04:00
|
|
|
|
|
|
|
|
|
/* Find free menu entry. */
|
2003-06-09 22:48:40 +04:00
|
|
|
|
for (ix = DYN_MENU_START; ; ix++) {
|
|
|
|
|
if (ix > num_menus && !double_menus())
|
|
|
|
|
return -1;
|
|
|
|
|
if (!(menus[ix].mopt & MC_VALID))
|
|
|
|
|
break;
|
|
|
|
|
}
|
1998-07-16 11:08:26 +04:00
|
|
|
|
|
|
|
|
|
/* Set Entries */
|
2003-06-09 22:48:40 +04:00
|
|
|
|
m = menus + ix;
|
2003-06-10 21:19:04 +04:00
|
|
|
|
m->title = title;
|
2003-06-09 22:48:40 +04:00
|
|
|
|
m->opts = opts;
|
|
|
|
|
m->numopts = numopts;
|
|
|
|
|
m->x = x;
|
|
|
|
|
m->y = y;
|
|
|
|
|
m->h = h;
|
|
|
|
|
m->w = w;
|
|
|
|
|
m->mopt = mopt | MC_VALID;
|
|
|
|
|
m->post_act = post_act;
|
2003-07-07 16:20:56 +04:00
|
|
|
|
m->draw_line = draw_line;
|
2003-06-09 22:48:40 +04:00
|
|
|
|
m->exit_act = exit_act;
|
|
|
|
|
m->helpstr = help;
|
|
|
|
|
m->exitstr = exit ? exit : "Exit";
|
|
|
|
|
|
|
|
|
|
init_menu(m);
|
1998-07-16 11:08:26 +04:00
|
|
|
|
|
|
|
|
|
return ix;
|
|
|
|
|
}
|
|
|
|
|
|
2000-08-15 05:01:41 +04:00
|
|
|
|
void
|
2003-06-03 01:19:35 +04:00
|
|
|
|
free_menu(int menu_no)
|
1998-07-16 11:08:26 +04:00
|
|
|
|
{
|
2003-06-09 22:48:40 +04:00
|
|
|
|
menudesc *m;
|
|
|
|
|
|
|
|
|
|
if (menu_no < 0 || menu_no >= num_menus)
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
m = menus + menu_no;
|
|
|
|
|
if ((m->mopt & MC_VALID))
|
|
|
|
|
return;
|
|
|
|
|
if (m->mw != NULL)
|
|
|
|
|
delwin(m->mw);
|
|
|
|
|
memset(m, 0, sizeof *m);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
|
set_menu_numopts(int menu, int numopts)
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
menus[menu].numopts = numopts;
|
1998-07-16 11:08:26 +04:00
|
|
|
|
}
|