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