HACK: pinfo->private_data points to smb_info again
[wireshark-wip.git] / epan / diam_dict.l
blobdb6a724294e4ae47a83f990035d47b14222b6dfc
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 "DiamDict" rather than "yy", so this scanner
28  * can coexist with other scanners.
29  */
30 %option prefix="DiamDict"
32 %option outfile="diam_dict.c"
35         /*
36          ** diam_dict.h
37          ** Diameter Dictionary Import Routines
38          **
39          ** $Id$
40          **
41          ** (c) 2007, Luis E. Garcia Ontanon <luis@ontanon.org>
42          **
43          ** This library is free software; you can redistribute it and/or
44          ** modify it under the terms of the GNU Library General Public
45          ** License as published by the Free Software Foundation; either
46          ** version 2 of the License, or (at your option) any later version.
47          **
48          ** This library is distributed in the hope that it will be useful,
49          ** but WITHOUT ANY WARRANTY; without even the implied warranty of
50          ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
51          ** Library General Public License for more details.
52          **
53          ** You should have received a copy of the GNU Library General Public
54          ** License along with this library; if not, write to the Free Software
55          ** Foundation, Inc., 51 Franklin Street, Fifth Floor,
56          ** Boston, MA  02110-1301, USA.
57          */
59 #include "config.h"
61 #include <glib.h>
62 #include <stdio.h>
63 #include <string.h>
64 #include <errno.h>
65 #include <stdlib.h>
66 #include <stdarg.h>
67 #include "diam_dict.h"
68 #include "diam_dict_lex.h"
69 #include <epan/to_str.h>
70 #include <wsutil/file_util.h>
72 typedef struct entity_t {
73         char* name;
74         char* file;
75         struct entity_t* next;
76 } entity_t;
78 #define ATTR_UINT(cont) do { D(("attr_uint " #cont "\t" )); attr_uint = &(cont); yy_push_state(GET_UINT_ATTR); } while(0)
79 #define ATTR_STR(cont) do { D(("attr_str " #cont "\t" )); attr_str = &(cont); yy_push_state(GET_ATTR); } while(0)
80 #define IGNORE() do { D(("ignore: %s\t",yytext)); yy_push_state(IGNORE_ATTR); } while(0)
82 #define D(args) ddict_debug args
84 #define MAX_INCLUDE_DEPTH 10
85 #define YY_INPUT(buf,result,max_size) { result = current_yyinput(buf,max_size); }
86 #define ECHO
87 #define APPEND(txt,len) append_to_buffer(txt,len)
89 static entity_t ents;
90 static YY_BUFFER_STATE include_stack[MAX_INCLUDE_DEPTH];
91 static int include_stack_ptr = 0;
92 static size_t (*current_yyinput)(char*,size_t);
93 static const char* sys_dir;
94 static ddict_t* dict;
95 static ddict_application_t* appl;
96 static ddict_avp_t* avp;
97 static ddict_enum_t* enumitem;
98 static ddict_gavp_t* gavp;
99 static ddict_typedefn_t* typedefn;
100 static ddict_cmd_t* cmd;
101 static ddict_vendor_t* vnd;
102 static ddict_xmlpi_t* xmlpi;
104 static ddict_application_t* last_appl;
105 static ddict_avp_t* last_avp;
106 static ddict_enum_t* last_enumitem;
107 static ddict_gavp_t* last_gavp;
108 static ddict_typedefn_t* last_typedefn;
109 static ddict_cmd_t* last_cmd;
110 static ddict_vendor_t* last_vnd;
111 static ddict_xmlpi_t* last_xmlpi;
113 static char** attr_str;
114 static unsigned* attr_uint;
116 static void ddict_debug(const char* fmt, ...);
117 static void append_to_buffer(const char* txt, int len);
118 static FILE* ddict_open(const char*, const char*);
123 xmlpi_start [[:blank:] \r\n]*<\?[[:blank:] \r\n]*
124 xmlpi_end [[:blank:] \r\n]*\?>[[:blank:] \r\n]*
125 xmlpi_key_attr [[:blank:] \r\n]*key[[:blank:] \r\n]*=[[:blank:] \r\n]*\042
126 xmlpi_value_attr [[:blank:] \r\n]*value[[:blank:] \r\n]*=[[:blank:] \r\n]*\042
128 comment_start [[:blank:] \r\n]*<!--[[:blank:] \r\n]*
129 comment_end [[:blank:] \r\n]*-->[[:blank:] \r\n]*
130 open_tag [[:blank:] \r\n]*<[[:blank:] \r\n]*
131 end_tag [[:blank:] \r\n]*\/>[[:blank:] \r\n]*
132 close_tag [[:blank:] \r\n]*>[[:blank:] \r\n]*
133 open_closetag [[:blank:] \r\n]*<\/[[:blank:] \r\n]*
134 equals [[:blank:] \r\n]*=[[:blank:] \r\n]*
135 whitespace [[:blank:] \r\n]*
136 dquoted \042[^\042]*\042
138 doctype [[:blank:] \r\n]*<!DOCTYPE[^\[]*\[[[:blank:] \r\n]*
139 doctype_end [[:blank:] \r\n]*\][[:blank:] \r\n]*>[[:blank:] \r\n]*
141 start_entity [[:blank:] \r\n]*<\!ENTITY[[:blank:] \r\n]*
142 system [[:blank:] \r\n]*SYSTEM[[:blank:] \r\n]*\042
143 entityname [a-z0-9-]+
144 ndquot [^\042]+
145 end_entity \042[[:blank:] \r\n]*>[[:blank:] \r\n]*
147 entity \&[a-z0-9-]+;
149 any .
154 stop >
155 stop_end \/>
156 dquot \042
157 number [-]?[0-9]*
159 dictionary_start <dictionary>
160 dictionary_end <\/dictionary>
162 base_start <base[^>*]*>
163 base_end <\/base>
165 application_start <application
166 application_end<\/application>
168 command_start <command
169 command_end<\/command>
171 typedefn_start <typedefn
173 avp_start <avp
174 avp_end <\/avp>
176 type_start <type
177 enum_start <enum
179 grouped_start <grouped>
180 grouped_end <\/grouped>
182 vendor_start <vendor
183 gavp_start <gavp
185 ignored_attr [a-z0-9-]+=
186 ignored_quoted \042[^\042]*\042
188 name_attr name=\042
189 id_attr id=\042
190 code_attr code=\042
191 vendor_attr vendor-id=\042
192 typename_attr type-name=\042
193 typeparent_attr type-parent=\042
194 description_attr description=\042
198 %S LOADING LOADING_COMMENT LOADING_XMLPI ENTITY GET_SYSTEM GET_FILE END_ENTITY
199 %S GET_ATTR GET_UINT_ATTR END_ATTR OUTSIDE IN_DICT IN_APPL IN_AVP APPL_ATTRS IGNORE_ATTR
200 %S TYPE_ATTRS GAVP_ATTRS ENUM_ATTRS AVP_ATTRS VENDOR_ATTRS COMMAND_ATTRS TYPEDEFN_ATTRS
201 %S XMLPI_ATTRS XMLPI_GETKEY XMLPI_GETVAL XMLPI_ENDATTR
203 <LOADING>{doctype} ;
204 <LOADING>{doctype_end} ;
206 <LOADING>{comment_start} BEGIN LOADING_COMMENT;
207 <LOADING_COMMENT>. ;
208 <LOADING_COMMENT>{comment_end} BEGIN LOADING;
210 <LOADING>{xmlpi_start} BEGIN LOADING_XMLPI;
211 <LOADING_XMLPI>{whitespace} ;
212 <LOADING_XMLPI>{entityname} {
213         xmlpi = g_new(ddict_xmlpi_t,1);
214         xmlpi->name = g_strdup(yytext);
215         xmlpi->key = NULL;
216         xmlpi->value = NULL;
217         xmlpi->next = NULL;
219         if (!dict->xmlpis) last_xmlpi = dict->xmlpis = xmlpi;
220         else last_xmlpi = last_xmlpi->next = xmlpi;
222         BEGIN XMLPI_ATTRS;
225 <XMLPI_ATTRS>{xmlpi_key_attr} BEGIN XMLPI_GETKEY;
226 <XMLPI_GETKEY>{ndquot} { xmlpi->key = strdup(yytext); BEGIN XMLPI_ATTRS; }
228 <XMLPI_ATTRS>{xmlpi_value_attr} BEGIN XMLPI_GETVAL;
229 <XMLPI_GETVAL>{ndquot} { xmlpi->value = strdup(yytext); BEGIN XMLPI_ATTRS; }
231 <XMLPI_ATTRS>.
232 <XMLPI_ATTRS>{xmlpi_end} BEGIN LOADING;
235 <LOADING>{start_entity} BEGIN ENTITY;
236 <ENTITY>{entityname} {
237         entity_t* e = g_new(entity_t,1);
238         e->name = strdup(yytext);
239         e->next = ents.next;
240         ents.next = e;
241         BEGIN GET_SYSTEM;
242         };
243 <GET_SYSTEM>{system} BEGIN GET_FILE;
244 <GET_FILE>{ndquot} {
245                 ents.next->file = strdup(yytext);
246                 BEGIN END_ENTITY;
247         }
248 <END_ENTITY>{end_entity} BEGIN LOADING;
250 <LOADING>{open_tag} APPEND("<",1);
252 <LOADING>{close_tag} APPEND(">",1);
254 <LOADING>{end_tag} APPEND("/>",2);
256 <LOADING>{open_closetag} APPEND("</",2);
258 <LOADING>{whitespace} APPEND(" ",1);
260 <LOADING>{dquoted} APPEND(yytext,yyleng);
262 <LOADING>{equals} APPEND("=",1);
264 <LOADING>{any} APPEND(yytext,yyleng);
266 <LOADING>{entity} {
267         char* p = ++yytext;
268         entity_t* e;
270         while(*p != ';') p++;
272         *p = '\0';
274         D(("looking for entity: %s\n",yytext));
276         if ( include_stack_ptr >= MAX_INCLUDE_DEPTH ) {
277                 fprintf(stderr, "included files nested to deeply\n");
278                 yyterminate();
279         }
281         for (e = ents.next; e; e = e->next) {
282                 if (strcmp(e->name,yytext) == 0) {
283                         yyin = ddict_open(sys_dir,e->file);
284                         D(("entity: %s filename: %s yyin: %p\n",e->name,e->file,yyin));
285                         if (!yyin) {
286                                 if (errno)
287                                         fprintf(stderr, "Could not open file: '%s', error: %s\n", e->file, g_strerror(errno) );
288                                 else
289                                         fprintf(stderr, "Could not open file: '%s', error unknown (errno == 0)\n", e->file );
290                                 yyterminate();
291                         } else {
292                                 include_stack[include_stack_ptr++] = YY_CURRENT_BUFFER;
293                                 yy_switch_to_buffer(yy_create_buffer( yyin, YY_BUF_SIZE ) );
294                                 BEGIN LOADING;
295                         }
296                         break;
297                 }
298         }
300         if (!e) {
301                 fprintf(stderr, "Could not find entity: '%s'\n", yytext );
302                 yyterminate();
303         }
307 <<EOF>> {
308         if (!yyin) yyterminate();
310         fclose(yyin);
311         D(("closing: %p %i\n",yyin,include_stack_ptr));
313         if ( --include_stack_ptr < 0 ) {
314                 D(("DONE READING\n"));
315                 yyin = NULL;
316                 yyterminate();
317         } else {
318                 yy_delete_buffer( YY_CURRENT_BUFFER );
319                 yy_switch_to_buffer(include_stack[include_stack_ptr]);
320                 BEGIN LOADING;
321         }
325 <GET_ATTR>{ndquot} {
326         *attr_str = strdup(yytext);
327         D(("%s\n",yytext));
328         attr_str = NULL;
329         BEGIN END_ATTR;
332 <GET_UINT_ATTR>{number} {
333         *attr_uint = strtoul(yytext,NULL,10);
334         D(("%s\n",yytext););
335         attr_uint = NULL;
336         BEGIN END_ATTR;
339 <END_ATTR>{dquot} {     yy_pop_state(); }
341 <IGNORE_ATTR>. {
342         /* XXX: should go?*/
343         D(("{%s}",yytext));
346 <IGNORE_ATTR>{ignored_quoted} {
347         D(("=>%s<=\n",yytext));
348         yy_pop_state();
351 <OUTSIDE>{dictionary_start} {
352         D(("dictionary_start\n"));
354         BEGIN IN_DICT;
357 <IN_DICT>{base_start} {
358         D(("base_start\n"));
359         BEGIN IN_APPL;
362 <IN_DICT>{application_start} {
363         D(("application_start\n"));
365         appl = g_new(ddict_application_t,1);
366         appl->name = NULL;
367         appl->code = 0;
368         appl->next = NULL;
370         if (!dict->applications) last_appl = dict->applications = appl;
371         else last_appl = last_appl->next = appl;
373         BEGIN APPL_ATTRS;
376 <APPL_ATTRS>{name_attr} { ATTR_STR(appl->name); }
377 <APPL_ATTRS>{id_attr} { ATTR_UINT(appl->code); }
379 <APPL_ATTRS>{stop} BEGIN IN_APPL;
380 <APPL_ATTRS>{stop_end} BEGIN IN_DICT;
382 <IN_APPL>{command_end}                  ;
384 <IN_APPL>{command_start}                {
385         D(("command_start\n"));
387         cmd = g_new(ddict_cmd_t,1);
388         cmd->name = NULL;
389         cmd->vendor = NULL;
390         cmd->code = 0;
391         cmd->next = NULL;
393         if (!dict->cmds) last_cmd = dict->cmds = cmd;
394         else last_cmd = last_cmd->next = cmd;
396         BEGIN COMMAND_ATTRS;
399 <COMMAND_ATTRS>{name_attr}              { ATTR_STR(cmd->name); }
400 <COMMAND_ATTRS>{vendor_attr}    { ATTR_STR(cmd->vendor); }
401 <COMMAND_ATTRS>{code_attr}              { ATTR_UINT(cmd->code); }
402 <COMMAND_ATTRS>{stop}                   |
403 <COMMAND_ATTRS>{stop_end}               { BEGIN IN_APPL; }
405 <IN_APPL>{vendor_start} {
406         D(("vendor_start\n"));
408         vnd = g_new(ddict_vendor_t,1);
409         vnd->name = NULL;
410         vnd->code = 0;
411         vnd->next = NULL;
413         if (!dict->vendors) last_vnd = dict->vendors = vnd;
414         else last_vnd = last_vnd->next = vnd;
416         BEGIN VENDOR_ATTRS;
419 <VENDOR_ATTRS>{name_attr}               { ATTR_STR(vnd->desc); }
420 <VENDOR_ATTRS>{vendor_attr}             { ATTR_STR(vnd->name); }
421 <VENDOR_ATTRS>{code_attr}               { ATTR_UINT(vnd->code); }
422 <VENDOR_ATTRS>{stop}                    |
423 <VENDOR_ATTRS>{stop_end}                { BEGIN IN_APPL; }
425 <IN_APPL>{typedefn_start} {
426         D(("typedefn_start\n"));
428         typedefn = g_new(ddict_typedefn_t,1);
429         typedefn->name = NULL;
430         typedefn->parent = NULL;
431         typedefn->next = NULL;
433         if (!dict->typedefns) last_typedefn = dict->typedefns = typedefn;
434         else last_typedefn = last_typedefn->next = typedefn;
436         BEGIN TYPEDEFN_ATTRS;
439 <TYPEDEFN_ATTRS>{typename_attr}         { ATTR_STR(typedefn->name); }
440 <TYPEDEFN_ATTRS>{typeparent_attr}       { ATTR_STR(typedefn->parent); }
441 <TYPEDEFN_ATTRS>{stop}                  |
442 <TYPEDEFN_ATTRS>{stop_end}              { BEGIN IN_APPL; }
445 <IN_APPL>{avp_start}    {
446         D(("avp_start\n"));
448         avp = g_new(ddict_avp_t,1);
449         avp->name = NULL;
450         avp->description = NULL;
451         avp->vendor = NULL;
452         avp->code = 0;
453         avp->type = NULL;
454         avp->enums = NULL;
455         avp->gavps = NULL;
456         avp->next = NULL;
458         if (! dict->avps ) last_avp = dict->avps = avp;
459         else last_avp = last_avp->next = avp;
461         BEGIN AVP_ATTRS;
464 <AVP_ATTRS>{name_attr}                  { ATTR_STR(avp->name); }
465 <AVP_ATTRS>{description_attr}   { ATTR_STR(avp->description); }
466 <AVP_ATTRS>{vendor_attr}                { ATTR_STR(avp->vendor); }
467 <AVP_ATTRS>{code_attr}                  { ATTR_UINT(avp->code); }
468 <AVP_ATTRS>{stop}                               { BEGIN IN_AVP;  }
469 <AVP_ATTRS>{stop_end}                   { BEGIN IN_APPL; }
472 <IN_AVP>{grouped_start} { avp->type = strdup("Grouped"); };
473 <IN_AVP>{grouped_end} ;
475 <IN_AVP>{type_start} { BEGIN TYPE_ATTRS; }
476 <TYPE_ATTRS>{typename_attr}                     { ATTR_STR(avp->type); }
478 <IN_AVP>{gavp_start} {
479         D(("gavp_start\n"));
481         gavp = g_new(ddict_gavp_t,1);
482         gavp->name = NULL;
483         gavp->code = 0;
484         gavp->next = NULL;
486         if (!avp->gavps) last_gavp = avp->gavps = gavp;
487         else last_gavp = last_gavp->next = gavp;
489         BEGIN GAVP_ATTRS;
493 <GAVP_ATTRS>{name_attr}                 { ATTR_STR(gavp->name); }
496 <IN_AVP>{enum_start} {
497         D(("enum_start\n"));
499         enumitem = g_new(ddict_enum_t,1);
500         enumitem->name = NULL;
501         enumitem->code = 0;
502         enumitem->next = NULL;
504         if (!avp->enums) last_enumitem = avp->enums = enumitem;
505         else last_enumitem = last_enumitem->next = enumitem;
507         BEGIN ENUM_ATTRS;
511 <ENUM_ATTRS>{name_attr}                 { ATTR_STR(enumitem->name); }
512 <ENUM_ATTRS>{code_attr}                 { ATTR_UINT(enumitem->code); }
514 <TYPE_ATTRS,GAVP_ATTRS,ENUM_ATTRS>{stop}                        { BEGIN IN_AVP; }
515 <TYPE_ATTRS,GAVP_ATTRS,ENUM_ATTRS>{stop_end}            { BEGIN IN_AVP; }
517 <IN_AVP>{avp_end} { D(("avp_end")); BEGIN IN_APPL; }
519 <IN_APPL>{application_end} |
520 <IN_APPL>{base_end} {
521         BEGIN IN_DICT;
524 <IN_DICT>{dictionary_end} {
525         yyterminate();
528 <AVP_ATTRS,ENUM_ATTRS,GAVP_ATTRS,TYPE_ATTRS,TYPEDEFN_ATTRS,VENDOR_ATTRS,APPL_ATTRS,COMMAND_ATTRS>{ignored_attr} IGNORE();
530 <OUTSIDE>. ;
539 static int debugging  = 0;
541 static void ddict_debug(const char* fmt, ...) {
542         va_list ap;
544         va_start(ap, fmt);
545         if (debugging) vfprintf(stderr, fmt, ap);
546         va_end(ap);
548         fflush(stderr);
552 static char* strbuf = NULL;
553 static char* write_ptr = NULL;
554 static char* read_ptr = NULL;
556 static unsigned size_strbuf = 8192;
557 static unsigned len_strbuf = 0;
559 extern void ddict_unused(void);
560 void ddict_unused(void) {
561         yy_top_state();
564 static void append_to_buffer(const char* txt, int len) {
566         if (strbuf == NULL) {
567                 read_ptr = write_ptr = strbuf = (char*)g_malloc(size_strbuf);
568         }
570         if ( (len_strbuf + len) >= size_strbuf ) {
571                 read_ptr = strbuf = (char*)g_realloc(strbuf,size_strbuf *= 2);
572         }
574         write_ptr = strbuf + len_strbuf;
575         strncpy(write_ptr,txt,len);
576         len_strbuf += len;
580 static size_t file_input(char* buf, size_t max) {
581         size_t read_cnt;
583         read_cnt = fread(buf,1,max,yyin);
585         if ( read_cnt == max ) {
586                 return max;
587         } else if (read_cnt > 0) {
588                 return read_cnt;
589         } else {
590                 return YY_NULL;
591         }
595 static size_t string_input(char* buf, size_t max) {
596         if (read_ptr >= write_ptr ) {
597                 return YY_NULL;
598         } else if ( read_ptr + max > write_ptr ) {
599                 max = write_ptr - read_ptr;
600         }
602         memcpy(buf,read_ptr,max);
603         read_ptr += max;
605         return max;
608 static FILE* ddict_open(const char* system_directory, const char* filename) {
609         FILE* fh;
610         char* fname;
611         if (system_directory) {
612                 fname = g_strdup_printf("%s" G_DIR_SEPARATOR_S "%s",
613                     system_directory,filename);
614         } else {
615                 fname = g_strdup(filename);
616         }
618         fh = ws_fopen(fname,"r");
620         D(("fname: %s fh: %p\n",fname,fh));
622         g_free(fname);
625         return fh;
628 ddict_t* ddict_scan(const char* system_directory, const char* filename, int dbg) {
630         debugging = dbg;
632         sys_dir = system_directory;
634         yyin = ddict_open(sys_dir,filename);
636         if (yyin == NULL) {
637                 D(("unable to open %s\n", filename));
638                 return NULL;
639         }
641         write_ptr = NULL;
642         read_ptr = NULL;
644         dict = g_new(ddict_t,1);
645         dict->applications = NULL;
646         dict->cmds = NULL;
647         dict->vendors = NULL;
648         dict->typedefns = NULL;
649         dict->avps = NULL;
650         dict->xmlpis = NULL;
652         appl = NULL;
653         avp = NULL;
654         enumitem = NULL;
655         gavp = NULL;
656         typedefn = NULL;
657         cmd = NULL;
658         vnd = NULL;
659         xmlpi = NULL;
661         last_appl = NULL;
662         last_avp = NULL;
663         last_enumitem = NULL;
664         last_gavp = NULL;
665         last_typedefn = NULL;
666         last_cmd = NULL;
667         last_vnd = NULL;
668         last_xmlpi = NULL;
670         ents.next = NULL;
671         current_yyinput = file_input;
672         BEGIN LOADING;
673         yylex();
675         D(("\n---------------\n%s\n------- %d -------\n",strbuf,len_strbuf));
677         current_yyinput = string_input;
679         BEGIN OUTSIDE;
680         yylex();
682         g_free(strbuf);
683         strbuf = NULL;
684         size_strbuf = 8192;
686         return dict;
689 void ddict_free(ddict_t* d) {
690         ddict_application_t *p, *pn;
691         ddict_vendor_t *v, *vn;
692         ddict_cmd_t *c, *cn;
693         ddict_typedefn_t *t, *tn;
694         ddict_avp_t *a, *an;
696 #define FREE_NAMEANDOBJ(n) do { if(n->name) g_free(n->name); g_free(n); } while(0)
698         for (p = d->applications; p; p = pn ) {
699                 pn = p->next;
700                 FREE_NAMEANDOBJ(p);
701         }
703         for (v = d->vendors; v; v = vn) {
704                 vn = v->next;
705                 if (!v->desc)  g_free(v->desc);
706                 FREE_NAMEANDOBJ(v);
707         }
709         for (c = d->cmds; c; c = cn ) {
710                 cn = c->next;
711                 FREE_NAMEANDOBJ(c);
712         }
714         for (t = d->typedefns; t; t = tn) {
715                 tn = t->next;
716                 if (!t->parent)  g_free(t->parent);
717                 FREE_NAMEANDOBJ(t);
718         }
720         for (a = d->avps; a; a = an) {
721                 ddict_gavp_t* g, *gn;
722                 ddict_enum_t* e, *en;
723                 an = a->next;
725                 for (g = a->gavps; g; g = gn) {
726                         gn = g->next;
727                         FREE_NAMEANDOBJ(g);
728                 }
730                 for (e = a->enums; e; e = en) {
731                         en = e->next;
732                         FREE_NAMEANDOBJ(e);
733                 }
735                 if (!a->vendor)  g_free(a->vendor);
736                 if (!a->type)  g_free(a->type);
737                 if (!a->description)  g_free(a->description);
738                 FREE_NAMEANDOBJ(a);
739         }
741         g_free(d);
744 void ddict_print(FILE* fh, ddict_t* d) {
745         ddict_application_t* p;
746         ddict_vendor_t* v;
747         ddict_cmd_t* c;
748         ddict_typedefn_t* t;
749         ddict_avp_t* a;
752         for (p = d->applications; p; p = p->next) {
753                 fprintf(fh,"Application: %s[%u]:\n",
754                                 p->name ? p->name : "-",
755                                 p->code);
756         }
758         for (v = d->vendors; v; v = v->next) {
759                 fprintf(fh,"Vendor: %s[%u]:\n",
760                                 v->name ? v->name : "-",
761                                 v->code);
762         }
764         for (c = d->cmds; c; c = c->next) {
765                 fprintf(fh,"Command: %s[%u] \n",
766                                 c->name ? c->name : "-",
767                                 c->code);
768         }
770         for (t = d->typedefns; t; t = t->next) {
771                 fprintf(fh,"Type: %s -> %s \n",
772                                 t->name ? t->name : "-",
773                                 t->parent ? t->parent : "" );
774         }
776         for (a = d->avps; a; a = a->next) {
777                 ddict_gavp_t* g;
778                 ddict_enum_t* e;
779                 fprintf(fh,"AVP: %s[%u:%s] %s %s\n",
780                                 a->name ? a->name : "-",
781                                 a->code,
782                                 a->vendor ? a->vendor : "None",
783                                 a->type ? a->type : "-",
784                                 a->description ? a->description : "");
786                 for (g = a->gavps; g; g = g->next) {
787                         fprintf(fh,"\tGAVP: %s\n",
788                                         g->name ? g->name : "-" );
789                 }
791                 for (e = a->enums; e; e = e->next) {
792                         fprintf(fh,"\tEnum: %s[%u]\n",
793                                         e->name ? e->name : "-",
794                                         e->code);
795                 }
796         }
800  * We want to stop processing when we get to the end of the input.
801  * (%option noyywrap is not used because if used then
802  * some flex versions (eg: 2.5.35) generate code which causes
803  * warnings by the Windows VC compiler).
804  */
806 int yywrap(void) {
807     return 1;
810 #ifdef TEST_DIAM_DICT_STANDALONE
811 int main(int argc, char** argv) {
812         ddict_t* d;
813         char* dname = NULL;
814         char* fname;
815         int i = 1;
817         switch (argc) {
818                 case 3:
819                         dname = argv[i++];
820                 case 2:
821                         fname = argv[i];
822                         break;
823                 default:
824                         fprintf(stderr,"%s: usage [dictionary_dir] dictionary_filename\n",argv[0]);
825                         return 1;
826         }
828         d = ddict_scan(dname,fname,1);
829         if (d == NULL) {
830                 fprintf(stderr, "Can't open dictionary\n");
831                 return 2;
832         }
834         ddict_print(stdout, d);
836         return 0;
838 #endif