Remove the advertising clause and appease the eye a bit (still not good, but better). Almost no functional change.diff -r1.8 -r1.9 src/usr.bin/menuc/defs.h
(mbalmer)
--- 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 | |||
63 | EXTERN char *prog_name; | 59 | EXTERN char *prog_name; | |
64 | EXTERN char *src_name; | 60 | EXTERN char *src_name; | |
65 | EXTERN char *out_name INIT("menu_defs"); | 61 | EXTERN char *out_name INIT("menu_defs"); | |
66 | EXTERN char *sys_name INIT("menu_sys.def"); | 62 | EXTERN char *sys_name INIT("menu_sys.def"); | |
67 | 63 | |||
68 | EXTERN int do_dynamic INIT(0); | 64 | EXTERN int do_dynamic INIT(0); | |
69 | EXTERN int do_msgxlat INIT(0); | 65 | EXTERN int do_msgxlat INIT(0); | |
70 | EXTERN int line_no INIT(1); | 66 | EXTERN int line_no INIT(1); | |
71 | EXTERN int had_errors INIT(FALSE); | 67 | EXTERN int had_errors INIT(FALSE); | |
72 | EXTERN int max_strlen INIT(1); | 68 | EXTERN int max_strlen INIT(1); | |
73 | 69 | |||
74 | EXTERN id_rec *root INIT(NULL); | 70 | EXTERN id_rec *root INIT(NULL); | |
75 | 71 | |||
76 | EXTERN struct menu_info default_info; | 72 | EXTERN struct menu_info default_info; | |
77 | EXTERN id_rec default_menu; | 73 | EXTERN id_rec default_menu; | |
78 | 74 | |||
79 | EXTERN action error_act INIT({NULL}); | 75 | EXTERN action error_act INIT({NULL}); | |
80 | 76 | |||
81 | /* Prototypes. */ | 77 | /* Prototypes. */ | |
82 | 78 | |||
83 | /* From util.c */ | 79 | /* From util.c */ | |
84 | void yyerror(const char *, ...) | 80 | void yyerror(const char *, ...) | |
85 | __attribute__((__format__(__printf__, 1, 2))); | 81 | __attribute__((__format__(__printf__, 1, 2))); | |
86 | void buff_add_ch(char); | 82 | void buff_add_ch(char); | |
87 | char *buff_copy(void); | 83 | char *buff_copy(void); | |
88 | 84 | |||
89 | /* from scan.l */ | 85 | /* from scan.l */ | |
90 | int yylex(void); | 86 | int yylex(void); | |
91 | 87 | |||
92 | /* from parse.y */ | 88 | /* from parse.y */ | |
93 | int yyparse(void); | 89 | int yyparse(void); | |
94 | 90 | |||
95 | /* Vars not defined in main.c */ | 91 | /* Vars not defined in main.c */ | |
96 | extern FILE *yyin; | 92 | extern FILE *yyin; | |
97 | 93 | |||
98 | /* from avl.c */ | 94 | /* from avl.c */ | |
99 | id_rec *find_id(id_rec *, char *); | 95 | id_rec *find_id(id_rec *, char *); | |
100 | int insert_id(id_rec **, id_rec *); | 96 | int insert_id(id_rec **, id_rec *); | |
101 | 97 | |||
102 | /* from mdb.c */ | 98 | /* from mdb.c */ | |
103 | id_rec *get_menu(char *); | 99 | id_rec *get_menu(char *); | |
104 | void check_defined(void); | 100 | void check_defined(void); | |
105 | void write_menu_file(char *); | 101 | void write_menu_file(char *); | |
106 | 102 |
--- 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 */ | |
45 | typedef struct menu_info menu_info; | 41 | typedef 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 | |||
49 | typedef struct id_rec { | 45 | typedef 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 | |||
63 | typedef struct action { | 59 | typedef struct action { | |
64 | char *code; | 60 | char *code; | |
65 | int endwin; | 61 | int endwin; | |
66 | } action; | 62 | } action; | |
67 | 63 | |||
68 | typedef struct optn_info { | 64 | typedef 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 | |||
78 | struct menu_info { | 74 | struct 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 |
--- 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 */ | |
60 | void usage (char *); | 56 | __dead void usage(void); | |
61 | 57 | |||
62 | int | 58 | int | |
63 | main (int argc, char **argv) | 59 | main(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 | |||
119 | void | 110 | __dead void | |
120 | usage (char *prog) | 111 | usage(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 | } |
--- 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 | |
62 | static int menu_no = 0; | 58 | static int menu_no = 0; | |
63 | static id_rec *menus[MAX]; | 59 | static 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 | |||
73 | id_rec * | 69 | id_rec * | |
74 | get_menu (char *name) | 70 | get_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 | ||||
101 | void | 96 | void | |
102 | check_defined (void) | 97 | check_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. */ | |
113 | void | 108 | void | |
114 | write_menu_file (char *initcode) | 109 | write_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 | } |
--- 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. */ | |
57 | static int __menu_init = 0; | 53 | static int __menu_init = 0; | |
58 | static int max_lines = 0, max_cols = 0; | 54 | static int max_lines = 0, max_cols = 0; | |
59 | #ifndef scrolltext | 55 | #ifndef scrolltext | |
60 | static const char *scrolltext = " <: page up, >: page down"; | 56 | static const char *scrolltext = " <: page up, >: page down"; | |
61 | #endif | 57 | #endif | |
62 | 58 | |||
63 | #ifdef DYNAMIC_MENUS | 59 | #ifdef DYNAMIC_MENUS | |
64 | static int num_menus = 0; | 60 | static int num_menus = 0; | |
65 | #define DYN_INIT_NUM 32 | 61 | #define DYN_INIT_NUM 32 | |
66 | static menudesc **menu_list; | 62 | static 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! */ | |
73 | static void init_menu(menudesc *m); | 69 | static void init_menu(menudesc *m); | |
74 | static char opt_ch(menudesc *m, int op_no); | 70 | static char opt_ch(menudesc *m, int op_no); | |
75 | static void draw_menu(menudesc *m, void *arg); | 71 | static void draw_menu(menudesc *m, void *arg); | |
76 | static void process_help(menudesc *m); | 72 | static void process_help(menudesc *m); | |
77 | static void process_req(menudesc *m, void *arg, int req); | 73 | static void process_req(menudesc *m, void *arg, int req); | |
78 | static int menucmd(WINDOW *w); | 74 | static 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 | |||
87 | static int | 83 | static int | |
88 | menucmd(WINDOW *w) | 84 | menucmd(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 | |||
135 | static void | 131 | static void | |
136 | init_menu(menudesc *m) | 132 | init_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 | |||
281 | static char | 277 | static char | |
282 | opt_ch(menudesc *m, int op_no) | 278 | opt_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 | |||
298 | static void | 294 | static void | |
299 | draw_menu_line(menudesc *m, int opt, int cury, void *arg, const char *text) | 295 | draw_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 | |||
319 | static void | 315 | static void | |
320 | draw_menu(menudesc *m, void *arg) | 316 | draw_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 | |||
390 | static void | 386 | static void | |
391 | /*ARGSUSED*/ | 387 | /*ARGSUSED*/ | |
392 | process_help(menudesc *m) | 388 | process_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 | |||
489 | static void | 485 | static void | |
490 | process_req(menudesc *m, void *arg, int req) | 486 | process_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 | |||
596 | int | 592 | int | |
597 | menu_init(void) | 593 | menu_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 | |||
642 | void | 638 | void | |
643 | process_menu(int num, void *arg) | 639 | process_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 | |||
745 | void | 741 | void | |
746 | set_menu_numopts(int menu, int numopts) | 742 | set_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 | |||
756 | static int | 752 | static int | |
757 | double_menus(void) | 753 | double_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 | |||
772 | int | 768 | int | |
773 | new_menu(const char *title, menu_ent *opts, int numopts, | 769 | new_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 | |||
817 | void | 813 | void | |
818 | free_menu(int menu_no) | 814 | free_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 | } |
--- 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 | |
47 | This implements a curses based menu system. | 43 | This implements a curses based menu system. | |
48 | A source file that describes menus, their options, and how to process | 44 | A source file that describes menus, their options, and how to process | |
49 | the options is given to | 45 | the options is given to | |
50 | .Nm | 46 | .Nm | |
51 | and produces both a .c and a .h file that implement the menu system. | 47 | and produces both a .c and a .h file that implement the menu system. | |
52 | The standard base name of the files is | 48 | The standard base name of the files is | |
53 | .Pa menu_defs . | 49 | .Pa menu_defs . | |
54 | The | 50 | The | |
55 | .Fl o Ar name | 51 | .Fl o Ar name | |
56 | can be used to specify a different base name. | 52 | can 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 | |
60 | Can be set to point to a different set of definition files for | 56 | Can be set to point to a different set of definition files for | |
61 | .Nm . | 57 | .Nm . | |
62 | The current location defaults to | 58 | The 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 | |
66 | The input | 62 | The input | |
67 | .Ar file | 63 | .Ar file | |
68 | defines static menus and options for processing those menus. | 64 | defines static menus and options for processing those menus. | |
69 | It also contains comments, initial C code that is required to provide | 65 | It also contains comments, initial C code that is required to provide | |
70 | for definitions and other code necessary for the menu system, and an | 66 | for definitions and other code necessary for the menu system, and an | |
71 | option declaration if dynamic menus are requested. | 67 | option declaration if dynamic menus are requested. | |
72 | .Pp | 68 | .Pp | |
73 | Comments may appear anywhere in the input | 69 | Comments may appear anywhere in the input | |
74 | .Ar file | 70 | .Ar file | |
75 | and are like a space in the input. | 71 | and are like a space in the input. | |
76 | They are like C comments starting with | 72 | They are like C comments starting with | |
77 | .Em /* | 73 | .Em /* | |
78 | and ending with | 74 | and ending with | |
79 | .Em */ . | 75 | .Em */ . | |
80 | They are unlike C comments in that they may be nested. | 76 | They are unlike C comments in that they may be nested. | |
81 | A comment does not end until a matching end comment is found. | 77 | A comment does not end until a matching end comment is found. | |
82 | .Pp | 78 | .Pp | |
83 | In many places, C code is included in the definition | 79 | In many places, C code is included in the definition | |
84 | .Ar file . | 80 | .Ar file . | |
85 | All C code is passed verbatim to the C output file. | 81 | All C code is passed verbatim to the C output file. | |
86 | .Nm | 82 | .Nm | |
87 | comments do not start in C code and comments in the C code are | 83 | comments do not start in C code and comments in the C code are | |
88 | passed verbatim to the output. | 84 | passed verbatim to the output. | |
89 | The C comments are not recognized by | 85 | The C comments are not recognized by | |
90 | .Nm . | 86 | .Nm . | |
91 | In all cases, C code starts with a left brace | 87 | In all cases, C code starts with a left brace | |
92 | .Pq Em \&{ | 88 | .Pq Em \&{ | |
93 | and ends with the matching right brace | 89 | and ends with the matching right brace | |
94 | .Pq Em \&} . | 90 | .Pq Em \&} . | |
95 | It is important to recognize that in code segments, any brace | 91 | It is important to recognize that in code segments, any brace | |
96 | will be counted, even if it is in a C comment inside the code. | 92 | will be counted, even if it is in a C comment inside the code. | |
97 | .Pp | 93 | .Pp | |
98 | The | 94 | The | |
99 | .Ar file | 95 | .Ar file | |
100 | contains an initial (and optional) code block followed by any | 96 | contains an initial (and optional) code block followed by any | |
101 | number of menu definition elements in any order. | 97 | number of menu definition elements in any order. | |
102 | The initial code block usually contains includes of header files used by | 98 | The initial code block usually contains includes of header files used by | |
103 | code in the menu code blocks later in the | 99 | code in the menu code blocks later in the | |
104 | .Ar file . | 100 | .Ar file . | |
105 | If | 101 | If | |
106 | .Dv USER_MENU_INIT | 102 | .Dv USER_MENU_INIT | |
107 | is #defined, then it will be evaluated before the | 103 | is #defined, then it will be evaluated before the | |
108 | rest of the menu is initialised, if it evaluates to a non-zero value | 104 | rest of the menu is initialised, if it evaluates to a non-zero value | |
109 | then the initialisation will fail. | 105 | then the initialisation will fail. | |
110 | The file is free format, so the actual formatting of the input | 106 | The file is free format, so the actual formatting of the input | |
111 | .Ar file | 107 | .Ar file | |
112 | is to the taste of the programmer. | 108 | is to the taste of the programmer. | |
113 | .Pp | 109 | .Pp | |
114 | All other C code that will appear in an | 110 | All other C code that will appear in an | |
115 | .Em action . | 111 | .Em action . | |
116 | This will be specified as | 112 | This will be specified as | |
117 | .Aq Em action | 113 | .Aq Em action | |
118 | in later text. | 114 | in later text. | |
119 | Such an action will appear as: | 115 | Such 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] | |
121 | in the | 117 | in the | |
122 | .Ar file . | 118 | .Ar file . | |
123 | The | 119 | The | |
124 | .Aq Em opt_endwin , | 120 | .Aq Em opt_endwin , | |
125 | if present is: | 121 | if present is: | |
126 | .Dl ( endwin ) | 122 | .Dl ( endwin ) | |
127 | and specifies that the curses | 123 | and specifies that the curses | |
128 | .Fn endwin | 124 | .Fn endwin | |
129 | function should be called before executing the code and | 125 | function should be called before executing the code and | |
130 | then reinstating the current curses window after the | 126 | then reinstating the current curses window after the | |
131 | code has been run. | 127 | code has been run. | |
132 | The | 128 | The | |
133 | .Aq Em code | 129 | .Aq Em code | |
134 | is as described above. | 130 | is as described above. | |
135 | .Pp | 131 | .Pp | |
136 | There are four kinds of menu definition elements. | 132 | There are four kinds of menu definition elements. | |
137 | The first one just declares whether the programmer wants dynamic menus | 133 | The first one just declares whether the programmer wants dynamic menus | |
138 | available. | 134 | available. | |
139 | The default is static menus only. | 135 | The default is static menus only. | |
140 | The static menus are the ones defined by the menu definitions and do not | 136 | The static menus are the ones defined by the menu definitions and do not | |
141 | change at run time. | 137 | change at run time. | |
142 | The dynamic menus provide the programmer with a method to create and | 138 | The dynamic menus provide the programmer with a method to create and | |
143 | modify menus during the running of the program. | 139 | modify menus during the running of the program. | |
144 | To include dynamic menus, one needs only add the declaration: | 140 | To include dynamic menus, one needs only add the declaration: | |
145 | .Dl allow dynamic menus ; | 141 | .Dl allow dynamic menus ; | |
146 | The semicolon is required to terminate this declaration. | 142 | The semicolon is required to terminate this declaration. | |
147 | This declaration may appear anywhere in the | 143 | This declaration may appear anywhere in the | |
148 | .Ar file , | 144 | .Ar file , | |
149 | but usually appears before any menus are defined. | 145 | but usually appears before any menus are defined. | |
150 | .Pp | 146 | .Pp | |
151 | The next element is a code block to execute if the curses | 147 | The next element is a code block to execute if the curses | |
152 | screen can not be successfully initialized. | 148 | screen can not be successfully initialized. | |
153 | The declaration | 149 | The declaration | |
154 | .Dl error code ; | 150 | .Dl error code ; | |
155 | tells the menu system to execute the associated code block | 151 | tells the menu system to execute the associated code block | |
156 | if the initialization fails. | 152 | if the initialization fails. | |
157 | If no code is provided, a default code block is used that prints | 153 | If no code is provided, a default code block is used that prints | |
158 | .Dl Could not initialize curses. | 154 | .Dl Could not initialize curses. | |
159 | and exits. | 155 | and exits. | |
160 | This element may appear anywhere in the | 156 | This element may appear anywhere in the | |
161 | .Ar file | 157 | .Ar file | |
162 | but usually appears before any menus are defined. | 158 | but usually appears before any menus are defined. | |
163 | .Pp | 159 | .Pp | |
164 | The next element defines default options for menus. | 160 | The next element defines default options for menus. | |
165 | Each menu is built from a list of options. | 161 | Each menu is built from a list of options. | |
166 | These options include the location of the upper left corner of the menu, | 162 | These options include the location of the upper left corner of the menu, | |
167 | whether there is a "box" drawn around the menu, whether the menu is | 163 | whether there is a "box" drawn around the menu, whether the menu is | |
168 | scrollable, the menu's title, whether shortcut letters are | 164 | scrollable, the menu's title, whether shortcut letters are | |
169 | allowed, whether a standard exit option should be included | 165 | allowed, whether a standard exit option should be included | |
170 | in the menu and text associated with the standard exit option. | 166 | in the menu and text associated with the standard exit option. | |
171 | The general format is: | 167 | The 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 | |
174 | The supported options are: | 170 | The 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 | |
177 | The column number of the upper left corner of the menu window. | 173 | The column number of the upper left corner of the menu window. | |
178 | If | 174 | If | |
179 | .Va startx | 175 | .Va startx | |
180 | is -1 the menu will be centered horizontally. | 176 | is -1 the menu will be centered horizontally. | |
181 | .It Ic y = Va starty | 177 | .It Ic y = Va starty | |
182 | The row number of the upper left corner of the menu window. | 178 | The row number of the upper left corner of the menu window. | |
183 | If | 179 | If | |
184 | .Va starty | 180 | .Va starty | |
185 | is negative then the menu will be placed below any message text, but | 181 | is negative then the menu will be placed below any message text, but | |
186 | in at least row | 182 | in at least row | |
187 | .Va -starty . | 183 | .Va -starty . | |
188 | .It Ic h = Va height | 184 | .It Ic h = Va height | |
189 | Specifies the number of menu entries to be displayed. | 185 | Specifies the number of menu entries to be displayed. | |
190 | If zero, the height will be based on the number of entries. | 186 | If zero, the height will be based on the number of entries. | |
191 | .It Ic h = Va width | 187 | .It Ic h = Va width | |
192 | Specifies the width of the menu window. | 188 | Specifies the width of the menu window. | |
193 | If zero, the width will be that of the longest menu text line. | 189 | If zero, the width will be that of the longest menu text line. | |
194 | .It Ic title Va text | 190 | .It Ic title Va text | |
195 | The specified | 191 | The specified | |
196 | .Va text | 192 | .Va text | |
197 | will be displayed at the top of the menu window (inside any box). | 193 | will be displayed at the top of the menu window (inside any box). | |
198 | .It Ic box | 194 | .It Ic box | |
199 | If specified, draw a box around the menu. | 195 | If specified, draw a box around the menu. | |
200 | .It Ic clear | 196 | .It Ic clear | |
201 | If specified, clear the window before performing the | 197 | If specified, clear the window before performing the | |
202 | .Va action . | 198 | .Va action . | |
203 | .It Ic exit | 199 | .It Ic exit | |
204 | If specified add an addition option to exit the menu. | 200 | If specified add an addition option to exit the menu. | |
205 | .It Ic exitstring Va text | 201 | .It Ic exitstring Va text | |
206 | The menu label for the | 202 | The menu label for the | |
207 | .Va exit | 203 | .Va exit | |
208 | option. | 204 | option. | |
209 | If not specified defaults to "exit". | 205 | If not specified defaults to "exit". | |
210 | .It Ic default exit | 206 | .It Ic default exit | |
211 | If specified, place the cursor on the | 207 | If specified, place the cursor on the | |
212 | .Va exit | 208 | .Va exit | |
213 | line of the menu, instead of the top line. | 209 | line of the menu, instead of the top line. | |
214 | .It Ic shortcut | 210 | .It Ic shortcut | |
215 | If specified, add alphabetic tags to each menu line. | 211 | If specified, add alphabetic tags to each menu line. | |
216 | .It Ic scrollable | 212 | .It Ic scrollable | |
217 | If specified, and the menu has more lines than will fit in its window, then | 213 | If specified, and the menu has more lines than will fit in its window, then | |
218 | only part of the menu will be displayed and the | 214 | only part of the menu will be displayed and the | |
219 | .Sq \*[Lt] | 215 | .Sq \*[Lt] | |
220 | and | 216 | and | |
221 | .Sq \*[Gt] | 217 | .Sq \*[Gt] | |
222 | keys will scroll the displayed menu lines. | 218 | keys will scroll the displayed menu lines. | |
223 | .It Ic always scroll | 219 | .It Ic always scroll | |
224 | If specified, allow for the scroll message line even if the menu doesn't | 220 | If specified, allow for the scroll message line even if the menu doesn't | |
225 | appear to have too many lines. | 221 | appear to have too many lines. | |
226 | Useful for dynamic menus, when the number of entries isn't known when the | 222 | Useful for dynamic menus, when the number of entries isn't known when the | |
227 | menu window is created.. | 223 | menu window is created.. | |
228 | .It Ic sub menu | 224 | .It Ic sub menu | |
229 | If specified, the screen contents that the menu window overwrites are saved | 225 | If specified, the screen contents that the menu window overwrites are saved | |
230 | and restored when the menu exits. | 226 | and restored when the menu exits. | |
231 | .El | 227 | .El | |
232 | The | 228 | The | |
233 | .Ic box , clear , exit , default exit , shortcut , scrollable , always scroll , | 229 | .Ic box , clear , exit , default exit , shortcut , scrollable , always scroll , | |
234 | and | 230 | and | |
235 | .Ic sub menu | 231 | .Ic sub menu | |
236 | options can be preceded by | 232 | options can be preceded by | |
237 | .Ic no | 233 | .Ic no | |
238 | in order to negate a default. | 234 | in order to negate a default. | |
239 | .Pp | 235 | .Pp | |
240 | The | 236 | The | |
241 | .Va text | 237 | .Va text | |
242 | arguments can be either a quoted text string or a name #defined to something | 238 | arguments can be either a quoted text string or a name #defined to something | |
243 | suitable for initialising a const char * field. | 239 | suitable for initialising a const char * field. | |
244 | .Pp | 240 | .Pp | |
245 | The default declaration may appear multiple times. | 241 | The default declaration may appear multiple times. | |
246 | Each time, it sets the default values for menu definitions that follow | 242 | Each time, it sets the default values for menu definitions that follow | |
247 | in the | 243 | in the | |
248 | .Ar file . | 244 | .Ar file . | |
249 | In each menu definition, any or all of these default definitions | 245 | In each menu definition, any or all of these default definitions | |
250 | may be overridden for that menu. | 246 | may be overridden for that menu. | |
251 | .Pp | 247 | .Pp | |
252 | The final element is the actual static menu definitions. | 248 | The final element is the actual static menu definitions. | |
253 | The format and order for a menu definition is: | 249 | The format and order for a menu definition is: | |
254 | .Bd -ragged -offset indent | 250 | .Bd -ragged -offset indent | |
255 | menu \*[Lt]name\*[Gt] \*[Lt]options\*[Gt] ; | 251 | menu \*[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 | |
262 | Names are unquoted strings of alpha-numeric and underscore | 258 | Names are unquoted strings of alpha-numeric and underscore | |
263 | characters. | 259 | characters. | |
264 | They must start with an alpha character. | 260 | They must start with an alpha character. | |
265 | In C source, a menu named | 261 | In C source, a menu named | |
266 | .Dq foo | 262 | .Dq foo | |
267 | is appears as | 263 | is appears as | |
268 | .Dq MENU_foo . | 264 | .Dq MENU_foo . | |
269 | (Capitalization is important.) | 265 | (Capitalization is important.) | |
270 | This is important, because the menu is displayed and processed by | 266 | This is important, because the menu is displayed and processed by | |
271 | calling the function | 267 | calling the function | |
272 | .Dl process_menu (MENU_foo, arg) ; | 268 | .Dl process_menu (MENU_foo, arg) ; | |
273 | .Pp | 269 | .Pp | |
274 | The options are a comma separated list of options as in the | 270 | The options are a comma separated list of options as in the | |
275 | .Dq default | 271 | .Dq default | |
276 | declaration. | 272 | declaration. | |
277 | These override the options from the most recent default declaration. | 273 | These override the options from the most recent default declaration. | |
278 | .Pp | 274 | .Pp | |
279 | The display action is optional and provides C code to | 275 | The display action is optional and provides C code to | |
280 | execute at each and every time the menu is displayed for processing. | 276 | execute at each and every time the menu is displayed for processing. | |
281 | If it is included, the format is: | 277 | If it is included, the format is: | |
282 | .Dl display \*[Lt]action\*[Gt] ; | 278 | .Dl display \*[Lt]action\*[Gt] ; | |
283 | .Pp | 279 | .Pp | |
284 | The bulk of the menu definition is the specification | 280 | The bulk of the menu definition is the specification | |
285 | of the menu items. | 281 | of the menu items. | |
286 | The general format of a menu item is: | 282 | The 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] ; | |
288 | The | 284 | The | |
289 | .Aq Em string | 285 | .Aq Em string | |
290 | is the text displayed for the menu item, this must be a quoted string | 286 | is the text displayed for the menu item, this must be a quoted string | |
291 | or a name #defined to something that will initialise a const char * field. | 287 | or a name #defined to something that will initialise a const char * field. | |
292 | There may be an arbitrary number of these items. | 288 | There 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 | |
294 | of 51 should be recognized. | 290 | of 51 should be recognized. | |
295 | It produces shortcuts a to w, y, z, and A to Z. | 291 | It produces shortcuts a to w, y, z, and A to Z. | |
296 | x is the shortcut for the exit item.) | 292 | x is the shortcut for the exit item.) | |
297 | .Pp | 293 | .Pp | |
298 | The | 294 | The | |
299 | .Aq Em element_list | 295 | .Aq Em element_list | |
300 | is a comma separated list of what to do when the item is selected. | 296 | is a comma separated list of what to do when the item is selected. | |
301 | They may appear in any order. | 297 | They may appear in any order. | |
302 | .Pp | 298 | .Pp | |
303 | The first element processed when a menu item | 299 | The first element processed when a menu item | |
304 | is selected is the associated action. | 300 | is selected is the associated action. | |
305 | The next element to be processed is the sub or next menu option. | 301 | The next element to be processed is the sub or next menu option. | |
306 | They are declared as: | 302 | They 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] | |
309 | The difference between these two is that a sub | 305 | The difference between these two is that a sub | |
310 | menu will return to the current menu when exited. | 306 | menu will return to the current menu when exited. | |
311 | The next menu will just replace the current | 307 | The next menu will just replace the current | |
312 | menu and when exited, will return to where the | 308 | menu and when exited, will return to where the | |
313 | current menu would have gone. | 309 | current menu would have gone. | |
314 | Only one of menu element may be used for each menu item. | 310 | Only one of menu element may be used for each menu item. | |
315 | Finally, after processing both the action and a sub menu, | 311 | Finally, after processing both the action and a sub menu, | |
316 | the current menu will be exited if the element | 312 | the current menu will be exited if the element | |
317 | .Dl exit | 313 | .Dl exit | |
318 | is specified. | 314 | is specified. | |
319 | .Em Note : | 315 | .Em Note : | |
320 | If | 316 | If | |
321 | .Em exit | 317 | .Em exit | |
322 | is specified, next menu will not work because | 318 | is specified, next menu will not work because | |
323 | the menu system will exit the | 319 | the menu system will exit the | |
324 | .Em current | 320 | .Em current | |
325 | menu, even if current has been set by | 321 | menu, even if current has been set by | |
326 | .Em next menu . | 322 | .Em next menu . | |
327 | .Pp | 323 | .Pp | |
328 | After all menu items, the final two menu definition | 324 | After all menu items, the final two menu definition | |
329 | elements may appear. | 325 | elements may appear. | |
330 | The exit action is optional and provides C code to | 326 | The exit action is optional and provides C code to | |
331 | execute in the process of exiting a menu. | 327 | execute in the process of exiting a menu. | |
332 | If it is included, the format is: | 328 | If it is included, the format is: | |
333 | .Dl exit \*[Lt]action\*[Gt] ; | 329 | .Dl exit \*[Lt]action\*[Gt] ; | |
334 | .Pp | 330 | .Pp | |
335 | The final part of the menu definition is the optional | 331 | The final part of the menu definition is the optional | |
336 | help string. | 332 | help string. | |
337 | The format is: | 333 | The format is: | |
338 | .Dl help \*[Lt]text\*[Gt] ; | 334 | .Dl help \*[Lt]text\*[Gt] ; | |
339 | This text is displayed in a full page | 335 | This text is displayed in a full page | |
340 | help window if the question mark is typed. | 336 | help window if the question mark is typed. | |
341 | The actual help text starts with a left brace | 337 | The actual help text starts with a left brace | |
342 | .Pq Em \&{ | 338 | .Pq Em \&{ | |
343 | and ends with the matching right brace | 339 | and ends with the matching right brace | |
344 | .Pq Em \&} . | 340 | .Pq Em \&} . | |
345 | The braces are not included in the | 341 | The braces are not included in the | |
346 | help string, but all other characters between | 342 | help string, but all other characters between | |
347 | them are included. | 343 | them are included. | |
348 | Newlines in the code translate to newlines in the help text. | 344 | Newlines in the code translate to newlines in the help text. | |
349 | Alternatively, the name of a const char * variable may be given. | 345 | Alternatively, the name of a const char * variable may be given. | |
350 | .Sh DYNAMIC MENUS | 346 | .Sh DYNAMIC MENUS | |
351 | If requested, | 347 | If requested, | |
352 | .Nm | 348 | .Nm | |
353 | supports dynamic menus by allowing the user to create new | 349 | supports dynamic menus by allowing the user to create new | |
354 | menus. | 350 | menus. | |
355 | The related definitions for using dynamic menus are: | 351 | The related definitions for using dynamic menus are: | |
356 | .Bd -literal | 352 | .Bd -literal | |
357 | struct menudesc; | 353 | struct menudesc; | |
358 | 354 | |||
359 | typedef | 355 | typedef | |
360 | struct menu_ent { | 356 | struct 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 | |||
375 | typedef | 371 | typedef | |
376 | struct menudesc { | 372 | struct 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 | |||
404 | int new_menu(const char *title, menu_ent *opts, int numopts, | 400 | int 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 | |||
411 | void free_menu (int menu_no); | 407 | void free_menu (int menu_no); | |
412 | .Ed | 408 | .Ed | |
413 | .Pp | 409 | .Pp | |
414 | The | 410 | The | |
415 | .Ar title | 411 | .Ar title | |
416 | is the title displayed at the top of the menu. | 412 | is the title displayed at the top of the menu. | |
417 | The | 413 | The | |
418 | .Ar opts | 414 | .Ar opts | |
419 | is an array of menu entry definitions that has | 415 | is an array of menu entry definitions that has | |
420 | .Ar numopts | 416 | .Ar numopts | |
421 | elements. | 417 | elements. | |
422 | The programmer must build this array and | 418 | The programmer must build this array and | |
423 | fill in all of the fields before processing calling | 419 | fill in all of the fields before processing calling | |
424 | .Fn process_menu | 420 | .Fn process_menu | |
425 | for the new menu. | 421 | for the new menu. | |
426 | The fields of the | 422 | The fields of the | |
427 | .Ar opts | 423 | .Ar opts | |
428 | may change at any time. | 424 | may change at any time. | |
429 | For example, | 425 | For example, | |
430 | .Em opt_name | 426 | .Em opt_name | |
431 | may change as a result of selecting that option. | 427 | may change as a result of selecting that option. | |
432 | When the menu is redisplayed, the new text is printed. | 428 | When the menu is redisplayed, the new text is printed. | |
433 | Arguments, | 429 | Arguments, | |
434 | .Ar x , y , h , | 430 | .Ar x , y , h , | |
435 | and | 431 | and | |
436 | .Ar w | 432 | .Ar w | |
437 | are the same as the options in the menu description. | 433 | are the same as the options in the menu description. | |
438 | .Ar mopt | 434 | .Ar mopt | |
439 | is the boolean options. | 435 | is the boolean options. | |
440 | Note, box, clear, exit and shortcuts are enabled by default. | 436 | Note, box, clear, exit and shortcuts are enabled by default. | |
441 | You need to add option flags to turn them off or turn on scrollable menus. | 437 | You need to add option flags to turn them off or turn on scrollable menus. | |
442 | The options | 438 | The options | |
443 | .Ar post_act , | 439 | .Ar post_act , | |
444 | and | 440 | and | |
445 | .Ar exit_act | 441 | .Ar exit_act | |
446 | are function pointers to the display action and the exit action. | 442 | are function pointers to the display action and the exit action. | |
447 | If they are | 443 | If they are | |
448 | .Dv NULL , | 444 | .Dv NULL , | |
449 | no call will be made. | 445 | no call will be made. | |
450 | .Ar draw_line | 446 | .Ar draw_line | |
451 | will be called to display the menu line if the corresponding opt_name | 447 | will be called to display the menu line if the corresponding opt_name | |
452 | field is | 448 | field is | |
453 | .Dv NULL . | 449 | .Dv NULL . | |
454 | .Ar help | 450 | .Ar help | |
455 | is the text to display in a help screen. | 451 | is the text to display in a help screen. | |
456 | And finally, | 452 | And finally, | |
457 | .Ar exitstr | 453 | .Ar exitstr | |
458 | is the text for the 'exit' line of the menu. | 454 | is the text for the 'exit' line of the menu. | |
459 | If | 455 | If | |
460 | .Dv NULL , | 456 | .Dv NULL , | |
461 | "Exit" is used. | 457 | "Exit" is used. | |
462 | A | 458 | A | |
463 | .Dv NULL | 459 | .Dv NULL | |
464 | help pointer will disable the help feature for the menu. | 460 | help 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 | |
471 | The following is a simple menu definition file. | 467 | The following is a simple menu definition file. | |
472 | It is complete in that the output of | 468 | It is complete in that the output of | |
473 | .Nm | 469 | .Nm | |
474 | may be compiled into a complete program. | 470 | may be compiled into a complete program. | |
475 | For example, if the following was in a file called | 471 | For example, if the following was in a file called | |
476 | .Pa example.mc , | 472 | .Pa example.mc , | |
477 | an executable program could be produced by the following commands. | 473 | an executable program could be produced by the following commands. | |
478 | .Bd -literal -offset indent | 474 | .Bd -literal -offset indent | |
479 | menuc -o example example.mc | 475 | menuc -o example example.mc | |
480 | cc -o example example.c -lcurses | 476 | cc -o example example.c -lcurses | |
481 | .Ed | 477 | .Ed | |
482 | A much more complete example is available with the source | 478 | A much more complete example is available with the source | |
483 | distribution in a subdirectory called | 479 | distribution 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. */ | |
493 | int | 489 | int | |
494 | main() | 490 | main() | |
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! */ | |
502 | void | 498 | void | |
503 | init_main() | 499 | init_main() | |
504 | { | 500 | { | |
505 | } | 501 | } | |
506 | } | 502 | } | |
507 | 503 | |||
508 | default x=20, y=10, box, scrollable, exit; | 504 | default x=20, y=10, box, scrollable, exit; | |
509 | 505 | |||
510 | error action { | 506 | error 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 | |||
515 | menu main, title "Main Menu", no exit, no shortcut; | 511 | menu 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 { | |
526 | This is a simple help screen for an example menu definition file. | 522 | This is a simple help screen for an example menu definition file. | |
527 | }; | 523 | }; | |
528 | 524 | |||
529 | menu othermenu, title "Sub/Next Menu", x=5, y=5, no box; | 525 | menu 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 | |
536 | for Piermont Information Systems Inc. | 532 | for Piermont Information Systems Inc. | |
537 | Initial ideas for this were developed and implemented in Pascal at the | 533 | Initial ideas for this were developed and implemented in Pascal at the | |
538 | Leiden University, Netherlands, in the summer of 1980. | 534 | Leiden University, Netherlands, in the summer of 1980. | |
539 | .Sh BUGS | 535 | .Sh BUGS | |
540 | Both | 536 | Both | |
541 | .Nm | 537 | .Nm | |
542 | and | 538 | and | |
543 | .Nm msgc | 539 | .Nm msgc | |
544 | are probably only used by | 540 | are probably only used by | |
545 | .Nm sysinst . | 541 | .Nm sysinst . | |
546 | The features of both have been tailored for | 542 | The features of both have been tailored for | |
547 | .Nm sysinst , | 543 | .Nm sysinst , | |
548 | and further changes are likely to occur. | 544 | and further changes are likely to occur. |
--- 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 | |||
45 | static id_rec *cur_menu; | 41 | static id_rec *cur_menu; | |
46 | static optn_info *cur_optn; | 42 | static 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 | |||
72 | system : init_code menu_list | 68 | system : 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 | |||
79 | init_code : /* empty */ { $$ = ""; } | 75 | init_code : /* empty */ { $$ = ""; } | |
80 | | CODE | 76 | | CODE | |
81 | ; | 77 | ; | |
82 | 78 | |||
83 | menu_list : /* empty */ | 79 | menu_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 | |||
91 | dynamic_def : ALLOW DYNAMIC MENUS ';' | 87 | dynamic_def : ALLOW DYNAMIC MENUS ';' | |
92 | { do_dynamic = 1; } | 88 | { do_dynamic = 1; } | |
93 | 89 | |||
94 | msgxlat_def : ALLOW DYNAMIC MESSAGES ';' | 90 | msgxlat_def : ALLOW DYNAMIC MESSAGES ';' | |
95 | { do_msgxlat = 1; } | 91 | { do_msgxlat = 1; } | |
96 | 92 | |||
97 | initerror_def : ERROR action ';' | 93 | initerror_def : ERROR action ';' | |
98 | { error_act = $2; } | 94 | { error_act = $2; } | |
99 | 95 | |||
100 | default_def : DEFAULT | 96 | default_def : DEFAULT | |
101 | { cur_menu = &default_menu; } | 97 | { cur_menu = &default_menu; } | |
102 | opt opt_list ";" | 98 | opt opt_list ";" | |
103 | 99 | |||
104 | menu_def : MENU NAME | 100 | menu_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 | |||
127 | opts : /* empty */ | 123 | opts : /* empty */ | |
128 | | opt_list | 124 | | opt_list | |
129 | ; | 125 | ; | |
130 | 126 | |||
131 | opt_list : "," opt | 127 | opt_list : "," opt | |
132 | | opt_list "," opt | 128 | | opt_list "," opt | |
133 | ; | 129 | ; | |
134 | 130 | |||
135 | text : NAME | STRING | 131 | text : NAME | STRING | |
136 | 132 | |||
137 | opt : NO EXIT { cur_menu->info->mopt |= MC_NOEXITOPT; } | 133 | opt : 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 | |||
162 | option_list : option | 158 | option_list : option | |
163 | | option_list option { $2->next = $1; $$ = $2; } | 159 | | option_list option { $2->next = $1; $$ = $2; } | |
164 | ; | 160 | ; | |
165 | 161 | |||
166 | option : OPTION | 162 | option : 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 | |||
182 | option_legend : text { cur_optn->name = $1; } | 178 | option_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 | |||
185 | elem_list : elem | 181 | elem_list : elem | |
186 | | elem_list "," elem | 182 | | elem_list "," elem | |
187 | ; | 183 | ; | |
188 | 184 | |||
189 | elem : NEXT MENU NAME | 185 | elem : 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 | |||
210 | action : ACTION act_opt CODE | 206 | action : ACTION act_opt CODE | |
211 | { $$.code = $3; | 207 | { $$.code = $3; | |
212 | $$.endwin = $2; | 208 | $$.endwin = $2; | |
213 | } | 209 | } | |
214 | ; | 210 | ; | |
215 | 211 | |||
216 | act_opt : /* empty */ { $$ = 0; } | 212 | act_opt : /* empty */ { $$ = 0; } | |
217 | | "(" ENDWIN ")" { $$ = 1; } | 213 | | "(" ENDWIN ")" { $$ = 1; } | |
218 | ; | 214 | ; | |
219 | 215 | |||
220 | dispact : /* empty */ { cur_menu->info->postact.code = ""; } | 216 | dispact : /* 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 | |||
225 | exitact : /* empty */ { cur_menu->info->exitact.code = ""; } | 221 | exitact : /* 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 | |||
229 | helpstr : /* empty */ { cur_menu->info->helpstr = NULL; } | 225 | helpstr : /* 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 | ; |
--- 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 | |||
47 | static int level; /* For nested comments. */ | 43 | static int level; /* For nested comments. */ | |
48 | static int comstart; /* line number of comment start. */ | 44 | static 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 | |||
65 | x { return X; } | 61 | x { return X; } | |
66 | 62 | |||
67 | y { return Y; } | 63 | y { return Y; } | |
68 | 64 | |||
69 | w { return W; } | 65 | w { return W; } | |
70 | 66 | |||
71 | h { return H; } | 67 | h { return H; } | |
72 | 68 | |||
73 | no { return NO; } | 69 | no { return NO; } | |
74 | 70 | |||
75 | box { return BOX; } | 71 | box { return BOX; } | |
76 | 72 | |||
77 | sub { return SUB; } | 73 | sub { return SUB; } | |
78 | 74 | |||
79 | help { return HELP; } | 75 | help { return HELP; } | |
80 | 76 | |||
81 | menu { return MENU; } | 77 | menu { return MENU; } | |
82 | 78 | |||
83 | menus { return MENUS; } | 79 | menus { return MENUS; } | |
84 | 80 | |||
85 | next { return NEXT; } | 81 | next { return NEXT; } | |
86 | 82 | |||
87 | exit { return EXIT; } | 83 | exit { return EXIT; } | |
88 | 84 | |||
89 | exitstring { return EXITSTRING; } | 85 | exitstring { return EXITSTRING; } | |
90 | 86 | |||
91 | title { return TITLE; } | 87 | title { return TITLE; } | |
92 | 88 | |||
93 | action { return ACTION; } | 89 | action { return ACTION; } | |
94 | 90 | |||
95 | endwin { return ENDWIN; } | 91 | endwin { return ENDWIN; } | |
96 | 92 | |||
97 | option { return OPTION; } | 93 | option { return OPTION; } | |
98 | 94 | |||
99 | default { return DEFAULT; } | 95 | default { return DEFAULT; } | |
100 | 96 | |||
101 | display { return DISPLAY; } | 97 | display { return DISPLAY; } | |
102 | 98 | |||
103 | error { return ERROR; } | 99 | error { return ERROR; } | |
104 | 100 | |||
105 | allow { return ALLOW; } | 101 | allow { return ALLOW; } | |
106 | 102 | |||
107 | dynamic { return DYNAMIC; } | 103 | dynamic { return DYNAMIC; } | |
108 | 104 | |||
109 | messages { return MESSAGES; } | 105 | messages { return MESSAGES; } | |
110 | 106 | |||
111 | scrollable { return SCROLLABLE; } | 107 | scrollable { return SCROLLABLE; } | |
112 | 108 | |||
113 | shortcut { return SHORTCUT; } | 109 | shortcut { return SHORTCUT; } | |
114 | 110 | |||
115 | clear { return CLEAR; } | 111 | clear { return CLEAR; } | |
116 | 112 | |||
117 | always { return ALWAYS; } | 113 | always { return ALWAYS; } | |
118 | 114 | |||
119 | scroll { return SCROLL; } | 115 | scroll { 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 | |||
133 | 0|[-1-9][0-9]* { | 129 | 0|[-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 | |
190 | YYSTYPE yylval; | 186 | YYSTYPE yylval; | |
191 | 187 | |||
192 | main() | 188 | main() | |
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 |
--- 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 */ | |
59 | void | 54 | void | |
60 | yyerror(const char *fmt, ...) | 55 | yyerror(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 */ | |
74 | static char *mc_buff = NULL; | 68 | static char *mc_buff = NULL; | |
75 | static int mc_size = 0; | 69 | static int mc_size = 0; | |
76 | static int mc_loc = 0; | 70 | static int mc_loc = 0; | |
77 | 71 | |||
78 | void buff_add_ch (char ch) | 72 | void | |
73 | buff_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 | ||||
105 | char * | 99 | char * | |
106 | buff_copy (void) | 100 | buff_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 | } |