Tweek the "no shortcut" code.

MC_NOSHORTKEY to NOSHORTCUT
   added option "shortcut" to menuc input language.
   added example of this kind of menu in testm.
This commit is contained in:
phil 2000-08-15 02:09:11 +00:00
parent caa284ac57
commit 94c7405838
7 changed files with 43 additions and 33 deletions

View File

@ -1,4 +1,4 @@
/* $NetBSD: mdb.c,v 1.16 2000/08/15 01:01:41 hubertf Exp $ */ /* $NetBSD: mdb.c,v 1.17 2000/08/15 02:09:11 phil Exp $ */
/* /*
* Copyright 1997 Piermont Information Systems Inc. * Copyright 1997 Piermont Information Systems Inc.
@ -194,12 +194,10 @@ write_menu_file (char *initcode)
"#define MC_NOEXITOPT 1\n" "#define MC_NOEXITOPT 1\n"
"#define MC_NOBOX 2\n" "#define MC_NOBOX 2\n"
"#define MC_SCROLL 4\n" "#define MC_SCROLL 4\n"
"#define MC_NOSHORTCUT 16 /* don't display letter shortcuts */\n" "#define MC_NOSHORTCUT 8\n"
"#define MC_VALID 256\n"
); );
if (do_dynamic)
(void) fprintf (out_file, "#define MC_VALID 8\n");
(void) fprintf (out_file, "%s", (void) fprintf (out_file, "%s",
"\n" "\n"
"/* initilization flag */\n" "/* initilization flag */\n"

View File

@ -1,4 +1,4 @@
/* $NetBSD: mdb.h,v 1.4 1999/06/20 02:07:18 cgd Exp $ */ /* $NetBSD: mdb.h,v 1.5 2000/08/15 02:09:11 phil Exp $ */
/* /*
* Copyright 1997 Piermont Information Systems Inc. * Copyright 1997 Piermont Information Systems Inc.
@ -91,5 +91,6 @@ struct menu_info {
#define NOEXITOPT 1 #define NOEXITOPT 1
#define NOBOX 2 #define NOBOX 2
#define SCROLL 4 #define SCROLL 4
#define NOSHORTCUT 8
#endif #endif

View File

@ -1,4 +1,4 @@
/* $NetBSD: menu_sys.def,v 1.23 2000/08/15 01:01:41 hubertf Exp $ */ /* $NetBSD: menu_sys.def,v 1.24 2000/08/15 02:09:11 phil Exp $ */
/* /*
* Copyright 1997 Piermont Information Systems Inc. * Copyright 1997 Piermont Information Systems Inc.
@ -372,9 +372,9 @@ post_menu (struct menudesc *m)
selrow = cury; selrow = cury;
} else } else
mvwaddstr (m->mw, cury, hasbox, " "); mvwaddstr (m->mw, cury, hasbox, " ");
if (! (m->mopt & MC_NOSHORTCUT)) { if (!(m->mopt & MC_NOSHORTCUT)) {
(void) sprintf (optstr, "%c: ", opt_ch(i)); (void) sprintf (optstr, "%c: ", opt_ch(i));
waddstr (m->mw, optstr); waddstr (m->mw, optstr);
} }
waddstr (m->mw, m->opts[i].opt_name); waddstr (m->mw, m->opts[i].opt_name);
if (m->cursel == i) if (m->cursel == i)
@ -389,7 +389,7 @@ post_menu (struct menudesc *m)
selrow = cury; selrow = cury;
} else } else
mvwaddstr (m->mw, cury, hasbox, " "); mvwaddstr (m->mw, cury, hasbox, " ");
if (! (m->mopt & MC_NOSHORTCUT)) if (!(m->mopt & MC_NOSHORTCUT))
waddstr (m->mw, "x: "); waddstr (m->mw, "x: ");
waddstr (m->mw, m->exitstr); waddstr (m->mw, m->exitstr);
if (m->cursel >= m->numopts) if (m->cursel >= m->numopts)
@ -565,13 +565,13 @@ process_req (struct menudesc *m, int num, int req)
m->cursel = m->numopts; m->cursel = m->numopts;
scroll_sel = 1; scroll_sel = 1;
refresh = 1; refresh = 1;
} else { } else
if (! (m->mopt & MC_NOSHORTCUT)) { if (!(m->mopt & MC_NOSHORTCUT)) {
if (ch > 'z') if (ch > 'z')
ch = 255; ch = 255;
if (ch >= 'a') { if (ch >= 'a') {
if (ch > 'x') ch--; if (ch > 'x') ch--;
ch = ch - 'a'; ch = ch - 'a';
} else } else
ch = 25 + ch - 'A'; ch = 25 + ch - 'A';
if (ch < 0 || ch >= m->numopts) if (ch < 0 || ch >= m->numopts)
@ -581,8 +581,8 @@ process_req (struct menudesc *m, int num, int req)
scroll_sel = 1; scroll_sel = 1;
refresh = 1; refresh = 1;
} }
} } else
} mbeep();
} }
if (m->mopt & MC_SCROLL && scroll_sel) { if (m->mopt & MC_SCROLL && scroll_sel) {
@ -749,8 +749,8 @@ double_menus (void)
int 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, int x, int y, int h, int w, int mopt,
void (*post_act)(void), void (*exit_act), char * help) void (*post_act)(void), void (*exit_act), char * help)
{ {
int ix; int ix;
@ -766,7 +766,7 @@ new_menu (char * title, menu_ent * opts, int numopts,
/* if ix == num_menus ... panic */ /* if ix == num_menus ... panic */
/* Set Entries */ /* Set Entries */
menus[ix].title = title?title:""; menus[ix].title = title ? title : "";
menus[ix].opts = opts; menus[ix].opts = opts;
menus[ix].numopts = numopts; menus[ix].numopts = numopts;
menus[ix].x = x; menus[ix].x = x;

View File

@ -1,4 +1,4 @@
/* $NetBSD: parse.y,v 1.8 1999/07/26 06:19:01 christos Exp $ */ /* $NetBSD: parse.y,v 1.9 2000/08/15 02:09:11 phil Exp $ */
/* /*
* Copyright 1997 Piermont Information Systems Inc. * Copyright 1997 Piermont Information Systems Inc.
@ -57,7 +57,7 @@ static optn_info *cur_optn;
%token <i_value> X Y W H NO BOX SUB HELP MENU NEXT EXIT ACTION ENDWIN OPTION %token <i_value> X Y W H NO BOX SUB HELP MENU NEXT EXIT ACTION ENDWIN OPTION
%token <i_value> TITLE DEFAULT DISPLAY ERROR EXITSTRING ALLOW DYNAMIC MENUS %token <i_value> TITLE DEFAULT DISPLAY ERROR EXITSTRING ALLOW DYNAMIC MENUS
SCROLLABLE SCROLLABLE SHORTCUT
%token <s_value> STRING NAME CODE INT_CONST CHAR_CONST %token <s_value> STRING NAME CODE INT_CONST CHAR_CONST
%type <s_value> init_code system helpstr %type <s_value> init_code system helpstr
@ -134,6 +134,8 @@ opt : NO EXIT { cur_menu->info->mopt |= NOEXITOPT; }
| BOX { cur_menu->info->mopt &= ~NOBOX; } | BOX { cur_menu->info->mopt &= ~NOBOX; }
| NO SCROLLABLE { cur_menu->info->mopt &= ~SCROLL; } | NO SCROLLABLE { cur_menu->info->mopt &= ~SCROLL; }
| SCROLLABLE { cur_menu->info->mopt |= SCROLL; } | SCROLLABLE { cur_menu->info->mopt |= SCROLL; }
| NO SHORTCUT { cur_menu->info->mopt |= NOSHORTCUT; }
| SHORTCUT { cur_menu->info->mopt &= ~NOSHORTCUT; }
| X "=" INT_CONST { cur_menu->info->x = atoi($3); } | X "=" INT_CONST { cur_menu->info->x = atoi($3); }
| Y "=" INT_CONST { cur_menu->info->y = atoi($3); } | Y "=" INT_CONST { cur_menu->info->y = atoi($3); }
| W "=" INT_CONST { cur_menu->info->w = atoi($3); } | W "=" INT_CONST { cur_menu->info->w = atoi($3); }

View File

@ -1,4 +1,4 @@
/* $NetBSD: scan.l,v 1.8 1999/06/20 02:07:18 cgd Exp $ */ /* $NetBSD: scan.l,v 1.9 2000/08/15 02:09:11 phil Exp $ */
/* /*
* Copyright 1997 Piermont Information Systems Inc. * Copyright 1997 Piermont Information Systems Inc.
@ -106,6 +106,8 @@ dynamic { return DYNAMIC; }
scrollable { return SCROLLABLE; } scrollable { return SCROLLABLE; }
shortcut { return SHORTCUT; }
\"([^\"\n]*(\\\")?)*\" { \"([^\"\n]*(\\\")?)*\" {
yylval.s_value = strdup (yytext); yylval.s_value = strdup (yytext);
max_strlen = max_strlen > strlen(yytext) max_strlen = max_strlen > strlen(yytext)

View File

@ -1,4 +1,4 @@
/* $NetBSD: main.c,v 1.3 1998/07/23 17:56:00 phil Exp $ */ /* $NetBSD: main.c,v 1.4 2000/08/15 02:09:12 phil Exp $ */
/* /*
* Copyright 1997 Piermont Information Systems Inc. * Copyright 1997 Piermont Information Systems Inc.
@ -58,9 +58,9 @@ char ent_text[5][50] = {"name: ", "strt: ", "city: ", "opt 4", "NUM: "};
/* opt processing routines .. */ /* opt processing routines .. */
int opt_1 (void); int opt_1 (struct menudesc *m);
int opt_1 (void) int opt_1 (struct menudesc *m)
{ {
msg_clear(); msg_clear();
msg_prompt (MSG_name, "", &ent_text[0][6], 40); msg_prompt (MSG_name, "", &ent_text[0][6], 40);
@ -68,9 +68,9 @@ int opt_1 (void)
return 0; return 0;
} }
int opt_2 (void); int opt_2 (struct menudesc *m);
int opt_2 (void) int opt_2 (struct menudesc *m)
{ {
msg_clear(); msg_clear();
msg_prompt (MSG_street, "", &ent_text[1][6], 40); msg_prompt (MSG_street, "", &ent_text[1][6], 40);
@ -78,9 +78,9 @@ int opt_2 (void)
return 0; return 0;
} }
int opt_3 (void); int opt_3 (struct menudesc *m);
int opt_3 (void) int opt_3 (struct menudesc *m)
{ {
msg_clear(); msg_clear();
msg_prompt (MSG_city, "", &ent_text[2][6], 40); msg_prompt (MSG_city, "", &ent_text[2][6], 40);
@ -101,7 +101,6 @@ int num = 0;
void do_dynamic(void); void do_dynamic(void);
void dyn_disp (void); void dyn_disp (void);
void dyn_disp (void) void dyn_disp (void)
{ {
sprintf (&ent_text[4][5], "%d", num++); sprintf (&ent_text[4][5], "%d", num++);

View File

@ -1,4 +1,4 @@
/* $NetBSD: menus.mc,v 1.9 1998/07/16 07:08:26 phil Exp $ */ /* $NetBSD: menus.mc,v 1.10 2000/08/15 02:09:12 phil Exp $ */
/* /*
* Copyright 1997 Piermont Information Systems Inc. * Copyright 1997 Piermont Information Systems Inc.
@ -75,7 +75,10 @@ menu root, title " Main Menu of Test System", x=10;
sub menu scrollit2 sub menu scrollit2
; ;
option "Big non-scrollable menu, bombs on small screens", option "Big non-scrollable menu, bombs on small screens",
sub menu bigscroll sub menu bigscroll
;
option "A menu with no shortcuts",
sub menu noshort
; ;
option "A dynamic menu ...", option "A dynamic menu ...",
action { do_dynamic (); } action { do_dynamic (); }
@ -185,6 +188,11 @@ menu middle, no box;
menu nextmenu, title " A next window! ? for comments", no exit; menu nextmenu, title " A next window! ? for comments", no exit;
option "Just Exit!:", exit; option "Just Exit!:", exit;
menu noshort, title " No shortcut characters!", no shortcut;
option "first", action {};
option "second", action {};
option "third", action {};
menu scrollit, scrollable, h=4, title " Scrollable Menu"; menu scrollit, scrollable, h=4, title " Scrollable Menu";
option "option 1", action {}; option "option 1", action {};
option "option 2", action {}; option "option 2", action {};