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