Tue Mar 6 16:55:18 2012 UTC ()
Remove the advertising clause and appease the eye a bit (still not good, but
better).  Almost no functional change.


(mbalmer)
diff -r1.8 -r1.9 src/usr.bin/menuc/defs.h
diff -r1.8 -r1.9 src/usr.bin/menuc/mdb.h
diff -r1.10 -r1.11 src/usr.bin/menuc/main.c
diff -r1.45 -r1.46 src/usr.bin/menuc/mdb.c
diff -r1.58 -r1.59 src/usr.bin/menuc/menu_sys.def
diff -r1.29 -r1.30 src/usr.bin/menuc/menuc.1
diff -r1.15 -r1.16 src/usr.bin/menuc/parse.y
diff -r1.15 -r1.16 src/usr.bin/menuc/scan.l
diff -r1.4 -r1.5 src/usr.bin/menuc/util.c

cvs diff -r1.8 -r1.9 src/usr.bin/menuc/defs.h (switch to unified diff)

--- src/usr.bin/menuc/defs.h 2003/10/27 00:12:43 1.8
+++ src/usr.bin/menuc/defs.h 2012/03/06 16:55:18 1.9
@@ -1,106 +1,102 @@ @@ -1,106 +1,102 @@
1/* $NetBSD: defs.h,v 1.8 2003/10/27 00:12:43 lukem Exp $ */ 1/* $NetBSD: defs.h,v 1.9 2012/03/06 16:55:18 mbalmer Exp $ */
2 2
3/* 3/*
4 * Copyright 1997 Piermont Information Systems Inc. 4 * Copyright 1997 Piermont Information Systems Inc.
5 * All rights reserved. 5 * All rights reserved.
6 * 6 *
7 * Written by Philip A. Nelson for Piermont Information Systems Inc. 7 * Written by Philip A. Nelson for Piermont Information Systems Inc.
8 * 8 *
9 * Redistribution and use in source and binary forms, with or without 9 * Redistribution and use in source and binary forms, with or without
10 * modification, are permitted provided that the following conditions 10 * modification, are permitted provided that the following conditions
11 * are met: 11 * are met:
12 * 1. Redistributions of source code must retain the above copyright 12 * 1. Redistributions of source code must retain the above copyright
13 * notice, this list of conditions and the following disclaimer. 13 * notice, this list of conditions and the following disclaimer.
14 * 2. Redistributions in binary form must reproduce the above copyright 14 * 2. Redistributions in binary form must reproduce the above copyright
15 * notice, this list of conditions and the following disclaimer in the 15 * notice, this list of conditions and the following disclaimer in the
16 * documentation and/or other materials provided with the distribution. 16 * documentation and/or other materials provided with the distribution.
17 * 3. All advertising materials mentioning features or use of this software 17 * 3. The name of Piermont Information Systems Inc. may not be used to endorse
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 18 * or promote products derived from this software without specific prior
23 * written permission. 19 * written permission.
24 * 20 *
25 * THIS SOFTWARE IS PROVIDED BY PIERMONT INFORMATION SYSTEMS INC. ``AS IS'' 21 * THIS SOFTWARE IS PROVIDED BY PIERMONT INFORMATION SYSTEMS INC. ``AS IS''
26 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 22 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
27 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 23 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
28 * ARE DISCLAIMED. IN NO EVENT SHALL PIERMONT INFORMATION SYSTEMS INC. BE  24 * ARE DISCLAIMED. IN NO EVENT SHALL PIERMONT INFORMATION SYSTEMS INC. BE
29 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR  25 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
30 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF  26 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
31 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 27 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
32 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 28 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
33 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 29 * 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  30 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
35 * THE POSSIBILITY OF SUCH DAMAGE. 31 * THE POSSIBILITY OF SUCH DAMAGE.
36 * 32 *
37 */ 33 */
38 34
39/* defs.h: definitions needed for the menu system. */ 35/* defs.h: definitions needed for the menu system. */
40 36
41#if HAVE_NBTOOL_CONFIG_H 37#if HAVE_NBTOOL_CONFIG_H
42#include "nbtool_config.h" 38#include "nbtool_config.h"
43#endif 39#endif
44 40
45#include <stdio.h> 41#include <stdio.h>
46 42
47#include "mdb.h" 43#include "mdb.h"
48 44
49#ifdef MAIN 45#ifdef MAIN
50#define EXTERN  46#define EXTERN
51#define INIT(x) = x 47#define INIT(x) = x
52#else 48#else
53#define EXTERN extern 49#define EXTERN extern
54#define INIT(x) 50#define INIT(x)
55#endif 51#endif
56 52
57/* some constants */ 53/* some constants */
58#define TRUE 1 54#define TRUE 1
59#define FALSE 0 55#define FALSE 0
60 56
61/* Global variables .. to be defined in main.c, extern elsewhere. */ 57/* Global variables .. to be defined in main.c, extern elsewhere. */
62 58
63EXTERN char *prog_name; 59EXTERN char *prog_name;
64EXTERN char *src_name; 60EXTERN char *src_name;
65EXTERN char *out_name INIT("menu_defs"); 61EXTERN char *out_name INIT("menu_defs");
66EXTERN char *sys_name INIT("menu_sys.def"); 62EXTERN char *sys_name INIT("menu_sys.def");
67 63
68EXTERN int do_dynamic INIT(0); 64EXTERN int do_dynamic INIT(0);
69EXTERN int do_msgxlat INIT(0); 65EXTERN int do_msgxlat INIT(0);
70EXTERN int line_no INIT(1); 66EXTERN int line_no INIT(1);
71EXTERN int had_errors INIT(FALSE); 67EXTERN int had_errors INIT(FALSE);
72EXTERN int max_strlen INIT(1); 68EXTERN int max_strlen INIT(1);
73 69
74EXTERN id_rec *root INIT(NULL); 70EXTERN id_rec *root INIT(NULL);
75 71
76EXTERN struct menu_info default_info; 72EXTERN struct menu_info default_info;
77EXTERN id_rec default_menu; 73EXTERN id_rec default_menu;
78 74
79EXTERN action error_act INIT({NULL}); 75EXTERN action error_act INIT({NULL});
80 76
81/* Prototypes. */ 77/* Prototypes. */
82 78
83/* From util.c */ 79/* From util.c */
84void yyerror(const char *, ...) 80void yyerror(const char *, ...)
85 __attribute__((__format__(__printf__, 1, 2))); 81 __attribute__((__format__(__printf__, 1, 2)));
86void buff_add_ch(char); 82void buff_add_ch(char);
87char *buff_copy(void);  83char *buff_copy(void);
88 84
89/* from scan.l */ 85/* from scan.l */
90int yylex(void); 86int yylex(void);
91 87
92/* from parse.y */ 88/* from parse.y */
93int yyparse(void); 89int yyparse(void);
94 90
95/* Vars not defined in main.c */ 91/* Vars not defined in main.c */
96extern FILE *yyin; 92extern FILE *yyin;
97 93
98/* from avl.c */ 94/* from avl.c */
99id_rec *find_id(id_rec *, char *); 95id_rec *find_id(id_rec *, char *);
100int insert_id(id_rec **, id_rec *); 96int insert_id(id_rec **, id_rec *);
101 97
102/* from mdb.c */ 98/* from mdb.c */
103id_rec *get_menu(char *); 99id_rec *get_menu(char *);
104void check_defined(void); 100void check_defined(void);
105void write_menu_file(char *); 101void write_menu_file(char *);
106 102

cvs diff -r1.8 -r1.9 src/usr.bin/menuc/mdb.h (switch to unified diff)

--- src/usr.bin/menuc/mdb.h 2006/02/20 21:06:40 1.8
+++ src/usr.bin/menuc/mdb.h 2012/03/06 16:55:18 1.9
@@ -1,102 +1,98 @@ @@ -1,102 +1,98 @@
1/* $NetBSD: mdb.h,v 1.8 2006/02/20 21:06:40 dsl Exp $ */ 1/* $NetBSD: mdb.h,v 1.9 2012/03/06 16:55:18 mbalmer Exp $ */
2 2
3/* 3/*
4 * Copyright 1997 Piermont Information Systems Inc. 4 * Copyright 1997 Piermont Information Systems Inc.
5 * All rights reserved. 5 * All rights reserved.
6 * 6 *
7 * Written by Philip A. Nelson for Piermont Information Systems Inc. 7 * Written by Philip A. Nelson for Piermont Information Systems Inc.
8 * 8 *
9 * Redistribution and use in source and binary forms, with or without 9 * Redistribution and use in source and binary forms, with or without
10 * modification, are permitted provided that the following conditions 10 * modification, are permitted provided that the following conditions
11 * are met: 11 * are met:
12 * 1. Redistributions of source code must retain the above copyright 12 * 1. Redistributions of source code must retain the above copyright
13 * notice, this list of conditions and the following disclaimer. 13 * notice, this list of conditions and the following disclaimer.
14 * 2. Redistributions in binary form must reproduce the above copyright 14 * 2. Redistributions in binary form must reproduce the above copyright
15 * notice, this list of conditions and the following disclaimer in the 15 * notice, this list of conditions and the following disclaimer in the
16 * documentation and/or other materials provided with the distribution. 16 * documentation and/or other materials provided with the distribution.
17 * 3. All advertising materials mentioning features or use of this software 17 * 3. The name of Piermont Information Systems Inc. may not be used to endorse
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 18 * or promote products derived from this software without specific prior
23 * written permission. 19 * written permission.
24 * 20 *
25 * THIS SOFTWARE IS PROVIDED BY PIERMONT INFORMATION SYSTEMS INC. ``AS IS'' 21 * THIS SOFTWARE IS PROVIDED BY PIERMONT INFORMATION SYSTEMS INC. ``AS IS''
26 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 22 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
27 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 23 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
28 * ARE DISCLAIMED. IN NO EVENT SHALL PIERMONT INFORMATION SYSTEMS INC. BE  24 * ARE DISCLAIMED. IN NO EVENT SHALL PIERMONT INFORMATION SYSTEMS INC. BE
29 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR  25 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
30 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF  26 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
31 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 27 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
32 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 28 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
33 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 29 * 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  30 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
35 * THE POSSIBILITY OF SUCH DAMAGE. 31 * THE POSSIBILITY OF SUCH DAMAGE.
36 * 32 *
37 */ 33 */
38 34
39/* mdb.h - definitions for the menu database. */ 35/* mdb.h - definitions for the menu database. */
40 36
41#ifndef MDB_H 37#ifndef MDB_H
42#define MDB_H 38#define MDB_H
43 39
44/* forward declaration */ 40/* forward declaration */
45typedef struct menu_info menu_info; 41typedef struct menu_info menu_info;
46 42
47/* The declarations for the balanced binary trees. */ 43/* The declarations for the balanced binary trees. */
48 44
49typedef struct id_rec { 45typedef struct id_rec {
50 /* The balanced binary tree fields. */ 46 /* The balanced binary tree fields. */
51 char *id; /* The name. */ 47 char *id; /* The name. */
52 short balance; /* For the balanced tree. */ 48 short balance; /* For the balanced tree. */
53 struct id_rec *left, *right; /* Tree pointers. */ 49 struct id_rec *left, *right; /* Tree pointers. */
54  50
55 /* Other information fields. */ 51 /* Other information fields. */
56 menu_info *info; 52 menu_info *info;
57 int menu_no; 53 int menu_no;
58} id_rec; 54} id_rec;
59 55
60 56
61/* menu definitions records. */ 57/* menu definitions records. */
62 58
63typedef struct action { 59typedef struct action {
64 char *code; 60 char *code;
65 int endwin; 61 int endwin;
66} action; 62} action;
67 63
68typedef struct optn_info { 64typedef struct optn_info {
69 char *name; 65 char *name;
70 int name_is_code; 66 int name_is_code;
71 int menu; 67 int menu;
72 int issub; 68 int issub;
73 int doexit; 69 int doexit;
74 action optact; 70 action optact;
75 struct optn_info *next; 71 struct optn_info *next;
76} optn_info; 72} optn_info;
77  73
78struct menu_info { 74struct menu_info {
79 char *title; 75 char *title;
80 char *helpstr; 76 char *helpstr;
81 char *exitstr; 77 char *exitstr;
82 int mopt; 78 int mopt;
83 int y, x; 79 int y, x;
84 int h, w; 80 int h, w;
85 int numopt; 81 int numopt;
86 int name_is_code; 82 int name_is_code;
87 optn_info *optns; 83 optn_info *optns;
88 action postact; 84 action postact;
89 action exitact; 85 action exitact;
90}; 86};
91 87
92/* defines for mopt */ 88/* defines for mopt */
93#define MC_NOEXITOPT 1 89#define MC_NOEXITOPT 1
94#define MC_NOBOX 2 90#define MC_NOBOX 2
95#define MC_SCROLL 4 91#define MC_SCROLL 4
96#define MC_NOSHORTCUT 8 92#define MC_NOSHORTCUT 8
97#define MC_NOCLEAR 16 93#define MC_NOCLEAR 16
98#define MC_DFLTEXIT 32 94#define MC_DFLTEXIT 32
99#define MC_ALWAYS_SCROLL 64 95#define MC_ALWAYS_SCROLL 64
100#define MC_SUBMENU 128 96#define MC_SUBMENU 128
101#define MC_VALID 0x10000 97#define MC_VALID 0x10000
102#endif 98#endif

cvs diff -r1.10 -r1.11 src/usr.bin/menuc/main.c (switch to unified diff)

--- src/usr.bin/menuc/main.c 2004/06/20 22:20:16 1.10
+++ src/usr.bin/menuc/main.c 2012/03/06 16:55:18 1.11
@@ -1,124 +1,115 @@ @@ -1,124 +1,115 @@
1/* $NetBSD: main.c,v 1.10 2004/06/20 22:20:16 jmc Exp $ */ 1/* $NetBSD: main.c,v 1.11 2012/03/06 16:55:18 mbalmer Exp $ */
2 2
3/* 3/*
4 * Copyright 1997 Piermont Information Systems Inc. 4 * Copyright 1997 Piermont Information Systems Inc.
5 * All rights reserved. 5 * All rights reserved.
6 * 6 *
7 * Written by Philip A. Nelson for Piermont Information Systems Inc. 7 * Written by Philip A. Nelson for Piermont Information Systems Inc.
8 * 8 *
9 * Redistribution and use in source and binary forms, with or without 9 * Redistribution and use in source and binary forms, with or without
10 * modification, are permitted provided that the following conditions 10 * modification, are permitted provided that the following conditions
11 * are met: 11 * are met:
12 * 1. Redistributions of source code must retain the above copyright 12 * 1. Redistributions of source code must retain the above copyright
13 * notice, this list of conditions and the following disclaimer. 13 * notice, this list of conditions and the following disclaimer.
14 * 2. Redistributions in binary form must reproduce the above copyright 14 * 2. Redistributions in binary form must reproduce the above copyright
15 * notice, this list of conditions and the following disclaimer in the 15 * notice, this list of conditions and the following disclaimer in the
16 * documentation and/or other materials provided with the distribution. 16 * documentation and/or other materials provided with the distribution.
17 * 3. All advertising materials mentioning features or use of this software 17 * 3. The name of Piermont Information Systems Inc. may not be used to endorse
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 18 * or promote products derived from this software without specific prior
23 * written permission. 19 * written permission.
24 * 20 *
25 * THIS SOFTWARE IS PROVIDED BY PIERMONT INFORMATION SYSTEMS INC. ``AS IS'' 21 * THIS SOFTWARE IS PROVIDED BY PIERMONT INFORMATION SYSTEMS INC. ``AS IS''
26 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 22 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
27 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 23 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
28 * ARE DISCLAIMED. IN NO EVENT SHALL PIERMONT INFORMATION SYSTEMS INC. BE  24 * ARE DISCLAIMED. IN NO EVENT SHALL PIERMONT INFORMATION SYSTEMS INC. BE
29 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR  25 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
30 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF  26 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
31 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 27 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
32 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 28 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
33 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 29 * 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  30 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
35 * THE POSSIBILITY OF SUCH DAMAGE. 31 * THE POSSIBILITY OF SUCH DAMAGE.
36 * 32 *
37 */ 33 */
38 34
39/* main.c - main program for menu compiler. */ 35/* main.c - main program for menu compiler. */
40 36
41#if HAVE_NBTOOL_CONFIG_H 37#if HAVE_NBTOOL_CONFIG_H
42#include "nbtool_config.h" 38#include "nbtool_config.h"
43#endif 39#endif
44 40
45#include <sys/cdefs.h> 41#include <sys/cdefs.h>
46 42
47#if defined(__RCSID) && !defined(lint) 43#if defined(__RCSID) && !defined(lint)
48__RCSID("$NetBSD: main.c,v 1.10 2004/06/20 22:20:16 jmc Exp $"); 44__RCSID("$NetBSD: main.c,v 1.11 2012/03/06 16:55:18 mbalmer Exp $");
49#endif 45#endif
50 46
51 47
52#include <stdio.h> 48#include <stdio.h>
53#include <stdlib.h> 49#include <stdlib.h>
54#include <unistd.h> 50#include <unistd.h>
55 51
56#define MAIN 52#define MAIN
57#include "defs.h" 53#include "defs.h"
58 54
59/* Local prototypes */ 55/* Local prototypes */
60void usage (char *); 56__dead void usage(void);
61 57
62int 58int
63main (int argc, char **argv) 59main(int argc, char **argv)
64{ 60{
65 int ch; 61 int ch;
66 62
67 prog_name = argv[0]; 
68  
69 /* Process the arguments. */ 63 /* Process the arguments. */
70 while ( (ch = getopt (argc, argv, "o:")) != -1 ) { 64 while ((ch = getopt(argc, argv, "o:")) != -1 ) {
71 switch (ch) { 65 switch (ch) {
72 case 'o': /* output file name */ 66 case 'o': /* output file name */
73 out_name = optarg; 67 out_name = optarg;
74 break; 68 break;
75 default: 69 default:
76 usage (prog_name); 70 usage();
77 } 71 }
78 } 72 }
79 73
80 if (optind != argc-1) 74 if (optind != argc - 1)
81 usage (prog_name); 75 usage();
82 76
83 src_name = argv[optind]; 77 src_name = argv[optind];
84 78
85 yyin = fopen (src_name, "r"); 79 yyin = fopen(src_name, "r");
86 if (yyin == NULL) { 80 if (yyin == NULL) {
87 (void) fprintf (stderr, "%s: could not open %s.\n", 81 (void)fprintf(stderr, "%s: could not open %s.\n", prog_name,
88 prog_name, src_name); 82 src_name);
89 exit (1); 83 exit(1);
90 } 84 }
91 85
92 /* The default menu */ 86 /* The default menu */
93 default_menu.info = &default_info; 87 default_menu.info = &default_info;
94 default_info.title = "\"\""; 88 default_info.title = "\"\"";
95 default_info.helpstr = NULL; 89 default_info.helpstr = NULL;
96 default_info.exitstr = NULL; 90 default_info.exitstr = NULL;
97 default_info.mopt = 0; 91 default_info.mopt = 0;
98 default_info.x = -1; 92 default_info.x = -1;
99 default_info.y = 0; 93 default_info.y = 0;
100 default_info.h = 0; 94 default_info.h = 0;
101 default_info.w = 0; 95 default_info.w = 0;
102 default_info.numopt = 0; 96 default_info.numopt = 0;
103 default_info.optns = NULL; 97 default_info.optns = NULL;
104 default_info.postact.code = NULL; 98 default_info.postact.code = NULL;
105 default_info.postact.endwin = FALSE; 99 default_info.postact.endwin = FALSE;
106 default_info.exitact.code = NULL; 100 default_info.exitact.code = NULL;
107 default_info.exitact.endwin = FALSE; 101 default_info.exitact.endwin = FALSE;
108 102
109 /* Do the parse */ 103 /* Do the parse */
110 (void) yyparse (); 104 (void)yyparse();
111 105
112 if (had_errors) 106 return had_errors ? 1 : 0;
113 return 1; 
114 
115 return 0; 
116} 107}
117 108
118 109
119void 110__dead void
120usage (char *prog) 111usage(void)
121{ 112{
122 (void) fprintf (stderr, "%s [-o name] file\n", prog); 113 (void)fprintf (stderr, "%s [-o name] file\n", getprogname());
123 exit (1); 114 exit(1);
124} 115}

cvs diff -r1.45 -r1.46 src/usr.bin/menuc/mdb.c (switch to unified diff)

