Whitespace and other layout stuff.
Change an elsif sequence to switch()
This commit is contained in:
parent
eac03aee15
commit
99778eca69
@ -1,4 +1,4 @@
|
||||
/* $NetBSD: menu_sys.def,v 1.34 2003/05/09 10:24:50 dsl Exp $ */
|
||||
/* $NetBSD: menu_sys.def,v 1.35 2003/06/02 21:19:35 dsl Exp $ */
|
||||
|
||||
/*
|
||||
* Copyright 1997 Piermont Information Systems Inc.
|
||||
@ -83,7 +83,7 @@ static int menucmd (WINDOW *w);
|
||||
#define mbeep() (void)fputc('\a', stderr)
|
||||
|
||||
static int
|
||||
menucmd (WINDOW *w)
|
||||
menucmd(WINDOW *w)
|
||||
{
|
||||
int ch;
|
||||
|
||||
@ -131,7 +131,7 @@ menucmd (WINDOW *w)
|
||||
}
|
||||
|
||||
static void
|
||||
init_menu (struct menudesc *m)
|
||||
init_menu(struct menudesc *m)
|
||||
{
|
||||
int wmax;
|
||||
int hadd, wadd, exithadd;
|
||||
@ -156,7 +156,7 @@ init_menu (struct menudesc *m)
|
||||
if (m->h < m->numopts + exithadd) {
|
||||
if (!(m->mopt & MC_SCROLL) || m->h < 3) {
|
||||
endwin();
|
||||
(void) fprintf (stderr,
|
||||
(void)fprintf(stderr,
|
||||
"Window too short for menu \"%s\"\n",
|
||||
m->title);
|
||||
exit(1);
|
||||
@ -167,7 +167,7 @@ init_menu (struct menudesc *m)
|
||||
/* check for screen fit */
|
||||
if (m->y + m->h + hadd > max_lines) {
|
||||
endwin();
|
||||
(void) fprintf (stderr,
|
||||
(void)fprintf(stderr,
|
||||
"Screen too short for menu \"%s\"\n", m->title);
|
||||
exit(1);
|
||||
|
||||
@ -177,15 +177,15 @@ init_menu (struct menudesc *m)
|
||||
if (m->w == 0) {
|
||||
if (m->mopt & MC_SCROLL)
|
||||
wmax = MAX(wmax,strlen(scrolltext));
|
||||
for (i=0; i < m->numopts; i++ )
|
||||
wmax = MAX(wmax,strlen(m->opts[i].opt_name)+3);
|
||||
for (i = 0; i < m->numopts; i++)
|
||||
wmax = MAX(wmax, strlen(m->opts[i].opt_name) + 3);
|
||||
m->w = wmax;
|
||||
}
|
||||
|
||||
/* check and adjust for screen fit */
|
||||
if (m->w + wadd > max_cols) {
|
||||
endwin();
|
||||
(void) fprintf (stderr,
|
||||
(void)fprintf(stderr,
|
||||
"Screen too narrow for menu \"%s\"\n", m->title);
|
||||
exit(1);
|
||||
|
||||
@ -201,7 +201,7 @@ init_menu (struct menudesc *m)
|
||||
|
||||
if (m->mw == NULL) {
|
||||
endwin();
|
||||
(void) fprintf (stderr,
|
||||
(void)fprintf(stderr,
|
||||
"Could not create window for menu \"%s\"\n", m->title);
|
||||
exit(1);
|
||||
}
|
||||
@ -214,19 +214,20 @@ init_menu (struct menudesc *m)
|
||||
}
|
||||
|
||||
static char
|
||||
opt_ch (int op_no)
|
||||
opt_ch(int op_no)
|
||||
{
|
||||
char c;
|
||||
if (op_no < 25) {
|
||||
c = 'a' + op_no;
|
||||
if (c >= 'x') c++;
|
||||
if (c >= 'x')
|
||||
c++;
|
||||
} else
|
||||
c = 'A' + op_no - 25;
|
||||
return (char) c;
|
||||
return c;
|
||||
}
|
||||
|
||||
static void
|
||||
post_menu (struct menudesc *m)
|
||||
post_menu(struct menudesc *m)
|
||||
{
|
||||
int i;
|
||||
int hasbox, cury, maxy, selrow, lastopt;
|
||||
@ -239,12 +240,12 @@ post_menu (struct menudesc *m)
|
||||
hasbox = 0;
|
||||
} else {
|
||||
cury = 1;
|
||||
maxy = m->h+1;
|
||||
maxy = m->h + 1;
|
||||
hasbox = 1;
|
||||
}
|
||||
|
||||
/* Clear the window */
|
||||
wclear (m->mw);
|
||||
wclear(m->mw);
|
||||
|
||||
tadd = strlen(m->title) ? 2 : 0;
|
||||
|
||||
@ -263,18 +264,18 @@ post_menu (struct menudesc *m)
|
||||
} else
|
||||
lastopt = m->numopts;
|
||||
|
||||
for (i=m->topline; i<lastopt; i++, cury++) {
|
||||
for (i = m->topline; i < lastopt; i++, cury++) {
|
||||
if (m->cursel == i) {
|
||||
mvwaddstr (m->mw, cury, hasbox, ">");
|
||||
mvwaddstr(m->mw, cury, hasbox, ">");
|
||||
wstandout(m->mw);
|
||||
selrow = cury;
|
||||
} else
|
||||
mvwaddstr (m->mw, cury, hasbox, " ");
|
||||
mvwaddstr(m->mw, cury, hasbox, " ");
|
||||
if (!(m->mopt & MC_NOSHORTCUT)) {
|
||||
(void) sprintf (optstr, "%c: ", opt_ch(i));
|
||||
waddstr (m->mw, optstr);
|
||||
(void)sprintf (optstr, "%c: ", opt_ch(i));
|
||||
waddstr(m->mw, optstr);
|
||||
}
|
||||
waddstr (m->mw, m->opts[i].opt_name);
|
||||
waddstr(m->mw, m->opts[i].opt_name);
|
||||
if (m->cursel == i)
|
||||
wstandend(m->mw);
|
||||
}
|
||||
@ -282,14 +283,14 @@ post_menu (struct menudesc *m)
|
||||
/* Add the exit option. */
|
||||
if (!(m->mopt & MC_NOEXITOPT) && cury < maxy) {
|
||||
if (m->cursel >= m->numopts) {
|
||||
mvwaddstr (m->mw, cury, hasbox, ">");
|
||||
mvwaddstr(m->mw, cury, hasbox, ">");
|
||||
wstandout(m->mw);
|
||||
selrow = cury;
|
||||
} else
|
||||
mvwaddstr (m->mw, cury, hasbox, " ");
|
||||
mvwaddstr(m->mw, cury, hasbox, " ");
|
||||
if (!(m->mopt & MC_NOSHORTCUT))
|
||||
waddstr (m->mw, "x: ");
|
||||
waddstr (m->mw, m->exitstr);
|
||||
waddstr(m->mw, m->exitstr);
|
||||
if (m->cursel >= m->numopts)
|
||||
wstandend(m->mw);
|
||||
cury++;
|
||||
@ -297,7 +298,7 @@ post_menu (struct menudesc *m)
|
||||
|
||||
/* Add the scroll line */
|
||||
if (m->mopt & MC_SCROLL) {
|
||||
mvwaddstr (m->mw, cury, hasbox, scrolltext);
|
||||
mvwaddstr(m->mw, cury, hasbox, scrolltext);
|
||||
if (selrow < 0)
|
||||
selrow = cury;
|
||||
}
|
||||
@ -311,7 +312,7 @@ post_menu (struct menudesc *m)
|
||||
|
||||
static void
|
||||
/*ARGSUSED*/
|
||||
process_help (struct menudesc *m, int num)
|
||||
process_help(struct menudesc *m, int num)
|
||||
{
|
||||
const char *help = m->helpstr;
|
||||
int lineoff = 0;
|
||||
@ -338,10 +339,10 @@ process_help (struct menudesc *m, int num)
|
||||
}
|
||||
|
||||
wclear(stdscr);
|
||||
mvwaddstr (stdscr, 0, 0,
|
||||
mvwaddstr(stdscr, 0, 0,
|
||||
"Help: exit: x, page up: u <, page down: d >");
|
||||
mvwaddstr (stdscr, 2, 0, help);
|
||||
wmove (stdscr, 1, 0);
|
||||
mvwaddstr(stdscr, 2, 0, help);
|
||||
wmove(stdscr, 1, 0);
|
||||
wrefresh(stdscr);
|
||||
|
||||
do {
|
||||
@ -391,116 +392,132 @@ process_help (struct menudesc *m, int num)
|
||||
}
|
||||
|
||||
static void
|
||||
process_req (struct menudesc *m, int num, int req)
|
||||
process_req(struct menudesc *m, int num, int req)
|
||||
{
|
||||
int ch;
|
||||
int hasexit = (m->mopt & MC_NOEXITOPT ? 0 : 1 );
|
||||
int hasexit = (m->mopt & MC_NOEXITOPT ? 0 : 1);
|
||||
int refr = 0;
|
||||
int scroll_sel = 0;
|
||||
|
||||
if (req == REQ_EXECUTE)
|
||||
switch(req) {
|
||||
|
||||
case REQ_EXECUTE:
|
||||
return;
|
||||
|
||||
else if (req == REQ_NEXT_ITEM) {
|
||||
if (m->cursel < m->numopts + hasexit - 1) {
|
||||
m->cursel++;
|
||||
scroll_sel = 1;
|
||||
refr = 1;
|
||||
if (m->mopt & MC_SCROLL &&
|
||||
m->cursel >= m->topline + m->h -1 )
|
||||
m->topline += 1;
|
||||
} else
|
||||
case REQ_NEXT_ITEM:
|
||||
if (m->cursel >= m->numopts + hasexit - 1) {
|
||||
mbeep();
|
||||
return;
|
||||
}
|
||||
m->cursel++;
|
||||
scroll_sel = 1;
|
||||
refr = 1;
|
||||
if (m->mopt & MC_SCROLL && m->cursel >= m->topline + m->h - 1)
|
||||
m->topline += 1;
|
||||
break;
|
||||
|
||||
} else if (req == REQ_PREV_ITEM) {
|
||||
if (m->cursel > 0) {
|
||||
m->cursel--;
|
||||
scroll_sel = 1;
|
||||
refr = 1;
|
||||
if (m->cursel < m->topline )
|
||||
m->topline -= 1;
|
||||
} else
|
||||
case REQ_PREV_ITEM:
|
||||
if (m->cursel <= 0) {
|
||||
mbeep();
|
||||
return;
|
||||
}
|
||||
m->cursel--;
|
||||
scroll_sel = 1;
|
||||
refr = 1;
|
||||
if (m->cursel < m->topline)
|
||||
m->topline -= 1;
|
||||
break;
|
||||
|
||||
} else if (req == REQ_REDISPLAY) {
|
||||
case REQ_REDISPLAY:
|
||||
wclear(stdscr);
|
||||
wrefresh(stdscr);
|
||||
if (m->post_act)
|
||||
(*m->post_act)();
|
||||
refr = 1;
|
||||
break;
|
||||
|
||||
} else if (req == REQ_HELP) {
|
||||
process_help (m, num);
|
||||
case REQ_HELP:
|
||||
process_help(m, num);
|
||||
refr = 1;
|
||||
break;
|
||||
|
||||
} else if (req == REQ_SCROLLUP) {
|
||||
if (!(m->mopt & MC_SCROLL))
|
||||
case REQ_SCROLLUP:
|
||||
if (!(m->mopt & MC_SCROLL)) {
|
||||
mbeep();
|
||||
else if (m->cursel == 0)
|
||||
mbeep();
|
||||
else {
|
||||
m->topline = MAX(0, m->topline - m->h + 1);
|
||||
m->cursel = MAX(0, m->cursel - m->h + 1);
|
||||
wclear(m->mw);
|
||||
refr = 1;
|
||||
return;
|
||||
}
|
||||
|
||||
} else if (req == REQ_SCROLLDOWN) {
|
||||
if (!(m->mopt & MC_SCROLL))
|
||||
if (m->cursel == 0) {
|
||||
mbeep();
|
||||
else if (m->cursel >= m->numopts + hasexit - 1)
|
||||
mbeep();
|
||||
else {
|
||||
m->topline = MIN(m->topline + m->h - 1,
|
||||
m->numopts + hasexit - m->h + 1);
|
||||
m->cursel = MIN(m->numopts + hasexit - 1,
|
||||
m->cursel + m->h - 1);
|
||||
wclear(m->mw);
|
||||
refr = 1;
|
||||
return;
|
||||
}
|
||||
m->topline = MAX(0, m->topline - m->h + 1);
|
||||
m->cursel = MAX(0, m->cursel - m->h + 1);
|
||||
wclear(m->mw);
|
||||
refr = 1;
|
||||
break;
|
||||
|
||||
} else {
|
||||
case REQ_SCROLLDOWN:
|
||||
if (!(m->mopt & MC_SCROLL)) {
|
||||
mbeep();
|
||||
return;
|
||||
}
|
||||
if (m->cursel >= m->numopts + hasexit - 1) {
|
||||
mbeep();
|
||||
return;
|
||||
}
|
||||
m->topline = MIN(m->topline + m->h - 1,
|
||||
m->numopts + hasexit - m->h + 1);
|
||||
m->cursel = MIN(m->numopts + hasexit - 1,
|
||||
m->cursel + m->h - 1);
|
||||
wclear(m->mw);
|
||||
refr = 1;
|
||||
break;
|
||||
|
||||
default:
|
||||
ch = req;
|
||||
if (ch == 'x' && hasexit) {
|
||||
m->cursel = m->numopts;
|
||||
scroll_sel = 1;
|
||||
refr = 1;
|
||||
} else
|
||||
if (!(m->mopt & MC_NOSHORTCUT)) {
|
||||
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();
|
||||
else {
|
||||
m->cursel = ch;
|
||||
scroll_sel = 1;
|
||||
refr = 1;
|
||||
}
|
||||
} else
|
||||
mbeep();
|
||||
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;
|
||||
}
|
||||
m->cursel = ch;
|
||||
scroll_sel = 1;
|
||||
refr = 1;
|
||||
}
|
||||
|
||||
if (m->mopt & MC_SCROLL && scroll_sel) {
|
||||
while (m->cursel >= m->topline + m->h -1 )
|
||||
m->topline = MIN(m->topline+m->h-1,
|
||||
m->numopts+hasexit-m->h+1);
|
||||
while (m->cursel >= m->topline + m->h - 1)
|
||||
m->topline = MIN(m->topline + m->h - 1,
|
||||
m->numopts + hasexit - m->h + 1);
|
||||
while (m->cursel < m->topline)
|
||||
m->topline = MAX(0,m->topline-m->h+1);
|
||||
m->topline = MAX(0, m->topline - m->h + 1);
|
||||
}
|
||||
|
||||
if (refr) {
|
||||
post_menu (m);
|
||||
wrefresh (m->mw);
|
||||
post_menu(m);
|
||||
wrefresh(m->mw);
|
||||
}
|
||||
}
|
||||
|
||||
int
|
||||
menu_init (void)
|
||||
menu_init(void)
|
||||
{
|
||||
|
||||
if (__menu_init)
|
||||
@ -532,12 +549,12 @@ menu_init (void)
|
||||
num_menus = DYN_INIT_NUM;
|
||||
while (num_menus < DYN_MENU_START)
|
||||
num_menus *= 2;
|
||||
menus = (menudesc *) malloc(sizeof(menudesc)*num_menus);
|
||||
menus = malloc(sizeof(menudesc) * num_menus);
|
||||
if (menus == NULL)
|
||||
return 2;
|
||||
(void) memset ((void *)menus, 0, sizeof(menudesc)*num_menus);
|
||||
(void) memcpy ((void *)menus, (void *)menu_def,
|
||||
sizeof(menudesc)*DYN_MENU_START);
|
||||
(void)memset(menus, 0, sizeof(menudesc) * num_menus);
|
||||
(void)memcpy(menus, (void *)menu_def,
|
||||
sizeof(menudesc) * DYN_MENU_START);
|
||||
num_avail = num_menus - DYN_MENU_START;
|
||||
#endif
|
||||
|
||||
@ -546,7 +563,7 @@ menu_init (void)
|
||||
}
|
||||
|
||||
void
|
||||
process_menu (int num)
|
||||
process_menu(int num)
|
||||
{
|
||||
int sel = 0;
|
||||
int req, done;
|
||||
@ -586,15 +603,15 @@ process_menu (int num)
|
||||
/* Process the display action */
|
||||
if (m->post_act)
|
||||
(*m->post_act)();
|
||||
post_menu (m);
|
||||
wrefresh (m->mw);
|
||||
post_menu(m);
|
||||
wrefresh(m->mw);
|
||||
|
||||
while ((req = menucmd (m->mw)) != REQ_EXECUTE)
|
||||
process_req (m, num, req);
|
||||
|
||||
sel = m->cursel;
|
||||
wclear (m->mw);
|
||||
wrefresh (m->mw);
|
||||
wclear(m->mw);
|
||||
wrefresh(m->mw);
|
||||
|
||||
/* Process the items */
|
||||
if (sel < m->numopts) {
|
||||
@ -638,22 +655,17 @@ process_menu (int num)
|
||||
|
||||
/* Beginning of routines for dynamic menus. */
|
||||
|
||||
/* local prototypes */
|
||||
static int double_menus (void);
|
||||
|
||||
static int
|
||||
double_menus (void)
|
||||
double_menus(void)
|
||||
{
|
||||
menudesc *temp;
|
||||
|
||||
temp = (menudesc *) malloc(sizeof(menudesc)*num_menus*2);
|
||||
temp = malloc(sizeof(menudesc) * num_menus * 2);
|
||||
if (temp == NULL)
|
||||
return 0;
|
||||
(void) memset ((void *)temp, 0,
|
||||
sizeof(menudesc)*num_menus*2);
|
||||
(void) memcpy ((void *)temp, (void *)menus,
|
||||
sizeof(menudesc)*num_menus);
|
||||
free (menus);
|
||||
(void) memset(temp, 0, sizeof(menudesc) * num_menus * 2);
|
||||
(void) memcpy(temp, menus, sizeof(menudesc) * num_menus);
|
||||
free(menus);
|
||||
menus = temp;
|
||||
num_avail = num_menus;
|
||||
num_menus *= 2;
|
||||
@ -662,7 +674,7 @@ double_menus (void)
|
||||
}
|
||||
|
||||
int
|
||||
new_menu (char * title, menu_ent * opts, int numopts,
|
||||
new_menu(char * title, menu_ent * opts, int numopts,
|
||||
int x, int y, int h, int w, int mopt,
|
||||
void (*post_act)(void), void (*exit_act)(void), char * help)
|
||||
{
|
||||
@ -670,7 +682,7 @@ new_menu (char * title, menu_ent * opts, int numopts,
|
||||
|
||||
/* Check for free menu entry. */
|
||||
if (num_avail == 0)
|
||||
if (!double_menus ())
|
||||
if (!double_menus())
|
||||
return -1;
|
||||
|
||||
/* Find free menu entry. */
|
||||
@ -693,17 +705,17 @@ new_menu (char * title, menu_ent * opts, int numopts,
|
||||
menus[ix].helpstr = help;
|
||||
menus[ix].exitstr = "Exit";
|
||||
|
||||
init_menu (&menus[ix]);
|
||||
init_menu(&menus[ix]);
|
||||
|
||||
return ix;
|
||||
}
|
||||
|
||||
void
|
||||
free_menu (int menu_no)
|
||||
free_menu(int menu_no)
|
||||
{
|
||||
if (menu_no < num_menus) {
|
||||
menus[menu_no].mopt &= ~MC_VALID;
|
||||
if (menus[menu_no].mw != NULL)
|
||||
delwin (menus[menu_no].mw);
|
||||
delwin(menus[menu_no].mw);
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user