Add extra command 'allow dynamic messages' which will push all texts through

the msgc translation service.
Allow for texts being NULL as well as "", don't use strlen() to test for "".
This commit is contained in:
dsl 2003-06-10 17:19:04 +00:00
parent 0b52d9cd7b
commit 19605a628c
5 changed files with 50 additions and 28 deletions

View File

@ -1,4 +1,4 @@
/* $NetBSD: defs.h,v 1.5 2002/01/29 10:20:35 tv Exp $ */
/* $NetBSD: defs.h,v 1.6 2003/06/10 17:19:04 dsl Exp $ */
/*
* Copyright 1997 Piermont Information Systems Inc.
@ -66,6 +66,7 @@ EXTERN char *out_name INIT("menu_defs");
EXTERN char *sys_name INIT("menu_sys.def");
EXTERN int do_dynamic INIT(0);
EXTERN int do_msgxlat INIT(0);
EXTERN int line_no INIT(1);
EXTERN int had_errors INIT(FALSE);
EXTERN int max_strlen INIT(1);

View File

@ -1,4 +1,4 @@
/* $NetBSD: mdb.c,v 1.32 2003/06/09 18:48:40 dsl Exp $ */
/* $NetBSD: mdb.c,v 1.33 2003/06/10 17:19:04 dsl Exp $ */
/*
* Copyright 1997 Piermont Information Systems Inc.
@ -159,8 +159,14 @@ write_menu_file (char *initcode)
"#include <curses.h>\n\n"
);
if (do_msgxlat)
(void)fprintf(out_file, "#define MSG_XLAT(x) msg_string(x)\n");
else
(void)fprintf(out_file, "#define MSG_XLAT(x) (x)\n");
if (do_dynamic)
(void) fprintf (out_file, "#define DYNAMIC_MENUS\n\n");
(void)fprintf(out_file, "#define DYNAMIC_MENUS\n");
if (do_dynamic || do_msgxlat)
(void)fprintf(out_file, "\n");
(void) fprintf (out_file,
"typedef struct menudesc menudesc;\n"
@ -256,19 +262,19 @@ write_menu_file (char *initcode)
for (i=0; i<menu_no; i++) {
if (strlen(menus[i]->info->postact.code)) {
(void) fprintf (out_file,
"static void menu_%d_postact(menudesc *menu, void *arg);\n"
"static void menu_%d_postact(menudesc *menu, void *arg)\n{", i, i);
"/*ARGSUSED*/\n"
"static void menu_%d_postact(menudesc *menu, void *arg)\n{\n", i);
if (menus[i]->info->postact.endwin)
(void) fprintf (out_file, "\tendwin();\n"
"\t__m_endwin = 1;\n");
(void) fprintf (out_file,
"\t%s\n}\n",
"\t%s\n}\n\n",
menus[i]->info->postact.code);
}
if (strlen(menus[i]->info->exitact.code)) {
(void) fprintf (out_file,
"static void menu_%d_exitact(menudesc *menu, void *arg);\n"
"static void menu_%d_exitact(menudesc *menu, void *arg)\n{", i, i);
"/*ARGSUSED*/\n"
"static void menu_%d_exitact(menudesc *menu, void *arg)\n{\n", i);
if (menus[i]->info->exitact.endwin)
(void) fprintf (out_file, "\tendwin();\n"
"\t__m_endwin = 1;\n");

View File