--- src/usr.bin/menuc/mdb.c 2011/09/06 18:16:38 1.45
+++ src/usr.bin/menuc/mdb.c 2012/03/06 16:55:18 1.46
@@ -1,454 +1,431 @@ @@ -1,454 +1,431 @@
1/* $NetBSD: mdb.c,v 1.45 2011/09/06 18:16:38 joerg Exp $ */ 1/* $NetBSD: mdb.c,v 1.46 2012/03/06 16:55:18 mbalmer Exp $ */
2 2
3/* 3/*
4 * Copyright 1997 Piermont Information Systems Inc. 4 * Copyright 1997 Piermont Information Systems Inc.
5 * All rights reserved. 5 * All rights reserved.
6 * 6 *
7 * Written by Philip A. Nelson for Piermont Information Systems Inc. 7 * Written by Philip A. Nelson for Piermont Information Systems Inc.
8 * 8 *
9 * Redistribution and use in source and binary forms, with or without 9 * Redistribution and use in source and binary forms, with or without
10 * modification, are permitted provided that the following conditions 10 * modification, are permitted provided that the following conditions
11 * are met: 11 * are met:
12 * 1. Redistributions of source code must retain the above copyright 12 * 1. Redistributions of source code must retain the above copyright
13 * notice, this list of conditions and the following disclaimer. 13 * notice, this list of conditions and the following disclaimer.
14 * 2. Redistributions in binary form must reproduce the above copyright 14 * 2. Redistributions in binary form must reproduce the above copyright
15 * notice, this list of conditions and the following disclaimer in the 15 * notice, this list of conditions and the following disclaimer in the
16 * documentation and/or other materials provided with the distribution. 16 * documentation and/or other materials provided with the distribution.
17 * 3. All advertising materials mentioning features or use of this software 17 * 3. The name of Piermont Information Systems Inc. may not be used to endorse
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 18 * or promote products derived from this software without specific prior
23 * written permission. 19 * written permission.
24 * 20 *
25 * THIS SOFTWARE IS PROVIDED BY PIERMONT INFORMATION SYSTEMS INC. ``AS IS'' 21 * THIS SOFTWARE IS PROVIDED BY PIERMONT INFORMATION SYSTEMS INC. ``AS IS''
26 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 22 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
27 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 23 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
28 * ARE DISCLAIMED. IN NO EVENT SHALL PIERMONT INFORMATION SYSTEMS INC. BE  24 * ARE DISCLAIMED. IN NO EVENT SHALL PIERMONT INFORMATION SYSTEMS INC. BE
29 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR  25 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
30 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF  26 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
31 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 27 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
32 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 28 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
33 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 29 * 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  30 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
35 * THE POSSIBILITY OF SUCH DAMAGE. 31 * THE POSSIBILITY OF SUCH DAMAGE.
36 * 32 *
37 */ 33 */
38 34
39/* mdb.c - menu database manipulation */ 35/* mdb.c - menu database manipulation */
40 36
41#if HAVE_NBTOOL_CONFIG_H 37#if HAVE_NBTOOL_CONFIG_H
42#include "nbtool_config.h" 38#include "nbtool_config.h"
43#endif 39#endif
44 40
45#include <sys/cdefs.h> 41#include <sys/cdefs.h>
46 42
47#if defined(__RCSID) && !defined(lint) 43#if defined(__RCSID) && !defined(lint)
48__RCSID("$NetBSD: mdb.c,v 1.45 2011/09/06 18:16:38 joerg Exp $"); 44__RCSID("$NetBSD: mdb.c,v 1.46 2012/03/06 16:55:18 mbalmer Exp $");
49#endif 45#endif
50 46
51 47
52#include <stdio.h> 48#include <stdio.h>
53#include <stdlib.h> 49#include <stdlib.h>
54#include <string.h> 50#include <string.h>
55#include "mdb.h" 51#include "mdb.h"
56#include "defs.h" 52#include "defs.h"
57#include "pathnames.h" 53#include "pathnames.h"
58 54
59/* Data */ 55/* Data */
60#undef MAX 56#undef MAX
61#define MAX 1000 57#define MAX 1000
62static int menu_no = 0; 58static int menu_no = 0;
63static id_rec *menus[MAX]; 59static id_rec *menus[MAX];
64 60
65/* Other defines */ 61/* Other defines */
66#define OPT_SUB 1 62#define OPT_SUB 1
67#define OPT_ENDWIN 2 63#define OPT_ENDWIN 2
68#define OPT_EXIT 4 64#define OPT_EXIT 4
69 65
70 66
71/* get_menu returns a pointer to a newly created id_rec or an old one. */ 67/* get_menu returns a pointer to a newly created id_rec or an old one. */
72 68
73id_rec * 69id_rec *
74get_menu (char *name) 70get_menu(char *name)
75{ 71{
76 id_rec *temp; 72 id_rec *temp;
77 73
78 temp = find_id (root, name); 74 temp = find_id (root, name);
79 75
80 if (temp == NULL) { 76 if (temp == NULL) {
81 if (menu_no < MAX) { 77 if (menu_no < MAX) {
82 temp = (id_rec *) malloc (sizeof(id_rec)); 78 temp = (id_rec *)malloc(sizeof(id_rec));
83 temp->id = strdup(name); 79 temp->id = strdup(name);
84 temp->info = NULL; 80 temp->info = NULL;
85 temp->menu_no = menu_no; 81 temp->menu_no = menu_no;
86 menus[menu_no++] = temp; 82 menus[menu_no++] = temp;
87 insert_id (&root, temp); 83 insert_id(&root, temp);
88 } else { 84 } else {
89 (void) fprintf (stderr, "Too many menus. " 85 (void)fprintf(stderr, "Too many menus. "
90 "Increase MAX.\n"); 86 "Increase MAX.\n");
91 exit(1); 87 exit(1);
92 } 88 }
93 } 89 }
94 90
95 return temp; 91 return temp;
96} 92}
97 93
98 94
99/* Verify that all menus are defined. */ 95/* Verify that all menus are defined. */
100 
101void 96void
102check_defined (void) 97check_defined(void)
103{ 98{
104 int i; 99 int i;
105 100
106 for (i=0; i<menu_no; i++) 101 for (i = 0; i < menu_no; i++)
107 if (!menus[i]->info) 102 if (!menus[i]->info)
108 yyerror ("Menu '%s' undefined.", menus[i]->id); 103 yyerror ("Menu '%s' undefined.", menus[i]->id);
109} 104}
110 105
111 106
112/* Write out the menu file. */ 107/* Write out the menu file. */
113void 108void
114write_menu_file (char *initcode) 109write_menu_file(char *initcode)
115{ 110{
116 FILE *out_file; 111 FILE *out_file, *sys_file;
117 FILE *sys_file; 
118 int i, j; 112 int i, j;
119 char hname[1024]; 113 char hname[1024], cname[1024], sname[1024];
120 char cname[1024]; 114 char *sys_prefix, *tmpstr;
121 char sname[1024]; 115 int name_is_code, nlen, ch;
122 char *sys_prefix; 
123 char *tmpstr; 
124 int name_is_code; 
125 
126 int nlen; 
127 
128 int ch; 
129 
130 optn_info *toptn; 116 optn_info *toptn;
131 117
132 /* Generate file names */ 118 /* Generate file names */
133 snprintf (hname, 1024, "%s.h", out_name); 119 snprintf(hname, 1024, "%s.h", out_name);
134 nlen = strlen(hname); 120 nlen = strlen(hname);
135 if (hname[nlen-2] != '.' || hname[nlen-1] != 'h') { 121 if (hname[nlen-2] != '.' || hname[nlen-1] != 'h') {
136 (void) fprintf (stderr, "%s: name `%s` too long.\n", 122 (void)fprintf(stderr, "%s: name `%s` too long.\n",
137 prog_name, out_name); 123 prog_name, out_name);
138 exit(1); 124 exit(1);
139 } 125 }
140 snprintf (cname, 1024, "%s.c", out_name); 126 snprintf(cname, 1024, "%s.c", out_name);
141 127
142 /* Open the menu_sys file first. */ 128 /* Open the menu_sys file first. */
143 sys_prefix = getenv ("MENUDEF"); 129 sys_prefix = getenv("MENUDEF");
144 if (sys_prefix == NULL) 130 if (sys_prefix == NULL)
145 sys_prefix = _PATH_DEFSYSPREFIX; 131 sys_prefix = _PATH_DEFSYSPREFIX;
146 snprintf (sname, 1024, "%s/%s", sys_prefix, sys_name); 132 snprintf(sname, 1024, "%s/%s", sys_prefix, sys_name);
147 sys_file = fopen (sname, "r"); 133 sys_file = fopen (sname, "r");
148 if (sys_file == NULL) { 134 if (sys_file == NULL) {
149 (void) fprintf (stderr, "%s: could not open %s.\n", 135 (void)fprintf(stderr, "%s: could not open %s.\n",
150 prog_name, sname); 136 prog_name, sname);
151 exit (1); 137 exit(1);
152 } 138 }
153 139
154 /* Output the .h file first. */ 140 /* Output the .h file first. */
155 out_file = fopen (hname, "w"); 141 out_file = fopen(hname, "w");
156 if (out_file == NULL) { 142 if (out_file == NULL) {
157 (void) fprintf (stderr, "%s: could not open %s.\n", 143 (void)fprintf(stderr, "%s: could not open %s.\n",
158 prog_name, hname); 144 prog_name, hname);
159 exit (1); 145 exit(1);
160 } 146 }
161 147
162 /* Write it */ 148 /* Write it */
163 (void) fprintf (out_file, "%s", 149 (void)fprintf(out_file, "%s",
164 "/* menu system definitions. */\n" 150 "/* menu system definitions. */\n"
165 "\n" 151 "\n"
166 "#ifndef MENU_DEFS_H\n" 152 "#ifndef MENU_DEFS_H\n"
167 "#define MENU_DEFS_H\n" 153 "#define MENU_DEFS_H\n"
168 "#include <stdlib.h>\n" 154 "#include <stdlib.h>\n"
169 "#include <string.h>\n" 155 "#include <string.h>\n"
170 "#include <ctype.h>\n" 156 "#include <ctype.h>\n"
171 "#include <curses.h>\n\n" 157 "#include <curses.h>\n\n"
172 ); 158 );
173 159
174 if (do_msgxlat) 160 if (do_msgxlat)
175 (void)fprintf(out_file, "#define MSG_XLAT(x) msg_string(x)\n"); 161 (void)fprintf(out_file, "#define MSG_XLAT(x) msg_string(x)\n");
176 else 162 else
177 (void)fprintf(out_file, "#define MSG_XLAT(x) (x)\n"); 163 (void)fprintf(out_file, "#define MSG_XLAT(x) (x)\n");
178 if (do_dynamic) 164 if (do_dynamic)
179 (void)fprintf(out_file, "#define DYNAMIC_MENUS\n"); 165 (void)fprintf(out_file, "#define DYNAMIC_MENUS\n");
180 if (do_dynamic || do_msgxlat) 166 if (do_dynamic || do_msgxlat)
181 (void)fprintf(out_file, "\n"); 167 (void)fprintf(out_file, "\n");
182 168
183 (void)fprintf(out_file, 169 (void)fprintf(out_file,
184 "typedef struct menudesc menudesc;\n"  170 "typedef struct menudesc menudesc;\n"
185 "typedef struct menu_ent menu_ent;\n"  171 "typedef struct menu_ent menu_ent;\n"
186 "struct menu_ent {\n" 172 "struct menu_ent {\n"
187 " const char *opt_name;\n" 173 " const char *opt_name;\n"
188 " int opt_menu;\n" 174 " int opt_menu;\n"
189 " int opt_flags;\n" 175 " int opt_flags;\n"
190 " int (*opt_action)(menudesc *, void *);\n" 176 " int (*opt_action)(menudesc *, void *);\n"
191 "};\n\n" 177 "};\n\n"
192 "#define OPT_SUB 1\n" 178 "#define OPT_SUB 1\n"
193 "#define OPT_ENDWIN 2\n" 179 "#define OPT_ENDWIN 2\n"
194 "#define OPT_EXIT 4\n" 180 "#define OPT_EXIT 4\n"
195 "#define OPT_IGNORE 8\n" 181 "#define OPT_IGNORE 8\n"
196 "#define OPT_NOMENU -1\n\n" 182 "#define OPT_NOMENU -1\n\n"
197 "struct menudesc {\n" 183 "struct menudesc {\n"
198 " const char *title;\n" 184 " const char *title;\n"
199 " int y, x;\n" 185 " int y, x;\n"
200 " int h, w;\n" 186 " int h, w;\n"
201 " int mopt;\n" 187 " int mopt;\n"
202 " int numopts;\n" 188 " int numopts;\n"
203 " int cursel;\n" 189 " int cursel;\n"
204 " int topline;\n" 190 " int topline;\n"
205 " menu_ent *opts;\n" 191 " menu_ent *opts;\n"
206 " WINDOW *mw;\n" 192 " WINDOW *mw;\n"
207 " WINDOW *sv_mw;\n" 193 " WINDOW *sv_mw;\n"
208 " const char *helpstr;\n" 194 " const char *helpstr;\n"
209 " const char *exitstr;\n" 195 " const char *exitstr;\n"
210 " void (*post_act)(menudesc *, void *);\n" 196 " void (*post_act)(menudesc *, void *);\n"
211 " void (*exit_act)(menudesc *, void *);\n" 197 " void (*exit_act)(menudesc *, void *);\n"
212 " void (*draw_line)(menudesc *, int, void *);\n" 198 " void (*draw_line)(menudesc *, int, void *);\n"
213 "};\n" 199 "};\n"
214 "\n" 200 "\n"
215 "/* defines for mopt field. */\n" 201 "/* defines for mopt field. */\n"
216#define STR(x) #x 202#define STR(x) #x
217#define MC_OPT(x) "#define " #x " " STR(x) "\n" 203#define MC_OPT(x) "#define " #x " " STR(x) "\n"
218 MC_OPT(MC_NOEXITOPT) 204 MC_OPT(MC_NOEXITOPT)
219 MC_OPT(MC_NOBOX) 205 MC_OPT(MC_NOBOX)
220 MC_OPT(MC_SCROLL) 206 MC_OPT(MC_SCROLL)
221 MC_OPT(MC_NOSHORTCUT) 207 MC_OPT(MC_NOSHORTCUT)
222 MC_OPT(MC_NOCLEAR) 208 MC_OPT(MC_NOCLEAR)
223 MC_OPT(MC_DFLTEXIT) 209 MC_OPT(MC_DFLTEXIT)
224 MC_OPT(MC_ALWAYS_SCROLL) 210 MC_OPT(MC_ALWAYS_SCROLL)
225 MC_OPT(MC_SUBMENU) 211 MC_OPT(MC_SUBMENU)
226 MC_OPT(MC_VALID) 212 MC_OPT(MC_VALID)
227#undef MC_OPT 213#undef MC_OPT
228#undef STR 214#undef STR
229 ); 215 );
230 216
231 (void) fprintf (out_file, "%s", 217 (void)fprintf(out_file, "%s",
232 "\n" 218 "\n"
233 "/* Prototypes */\n" 219 "/* Prototypes */\n"
234 "int menu_init(void);\n" 220 "int menu_init(void);\n"
235 "void process_menu(int, void *);\n" 221 "void process_menu(int, void *);\n"
236 "__dead void __menu_initerror(void);\n" 222 "__dead void __menu_initerror(void);\n"
237 ); 223 );
238 224
239 if (do_dynamic) 225 if (do_dynamic)
240 (void) fprintf (out_file, "%s", 226 (void)fprintf(out_file, "%s",
241 "int new_menu(const char *, menu_ent *, int, \n" 227 "int new_menu(const char *, menu_ent *, int, \n"
242 "\tint, int, int, int, int,\n" 228 "\tint, int, int, int, int,\n"
243 "\tvoid (*)(menudesc *, void *), " 229 "\tvoid (*)(menudesc *, void *), "
244 "void (*)(menudesc *, int, void *),\n" 230 "void (*)(menudesc *, int, void *),\n"
245 "\tvoid (*)(menudesc *, void *), " 231 "\tvoid (*)(menudesc *, void *), "
246 "const char *, const char *);\n" 232 "const char *, const char *);\n"
247 "void free_menu(int);\n" 233 "void free_menu(int);\n"
248 "void set_menu_numopts(int, int);\n" 234 "void set_menu_numopts(int, int);\n"
249 ); 235 );
250 236
251 (void) fprintf (out_file, "\n/* Menu names */\n"); 237 (void)fprintf(out_file, "\n/* Menu names */\n");
252 for (i=0; i<menu_no; i++) { 238 for (i = 0; i < menu_no; i++)
253 (void) fprintf (out_file, "#define MENU_%s\t%d\n", 239 (void)fprintf(out_file, "#define MENU_%s\t%d\n",
254 menus[i]->id, i); 240 menus[i]->id, i);
255 } 
256 241
257 if (do_dynamic) 242 if (do_dynamic)
258 (void) fprintf (out_file, "\n#define DYN_MENU_START\t%d", 243 (void)fprintf(out_file, "\n#define DYN_MENU_START\t%d",
259 menu_no); 244 menu_no);
260 245
261 (void) fprintf (out_file, "\n#define MAX_STRLEN %d\n" 246 (void)fprintf (out_file, "\n#define MAX_STRLEN %d\n"
262 "#endif\n", max_strlen); 247 "#endif\n", max_strlen);
263 fclose (out_file); 248 fclose(out_file);
264 249
265 /* Now the C file */ 250 /* Now the C file */
266 out_file = fopen (cname, "w"); 251 out_file = fopen(cname, "w");
267 if (out_file == NULL) { 252 if (out_file == NULL) {
268 (void) fprintf (stderr, "%s: could not open %s.\n", 253 (void)fprintf(stderr, "%s: could not open %s.\n",
269 prog_name, cname); 254 prog_name, cname);
270 exit (1); 255 exit(1);
271 } 256 }
272 257
273 /* initial code */ 258 /* initial code */
274 fprintf (out_file, "#include \"%s\"\n\n", hname); 259 fprintf(out_file, "#include \"%s\"\n\n", hname);
275 fprintf (out_file, "%s\n\n", initcode); 260 fprintf(out_file, "%s\n\n", initcode);
276 261
277 /* data definitions */ 262 /* data definitions */
278 263
279 /* func defs */ 264 /* func defs */
280 for (i=0; i<menu_no; i++) { 265 for (i = 0; i < menu_no; i++) {
281 if (strlen(menus[i]->info->postact.code)) { 266 if (strlen(menus[i]->info->postact.code)) {
282 (void) fprintf (out_file, 267 (void)fprintf(out_file, "/*ARGSUSED*/\n"
283 "/*ARGSUSED*/\n" 268 "static void menu_%d_postact(menudesc *menu, void *arg)\n{\n", i);
284 "static void menu_%d_postact(menudesc *menu, void *arg)\n{\n", i); 
285 if (menus[i]->info->postact.endwin) 269 if (menus[i]->info->postact.endwin)
286 (void) fprintf (out_file, "\tendwin();\n"); 270 (void)fprintf(out_file, "\tendwin();\n");
287 (void) fprintf (out_file, 271 (void)fprintf(out_file, "\t%s\n}\n\n",
288 "\t%s\n}\n\n", 272 menus[i]->info->postact.code);
289 menus[i]->info->postact.code); 
290 } 273 }
291 if (strlen(menus[i]->info->exitact.code)) { 274 if (strlen(menus[i]->info->exitact.code)) {
292 (void) fprintf (out_file, 275 (void)fprintf(out_file, "/*ARGSUSED*/\n"
293 "/*ARGSUSED*/\n" 276 "static void menu_%d_exitact(menudesc *menu, void *arg)\n{\n", i);
294 "static void menu_%d_exitact(menudesc *menu, void *arg)\n{\n", i); 
295 if (menus[i]->info->exitact.endwin) 277 if (menus[i]->info->exitact.endwin)
296 (void) fprintf (out_file, "\tendwin();\n"); 278 (void)fprintf(out_file, "\tendwin();\n");
297 (void) fprintf (out_file, "\t%s\n}\n\n", 279 (void)fprintf(out_file, "\t%s\n}\n\n",
298 menus[i]->info->exitact.code); 280 menus[i]->info->exitact.code);
299 } 281 }
300 j = 0; 282 j = 0;
301 toptn = menus[i]->info->optns; 283 toptn = menus[i]->info->optns;
302 for (;toptn != NULL; j++, toptn = toptn->next) { 284 for (; toptn != NULL; j++, toptn = toptn->next) {
303 if (strlen(toptn->optact.code) == 0) 285 if (strlen(toptn->optact.code) == 0)
304 continue; 286 continue;
305 287
306 (void) fprintf (out_file, 288 (void)fprintf(out_file, "/*ARGSUSED*/\n"
307 "/*ARGSUSED*/\n" 289 "static int opt_act_%d_%d(menudesc *m, void *arg)\n"
308 "static int opt_act_%d_%d(menudesc *m, void *arg)\n" 290 "{\n\t%s\n\treturn %s;\n}\n\n",
309 "{\n\t%s\n\treturn %s;\n}\n\n", 291 i, j, toptn->optact.code,
310 i, j, toptn->optact.code, 292 (toptn->doexit ? "1" : "0"));
311 (toptn->doexit ? "1" : "0")); 
312 } 293 }
313 294
314 } 295 }
315 296
316 /* optentX */ 297 /* optentX */
317 for (i=0; i<menu_no; i++) { 298 for (i = 0; i < menu_no; i++) {
318 if (menus[i]->info->numopt > 53) { 299 if (menus[i]->info->numopt > 53) {
319 (void) fprintf (stderr, "Menu %s has " 300 (void)fprintf(stderr, "Menu %s has "
320 "too many options.\n", 301 "too many options.\n",
321 menus[i]->info->title); 302 menus[i]->info->title);
322 exit (1); 303 exit(1);
323 } 304 }
324 (void) fprintf (out_file, 305 (void)fprintf(out_file, "static menu_ent optent%d[] = {\n", i);
325 "static menu_ent optent%d[] = {\n", i); 
326 name_is_code = 0; 306 name_is_code = 0;
327 for (j = 0, toptn = menus[i]->info->optns; toptn; 307 for (j = 0, toptn = menus[i]->info->optns; toptn;
328 toptn = toptn->next, j++) { 308 toptn = toptn->next, j++) {
329 name_is_code += toptn->name_is_code; 309 name_is_code += toptn->name_is_code;
330 (void) fprintf (out_file, "\t{%s,%d,%d,", 310 (void)fprintf(out_file, "\t{%s,%d,%d,",
331 toptn->name_is_code ? "0" : toptn->name, 311 toptn->name_is_code ? "0" : toptn->name,
332 toptn->menu, 312 toptn->menu,
333 (toptn->issub ? OPT_SUB : 0) 313 (toptn->issub ? OPT_SUB : 0)
334 +(toptn->doexit ? OPT_EXIT : 0) 314 +(toptn->doexit ? OPT_EXIT : 0)
335 +(toptn->optact.endwin ? OPT_ENDWIN : 0)); 315 +(toptn->optact.endwin ? OPT_ENDWIN : 0));
336 if (strlen(toptn->optact.code))  316 if (strlen(toptn->optact.code))
337 (void) fprintf (out_file, "opt_act_%d_%d}", 317 (void)fprintf(out_file, "opt_act_%d_%d}", i, j);
338 i, j); 
339 else 318 else
340 (void) fprintf (out_file, "NULL}"); 319 (void)fprintf(out_file, "NULL}");
341 (void) fprintf (out_file, "%s\n", 320 (void)fprintf(out_file, "%s\n",
342 (toptn->next ? "," : "")); 321 (toptn->next ? "," : ""));
343 } 322 }
344 (void) fprintf (out_file, "\t};\n\n"); 323 (void)fprintf(out_file, "\t};\n\n");
345 324
346 if (name_is_code) { 325 if (name_is_code) {
347 menus[i]->info->name_is_code = 1; 326 menus[i]->info->name_is_code = 1;
348 fprintf(out_file, "static void menu_%d_legend(" 327 fprintf(out_file, "static void menu_%d_legend("
349 "menudesc *menu, int opt, void *arg)\n{\n" 328 "menudesc *menu, int opt, void *arg)\n{\n"
350 "\tswitch (opt) {\n", i); 329 "\tswitch (opt) {\n", i);
351 for (j = 0, toptn = menus[i]->info->optns; toptn; 330 for (j = 0, toptn = menus[i]->info->optns; toptn;
352 toptn = toptn->next, j++) { 331 toptn = toptn->next, j++) {
353 if (!toptn->name_is_code) 332 if (!toptn->name_is_code)
354 continue; 333 continue;
355 fprintf(out_file, "\tcase %d:\n\t\t{%s};\n" 334 fprintf(out_file, "\tcase %d:\n\t\t{%s};\n"
356 "\t\tbreak;\n", j, toptn->name); 335 "\t\tbreak;\n", j, toptn->name);
357 } 336 }
358 fprintf(out_file, "\t}\n}\n\n"); 337 fprintf(out_file, "\t}\n}\n\n");
359 } 338 }
360 } 339 }
361 340
362 341
363 /* menus */ 342 /* menus */
364 if (!do_dynamic) { 343 if (!do_dynamic)
365 (void) fprintf (out_file, "static int num_menus = %d;\n", menu_no); 344 (void)fprintf(out_file, "static int num_menus = %d;\n",
366 } 345 menu_no);
367 346
368 (void) fprintf (out_file, "static struct menudesc menu_def[] = {\n"); 347 (void)fprintf(out_file, "static struct menudesc menu_def[] = {\n");
369 for (i=0; i<menu_no; i++) { 348 for (i = 0; i < menu_no; i++) {
370 (void) fprintf (out_file, 349 (void)fprintf(out_file,
371 "\t{%s,%d,%d,%d,%d,%d,%d,0,0,optent%d,NULL,NULL,", 350 "\t{%s,%d,%d,%d,%d,%d,%d,0,0,optent%d,NULL,NULL,",
372 menus[i]->info->title, menus[i]->info->y, 351 menus[i]->info->title, menus[i]->info->y,
373 menus[i]->info->x, menus[i]->info->h, 352 menus[i]->info->x, menus[i]->info->h,
374 menus[i]->info->w, menus[i]->info->mopt, 353 menus[i]->info->w, menus[i]->info->mopt,
375 menus[i]->info->numopt, i); 354 menus[i]->info->numopt, i);
376 if (menus[i]->info->helpstr == NULL) 355 if (menus[i]->info->helpstr == NULL)
377 (void) fprintf (out_file, "NULL"); 356 (void)fprintf(out_file, "NULL");
378 else { 357 else {
379 tmpstr = menus[i]->info->helpstr; 358 tmpstr = menus[i]->info->helpstr;
380 if (*tmpstr != '"') 359 if (*tmpstr != '"')
381 (void)fprintf(out_file, "%s", tmpstr); 360 (void)fprintf(out_file, "%s", tmpstr);
382 else { 361 else {
383 /* Skip an initial newline. */ 362 /* Skip an initial newline. */
384 if (tmpstr[1] == '\n') 363 if (tmpstr[1] == '\n')
385 *++tmpstr = '"'; 364 *++tmpstr = '"';
386 (void) fprintf (out_file, "\n"); 365 (void)fprintf(out_file, "\n");
387 while (*tmpstr) { 366 while (*tmpstr) {
388 if (*tmpstr != '\n') { 367 if (*tmpstr != '\n') {
389 fputc (*tmpstr++, out_file); 368 fputc(*tmpstr++, out_file);
390 continue; 369 continue;
391 } 370 }
392 (void) fprintf (out_file, "\\n\"\n\""); 371 (void)fprintf(out_file, "\\n\"\n\"");
393 tmpstr++; 372 tmpstr++;
394 } 373 }
395 } 374 }
396 } 375 }
397 (void) fprintf (out_file, ","); 376 (void)fprintf(out_file, ",");
398 if (menus[i]->info->mopt & MC_NOEXITOPT) 377 if (menus[i]->info->mopt & MC_NOEXITOPT)
399 (void) fprintf (out_file, "NULL"); 378 (void) fprintf (out_file, "NULL");
400 else if (menus[i]->info->exitstr != NULL) 379 else if (menus[i]->info->exitstr != NULL)
401 (void) fprintf (out_file, "%s", 380 (void)fprintf(out_file, "%s", menus[i]->info->exitstr);
402 menus[i]->info->exitstr); 
403 else 381 else
404 (void) fprintf (out_file, "\"Exit\""); 382 (void)fprintf(out_file, "\"Exit\"");
405 if (strlen(menus[i]->info->postact.code)) 383 if (strlen(menus[i]->info->postact.code))
406 (void) fprintf (out_file, ",menu_%d_postact", i); 384 (void)fprintf(out_file, ",menu_%d_postact", i);
407 else 385 else
408 (void) fprintf (out_file, ",NULL"); 386 (void)fprintf(out_file, ",NULL");
409 if (strlen(menus[i]->info->exitact.code)) 387 if (strlen(menus[i]->info->exitact.code))
410 (void) fprintf (out_file, ",menu_%d_exitact", i); 388 (void)fprintf(out_file, ",menu_%d_exitact", i);
411 else 389 else
412 (void) fprintf (out_file, ",NULL"); 390 (void)fprintf(out_file, ",NULL");
413 if (menus[i]->info->name_is_code) 391 if (menus[i]->info->name_is_code)
414 (void) fprintf (out_file, ",menu_%d_legend", i); 392 (void)fprintf(out_file, ",menu_%d_legend", i);
415 else 393 else
416 (void) fprintf (out_file, ",NULL"); 394 (void)fprintf(out_file, ",NULL");
417 395
418 (void) fprintf (out_file, "},\n"); 396 (void)fprintf(out_file, "},\n");
419 397
420 } 398 }
421 (void) fprintf (out_file, "{NULL, 0, 0, 0, 0, 0, 0, 0, 0, " 399 (void)fprintf(out_file, "{NULL, 0, 0, 0, 0, 0, 0, 0, 0, "
422 "NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL}};\n\n"); 400 "NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL}};\n\n");
423 401
424 /* __menu_initerror: initscr failed. */ 402 /* __menu_initerror: initscr failed. */
425 (void) fprintf (out_file,  403 (void)fprintf(out_file,
426 "/* __menu_initerror: initscr failed. */\n" 404 "/* __menu_initerror: initscr failed. */\n"
427 "void __menu_initerror (void) {\n"); 405 "void __menu_initerror (void) {\n");
428 if (error_act.code == NULL) { 406 if (error_act.code == NULL) {
429 (void) fprintf (out_file, 407 (void)fprintf(out_file,
430 "\t(void) fprintf (stderr, " 408 "\t(void) fprintf (stderr, "
431 "\"%%s: Could not initialize curses\\n\", " 409 "\"%%s: Could not initialize curses\\n\", "
432 "getprogname());\n" 410 "getprogname());\n"
433 "\texit(1);\n" 411 "\texit(1);\n"
434 "}\n"); 412 "}\n");
435 } else { 413 } else {
436 if (error_act.endwin) 414 if (error_act.endwin)
437 (void) fprintf (out_file, "\tendwin();\n"); 415 (void)fprintf(out_file, "\tendwin();\n");
438 (void) fprintf (out_file, "%s\n}\n", error_act.code); 416 (void)fprintf(out_file, "%s\n}\n", error_act.code);
439 } 417 }
440 418
441 /* Copy menu_sys.def file. */ 419 /* Copy menu_sys.def file. */
442 while ((ch = fgetc(sys_file)) != '\014') /* Control-L */ 420 while ((ch = fgetc(sys_file)) != '\014') /* Control-L */
443 fputc(ch, out_file); 421 fputc(ch, out_file);
444 422
445 if (do_dynamic) { 423 if (do_dynamic) {
446 while ((ch = fgetc(sys_file)) != '\n') 424 while ((ch = fgetc(sys_file)) != '\n')
447 /* skip it */; 425 /* skip it */;
448 while ((ch = fgetc(sys_file)) != EOF) 426 while ((ch = fgetc(sys_file)) != EOF)
449 fputc(ch, out_file); 427 fputc(ch, out_file);
450 } 428 }
451  429 fclose(out_file);
452 fclose (out_file); 430 fclose(sys_file);
453 fclose (sys_file); 
454} 431}

