1*40c86e8bSmbalmer /* $NetBSD: msgmain.c,v 1.9 2012/03/06 16:26:01 mbalmer Exp $ */
2584c2298Sphil
3584c2298Sphil /*
4584c2298Sphil * Copyright 1997 Piermont Information Systems Inc.
5584c2298Sphil * All rights reserved.
6584c2298Sphil *
7584c2298Sphil * Written by Philip A. Nelson for Piermont Information Systems Inc.
8584c2298Sphil *
9584c2298Sphil * Redistribution and use in source and binary forms, with or without
10584c2298Sphil * modification, are permitted provided that the following conditions
11584c2298Sphil * are met:
12584c2298Sphil * 1. Redistributions of source code must retain the above copyright
13584c2298Sphil * notice, this list of conditions and the following disclaimer.
14584c2298Sphil * 2. Redistributions in binary form must reproduce the above copyright
15584c2298Sphil * notice, this list of conditions and the following disclaimer in the
16584c2298Sphil * documentation and/or other materials provided with the distribution.
17*40c86e8bSmbalmer * 3. The name of Piermont Information Systems Inc. may not be used to endorse
18584c2298Sphil * or promote products derived from this software without specific prior
19584c2298Sphil * written permission.
20584c2298Sphil *
21584c2298Sphil * THIS SOFTWARE IS PROVIDED BY PIERMONT INFORMATION SYSTEMS INC. ``AS IS''
22584c2298Sphil * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
23584c2298Sphil * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
24584c2298Sphil * ARE DISCLAIMED. IN NO EVENT SHALL PIERMONT INFORMATION SYSTEMS INC. BE
25584c2298Sphil * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
26584c2298Sphil * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
27584c2298Sphil * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
28584c2298Sphil * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
29584c2298Sphil * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
30584c2298Sphil * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
31584c2298Sphil * THE POSSIBILITY OF SUCH DAMAGE.
32584c2298Sphil *
33584c2298Sphil */
34584c2298Sphil
35584c2298Sphil /* main.c - main program */
36584c2298Sphil
37b2f78261Sjmc #if HAVE_NBTOOL_CONFIG_H
38b2f78261Sjmc #include "nbtool_config.h"
39b2f78261Sjmc #endif
40b2f78261Sjmc
41a8d6388eSagc #include <sys/cdefs.h>
42a8d6388eSagc
43abcf838dSlukem #if defined(__RCSID) && !defined(lint)
44*40c86e8bSmbalmer __RCSID("$NetBSD: msgmain.c,v 1.9 2012/03/06 16:26:01 mbalmer Exp $");
45a8d6388eSagc #endif
46a8d6388eSagc
47a8d6388eSagc
48584c2298Sphil #include <stdio.h>
49fcd0fb11Smatt #include <stdlib.h>
506abf6a01Sperry #include <unistd.h>
51584c2298Sphil
52584c2298Sphil #define MAIN
53584c2298Sphil #include "defs.h"
54584c2298Sphil
55584c2298Sphil /* Local prototypes */
56584c2298Sphil void usage (char *);
57584c2298Sphil
58584c2298Sphil int
main(int argc,char ** argv)59584c2298Sphil main (int argc, char **argv)
60584c2298Sphil {
61584c2298Sphil int ch;
62584c2298Sphil
63584c2298Sphil prog_name = argv[0];
64584c2298Sphil
65584c2298Sphil /* Process the arguments. */
66979f7a00Slukem while ( (ch = getopt (argc, argv, "o:")) != -1 ) {
67584c2298Sphil switch (ch) {
68584c2298Sphil case 'o': /* output file name */
69584c2298Sphil out_name = optarg;
70584c2298Sphil break;
71584c2298Sphil default:
72584c2298Sphil usage (prog_name);
73584c2298Sphil }
74584c2298Sphil }
75584c2298Sphil
76584c2298Sphil if (optind != argc-1)
77584c2298Sphil usage (prog_name);
78584c2298Sphil
79584c2298Sphil src_name = argv[optind];
80584c2298Sphil
81584c2298Sphil yyin = fopen (src_name, "r");
82584c2298Sphil if (yyin == NULL) {
83584c2298Sphil (void) fprintf (stderr, "%s: could not open %s.\n",
84584c2298Sphil prog_name, src_name);
85584c2298Sphil exit (1);
86584c2298Sphil }
87584c2298Sphil
88584c2298Sphil /* Do the parse */
89584c2298Sphil (void) yyparse ();
90584c2298Sphil
91584c2298Sphil if (had_errors)
92584c2298Sphil return 1;
93584c2298Sphil
94584c2298Sphil write_msg_file();
95584c2298Sphil
96584c2298Sphil return 0;
97584c2298Sphil }
98584c2298Sphil
99584c2298Sphil
100584c2298Sphil void
usage(char * prog)101584c2298Sphil usage (char *prog)
102584c2298Sphil {
103584c2298Sphil (void) fprintf (stderr, "%s [-o name] file\n", prog);
104584c2298Sphil exit (1);
105584c2298Sphil }
106