xref: /minix3/usr.bin/msgc/msgmain.c (revision d44a5ed1c177718aebe860f2bd736ea12fb19804)
1*d44a5ed1SThomas Cort /*	$NetBSD: msgmain.c,v 1.9 2012/03/06 16:26:01 mbalmer Exp $	*/
2*d44a5ed1SThomas Cort 
3*d44a5ed1SThomas Cort /*
4*d44a5ed1SThomas Cort  * Copyright 1997 Piermont Information Systems Inc.
5*d44a5ed1SThomas Cort  * All rights reserved.
6*d44a5ed1SThomas Cort  *
7*d44a5ed1SThomas Cort  * Written by Philip A. Nelson for Piermont Information Systems Inc.
8*d44a5ed1SThomas Cort  *
9*d44a5ed1SThomas Cort  * Redistribution and use in source and binary forms, with or without
10*d44a5ed1SThomas Cort  * modification, are permitted provided that the following conditions
11*d44a5ed1SThomas Cort  * are met:
12*d44a5ed1SThomas Cort  * 1. Redistributions of source code must retain the above copyright
13*d44a5ed1SThomas Cort  *    notice, this list of conditions and the following disclaimer.
14*d44a5ed1SThomas Cort  * 2. Redistributions in binary form must reproduce the above copyright
15*d44a5ed1SThomas Cort  *    notice, this list of conditions and the following disclaimer in the
16*d44a5ed1SThomas Cort  *    documentation and/or other materials provided with the distribution.
17*d44a5ed1SThomas Cort  * 3. The name of Piermont Information Systems Inc. may not be used to endorse
18*d44a5ed1SThomas Cort  *    or promote products derived from this software without specific prior
19*d44a5ed1SThomas Cort  *    written permission.
20*d44a5ed1SThomas Cort  *
21*d44a5ed1SThomas Cort  * THIS SOFTWARE IS PROVIDED BY PIERMONT INFORMATION SYSTEMS INC. ``AS IS''
22*d44a5ed1SThomas Cort  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
23*d44a5ed1SThomas Cort  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
24*d44a5ed1SThomas Cort  * ARE DISCLAIMED. IN NO EVENT SHALL PIERMONT INFORMATION SYSTEMS INC. BE
25*d44a5ed1SThomas Cort  * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
26*d44a5ed1SThomas Cort  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
27*d44a5ed1SThomas Cort  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
28*d44a5ed1SThomas Cort  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
29*d44a5ed1SThomas Cort  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
30*d44a5ed1SThomas Cort  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
31*d44a5ed1SThomas Cort  * THE POSSIBILITY OF SUCH DAMAGE.
32*d44a5ed1SThomas Cort  *
33*d44a5ed1SThomas Cort  */
34*d44a5ed1SThomas Cort 
35*d44a5ed1SThomas Cort /* main.c - main program */
36*d44a5ed1SThomas Cort 
37*d44a5ed1SThomas Cort #if HAVE_NBTOOL_CONFIG_H
38*d44a5ed1SThomas Cort #include "nbtool_config.h"
39*d44a5ed1SThomas Cort #endif
40*d44a5ed1SThomas Cort 
41*d44a5ed1SThomas Cort #include <sys/cdefs.h>
42*d44a5ed1SThomas Cort 
43*d44a5ed1SThomas Cort #if defined(__RCSID) && !defined(lint)
44*d44a5ed1SThomas Cort __RCSID("$NetBSD: msgmain.c,v 1.9 2012/03/06 16:26:01 mbalmer Exp $");
45*d44a5ed1SThomas Cort #endif
46*d44a5ed1SThomas Cort 
47*d44a5ed1SThomas Cort 
48*d44a5ed1SThomas Cort #include <stdio.h>
49*d44a5ed1SThomas Cort #include <stdlib.h>
50*d44a5ed1SThomas Cort #include <unistd.h>
51*d44a5ed1SThomas Cort 
52*d44a5ed1SThomas Cort #define MAIN
53*d44a5ed1SThomas Cort #include "defs.h"
54*d44a5ed1SThomas Cort 
55*d44a5ed1SThomas Cort /* Local prototypes */
56*d44a5ed1SThomas Cort void usage (char *);
57*d44a5ed1SThomas Cort 
58*d44a5ed1SThomas Cort int
main(int argc,char ** argv)59*d44a5ed1SThomas Cort main (int argc, char **argv)
60*d44a5ed1SThomas Cort {
61*d44a5ed1SThomas Cort 	int ch;
62*d44a5ed1SThomas Cort 
63*d44a5ed1SThomas Cort 	prog_name = argv[0];
64*d44a5ed1SThomas Cort 
65*d44a5ed1SThomas Cort 	/* Process the arguments. */
66*d44a5ed1SThomas Cort 	while ( (ch = getopt (argc, argv, "o:")) != -1 ) {
67*d44a5ed1SThomas Cort 		switch (ch) {
68*d44a5ed1SThomas Cort 		case 'o': /* output file name */
69*d44a5ed1SThomas Cort 			out_name = optarg;
70*d44a5ed1SThomas Cort 			break;
71*d44a5ed1SThomas Cort 		default:
72*d44a5ed1SThomas Cort 			usage (prog_name);
73*d44a5ed1SThomas Cort 		}
74*d44a5ed1SThomas Cort 	}
75*d44a5ed1SThomas Cort 
76*d44a5ed1SThomas Cort 	if (optind != argc-1)
77*d44a5ed1SThomas Cort 		usage (prog_name);
78*d44a5ed1SThomas Cort 
79*d44a5ed1SThomas Cort 	src_name = argv[optind];
80*d44a5ed1SThomas Cort 
81*d44a5ed1SThomas Cort 	yyin = fopen (src_name, "r");
82*d44a5ed1SThomas Cort 	if (yyin == NULL) {
83*d44a5ed1SThomas Cort 		(void) fprintf (stderr, "%s: could not open %s.\n",
84*d44a5ed1SThomas Cort 				prog_name, src_name);
85*d44a5ed1SThomas Cort 		exit (1);
86*d44a5ed1SThomas Cort 	}
87*d44a5ed1SThomas Cort 
88*d44a5ed1SThomas Cort 	/* Do the parse */
89*d44a5ed1SThomas Cort 	(void) yyparse ();
90*d44a5ed1SThomas Cort 
91*d44a5ed1SThomas Cort 	if (had_errors)
92*d44a5ed1SThomas Cort 		return 1;
93*d44a5ed1SThomas Cort 
94*d44a5ed1SThomas Cort 	write_msg_file();
95*d44a5ed1SThomas Cort 
96*d44a5ed1SThomas Cort 	return 0;
97*d44a5ed1SThomas Cort }
98*d44a5ed1SThomas Cort 
99*d44a5ed1SThomas Cort 
100*d44a5ed1SThomas Cort void
usage(char * prog)101*d44a5ed1SThomas Cort usage (char *prog)
102*d44a5ed1SThomas Cort {
103*d44a5ed1SThomas Cort 	(void) fprintf (stderr, "%s [-o name] file\n", prog);
104*d44a5ed1SThomas Cort 	exit (1);
105*d44a5ed1SThomas Cort }
106