cvs diff -r1.58 -r1.59 src/usr.bin/menuc/menu_sys.def (switch to unified diff)

--- src/usr.bin/menuc/menu_sys.def 2006/02/20 21:06:40 1.58
+++ src/usr.bin/menuc/menu_sys.def 2012/03/06 16:55:18 1.59
@@ -1,831 +1,827 @@ @@ -1,831 +1,827 @@
1/* $NetBSD: menu_sys.def,v 1.58 2006/02/20 21:06:40 dsl Exp $ */ 1/* $NetBSD: menu_sys.def,v 1.59 2012/03/06 16:55:18 mbalmer Exp $ */
2 2
3/* 3/*
4 * Copyright 1997 Piermont Information Systems Inc. 4 * Copyright 1997 Piermont Information Systems Inc.
5 * All rights reserved. 5 * All rights reserved.
6 * 6 *
7 * Written by Philip A. Nelson for Piermont Information Systems Inc. 7 * Written by Philip A. Nelson for Piermont Information Systems Inc.
8 * 8 *
9 * Redistribution and use in source and binary forms, with or without 9 * Redistribution and use in source and binary forms, with or without
10 * modification, are permitted provided that the following conditions 10 * modification, are permitted provided that the following conditions
11 * are met: 11 * are met:
12 * 1. Redistributions of source code must retain the above copyright 12 * 1. Redistributions of source code must retain the above copyright
13 * notice, this list of conditions and the following disclaimer. 13 * notice, this list of conditions and the following disclaimer.
14 * 2. Redistributions in binary form must reproduce the above copyright 14 * 2. Redistributions in binary form must reproduce the above copyright
15 * notice, this list of conditions and the following disclaimer in the 15 * notice, this list of conditions and the following disclaimer in the
16 * documentation and/or other materials provided with the distribution. 16 * documentation and/or other materials provided with the distribution.
17 * 3. All advertising materials mentioning features or use of this software 17 * 3. The name of Piermont Information Systems Inc. may not be used to endorse
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 18 * or promote products derived from this software without specific prior
23 * written permission. 19 * written permission.
24 * 20 *
25 * THIS SOFTWARE IS PROVIDED BY PIERMONT INFORMATION SYSTEMS INC. ``AS IS'' 21 * THIS SOFTWARE IS PROVIDED BY PIERMONT INFORMATION SYSTEMS INC. ``AS IS''
26 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 22 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
27 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 23 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
28 * ARE DISCLAIMED. IN NO EVENT SHALL PIERMONT INFORMATION SYSTEMS INC. BE  24 * ARE DISCLAIMED. IN NO EVENT SHALL PIERMONT INFORMATION SYSTEMS INC. BE
29 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR  25 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
30 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF  26 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
31 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 27 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
32 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 28 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
33 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 29 * 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  30 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
35 * THE POSSIBILITY OF SUCH DAMAGE. 31 * THE POSSIBILITY OF SUCH DAMAGE.
36 * 32 *
37 */ 33 */
38 34
39/* menu_sys.defs -- Menu system standard routines. */ 35/* menu_sys.defs -- Menu system standard routines. */
40 36
41#include <string.h> 37#include <string.h>
42#include <ctype.h> 38#include <ctype.h>
43 39
44#define REQ_EXECUTE 1000 40#define REQ_EXECUTE 1000
45#define REQ_NEXT_ITEM 1001 41#define REQ_NEXT_ITEM 1001
46#define REQ_PREV_ITEM 1002 42#define REQ_PREV_ITEM 1002
47#define REQ_REDISPLAY 1003 43#define REQ_REDISPLAY 1003
48#define REQ_SCROLLDOWN 1004 44#define REQ_SCROLLDOWN 1004
49#define REQ_SCROLLUP 1005 45#define REQ_SCROLLUP 1005
50#define REQ_HELP 1006 46#define REQ_HELP 1006
51 47
52/* Macros */ 48/* Macros */
53#define MAX(x,y) ((x)>(y)?(x):(y)) 49#define MAX(x,y) ((x)>(y)?(x):(y))
54#define MIN(x,y) ((x)<(y)?(x):(y)) 50#define MIN(x,y) ((x)<(y)?(x):(y))
55 51
56/* Initialization state. */ 52/* Initialization state. */
57static int __menu_init = 0; 53static int __menu_init = 0;
58static int max_lines = 0, max_cols = 0; 54static int max_lines = 0, max_cols = 0;
59#ifndef scrolltext 55#ifndef scrolltext
60static const char *scrolltext = " <: page up, >: page down"; 56static const char *scrolltext = " <: page up, >: page down";
61#endif 57#endif
62 58
63#ifdef DYNAMIC_MENUS 59#ifdef DYNAMIC_MENUS
64static int num_menus = 0; 60static int num_menus = 0;
65#define DYN_INIT_NUM 32 61#define DYN_INIT_NUM 32
66static menudesc **menu_list; 62static menudesc **menu_list;
67#define MENUS(n) (*(menu_list[n])) 63#define MENUS(n) (*(menu_list[n]))
68#else 64#else
69#define MENUS(n) (menu_def[n]) 65#define MENUS(n) (menu_def[n])
70#endif 66#endif
71 67
72/* prototypes for in here! */ 68/* prototypes for in here! */
73static void init_menu(menudesc *m); 69static void init_menu(menudesc *m);
74static char opt_ch(menudesc *m, int op_no); 70static char opt_ch(menudesc *m, int op_no);
75static void draw_menu(menudesc *m, void *arg); 71static void draw_menu(menudesc *m, void *arg);
76static void process_help(menudesc *m); 72static void process_help(menudesc *m);
77static void process_req(menudesc *m, void *arg, int req); 73static void process_req(menudesc *m, void *arg, int req);
78static int menucmd(WINDOW *w); 74static int menucmd(WINDOW *w);
79 75
80#ifndef NULL 76#ifndef NULL
81#define NULL 0 77#define NULL 0
82#endif 78#endif
83 79
84/* menu system processing routines */ 80/* menu system processing routines */
85#define mbeep() (void)fputc('\a', stderr) 81#define mbeep() (void)fputc('\a', stderr)
86 82
87static int 83static int
88menucmd(WINDOW *w) 84menucmd(WINDOW *w)
89{ 85{
90 int ch; 86 int ch;
91 87
92 while (TRUE) { 88 while (TRUE) {
93 ch = wgetch(w); 89 ch = wgetch(w);
94  90
95 switch (ch) { 91 switch (ch) {
96 case '\n': 92 case '\n':
97 return REQ_EXECUTE; 93 return REQ_EXECUTE;
98 case '\016': /* Control-P */ 94 case '\016': /* Control-P */
99 case KEY_DOWN: 95 case KEY_DOWN:
100 return REQ_NEXT_ITEM; 96 return REQ_NEXT_ITEM;
101 case '\020': /* Control-N */ 97 case '\020': /* Control-N */
102 case KEY_UP: 98 case KEY_UP:
103 return REQ_PREV_ITEM; 99 return REQ_PREV_ITEM;
104 case '\014': /* Control-L */ 100 case '\014': /* Control-L */
105 return REQ_REDISPLAY; 101 return REQ_REDISPLAY;
106 case '<': 102 case '<':
107 case '\010': /* Control-H (backspace) */ 103 case '\010': /* Control-H (backspace) */
108 case KEY_PPAGE: 104 case KEY_PPAGE:
109 case KEY_LEFT: 105 case KEY_LEFT:
110 return REQ_SCROLLUP; 106 return REQ_SCROLLUP;
111 case '\026': /* Control-V */ 107 case '\026': /* Control-V */
112 case '>': 108 case '>':
113 case ' ': 109 case ' ':
114 case KEY_NPAGE: 110 case KEY_NPAGE:
115 case KEY_RIGHT: 111 case KEY_RIGHT:
116 return REQ_SCROLLDOWN; 112 return REQ_SCROLLDOWN;
117 case '?': 113 case '?':
118 return REQ_HELP; 114 return REQ_HELP;
119 case '\033': /* esc-v is scroll down */ 115 case '\033': /* esc-v is scroll down */
120 ch = wgetch(w); 116 ch = wgetch(w);
121 if (ch == 'v') 117 if (ch == 'v')
122 return REQ_SCROLLUP; 118 return REQ_SCROLLUP;
123 else 119 else
124 ch = 0; /* zap char so we beep */ 120 ch = 0; /* zap char so we beep */
125 } 121 }
126  122
127 if (isalpha(ch))  123 if (isalpha(ch))
128 return ch; 124 return ch;
129 125
130 mbeep(); 126 mbeep();
131 wrefresh(w); 127 wrefresh(w);
132 } 128 }
133} 129}
134 130
135static void 131static void
136init_menu(menudesc *m) 132init_menu(menudesc *m)
137{ 133{
138 int wmax; 134 int wmax;
139 int hadd, wadd, exithadd; 135 int hadd, wadd, exithadd;
140 int i; 136 int i;
141 int x, y, w; 137 int x, y, w;
142 const char *title, *tp, *ep; 138 const char *title, *tp, *ep;
143 139
144 x = m->x; 140 x = m->x;
145 y = m->y; 141 y = m->y;
146 w = m->w; 142 w = m->w;
147 wmax = 0; 143 wmax = 0;
148 hadd = ((m->mopt & MC_NOBOX) ? 0 : 2); 144 hadd = ((m->mopt & MC_NOBOX) ? 0 : 2);
149 wadd = ((m->mopt & MC_NOBOX) ? 2 : 4); 145 wadd = ((m->mopt & MC_NOBOX) ? 2 : 4);
150 if (!(m->mopt & MC_NOSHORTCUT)) 146 if (!(m->mopt & MC_NOSHORTCUT))
151 wadd += 3; 147 wadd += 3;
152 148
153 if (m->title && *(title = MSG_XLAT(m->title)) != 0) { 149 if (m->title && *(title = MSG_XLAT(m->title)) != 0) {
154 /* Allow multiple line titles */ 150 /* Allow multiple line titles */
155 for (tp = title; (ep = strchr(tp, '\n')); tp = ep + 1) { 151 for (tp = title; (ep = strchr(tp, '\n')); tp = ep + 1) {
156 i = ep - tp; 152 i = ep - tp;
157 wmax = MAX(wmax, i); 153 wmax = MAX(wmax, i);
158 hadd++; 154 hadd++;
159 } 155 }
160 hadd++; 156 hadd++;
161 i = strlen(tp); 157 i = strlen(tp);
162 wmax = MAX(wmax, i); 158 wmax = MAX(wmax, i);
163 if (i != 0) 159 if (i != 0)
164 hadd++; 160 hadd++;
165 } else { 161 } else {
166 m->title = NULL; 162 m->title = NULL;
167 title = "untitled"; 163 title = "untitled";
168 } 164 }
169 exithadd = ((m->mopt & MC_NOEXITOPT) ? 0 : 1); 165 exithadd = ((m->mopt & MC_NOEXITOPT) ? 0 : 1);
170 166
171#ifdef MSG_DEFS_H 167#ifdef MSG_DEFS_H
172 if (y < 0) { 168 if (y < 0) {
173 /* put menu box below message text */ 169 /* put menu box below message text */
174 y = -y; 170 y = -y;
175 i = msg_row(); 171 i = msg_row();
176 if (i > y) 172 if (i > y)
177 y = i; 173 y = i;
178 } 174 }
179#endif 175#endif
180 176
181 /* Calculate h? h == number of visible options. */ 177 /* Calculate h? h == number of visible options. */
182 if (m->h == 0) 178 if (m->h == 0)
183 m->h = m->numopts + exithadd; 179 m->h = m->numopts + exithadd;
184 180
185 if (m->h > max_lines - y - hadd) { 181 if (m->h > max_lines - y - hadd) {
186 /* Not enough space for all the options */ 182 /* Not enough space for all the options */
187 if (m->h <= 4 || !(m->mopt & (MC_SCROLL | MC_ALWAYS_SCROLL))) { 183 if (m->h <= 4 || !(m->mopt & (MC_SCROLL | MC_ALWAYS_SCROLL))) {
188 /* move menu up screen */ 184 /* move menu up screen */
189 y = max_lines - hadd - m->h; 185 y = max_lines - hadd - m->h;
190 if (y < 0) 186 if (y < 0)
191 y = 0; 187 y = 0;
192 } 188 }
193 m->h = max_lines - y - hadd; 189 m->h = max_lines - y - hadd;
194 } 190 }
195 191
196 if (m->h < m->numopts + exithadd || m->mopt & MC_ALWAYS_SCROLL) { 192 if (m->h < m->numopts + exithadd || m->mopt & MC_ALWAYS_SCROLL) {
197 /* We need to add the scroll text...  193 /* We need to add the scroll text...
198 * The used to be a check for MC_SCROLL here, but it is 194 * The used to be a check for MC_SCROLL here, but it is
199 * fairly pointless - you just don't want the program 195 * fairly pointless - you just don't want the program
200 * to exit on this sort of error. 196 * to exit on this sort of error.
201 */ 197 */
202 if (m->h < 3) { 198 if (m->h < 3) {
203 endwin(); 199 endwin();
204 (void)fprintf(stderr, 200 (void)fprintf(stderr,
205 "Window too short (m->h %d, m->numopts %d, exithadd %d, y %d, max_lines %d, hadd %d) for menu \"%.30s\"\n", 201 "Window too short (m->h %d, m->numopts %d, exithadd %d, y %d, max_lines %d, hadd %d) for menu \"%.30s\"\n",
206 m->h, m->numopts, exithadd, y, max_lines, hadd, 202 m->h, m->numopts, exithadd, y, max_lines, hadd,
207 title); 203 title);
208 exit(1); 204 exit(1);
209 } 205 }
210 hadd++; 206 hadd++;
211 m->h = MIN(m->h, max_lines - y - hadd); 207 m->h = MIN(m->h, max_lines - y - hadd);
212 i = strlen(scrolltext); 208 i = strlen(scrolltext);
213 wmax = MAX(wmax, i); 209 wmax = MAX(wmax, i);
214 } 210 }
215 211
216 /* Calculate w? */ 212 /* Calculate w? */
217 if (w == 0) { 213 if (w == 0) {
218 int l; 214 int l;
219 for (i = 0; i < m->numopts; i++) { 215 for (i = 0; i < m->numopts; i++) {
220 tp = MSG_XLAT(m->opts[i].opt_name); 216 tp = MSG_XLAT(m->opts[i].opt_name);
221 if (tp == NULL) 217 if (tp == NULL)
222 continue; 218 continue;
223 l = strlen(tp); 219 l = strlen(tp);
224 wmax = MAX(wmax, l); 220 wmax = MAX(wmax, l);
225 } 221 }
226 w = wmax; 222 w = wmax;
227 } 223 }
228 224
229 /* check and adjust for screen fit */ 225 /* check and adjust for screen fit */
230 if (w + wadd > max_cols) { 226 if (w + wadd > max_cols) {
231 endwin(); 227 endwin();
232 (void)fprintf(stderr, 228 (void)fprintf(stderr,
233 "Screen too narrow (%d + %d > %d) for menu \"%s\"\n", 229 "Screen too narrow (%d + %d > %d) for menu \"%s\"\n",
234 w, wadd, max_cols, title); 230 w, wadd, max_cols, title);
235 exit(1); 231 exit(1);
236 232
237 } 233 }
238 234
239 if (x == -1) 235 if (x == -1)
240 x = (max_cols - (w + wadd)) / 2; /* center */ 236 x = (max_cols - (w + wadd)) / 2; /* center */
241 else if (x + w + wadd > max_cols) 237 else if (x + w + wadd > max_cols)
242 x = max_cols - (w + wadd); /* right align */ 238 x = max_cols - (w + wadd); /* right align */
243 239
244 if (y == 0) { 240 if (y == 0) {
245 /* Center - rather than top */ 241 /* Center - rather than top */
246 y = (max_lines - hadd - m->h) / 2; 242 y = (max_lines - hadd - m->h) / 2;
247 } 243 }
248 244
249 /* Get the windows. */ 245 /* Get the windows. */
250 m->mw = newwin(m->h + hadd, w + wadd, y, x); 246 m->mw = newwin(m->h + hadd, w + wadd, y, x);
251 247
252 if (m->mw == NULL) { 248 if (m->mw == NULL) {
253 endwin(); 249 endwin();
254 (void)fprintf(stderr, 250 (void)fprintf(stderr,
255 "Could not create window (%d + %d, %d + %d, %d, %d) for menu \"%s\"\n", 251 "Could not create window (%d + %d, %d + %d, %d, %d) for menu \"%s\"\n",
256 m->h, hadd, w, wadd, y, x, title); 252 m->h, hadd, w, wadd, y, x, title);
257 exit(1); 253 exit(1);
258 } 254 }
259 keypad(m->mw, TRUE); /* enable multi-key assembling for win */ 255 keypad(m->mw, TRUE); /* enable multi-key assembling for win */
260 256
261 /* XXX is it even worth doing this right? */ 257 /* XXX is it even worth doing this right? */
262 if (has_colors()) { 258 if (has_colors()) {
263 wbkgd(m->mw, COLOR_PAIR(1)); 259 wbkgd(m->mw, COLOR_PAIR(1));
264 wattrset(m->mw, COLOR_PAIR(1)); 260 wattrset(m->mw, COLOR_PAIR(1));
265 } 261 }
266 262
267 if (m->mopt & MC_SUBMENU) { 263 if (m->mopt & MC_SUBMENU) {
268 /* Keep a copy of what is on the screen under the window */ 264 /* Keep a copy of what is on the screen under the window */
269 m->sv_mw = newwin(m->h + hadd, w + wadd, y, x); 265 m->sv_mw = newwin(m->h + hadd, w + wadd, y, x);
270 /* 266 /*
271 * cursrc contains post-doupdate() data, not post-refresh() 267 * cursrc contains post-doupdate() data, not post-refresh()
272 * data so we must call doupdate to ensure we save the 268 * data so we must call doupdate to ensure we save the
273 * correct data. Avoids PR 26660. 269 * correct data. Avoids PR 26660.
274 */ 270 */
275 doupdate(); 271 doupdate();
276 if (m->sv_mw) 272 if (m->sv_mw)
277 overwrite(curscr, m->sv_mw); 273 overwrite(curscr, m->sv_mw);
278 } 274 }
279} 275}
280 276
281static char 277static char
282opt_ch(menudesc *m, int op_no) 278opt_ch(menudesc *m, int op_no)
283{ 279{
284 char c; 280 char c;
285 281
286 if (op_no == m->numopts) 282 if (op_no == m->numopts)
287 return 'x'; 283 return 'x';
288 284
289 if (op_no < 25) { 285 if (op_no < 25) {
290 c = 'a' + op_no; 286 c = 'a' + op_no;
291 if (c >= 'x') 287 if (c >= 'x')
292 c++; 288 c++;
293 } else  289 } else
294 c = 'A' + op_no - 25; 290 c = 'A' + op_no - 25;
295 return c; 291 return c;
296} 292}
297 293
298static void 294static void
299draw_menu_line(menudesc *m, int opt, int cury, void *arg, const char *text) 295draw_menu_line(menudesc *m, int opt, int cury, void *arg, const char *text)
300{ 296{
301 int hasbox = m->mopt & MC_NOBOX ? 0 : 1; 297 int hasbox = m->mopt & MC_NOBOX ? 0 : 1;
302 298
303 if (m->cursel == opt) { 299 if (m->cursel == opt) {
304 mvwaddstr(m->mw, cury, hasbox, ">"); 300 mvwaddstr(m->mw, cury, hasbox, ">");
305 wstandout(m->mw); 301 wstandout(m->mw);
306 } else 302 } else
307 mvwaddstr(m->mw, cury, hasbox, " "); 303 mvwaddstr(m->mw, cury, hasbox, " ");
308 if (!(m->mopt & MC_NOSHORTCUT)) 304 if (!(m->mopt & MC_NOSHORTCUT))
309 wprintw(m->mw, "%c: ", opt_ch(m, opt)); 305 wprintw(m->mw, "%c: ", opt_ch(m, opt));
310 306
311 if (!text && m->draw_line) 307 if (!text && m->draw_line)
312 m->draw_line(m, opt, arg); 308 m->draw_line(m, opt, arg);
313 else 309 else
314 waddstr(m->mw, MSG_XLAT(text)); 310 waddstr(m->mw, MSG_XLAT(text));
315 if (m->cursel == opt) 311 if (m->cursel == opt)
316 wstandend(m->mw); 312 wstandend(m->mw);
317} 313}
318 314
319static void 315static void
320draw_menu(menudesc *m, void *arg) 316draw_menu(menudesc *m, void *arg)
321{ 317{
322 int opt; 318 int opt;
323 int hasbox, cury, maxy; 319 int hasbox, cury, maxy;
324 int tadd; 320 int tadd;
325 int hasexit = (m->mopt & MC_NOEXITOPT ? 0 : 1); 321 int hasexit = (m->mopt & MC_NOEXITOPT ? 0 : 1);
326 const char *tp, *ep; 322 const char *tp, *ep;
327  323
328 hasbox = (m->mopt & MC_NOBOX ? 0 : 1); 324 hasbox = (m->mopt & MC_NOBOX ? 0 : 1);
329 325
330 /* Clear the window */ 326 /* Clear the window */
331 wclear(m->mw); 327 wclear(m->mw);
332 328
333 tadd = hasbox; 329 tadd = hasbox;
334 if (m->title) { 330 if (m->title) {
335 for (tp = MSG_XLAT(m->title); ; tp = ep + 1) { 331 for (tp = MSG_XLAT(m->title); ; tp = ep + 1) {
336 ep = strchr(tp , '\n'); 332 ep = strchr(tp , '\n');
337 mvwaddnstr(m->mw, tadd++, hasbox + 1, tp, 333 mvwaddnstr(m->mw, tadd++, hasbox + 1, tp,
338 ep ? ep - tp : -1); 334 ep ? ep - tp : -1);
339 if (ep == NULL || *ep == 0) 335 if (ep == NULL || *ep == 0)
340 break; 336 break;
341 } 337 }
342 tadd++; 338 tadd++;
343 } 339 }
344 340
345 cury = tadd; 341 cury = tadd;
346 maxy = getmaxy(m->mw) - hasbox; 342 maxy = getmaxy(m->mw) - hasbox;
347 if (m->numopts + hasexit > m->h) 343 if (m->numopts + hasexit > m->h)
348 /* allow for scroll text */ 344 /* allow for scroll text */
349 maxy--; 345 maxy--;
350 346
351 if (m->cursel == -1) { 347 if (m->cursel == -1) {
352 m->cursel = m->numopts; 348 m->cursel = m->numopts;
353 if (m->h <= m->numopts) 349 if (m->h <= m->numopts)
354 m->topline = m->numopts + 1 - m->h; 350 m->topline = m->numopts + 1 - m->h;
355 } 351 }
356 352
357 while (m->cursel >= m->topline + m->h) 353 while (m->cursel >= m->topline + m->h)
358 m->topline = MIN(m->topline + m->h, 354 m->topline = MIN(m->topline + m->h,
359 m->numopts + hasexit - m->h); 355 m->numopts + hasexit - m->h);
360 while (m->cursel < m->topline) 356 while (m->cursel < m->topline)
361 m->topline = MAX(0, m->topline - m->h); 357 m->topline = MAX(0, m->topline - m->h);
362 358
363 for (opt = m->topline; opt < m->numopts; opt++) { 359 for (opt = m->topline; opt < m->numopts; opt++) {
364 if (cury >= maxy) 360 if (cury >= maxy)
365 break; 361 break;
366 draw_menu_line(m, opt, cury++, arg, m->opts[opt].opt_name); 362 draw_menu_line(m, opt, cury++, arg, m->opts[opt].opt_name);
367 } 363 }
368 364
369 /* Add the exit option. */ 365 /* Add the exit option. */
370 if (!(m->mopt & MC_NOEXITOPT)) { 366 if (!(m->mopt & MC_NOEXITOPT)) {
371 if (cury < maxy) 367 if (cury < maxy)
372 draw_menu_line(m, m->numopts, cury++, arg, m->exitstr); 368 draw_menu_line(m, m->numopts, cury++, arg, m->exitstr);
373 else 369 else
374 opt = 0; 370 opt = 0;
375 } 371 }
376 372
377 /* Add the scroll line */ 373 /* Add the scroll line */
378 if (opt != m->numopts || m->topline != 0) 374 if (opt != m->numopts || m->topline != 0)
379 mvwaddstr(m->mw, cury, hasbox, scrolltext); 375 mvwaddstr(m->mw, cury, hasbox, scrolltext);
380 376
381 /* Add the box. */ 377 /* Add the box. */
382 if (!(m->mopt & MC_NOBOX)) 378 if (!(m->mopt & MC_NOBOX))
383 box(m->mw, 0, 0); 379 box(m->mw, 0, 0);
384 380
385 wmove(m->mw, tadd + m->cursel - m->topline, hasbox); 381 wmove(m->mw, tadd + m->cursel - m->topline, hasbox);
386 wrefresh(m->mw); 382 wrefresh(m->mw);
387} 383}
388 384
389 385
390static void 386static void
391/*ARGSUSED*/ 387/*ARGSUSED*/
392process_help(menudesc *m) 388process_help(menudesc *m)
393{ 389{
394 const char *help = m->helpstr; 390 const char *help = m->helpstr;
395 WINDOW *sv_curscr; 391 WINDOW *sv_curscr;
396 int lineoff = 0; 392 int lineoff = 0;
397 int curoff = 0; 393 int curoff = 0;
398 int again; 394 int again;
399 int winin; 395 int winin;
400 396
401 /* Is there help? */ 397 /* Is there help? */
402 if (!help) { 398 if (!help) {
403 mbeep(); 399 mbeep();
404 return; 400 return;
405 } 401 }
406 sv_curscr = newwin(getmaxy(curscr), getmaxx(curscr), 0, 0); 402 sv_curscr = newwin(getmaxy(curscr), getmaxx(curscr), 0, 0);
407 if (!sv_curscr) { 403 if (!sv_curscr) {
408 mbeep(); 404 mbeep();
409 return; 405 return;
410 } 406 }
411 /* 407 /*
412 * Save screen contents so we can restore before returning. 408 * Save screen contents so we can restore before returning.
413 * cursrc contains post-doupdate() data, not post-refresh() 409 * cursrc contains post-doupdate() data, not post-refresh()
414 * data so we must call doupdate to ensure we save the 410 * data so we must call doupdate to ensure we save the
415 * correct data. Avoids PR 26660. 411 * correct data. Avoids PR 26660.
416 */ 412 */
417 doupdate(); 413 doupdate();
418 overwrite(curscr, sv_curscr); 414 overwrite(curscr, sv_curscr);
419 touchwin(stdscr); 415 touchwin(stdscr);
420 416
421 help = MSG_XLAT(help); 417 help = MSG_XLAT(help);
422 /* Display the help information. */ 418 /* Display the help information. */
423 do { 419 do {
424 if (lineoff < curoff) { 420 if (lineoff < curoff) {
425 help = MSG_XLAT(m->helpstr); 421 help = MSG_XLAT(m->helpstr);
426 curoff = 0; 422 curoff = 0;
427 } 423 }
428 while (*help && curoff < lineoff) { 424 while (*help && curoff < lineoff) {
429 if (*help == '\n') 425 if (*help == '\n')
430 curoff++; 426 curoff++;
431 help++; 427 help++;
432 } 428 }
433  429
434 wclear(stdscr); 430 wclear(stdscr);
435 mvwaddstr(stdscr, 0, 0,  431 mvwaddstr(stdscr, 0, 0,
436 "Help: exit: x, page up: u <, page down: d >"); 432 "Help: exit: x, page up: u <, page down: d >");
437 mvwaddstr(stdscr, 2, 0, help); 433 mvwaddstr(stdscr, 2, 0, help);
438 wmove(stdscr, 1, 0); 434 wmove(stdscr, 1, 0);
439 wrefresh(stdscr); 435 wrefresh(stdscr);
440 436
441 do { 437 do {
442 winin = wgetch(stdscr); 438 winin = wgetch(stdscr);
443 if (winin < KEY_MIN) 439 if (winin < KEY_MIN)
444 winin = tolower(winin); 440 winin = tolower(winin);
445 again = 0; 441 again = 0;
446 switch (winin) { 442 switch (winin) {
447 case '<': 443 case '<':
448 case 'u': 444 case 'u':
449 case KEY_UP: 445 case KEY_UP:
450 case KEY_LEFT: 446 case KEY_LEFT:
451 case KEY_PPAGE: 447 case KEY_PPAGE:
452 if (lineoff) 448 if (lineoff)
453 lineoff -= max_lines - 2; 449 lineoff -= max_lines - 2;
454 else 450 else
455 again = 1; 451 again = 1;
456 break; 452 break;
457 case '>': 453 case '>':
458 case 'd': 454 case 'd':
459 case KEY_DOWN: 455 case KEY_DOWN:
460 case KEY_RIGHT: 456 case KEY_RIGHT:
461 case KEY_NPAGE: 457 case KEY_NPAGE:
462 if (*help) 458 if (*help)
463 lineoff += max_lines - 2; 459 lineoff += max_lines - 2;
464 else 460 else
465 again = 1; 461 again = 1;
466 break; 462 break;
467 case 'q': 463 case 'q':
468 break; 464 break;
469 case 'x': 465 case 'x':
470 winin = 'q'; 466 winin = 'q';
471 break; 467 break;
472 default: 468 default:
473 again = 1; 469 again = 1;
474 } 470 }
475 if (again) 471 if (again)
476 mbeep(); 472 mbeep();
477 } while (again); 473 } while (again);
478 } while (winin != 'q'); 474 } while (winin != 'q');
479 475
480 /* Restore the original screen contents */ 476 /* Restore the original screen contents */
481 touchwin(sv_curscr); 477 touchwin(sv_curscr);
482 wnoutrefresh(sv_curscr); 478 wnoutrefresh(sv_curscr);
483 delwin(sv_curscr); 479 delwin(sv_curscr);
484 480
485 /* Some code thinks that wrefresh(stdout) is a good idea... */ 481 /* Some code thinks that wrefresh(stdout) is a good idea... */
486 wclear(stdscr); 482 wclear(stdscr);
487} 483}
488 484
489static void 485static void
490process_req(menudesc *m, void *arg, int req) 486process_req(menudesc *m, void *arg, int req)
491{ 487{
492 int ch; 488 int ch;
493 int hasexit = (m->mopt & MC_NOEXITOPT ? 0 : 1); 489 int hasexit = (m->mopt & MC_NOEXITOPT ? 0 : 1);
494 490
495 switch(req) { 491 switch(req) {
496 492
497 case REQ_EXECUTE: 493 case REQ_EXECUTE:
498 return; 494 return;
499 495
500 case REQ_NEXT_ITEM: 496 case REQ_NEXT_ITEM:
501 ch = m->cursel; 497 ch = m->cursel;
502 for (;;) { 498 for (;;) {
503 ch++; 499 ch++;
504 if (ch >= m->numopts + hasexit) { 500 if (ch >= m->numopts + hasexit) {
505 mbeep(); 501 mbeep();
506 return; 502 return;
507 } 503 }
508 if (hasexit && ch == m->numopts) 504 if (hasexit && ch == m->numopts)
509 break; 505 break;
510 if (!(m->opts[ch].opt_flags & OPT_IGNORE)) 506 if (!(m->opts[ch].opt_flags & OPT_IGNORE))
511 break; 507 break;
512 } 508 }
513 m->cursel = ch; 509 m->cursel = ch;
514 if (m->cursel >= m->topline + m->h) 510 if (m->cursel >= m->topline + m->h)
515 m->topline = m->cursel - m->h + 1; 511 m->topline = m->cursel - m->h + 1;
516 break; 512 break;
517 513
518 case REQ_PREV_ITEM: 514 case REQ_PREV_ITEM:
519 ch = m->cursel; 515 ch = m->cursel;
520 for (;;) { 516 for (;;) {
521 if (ch <= 0) { 517 if (ch <= 0) {
522 mbeep(); 518 mbeep();
523 return; 519 return;
524 } 520 }
525 ch--; 521 ch--;
526 if (!(m->opts[ch].opt_flags & OPT_IGNORE)) 522 if (!(m->opts[ch].opt_flags & OPT_IGNORE))
527 break; 523 break;
528 } 524 }
529 m->cursel = ch; 525 m->cursel = ch;
530 if (m->cursel < m->topline) 526 if (m->cursel < m->topline)
531 m->topline = m->cursel; 527 m->topline = m->cursel;
532 break; 528 break;
533 529
534 case REQ_HELP: 530 case REQ_HELP:
535 process_help(m); 531 process_help(m);
536 break; 532 break;
537 533
538 case REQ_REDISPLAY: 534 case REQ_REDISPLAY:
539 endwin(); 535 endwin();
540 doupdate(); 536 doupdate();
541 break; 537 break;
542 538
543 case REQ_SCROLLUP: 539 case REQ_SCROLLUP:
544 if (m->cursel == 0) { 540 if (m->cursel == 0) {
545 mbeep(); 541 mbeep();
546 return; 542 return;
547 } 543 }
548 m->topline = MAX(0, m->topline - m->h); 544 m->topline = MAX(0, m->topline - m->h);
549 m->cursel = MAX(0, m->cursel - m->h); 545 m->cursel = MAX(0, m->cursel - m->h);
550 wclear(m->mw); 546 wclear(m->mw);
551 break; 547 break;
552 548
553 case REQ_SCROLLDOWN: 549 case REQ_SCROLLDOWN:
554 if (m->cursel >= m->numopts + hasexit - 1) { 550 if (m->cursel >= m->numopts + hasexit - 1) {
555 mbeep(); 551 mbeep();
556 return; 552 return;
557 } 553 }
558 m->topline = MIN(m->topline + m->h, 554 m->topline = MIN(m->topline + m->h,
559 MAX(m->numopts + hasexit - m->h, 0)); 555 MAX(m->numopts + hasexit - m->h, 0));
560 m->cursel = MIN(m->numopts + hasexit - 1, m->cursel + m->h); 556 m->cursel = MIN(m->numopts + hasexit - 1, m->cursel + m->h);
561 wclear(m->mw); 557 wclear(m->mw);
562 break; 558 break;
563 559
564 default: 560 default:
565 ch = req; 561 ch = req;
566 if (ch == 'x' && hasexit) { 562 if (ch == 'x' && hasexit) {
567 m->cursel = m->numopts; 563 m->cursel = m->numopts;
568 break; 564 break;
569 } 565 }
570 if (m->mopt & MC_NOSHORTCUT) { 566 if (m->mopt & MC_NOSHORTCUT) {
571 mbeep(); 567 mbeep();
572 return; 568 return;
573 } 569 }
574 if (ch > 'z') 570 if (ch > 'z')
575 ch = 255; 571 ch = 255;
576 if (ch >= 'a') { 572 if (ch >= 'a') {
577 if (ch > 'x') 573 if (ch > 'x')
578 ch--; 574 ch--;
579 ch = ch - 'a'; 575 ch = ch - 'a';
580 } else 576 } else
581 ch = 25 + ch - 'A'; 577 ch = 25 + ch - 'A';
582 if (ch < 0 || ch >= m->numopts) { 578 if (ch < 0 || ch >= m->numopts) {
583 mbeep(); 579 mbeep();
584 return; 580 return;
585 } 581 }
586 if (m->opts[ch].opt_flags & OPT_IGNORE) { 582 if (m->opts[ch].opt_flags & OPT_IGNORE) {
587 mbeep(); 583 mbeep();
588 return; 584 return;
589 } 585 }
590 m->cursel = ch; 586 m->cursel = ch;
591 } 587 }
592 588
593 draw_menu(m, arg); 589 draw_menu(m, arg);
594} 590}
595 591
596int 592int
597menu_init(void) 593menu_init(void)
598{ 594{
599 int i; 595 int i;
600 596
601 if (__menu_init) 597 if (__menu_init)
602 return 0; 598 return 0;
603 599
604#ifdef USER_MENU_INIT 600#ifdef USER_MENU_INIT
605 if (USER_MENU_INIT) 601 if (USER_MENU_INIT)
606 return 1; 602 return 1;
607#endif 603#endif
608 604
609 if (initscr() == NULL) 605 if (initscr() == NULL)
610 return 1; 606 return 1;
611 607
612 cbreak(); 608 cbreak();
613 noecho(); 609 noecho();
614 610
615 /* XXX Should be configurable but it almost isn't worth it. */ 611 /* XXX Should be configurable but it almost isn't worth it. */
616 if (has_colors()) { 612 if (has_colors()) {
617 start_color(); 613 start_color();
618 init_pair(1, COLOR_WHITE, COLOR_BLUE); 614 init_pair(1, COLOR_WHITE, COLOR_BLUE);
619 bkgd(COLOR_PAIR(1)); 615 bkgd(COLOR_PAIR(1));
620 attrset(COLOR_PAIR(1)); 616 attrset(COLOR_PAIR(1));
621 } 617 }
622 618
623 max_lines = getmaxy(stdscr); 619 max_lines = getmaxy(stdscr);
624 max_cols = getmaxx(stdscr); 620 max_cols = getmaxx(stdscr);
625 keypad(stdscr, TRUE); 621 keypad(stdscr, TRUE);
626#ifdef DYNAMIC_MENUS 622#ifdef DYNAMIC_MENUS
627 num_menus = DYN_INIT_NUM; 623 num_menus = DYN_INIT_NUM;
628 while (num_menus < DYN_MENU_START) 624 while (num_menus < DYN_MENU_START)
629 num_menus *= 2; 625 num_menus *= 2;
630 menu_list = malloc(sizeof *menu_list * num_menus); 626 menu_list = malloc(sizeof *menu_list * num_menus);
631 if (menu_list == NULL) 627 if (menu_list == NULL)
632 return 2; 628 return 2;
633 (void)memset(menu_list, 0, sizeof *menu_list * num_menus); 629 (void)memset(menu_list, 0, sizeof *menu_list * num_menus);
634 for (i = 0; i < DYN_MENU_START; i++) 630 for (i = 0; i < DYN_MENU_START; i++)
635 menu_list[i] = &menu_def[i]; 631 menu_list[i] = &menu_def[i];
636#endif 632#endif
637 633
638 __menu_init = 1; 634 __menu_init = 1;
639 return 0; 635 return 0;
640} 636}
641 637
642void 638void
643process_menu(int num, void *arg) 639process_menu(int num, void *arg)
644{ 640{
645 int sel = 0; 641 int sel = 0;
646 int req; 642 int req;
647 menu_ent *opt; 643 menu_ent *opt;
648 644
649 menudesc *m; 645 menudesc *m;
650 646
651 /* Initialize? */ 647 /* Initialize? */
652 if (menu_init()) { 648 if (menu_init()) {
653 __menu_initerror(); 649 __menu_initerror();
654 return; 650 return;
655 } 651 }
656 652
657 if (num < 0 || num >= num_menus) 653 if (num < 0 || num >= num_menus)
658 return; 654 return;
659 m = &MENUS(num); 655 m = &MENUS(num);
660 if (m == NULL) 656 if (m == NULL)
661 return; 657 return;
662 658
663 /* Default to select option 0 and display from 0 */ 659 /* Default to select option 0 and display from 0 */
664 m->topline = 0; 660 m->topline = 0;
665 if ((m->mopt & (MC_DFLTEXIT | MC_NOEXITOPT)) == MC_DFLTEXIT) 661 if ((m->mopt & (MC_DFLTEXIT | MC_NOEXITOPT)) == MC_DFLTEXIT)
666 m->cursel = -1; 662 m->cursel = -1;
667 else 663 else
668 m->cursel = 0; 664 m->cursel = 0;
669 665
670 for (;;) { 666 for (;;) {
671 if (isendwin()) 667 if (isendwin())
672 /* I'm not sure this is needed with netbsd's curses */ 668 /* I'm not sure this is needed with netbsd's curses */
673 doupdate(); 669 doupdate();
674 /* Process the display action */ 670 /* Process the display action */
675 if (m->post_act) 671 if (m->post_act)
676 (*m->post_act)(m, arg); 672 (*m->post_act)(m, arg);
677 if (m->mw == NULL) 673 if (m->mw == NULL)
678 init_menu(m); 674 init_menu(m);
679 draw_menu(m, arg); 675 draw_menu(m, arg);
680 676
681 while ((req = menucmd(m->mw)) != REQ_EXECUTE) 677 while ((req = menucmd(m->mw)) != REQ_EXECUTE)
682 process_req(m, arg, req); 678 process_req(m, arg, req);
683 679
684 sel = m->cursel; 680 sel = m->cursel;
685 if (!(m->mopt & MC_NOCLEAR)) { 681 if (!(m->mopt & MC_NOCLEAR)) {
686 wclear(m->mw); 682 wclear(m->mw);
687 if (m->sv_mw) 683 if (m->sv_mw)
688 overwrite(m->sv_mw, m->mw); 684 overwrite(m->sv_mw, m->mw);
689 wnoutrefresh(m->mw); 685 wnoutrefresh(m->mw);
690 } 686 }
691 687
692 /* Process the items */ 688 /* Process the items */
693 if (sel >= m->numopts) 689 if (sel >= m->numopts)
694 /* exit option */ 690 /* exit option */
695 break; 691 break;
696 692
697 opt = &m->opts[sel]; 693 opt = &m->opts[sel];
698 if (opt->opt_flags & OPT_IGNORE) 694 if (opt->opt_flags & OPT_IGNORE)
699 continue; 695 continue;
700 if (opt->opt_flags & OPT_ENDWIN) 696 if (opt->opt_flags & OPT_ENDWIN)
701 endwin(); 697 endwin();
702 if (opt->opt_action && (*opt->opt_action)(m, arg)) 698 if (opt->opt_action && (*opt->opt_action)(m, arg))
703 break; 699 break;
704 700
705 if (opt->opt_menu != -1) { 701 if (opt->opt_menu != -1) {
706 if (!(opt->opt_flags & OPT_SUB)) { 702 if (!(opt->opt_flags & OPT_SUB)) {
707 num = opt->opt_menu; 703 num = opt->opt_menu;
708 wclear(m->mw); 704 wclear(m->mw);
709 if (m->sv_mw) { 705 if (m->sv_mw) {
710 overwrite(m->sv_mw, m->mw); 706 overwrite(m->sv_mw, m->mw);
711 delwin(m->sv_mw); 707 delwin(m->sv_mw);
712 m->sv_mw = NULL; 708 m->sv_mw = NULL;
713 } 709 }
714 wnoutrefresh(m->mw); 710 wnoutrefresh(m->mw);
715 delwin(m->mw); 711 delwin(m->mw);
716 m->mw = NULL; 712 m->mw = NULL;
717 m = &MENUS(num); 713 m = &MENUS(num);
718 continue; 714 continue;
719 } 715 }
720 process_menu(opt->opt_menu, arg); 716 process_menu(opt->opt_menu, arg);
721 } 717 }
722 if (opt->opt_flags & OPT_EXIT) 718 if (opt->opt_flags & OPT_EXIT)
723 break; 719 break;
724 } 720 }
725 721
726 if (m->mopt & MC_NOCLEAR) { 722 if (m->mopt & MC_NOCLEAR) {
727 wclear(m->mw); 723 wclear(m->mw);
728 if (m->sv_mw) 724 if (m->sv_mw)
729 overwrite(m->sv_mw, m->mw); 725 overwrite(m->sv_mw, m->mw);
730 wnoutrefresh(m->mw); 726 wnoutrefresh(m->mw);
731 } 727 }
732 728
733 /* Process the exit action */ 729 /* Process the exit action */
734 if (m->exit_act) 730 if (m->exit_act)
735 (*m->exit_act)(m, arg); 731 (*m->exit_act)(m, arg);
736 delwin(m->mw); 732 delwin(m->mw);
737 m->mw = NULL; 733 m->mw = NULL;
738 if (m->sv_mw) { 734 if (m->sv_mw) {
739 delwin(m->sv_mw); 735 delwin(m->sv_mw);
740 m->sv_mw = NULL; 736 m->sv_mw = NULL;
741 } 737 }
742} 738}
743 739
744 740
745void 741void
746set_menu_numopts(int menu, int numopts) 742set_menu_numopts(int menu, int numopts)
747{ 743{
748 744
749 MENUS(menu).numopts = numopts; 745 MENUS(menu).numopts = numopts;
750} 746}
751 747
752 /* Control L is end of standard routines, remaining only for dynamic. */ 748 /* Control L is end of standard routines, remaining only for dynamic. */
753 749
754/* Beginning of routines for dynamic menus. */ 750/* Beginning of routines for dynamic menus. */
755 751
756static int  752static int
757double_menus(void) 753double_menus(void)
758{ 754{
759 menudesc **temp; 755 menudesc **temp;
760 int sz = sizeof *menu_list * num_menus; 756 int sz = sizeof *menu_list * num_menus;
761 757
762 temp = realloc(menu_list, sz * 2); 758 temp = realloc(menu_list, sz * 2);
763 if (temp == NULL) 759 if (temp == NULL)
764 return 0; 760 return 0;
765 (void)memset(temp + num_menus, 0, sz); 761 (void)memset(temp + num_menus, 0, sz);
766 menu_list = temp; 762 menu_list = temp;
767 num_menus *= 2; 763 num_menus *= 2;
768 764
769 return 1; 765 return 1;
770} 766}
771 767
772int 768int
773new_menu(const char *title, menu_ent *opts, int numopts,  769new_menu(const char *title, menu_ent *opts, int numopts,
774 int x, int y, int h, int w, int mopt, 770 int x, int y, int h, int w, int mopt,
775 void (*post_act)(menudesc *, void *), 771 void (*post_act)(menudesc *, void *),
776 void (*draw_line)(menudesc *, int, void *), 772 void (*draw_line)(menudesc *, int, void *),
777 void (*exit_act)(menudesc *, void *), 773 void (*exit_act)(menudesc *, void *),
778 const char *help, const char *exit_str) 774 const char *help, const char *exit_str)
779{ 775{
780 int ix; 776 int ix;
781 menudesc *m; 777 menudesc *m;
782 778
783 /* Find free menu entry. */ 779 /* Find free menu entry. */
784 for (ix = DYN_MENU_START; ; ix++) { 780 for (ix = DYN_MENU_START; ; ix++) {
785 if (ix >= num_menus && !double_menus()) 781 if (ix >= num_menus && !double_menus())
786 return -1; 782 return -1;
787 m = menu_list[ix]; 783 m = menu_list[ix];
788 if (m == NULL) { 784 if (m == NULL) {
789 m = calloc(sizeof *m, 1); 785 m = calloc(sizeof *m, 1);
790 if (m == NULL) 786 if (m == NULL)
791 return -1; 787 return -1;
792 menu_list[ix] = m; 788 menu_list[ix] = m;
793 break; 789 break;
794 } 790 }
795 if (!(m->mopt & MC_VALID)) 791 if (!(m->mopt & MC_VALID))
796 break; 792 break;
797 } 793 }
798 794
799 /* Set Entries */ 795 /* Set Entries */
800 m->title = title; 796 m->title = title;
801 m->opts = opts; 797 m->opts = opts;
802 m->numopts = numopts; 798 m->numopts = numopts;
803 m->x = x; 799 m->x = x;
804 m->y = y; 800 m->y = y;
805 m->h = h; 801 m->h = h;
806 m->w = w; 802 m->w = w;
807 m->mopt = mopt | MC_VALID; 803 m->mopt = mopt | MC_VALID;
808 m->post_act = post_act; 804 m->post_act = post_act;
809 m->draw_line = draw_line; 805 m->draw_line = draw_line;
810 m->exit_act = exit_act; 806 m->exit_act = exit_act;
811 m->helpstr = help; 807 m->helpstr = help;
812 m->exitstr = exit_str ? exit_str : "Exit"; 808 m->exitstr = exit_str ? exit_str : "Exit";
813 809
814 return ix; 810 return ix;
815} 811}
816 812
817void 813void
818free_menu(int menu_no) 814free_menu(int menu_no)
819{ 815{
820 menudesc *m; 816 menudesc *m;
821 817
822 if (menu_no < 0 || menu_no >= num_menus) 818 if (menu_no < 0 || menu_no >= num_menus)
823 return; 819 return;
824 820
825 m = menu_list[menu_no]; 821 m = menu_list[menu_no];
826 if (!(m->mopt & MC_VALID)) 822 if (!(m->mopt & MC_VALID))
827 return; 823 return;
828 if (m->mw != NULL) 824 if (m->mw != NULL)
829 delwin(m->mw); 825 delwin(m->mw);
830 memset(m, 0, sizeof *m); 826 memset(m, 0, sizeof *m);
831} 827}

