1*525a267eSThomas Cort /* $NetBSD: main.c,v 1.11 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 /* main.c - main program for menu compiler. */
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: main.c,v 1.11 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 <unistd.h>
51*525a267eSThomas Cort
52*525a267eSThomas Cort #define MAIN
53*525a267eSThomas Cort #include "defs.h"
54*525a267eSThomas Cort
55*525a267eSThomas Cort /* Local prototypes */
56*525a267eSThomas Cort __dead void usage(void);
57*525a267eSThomas Cort
58*525a267eSThomas Cort int
main(int argc,char ** argv)59*525a267eSThomas Cort main(int argc, char **argv)
60*525a267eSThomas Cort {
61*525a267eSThomas Cort int ch;
62*525a267eSThomas Cort
63*525a267eSThomas Cort /* Process the arguments. */
64*525a267eSThomas Cort while ((ch = getopt(argc, argv, "o:")) != -1 ) {
65*525a267eSThomas Cort switch (ch) {
66*525a267eSThomas Cort case 'o': /* output file name */
67*525a267eSThomas Cort out_name = optarg;
68*525a267eSThomas Cort break;
69*525a267eSThomas Cort default:
70*525a267eSThomas Cort usage();
71*525a267eSThomas Cort }
72*525a267eSThomas Cort }
73*525a267eSThomas Cort
74*525a267eSThomas Cort if (optind != argc - 1)
75*525a267eSThomas Cort usage();
76*525a267eSThomas Cort
77*525a267eSThomas Cort src_name = argv[optind];
78*525a267eSThomas Cort
79*525a267eSThomas Cort yyin = fopen(src_name, "r");
80*525a267eSThomas Cort if (yyin == NULL) {
81*525a267eSThomas Cort (void)fprintf(stderr, "%s: could not open %s.\n", prog_name,
82*525a267eSThomas Cort src_name);
83*525a267eSThomas Cort exit(1);
84*525a267eSThomas Cort }
85*525a267eSThomas Cort
86*525a267eSThomas Cort /* The default menu */
87*525a267eSThomas Cort default_menu.info = &default_info;
88*525a267eSThomas Cort default_info.title = "\"\"";
89*525a267eSThomas Cort default_info.helpstr = NULL;
90*525a267eSThomas Cort default_info.exitstr = NULL;
91*525a267eSThomas Cort default_info.mopt = 0;
92*525a267eSThomas Cort default_info.x = -1;
93*525a267eSThomas Cort default_info.y = 0;
94*525a267eSThomas Cort default_info.h = 0;
95*525a267eSThomas Cort default_info.w = 0;
96*525a267eSThomas Cort default_info.numopt = 0;
97*525a267eSThomas Cort default_info.optns = NULL;
98*525a267eSThomas Cort default_info.postact.code = NULL;
99*525a267eSThomas Cort default_info.postact.endwin = FALSE;
100*525a267eSThomas Cort default_info.exitact.code = NULL;
101*525a267eSThomas Cort default_info.exitact.endwin = FALSE;
102*525a267eSThomas Cort
103*525a267eSThomas Cort /* Do the parse */
104*525a267eSThomas Cort (void)yyparse();
105*525a267eSThomas Cort
106*525a267eSThomas Cort return had_errors ? 1 : 0;
107*525a267eSThomas Cort }
108*525a267eSThomas Cort
109*525a267eSThomas Cort
110*525a267eSThomas Cort __dead void
usage(void)111*525a267eSThomas Cort usage(void)
112*525a267eSThomas Cort {
113*525a267eSThomas Cort (void)fprintf (stderr, "%s [-o name] file\n", getprogname());
114*525a267eSThomas Cort exit(1);
115*525a267eSThomas Cort }
116