@ -1,4 +1,4 @@
/* $NetBSD: menu_sys.def,v 1.39 2003/06/09 18:48:41 dsl Exp $ */
/* $NetBSD: menu_sys.def,v 1.40 2003/06/10 17:19:04 dsl Exp $ */
/*
* Copyright 1997 Piermont Information Systems Inc.
@ -135,14 +135,21 @@ init_menu(menudesc *m)
int wmax;
int hadd, wadd, exithadd;
int i;
const char *title;
hadd = ((m->mopt & MC_NOBOX) ? 0 : 2);
wadd = ((m->mopt & MC_NOBOX) ? 2 : 4);
hadd += strlen(m->title) != 0 ? 2 : 0;
if (m->title && *(title = MSG_XLAT(m->title)) != 0) {
wmax = strlen(title);
hadd += 2;
} else {
m->title = NULL;
title = "untitled";
wmax = 0;
}
exithadd = ((m->mopt & MC_NOEXITOPT) ? 0 : 1);
wmax = strlen(m->title);
/* Calculate h? h == number of visible options. */
if (m->h == 0)
@ -154,7 +161,7 @@ init_menu(menudesc *m)
endwin();
(void)fprintf(stderr,
"Window too short for menu \"%s\"\n",
m->title);
title);
exit(1);
}
hadd++;
@ -167,7 +174,7 @@ init_menu(menudesc *m)
endwin();
(void)fprintf(stderr,
"Screen too short (%d + %d + %d > %d) for menu \"%s\"\n",
m->y, m->h, hadd, max_lines, m->title);
m->y, m->h, hadd, max_lines, title);
exit(1);
}
@ -178,7 +185,7 @@ init_menu(menudesc *m)
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);
wmax = MAX(wmax, strlen(MSG_XLAT(m->opts[i].opt_name)) + 3);
m->w = wmax;
}
@ -186,7 +193,7 @@ init_menu(menudesc *m)
if (m->w + wadd > max_cols) {
endwin();
(void)fprintf(stderr,
"Screen too narrow for menu \"%s\"\n", m->title);
"Screen too narrow for menu \"%s\"\n", title);
exit(1);
}
@ -201,7 +208,7 @@ init_menu(menudesc *m)
if (m->mw == NULL) {
endwin();
(void)fprintf(stderr,
"Could not create window for menu \"%s\"\n", m->title);
"Could not create window for menu \"%s\"\n", title);
exit(1);
}
keypad(m->mw, TRUE); /* enable multi-key assembling for win */
@ -263,14 +270,14 @@ draw_menu(menudesc *m)
/* Clear the window */
wclear(m->mw);
tadd = strlen(m->title) ? 2 : 0;
if (tadd) {
if (m->title) {
mvwaddstr(m->mw, hasbox, hasbox, " ");
mvwaddstr(m->mw, hasbox, hasbox + 1, m->title);
mvwaddstr(m->mw, hasbox, hasbox + 1, MSG_XLAT(m->title));
tadd = 2;
cury += tadd;
maxy += tadd;
}
} else
tadd = 0;
if (m->cursel == -1) {
m->cursel = m->numopts;
@ -282,13 +289,14 @@ draw_menu(menudesc *m)
if (cury >= maxy)
break;
draw_menu_line(m, opt, cury++, opt_ch(opt),
m->opts[opt].opt_name);
MSG_XLAT(m->opts[opt].opt_name));
}
/* Add the exit option. */
if (!(m->mopt & MC_NOEXITOPT)) {
if (cury < maxy)
draw_menu_line(m, m->numopts, cury++, 'x', m->exitstr);
draw_menu_line(m, m->numopts, cury++, 'x',
MSG_XLAT(m->exitstr));
else
opt = 0;
}
@ -320,11 +328,12 @@ process_help(menudesc *m, int num)
mbeep();
return;
}
help = MSG_XLAT(help);
/* Display the help information. */
do {
if (lineoff < curoff) {
help = m->helpstr;
help = MSG_XLAT(m->helpstr);
curoff = 0;
}
while (*help && curoff < lineoff) {
@ -661,7 +670,7 @@ new_menu(const char *title, menu_ent *opts, int numopts,
/* Set Entries */
m = menus + ix;
m->title = title ? title : "";
m->title = title;
m->opts = opts;
m->numopts = numopts;
m->x = x;

View File

@ -1,4 +1,4 @@
/* $NetBSD: parse.y,v 1.11 2003/05/08 16:20:57 dsl Exp $ */
/* $NetBSD: parse.y,v 1.12 2003/06/10 17:19:04 dsl Exp $ */
/*
* 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> TITLE DEFAULT DISPLAY ERROR EXITSTRING ALLOW DYNAMIC MENUS
SCROLLABLE SHORTCUT
SCROLLABLE SHORTCUT MESSAGES
%token <s_value> STRING NAME CODE INT_CONST CHAR_CONST
%type <s_value> init_code system helpstr text
@ -85,11 +85,15 @@ menu_list : /* empty */
| menu_list default_def
| menu_list initerror_def
| menu_list dynamic_def
| menu_list msgxlat_def
;
dynamic_def : ALLOW DYNAMIC MENUS ';'
{ do_dynamic = 1; }
msgxlat_def : ALLOW DYNAMIC MESSAGES ';'
{ do_msgxlat = 1; }
initerror_def : ERROR action ';'
{ error_act = $2; }

View File

@ -1,4 +1,4 @@
/* $NetBSD: scan.l,v 1.9 2000/08/15 02:09:11 phil Exp $ */
/* $NetBSD: scan.l,v 1.10 2003/06/10 17:19:04 dsl Exp $ */
/*
* Copyright 1997 Piermont Information Systems Inc.
@ -104,6 +104,8 @@ allow { return ALLOW; }
dynamic { return DYNAMIC; }
messages { return MESSAGES; }
scrollable { return SCROLLABLE; }
shortcut { return SHORTCUT; }