cvs diff -r1.29 -r1.30 src/usr.bin/menuc/menuc.1 (switch to unified diff)

--- src/usr.bin/menuc/menuc.1 2009/07/11 18:38:30 1.29
+++ src/usr.bin/menuc/menuc.1 2012/03/06 16:55:18 1.30
@@ -1,548 +1,544 @@ @@ -1,548 +1,544 @@
1.\" $NetBSD: menuc.1,v 1.29 2009/07/11 18:38:30 joerg Exp $ 1.\" $NetBSD: menuc.1,v 1.30 2012/03/06 16:55:18 mbalmer Exp $
2.\" 2.\"
3.\" Copyright 1997 Piermont Information Systems Inc. 3.\" Copyright 1997 Piermont Information Systems Inc.
4.\" All rights reserved. 4.\" All rights reserved.
5.\" 5.\"
6.\" Written by Philip A. Nelson for Piermont Information Systems Inc. 6.\" Written by Philip A. Nelson for Piermont Information Systems Inc.
7.\" 7.\"
8.\" Redistribution and use in source and binary forms, with or without 8.\" Redistribution and use in source and binary forms, with or without
9.\" modification, are permitted provided that the following conditions 9.\" modification, are permitted provided that the following conditions
10.\" are met: 10.\" are met:
11.\" 1. Redistributions of source code must retain the above copyright 11.\" 1. Redistributions of source code must retain the above copyright
12.\" notice, this list of conditions and the following disclaimer. 12.\" notice, this list of conditions and the following disclaimer.
13.\" 2. Redistributions in binary form must reproduce the above copyright 13.\" 2. Redistributions in binary form must reproduce the above copyright
14.\" notice, this list of conditions and the following disclaimer in the 14.\" notice, this list of conditions and the following disclaimer in the
15.\" documentation and/or other materials provided with the distribution. 15.\" documentation and/or other materials provided with the distribution.
16.\" 3. All advertising materials mentioning features or use of this software 16.\" 3. The name of Piermont Information Systems Inc. may not be used to endorse
17.\" must display the following acknowledgement: 
18.\" This product includes software developed for the NetBSD Project by 
19.\" Piermont Information Systems Inc. 
20.\" 4. The name of Piermont Information Systems Inc. may not be used to endorse 
21.\" or promote products derived from this software without specific prior 17.\" or promote products derived from this software without specific prior
22.\" written permission. 18.\" written permission.
23.\" 19.\"
24.\" THIS SOFTWARE IS PROVIDED BY PIERMONT INFORMATION SYSTEMS INC. ``AS IS'' 20.\" THIS SOFTWARE IS PROVIDED BY PIERMONT INFORMATION SYSTEMS INC. ``AS IS''
25.\" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 21.\" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
26.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 22.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
27.\" ARE DISCLAIMED. IN NO EVENT SHALL PIERMONT INFORMATION SYSTEMS INC. BE 23.\" ARE DISCLAIMED. IN NO EVENT SHALL PIERMONT INFORMATION SYSTEMS INC. BE
28.\" LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 24.\" LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
29.\" CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 25.\" CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
30.\" SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 26.\" SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
31.\" INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 27.\" INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
32.\" CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 28.\" CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
33.\" ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF 29.\" ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
34.\" THE POSSIBILITY OF SUCH DAMAGE. 30.\" THE POSSIBILITY OF SUCH DAMAGE.
35.\" 31.\"
36.Dd August 2, 2004 32.Dd August 2, 2004
37.Dt MENUC 1 33.Dt MENUC 1
38.Os 34.Os
39.Sh NAME 35.Sh NAME
40.Nm menuc 36.Nm menuc
41.Nd menu compiler 37.Nd menu compiler
42.Sh SYNOPSIS 38.Sh SYNOPSIS
43.Nm 39.Nm
44.Op Fl o Ar name 40.Op Fl o Ar name
45.Ar file 41.Ar file
46.Sh DESCRIPTION 42.Sh DESCRIPTION
47This implements a curses based menu system. 43This implements a curses based menu system.
48A source file that describes menus, their options, and how to process 44A source file that describes menus, their options, and how to process
49the options is given to 45the options is given to
50.Nm 46.Nm
51and produces both a .c and a .h file that implement the menu system. 47and produces both a .c and a .h file that implement the menu system.
52The standard base name of the files is 48The standard base name of the files is
53.Pa menu_defs . 49.Pa menu_defs .
54The 50The
55.Fl o Ar name 51.Fl o Ar name
56can be used to specify a different base name. 52can be used to specify a different base name.
57.Sh ENVIRONMENT 53.Sh ENVIRONMENT
58.Bl -tag -width MENUDEF 54.Bl -tag -width MENUDEF
59.It Ev MENUDEF 55.It Ev MENUDEF
60Can be set to point to a different set of definition files for 56Can be set to point to a different set of definition files for
61.Nm . 57.Nm .
62The current location defaults to 58The current location defaults to
63.Pa /usr/share/misc . 59.Pa /usr/share/misc .
64.El 60.El
65.Sh MENU DESCRIPTIONS 61.Sh MENU DESCRIPTIONS
66The input 62The input
67.Ar file 63.Ar file
68defines static menus and options for processing those menus. 64defines static menus and options for processing those menus.
69It also contains comments, initial C code that is required to provide 65It also contains comments, initial C code that is required to provide
70for definitions and other code necessary for the menu system, and an 66for definitions and other code necessary for the menu system, and an
71option declaration if dynamic menus are requested. 67option declaration if dynamic menus are requested.
72.Pp 68.Pp
73Comments may appear anywhere in the input 69Comments may appear anywhere in the input
74.Ar file 70.Ar file
75and are like a space in the input. 71and are like a space in the input.
76They are like C comments starting with 72They are like C comments starting with
77.Em /* 73.Em /*
78and ending with 74and ending with
79.Em */ . 75.Em */ .
80They are unlike C comments in that they may be nested. 76They are unlike C comments in that they may be nested.
81A comment does not end until a matching end comment is found. 77A comment does not end until a matching end comment is found.
82.Pp 78.Pp
83In many places, C code is included in the definition 79In many places, C code is included in the definition
84.Ar file . 80.Ar file .
85All C code is passed verbatim to the C output file. 81All C code is passed verbatim to the C output file.
86.Nm 82.Nm
87comments do not start in C code and comments in the C code are 83comments do not start in C code and comments in the C code are
88passed verbatim to the output. 84passed verbatim to the output.
89The C comments are not recognized by 85The C comments are not recognized by
90.Nm . 86.Nm .
91In all cases, C code starts with a left brace 87In all cases, C code starts with a left brace
92.Pq Em \&{ 88.Pq Em \&{
93and ends with the matching right brace 89and ends with the matching right brace
94.Pq Em \&} . 90.Pq Em \&} .
95It is important to recognize that in code segments, any brace 91It is important to recognize that in code segments, any brace
96will be counted, even if it is in a C comment inside the code. 92will be counted, even if it is in a C comment inside the code.
97.Pp 93.Pp
98The 94The
99.Ar file 95.Ar file
100contains an initial (and optional) code block followed by any 96contains an initial (and optional) code block followed by any
101number of menu definition elements in any order. 97number of menu definition elements in any order.
102The initial code block usually contains includes of header files used by 98The initial code block usually contains includes of header files used by
103code in the menu code blocks later in the 99code in the menu code blocks later in the
104.Ar file . 100.Ar file .
105If 101If
106.Dv USER_MENU_INIT 102.Dv USER_MENU_INIT
107is #defined, then it will be evaluated before the 103is #defined, then it will be evaluated before the
108rest of the menu is initialised, if it evaluates to a non-zero value 104rest of the menu is initialised, if it evaluates to a non-zero value
109then the initialisation will fail. 105then the initialisation will fail.
110The file is free format, so the actual formatting of the input 106The file is free format, so the actual formatting of the input
111.Ar file 107.Ar file
112is to the taste of the programmer. 108is to the taste of the programmer.
113.Pp 109.Pp
114All other C code that will appear in an 110All other C code that will appear in an
115.Em action . 111.Em action .
116This will be specified as 112This will be specified as
117.Aq Em action 113.Aq Em action
118in later text. 114in later text.
119Such an action will appear as: 115Such an action will appear as:
120.Dl action \*[Lt]opt_endwin\*[Gt] \*[Lt]code\*[Gt] 116.Dl action \*[Lt]opt_endwin\*[Gt] \*[Lt]code\*[Gt]
121in the 117in the
122.Ar file . 118.Ar file .
123The 119The
124.Aq Em opt_endwin , 120.Aq Em opt_endwin ,
125if present is: 121if present is:
126.Dl ( endwin ) 122.Dl ( endwin )
127and specifies that the curses 123and specifies that the curses
128.Fn endwin 124.Fn endwin
129function should be called before executing the code and 125function should be called before executing the code and
130then reinstating the current curses window after the 126then reinstating the current curses window after the
131code has been run. 127code has been run.
132The 128The
133.Aq Em code 129.Aq Em code
134is as described above. 130is as described above.
135.Pp 131.Pp
136There are four kinds of menu definition elements. 132There are four kinds of menu definition elements.
137The first one just declares whether the programmer wants dynamic menus 133The first one just declares whether the programmer wants dynamic menus
138available. 134available.
139The default is static menus only. 135The default is static menus only.
140The static menus are the ones defined by the menu definitions and do not 136The static menus are the ones defined by the menu definitions and do not
141change at run time. 137change at run time.
142The dynamic menus provide the programmer with a method to create and 138The dynamic menus provide the programmer with a method to create and
143modify menus during the running of the program. 139modify menus during the running of the program.
144To include dynamic menus, one needs only add the declaration: 140To include dynamic menus, one needs only add the declaration:
145.Dl allow dynamic menus ; 141.Dl allow dynamic menus ;
146The semicolon is required to terminate this declaration. 142The semicolon is required to terminate this declaration.
147This declaration may appear anywhere in the 143This declaration may appear anywhere in the
148.Ar file , 144.Ar file ,
149but usually appears before any menus are defined. 145but usually appears before any menus are defined.
150.Pp 146.Pp
151The next element is a code block to execute if the curses 147The next element is a code block to execute if the curses
152screen can not be successfully initialized. 148screen can not be successfully initialized.
153The declaration 149The declaration
154.Dl error code ; 150.Dl error code ;
155tells the menu system to execute the associated code block 151tells the menu system to execute the associated code block
156if the initialization fails. 152if the initialization fails.
157If no code is provided, a default code block is used that prints 153If no code is provided, a default code block is used that prints
158.Dl Could not initialize curses. 154.Dl Could not initialize curses.
159and exits. 155and exits.
160This element may appear anywhere in the 156This element may appear anywhere in the
161.Ar file 157.Ar file
162but usually appears before any menus are defined. 158but usually appears before any menus are defined.
163.Pp 159.Pp
164The next element defines default options for menus. 160The next element defines default options for menus.
165Each menu is built from a list of options. 161Each menu is built from a list of options.
166These options include the location of the upper left corner of the menu, 162These options include the location of the upper left corner of the menu,
167whether there is a "box" drawn around the menu, whether the menu is 163whether there is a "box" drawn around the menu, whether the menu is
168scrollable, the menu's title, whether shortcut letters are 164scrollable, the menu's title, whether shortcut letters are
169allowed, whether a standard exit option should be included 165allowed, whether a standard exit option should be included
170in the menu and text associated with the standard exit option. 166in the menu and text associated with the standard exit option.
171The general format is: 167The general format is:
172.Dl default \*[Lt]comma separated option list\*[Gt] ; 168.Dl default \*[Lt]comma separated option list\*[Gt] ;
173.Pp 169.Pp
174The supported options are: 170The supported options are:
175.Bl -tag -width ".Ic exitstring Va text" 171.Bl -tag -width ".Ic exitstring Va text"
176.It Ic x = Va startx 172.It Ic x = Va startx
177The column number of the upper left corner of the menu window. 173The column number of the upper left corner of the menu window.
178If 174If
179.Va startx 175.Va startx
180is -1 the menu will be centered horizontally. 176is -1 the menu will be centered horizontally.
181.It Ic y = Va starty 177.It Ic y = Va starty
182The row number of the upper left corner of the menu window. 178The row number of the upper left corner of the menu window.
183If 179If
184.Va starty 180.Va starty
185is negative then the menu will be placed below any message text, but 181is negative then the menu will be placed below any message text, but
186in at least row 182in at least row
187.Va -starty . 183.Va -starty .
188.It Ic h = Va height 184.It Ic h = Va height
189Specifies the number of menu entries to be displayed. 185Specifies the number of menu entries to be displayed.
190If zero, the height will be based on the number of entries. 186If zero, the height will be based on the number of entries.
191.It Ic h = Va width 187.It Ic h = Va width
192Specifies the width of the menu window. 188Specifies the width of the menu window.
193If zero, the width will be that of the longest menu text line. 189If zero, the width will be that of the longest menu text line.
194.It Ic title Va text 190.It Ic title Va text
195The specified 191The specified
196.Va text 192.Va text
197will be displayed at the top of the menu window (inside any box). 193will be displayed at the top of the menu window (inside any box).
198.It Ic box 194.It Ic box
199If specified, draw a box around the menu. 195If specified, draw a box around the menu.
200.It Ic clear 196.It Ic clear
201If specified, clear the window before performing the 197If specified, clear the window before performing the
202.Va action . 198.Va action .
203.It Ic exit 199.It Ic exit
204If specified add an addition option to exit the menu. 200If specified add an addition option to exit the menu.
205.It Ic exitstring Va text 201.It Ic exitstring Va text
206The menu label for the 202The menu label for the
207.Va exit 203.Va exit
208option. 204option.
209If not specified defaults to "exit". 205If not specified defaults to "exit".
210.It Ic default exit 206.It Ic default exit
211If specified, place the cursor on the 207If specified, place the cursor on the
212.Va exit 208.Va exit
213line of the menu, instead of the top line. 209line of the menu, instead of the top line.
214.It Ic shortcut 210.It Ic shortcut
215If specified, add alphabetic tags to each menu line. 211If specified, add alphabetic tags to each menu line.
216.It Ic scrollable 212.It Ic scrollable
217If specified, and the menu has more lines than will fit in its window, then 213If specified, and the menu has more lines than will fit in its window, then
218only part of the menu will be displayed and the 214only part of the menu will be displayed and the
219.Sq \*[Lt] 215.Sq \*[Lt]
220and 216and
221.Sq \*[Gt] 217.Sq \*[Gt]
222keys will scroll the displayed menu lines. 218keys will scroll the displayed menu lines.
223.It Ic always scroll 219.It Ic always scroll
224If specified, allow for the scroll message line even if the menu doesn't 220If specified, allow for the scroll message line even if the menu doesn't
225appear to have too many lines. 221appear to have too many lines.
226Useful for dynamic menus, when the number of entries isn't known when the 222Useful for dynamic menus, when the number of entries isn't known when the
227menu window is created.. 223menu window is created..
228.It Ic sub menu 224.It Ic sub menu
229If specified, the screen contents that the menu window overwrites are saved 225If specified, the screen contents that the menu window overwrites are saved
230and restored when the menu exits. 226and restored when the menu exits.
231.El 227.El
232The 228The
233.Ic box , clear , exit , default exit , shortcut , scrollable , always scroll , 229.Ic box , clear , exit , default exit , shortcut , scrollable , always scroll ,
234and 230and
235.Ic sub menu 231.Ic sub menu
236options can be preceded by 232options can be preceded by
237.Ic no 233.Ic no
238in order to negate a default. 234in order to negate a default.
239.Pp 235.Pp
240The 236The
241.Va text 237.Va text
242arguments can be either a quoted text string or a name #defined to something 238arguments can be either a quoted text string or a name #defined to something
243suitable for initialising a const char * field. 239suitable for initialising a const char * field.
244.Pp 240.Pp
245The default declaration may appear multiple times. 241The default declaration may appear multiple times.
246Each time, it sets the default values for menu definitions that follow 242Each time, it sets the default values for menu definitions that follow
247in the 243in the
248.Ar file . 244.Ar file .
249In each menu definition, any or all of these default definitions 245In each menu definition, any or all of these default definitions
250may be overridden for that menu. 246may be overridden for that menu.
251.Pp 247.Pp
252The final element is the actual static menu definitions. 248The final element is the actual static menu definitions.
253The format and order for a menu definition is: 249The format and order for a menu definition is:
254.Bd -ragged -offset indent 250.Bd -ragged -offset indent
255menu \*[Lt]name\*[Gt] \*[Lt]options\*[Gt] ; 251menu \*[Lt]name\*[Gt] \*[Lt]options\*[Gt] ;
256 \*[Lt]display action\*[Gt] 252 \*[Lt]display action\*[Gt]
257 \*[Lt]menu items\*[Gt] 253 \*[Lt]menu items\*[Gt]
258 \*[Lt]exit action\*[Gt] 254 \*[Lt]exit action\*[Gt]
259 \*[Lt]help text\*[Gt] 255 \*[Lt]help text\*[Gt]
260.Ed 256.Ed
261.Pp 257.Pp
262Names are unquoted strings of alpha-numeric and underscore 258Names are unquoted strings of alpha-numeric and underscore
263characters. 259characters.
264They must start with an alpha character. 260They must start with an alpha character.
265In C source, a menu named 261In C source, a menu named
266.Dq foo 262.Dq foo
267is appears as 263is appears as
268.Dq MENU_foo . 264.Dq MENU_foo .
269(Capitalization is important.) 265(Capitalization is important.)
270This is important, because the menu is displayed and processed by 266This is important, because the menu is displayed and processed by
271calling the function 267calling the function
272.Dl process_menu (MENU_foo, arg) ; 268.Dl process_menu (MENU_foo, arg) ;
273.Pp 269.Pp
274The options are a comma separated list of options as in the 270The options are a comma separated list of options as in the
275.Dq default 271.Dq default
276declaration. 272declaration.
277These override the options from the most recent default declaration. 273These override the options from the most recent default declaration.
278.Pp 274.Pp
279The display action is optional and provides C code to 275The display action is optional and provides C code to
280execute at each and every time the menu is displayed for processing. 276execute at each and every time the menu is displayed for processing.
281If it is included, the format is: 277If it is included, the format is:
282.Dl display \*[Lt]action\*[Gt] ; 278.Dl display \*[Lt]action\*[Gt] ;
283.Pp 279.Pp
284The bulk of the menu definition is the specification 280The bulk of the menu definition is the specification
285of the menu items. 281of the menu items.
286The general format of a menu item is: 282The general format of a menu item is:
287.Dl option \*[Lt]string\*[Gt], \*[Lt]element_list\*[Gt] ; 283.Dl option \*[Lt]string\*[Gt], \*[Lt]element_list\*[Gt] ;
288The 284The
289.Aq Em string 285.Aq Em string
290is the text displayed for the menu item, this must be a quoted string 286is the text displayed for the menu item, this must be a quoted string
291or a name #defined to something that will initialise a const char * field. 287or a name #defined to something that will initialise a const char * field.
292There may be an arbitrary number of these items. 288There may be an arbitrary number of these items.
293(If there are shortcuts in the menu, a practical limit 289(If there are shortcuts in the menu, a practical limit
294of 51 should be recognized. 290of 51 should be recognized.
295It produces shortcuts a to w, y, z, and A to Z. 291It produces shortcuts a to w, y, z, and A to Z.
296x is the shortcut for the exit item.) 292x is the shortcut for the exit item.)
297.Pp 293.Pp
298The 294The
299.Aq Em element_list 295.Aq Em element_list
300is a comma separated list of what to do when the item is selected. 296is a comma separated list of what to do when the item is selected.
301They may appear in any order. 297They may appear in any order.
302.Pp 298.Pp
303The first element processed when a menu item 299The first element processed when a menu item
304is selected is the associated action. 300is selected is the associated action.
305The next element to be processed is the sub or next menu option. 301The next element to be processed is the sub or next menu option.
306They are declared as: 302They are declared as:
307.Dl next menu \*[Lt]name\*[Gt] 303.Dl next menu \*[Lt]name\*[Gt]
308.Dl sub menu \*[Lt]name\*[Gt] 304.Dl sub menu \*[Lt]name\*[Gt]
309The difference between these two is that a sub 305The difference between these two is that a sub
310menu will return to the current menu when exited. 306menu will return to the current menu when exited.
311The next menu will just replace the current 307The next menu will just replace the current
312menu and when exited, will return to where the 308menu and when exited, will return to where the
313current menu would have gone. 309current menu would have gone.
314Only one of menu element may be used for each menu item. 310Only one of menu element may be used for each menu item.
315Finally, after processing both the action and a sub menu, 311Finally, after processing both the action and a sub menu,
316the current menu will be exited if the element 312the current menu will be exited if the element
317.Dl exit 313.Dl exit
318is specified. 314is specified.
319.Em Note : 315.Em Note :
320If 316If
321.Em exit 317.Em exit
322is specified, next menu will not work because 318is specified, next menu will not work because
323the menu system will exit the 319the menu system will exit the
324.Em current 320.Em current
325menu, even if current has been set by 321menu, even if current has been set by
326.Em next menu . 322.Em next menu .
327.Pp 323.Pp
328After all menu items, the final two menu definition 324After all menu items, the final two menu definition
329elements may appear. 325elements may appear.
330The exit action is optional and provides C code to 326The exit action is optional and provides C code to
331execute in the process of exiting a menu. 327execute in the process of exiting a menu.
332If it is included, the format is: 328If it is included, the format is:
333.Dl exit \*[Lt]action\*[Gt] ; 329.Dl exit \*[Lt]action\*[Gt] ;
334.Pp 330.Pp
335The final part of the menu definition is the optional 331The final part of the menu definition is the optional
336help string. 332help string.
337The format is: 333The format is:
338.Dl help \*[Lt]text\*[Gt] ; 334.Dl help \*[Lt]text\*[Gt] ;
339This text is displayed in a full page 335This text is displayed in a full page
340help window if the question mark is typed. 336help window if the question mark is typed.
341The actual help text starts with a left brace 337The actual help text starts with a left brace
342.Pq Em \&{ 338.Pq Em \&{
343and ends with the matching right brace 339and ends with the matching right brace
344.Pq Em \&} . 340.Pq Em \&} .
345The braces are not included in the 341The braces are not included in the
346help string, but all other characters between 342help string, but all other characters between
347them are included. 343them are included.
348Newlines in the code translate to newlines in the help text. 344Newlines in the code translate to newlines in the help text.
349Alternatively, the name of a const char * variable may be given. 345Alternatively, the name of a const char * variable may be given.
350.Sh DYNAMIC MENUS 346.Sh DYNAMIC MENUS
351If requested, 347If requested,
352.Nm 348.Nm
353supports dynamic menus by allowing the user to create new 349supports dynamic menus by allowing the user to create new
354menus. 350menus.
355The related definitions for using dynamic menus are: 351The related definitions for using dynamic menus are:
356.Bd -literal 352.Bd -literal
357struct menudesc; 353struct menudesc;
358 354
359typedef 355typedef
360struct menu_ent { 356struct menu_ent {
361 const char *opt_name; 357 const char *opt_name;
362 int opt_menu; 358 int opt_menu;
363 int opt_flags; 359 int opt_flags;
364 int (*opt_action)(struct menudesc *, void *); 360 int (*opt_action)(struct menudesc *, void *);
365} menu_ent ; 361} menu_ent ;
366 362
367/* For opt_menu */ 363/* For opt_menu */
368#define OPT_NOMENU -1 364#define OPT_NOMENU -1
369 365
370/* For opt_flags */ 366/* For opt_flags */
371#define OPT_SUB 1 367#define OPT_SUB 1
372#define OPT_ENDWIN 2 368#define OPT_ENDWIN 2
373#define OPT_EXIT 4 369#define OPT_EXIT 4
374 370
375typedef 371typedef
376struct menudesc { 372struct menudesc {
377 const char *title; 373 const char *title;
378 int y, x; 374 int y, x;
379 int h, w; 375 int h, w;
380 int mopt; 376 int mopt;
381 int numopts; 377 int numopts;
382 int cursel; 378 int cursel;
383 int topline; 379 int topline;
384 menu_ent *opts; 380 menu_ent *opts;
385 WINDOW *mw; 381 WINDOW *mw;
386 WINDOW *sv_mw; 382 WINDOW *sv_mw;
387 const char *helpstr; 383 const char *helpstr;
388 const char *exitstr; 384 const char *exitstr;
389 void (*post_act)(struct menudesc *, void *); 385 void (*post_act)(struct menudesc *, void *);
390 void (*exit_act)(struct menudesc *, void *); 386 void (*exit_act)(struct menudesc *, void *);
391 void (*draw_line)(struct menudesc *, int, void *); 387 void (*draw_line)(struct menudesc *, int, void *);
392} menudesc ; 388} menudesc ;
393 389
394/* defines for mopt field. */ 390/* defines for mopt field. */
395#define MC_NOEXITOPT 1 391#define MC_NOEXITOPT 1
396#define MC_NOBOX 2 392#define MC_NOBOX 2
397#define MC_SCROLL 4 393#define MC_SCROLL 4
398#define MC_NOSHORTCUT 8 394#define MC_NOSHORTCUT 8
399#define MC_NOCLEAR 16 395#define MC_NOCLEAR 16
400#define MC_DFLTEXIT 32 396#define MC_DFLTEXIT 32
401#define MC_ALWAYS_SCROLL 64 397#define MC_ALWAYS_SCROLL 64
402#define MC_SUBMENU 128 398#define MC_SUBMENU 128
403 399
404int new_menu(const char *title, menu_ent *opts, int numopts, 400int new_menu(const char *title, menu_ent *opts, int numopts,
405 int x, int y, int h, int w, int mopt, 401 int x, int y, int h, int w, int mopt,
406 void (*post_act)(struct menudesc *, void *), 402 void (*post_act)(struct menudesc *, void *),
407 void (*draw_line)(struct menudesc *, int, void *), 403 void (*draw_line)(struct menudesc *, int, void *),
408 void (*exit_act)(struct menudesc *, void *), 404 void (*exit_act)(struct menudesc *, void *),
409 const char *help, const char *exitstr); 405 const char *help, const char *exitstr);
410 406
411void free_menu (int menu_no); 407void free_menu (int menu_no);
412.Ed 408.Ed
413.Pp 409.Pp
414The 410The
415.Ar title 411.Ar title
416is the title displayed at the top of the menu. 412is the title displayed at the top of the menu.
417The 413The
418.Ar opts 414.Ar opts
419is an array of menu entry definitions that has 415is an array of menu entry definitions that has
420.Ar numopts 416.Ar numopts
421elements. 417elements.
422The programmer must build this array and 418The programmer must build this array and
423fill in all of the fields before processing calling 419fill in all of the fields before processing calling
424.Fn process_menu 420.Fn process_menu
425for the new menu. 421for the new menu.
426The fields of the 422The fields of the
427.Ar opts 423.Ar opts
428may change at any time. 424may change at any time.
429For example, 425For example,
430.Em opt_name 426.Em opt_name
431may change as a result of selecting that option. 427may change as a result of selecting that option.
432When the menu is redisplayed, the new text is printed. 428When the menu is redisplayed, the new text is printed.
433Arguments, 429Arguments,
434.Ar x , y , h , 430.Ar x , y , h ,
435and 431and
436.Ar w 432.Ar w
437are the same as the options in the menu description. 433are the same as the options in the menu description.
438.Ar mopt 434.Ar mopt
439is the boolean options. 435is the boolean options.
440Note, box, clear, exit and shortcuts are enabled by default. 436Note, box, clear, exit and shortcuts are enabled by default.
441You need to add option flags to turn them off or turn on scrollable menus. 437You need to add option flags to turn them off or turn on scrollable menus.
442The options 438The options
443.Ar post_act , 439.Ar post_act ,
444and 440and
445.Ar exit_act 441.Ar exit_act
446are function pointers to the display action and the exit action. 442are function pointers to the display action and the exit action.
447If they are 443If they are
448.Dv NULL , 444.Dv NULL ,
449no call will be made. 445no call will be made.
450.Ar draw_line 446.Ar draw_line
451will be called to display the menu line if the corresponding opt_name 447will be called to display the menu line if the corresponding opt_name
452field is 448field is
453.Dv NULL . 449.Dv NULL .
454.Ar help 450.Ar help
455is the text to display in a help screen. 451is the text to display in a help screen.
456And finally, 452And finally,
457.Ar exitstr 453.Ar exitstr
458is the text for the 'exit' line of the menu. 454is the text for the 'exit' line of the menu.
459If 455If
460.Dv NULL , 456.Dv NULL ,
461"Exit" is used. 457"Exit" is used.
462A 458A
463.Dv NULL 459.Dv NULL
464help pointer will disable the help feature for the menu. 460help pointer will disable the help feature for the menu.
465.Sh FILES 461.Sh FILES
466.Bl -item 462.Bl -item
467.It 463.It
468.Pa /usr/share/misc/menu_sys.def 464.Pa /usr/share/misc/menu_sys.def
469.El 465.El
470.Sh EXAMPLES 466.Sh EXAMPLES
471The following is a simple menu definition file. 467The following is a simple menu definition file.
472It is complete in that the output of 468It is complete in that the output of
473.Nm 469.Nm
474may be compiled into a complete program. 470may be compiled into a complete program.
475For example, if the following was in a file called 471For example, if the following was in a file called
476.Pa example.mc , 472.Pa example.mc ,
477an executable program could be produced by the following commands. 473an executable program could be produced by the following commands.
478.Bd -literal -offset indent 474.Bd -literal -offset indent
479menuc -o example example.mc 475menuc -o example example.mc
480cc -o example example.c -lcurses 476cc -o example example.c -lcurses
481.Ed 477.Ed
482A much more complete example is available with the source 478A much more complete example is available with the source
483distribution in a subdirectory called 479distribution in a subdirectory called
484.Em testm . 480.Em testm .
485.Bd -literal 481.Bd -literal
486/* This is an example menu definition file for menuc. */ 482/* This is an example menu definition file for menuc. */
487 483
488{ 484{
489#include \*[Lt]stdio.h\*[Gt] 485#include \*[Lt]stdio.h\*[Gt]
490#include \*[Lt]unistd.h\*[Gt] 486#include \*[Lt]unistd.h\*[Gt]
491 487
492/* Main program! This is often in a different file. */ 488/* Main program! This is often in a different file. */
493int 489int
494main() 490main()
495 { 491 {
496 process_menu (MENU_main, NULL); 492 process_menu (MENU_main, NULL);
497 endwin(); 493 endwin();
498 return 0; 494 return 0;
499 } 495 }
500 496
501/* Example initialize function! */ 497/* Example initialize function! */
502void 498void
503init_main() 499init_main()
504 { 500 {
505 } 501 }
506} 502}
507 503
508default x=20, y=10, box, scrollable, exit; 504default x=20, y=10, box, scrollable, exit;
509 505
510error action { 506error action {
511 fprintf (stderr, "Example Menu: Could not initialize curses."); 507 fprintf (stderr, "Example Menu: Could not initialize curses.");
512 exit(1); 508 exit(1);
513}; 509};
514 510
515menu main, title "Main Menu", no exit, no shortcut; 511menu main, title "Main Menu", no exit, no shortcut;
516 display action { init_main(); }; 512 display action { init_main(); };
517 option "Option 1", 513 option "Option 1",
518 action (endwin) { 514 action (endwin) {
519 printf ("That was option 1!"); 515 printf ("That was option 1!");
520 sleep(3); 516 sleep(3);
521 }; 517 };
522 option "Sub Menu", sub menu othermenu; 518 option "Sub Menu", sub menu othermenu;
523 option "Next Menu", next menu othermenu; 519 option "Next Menu", next menu othermenu;
524 option "Quit", exit; 520 option "Quit", exit;
525 help { 521 help {
526This is a simple help screen for an example menu definition file. 522This is a simple help screen for an example menu definition file.
527}; 523};
528 524
529menu othermenu, title "Sub/Next Menu", x=5, y=5, no box; 525menu othermenu, title "Sub/Next Menu", x=5, y=5, no box;
530 option "Do Nothing!", action { }; 526 option "Do Nothing!", action { };
531.Ed 527.Ed
532.Sh SEE ALSO 528.Sh SEE ALSO
533.Xr msgc 1 529.Xr msgc 1
534.Sh AUTHORS 530.Sh AUTHORS
535.An Philip A. Nelson 531.An Philip A. Nelson
536for Piermont Information Systems Inc. 532for Piermont Information Systems Inc.
537Initial ideas for this were developed and implemented in Pascal at the 533Initial ideas for this were developed and implemented in Pascal at the
538Leiden University, Netherlands, in the summer of 1980. 534Leiden University, Netherlands, in the summer of 1980.
539.Sh BUGS 535.Sh BUGS
540Both 536Both
541.Nm 537.Nm
542and 538and
543.Nm msgc 539.Nm msgc
544are probably only used by 540are probably only used by
545.Nm sysinst . 541.Nm sysinst .
546The features of both have been tailored for 542The features of both have been tailored for
547.Nm sysinst , 543.Nm sysinst ,
548and further changes are likely to occur. 544and further changes are likely to occur.

