MSWSP: add ids for another unknown Property Set
[wireshark-wip.git] / plugins / wimaxasncp / wimaxasncp_dict.l
bloba643275453505afc34e992b9d6c2cf72349da718
1 /*
2  * We don't use input, so don't generate code for it.
3  */
4 %option noinput
6 /*
7  * We don't use unput, so don't generate code for it.
8  */
9 %option nounput
12  * We don't read from the terminal.
13  */
14 %option never-interactive
17  * The language we're scanning is case-insensitive.
18  */
19 %option caseless
22  * We use start condition stacks.
23  */
24 %option stack
27  * Prefix scanner routines with "WimaxasncpDict" rather than "yy", so this
28  * scanner can coexist with other scanners.
29  */
30 %option prefix="WimaxasncpDict"
32 %option outfile="wimaxasncp_dict.c"
35         /*
36          ** wimaxasncp_dict.h
37          ** WIMAXASNCP Dictionary Import Routines
38          **
39          ** $Id$
40          **
41          ** (c) 2007, Luis E. Garcia Ontanon <luis@ontanon.org>
42          ** (c) 2007, Stephen Croll <stephen.d.croll@gmail.com>
43          **
44          ** This library is free software; you can redistribute it and/or
45          ** modify it under the terms of the GNU Library General Public
46          ** License as published by the Free Software Foundation; either
47          ** version 2 of the License, or (at your option) any later version.
48          **
49          ** This library is distributed in the hope that it will be useful,
50          ** but WITHOUT ANY WARRANTY; without even the implied warranty of
51          ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
52          ** Library General Public License for more details.
53          **
54          ** You should have received a copy of the GNU Library General Public
55          ** License along with this library; if not, write to the Free Software
56          ** Foundation, Inc., 51 Franklin Street, Fifth Floor,
57          ** Boston, MA  02110-1301, USA.
58          */
60 #include "config.h"
62 #include <glib.h>
63 #include <stdio.h>
64 #include <string.h>
65 #include <errno.h>
66 #include <stdlib.h>
67 #include <stdarg.h>
68 #include <epan/emem.h>
69 #include <epan/value_string.h>
70 #include <epan/packet.h>        /* array_length */
71 #include <wsutil/file_util.h>
73 #include "wimaxasncp_dict.h"
74 #include "wimaxasncp_dict_lex.h"
76 typedef struct entity_t {
77         gchar *name;
78         gchar *file;
79         struct entity_t *next;
80 } entity_t;
82 #define ATTR_UINT(cont) do { D(("attr_uint " #cont "\t" )); attr_uint = &(cont); yy_push_state(GET_UINT_ATTR); } while(0)
83 #define ATTR_UINT16(cont) do { D(("attr_uint16 " #cont "\t" )); attr_uint16 = &(cont); yy_push_state(GET_UINT16_ATTR); } while(0)
84 #define ATTR_STR(cont) do { D(("attr_str " #cont "\t" )); attr_str = &(cont); yy_push_state(GET_ATTR); } while(0)
85 #define ATTR_DECODER(cont) do { D(("attr_decoder " #cont "\t" )); attr_uint = &(cont); yy_push_state(GET_DECODER_ATTR); } while(0)
86 #define WIMAXASNCP_IGNORE() do { D(("ignore: %s\t",yytext)); yy_push_state(IGNORE_ATTR); } while(0)
88 #define D(args) wimaxasncp_dict_debug args
90 #define MAX_INCLUDE_DEPTH 10
91 #define YY_INPUT(buf,result,max_size) { result = current_yyinput(buf,max_size); }
92 #define ECHO
93 #define APPEND(txt,len) append_to_buffer(txt,(int)len)
95 static entity_t ents;
96 static YY_BUFFER_STATE include_stack[MAX_INCLUDE_DEPTH];
97 static int include_stack_ptr = 0;
98 static size_t (*current_yyinput)(gchar*,size_t);
99 static const gchar *sys_dir;
100 static wimaxasncp_dict_t *dict;
101 static wimaxasncp_dict_tlv_t *tlv;
102 static wimaxasncp_dict_enum_t *enumitem;
103 static wimaxasncp_dict_xmlpi_t *xmlpi;
105 static wimaxasncp_dict_tlv_t *last_tlv;
106 static wimaxasncp_dict_enum_t *last_enumitem;
107 static wimaxasncp_dict_xmlpi_t *last_xmlpi;
109 static gchar **attr_str;
110 static guint *attr_uint;
111 static gint16 *attr_uint16;
113 static guint wimaxasncp_bits(guint bits, char *n);
114 static gint wimaxasncp_decode_type(const gchar *name);
115 static void wimaxasncp_dict_debug(const gchar *fmt, ...);
116 static void append_to_buffer(const gchar *txt, int len);
117 static FILE *wimaxasncp_dict_open(const gchar*, const gchar*);
119 static GString *dict_error = NULL;
124 xmlpi_start [[:blank:] \r\n]*<\?[[:blank:] \r\n]*
125 xmlpi_end [[:blank:] \r\n]*\?>[[:blank:] \r\n]*
126 xmlpi_key_attr [[:blank:] \r\n]*key[[:blank:] \r\n]*=[[:blank:] \r\n]*\042
127 xmlpi_value_attr [[:blank:] \r\n]*value[[:blank:] \r\n]*=[[:blank:] \r\n]*\042
129 comment_start [[:blank:] \r\n]*<!--[[:blank:] \r\n]*
130 comment_end [[:blank:] \r\n]*-->[[:blank:] \r\n]*
131 open_tag [[:blank:] \r\n]*<[[:blank:] \r\n]*
132 end_tag [[:blank:] \r\n]*\/>[[:blank:] \r\n]*
133 close_tag [[:blank:] \r\n]*>[[:blank:] \r\n]*
134 open_closetag [[:blank:] \r\n]*<\/[[:blank:] \r\n]*
135 equals [[:blank:] \r\n]*=[[:blank:] \r\n]*
136 whitespace [[:blank:] \r\n]*
137 dquoted \042[^\042]*\042
139 doctype [[:blank:] \r\n]*<!DOCTYPE[^\[]*\[[[:blank:] \r\n]*
140 doctype_end [[:blank:] \r\n]*\][[:blank:] \r\n]*>[[:blank:] \r\n]*
142 start_entity [[:blank:] \r\n]*<\!ENTITY[[:blank:] \r\n]*
143 system [[:blank:] \r\n]*SYSTEM[[:blank:] \r\n]*\042
144 entityname [a-z0-9-]+
145 ndquot [^\042]+
146 end_entity \042[[:blank:] \r\n]*>[[:blank:] \r\n]*
148 entity \&[a-z0-9-]+;
150 any .
155 stop >
156 stop_end \/>
157 dquot \042
158 number [-]?[0-9]*|(0x)?[0-9a-fA-F]*
160 dictionary_start <dictionary>
161 dictionary_end <\/dictionary>
163 tlv_start <tlv
164 tlv_end <\/tlv>
166 type_start <type
167 enum_start <enum
169 ignored_attr [a-z0-9-]+=
170 ignored_quoted \042[^\042]*\042
172 name_attr name=\042
173 type_attr type=\042
174 code_attr code=\042
175 typename_attr type-name=\042
176 description_attr description=\042
177 decoder_attr decoder=\042
178 since_attr since=\042
181 %S LOADING LOADING_COMMENT LOADING_XMLPI ENTITY GET_SYSTEM GET_FILE END_ENTITY
182 %S GET_ATTR GET_UINT_ATTR GET_UINT16_ATTR
183 %S BIT32 BIT16 BIT8 GET_DECODER_ATTR END_ATTR
184 %S OUTSIDE IN_DICT IN_APPL IN_TLV IGNORE_ATTR
185 %S ENUM_ATTRS TLV_ATTRS
186 %S XMLPI_ATTRS XMLPI_GETKEY XMLPI_GETVAL XMLPI_ENDATTR
188 <LOADING>{doctype} ;
189 <LOADING>{doctype_end} ;
191 <LOADING>{comment_start} BEGIN LOADING_COMMENT;
192 <LOADING_COMMENT>. ;
193 <LOADING_COMMENT>{comment_end} BEGIN LOADING;
195 <LOADING>{xmlpi_start} BEGIN LOADING_XMLPI;
196 <LOADING_XMLPI>{whitespace} ;
197 <LOADING_XMLPI>{entityname} {
198         xmlpi = g_new(wimaxasncp_dict_xmlpi_t,1);
199         xmlpi->name = g_strdup(yytext);
200         xmlpi->key = NULL;
201         xmlpi->value = NULL;
202         xmlpi->next = NULL;
204         if (!dict->xmlpis) last_xmlpi = dict->xmlpis = xmlpi;
205         else last_xmlpi = last_xmlpi->next = xmlpi;
207         BEGIN XMLPI_ATTRS;
210 <XMLPI_ATTRS>{xmlpi_key_attr} BEGIN XMLPI_GETKEY;
211 <XMLPI_GETKEY>{ndquot} { xmlpi->key = g_strdup(yytext); BEGIN XMLPI_ATTRS; }
213 <XMLPI_ATTRS>{xmlpi_value_attr} BEGIN XMLPI_GETVAL;
214 <XMLPI_GETVAL>{ndquot} { xmlpi->value = g_strdup(yytext); BEGIN XMLPI_ATTRS; }
216 <XMLPI_ATTRS>.
217 <XMLPI_ATTRS>{xmlpi_end} BEGIN LOADING;
220 <LOADING>{start_entity} BEGIN ENTITY;
221 <ENTITY>{entityname} {
222         entity_t *e = g_new(entity_t,1);
223         D(("ENTITY: %s\n",yytext));
224         e->name = g_strdup(yytext);
225         e->next = ents.next;
226         ents.next = e;
227         BEGIN GET_SYSTEM;
229 <GET_SYSTEM>{system} BEGIN GET_FILE;
230 <GET_FILE>{ndquot} {
231         D(("GET_FILE: %s\n",yytext));
232         ents.next->file = g_strdup(yytext);
233         BEGIN END_ENTITY;
235 <END_ENTITY>{end_entity} BEGIN LOADING;
237 <LOADING>{open_tag} APPEND("<",1);
239 <LOADING>{close_tag} APPEND(">",1);
241 <LOADING>{end_tag} APPEND("/>",2);
243 <LOADING>{open_closetag} APPEND("</",2);
245 <LOADING>{whitespace} APPEND(" ",1);
247 <LOADING>{dquoted} APPEND(yytext,yyleng);
249 <LOADING>{equals} APPEND("=",1);
251 <LOADING>{any} APPEND(yytext,yyleng);
253 <LOADING,IN_DICT>{entity} {
254         gchar *p = ++yytext, *temp_str;
255         entity_t* e;
257         while(*p != ';') p++;
259         *p = '\0';
261         D(("looking for entity: %s\n",yytext));
263         if ( include_stack_ptr >= MAX_INCLUDE_DEPTH ) {
264                 dict_error = g_string_append(
265                         dict_error, "included files nested too deeply\n");
266                 yyterminate();
267         }
269         include_stack[include_stack_ptr++] = YY_CURRENT_BUFFER;
272         for (e = ents.next; e; e = e->next) {
273                 if (strcmp(e->name,yytext) == 0) {
274                         yyin = wimaxasncp_dict_open(sys_dir,e->file);
275                         D(("entity: %s filename: %s yyin: %p\n",e->name,e->file,yyin));
276                         if (!yyin) {
277                                 yyterminate();
278                         } else {
279                                 yy_switch_to_buffer(yy_create_buffer( yyin, YY_BUF_SIZE ) );
280                         }
281                         break;
282                 }
283         }
285         if (!e) {
286                 temp_str = g_strdup_printf(
287                         "cannot find entity: '%s'\n", yytext);
288                 dict_error = g_string_append(dict_error, temp_str);
289                 g_free(temp_str);
290                 yyterminate();
291         }
295 <<EOF>> {
296         if (!yyin) yyterminate();
298         fclose(yyin);
299         D(("closing: %p %i\n",yyin,include_stack_ptr));
301         if ( --include_stack_ptr < 0 ) {
302                 D(("DONE READING\n"));
303                 yyin = NULL;
304                 yyterminate();
305         } else {
306                 yy_delete_buffer( YY_CURRENT_BUFFER );
307                 yy_switch_to_buffer(include_stack[include_stack_ptr]);
308                 BEGIN LOADING;
309         }
313 <GET_ATTR>{ndquot} {
314         *attr_str = g_strdup(yytext);
315         D(("%s\n",yytext));
316         attr_str = NULL;
317         BEGIN END_ATTR;
320 <GET_UINT_ATTR>{number} {
321         *attr_uint = (guint)strtoul(yytext,NULL,0);
322         D(("%s\n",yytext););
323         attr_uint = NULL;
324         BEGIN END_ATTR;
327 <GET_UINT16_ATTR>{number} {
328         *attr_uint16 = (gint16) strtol(yytext,NULL,0);
329         D(("%s\n",yytext););
330         attr_uint16 = NULL;
331         BEGIN END_ATTR;
334 <GET_UINT_ATTR>"WIMAXASNCP_BIT32"[ \t]*"("    { BEGIN BIT32; }
336 <BIT32>[0-9]+ {
337         *attr_uint = wimaxasncp_bits(32, yytext);
338         D(("WIMAXASNCP_BIT32(%s)\n",yytext););
339         attr_uint = NULL;
342 <GET_UINT_ATTR>"WIMAXASNCP_BIT16"[ \t]*"("    { BEGIN BIT16; }
344 <BIT16>[0-9]+ {
345         *attr_uint = wimaxasncp_bits(16, yytext);
346         D(("WIMAXASNCP_BIT16(%s)\n",yytext););
347         attr_uint = NULL;
350 <GET_UINT_ATTR>"WIMAXASNCP_BIT8"[ \t]*"("     { BEGIN BIT8; }
352 <BIT8>[0-9]+ {
353         *attr_uint = wimaxasncp_bits(8, yytext);
354         D(("WIMAXASNCP_BIT8(%s)\n",yytext););
355         attr_uint = NULL;
358 <BIT32,BIT16,BIT8>[ \t]*")" { BEGIN END_ATTR; }
360 <GET_DECODER_ATTR>{ndquot} {
361         *attr_uint = wimaxasncp_decode_type(yytext);
362         D(("%s\n",yytext));
363         attr_uint = NULL;
364         BEGIN END_ATTR;
367 <END_ATTR>{dquot} {     yy_pop_state(); }
369 <IGNORE_ATTR>. {
370         /* XXX: should go?*/
371         D(("{%s}",yytext));
374 <IGNORE_ATTR>{ignored_quoted} {
375         D(("=>%s<=\n",yytext));
376         yy_pop_state();
379 <OUTSIDE>{dictionary_start} {
380         D(("dictionary_start\n"));
382         BEGIN IN_DICT;
385 <IN_DICT>{tlv_start}    {
386         D(("tlv_start\n"));
388         tlv = g_new(wimaxasncp_dict_tlv_t,1);
389         tlv->type = 0;
390         tlv->name = NULL;
391         tlv->description = NULL;
392         tlv->decoder = 0;
393         tlv->since = 0;
394         tlv->hf_root = -1;
395         tlv->hf_value = -1;
396         tlv->hf_ipv4 = -1;
397         tlv->hf_ipv6 = -1;
398         tlv->hf_bsid = -1;
399         tlv->hf_protocol = -1;
400         tlv->hf_port_low = -1;
401         tlv->hf_port_high = -1;
402         tlv->hf_ipv4_mask = -1;
403         tlv->hf_ipv6_mask = -1;
404         tlv->hf_vendor_id = -1;
405         tlv->hf_vendor_rest_of_info = -1;
406         tlv->enum_vs = NULL;
407         tlv->enums = NULL;
408         tlv->next = NULL;
410         if (! dict->tlvs ) last_tlv = dict->tlvs = tlv;
411         else last_tlv = last_tlv->next = tlv;
413         BEGIN TLV_ATTRS;
416 <TLV_ATTRS>{name_attr}                  { ATTR_STR(tlv->name); }
417 <TLV_ATTRS>{description_attr}           { ATTR_STR(tlv->description); }
418 <TLV_ATTRS>{type_attr}                  { ATTR_UINT16(tlv->type); }
419 <TLV_ATTRS>{decoder_attr}               { ATTR_DECODER(tlv->decoder); }
420 <TLV_ATTRS>{since_attr}                 { ATTR_UINT(tlv->since); }
421 <TLV_ATTRS>{stop}                       { BEGIN IN_TLV;  }
422 <TLV_ATTRS>{stop_end}                   { BEGIN IN_DICT; }
425 <IN_TLV>{enum_start} {
426         D(("enum_start\n"));
428         enumitem = g_new(wimaxasncp_dict_enum_t,1);
429         enumitem->name = NULL;
430         enumitem->code = 0;
431         enumitem->next = NULL;
433         if (!tlv->enums) last_enumitem = tlv->enums = enumitem;
434         else last_enumitem = last_enumitem->next = enumitem;
436         BEGIN ENUM_ATTRS;
440 <ENUM_ATTRS>{name_attr}                 { ATTR_STR(enumitem->name); }
441 <ENUM_ATTRS>{code_attr}                 { ATTR_UINT(enumitem->code); }
443 <ENUM_ATTRS>{stop}           { BEGIN IN_TLV; }
444 <ENUM_ATTRS>{stop_end}       { BEGIN IN_TLV; }
446 <IN_TLV>{tlv_end} { D(("tlv_end")); BEGIN IN_DICT; }
448 <IN_DICT>{dictionary_end} {
449         yyterminate();
452 <TLV_ATTRS,ENUM_ATTRS>{ignored_attr} WIMAXASNCP_IGNORE();
454 <OUTSIDE>. ;
463 static int debugging  = 0;
465 static void wimaxasncp_dict_debug(const gchar *fmt, ...) {
466         va_list ap;
468         va_start(ap, fmt);
469         if (debugging) vfprintf(stderr, fmt, ap);
470         va_end(ap);
472         fflush(stderr);
475 static guint wimaxasncp_bits(guint bits, char *n)
477         return 1 << ((bits - 1) - (strtoul(n, NULL, 10)));
480 static const value_string wimaxasncp_decode_type_vals[] =
482   { WIMAXASNCP_TLV_TBD,                 "WIMAXASNCP_TLV_TBD"},
483   { WIMAXASNCP_TLV_COMPOUND,            "WIMAXASNCP_TLV_COMPOUND"},
484   { WIMAXASNCP_TLV_BYTES,               "WIMAXASNCP_TLV_BYTES"},
485   { WIMAXASNCP_TLV_ENUM8,               "WIMAXASNCP_TLV_ENUM8"},
486   { WIMAXASNCP_TLV_ENUM16,              "WIMAXASNCP_TLV_ENUM16"},
487   { WIMAXASNCP_TLV_ENUM32,              "WIMAXASNCP_TLV_ENUM32"},
488   { WIMAXASNCP_TLV_ETHER,               "WIMAXASNCP_TLV_ETHER"},
489   { WIMAXASNCP_TLV_ASCII_STRING,        "WIMAXASNCP_TLV_ASCII_STRING"},
490   { WIMAXASNCP_TLV_FLAG0,               "WIMAXASNCP_TLV_FLAG0"},
491   { WIMAXASNCP_TLV_BITFLAGS8,           "WIMAXASNCP_TLV_BITFLAGS8"},
492   { WIMAXASNCP_TLV_BITFLAGS16,          "WIMAXASNCP_TLV_BITFLAGS16"},
493   { WIMAXASNCP_TLV_BITFLAGS32,          "WIMAXASNCP_TLV_BITFLAGS32"},
494   { WIMAXASNCP_TLV_ID,                  "WIMAXASNCP_TLV_ID"},
495   { WIMAXASNCP_TLV_HEX8,                "WIMAXASNCP_TLV_HEX8"},
496   { WIMAXASNCP_TLV_HEX16,               "WIMAXASNCP_TLV_HEX16"},
497   { WIMAXASNCP_TLV_HEX32,               "WIMAXASNCP_TLV_HEX32"},
498   { WIMAXASNCP_TLV_DEC8,                "WIMAXASNCP_TLV_DEC8"},
499   { WIMAXASNCP_TLV_DEC16,               "WIMAXASNCP_TLV_DEC16"},
500   { WIMAXASNCP_TLV_DEC32,               "WIMAXASNCP_TLV_DEC32"},
501   { WIMAXASNCP_TLV_IP_ADDRESS,          "WIMAXASNCP_TLV_IP_ADDRESS"},
502   { WIMAXASNCP_TLV_IPV4_ADDRESS,        "WIMAXASNCP_TLV_IPV4_ADDRESS"},
503   { WIMAXASNCP_TLV_PROTOCOL_LIST,       "WIMAXASNCP_TLV_PROTOCOL_LIST"},
504   { WIMAXASNCP_TLV_PORT_RANGE_LIST,     "WIMAXASNCP_TLV_PORT_RANGE_LIST"},
505   { WIMAXASNCP_TLV_IP_ADDRESS_MASK_LIST,"WIMAXASNCP_TLV_IP_ADDRESS_MASK_LIST"},
506   { WIMAXASNCP_TLV_EAP,                 "WIMAXASNCP_TLV_EAP"},
507   { WIMAXASNCP_TLV_VENDOR_SPECIFIC,     "WIMAXASNCP_TLV_VENDOR_SPECIFIC"},
508   { 0, NULL}
511 static gint wimaxasncp_decode_type(const gchar *name)
513         gsize i;
514         for (i = 0; i < array_length(wimaxasncp_decode_type_vals) - 1; ++i)
515         {
516                 if (strcmp(name, wimaxasncp_decode_type_vals[i].strptr) == 0)
517                 {
518                         return wimaxasncp_decode_type_vals[i].value;
519                 }
520         }
522         /* not found, emit some sort of error here? */
524         return WIMAXASNCP_TLV_TBD;
527 static gchar *strbuf = NULL;
528 static gchar *write_ptr = NULL;
529 static gchar *read_ptr = NULL;
531 static guint size_strbuf = 8192;
532 static guint len_strbuf = 0;
534 extern void wimaxasncp_dict_unused(void);
535 void wimaxasncp_dict_unused(void) {
536         yy_top_state();
539 static void append_to_buffer(const gchar *txt, int len) {
541         if (strbuf == NULL) {
542                 read_ptr = write_ptr = strbuf = (gchar *)g_malloc(size_strbuf);
543         }
545         if ( (len_strbuf + len + 1) >= size_strbuf ) {
546                 read_ptr = strbuf = (gchar *)g_realloc(strbuf,size_strbuf *= 2);
547         }
549         write_ptr = strbuf + len_strbuf;
550         strncpy(write_ptr,txt,len);
551         len_strbuf += len;
552         strbuf[len_strbuf] = '\0';
555 static size_t file_input(gchar *buf, size_t max) {
556         size_t read_cnt;
558         read_cnt = fread(buf,1,max,yyin);
560         if ( read_cnt == max ) {
561                 return max;
562         } else if (read_cnt > 0) {
563                 return read_cnt;
564         } else {
565                 return YY_NULL;
566         }
570 static size_t string_input(gchar *buf, size_t max) {
571         if (read_ptr >= write_ptr ) {
572                 return YY_NULL;
573         } else if ( read_ptr + max > write_ptr ) {
574                 max = write_ptr - read_ptr;
575         }
577         memcpy(buf,read_ptr,max);
578         read_ptr += max;
580         return max;
583 static FILE *wimaxasncp_dict_open(
584         const gchar *system_directory,
585         const gchar *filename)
587         FILE *fh;
588         gchar *fname;
589         if (system_directory)
590         {
591                 fname = g_strdup_printf("%s%s%s",
592                            system_directory, G_DIR_SEPARATOR_S,filename);
593         }
594         else
595         {
596                 fname = g_strdup(filename);
597         }
599         fh = ws_fopen(fname,"r");
601         D(("fname: %s fh: %p\n",fname,fh));
603         g_free(fname);
606         return fh;
609 wimaxasncp_dict_t *wimaxasncp_dict_scan(
610         const gchar *system_directory, const gchar *filename, int dbg,
611         gchar **error) {
613         entity_t *e;
615         dict_error = g_string_new("");
617         debugging = dbg;
619         sys_dir = system_directory;
621         write_ptr = NULL;
622         read_ptr = NULL;
624         if (dict)
625         {
626                 wimaxasncp_dict_free(dict);
627         }
629         dict = g_new(wimaxasncp_dict_t,1);
630         dict->tlvs = NULL;
631         dict->xmlpis = NULL;
633         tlv = NULL;
634         enumitem = NULL;
635         xmlpi = NULL;
637         last_tlv = NULL;
638         last_enumitem = NULL;
639         last_xmlpi = NULL;
641         ents.next = NULL;
643         yyin = wimaxasncp_dict_open(sys_dir,filename);
645         if (yyin)
646         {
647                 current_yyinput = file_input;
648                 BEGIN LOADING;
649                 yylex();
651                 D(("\n---------------\n%s\n------- %d -------\n",
652                    strbuf, len_strbuf));
654                 current_yyinput = string_input;
656                 BEGIN OUTSIDE;
657                 yylex();
658         }
660         e = ents.next;
661         while (e)
662         {
663                 entity_t *next = e->next;
664                 g_free(e->name);
665                 g_free(e->file);
666                 g_free(e);
667                 e = next;
668         }
670         g_free(strbuf);
671         strbuf = NULL;
672         size_strbuf = 8192;
674         if (dict_error->len > 0)
675         {
676                 *error = dict_error->str;
677                 g_string_free(dict_error, FALSE);
678         }
679         else
680         {
681                 *error = NULL;
682                 g_string_free(dict_error, TRUE);
683         }
685         return dict;
688 void wimaxasncp_dict_free(wimaxasncp_dict_t *d) {
689         wimaxasncp_dict_tlv_t *t, *tn;
691 #define FREE_NAMEANDOBJ(n) do { if(n->name) g_free(n->name); g_free(n); } while(0)
693         for (t = d->tlvs; t; t = tn) {
694                 wimaxasncp_dict_enum_t *e, *en;
695                 tn = t->next;
697                 for (e = t->enums; e; e = en) {
698                         en = e->next;
699                         FREE_NAMEANDOBJ(e);
700                 }
702                 if (!t->description)  g_free(t->description);
703                 FREE_NAMEANDOBJ(t);
704         }
706         g_free(d);
709 void wimaxasncp_dict_print(FILE *fh, wimaxasncp_dict_t *d) {
710         wimaxasncp_dict_tlv_t *tlvp;
712         fprintf(fh,"\n");
714         for (tlvp = d->tlvs; tlvp; tlvp = tlvp->next) {
715                 wimaxasncp_dict_enum_t *e;
716                 fprintf(fh,"TLV: %s[%u] %s[%d] %s (since %u)\n",
717                                 tlvp->name ? tlvp->name : "-",
718                                 tlvp->type,
719                                 val_to_str(tlvp->decoder,
720                                            wimaxasncp_decode_type_vals,
721                                            "Unknown"),
722                                 tlvp->decoder,
723                                 tlvp->description ? tlvp->description : "",
724                                 tlvp->since);
726                 for (e = tlvp->enums; e; e = e->next) {
727                         fprintf(fh,"\tEnum: %s[%u]\n",
728                                         e->name ? e->name : "-",
729                                         e->code);
730                 }
731         }
735  * We want to stop processing when we get to the end of the input.
736  * (%option noyywrap is not used because if used then
737  * some flex versions (eg: 2.5.35) generate code which causes
738  * warnings by the Windows VC compiler).
739  */
741 int yywrap(void) {
742     return 1;
745 #ifdef TEST_WIMAXASNCP_DICT_STANDALONE
746 int main(int argc, char **argv) {
747         wimaxasncp_dict_t *d;
748         gchar *dname = NULL;
749         gchar *fname;
750         int i = 1;
752         switch (argc) {
753                 case 3:
754                         dname = argv[i++];
755                 case 2:
756                         fname = argv[i];
757                         break;
758                 default:
759                         fprintf(stderr,"%s: usage [dictionary_dir] dictionary_filename\n",argv[0]);
760                         return 1;
761         }
763         d = wimaxasncp_dict_scan(dname,fname,1,&dict_error);
765         if (dict_error)
766         {
767                 printf("wimaxasncp - %s", dict_error);
768                 g_free(dict_error);
769         }
771         wimaxasncp_dict_print(stdout, d);
773         return 0;
775 #endif