2 /* Include this before everything else, for various large-file definitions */
5 // warning C4267: 'argument' : conversion from 'size_t' to 'int', possible loss of data
8 #pragma warning(disable : 4267)
13 * We want a reentrant scanner.
18 * We don't use input, so don't generate code for it.
23 * We don't use unput, so don't generate code for it.
28 * We don't read interactively from the terminal.
30 %option never-interactive
33 * We want to stop processing when we get to the end of the input.
38 * The type for the state we keep for a scanner.
40 %option extra-type="WimaxasncpDict_scanner_state_t *"
43 * We have to override the memory allocators so that we don't get
44 * "unused argument" warnings from the yyscanner argument (which
45 * we don't use, as we have a global memory allocator).
47 * We provide, as macros, our own versions of the routines generated by Flex,
48 * which just call malloc()/realloc()/free() (as the Flex versions do),
49 * discarding the extra argument.
56 * The language we're scanning is case-insensitive.
61 * We use start condition stacks.
66 * Prefix scanner routines with "WimaxasncpDict_" rather than "yy", so this
67 * scanner can coexist with other scanners.
69 %option prefix="WimaxasncpDict_"
71 %option outfile="wimaxasncp_dict.c"
76 ** WIMAXASNCP Dictionary Import Routines
78 ** (c) 2007, Luis E. Garcia Ontanon <luis@ontanon.org>
79 ** (c) 2007, Stephen Croll <stephen.d.croll@gmail.com>
81 ** This library is free software; you can redistribute it and/or
82 ** modify it under the terms of the GNU Library General Public
83 ** License as published by the Free Software Foundation; either
84 ** version 2 of the License, or (at your option) any later version.
86 ** This library is distributed in the hope that it will be useful,
87 ** but WITHOUT ANY WARRANTY; without even the implied warranty of
88 ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
89 ** Library General Public License for more details.
91 ** You should have received a copy of the GNU Library General Public
92 ** License along with this library; if not, write to the Free Software
93 ** Foundation, Inc., 51 Franklin Street, Fifth Floor,
94 ** Boston, MA 02110-1301, USA.
103 #include <epan/value_string.h>
104 #include <epan/packet.h> /* array_length */
105 #include <wsutil/file_util.h>
107 #include "wimaxasncp_dict.h"
109 DIAG_OFF(sign-compare)
111 typedef struct entity_t {
114 struct entity_t *next;
117 #define ATTR_UINT(cont) do { D(("attr_uint " #cont "\t" )); yyextra->attr_uint = &(cont); yy_push_state(GET_UINT_ATTR, yyscanner); } while(0)
118 #define ATTR_UINT16(cont) do { D(("attr_uint16 " #cont "\t" )); yyextra->attr_uint16 = &(cont); yy_push_state(GET_UINT16_ATTR, yyscanner); } while(0)
119 #define ATTR_STR(cont) do { D(("attr_str " #cont "\t" )); yyextra->attr_str = &(cont); yy_push_state(GET_ATTR, yyscanner); } while(0)
120 #define ATTR_DECODER(cont) do { D(("attr_decoder " #cont "\t" )); yyextra->attr_uint = &(cont); yy_push_state(GET_DECODER_ATTR, yyscanner); } while(0)
121 #define WIMAXASNCP_IGNORE() do { D(("ignore: %s\t",yytext)); yy_push_state(IGNORE_ATTR, yyscanner); } while(0)
123 #define D(args) wimaxasncp_dict_debug args
125 #define MAX_INCLUDE_DEPTH 10
126 #define YY_INPUT(buf,result,max_size) { result = yyextra->current_yyinput(buf,max_size,yyscanner); }
127 #define YY_USER_INIT { \
128 WimaxasncpDict_scanner_state_t *scanner_state = WimaxasncpDict_get_extra(yyscanner); \
129 BEGIN(scanner_state->start_state); \
132 #define APPEND(txt,len) append_to_buffer(txt,(int)len,yyextra)
137 const gchar *sys_dir;
146 wimaxasncp_dict_t *dict;
147 wimaxasncp_dict_tlv_t *tlv;
148 wimaxasncp_dict_enum_t *enumitem;
149 wimaxasncp_dict_xmlpi_t *xmlpi;
151 wimaxasncp_dict_tlv_t *last_tlv;
152 wimaxasncp_dict_enum_t *last_enumitem;
153 wimaxasncp_dict_xmlpi_t *last_xmlpi;
157 YY_BUFFER_STATE include_stack[MAX_INCLUDE_DEPTH];
158 int include_stack_ptr;
159 size_t (*current_yyinput)(gchar*,size_t,yyscan_t);
166 } WimaxasncpDict_scanner_state_t;
168 static guint wimaxasncp_bits(guint bits, char *n);
169 static gint wimaxasncp_decode_type(const gchar *name);
170 static void wimaxasncp_dict_debug(const gchar *fmt, ...) G_GNUC_PRINTF(1, 2);
171 static void append_to_buffer(const gchar *txt, int len, WimaxasncpDict_scanner_state_t *state);
172 static FILE *wimaxasncp_dict_open(const gchar*, const gchar*);
175 * Sleazy hack to suppress compiler warnings in yy_fatal_error().
177 #define YY_EXIT_FAILURE ((void)yyscanner, 2)
180 * Macros for the allocators, to discard the extra argument.
182 #define WimaxasncpDict_alloc(size, yyscanner) (void *)malloc(size)
183 #define WimaxasncpDict_realloc(ptr, size, yyscanner) (void *)realloc((char *)(ptr), (size))
184 #define WimaxasncpDict_free(ptr, yyscanner) free((char *)ptr)
189 xmlpi_start [[:blank:] \r\n]*<\?[[:blank:] \r\n]*
190 xmlpi_end [[:blank:] \r\n]*\?>[[:blank:] \r\n]*
191 xmlpi_key_attr [[:blank:] \r\n]*key[[:blank:] \r\n]*=[[:blank:] \r\n]*\042
192 xmlpi_value_attr [[:blank:] \r\n]*value[[:blank:] \r\n]*=[[:blank:] \r\n]*\042
194 comment_start [[:blank:] \r\n]*<!--[[:blank:] \r\n]*
195 comment_end [[:blank:] \r\n]*-->[[:blank:] \r\n]*
196 open_tag [[:blank:] \r\n]*<[[:blank:] \r\n]*
197 end_tag [[:blank:] \r\n]*\/>[[:blank:] \r\n]*
198 close_tag [[:blank:] \r\n]*>[[:blank:] \r\n]*
199 open_closetag [[:blank:] \r\n]*<\/[[:blank:] \r\n]*
200 equals [[:blank:] \r\n]*=[[:blank:] \r\n]*
201 whitespace [[:blank:] \r\n]*
202 dquoted \042[^\042]*\042
204 doctype [[:blank:] \r\n]*<!DOCTYPE[^\[]*\[[[:blank:] \r\n]*
205 doctype_end [[:blank:] \r\n]*\][[:blank:] \r\n]*>[[:blank:] \r\n]*
207 start_entity [[:blank:] \r\n]*<\!ENTITY[[:blank:] \r\n]*
208 system [[:blank:] \r\n]*SYSTEM[[:blank:] \r\n]*\042
209 entityname [a-z0-9-]+
211 end_entity \042[[:blank:] \r\n]*>[[:blank:] \r\n]*
223 number [-]?[0-9]*|(0x)?[0-9a-fA-F]*
225 dictionary_start <dictionary>
226 dictionary_end <\/dictionary>
234 ignored_attr [a-z0-9-]+=
235 ignored_quoted \042[^\042]*\042
240 typename_attr type-name=\042
241 description_attr description=\042
242 decoder_attr decoder=\042
243 since_attr since=\042
246 %S LOADING LOADING_COMMENT LOADING_XMLPI ENTITY GET_SYSTEM GET_FILE END_ENTITY
247 %S GET_ATTR GET_UINT_ATTR GET_UINT16_ATTR
248 %S BIT32 BIT16 BIT8 GET_DECODER_ATTR END_ATTR
249 %S OUTSIDE IN_DICT IN_APPL IN_TLV IGNORE_ATTR
250 %S ENUM_ATTRS TLV_ATTRS
251 %S XMLPI_ATTRS XMLPI_GETKEY XMLPI_GETVAL XMLPI_ENDATTR
254 <LOADING>{doctype_end} ;
256 <LOADING>{comment_start} BEGIN LOADING_COMMENT;
258 <LOADING_COMMENT>{comment_end} BEGIN LOADING;
260 <LOADING>{xmlpi_start} BEGIN LOADING_XMLPI;
261 <LOADING_XMLPI>{whitespace} ;
262 <LOADING_XMLPI>{entityname} {
263 yyextra->xmlpi = g_new(wimaxasncp_dict_xmlpi_t,1);
264 yyextra->xmlpi->name = g_strdup(yytext);
265 yyextra->xmlpi->key = NULL;
266 yyextra->xmlpi->value = NULL;
267 yyextra->xmlpi->next = NULL;
269 if (!yyextra->dict->xmlpis) yyextra->last_xmlpi = yyextra->dict->xmlpis = yyextra->xmlpi;
270 else yyextra->last_xmlpi = yyextra->last_xmlpi->next = yyextra->xmlpi;
275 <XMLPI_ATTRS>{xmlpi_key_attr} BEGIN XMLPI_GETKEY;
276 <XMLPI_GETKEY>{ndquot} { yyextra->xmlpi->key = g_strdup(yytext); BEGIN XMLPI_ATTRS; }
278 <XMLPI_ATTRS>{xmlpi_value_attr} BEGIN XMLPI_GETVAL;
279 <XMLPI_GETVAL>{ndquot} { yyextra->xmlpi->value = g_strdup(yytext); BEGIN XMLPI_ATTRS; }
282 <XMLPI_ATTRS>{xmlpi_end} BEGIN LOADING;
285 <LOADING>{start_entity} BEGIN ENTITY;
286 <ENTITY>{entityname} {
287 entity_t *e = g_new(entity_t,1);
288 D(("ENTITY: %s\n",yytext));
289 e->name = g_strdup(yytext);
290 e->next = yyextra->ents;
294 <GET_SYSTEM>{system} BEGIN GET_FILE;
296 D(("GET_FILE: %s\n",yytext));
297 yyextra->ents->file = g_strdup(yytext);
300 <END_ENTITY>{end_entity} BEGIN LOADING;
302 <LOADING>{open_tag} APPEND("<",1);
304 <LOADING>{close_tag} APPEND(">",1);
306 <LOADING>{end_tag} APPEND("/>",2);
308 <LOADING>{open_closetag} APPEND("</",2);
310 <LOADING>{whitespace} APPEND(" ",1);
312 <LOADING>{dquoted} APPEND(yytext,yyleng);
314 <LOADING>{equals} APPEND("=",1);
316 <LOADING>{any} APPEND(yytext,yyleng);
318 <LOADING,IN_DICT>{entity} {
319 gchar *p = ++yytext, *temp_str;
322 while(*p != ';') p++;
326 D(("looking for entity: %s\n",yytext));
328 if ( yyextra->include_stack_ptr >= MAX_INCLUDE_DEPTH ) {
329 yyextra->dict_error = g_string_append(
330 yyextra->dict_error, "included files nested too deeply\n");
334 yyextra->include_stack[yyextra->include_stack_ptr++] = YY_CURRENT_BUFFER;
337 for (e = yyextra->ents; e; e = e->next) {
338 if (strcmp(e->name,yytext) == 0) {
339 yyin = wimaxasncp_dict_open(yyextra->sys_dir,e->file);
340 D(("entity: %s filename: %s yyin: %p\n",e->name,e->file,(void*)yyin));
344 WimaxasncpDict__switch_to_buffer(WimaxasncpDict__create_buffer(yyin, YY_BUF_SIZE, yyscanner), yyscanner);
351 temp_str = g_strdup_printf(
352 "cannot find entity: '%s'\n", yytext);
353 yyextra->dict_error = g_string_append(yyextra->dict_error, temp_str);
361 if (!yyin) yyterminate();
364 D(("closing: %p %i\n",(void*)yyin,yyextra->include_stack_ptr));
366 if ( --yyextra->include_stack_ptr < 0 ) {
367 D(("DONE READING\n"));
371 WimaxasncpDict__delete_buffer(YY_CURRENT_BUFFER, yyscanner);
372 WimaxasncpDict__switch_to_buffer(yyextra->include_stack[yyextra->include_stack_ptr], yyscanner);
379 *yyextra->attr_str = wmem_strdup(wmem_epan_scope(), yytext);
381 yyextra->attr_str = NULL;
385 <GET_UINT_ATTR>{number} {
386 *yyextra->attr_uint = (guint)strtoul(yytext,NULL,0);
388 yyextra->attr_uint = NULL;
392 <GET_UINT16_ATTR>{number} {
393 *yyextra->attr_uint16 = (gint16) strtol(yytext,NULL,0);
395 yyextra->attr_uint16 = NULL;
399 <GET_UINT_ATTR>"WIMAXASNCP_BIT32"[ \t]*"(" { BEGIN BIT32; }
402 *yyextra->attr_uint = wimaxasncp_bits(32, yytext);
403 D(("WIMAXASNCP_BIT32(%s)\n",yytext););
404 yyextra->attr_uint = NULL;
407 <GET_UINT_ATTR>"WIMAXASNCP_BIT16"[ \t]*"(" { BEGIN BIT16; }
410 *yyextra->attr_uint = wimaxasncp_bits(16, yytext);
411 D(("WIMAXASNCP_BIT16(%s)\n",yytext););
412 yyextra->attr_uint = NULL;
415 <GET_UINT_ATTR>"WIMAXASNCP_BIT8"[ \t]*"(" { BEGIN BIT8; }
418 *yyextra->attr_uint = wimaxasncp_bits(8, yytext);
419 D(("WIMAXASNCP_BIT8(%s)\n",yytext););
420 yyextra->attr_uint = NULL;
423 <BIT32,BIT16,BIT8>[ \t]*")" { BEGIN END_ATTR; }
425 <GET_DECODER_ATTR>{ndquot} {
426 *yyextra->attr_uint = wimaxasncp_decode_type(yytext);
428 yyextra->attr_uint = NULL;
432 <END_ATTR>{dquot} { yy_pop_state(yyscanner); }
439 <IGNORE_ATTR>{ignored_quoted} {
440 D(("=>%s<=\n",yytext));
441 yy_pop_state(yyscanner);
444 <OUTSIDE>{dictionary_start} {
445 D(("dictionary_start\n"));
450 <IN_DICT>{tlv_start} {
453 yyextra->tlv = wmem_new0(wmem_epan_scope(), wimaxasncp_dict_tlv_t);
454 yyextra->tlv->hf_root = -1;
455 yyextra->tlv->hf_value = -1;
456 yyextra->tlv->hf_ipv4 = -1;
457 yyextra->tlv->hf_ipv6 = -1;
458 yyextra->tlv->hf_bsid = -1;
459 yyextra->tlv->hf_protocol = -1;
460 yyextra->tlv->hf_port_low = -1;
461 yyextra->tlv->hf_port_high = -1;
462 yyextra->tlv->hf_ipv4_mask = -1;
463 yyextra->tlv->hf_ipv6_mask = -1;
464 yyextra->tlv->hf_vendor_id = -1;
465 yyextra->tlv->hf_vendor_rest_of_info = -1;
467 if (! yyextra->dict->tlvs )
468 yyextra->last_tlv = yyextra->dict->tlvs = yyextra->tlv;
470 yyextra->last_tlv = yyextra->last_tlv->next = yyextra->tlv;
475 <TLV_ATTRS>{name_attr} { ATTR_STR(yyextra->tlv->name); }
476 <TLV_ATTRS>{description_attr} { ATTR_STR(yyextra->tlv->description); }
477 <TLV_ATTRS>{type_attr} { ATTR_UINT16(yyextra->tlv->type); }
478 <TLV_ATTRS>{decoder_attr} { ATTR_DECODER(yyextra->tlv->decoder); }
479 <TLV_ATTRS>{since_attr} { ATTR_UINT(yyextra->tlv->since); }
480 <TLV_ATTRS>{stop} { BEGIN IN_TLV; }
481 <TLV_ATTRS>{stop_end} { BEGIN IN_DICT; }
484 <IN_TLV>{enum_start} {
487 yyextra->enumitem = wmem_new(wmem_epan_scope(), wimaxasncp_dict_enum_t);
488 yyextra->enumitem->name = NULL;
489 yyextra->enumitem->code = 0;
490 yyextra->enumitem->next = NULL;
492 if (!yyextra->tlv->enums)
493 yyextra->last_enumitem = yyextra->tlv->enums = yyextra->enumitem;
495 yyextra->last_enumitem = yyextra->last_enumitem->next = yyextra->enumitem;
501 <ENUM_ATTRS>{name_attr} { ATTR_STR(yyextra->enumitem->name); }
502 <ENUM_ATTRS>{code_attr} { ATTR_UINT(yyextra->enumitem->code); }
504 <ENUM_ATTRS>{stop} { BEGIN IN_TLV; }
505 <ENUM_ATTRS>{stop_end} { BEGIN IN_TLV; }
507 <IN_TLV>{tlv_end} { D(("tlv_end")); BEGIN IN_DICT; }
509 <IN_DICT>{dictionary_end} {
513 <TLV_ATTRS,ENUM_ATTRS>{ignored_attr} WIMAXASNCP_IGNORE();
524 DIAG_ON(sign-compare)
526 static int debugging = 0;
528 static void wimaxasncp_dict_debug(const gchar *fmt, ...) {
532 if (debugging) vfprintf(stderr, fmt, ap);
538 static guint wimaxasncp_bits(guint bits, char *n)
540 return 1u << ((bits - 1) - (strtoul(n, NULL, 10)));
543 static const value_string wimaxasncp_decode_type_vals[] =
545 { WIMAXASNCP_TLV_TBD, "WIMAXASNCP_TLV_TBD"},
546 { WIMAXASNCP_TLV_COMPOUND, "WIMAXASNCP_TLV_COMPOUND"},
547 { WIMAXASNCP_TLV_BYTES, "WIMAXASNCP_TLV_BYTES"},
548 { WIMAXASNCP_TLV_ENUM8, "WIMAXASNCP_TLV_ENUM8"},
549 { WIMAXASNCP_TLV_ENUM16, "WIMAXASNCP_TLV_ENUM16"},
550 { WIMAXASNCP_TLV_ENUM32, "WIMAXASNCP_TLV_ENUM32"},
551 { WIMAXASNCP_TLV_ETHER, "WIMAXASNCP_TLV_ETHER"},
552 { WIMAXASNCP_TLV_ASCII_STRING, "WIMAXASNCP_TLV_ASCII_STRING"},
553 { WIMAXASNCP_TLV_FLAG0, "WIMAXASNCP_TLV_FLAG0"},
554 { WIMAXASNCP_TLV_BITFLAGS8, "WIMAXASNCP_TLV_BITFLAGS8"},
555 { WIMAXASNCP_TLV_BITFLAGS16, "WIMAXASNCP_TLV_BITFLAGS16"},
556 { WIMAXASNCP_TLV_BITFLAGS32, "WIMAXASNCP_TLV_BITFLAGS32"},
557 { WIMAXASNCP_TLV_ID, "WIMAXASNCP_TLV_ID"},
558 { WIMAXASNCP_TLV_HEX8, "WIMAXASNCP_TLV_HEX8"},
559 { WIMAXASNCP_TLV_HEX16, "WIMAXASNCP_TLV_HEX16"},
560 { WIMAXASNCP_TLV_HEX32, "WIMAXASNCP_TLV_HEX32"},
561 { WIMAXASNCP_TLV_DEC8, "WIMAXASNCP_TLV_DEC8"},
562 { WIMAXASNCP_TLV_DEC16, "WIMAXASNCP_TLV_DEC16"},
563 { WIMAXASNCP_TLV_DEC32, "WIMAXASNCP_TLV_DEC32"},
564 { WIMAXASNCP_TLV_IP_ADDRESS, "WIMAXASNCP_TLV_IP_ADDRESS"},
565 { WIMAXASNCP_TLV_IPV4_ADDRESS, "WIMAXASNCP_TLV_IPV4_ADDRESS"},
566 { WIMAXASNCP_TLV_PROTOCOL_LIST, "WIMAXASNCP_TLV_PROTOCOL_LIST"},
567 { WIMAXASNCP_TLV_PORT_RANGE_LIST, "WIMAXASNCP_TLV_PORT_RANGE_LIST"},
568 { WIMAXASNCP_TLV_IP_ADDRESS_MASK_LIST,"WIMAXASNCP_TLV_IP_ADDRESS_MASK_LIST"},
569 { WIMAXASNCP_TLV_EAP, "WIMAXASNCP_TLV_EAP"},
570 { WIMAXASNCP_TLV_VENDOR_SPECIFIC, "WIMAXASNCP_TLV_VENDOR_SPECIFIC"},
574 static gint wimaxasncp_decode_type(const gchar *name)
577 for (i = 0; i < array_length(wimaxasncp_decode_type_vals) - 1; ++i)
579 if (strcmp(name, wimaxasncp_decode_type_vals[i].strptr) == 0)
581 return wimaxasncp_decode_type_vals[i].value;
585 /* not found, emit some sort of error here? */
587 return WIMAXASNCP_TLV_TBD;
590 extern void wimaxasncp_dict_unused(yyscan_t yyscanner);
591 void wimaxasncp_dict_unused(yyscan_t yyscanner) {
592 yy_top_state(yyscanner);
595 static void append_to_buffer(const gchar *txt, int len, WimaxasncpDict_scanner_state_t *state) {
597 if (state->strbuf == NULL) {
598 state->read_ptr = state->write_ptr = state->strbuf = (gchar *)g_malloc(state->size_strbuf);
601 if ( (state->len_strbuf + len + 1) >= state->size_strbuf ) {
602 state->read_ptr = state->strbuf = (gchar *)g_realloc(state->strbuf,state->size_strbuf *= 2);
605 state->write_ptr = state->strbuf + state->len_strbuf;
606 strncpy(state->write_ptr,txt,len);
607 state->len_strbuf += len;
608 state->strbuf[state->len_strbuf] = '\0';
611 static size_t file_input(gchar *buf, size_t max, yyscan_t scanner) {
612 FILE *in = yyget_in(scanner);
615 read_cnt = fread(buf,1,max,in);
617 if ( read_cnt == max ) {
619 } else if (read_cnt > 0) {
627 static size_t string_input(gchar *buf, size_t max, yyscan_t scanner) {
628 WimaxasncpDict_scanner_state_t *statep = yyget_extra(scanner);
630 if (statep->read_ptr >= statep->write_ptr ) {
632 } else if ( statep->read_ptr + max > statep->write_ptr ) {
633 max = statep->write_ptr - statep->read_ptr;
636 memcpy(buf,statep->read_ptr,max);
637 statep->read_ptr += max;
642 static FILE *wimaxasncp_dict_open(
643 const gchar *system_directory,
644 const gchar *filename)
648 if (system_directory)
650 fname = g_strdup_printf("%s%s%s",
651 system_directory, G_DIR_SEPARATOR_S,filename);
655 fname = g_strdup(filename);
658 fh = ws_fopen(fname,"r");
660 D(("fname: %s fh: %p\n",fname,(void*)fh));
668 wimaxasncp_dict_t *wimaxasncp_dict_scan(
669 const gchar *system_directory, const gchar *filename, int dbg,
672 WimaxasncpDict_scanner_state_t state;
679 state.dict_error = g_string_new("");
681 state.sys_dir = system_directory;
683 state.dict = g_new(wimaxasncp_dict_t,1);
684 state.dict->tlvs = NULL;
685 state.dict->xmlpis = NULL;
688 state.size_strbuf = 8192;
689 state.len_strbuf = 0;
691 state.write_ptr = NULL;
692 state.read_ptr = NULL;
695 state.enumitem = NULL;
698 state.last_tlv = NULL;
699 state.last_enumitem = NULL;
700 state.last_xmlpi = NULL;
707 * Reads the file, does some work, and stores a modified version
708 * of the file contents in memory.
710 state.current_yyinput = file_input;
711 state.include_stack_ptr = 0;
713 in = wimaxasncp_dict_open(system_directory,filename);
717 * Couldn't open the dictionary.
719 * Treat all failures other then ENOENT as errors?
725 if (WimaxasncpDict_lex_init(&scanner) != 0) {
726 D(("Can't initialize scanner: %s\n", strerror(errno)));
732 WimaxasncpDict_set_in(in, scanner);
734 /* Associate the state with the scanner */
735 WimaxasncpDict_set_extra(&state, scanner);
737 state.start_state = LOADING;
738 WimaxasncpDict_lex(scanner);
740 WimaxasncpDict_lex_destroy(scanner);
742 * XXX - can the lexical analyzer terminate without closing
743 * all open input files?
746 D(("\n---------------\n%s\n------- %d -------\n",
747 state.strbuf, state.len_strbuf));
752 * Reads the modified version of the file contents and does the
755 state.current_yyinput = string_input;
757 if (WimaxasncpDict_lex_init(&scanner) != 0) {
758 D(("Can't initialize scanner: %s\n", strerror(errno)));
761 g_free(state.strbuf);
765 /* Associate the state with the scanner */
766 WimaxasncpDict_set_extra(&state, scanner);
768 state.start_state = OUTSIDE;
769 WimaxasncpDict_lex(scanner);
771 WimaxasncpDict_lex_destroy(scanner);
772 g_free(state.strbuf);
777 entity_t *next = e->next;
784 if (state.dict_error->len > 0)
786 *error = g_string_free(state.dict_error, FALSE);
791 g_string_free(state.dict_error, TRUE);
796 void wimaxasncp_dict_free(wimaxasncp_dict_t *d) {
797 wimaxasncp_dict_tlv_t *t, *tn;
799 #define FREE_NAMEANDOBJ(n) do { g_free(n->name); g_free(n); } while(0)
801 for (t = d->tlvs; t; t = tn) {
802 wimaxasncp_dict_enum_t *e, *en;
805 for (e = t->enums; e; e = en) {
810 g_free(t->description);
817 void wimaxasncp_dict_print(FILE *fh, wimaxasncp_dict_t *d) {
818 wimaxasncp_dict_tlv_t *tlvp;
822 for (tlvp = d->tlvs; tlvp; tlvp = tlvp->next) {
823 wimaxasncp_dict_enum_t *e;
824 fprintf(fh,"TLV: %s[%u] %s[%d] %s (since %u)\n",
825 tlvp->name ? tlvp->name : "-",
827 val_to_str(tlvp->decoder,
828 wimaxasncp_decode_type_vals,
831 tlvp->description ? tlvp->description : "",
834 for (e = tlvp->enums; e; e = e->next) {
835 fprintf(fh,"\tEnum: %s[%u]\n",
836 e->name ? e->name : "-",
842 #ifdef TEST_WIMAXASNCP_DICT_STANDALONE
843 int main(int argc, char **argv) {
844 wimaxasncp_dict_t *d;
856 fprintf(stderr,"%s: usage [dictionary_dir] dictionary_filename\n",argv[0]);
860 d = wimaxasncp_dict_scan(dname,fname,1,&dict_error);
864 printf("wimaxasncp - %s", dict_error);
868 wimaxasncp_dict_print(stdout, d);