cvs diff -r1.15 -r1.16 src/usr.bin/menuc/parse.y (switch to unified diff)

--- src/usr.bin/menuc/parse.y 2006/02/20 21:06:40 1.15
+++ src/usr.bin/menuc/parse.y 2012/03/06 16:55:18 1.16
@@ -1,232 +1,228 @@ @@ -1,232 +1,228 @@
1/* $NetBSD: parse.y,v 1.15 2006/02/20 21:06:40 dsl Exp $ */ 1/* $NetBSD: parse.y,v 1.16 2012/03/06 16:55:18 mbalmer Exp $ */
2 2
3/* 3/*
4 * Copyright 1997 Piermont Information Systems Inc. 4 * Copyright 1997 Piermont Information Systems Inc.
5 * All rights reserved. 5 * All rights reserved.
6 * 6 *
7 * Written by Philip A. Nelson for Piermont Information Systems Inc. 7 * Written by Philip A. Nelson for Piermont Information Systems Inc.
8 * 8 *
9 * Redistribution and use in source and binary forms, with or without 9 * Redistribution and use in source and binary forms, with or without
10 * modification, are permitted provided that the following conditions 10 * modification, are permitted provided that the following conditions
11 * are met: 11 * are met:
12 * 1. Redistributions of source code must retain the above copyright 12 * 1. Redistributions of source code must retain the above copyright
13 * notice, this list of conditions and the following disclaimer. 13 * notice, this list of conditions and the following disclaimer.
14 * 2. Redistributions in binary form must reproduce the above copyright 14 * 2. Redistributions in binary form must reproduce the above copyright
15 * notice, this list of conditions and the following disclaimer in the 15 * notice, this list of conditions and the following disclaimer in the
16 * documentation and/or other materials provided with the distribution. 16 * documentation and/or other materials provided with the distribution.
17 * 3. All advertising materials mentioning features or use of this software 17 * 3. The name of Piermont Information Systems Inc. may not be used to endorse
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 18 * or promote products derived from this software without specific prior
23 * written permission. 19 * written permission.
24 * 20 *
25 * THIS SOFTWARE IS PROVIDED BY PIERMONT INFORMATION SYSTEMS INC. ``AS IS'' 21 * THIS SOFTWARE IS PROVIDED BY PIERMONT INFORMATION SYSTEMS INC. ``AS IS''
26 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 22 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
27 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 23 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
28 * ARE DISCLAIMED. IN NO EVENT SHALL PIERMONT INFORMATION SYSTEMS INC. BE  24 * ARE DISCLAIMED. IN NO EVENT SHALL PIERMONT INFORMATION SYSTEMS INC. BE
29 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR  25 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
30 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF  26 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
31 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 27 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
32 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 28 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
33 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 29 * 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  30 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
35 * THE POSSIBILITY OF SUCH DAMAGE. 31 * THE POSSIBILITY OF SUCH DAMAGE.
36 * 32 *
37 */ 33 */
38 34
39 35
40%{ 36%{
41 37
42#include <stdio.h> 38#include <stdio.h>
43#include "defs.h" 39#include "defs.h"
44 40
45static id_rec *cur_menu; 41static id_rec *cur_menu;
46static optn_info *cur_optn; 42static optn_info *cur_optn;
47 43
48%} 44%}
49 45
50%union { 46%union {
51 char *s_value; 47 char *s_value;
52 int i_value; 48 int i_value;
53 optn_info *optn_value; 49 optn_info *optn_value;
54 action a_value; 50 action a_value;
55} 51}
56 52
57 53
58%token <i_value> X Y W H NO BOX SUB HELP MENU NEXT EXIT ACTION ENDWIN OPTION  54%token <i_value> X Y W H NO BOX SUB HELP MENU NEXT EXIT ACTION ENDWIN OPTION
59%token <i_value> TITLE DEFAULT DISPLAY ERROR EXITSTRING ALLOW DYNAMIC MENUS 55%token <i_value> TITLE DEFAULT DISPLAY ERROR EXITSTRING ALLOW DYNAMIC MENUS
60 SCROLLABLE SHORTCUT CLEAR MESSAGES ALWAYS SCROLL 56 SCROLLABLE SHORTCUT CLEAR MESSAGES ALWAYS SCROLL
61%token <s_value> STRING NAME CODE INT_CONST CHAR_CONST 57%token <s_value> STRING NAME CODE INT_CONST CHAR_CONST
62 58
63%type <s_value> init_code system helpstr text 59%type <s_value> init_code system helpstr text
64%type <optn_value> option option_list 60%type <optn_value> option option_list
65%type <i_value> act_opt 61%type <i_value> act_opt
66%type <a_value> action exitact 62%type <a_value> action exitact
67 63
68%start system 64%start system
69 65
70%% 66%%
71 67
72system : init_code menu_list 68system : init_code menu_list
73 { check_defined(); 69 { check_defined();
74 if (!had_errors) 70 if (!had_errors)
75 write_menu_file($1); 71 write_menu_file($1);
76 } 72 }
77 ; 73 ;
78 74
79init_code : /* empty */ { $$ = ""; } 75init_code : /* empty */ { $$ = ""; }
80 | CODE 76 | CODE
81 ; 77 ;
82 78
83menu_list : /* empty */ 79menu_list : /* empty */
84 | menu_list menu_def 80 | menu_list menu_def
85 | menu_list default_def 81 | menu_list default_def
86 | menu_list initerror_def 82 | menu_list initerror_def
87 | menu_list dynamic_def 83 | menu_list dynamic_def
88 | menu_list msgxlat_def 84 | menu_list msgxlat_def
89 ; 85 ;
90 86
91dynamic_def : ALLOW DYNAMIC MENUS ';' 87dynamic_def : ALLOW DYNAMIC MENUS ';'
92 { do_dynamic = 1; } 88 { do_dynamic = 1; }
93 89
94msgxlat_def : ALLOW DYNAMIC MESSAGES ';' 90msgxlat_def : ALLOW DYNAMIC MESSAGES ';'
95 { do_msgxlat = 1; } 91 { do_msgxlat = 1; }
96 92
97initerror_def : ERROR action ';' 93initerror_def : ERROR action ';'
98 { error_act = $2; } 94 { error_act = $2; }
99 95
100default_def : DEFAULT 96default_def : DEFAULT
101 { cur_menu = &default_menu; } 97 { cur_menu = &default_menu; }
102 opt opt_list ";" 98 opt opt_list ";"
103 99
104menu_def : MENU NAME 100menu_def : MENU NAME
105 { cur_menu = get_menu ($2); 101 { cur_menu = get_menu ($2);
106 if (cur_menu->info != NULL) 102 if (cur_menu->info != NULL)
107 yyerror ("Menu %s defined twice", $2); 103 yyerror ("Menu %s defined twice", $2);
108 else { 104 else {
109 cur_menu->info = 105 cur_menu->info =
110 (menu_info *) malloc (sizeof (menu_info)); 106 (menu_info *) malloc (sizeof (menu_info));
111 *(cur_menu->info) = default_info; 107 *(cur_menu->info) = default_info;
112 } 108 }
113 } 109 }
114 opts ";" dispact option_list exitact helpstr 110 opts ";" dispact option_list exitact helpstr
115 { optn_info *t; 111 { optn_info *t;
116 cur_menu->info->optns = NULL; 112 cur_menu->info->optns = NULL;
117 while ($7 != NULL) { 113 while ($7 != NULL) {
118 t = $7; 114 t = $7;
119 $7 = $7->next; 115 $7 = $7->next;
120 t->next = cur_menu->info->optns; 116 t->next = cur_menu->info->optns;
121 cur_menu->info->optns = t; 117 cur_menu->info->optns = t;
122 cur_menu->info->numopt++; 118 cur_menu->info->numopt++;
123 } 119 }
124 } 120 }
125 ; 121 ;
126 122
127opts : /* empty */ 123opts : /* empty */
128 | opt_list 124 | opt_list
129 ; 125 ;
130 126
131opt_list : "," opt 127opt_list : "," opt
132 | opt_list "," opt 128 | opt_list "," opt
133 ; 129 ;
134 130
135text : NAME | STRING 131text : NAME | STRING
136 132
137opt : NO EXIT { cur_menu->info->mopt |= MC_NOEXITOPT; } 133opt : NO EXIT { cur_menu->info->mopt |= MC_NOEXITOPT; }
138 | EXIT { cur_menu->info->mopt &= ~MC_NOEXITOPT; } 134 | EXIT { cur_menu->info->mopt &= ~MC_NOEXITOPT; }
139 | NO BOX { cur_menu->info->mopt |= MC_NOBOX; } 135 | NO BOX { cur_menu->info->mopt |= MC_NOBOX; }
140 | BOX { cur_menu->info->mopt &= ~MC_NOBOX; } 136 | BOX { cur_menu->info->mopt &= ~MC_NOBOX; }
141 | NO SCROLLABLE { cur_menu->info->mopt &= ~MC_SCROLL; } 137 | NO SCROLLABLE { cur_menu->info->mopt &= ~MC_SCROLL; }
142 | SCROLLABLE { cur_menu->info->mopt |= MC_SCROLL; } 138 | SCROLLABLE { cur_menu->info->mopt |= MC_SCROLL; }
143 | NO SHORTCUT { cur_menu->info->mopt |= MC_NOSHORTCUT; } 139 | NO SHORTCUT { cur_menu->info->mopt |= MC_NOSHORTCUT; }
144 | SHORTCUT { cur_menu->info->mopt &= ~MC_NOSHORTCUT; } 140 | SHORTCUT { cur_menu->info->mopt &= ~MC_NOSHORTCUT; }
145 | NO CLEAR { cur_menu->info->mopt |= MC_NOCLEAR; } 141 | NO CLEAR { cur_menu->info->mopt |= MC_NOCLEAR; }
146 | CLEAR { cur_menu->info->mopt &= ~MC_NOCLEAR; } 142 | CLEAR { cur_menu->info->mopt &= ~MC_NOCLEAR; }
147 | NO DEFAULT EXIT { cur_menu->info->mopt &= ~MC_DFLTEXIT; } 143 | NO DEFAULT EXIT { cur_menu->info->mopt &= ~MC_DFLTEXIT; }
148 | DEFAULT EXIT { cur_menu->info->mopt |= MC_DFLTEXIT; } 144 | DEFAULT EXIT { cur_menu->info->mopt |= MC_DFLTEXIT; }
149 | NO ALWAYS SCROLL { cur_menu->info->mopt &= ~MC_ALWAYS_SCROLL; } 145 | NO ALWAYS SCROLL { cur_menu->info->mopt &= ~MC_ALWAYS_SCROLL; }
150 | ALWAYS SCROLL { cur_menu->info->mopt |= MC_ALWAYS_SCROLL; } 146 | ALWAYS SCROLL { cur_menu->info->mopt |= MC_ALWAYS_SCROLL; }
151 | NO SUB MENU { cur_menu->info->mopt &= ~MC_SUBMENU; } 147 | NO SUB MENU { cur_menu->info->mopt &= ~MC_SUBMENU; }
152 | SUB MENU { cur_menu->info->mopt |= MC_SUBMENU; } 148 | SUB MENU { cur_menu->info->mopt |= MC_SUBMENU; }
153 | X "=" INT_CONST { cur_menu->info->x = atoi($3); } 149 | X "=" INT_CONST { cur_menu->info->x = atoi($3); }
154 | Y "=" INT_CONST { cur_menu->info->y = atoi($3); } 150 | Y "=" INT_CONST { cur_menu->info->y = atoi($3); }
155 | W "=" INT_CONST { cur_menu->info->w = atoi($3); } 151 | W "=" INT_CONST { cur_menu->info->w = atoi($3); }
156 | H "=" INT_CONST { cur_menu->info->h = atoi($3); } 152 | H "=" INT_CONST { cur_menu->info->h = atoi($3); }
157 | TITLE text { cur_menu->info->title = $2; } 153 | TITLE text { cur_menu->info->title = $2; }
158 | EXITSTRING text { cur_menu->info->exitstr = $2; 154 | EXITSTRING text { cur_menu->info->exitstr = $2;
159 cur_menu->info->mopt &= ~MC_NOEXITOPT; } 155 cur_menu->info->mopt &= ~MC_NOEXITOPT; }
160 ; 156 ;
161 157
162option_list : option 158option_list : option
163 | option_list option { $2->next = $1; $$ = $2; } 159 | option_list option { $2->next = $1; $$ = $2; }
164 ; 160 ;
165 161
166option : OPTION 162option : OPTION
167 { cur_optn = (optn_info *) malloc (sizeof(optn_info)); 163 { cur_optn = (optn_info *) malloc (sizeof(optn_info));
168 cur_optn->menu = -1; 164 cur_optn->menu = -1;
169 cur_optn->name = NULL; 165 cur_optn->name = NULL;
170 cur_optn->name_is_code = FALSE; 166 cur_optn->name_is_code = FALSE;
171 cur_optn->issub = FALSE; 167 cur_optn->issub = FALSE;
172 cur_optn->doexit = FALSE; 168 cur_optn->doexit = FALSE;
173 cur_optn->optact.code = ""; 169 cur_optn->optact.code = "";
174 cur_optn->optact.endwin = FALSE; 170 cur_optn->optact.endwin = FALSE;
175 cur_optn->next = NULL; 171 cur_optn->next = NULL;
176 } 172 }
177 option_legend "," 173 option_legend ","
178 elem_list ";" 174 elem_list ";"
179 { $$ = cur_optn; } 175 { $$ = cur_optn; }
180 ; 176 ;
181 177
182option_legend : text { cur_optn->name = $1; } 178option_legend : text { cur_optn->name = $1; }
183 | CODE { cur_optn->name = $1; cur_optn->name_is_code = TRUE;} 179 | CODE { cur_optn->name = $1; cur_optn->name_is_code = TRUE;}
184 180
185elem_list : elem 181elem_list : elem
186 | elem_list "," elem 182 | elem_list "," elem
187 ; 183 ;
188 184
189elem : NEXT MENU NAME 185elem : NEXT MENU NAME
190 { id_rec *t = get_menu ($3); 186 { id_rec *t = get_menu ($3);
191 if (cur_optn->menu != -1) 187 if (cur_optn->menu != -1)
192 yyerror ("Double sub/next menu definition"); 188 yyerror ("Double sub/next menu definition");
193 else { 189 else {
194 cur_optn->menu = t->menu_no; 190 cur_optn->menu = t->menu_no;
195 } 191 }
196 } 192 }
197 | SUB MENU NAME 193 | SUB MENU NAME
198 { id_rec *t = get_menu ($3); 194 { id_rec *t = get_menu ($3);
199 if (cur_optn->menu != -1) 195 if (cur_optn->menu != -1)
200 yyerror ("Double sub/next menu definition"); 196 yyerror ("Double sub/next menu definition");
201 else { 197 else {
202 cur_optn->menu = t->menu_no; 198 cur_optn->menu = t->menu_no;
203 cur_optn->issub = TRUE; 199 cur_optn->issub = TRUE;
204 } 200 }
205 } 201 }
206 | action { cur_optn->optact = $1; } 202 | action { cur_optn->optact = $1; }
207 | EXIT { cur_optn->doexit = TRUE; } 203 | EXIT { cur_optn->doexit = TRUE; }
208 ; 204 ;
209 205
210action : ACTION act_opt CODE 206action : ACTION act_opt CODE
211 { $$.code = $3; 207 { $$.code = $3;
212 $$.endwin = $2; 208 $$.endwin = $2;
213 } 209 }
214 ; 210 ;
215 211
216act_opt : /* empty */ { $$ = 0; } 212act_opt : /* empty */ { $$ = 0; }
217 | "(" ENDWIN ")" { $$ = 1; } 213 | "(" ENDWIN ")" { $$ = 1; }
218 ; 214 ;
219 215
220dispact : /* empty */ { cur_menu->info->postact.code = ""; } 216dispact : /* empty */ { cur_menu->info->postact.code = ""; }
221 | DISPLAY action ";" { cur_menu->info->postact = $2; } 217 | DISPLAY action ";" { cur_menu->info->postact = $2; }
222 ; 218 ;
223 219
224 220
225exitact : /* empty */ { cur_menu->info->exitact.code = ""; } 221exitact : /* empty */ { cur_menu->info->exitact.code = ""; }
226 | EXIT action ";" { cur_menu->info->exitact = $2; } 222 | EXIT action ";" { cur_menu->info->exitact = $2; }
227 ; 223 ;
228 224
229helpstr : /* empty */ { cur_menu->info->helpstr = NULL; } 225helpstr : /* empty */ { cur_menu->info->helpstr = NULL; }
230 | HELP CODE ";" { asprintf(&cur_menu->info->helpstr, "\"%s\"", $2); }  226 | HELP CODE ";" { asprintf(&cur_menu->info->helpstr, "\"%s\"", $2); }
231 | HELP text ";" { cur_menu->info->helpstr = $2; }  227 | HELP text ";" { cur_menu->info->helpstr = $2; }
232 ; 228 ;

