2 /* Include this before everything else, for various large-file definitions */
8 * We want a reentrant scanner.
13 * We don't use input, so don't generate code for it.
18 * We don't use unput, so don't generate code for it.
23 * We don't read interactively from the terminal.
25 %option never-interactive
28 * We want to stop processing when we get to the end of the input.
33 * The type for the state we keep for a scanner.
35 %option extra-type="WimaxasncpDict_scanner_state_t *"
38 * We have to override the memory allocators so that we don't get
39 * "unused argument" warnings from the yyscanner argument (which
40 * we don't use, as we have a global memory allocator).
42 * We provide, as macros, our own versions of the routines generated by Flex,
43 * which just call malloc()/realloc()/free() (as the Flex versions do),
44 * discarding the extra argument.
51 * The language we're scanning is case-insensitive.
56 * We use start condition stacks.
61 * Prefix scanner routines with "WimaxasncpDict_" rather than "yy", so this
62 * scanner can coexist with other scanners.
64 %option prefix="WimaxasncpDict_"
69 ** WIMAXASNCP Dictionary Import Routines
71 ** (c) 2007, Luis E. Garcia Ontanon <luis@ontanon.org>
72 ** (c) 2007, Stephen Croll <stephen.d.croll@gmail.com>
74 ** This library is free software; you can redistribute it and/or
75 ** modify it under the terms of the GNU Library General Public
76 ** License as published by the Free Software Foundation; either
77 ** version 2 of the License, or (at your option) any later version.
79 ** This library is distributed in the hope that it will be useful,
80 ** but WITHOUT ANY WARRANTY; without even the implied warranty of
81 ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
82 ** Library General Public License for more details.
84 ** You should have received a copy of the GNU Library General Public
85 ** License along with this library; if not, write to the Free Software
86 ** Foundation, Inc., 51 Franklin Street, Fifth Floor,
87 ** Boston, MA 02110-1301, USA.
96 #include <epan/value_string.h>
97 #include <epan/packet.h> /* array_length */
98 #include <wsutil/file_util.h>
100 #include "wimaxasncp_dict.h"
103 * Disable diagnostics in the code generated by Flex.
107 typedef struct entity_t {
110 struct entity_t *next;
113 #define ATTR_UINT(cont) do { D(("attr_uint " #cont "\t" )); yyextra->attr_uint = &(cont); yy_push_state(GET_UINT_ATTR, yyscanner); } while(0)
114 #define ATTR_UINT16(cont) do { D(("attr_uint16 " #cont "\t" )); yyextra->attr_uint16 = &(cont); yy_push_state(GET_UINT16_ATTR, yyscanner); } while(0)
115 #define ATTR_STR(cont) do { D(("attr_str " #cont "\t" )); yyextra->attr_str = &(cont); yy_push_state(GET_ATTR, yyscanner); } while(0)
116 #define ATTR_DECODER(cont) do { D(("attr_decoder " #cont "\t" )); yyextra->attr_uint = &(cont); yy_push_state(GET_DECODER_ATTR, yyscanner); } while(0)
117 #define WIMAXASNCP_IGNORE() do { D(("ignore: %s\t",yytext)); yy_push_state(IGNORE_ATTR, yyscanner); } while(0)
119 #define D(args) wimaxasncp_dict_debug args
121 #define MAX_INCLUDE_DEPTH 10
122 #define YY_INPUT(buf,result,max_size) { result = yyextra->current_yyinput(buf,max_size,yyscanner); }
123 #define YY_USER_INIT { \
124 WimaxasncpDict_scanner_state_t *scanner_state = WimaxasncpDict_get_extra(yyscanner); \
125 BEGIN(scanner_state->start_state); \
128 #define APPEND(txt,len) append_to_buffer(txt,(int)len,yyextra)
136 unsigned size_strbuf;
142 wimaxasncp_dict_t *dict;
143 wimaxasncp_dict_tlv_t *tlv;
144 wimaxasncp_dict_enum_t *enumitem;
145 wimaxasncp_dict_xmlpi_t *xmlpi;
147 wimaxasncp_dict_tlv_t *last_tlv;
148 wimaxasncp_dict_enum_t *last_enumitem;
149 wimaxasncp_dict_xmlpi_t *last_xmlpi;
153 YY_BUFFER_STATE include_stack[MAX_INCLUDE_DEPTH];
154 int include_stack_ptr;
155 size_t (*current_yyinput)(char*,size_t,yyscan_t);
159 int16_t *attr_uint16;
162 } WimaxasncpDict_scanner_state_t;
164 static unsigned wimaxasncp_bits(unsigned bits, char *n);
165 static int wimaxasncp_decode_type(const char *name);
166 static void wimaxasncp_dict_debug(const char *fmt, ...) G_GNUC_PRINTF(1, 2);
167 static void append_to_buffer(const char *txt, int len, WimaxasncpDict_scanner_state_t *state);
168 static FILE *wimaxasncp_dict_open(const char*, const char*);
171 * Sleazy hack to suppress compiler warnings in yy_fatal_error().
173 #define YY_EXIT_FAILURE ((void)yyscanner, 2)
176 * Macros for the allocators, to discard the extra argument.
178 #define WimaxasncpDict_alloc(size, yyscanner) (void *)malloc(size)
179 #define WimaxasncpDict_realloc(ptr, size, yyscanner) (void *)realloc((char *)(ptr), (size))
180 #define WimaxasncpDict_free(ptr, yyscanner) free((char *)ptr)
185 xmlpi_start [[:blank:] \r\n]*<\?[[:blank:] \r\n]*
186 xmlpi_end [[:blank:] \r\n]*\?>[[:blank:] \r\n]*
187 xmlpi_key_attr [[:blank:] \r\n]*key[[:blank:] \r\n]*=[[:blank:] \r\n]*\042
188 xmlpi_value_attr [[:blank:] \r\n]*value[[:blank:] \r\n]*=[[:blank:] \r\n]*\042
190 comment_start [[:blank:] \r\n]*<!--[[:blank:] \r\n]*
191 comment_end [[:blank:] \r\n]*-->[[:blank:] \r\n]*
192 open_tag [[:blank:] \r\n]*<[[:blank:] \r\n]*
193 end_tag [[:blank:] \r\n]*\/>[[:blank:] \r\n]*
194 close_tag [[:blank:] \r\n]*>[[:blank:] \r\n]*
195 open_closetag [[:blank:] \r\n]*<\/[[:blank:] \r\n]*
196 equals [[:blank:] \r\n]*=[[:blank:] \r\n]*
197 whitespace [[:blank:] \r\n]*
198 dquoted \042[^\042]*\042
200 doctype [[:blank:] \r\n]*<!DOCTYPE[^\[]*\[[[:blank:] \r\n]*
201 doctype_end [[:blank:] \r\n]*\][[:blank:] \r\n]*>[[:blank:] \r\n]*
203 start_entity [[:blank:] \r\n]*<\!ENTITY[[:blank:] \r\n]*
204 system [[:blank:] \r\n]*SYSTEM[[:blank:] \r\n]*\042
205 entityname [a-z0-9-]+
207 end_entity \042[[:blank:] \r\n]*>[[:blank:] \r\n]*
219 number [-]?[0-9]*|(0x)?[0-9a-fA-F]*
221 dictionary_start <dictionary>
222 dictionary_end <\/dictionary>
230 ignored_attr [a-z0-9-]+=
231 ignored_quoted \042[^\042]*\042
236 typename_attr type-name=\042
237 description_attr description=\042
238 decoder_attr decoder=\042
239 since_attr since=\042
242 %S LOADING LOADING_COMMENT LOADING_XMLPI ENTITY GET_SYSTEM GET_FILE END_ENTITY
243 %S GET_ATTR GET_UINT_ATTR GET_UINT16_ATTR
244 %S BIT32 BIT16 BIT8 GET_DECODER_ATTR END_ATTR
245 %S OUTSIDE IN_DICT IN_APPL IN_TLV IGNORE_ATTR
246 %S ENUM_ATTRS TLV_ATTRS
247 %S XMLPI_ATTRS XMLPI_GETKEY XMLPI_GETVAL XMLPI_ENDATTR
250 <LOADING>{doctype_end} ;
252 <LOADING>{comment_start} BEGIN LOADING_COMMENT;
254 <LOADING_COMMENT>{comment_end} BEGIN LOADING;
256 <LOADING>{xmlpi_start} BEGIN LOADING_XMLPI;
257 <LOADING_XMLPI>{whitespace} ;
258 <LOADING_XMLPI>{entityname} {
259 yyextra->xmlpi = g_new(wimaxasncp_dict_xmlpi_t,1);
260 yyextra->xmlpi->name = g_strdup(yytext);
261 yyextra->xmlpi->key = NULL;
262 yyextra->xmlpi->value = NULL;
263 yyextra->xmlpi->next = NULL;
265 if (!yyextra->dict->xmlpis) yyextra->last_xmlpi = yyextra->dict->xmlpis = yyextra->xmlpi;
266 else yyextra->last_xmlpi = yyextra->last_xmlpi->next = yyextra->xmlpi;
271 <XMLPI_ATTRS>{xmlpi_key_attr} BEGIN XMLPI_GETKEY;
272 <XMLPI_GETKEY>{ndquot} { yyextra->xmlpi->key = g_strdup(yytext); BEGIN XMLPI_ATTRS; }
274 <XMLPI_ATTRS>{xmlpi_value_attr} BEGIN XMLPI_GETVAL;
275 <XMLPI_GETVAL>{ndquot} { yyextra->xmlpi->value = g_strdup(yytext); BEGIN XMLPI_ATTRS; }
278 <XMLPI_ATTRS>{xmlpi_end} BEGIN LOADING;
281 <LOADING>{start_entity} BEGIN ENTITY;
282 <ENTITY>{entityname} {
283 entity_t *e = g_new(entity_t,1);
284 D(("ENTITY: %s\n",yytext));
285 e->name = g_strdup(yytext);
286 e->next = yyextra->ents;
290 <GET_SYSTEM>{system} BEGIN GET_FILE;
292 D(("GET_FILE: %s\n",yytext));
293 yyextra->ents->file = g_strdup(yytext);
296 <END_ENTITY>{end_entity} BEGIN LOADING;
298 <LOADING>{open_tag} APPEND("<",1);
300 <LOADING>{close_tag} APPEND(">",1);
302 <LOADING>{end_tag} APPEND("/>",2);
304 <LOADING>{open_closetag} APPEND("</",2);
306 <LOADING>{whitespace} APPEND(" ",1);
308 <LOADING>{dquoted} APPEND(yytext,yyleng);
310 <LOADING>{equals} APPEND("=",1);
312 <LOADING>{any} APPEND(yytext,yyleng);
314 <LOADING,IN_DICT>{entity} {
315 char *p = ++yytext, *temp_str;
318 while(*p != ';') p++;
322 D(("looking for entity: %s\n",yytext));
324 if ( yyextra->include_stack_ptr >= MAX_INCLUDE_DEPTH ) {
325 yyextra->dict_error = g_string_append(
326 yyextra->dict_error, "included files nested too deeply\n");
330 yyextra->include_stack[yyextra->include_stack_ptr++] = YY_CURRENT_BUFFER;
333 for (e = yyextra->ents; e; e = e->next) {
334 if (strcmp(e->name,yytext) == 0) {
335 yyin = wimaxasncp_dict_open(yyextra->sys_dir,e->file);
336 D(("entity: %s filename: %s yyin: %p\n",e->name,e->file,(void*)yyin));
340 WimaxasncpDict__switch_to_buffer(WimaxasncpDict__create_buffer(yyin, YY_BUF_SIZE, yyscanner), yyscanner);
347 temp_str = ws_strdup_printf(
348 "cannot find entity: '%s'\n", yytext);
349 yyextra->dict_error = g_string_append(yyextra->dict_error, temp_str);
357 if (!yyin) yyterminate();
360 D(("closing: %p %i\n",(void*)yyin,yyextra->include_stack_ptr));
362 if ( --yyextra->include_stack_ptr < 0 ) {
363 D(("DONE READING\n"));
367 WimaxasncpDict__delete_buffer(YY_CURRENT_BUFFER, yyscanner);
368 WimaxasncpDict__switch_to_buffer(yyextra->include_stack[yyextra->include_stack_ptr], yyscanner);
375 *yyextra->attr_str = wmem_strdup(wmem_epan_scope(), yytext);
377 yyextra->attr_str = NULL;
381 <GET_UINT_ATTR>{number} {
382 *yyextra->attr_uint = (unsigned)strtoul(yytext,NULL,0);
384 yyextra->attr_uint = NULL;
388 <GET_UINT16_ATTR>{number} {
389 *yyextra->attr_uint16 = (int16_t) strtol(yytext,NULL,0);
391 yyextra->attr_uint16 = NULL;
395 <GET_UINT_ATTR>"WIMAXASNCP_BIT32"[ \t]*"(" { BEGIN BIT32; }
398 *yyextra->attr_uint = wimaxasncp_bits(32, yytext);
399 D(("WIMAXASNCP_BIT32(%s)\n",yytext););
400 yyextra->attr_uint = NULL;
403 <GET_UINT_ATTR>"WIMAXASNCP_BIT16"[ \t]*"(" { BEGIN BIT16; }
406 *yyextra->attr_uint = wimaxasncp_bits(16, yytext);
407 D(("WIMAXASNCP_BIT16(%s)\n",yytext););
408 yyextra->attr_uint = NULL;
411 <GET_UINT_ATTR>"WIMAXASNCP_BIT8"[ \t]*"(" { BEGIN BIT8; }
414 *yyextra->attr_uint = wimaxasncp_bits(8, yytext);
415 D(("WIMAXASNCP_BIT8(%s)\n",yytext););
416 yyextra->attr_uint = NULL;
419 <BIT32,BIT16,BIT8>[ \t]*")" { BEGIN END_ATTR; }
421 <GET_DECODER_ATTR>{ndquot} {
422 *yyextra->attr_uint = wimaxasncp_decode_type(yytext);
424 yyextra->attr_uint = NULL;
428 <END_ATTR>{dquot} { yy_pop_state(yyscanner); }
435 <IGNORE_ATTR>{ignored_quoted} {
436 D(("=>%s<=\n",yytext));
437 yy_pop_state(yyscanner);
440 <OUTSIDE>{dictionary_start} {
441 D(("dictionary_start\n"));
446 <IN_DICT>{tlv_start} {
449 yyextra->tlv = wmem_new0(wmem_epan_scope(), wimaxasncp_dict_tlv_t);
451 if (! yyextra->dict->tlvs )
452 yyextra->last_tlv = yyextra->dict->tlvs = yyextra->tlv;
454 yyextra->last_tlv = yyextra->last_tlv->next = yyextra->tlv;
459 <TLV_ATTRS>{name_attr} { ATTR_STR(yyextra->tlv->name); }
460 <TLV_ATTRS>{description_attr} { ATTR_STR(yyextra->tlv->description); }
461 <TLV_ATTRS>{type_attr} { ATTR_UINT16(yyextra->tlv->type); }
462 <TLV_ATTRS>{decoder_attr} { ATTR_DECODER(yyextra->tlv->decoder); }
463 <TLV_ATTRS>{since_attr} { ATTR_UINT(yyextra->tlv->since); }
464 <TLV_ATTRS>{stop} { BEGIN IN_TLV; }
465 <TLV_ATTRS>{stop_end} { BEGIN IN_DICT; }
468 <IN_TLV>{enum_start} {
471 yyextra->enumitem = wmem_new(wmem_epan_scope(), wimaxasncp_dict_enum_t);
472 yyextra->enumitem->name = NULL;
473 yyextra->enumitem->code = 0;
474 yyextra->enumitem->next = NULL;
476 if (!yyextra->tlv->enums)
477 yyextra->last_enumitem = yyextra->tlv->enums = yyextra->enumitem;
479 yyextra->last_enumitem = yyextra->last_enumitem->next = yyextra->enumitem;
485 <ENUM_ATTRS>{name_attr} { ATTR_STR(yyextra->enumitem->name); }
486 <ENUM_ATTRS>{code_attr} { ATTR_UINT(yyextra->enumitem->code); }
488 <ENUM_ATTRS>{stop} { BEGIN IN_TLV; }
489 <ENUM_ATTRS>{stop_end} { BEGIN IN_TLV; }
491 <IN_TLV>{tlv_end} { D(("tlv_end")); BEGIN IN_DICT; }
493 <IN_DICT>{dictionary_end} {
497 <TLV_ATTRS,ENUM_ATTRS>{ignored_attr} WIMAXASNCP_IGNORE();
504 * Turn diagnostics back on, so we check the code that we've written.
508 static int debugging = 0;
510 static void wimaxasncp_dict_debug(const char *fmt, ...) {
514 if (debugging) vfprintf(stderr, fmt, ap);
520 static unsigned wimaxasncp_bits(unsigned bits, char *n)
522 return 1u << ((bits - 1) - (strtoul(n, NULL, 10)));
525 static const value_string wimaxasncp_decode_type_vals[] =
527 { WIMAXASNCP_TLV_TBD, "WIMAXASNCP_TLV_TBD"},
528 { WIMAXASNCP_TLV_COMPOUND, "WIMAXASNCP_TLV_COMPOUND"},
529 { WIMAXASNCP_TLV_BYTES, "WIMAXASNCP_TLV_BYTES"},
530 { WIMAXASNCP_TLV_ENUM8, "WIMAXASNCP_TLV_ENUM8"},
531 { WIMAXASNCP_TLV_ENUM16, "WIMAXASNCP_TLV_ENUM16"},
532 { WIMAXASNCP_TLV_ENUM32, "WIMAXASNCP_TLV_ENUM32"},
533 { WIMAXASNCP_TLV_ETHER, "WIMAXASNCP_TLV_ETHER"},
534 { WIMAXASNCP_TLV_ASCII_STRING, "WIMAXASNCP_TLV_ASCII_STRING"},
535 { WIMAXASNCP_TLV_FLAG0, "WIMAXASNCP_TLV_FLAG0"},
536 { WIMAXASNCP_TLV_BITFLAGS8, "WIMAXASNCP_TLV_BITFLAGS8"},
537 { WIMAXASNCP_TLV_BITFLAGS16, "WIMAXASNCP_TLV_BITFLAGS16"},
538 { WIMAXASNCP_TLV_BITFLAGS32, "WIMAXASNCP_TLV_BITFLAGS32"},
539 { WIMAXASNCP_TLV_ID, "WIMAXASNCP_TLV_ID"},
540 { WIMAXASNCP_TLV_HEX8, "WIMAXASNCP_TLV_HEX8"},
541 { WIMAXASNCP_TLV_HEX16, "WIMAXASNCP_TLV_HEX16"},
542 { WIMAXASNCP_TLV_HEX32, "WIMAXASNCP_TLV_HEX32"},
543 { WIMAXASNCP_TLV_DEC8, "WIMAXASNCP_TLV_DEC8"},
544 { WIMAXASNCP_TLV_DEC16, "WIMAXASNCP_TLV_DEC16"},
545 { WIMAXASNCP_TLV_DEC32, "WIMAXASNCP_TLV_DEC32"},
546 { WIMAXASNCP_TLV_IP_ADDRESS, "WIMAXASNCP_TLV_IP_ADDRESS"},
547 { WIMAXASNCP_TLV_IPV4_ADDRESS, "WIMAXASNCP_TLV_IPV4_ADDRESS"},
548 { WIMAXASNCP_TLV_PROTOCOL_LIST, "WIMAXASNCP_TLV_PROTOCOL_LIST"},
549 { WIMAXASNCP_TLV_PORT_RANGE_LIST, "WIMAXASNCP_TLV_PORT_RANGE_LIST"},
550 { WIMAXASNCP_TLV_IP_ADDRESS_MASK_LIST,"WIMAXASNCP_TLV_IP_ADDRESS_MASK_LIST"},
551 { WIMAXASNCP_TLV_EAP, "WIMAXASNCP_TLV_EAP"},
552 { WIMAXASNCP_TLV_VENDOR_SPECIFIC, "WIMAXASNCP_TLV_VENDOR_SPECIFIC"},
556 static int wimaxasncp_decode_type(const char *name)
559 for (i = 0; i < array_length(wimaxasncp_decode_type_vals) - 1; ++i)
561 if (strcmp(name, wimaxasncp_decode_type_vals[i].strptr) == 0)
563 return wimaxasncp_decode_type_vals[i].value;
567 /* not found, emit some sort of error here? */
569 return WIMAXASNCP_TLV_TBD;
572 extern void wimaxasncp_dict_unused(yyscan_t yyscanner);
573 void wimaxasncp_dict_unused(yyscan_t yyscanner) {
574 yy_top_state(yyscanner);
577 static void append_to_buffer(const char *txt, int len, WimaxasncpDict_scanner_state_t *state) {
579 if (state->strbuf == NULL) {
580 state->read_ptr = state->write_ptr = state->strbuf = (char *)g_malloc(state->size_strbuf);
583 if (state->len_strbuf + len >= state->size_strbuf) {
584 state->read_ptr = state->strbuf = (char *)g_realloc(state->strbuf,state->size_strbuf *= 2);
587 state->write_ptr = state->strbuf + state->len_strbuf;
588 memcpy(state->write_ptr, txt, len + 1);
589 state->len_strbuf += len;
592 static size_t file_input(char *buf, size_t max, yyscan_t scanner) {
593 FILE *in = yyget_in(scanner);
596 read_cnt = fread(buf,1,max,in);
598 if ( read_cnt == max ) {
600 } else if (read_cnt > 0) {
608 static size_t string_input(char *buf, size_t max, yyscan_t scanner) {
609 WimaxasncpDict_scanner_state_t *statep = yyget_extra(scanner);
611 if (statep->read_ptr >= statep->write_ptr ) {
613 } else if ( statep->read_ptr + max > statep->write_ptr ) {
614 max = statep->write_ptr - statep->read_ptr;
617 memcpy(buf,statep->read_ptr,max);
618 statep->read_ptr += max;
623 static FILE *wimaxasncp_dict_open(
624 const char *system_directory,
625 const char *filename)
629 if (system_directory)
631 fname = ws_strdup_printf("%s%s%s",
632 system_directory, G_DIR_SEPARATOR_S,filename);
636 fname = g_strdup(filename);
639 fh = ws_fopen(fname,"r");
641 D(("fname: %s fh: %p\n",fname,(void*)fh));
649 wimaxasncp_dict_t *wimaxasncp_dict_scan(
650 const char *system_directory, const char *filename, int dbg,
653 WimaxasncpDict_scanner_state_t state;
660 state.dict_error = g_string_new("");
662 state.sys_dir = system_directory;
664 state.dict = g_new(wimaxasncp_dict_t,1);
665 state.dict->tlvs = NULL;
666 state.dict->xmlpis = NULL;
669 state.size_strbuf = 8192;
670 state.len_strbuf = 0;
672 state.write_ptr = NULL;
673 state.read_ptr = NULL;
676 state.enumitem = NULL;
679 state.last_tlv = NULL;
680 state.last_enumitem = NULL;
681 state.last_xmlpi = NULL;
688 * Reads the file, does some work, and stores a modified version
689 * of the file contents in memory.
691 state.current_yyinput = file_input;
692 state.include_stack_ptr = 0;
694 in = wimaxasncp_dict_open(system_directory,filename);
698 * Couldn't open the dictionary.
700 * Treat all failures other then ENOENT as errors?
706 if (WimaxasncpDict_lex_init(&scanner) != 0) {
707 D(("Can't initialize scanner: %s\n", strerror(errno)));
713 WimaxasncpDict_set_in(in, scanner);
715 /* Associate the state with the scanner */
716 WimaxasncpDict_set_extra(&state, scanner);
718 state.start_state = LOADING;
719 WimaxasncpDict_lex(scanner);
721 WimaxasncpDict_lex_destroy(scanner);
723 * XXX - can the lexical analyzer terminate without closing
724 * all open input files?
727 D(("\n---------------\n%s\n------- %d -------\n",
728 state.strbuf, state.len_strbuf));
733 * Reads the modified version of the file contents and does the
736 state.current_yyinput = string_input;
738 if (WimaxasncpDict_lex_init(&scanner) != 0) {
739 D(("Can't initialize scanner: %s\n", strerror(errno)));
742 g_free(state.strbuf);
746 /* Associate the state with the scanner */
747 WimaxasncpDict_set_extra(&state, scanner);
749 state.start_state = OUTSIDE;
750 WimaxasncpDict_lex(scanner);
752 WimaxasncpDict_lex_destroy(scanner);
753 g_free(state.strbuf);
758 entity_t *next = e->next;
765 if (state.dict_error->len > 0)
767 *error = g_string_free(state.dict_error, FALSE);
772 g_string_free(state.dict_error, TRUE);
777 void wimaxasncp_dict_free(wimaxasncp_dict_t *d) {
778 wimaxasncp_dict_tlv_t *t, *tn;
780 #define FREE_NAMEANDOBJ(n) do { g_free(n->name); g_free(n); } while(0)
782 for (t = d->tlvs; t; t = tn) {
783 wimaxasncp_dict_enum_t *e, *en;
786 for (e = t->enums; e; e = en) {
791 g_free(t->description);
798 void wimaxasncp_dict_print(FILE *fh, wimaxasncp_dict_t *d) {
799 wimaxasncp_dict_tlv_t *tlvp;
803 for (tlvp = d->tlvs; tlvp; tlvp = tlvp->next) {
804 wimaxasncp_dict_enum_t *e;
805 fprintf(fh,"TLV: %s[%u] %s[%d] %s (since %u)\n",
806 tlvp->name ? tlvp->name : "-",
808 val_to_str(tlvp->decoder,
809 wimaxasncp_decode_type_vals,
812 tlvp->description ? tlvp->description : "",
815 for (e = tlvp->enums; e; e = e->next) {
816 fprintf(fh,"\tEnum: %s[%u]\n",
817 e->name ? e->name : "-",
823 #ifdef TEST_WIMAXASNCP_DICT_STANDALONE
824 int main(int argc, char **argv) {
825 wimaxasncp_dict_t *d;
837 fprintf(stderr,"%s: usage [dictionary_dir] dictionary_filename\n",argv[0]);
841 d = wimaxasncp_dict_scan(dname,fname,1,&dict_error);
845 printf("wimaxasncp - %s", dict_error);
849 wimaxasncp_dict_print(stdout, d);