1 1.53 martin /* $NetBSD: mdb.c,v 1.53 2019/06/23 11:31:10 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.53 martin __RCSID("$NetBSD: mdb.c,v 1.53 2019/06/23 11:31:10 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.52 christos static int menu_no = 1; /* Menu 0 is unused (means no menu) */ 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.52 christos temp = calloc(1, 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.52 christos for (i = 1; 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.52 christos " short opt_menu;\n" 181 1.52 christos " short opt_flags;\n" 182 1.38 dsl " int (*opt_action)(menudesc *, void *);\n" 183 1.30 dsl "};\n\n" 184 1.52 christos "#define OPT_NOMENU 0\n" 185 1.26 dsl "#define OPT_SUB 1\n" 186 1.26 dsl "#define OPT_ENDWIN 2\n" 187 1.26 dsl "#define OPT_EXIT 4\n" 188 1.35 dsl "#define OPT_IGNORE 8\n" 189 1.52 christos "#define OPT_NOSHORT 16\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.52 christos " short y, x;\n" 197 1.52 christos " short h, w;\n" 198 1.52 christos " short mopt;\n" 199 1.52 christos " short numopts;\n" 200 1.52 christos " short cursel;\n" 201 1.52 christos " short 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.51 martin MC_OPT(MC_CONTINUOUS) 229 1.41 dsl MC_OPT(MC_VALID) 230 1.41 dsl #undef MC_OPT 231 1.41 dsl #undef STR 232 1.35 dsl ); 233 1.9 phil 234 1.46 mbalmer (void)fprintf(out_file, "%s", 235 1.1 phil "\n" 236 1.1 phil "/* Prototypes */\n" 237 1.37 dsl "int menu_init(void);\n" 238 1.37 dsl "void process_menu(int, void *);\n" 239 1.45 joerg "__dead void __menu_initerror(void);\n" 240 1.11 phil ); 241 1.11 phil 242 1.11 phil if (do_dynamic) 243 1.46 mbalmer (void)fprintf(out_file, "%s", 244 1.37 dsl "int new_menu(const char *, menu_ent *, int, \n" 245 1.37 dsl "\tint, int, int, int, int,\n" 246 1.37 dsl "\tvoid (*)(menudesc *, void *), " 247 1.37 dsl "void (*)(menudesc *, int, void *),\n" 248 1.37 dsl "\tvoid (*)(menudesc *, void *), " 249 1.37 dsl "const char *, const char *);\n" 250 1.37 dsl "void free_menu(int);\n" 251 1.32 dsl "void set_menu_numopts(int, int);\n" 252 1.50 martin "menudesc *get_menudesc(int);\n" 253 1.11 phil ); 254 1.11 phil 255 1.46 mbalmer (void)fprintf(out_file, "\n/* Menu names */\n"); 256 1.52 christos for (i = 1; i < menu_no; i++) 257 1.46 mbalmer (void)fprintf(out_file, "#define MENU_%s\t%d\n", 258 1.46 mbalmer menus[i]->id, i); 259 1.9 phil 260 1.11 phil if (do_dynamic) 261 1.46 mbalmer (void)fprintf(out_file, "\n#define DYN_MENU_START\t%d", 262 1.46 mbalmer menu_no); 263 1.11 phil 264 1.46 mbalmer (void)fprintf (out_file, "\n#define MAX_STRLEN %d\n" 265 1.46 mbalmer "#endif\n", max_strlen); 266 1.46 mbalmer fclose(out_file); 267 1.1 phil 268 1.1 phil /* Now the C file */ 269 1.46 mbalmer out_file = fopen(cname, "w"); 270 1.1 phil if (out_file == NULL) { 271 1.46 mbalmer (void)fprintf(stderr, "%s: could not open %s.\n", 272 1.46 mbalmer prog_name, cname); 273 1.46 mbalmer exit(1); 274 1.1 phil } 275 1.1 phil 276 1.1 phil /* initial code */ 277 1.46 mbalmer fprintf(out_file, "#include \"%s\"\n\n", hname); 278 1.46 mbalmer fprintf(out_file, "%s\n\n", initcode); 279 1.1 phil 280 1.1 phil /* data definitions */ 281 1.1 phil 282 1.11 phil /* func defs */ 283 1.52 christos for (i = 1; i < menu_no; i++) { 284 1.47 martin if (do_expands && strlen(menus[i]->info->expact.code)) { 285 1.47 martin (void)fprintf(out_file, "/*ARGSUSED*/\n" 286 1.47 martin "static void menu_%d_expact(menudesc *menu, void *arg)\n{\n", i); 287 1.47 martin if (menus[i]->info->expact.endwin) 288 1.47 martin (void)fprintf(out_file, "\tendwin();\n"); 289 1.47 martin (void)fprintf(out_file, "\t%s\n}\n\n", 290 1.47 martin menus[i]->info->expact.code); 291 1.47 martin } 292 1.11 phil if (strlen(menus[i]->info->postact.code)) { 293 1.46 mbalmer (void)fprintf(out_file, "/*ARGSUSED*/\n" 294 1.46 mbalmer "static void menu_%d_postact(menudesc *menu, void *arg)\n{\n", i); 295 1.11 phil if (menus[i]->info->postact.endwin) 296 1.46 mbalmer (void)fprintf(out_file, "\tendwin();\n"); 297 1.46 mbalmer (void)fprintf(out_file, "\t%s\n}\n\n", 298 1.46 mbalmer menus[i]->info->postact.code); 299 1.11 phil } 300 1.11 phil if (strlen(menus[i]->info->exitact.code)) { 301 1.46 mbalmer (void)fprintf(out_file, "/*ARGSUSED*/\n" 302 1.46 mbalmer "static void menu_%d_exitact(menudesc *menu, void *arg)\n{\n", i); 303 1.11 phil if (menus[i]->info->exitact.endwin) 304 1.46 mbalmer (void)fprintf(out_file, "\tendwin();\n"); 305 1.46 mbalmer (void)fprintf(out_file, "\t%s\n}\n\n", 306 1.46 mbalmer menus[i]->info->exitact.code); 307 1.11 phil } 308 1.11 phil j = 0; 309 1.1 phil toptn = menus[i]->info->optns; 310 1.46 mbalmer for (; toptn != NULL; j++, toptn = toptn->next) { 311 1.30 dsl if (strlen(toptn->optact.code) == 0) 312 1.30 dsl continue; 313 1.30 dsl 314 1.46 mbalmer (void)fprintf(out_file, "/*ARGSUSED*/\n" 315 1.46 mbalmer "static int opt_act_%d_%d(menudesc *m, void *arg)\n" 316 1.46 mbalmer "{\n\t%s\n\treturn %s;\n}\n\n", 317 1.46 mbalmer i, j, toptn->optact.code, 318 1.46 mbalmer (toptn->doexit ? "1" : "0")); 319 1.11 phil } 320 1.11 phil 321 1.11 phil } 322 1.11 phil 323 1.11 phil /* optentX */ 324 1.52 christos for (i = 1; i < menu_no; i++) { 325 1.11 phil if (menus[i]->info->numopt > 53) { 326 1.46 mbalmer (void)fprintf(stderr, "Menu %s has " 327 1.11 phil "too many options.\n", 328 1.11 phil menus[i]->info->title); 329 1.46 mbalmer exit(1); 330 1.11 phil } 331 1.46 mbalmer (void)fprintf(out_file, "static menu_ent optent%d[] = {\n", i); 332 1.42 dsl name_is_code = 0; 333 1.42 dsl for (j = 0, toptn = menus[i]->info->optns; toptn; 334 1.42 dsl toptn = toptn->next, j++) { 335 1.42 dsl name_is_code += toptn->name_is_code; 336 1.47 martin (void)fprintf(out_file, "\t{ .opt_name = %s, " 337 1.47 martin ".opt_menu=%d, .opt_flags=%d, .opt_action=", 338 1.42 dsl toptn->name_is_code ? "0" : toptn->name, 339 1.42 dsl toptn->menu, 340 1.11 phil (toptn->issub ? OPT_SUB : 0) 341 1.11 phil +(toptn->doexit ? OPT_EXIT : 0) 342 1.11 phil +(toptn->optact.endwin ? OPT_ENDWIN : 0)); 343 1.11 phil if (strlen(toptn->optact.code)) 344 1.46 mbalmer (void)fprintf(out_file, "opt_act_%d_%d}", i, j); 345 1.8 phil else 346 1.46 mbalmer (void)fprintf(out_file, "NULL}"); 347 1.46 mbalmer (void)fprintf(out_file, "%s\n", 348 1.11 phil (toptn->next ? "," : "")); 349 1.1 phil } 350 1.46 mbalmer (void)fprintf(out_file, "\t};\n\n"); 351 1.11 phil 352 1.42 dsl if (name_is_code) { 353 1.42 dsl menus[i]->info->name_is_code = 1; 354 1.42 dsl fprintf(out_file, "static void menu_%d_legend(" 355 1.42 dsl "menudesc *menu, int opt, void *arg)\n{\n" 356 1.42 dsl "\tswitch (opt) {\n", i); 357 1.42 dsl for (j = 0, toptn = menus[i]->info->optns; toptn; 358 1.42 dsl toptn = toptn->next, j++) { 359 1.42 dsl if (!toptn->name_is_code) 360 1.42 dsl continue; 361 1.42 dsl fprintf(out_file, "\tcase %d:\n\t\t{%s};\n" 362 1.42 dsl "\t\tbreak;\n", j, toptn->name); 363 1.42 dsl } 364 1.42 dsl fprintf(out_file, "\t}\n}\n\n"); 365 1.42 dsl } 366 1.1 phil } 367 1.1 phil 368 1.11 phil 369 1.1 phil /* menus */ 370 1.46 mbalmer if (!do_dynamic) 371 1.46 mbalmer (void)fprintf(out_file, "static int num_menus = %d;\n", 372 1.46 mbalmer menu_no); 373 1.46 mbalmer 374 1.53 martin (void)fprintf(out_file, "static struct menudesc menu_def[] = {\n" 375 1.53 martin "\t{ },\n"); 376 1.52 christos for (i = 1; i < menu_no; i++) { 377 1.46 mbalmer (void)fprintf(out_file, 378 1.49 martin "\t{%s,", menus[i]->info->title); 379 1.49 martin if (do_expands) 380 1.49 martin (void)fprintf(out_file, 381 1.49 martin "NULL,"); 382 1.49 martin (void)fprintf(out_file, 383 1.49 martin "%d,%d,%d,%d,%d,%d,0,0,optent%d,NULL,NULL,", 384 1.49 martin menus[i]->info->y, 385 1.1 phil menus[i]->info->x, menus[i]->info->h, 386 1.1 phil menus[i]->info->w, menus[i]->info->mopt, 387 1.1 phil menus[i]->info->numopt, i); 388 1.5 phil if (menus[i]->info->helpstr == NULL) 389 1.46 mbalmer (void)fprintf(out_file, "NULL"); 390 1.5 phil else { 391 1.5 phil tmpstr = menus[i]->info->helpstr; 392 1.41 dsl if (*tmpstr != '"') 393 1.41 dsl (void)fprintf(out_file, "%s", tmpstr); 394 1.41 dsl else { 395 1.41 dsl /* Skip an initial newline. */ 396 1.41 dsl if (tmpstr[1] == '\n') 397 1.41 dsl *++tmpstr = '"'; 398 1.46 mbalmer (void)fprintf(out_file, "\n"); 399 1.41 dsl while (*tmpstr) { 400 1.41 dsl if (*tmpstr != '\n') { 401 1.46 mbalmer fputc(*tmpstr++, out_file); 402 1.41 dsl continue; 403 1.41 dsl } 404 1.46 mbalmer (void)fprintf(out_file, "\\n\"\n\""); 405 1.5 phil tmpstr++; 406 1.5 phil } 407 1.41 dsl } 408 1.5 phil } 409 1.46 mbalmer (void)fprintf(out_file, ","); 410 1.41 dsl if (menus[i]->info->mopt & MC_NOEXITOPT) 411 1.14 cgd (void) fprintf (out_file, "NULL"); 412 1.14 cgd else if (menus[i]->info->exitstr != NULL) 413 1.46 mbalmer (void)fprintf(out_file, "%s", menus[i]->info->exitstr); 414 1.14 cgd else 415 1.46 mbalmer (void)fprintf(out_file, "\"Exit\""); 416 1.47 martin if (do_expands) { 417 1.47 martin if (strlen(menus[i]->info->expact.code)) 418 1.47 martin (void)fprintf(out_file, ",menu_%d_expact", i); 419 1.47 martin else 420 1.47 martin (void)fprintf(out_file, ",NULL"); 421 1.47 martin } 422 1.11 phil if (strlen(menus[i]->info->postact.code)) 423 1.46 mbalmer (void)fprintf(out_file, ",menu_%d_postact", i); 424 1.11 phil else 425 1.46 mbalmer (void)fprintf(out_file, ",NULL"); 426 1.11 phil if (strlen(menus[i]->info->exitact.code)) 427 1.46 mbalmer (void)fprintf(out_file, ",menu_%d_exitact", i); 428 1.9 phil else 429 1.46 mbalmer (void)fprintf(out_file, ",NULL"); 430 1.42 dsl if (menus[i]->info->name_is_code) 431 1.46 mbalmer (void)fprintf(out_file, ",menu_%d_legend", i); 432 1.42 dsl else 433 1.46 mbalmer (void)fprintf(out_file, ",NULL"); 434 1.11 phil 435 1.46 mbalmer (void)fprintf(out_file, "},\n"); 436 1.9 phil 437 1.5 phil } 438 1.49 martin (void)fprintf(out_file, "{NULL"); 439 1.49 martin if (do_expands) 440 1.49 martin (void)fprintf(out_file, ", NULL"); 441 1.49 martin (void)fprintf(out_file, ", 0, 0, 0, 0, 0, 0, 0, 0, " 442 1.47 martin "NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL"); 443 1.47 martin if (do_expands) 444 1.47 martin (void)fprintf(out_file, ", NULL"); 445 1.47 martin (void)fprintf(out_file, "}};\n\n"); 446 1.1 phil 447 1.2 phil /* __menu_initerror: initscr failed. */ 448 1.46 mbalmer (void)fprintf(out_file, 449 1.2 phil "/* __menu_initerror: initscr failed. */\n" 450 1.2 phil "void __menu_initerror (void) {\n"); 451 1.2 phil if (error_act.code == NULL) { 452 1.46 mbalmer (void)fprintf(out_file, 453 1.2 phil "\t(void) fprintf (stderr, " 454 1.20 phil "\"%%s: Could not initialize curses\\n\", " 455 1.21 cgd "getprogname());\n" 456 1.2 phil "\texit(1);\n" 457 1.2 phil "}\n"); 458 1.2 phil } else { 459 1.2 phil if (error_act.endwin) 460 1.46 mbalmer (void)fprintf(out_file, "\tendwin();\n"); 461 1.46 mbalmer (void)fprintf(out_file, "%s\n}\n", error_act.code); 462 1.2 phil } 463 1.2 phil 464 1.11 phil /* Copy menu_sys.def file. */ 465 1.11 phil while ((ch = fgetc(sys_file)) != '\014') /* Control-L */ 466 1.26 dsl fputc(ch, out_file); 467 1.11 phil 468 1.11 phil if (do_dynamic) { 469 1.11 phil while ((ch = fgetc(sys_file)) != '\n') 470 1.11 phil /* skip it */; 471 1.11 phil while ((ch = fgetc(sys_file)) != EOF) 472 1.11 phil fputc(ch, out_file); 473 1.11 phil } 474 1.46 mbalmer fclose(out_file); 475 1.46 mbalmer fclose(sys_file); 476 1.1 phil } 477