cvs diff -r1.15 -r1.16 src/usr.bin/menuc/scan.l (switch to unified diff)

--- src/usr.bin/menuc/scan.l 2009/10/29 14:36:14 1.15
+++ src/usr.bin/menuc/scan.l 2012/03/06 16:55:18 1.16
@@ -1,200 +1,196 @@ @@ -1,200 +1,196 @@
1/* $NetBSD: scan.l,v 1.15 2009/10/29 14:36:14 christos Exp $ */ 1/* $NetBSD: scan.l,v 1.16 2012/03/06 16:55:18 mbalmer Exp $ */
2 2
3/* 3/*
4 * Copyright 1997 Piermont Information Systems Inc. 4 * Copyright 1997 Piermont Information Systems Inc.
5 * All rights reserved. 5 * All rights reserved.
6 * 6 *
7 * Written by Philip A. Nelson for Piermont Information Systems Inc. 7 * Written by Philip A. Nelson for Piermont Information Systems Inc.
8 * 8 *
9 * Redistribution and use in source and binary forms, with or without 9 * Redistribution and use in source and binary forms, with or without
10 * modification, are permitted provided that the following conditions 10 * modification, are permitted provided that the following conditions
11 * are met: 11 * are met:
12 * 1. Redistributions of source code must retain the above copyright 12 * 1. Redistributions of source code must retain the above copyright
13 * notice, this list of conditions and the following disclaimer. 13 * notice, this list of conditions and the following disclaimer.
14 * 2. Redistributions in binary form must reproduce the above copyright 14 * 2. Redistributions in binary form must reproduce the above copyright
15 * notice, this list of conditions and the following disclaimer in the 15 * notice, this list of conditions and the following disclaimer in the
16 * documentation and/or other materials provided with the distribution. 16 * documentation and/or other materials provided with the distribution.
17 * 3. All advertising materials mentioning features or use of this software 17 * 3. The name of Piermont Information Systems Inc. may not be used to endorse
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 18 * or promote products derived from this software without specific prior
23 * written permission. 19 * written permission.
24 * 20 *
25 * THIS SOFTWARE IS PROVIDED BY PIERMONT INFORMATION SYSTEMS INC. ``AS IS'' 21 * THIS SOFTWARE IS PROVIDED BY PIERMONT INFORMATION SYSTEMS INC. ``AS IS''
26 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 22 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
27 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 23 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
28 * ARE DISCLAIMED. IN NO EVENT SHALL PIERMONT INFORMATION SYSTEMS INC. BE  24 * ARE DISCLAIMED. IN NO EVENT SHALL PIERMONT INFORMATION SYSTEMS INC. BE
29 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR  25 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
30 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF  26 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
31 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 27 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
32 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 28 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
33 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 29 * 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  30 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
35 * THE POSSIBILITY OF SUCH DAMAGE. 31 * THE POSSIBILITY OF SUCH DAMAGE.
36 * 32 *
37 */ 33 */
38 34
39%{ 35%{
40/* scan.l: scanner description for menu compiler. */ 36/* scan.l: scanner description for menu compiler. */
41 37
42#include <stdio.h> 38#include <stdio.h>
43#include <string.h> 39#include <string.h>
44#include "defs.h" 40#include "defs.h"
45#include "parse.h" 41#include "parse.h"
46 42
47static int level; /* For nested comments. */ 43static int level; /* For nested comments. */
48static int comstart; /* line number of comment start. */ 44static int comstart; /* line number of comment start. */
49 45
50%} 46%}
51 47
52%x COMMENT 48%x COMMENT
53%x BRACE 49%x BRACE
54 50
55%option noinput 51%option noinput
56 52
57%% 53%%
58 54
59[ \t]+ { /* ignore spaces and tabs */ } 55[ \t]+ { /* ignore spaces and tabs */ }
60 56
61[\n] { line_no++; } 57[\n] { line_no++; }
62 58
63"="|";"|","|"("|")" { return (int)yytext[0]; } 59"="|";"|","|"("|")" { return (int)yytext[0]; }
64 60
65x { return X; } 61x { return X; }
66 62
67y { return Y; } 63y { return Y; }
68 64
69w { return W; } 65w { return W; }
70 66
71h { return H; } 67h { return H; }
72 68
73no { return NO; } 69no { return NO; }
74 70
75box { return BOX; } 71box { return BOX; }
76 72
77sub { return SUB; } 73sub { return SUB; }
78 74
79help { return HELP; } 75help { return HELP; }
80 76
81menu { return MENU; } 77menu { return MENU; }
82 78
83menus { return MENUS; } 79menus { return MENUS; }
84 80
85next { return NEXT; } 81next { return NEXT; }
86 82
87exit { return EXIT; } 83exit { return EXIT; }
88 84
89exitstring { return EXITSTRING; } 85exitstring { return EXITSTRING; }
90 86
91title { return TITLE; } 87title { return TITLE; }
92 88
93action { return ACTION; } 89action { return ACTION; }
94 90
95endwin { return ENDWIN; } 91endwin { return ENDWIN; }
96 92
97option { return OPTION; } 93option { return OPTION; }
98 94
99default { return DEFAULT; } 95default { return DEFAULT; }
100 96
101display { return DISPLAY; } 97display { return DISPLAY; }
102 98
103error { return ERROR; } 99error { return ERROR; }
104 100
105allow { return ALLOW; } 101allow { return ALLOW; }
106 102
107dynamic { return DYNAMIC; } 103dynamic { return DYNAMIC; }
108 104
109messages { return MESSAGES; } 105messages { return MESSAGES; }
110 106
111scrollable { return SCROLLABLE; } 107scrollable { return SCROLLABLE; }
112 108
113shortcut { return SHORTCUT; } 109shortcut { return SHORTCUT; }
114 110
115clear { return CLEAR; } 111clear { return CLEAR; }
116 112
117always { return ALWAYS; } 113always { return ALWAYS; }
118 114
119scroll { return SCROLL; } 115scroll { return SCROLL; }
120 116
121\"([^\"\n]*(\\\")?)*\" { 117\"([^\"\n]*(\\\")?)*\" {
122 yylval.s_value = strdup (yytext); 118 yylval.s_value = strdup (yytext);
123 max_strlen = max_strlen > strlen(yytext) 119 max_strlen = max_strlen > strlen(yytext)
124 ? max_strlen : strlen(yytext) + 1; 120 ? max_strlen : strlen(yytext) + 1;
125 return STRING; 121 return STRING;
126 } 122 }
127 123
128[a-zA-Z][a-zA-Z0-9_]* { 124[a-zA-Z][a-zA-Z0-9_]* {
129 yylval.s_value = strdup(yytext); 125 yylval.s_value = strdup(yytext);
130 return(NAME); 126 return(NAME);
131 } 127 }
132 128
1330|[-1-9][0-9]* { 1290|[-1-9][0-9]* {
134 yylval.s_value = strdup(yytext);  130 yylval.s_value = strdup(yytext);
135 return(INT_CONST); 131 return(INT_CONST);
136 } 132 }
137 133
138"'"[^'\\]|(\\[athrn])|(\\[0-9][0-9]?[0-9]?)"'" { 134"'"[^'\\]|(\\[athrn])|(\\[0-9][0-9]?[0-9]?)"'" {
139 yylval.s_value = strdup(yytext); 135 yylval.s_value = strdup(yytext);
140 return(CHAR_CONST); 136 return(CHAR_CONST);
141 } 137 }
142 138
143"/*" { level = 1; comstart = line_no; BEGIN COMMENT; } 139"/*" { level = 1; comstart = line_no; BEGIN COMMENT; }
144 140
145<COMMENT>"/*" { level++; } 141<COMMENT>"/*" { level++; }
146 142
147<COMMENT>"*/" { if (level-- == 1) BEGIN 0; } 143<COMMENT>"*/" { if (level-- == 1) BEGIN 0; }
148 144
149<COMMENT>"\n" { line_no++; } 145<COMMENT>"\n" { line_no++; }
150 146
151<COMMENT><<EOF>> { 147<COMMENT><<EOF>> {
152 yyerror ("EOF inside a comment that started at line %d", 148 yyerror ("EOF inside a comment that started at line %d",
153 comstart); 149 comstart);
154 exit (1); 150 exit (1);
155 } 151 }
156 152
157<COMMENT>. {/* eat character */} 153<COMMENT>. {/* eat character */}
158 154
159"{" { level = 1; BEGIN BRACE; } 155"{" { level = 1; BEGIN BRACE; }
160 156
161<BRACE>"{" { buff_add_ch(yytext[0]); level++; } 157<BRACE>"{" { buff_add_ch(yytext[0]); level++; }
162 158
163<BRACE>"}" { if (level-- == 1) { 159<BRACE>"}" { if (level-- == 1) {
164 BEGIN 0; 160 BEGIN 0;
165 yylval.s_value = buff_copy(); 161 yylval.s_value = buff_copy();
166 return CODE; 162 return CODE;
167 } else 163 } else
168 buff_add_ch (yytext[0]); 164 buff_add_ch (yytext[0]);
169 } 165 }
170 166
171<BRACE>"\n" { buff_add_ch (yytext[0]); line_no++; } 167<BRACE>"\n" { buff_add_ch (yytext[0]); line_no++; }
172 168
173<BRACE>. { buff_add_ch (yytext[0]); } 169<BRACE>. { buff_add_ch (yytext[0]); }
174 170
175. { 171. {
176 if (yytext[0] < ' ') 172 if (yytext[0] < ' ')
177 yyerror ("illegal character: ^%c",yytext[0] + '@'); 173 yyerror ("illegal character: ^%c",yytext[0] + '@');
178 else 174 else
179 if (yytext[0] > '~') 175 if (yytext[0] > '~')
180 yyerror ("illegal character: \\%3d", (int) yytext[0]); 176 yyerror ("illegal character: \\%3d", (int) yytext[0]);
181 else 177 else
182 yyerror ("illegal character: %s",yytext); 178 yyerror ("illegal character: %s",yytext);
183 179
184 /* To quiet the compiler */ 180 /* To quiet the compiler */
185 if (0) unput(0); 181 if (0) unput(0);
186 } 182 }
187%% 183%%
188 184
189#ifdef SCAN 185#ifdef SCAN
190YYSTYPE yylval; 186YYSTYPE yylval;
191 187
192main() 188main()
193{ 189{
194 int val; 190 int val;
195 191
196 line_no = 1; 192 line_no = 1;
197 while ( (val = yylex()) != 0 ) 193 while ( (val = yylex()) != 0 )
198 printf ("val = %d\n yytext = %s\n", val, yytext); 194 printf ("val = %d\n yytext = %s\n", val, yytext);
199} 195}
200#endif 196#endif

