No empty .Rs/.Re
[netbsd-mini2440.git] / crypto / dist / heimdal / lib / asn1 / main.c
blob9bad03fb4f3079fb84d7a0ddc0c00c30a280c722
1 /*
2 * Copyright (c) 1997-2005 Kungliga Tekniska Högskolan
3 * (Royal Institute of Technology, Stockholm, Sweden).
4 * All rights reserved.
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions
8 * are met:
10 * 1. Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer.
13 * 2. Redistributions in binary form must reproduce the above copyright
14 * notice, this list of conditions and the following disclaimer in the
15 * documentation and/or other materials provided with the distribution.
17 * 3. Neither the name of the Institute nor the names of its contributors
18 * may be used to endorse or promote products derived from this software
19 * without specific prior written permission.
21 * THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND
22 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
23 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
24 * ARE DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE
25 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
26 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
27 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
28 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
29 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
30 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
31 * SUCH DAMAGE.
34 #include "gen_locl.h"
35 #include <getarg.h>
36 #include "lex.h"
38 __RCSID("$Heimdal: main.c 20858 2007-06-03 18:56:41Z lha $"
39 "$NetBSD$");
41 extern FILE *yyin;
43 static getarg_strings preserve;
44 static getarg_strings seq;
46 int
47 preserve_type(const char *p)
49 int i;
50 for (i = 0; i < preserve.num_strings; i++)
51 if (strcmp(preserve.strings[i], p) == 0)
52 return 1;
53 return 0;
56 int
57 seq_type(const char *p)
59 int i;
60 for (i = 0; i < seq.num_strings; i++)
61 if (strcmp(seq.strings[i], p) == 0)
62 return 1;
63 return 0;
66 int dce_fix;
67 int rfc1510_bitstring;
68 int version_flag;
69 int help_flag;
70 struct getargs args[] = {
71 { "encode-rfc1510-bit-string", 0, arg_flag, &rfc1510_bitstring },
72 { "decode-dce-ber", 0, arg_flag, &dce_fix },
73 { "preserve-binary", 0, arg_strings, &preserve },
74 { "sequence", 0, arg_strings, &seq },
75 { "version", 0, arg_flag, &version_flag },
76 { "help", 0, arg_flag, &help_flag }
78 int num_args = sizeof(args) / sizeof(args[0]);
80 static void
81 usage(int code)
83 arg_printusage(args, num_args, NULL, "[asn1-file [name]]");
84 exit(code);
87 int error_flag;
89 int
90 main(int argc, char **argv)
92 int ret;
93 const char *file;
94 const char *name = NULL;
95 int optidx = 0;
97 setprogname(argv[0]);
98 if(getarg(args, num_args, argc, argv, &optidx))
99 usage(1);
100 if(help_flag)
101 usage(0);
102 if(version_flag) {
103 print_version(NULL);
104 exit(0);
106 if (argc == optidx) {
107 file = "stdin";
108 name = "stdin";
109 yyin = stdin;
110 } else {
111 file = argv[optidx];
112 yyin = fopen (file, "r");
113 if (yyin == NULL)
114 err (1, "open %s", file);
115 if (argc == optidx + 1) {
116 char *p;
117 name = estrdup(file);
118 p = strrchr(name, '.');
119 if (p)
120 *p = '\0';
121 } else
122 name = argv[optidx + 1];
125 init_generate (file, name);
126 initsym ();
127 ret = yyparse ();
128 if(ret != 0 || error_flag != 0)
129 exit(1);
130 close_generate ();
131 if (argc != optidx)
132 fclose(yyin);
133 return 0;