1 /* $NetBSD: main.c,v 1.1.1.2 2014/04/24 12:45:28 pettai Exp $ */
4 * Copyright (c) 1997-2005 Kungliga Tekniska Högskolan
5 * (Royal Institute of Technology, Stockholm, Sweden).
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
12 * 1. Redistributions of source code must retain the above copyright
13 * notice, this list of conditions and the following disclaimer.
15 * 2. Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in the
17 * documentation and/or other materials provided with the distribution.
19 * 3. Neither the name of the Institute nor the names of its contributors
20 * may be used to endorse or promote products derived from this software
21 * without specific prior written permission.
23 * THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND
24 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
25 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
26 * ARE DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE
27 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
28 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
29 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
30 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
31 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
32 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
37 #include <krb5/getarg.h>
44 static getarg_strings preserve
;
45 static getarg_strings seq
;
48 preserve_type(const char *p
)
51 for (i
= 0; i
< preserve
.num_strings
; i
++)
52 if (strcmp(preserve
.strings
[i
], p
) == 0)
58 seq_type(const char *p
)
61 for (i
= 0; i
< seq
.num_strings
; i
++)
62 if (strcmp(seq
.strings
[i
], p
) == 0)
69 int rfc1510_bitstring
;
74 struct getargs args
[] = {
75 { "template", 0, arg_flag
, &template_flag
},
76 { "encode-rfc1510-bit-string", 0, arg_flag
, &rfc1510_bitstring
},
77 { "decode-dce-ber", 0, arg_flag
, &support_ber
},
78 { "support-ber", 0, arg_flag
, &support_ber
},
79 { "preserve-binary", 0, arg_strings
, &preserve
},
80 { "sequence", 0, arg_strings
, &seq
},
81 { "one-code-file", 0, arg_flag
, &one_code_file
},
82 { "option-file", 0, arg_string
, &option_file
},
83 { "version", 0, arg_flag
, &version_flag
},
84 { "help", 0, arg_flag
, &help_flag
}
86 int num_args
= sizeof(args
) / sizeof(args
[0]);
91 arg_printusage(args
, num_args
, NULL
, "[asn1-file [name]]");
98 main(int argc
, char **argv
)
102 const char *name
= NULL
;
107 setprogname(argv
[0]);
108 if(getarg(args
, num_args
, argc
, argv
, &optidx
))
116 if (argc
== optidx
) {
122 yyin
= fopen (file
, "r");
124 err (1, "open %s", file
);
125 if (argc
== optidx
+ 1) {
127 name
= estrdup(file
);
128 p
= strrchr(name
, '.');
132 name
= argv
[optidx
+ 1];
136 * Parse extra options file
142 opt
= fopen(option_file
, "r");
148 arg
= calloc(2, sizeof(arg
[0]));
153 arg
[0] = option_file
;
157 while (fgets(buf
, sizeof(buf
), opt
) != NULL
) {
158 buf
[strcspn(buf
, "\n\r")] = '\0';
160 arg
= realloc(arg
, (len
+ 2) * sizeof(arg
[0]));
165 arg
[len
] = strdup(buf
);
166 if (arg
[len
] == NULL
) {
176 if(getarg(args
, num_args
, len
, arg
, &optidx
))
180 fprintf(stderr
, "extra args");
186 init_generate (file
, name
);
189 generate_header_of_codefile(name
);
193 if(ret
!= 0 || error_flag
!= 0)
203 for (i
= 1; i
< len
; i
++)