cvs diff -r1.4 -r1.5 src/usr.bin/menuc/util.c (switch to unified diff)

--- src/usr.bin/menuc/util.c 2004/06/20 22:20:16 1.4
+++ src/usr.bin/menuc/util.c 2012/03/06 16:55:18 1.5
@@ -1,112 +1,107 @@ @@ -1,112 +1,107 @@
1/* $NetBSD: util.c,v 1.4 2004/06/20 22:20:16 jmc Exp $ */ 1/* $NetBSD: util.c,v 1.5 2012/03/06 16:55:18 mbalmer Exp $ */
2 2
3/* 3/*
4 * Copyright 1997 Piermont Information Systems Inc. 4 * Copyright 1997 Piermont Information Systems Inc.
5 * All rights reserved. 5 * All rights reserved.
6 * 6 *
7 * Written by Philip A. Nelson for Piermont Information Systems Inc. 7 * Written by Philip A. Nelson for Piermont Information Systems Inc.
8 * 8 *
9 * Redistribution and use in source and binary forms, with or without 9 * Redistribution and use in source and binary forms, with or without
10 * modification, are permitted provided that the following conditions 10 * modification, are permitted provided that the following conditions
11 * are met: 11 * are met:
12 * 1. Redistributions of source code must retain the above copyright 12 * 1. Redistributions of source code must retain the above copyright
13 * notice, this list of conditions and the following disclaimer. 13 * notice, this list of conditions and the following disclaimer.
14 * 2. Redistributions in binary form must reproduce the above copyright 14 * 2. Redistributions in binary form must reproduce the above copyright
15 * notice, this list of conditions and the following disclaimer in the 15 * notice, this list of conditions and the following disclaimer in the
16 * documentation and/or other materials provided with the distribution. 16 * documentation and/or other materials provided with the distribution.
17 * 3. All advertising materials mentioning features or use of this software 17 * 3. The name of Piermont Information Systems Inc. may not be used to endorse
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 18 * or promote products derived from this software without specific prior
23 * written permission. 19 * written permission.
24 * 20 *
25 * THIS SOFTWARE IS PROVIDED BY PIERMONT INFORMATION SYSTEMS INC. ``AS IS'' 21 * THIS SOFTWARE IS PROVIDED BY PIERMONT INFORMATION SYSTEMS INC. ``AS IS''
26 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 22 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
27 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 23 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
28 * ARE DISCLAIMED. IN NO EVENT SHALL PIERMONT INFORMATION SYSTEMS INC. BE  24 * ARE DISCLAIMED. IN NO EVENT SHALL PIERMONT INFORMATION SYSTEMS INC. BE
29 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR  25 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
30 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF  26 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
31 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 27 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
32 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 28 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
33 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 29 * 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  30 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
35 * THE POSSIBILITY OF SUCH DAMAGE. 31 * THE POSSIBILITY OF SUCH DAMAGE.
36 * 32 *
37 */ 33 */
38 34
39/* util.c - utility routines. */ 35/* util.c - utility routines. */
40 36
41#if HAVE_NBTOOL_CONFIG_H 37#if HAVE_NBTOOL_CONFIG_H
42#include "nbtool_config.h" 38#include "nbtool_config.h"
43#endif 39#endif
44 40
45#include <sys/cdefs.h> 41#include <sys/cdefs.h>
46 42
47#if defined(__RCSID) && !defined(lint) 43#if defined(__RCSID) && !defined(lint)
48__RCSID("$NetBSD: util.c,v 1.4 2004/06/20 22:20:16 jmc Exp $"); 44__RCSID("$NetBSD: util.c,v 1.5 2012/03/06 16:55:18 mbalmer Exp $");
49#endif 45#endif
50 46
51 
52#include <stdio.h> 47#include <stdio.h>
53#include <stdlib.h> 48#include <stdlib.h>
54#include <string.h> 49#include <string.h>
55#include <stdarg.h> 50#include <stdarg.h>
56#include "defs.h" 51#include "defs.h"
57 52
58/* Error routine */ 53/* Error routine */
59void 54void
60yyerror(const char *fmt, ...) 55yyerror(const char *fmt, ...)
61{ 56{
62 va_list args; 57 va_list args;
63 58
64 va_start (args, fmt); 59 va_start(args, fmt);
65 printf ("%s:%d: ", src_name, line_no); 60 printf("%s:%d: ", src_name, line_no);
66 vfprintf (stdout, fmt, args); 61 vfprintf(stdout, fmt, args);
67 printf ("\n"); 62 printf("\n");
68 va_end (args); 63 va_end(args);
69 had_errors = TRUE; 64 had_errors = TRUE;
70} 65}
71 66
72 
73/* Buffer routines */ 67/* Buffer routines */
74static char *mc_buff = NULL; 68static char *mc_buff = NULL;
75static int mc_size = 0; 69static int mc_size = 0;
76static int mc_loc = 0; 70static int mc_loc = 0;
77 71
78void buff_add_ch (char ch) 72void
 73buff_add_ch(char ch)
