9 #include "asn1parser.h"
10 #include "asn1p_list.h"
12 int asn1p_parse(void **param);
14 void *asn1p__scan_bytes(const char *, int len);
15 void *asn1p__delete_buffer(void *);
16 void *asn1p_restart(FILE *);
18 extern int asn1p_lineno;
20 static int _asn1p_set_flags(enum asn1p_flags flags);
21 static int _asn1p_fix_modules(asn1p_t *a, const char *fname);
24 * Parse the given buffer.
27 asn1p_parse_buffer(const char *buffer, int size /* = -1 */, const char *debug_filename, int initial_lineno, enum asn1p_flags flags) {
33 if(_asn1p_set_flags(flags)) {
39 size = (int)strlen(buffer);
41 ybuf = asn1p__scan_bytes(buffer, size);
47 asn1p_lineno = initial_lineno;
50 asn1p_parse_debug_filename = debug_filename;
51 ret = asn1p_parse(ap);
52 asn1p_parse_debug_filename = NULL;
54 asn1p__delete_buffer(ybuf);
58 if(_asn1p_fix_modules(a, "-")) {
60 return NULL; /* FIXME: destroy (a) */
72 * Parse the file identified by its name.
75 asn1p_parse_file(const char *filename, enum asn1p_flags flags) {
84 if(_asn1p_set_flags(flags)) {
89 fp = fopen(filename, "r");
96 if(fstat(fileno(fp), &sb)
97 || !S_ISREG(sb.st_mode)) {
99 fprintf(stderr, "%s file not recognized: Bad file format\n",
111 asn1p_parse_debug_filename = filename;
112 ret = asn1p_parse(ap);
113 asn1p_parse_debug_filename = NULL;
119 if(_asn1p_fix_modules(a, filename)) {
121 return NULL; /* FIXME: destroy (a) */
131 extern int asn1p_lexer_types_year;
132 extern int asn1p_lexer_constructs_year;
133 extern int asn1p_lexer_extended_values;
134 extern int asn1p__flex_debug;
135 extern int asn1p_debug;
138 _asn1p_set_flags(enum asn1p_flags flags) {
140 asn1p_lexer_types_year = 0;
141 asn1p_lexer_constructs_year = 0;
142 asn1p__flex_debug = 0;
145 if(flags & A1P_DEBUG_LEXER) {
146 flags &= ~A1P_DEBUG_LEXER;
147 asn1p__flex_debug = 1;
150 if(flags & A1P_DEBUG_PARSER) {
151 flags &= ~A1P_DEBUG_PARSER;
155 if(flags & A1P_EXTENDED_VALUES) {
156 flags &= ~A1P_EXTENDED_VALUES;
157 asn1p_lexer_extended_values = 1;
159 asn1p_lexer_extended_values = 0;
163 * Check that we haven't missed an unknown flag.
174 _asn1p_fix_modules(asn1p_t *a, const char *fname) {
176 TQ_FOR(mod, &(a->modules), mod_next) {
177 mod->source_file_name = strdup(fname);
178 if(mod->source_file_name == NULL)