79{ 74{
80 char *t; 75 char *t;
81 76
82 if (mc_loc >= mc_size-1) { 77 if (mc_loc >= mc_size-1) {
83 if (mc_size == 0) 78 if (mc_size == 0)
84 mc_size = 80; 79 mc_size = 80;
85 else 80 else
86 mc_size *= 2; 81 mc_size *= 2;
87 t = (char *) malloc (mc_size); 82 t = (char *)malloc(mc_size);
88 if (t == NULL) { 83 if (t == NULL) {
89 (void) fprintf (stderr, "%s:%d: Malloc error\n", 84 (void)fprintf(stderr, "%s:%d: Malloc error\n",
90 src_name, line_no); 85 src_name, line_no);
91 exit (1); 86 exit(1);
92 } 87 }
93 if (mc_buff != NULL) { 88 if (mc_buff != NULL) {
94 strcpy (t, mc_buff); 89 strcpy(t, mc_buff);
95 free (mc_buff); 90 free(mc_buff);
96 } 91 }
97 mc_buff = t; 92 mc_buff = t;
98 } 93 }
99 mc_buff[mc_loc++] = ch; 94 mc_buff[mc_loc++] = ch;
100 mc_buff[mc_loc] = '\0'; 95 mc_buff[mc_loc] = '\0';
101} 96}
102 97
103/* get a copy of the string ! */ 98/* get a copy of the string ! */
104 
105char * 99char *
106buff_copy (void) 100buff_copy(void)
107{ 101{
108 char *res = strdup (mc_buff); 102 char *res = strdup(mc_buff);
 103
109 mc_loc = 0; 104 mc_loc = 0;
110 mc_buff[0] = '\0'; 105 mc_buff[0] = '\0';
111 return res; 106 return res;
112} 107}