msxml3: Only allow ASCII characters in number conversion.
[wine.git] / tools / widl / parser.l
blobd7d967023226e14ce3b88f33a3f22b223f9db167
1 /* -*-C-*-
2  * IDL Compiler
3  *
4  * Copyright 2002 Ove Kaaven
5  *
6  * This library is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU Lesser General Public
8  * License as published by the Free Software Foundation; either
9  * version 2.1 of the License, or (at your option) any later version.
10  *
11  * This library is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14  * Lesser General Public License for more details.
15  *
16  * You should have received a copy of the GNU Lesser General Public
17  * License along with this library; if not, write to the Free Software
18  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
19  */
21 %option stack
22 %option noinput nounput noyy_top_state
23 %option 8bit never-interactive prefix="parser_"
25 nl      \r?\n
26 ws      [ \f\t\r]
27 cident  [a-zA-Z_][0-9a-zA-Z_]*
28 u_suffix        (u|U)
29 l_suffix        (l|L)
30 int     [0-9]+({l_suffix}?{u_suffix}?|{u_suffix}?{l_suffix}?)?
31 hexd    [0-9a-fA-F]
32 hex     0(x|X){hexd}+({l_suffix}?{u_suffix}?|{u_suffix}?{l_suffix}?)?
33 uuid    {hexd}{8}-{hexd}{4}-{hexd}{4}-{hexd}{4}-{hexd}{12}
34 double  [0-9]+\.[0-9]+([eE][+-]?[0-9]+)*
36 %x QUOTE
37 %x WSTRQUOTE
38 %x ATTR
39 %x PP_LINE
40 %x PP_PRAGMA
41 %x SQUOTE
45 #include "config.h"
46 #include "wine/port.h"
48 #include <stdio.h>
49 #include <stdlib.h>
50 #include <string.h>
51 #include <ctype.h>
52 #include <assert.h>
53 #include <errno.h>
54 #include <limits.h>
56 #ifdef HAVE_UNISTD_H
57 #include <unistd.h>
58 #else
59 #define YY_NO_UNISTD_H
60 #endif
62 #include "widl.h"
63 #include "utils.h"
64 #include "parser.h"
65 #include "wine/wpp.h"
67 #include "parser.tab.h"
69 static void addcchar(char c);
70 static char *get_buffered_cstring(void);
72 static char *cbuffer;
73 static int cbufidx;
74 static int cbufalloc = 0;
76 static int kw_token(const char *kw);
77 static int attr_token(const char *kw);
79 static void switch_to_acf(void);
81 static warning_list_t *disabled_warnings = NULL;
83 #define MAX_IMPORT_DEPTH 20
84 struct {
85   YY_BUFFER_STATE state;
86   char *input_name;
87   int   line_number;
88   char *temp_name;
89 } import_stack[MAX_IMPORT_DEPTH];
90 int import_stack_ptr = 0;
92 /* converts an integer in string form to an unsigned long and prints an error
93  * on overflow */
94 static unsigned int xstrtoul(const char *nptr, char **endptr, int base)
96     unsigned long val;
98     errno = 0;
99     val = strtoul(nptr, endptr, base);
100     if ((val == ULONG_MAX && errno == ERANGE) || ((unsigned int)val != val))
101         error_loc("integer constant %s is too large\n", nptr);
102     return val;
105 UUID *parse_uuid(const char *u)
107   UUID* uuid = xmalloc(sizeof(UUID));
108   char b[3];
109   /* it would be nice to use UuidFromStringA */
110   uuid->Data1 = strtoul(u, NULL, 16);
111   uuid->Data2 = strtoul(u+9, NULL, 16);
112   uuid->Data3 = strtoul(u+14, NULL, 16);
113   b[2] = 0;
114   memcpy(b, u+19, 2); uuid->Data4[0] = strtoul(b, NULL, 16);
115   memcpy(b, u+21, 2); uuid->Data4[1] = strtoul(b, NULL, 16);
116   memcpy(b, u+24, 2); uuid->Data4[2] = strtoul(b, NULL, 16);
117   memcpy(b, u+26, 2); uuid->Data4[3] = strtoul(b, NULL, 16);
118   memcpy(b, u+28, 2); uuid->Data4[4] = strtoul(b, NULL, 16);
119   memcpy(b, u+30, 2); uuid->Data4[5] = strtoul(b, NULL, 16);
120   memcpy(b, u+32, 2); uuid->Data4[6] = strtoul(b, NULL, 16);
121   memcpy(b, u+34, 2); uuid->Data4[7] = strtoul(b, NULL, 16);
122   return uuid;
128  **************************************************************************
129  * The flexer starts here
130  **************************************************************************
131  */
133 <INITIAL>^{ws}*\#{ws}*pragma{ws}+ yy_push_state(PP_PRAGMA);
134 <INITIAL,ATTR>^{ws}*\#{ws}*     yy_push_state(PP_LINE);
135 <PP_LINE>[^\n]*         {
136                             int lineno;
137                             char *cptr, *fname;
138                             yy_pop_state();
139                             lineno = (int)strtol(yytext, &cptr, 10);
140                             if(!lineno)
141                                 error_loc("Malformed '#...' line-directive; invalid linenumber\n");
142                             fname = strchr(cptr, '"');
143                             if(!fname)
144                                 error_loc("Malformed '#...' line-directive; missing filename\n");
145                             fname++;
146                             cptr = strchr(fname, '"');
147                             if(!cptr)
148                                 error_loc("Malformed '#...' line-directive; missing terminating \"\n");
149                             *cptr = '\0';
150                             line_number = lineno - 1;  /* We didn't read the newline */
151                             input_name = xstrdup(fname);
152                         }
153 <PP_PRAGMA>midl_echo[^\n]*  yyless(9); yy_pop_state(); return tCPPQUOTE;
154 <PP_PRAGMA>winrt[^\n]*  {
155                             if(import_stack_ptr) {
156                                 if(!winrt_mode)
157                                     error_loc("winrt IDL file imported in non-winrt mode\n");
158                             }else {
159                                 const char *ptr = yytext+5;
161                                 winrt_mode = TRUE;
163                                 while(isspace(*ptr))
164                                     ptr++;
165                                 if(!strncmp(ptr, "ns_prefix", 9) && (!*(ptr += 9) || isspace(*ptr)))
166                                     use_abi_namespace = TRUE;
167                             }
168                             yy_pop_state();
169                         }
170 <PP_PRAGMA>[^\n]*       parser_lval.str = xstrdup(yytext); yy_pop_state(); return aPRAGMA;
171 <INITIAL>^{ws}*midl_pragma{ws}+warning return tPRAGMA_WARNING;
172 <INITIAL,ATTR>\"        yy_push_state(QUOTE); cbufidx = 0;
173 <QUOTE>\"               {
174                                 yy_pop_state();
175                                 parser_lval.str = get_buffered_cstring();
176                                 return aSTRING;
177                         }
178 <INITIAL,ATTR>L\"       yy_push_state(WSTRQUOTE); cbufidx = 0;
179 <WSTRQUOTE>\"           {
180                                 yy_pop_state();
181                                 parser_lval.str = get_buffered_cstring();
182                                 return aWSTRING;
183                         }
184 <INITIAL,ATTR>\'        yy_push_state(SQUOTE); cbufidx = 0;
185 <SQUOTE>\'              {
186                                 yy_pop_state();
187                                 parser_lval.str = get_buffered_cstring();
188                                 return aSQSTRING;
189                         }
190 <QUOTE,WSTRQUOTE,SQUOTE>\\\\    |
191 <QUOTE,WSTRQUOTE>\\\"   addcchar(yytext[1]);
192 <SQUOTE>\\\'    addcchar(yytext[1]);
193 <QUOTE,WSTRQUOTE,SQUOTE>\\.     addcchar('\\'); addcchar(yytext[1]);
194 <QUOTE,WSTRQUOTE,SQUOTE>.       addcchar(yytext[0]);
195 <INITIAL,ATTR>\[        yy_push_state(ATTR); return '[';
196 <ATTR>\]                yy_pop_state(); return ']';
197 <ATTR>{cident}          return attr_token(yytext);
198 <ATTR>{uuid}                    {
199                                 parser_lval.uuid = parse_uuid(yytext);
200                                 return aUUID;
201                         }
202 <INITIAL,ATTR>{hex}     {
203                                 parser_lval.num = xstrtoul(yytext, NULL, 0);
204                                 return aHEXNUM;
205                         }
206 <INITIAL,ATTR>{int}     {
207                                 parser_lval.num = xstrtoul(yytext, NULL, 0);
208                                 return aNUM;
209                         }
210 <INITIAL>{double}       {
211                                 parser_lval.dbl = strtod(yytext, NULL);
212                                 return aDOUBLE;
213                         }
214 SAFEARRAY{ws}*/\(       return tSAFEARRAY;
215 {cident}                return kw_token(yytext);
216 <INITIAL,ATTR>\n        line_number++;
217 <INITIAL,ATTR>{ws}
218 <INITIAL,ATTR>\<\<      return SHL;
219 <INITIAL,ATTR>\>\>      return SHR;
220 <INITIAL,ATTR>\-\>      return MEMBERPTR;
221 <INITIAL,ATTR>==        return EQUALITY;
222 <INITIAL,ATTR>!=        return INEQUALITY;
223 <INITIAL,ATTR>\>=       return GREATEREQUAL;
224 <INITIAL,ATTR>\<=       return LESSEQUAL;
225 <INITIAL,ATTR>\|\|      return LOGICALOR;
226 <INITIAL,ATTR>&&        return LOGICALAND;
227 <INITIAL,ATTR>\.\.\.    return ELLIPSIS;
228 <INITIAL,ATTR>.         return yytext[0];
229 <<EOF>>                 {
230                             if (import_stack_ptr)
231                                 return aEOF;
232                             if (acf_name)
233                             {
234                                 switch_to_acf();
235                                 return aACF;
236                             }
237                             yyterminate();
238                         }
241 #ifndef parser_wrap
242 int parser_wrap(void)
244         return 1;
246 #endif
248 struct keyword {
249         const char *kw;
250         int token;
251         int winrt_only : 1;
254 /* This table MUST be alphabetically sorted on the kw field */
255 static const struct keyword keywords[] = {
256         {"FALSE",           tFALSE,          0},
257         {"NULL",            tNULL,           0},
258         {"TRUE",            tTRUE,           0},
259         {"__cdecl",         tCDECL,          0},
260         {"__fastcall",      tFASTCALL,       0},
261         {"__int32",         tINT32,          0},
262         {"__int3264",       tINT3264,        0},
263         {"__int64",         tINT64,          0},
264         {"__pascal",        tPASCAL,         0},
265         {"__stdcall",       tSTDCALL,        0},
266         {"_cdecl",          tCDECL,          0},
267         {"_fastcall",       tFASTCALL,       0},
268         {"_pascal",         tPASCAL,         0},
269         {"_stdcall",        tSTDCALL,        0},
270         {"boolean",         tBOOLEAN,        0},
271         {"byte",            tBYTE,           0},
272         {"case",            tCASE,           0},
273         {"cdecl",           tCDECL,          0},
274         {"char",            tCHAR,           0},
275         {"coclass",         tCOCLASS,        0},
276         {"const",           tCONST,          0},
277         {"cpp_quote",       tCPPQUOTE,       0},
278         {"default",         tDEFAULT,        0},
279         {"dispinterface",   tDISPINTERFACE,  0},
280         {"double",          tDOUBLE,         0},
281         {"enum",            tENUM,           0},
282         {"error_status_t",  tERRORSTATUST,   0},
283         {"extern",          tEXTERN,         0},
284         {"float",           tFLOAT,          0},
285         {"handle_t",        tHANDLET,        0},
286         {"hyper",           tHYPER,          0},
287         {"import",          tIMPORT,         0},
288         {"importlib",       tIMPORTLIB,      0},
289         {"inline",          tINLINE,         0},
290         {"int",             tINT,            0},
291         {"interface",       tINTERFACE,      0},
292         {"library",         tLIBRARY,        0},
293         {"long",            tLONG,           0},
294         {"methods",         tMETHODS,        0},
295         {"module",          tMODULE,         0},
296         {"namespace",       tNAMESPACE,      1},
297         {"pascal",          tPASCAL,         0},
298         {"properties",      tPROPERTIES,     0},
299         {"register",        tREGISTER,       0},
300         {"short",           tSHORT,          0},
301         {"signed",          tSIGNED,         0},
302         {"sizeof",          tSIZEOF,         0},
303         {"small",           tSMALL,          0},
304         {"static",          tSTATIC,         0},
305         {"stdcall",         tSTDCALL,        0},
306         {"struct",          tSTRUCT,         0},
307         {"switch",          tSWITCH,         0},
308         {"typedef",         tTYPEDEF,        0},
309         {"union",           tUNION,          0},
310         {"unsigned",        tUNSIGNED,       0},
311         {"void",            tVOID,           0},
312         {"wchar_t",         tWCHAR,          0},
314 #define NKEYWORDS (sizeof(keywords)/sizeof(keywords[0]))
316 /* keywords only recognized in attribute lists
317  * This table MUST be alphabetically sorted on the kw field
318  */
319 static const struct keyword attr_keywords[] =
321         {"aggregatable",                tAGGREGATABLE,              0},
322         {"all_nodes",                   tALLNODES,                  0},
323         {"allocate",                    tALLOCATE,                  0},
324         {"annotation",                  tANNOTATION,                0},
325         {"apartment",                   tAPARTMENT,                 0},
326         {"appobject",                   tAPPOBJECT,                 0},
327         {"async",                       tASYNC,                     0},
328         {"async_uuid",                  tASYNCUUID,                 0},
329         {"auto_handle",                 tAUTOHANDLE,                0},
330         {"bindable",                    tBINDABLE,                  0},
331         {"both",                        tBOTH,                      0},
332         {"broadcast",                   tBROADCAST,                 0},
333         {"byte_count",                  tBYTECOUNT,                 0},
334         {"call_as",                     tCALLAS,                    0},
335         {"callback",                    tCALLBACK,                  0},
336         {"code",                        tCODE,                      0},
337         {"comm_status",                 tCOMMSTATUS,                0},
338         {"context_handle",              tCONTEXTHANDLE,             0},
339         {"context_handle_noserialize",  tCONTEXTHANDLENOSERIALIZE,  0},
340         {"context_handle_serialize",    tCONTEXTHANDLENOSERIALIZE,  0},
341         {"control",                     tCONTROL,                   0},
342         {"custom",                      tCUSTOM,                    0},
343         {"decode",                      tDECODE,                    0},
344         {"defaultbind",                 tDEFAULTBIND,               0},
345         {"defaultcollelem",             tDEFAULTCOLLELEM,           0},
346         {"defaultvalue",                tDEFAULTVALUE,              0},
347         {"defaultvtable",               tDEFAULTVTABLE,             0},
348         {"disable_consistency_check",   tDISABLECONSISTENCYCHECK,   0},
349         {"displaybind",                 tDISPLAYBIND,               0},
350         {"dllname",                     tDLLNAME,                   0},
351         {"dont_free",                   tDONTFREE,                  0},
352         {"dual",                        tDUAL,                      0},
353         {"enable_allocate",             tENABLEALLOCATE,            0},
354         {"encode",                      tENCODE,                    0},
355         {"endpoint",                    tENDPOINT,                  0},
356         {"entry",                       tENTRY,                     0},
357         {"explicit_handle",             tEXPLICITHANDLE,            0},
358         {"fault_status",                tFAULTSTATUS,               0},
359         {"force_allocate",              tFORCEALLOCATE,             0},
360         {"free",                        tFREE,                      0},
361         {"handle",                      tHANDLE,                    0},
362         {"helpcontext",                 tHELPCONTEXT,               0},
363         {"helpfile",                    tHELPFILE,                  0},
364         {"helpstring",                  tHELPSTRING,                0},
365         {"helpstringcontext",           tHELPSTRINGCONTEXT,         0},
366         {"helpstringdll",               tHELPSTRINGDLL,             0},
367         {"hidden",                      tHIDDEN,                    0},
368         {"id",                          tID,                        0},
369         {"idempotent",                  tIDEMPOTENT,                0},
370         {"ignore",                      tIGNORE,                    0},
371         {"iid_is",                      tIIDIS,                     0},
372         {"immediatebind",               tIMMEDIATEBIND,             0},
373         {"implicit_handle",             tIMPLICITHANDLE,            0},
374         {"in",                          tIN,                        0},
375         {"in_line",                     tIN_LINE,                   0},
376         {"input_sync",                  tINPUTSYNC,                 0},
377         {"lcid",                        tLCID,                      0},
378         {"length_is",                   tLENGTHIS,                  0},
379         {"licensed",                    tLICENSED,                  0},
380         {"local",                       tLOCAL,                     0},
381         {"maybe",                       tMAYBE,                     0},
382         {"message",                     tMESSAGE,                   0},
383         {"neutral",                     tNEUTRAL,                   0},
384         {"nocode",                      tNOCODE,                    0},
385         {"nonbrowsable",                tNONBROWSABLE,              0},
386         {"noncreatable",                tNONCREATABLE,              0},
387         {"nonextensible",               tNONEXTENSIBLE,             0},
388         {"notify",                      tNOTIFY,                    0},
389         {"notify_flag",                 tNOTIFYFLAG,                0},
390         {"object",                      tOBJECT,                    0},
391         {"odl",                         tODL,                       0},
392         {"oleautomation",               tOLEAUTOMATION,             0},
393         {"optimize",                    tOPTIMIZE,                  0},
394         {"optional",                    tOPTIONAL,                  0},
395         {"out",                         tOUT,                       0},
396         {"partial_ignore",              tPARTIALIGNORE,             0},
397         {"pointer_default",             tPOINTERDEFAULT,            0},
398         {"progid",                      tPROGID,                    0},
399         {"propget",                     tPROPGET,                   0},
400         {"propput",                     tPROPPUT,                   0},
401         {"propputref",                  tPROPPUTREF,                0},
402         {"proxy",                       tPROXY,                     0},
403         {"ptr",                         tPTR,                       0},
404         {"public",                      tPUBLIC,                    0},
405         {"range",                       tRANGE,                     0},
406         {"readonly",                    tREADONLY,                  0},
407         {"ref",                         tREF,                       0},
408         {"represent_as",                tREPRESENTAS,               0},
409         {"requestedit",                 tREQUESTEDIT,               0},
410         {"restricted",                  tRESTRICTED,                0},
411         {"retval",                      tRETVAL,                    0},
412         {"single",                      tSINGLE,                    0},
413         {"single_node",                 tSINGLENODE,                0},
414         {"size_is",                     tSIZEIS,                    0},
415         {"source",                      tSOURCE,                    0},
416         {"strict_context_handle",       tSTRICTCONTEXTHANDLE,       0},
417         {"string",                      tSTRING,                    0},
418         {"switch_is",                   tSWITCHIS,                  0},
419         {"switch_type",                 tSWITCHTYPE,                0},
420         {"threading",                   tTHREADING,                 0},
421         {"transmit_as",                 tTRANSMITAS,                0},
422         {"uidefault",                   tUIDEFAULT,                 0},
423         {"unique",                      tUNIQUE,                    0},
424         {"user_marshal",                tUSERMARSHAL,               0},
425         {"usesgetlasterror",            tUSESGETLASTERROR,          0},
426         {"uuid",                        tUUID,                      0},
427         {"v1_enum",                     tV1ENUM,                    0},
428         {"vararg",                      tVARARG,                    0},
429         {"version",                     tVERSION,                   0},
430         {"vi_progid",                   tVIPROGID,                  0},
431         {"wire_marshal",                tWIREMARSHAL,               0},
434 /* attributes TODO:
435     first_is
436     last_is
437     max_is
438     min_is
441 #define KWP(p) ((const struct keyword *)(p))
443 static int kw_cmp_func(const void *s1, const void *s2)
445         return strcmp(KWP(s1)->kw, KWP(s2)->kw);
448 static int kw_token(const char *kw)
450         struct keyword key, *kwp;
451         key.kw = kw;
452         kwp = bsearch(&key, keywords, NKEYWORDS, sizeof(keywords[0]), kw_cmp_func);
453         if (kwp && (!kwp->winrt_only || winrt_mode)) {
454                 parser_lval.str = xstrdup(kwp->kw);
455                 return kwp->token;
456         }
457         parser_lval.str = xstrdup(kw);
458         return is_type(kw) ? aKNOWNTYPE : is_namespace(kw) ? aNAMESPACE : aIDENTIFIER;
461 static int attr_token(const char *kw)
463         struct keyword key, *kwp;
464         key.kw = kw;
465         kwp = bsearch(&key, attr_keywords, sizeof(attr_keywords)/sizeof(attr_keywords[0]),
466                       sizeof(attr_keywords[0]), kw_cmp_func);
467         if (kwp && (!kwp->winrt_only || winrt_mode)) {
468             parser_lval.str = xstrdup(kwp->kw);
469             return kwp->token;
470         }
471         return kw_token(kw);
474 static void addcchar(char c)
476         if(cbufidx >= cbufalloc)
477         {
478                 cbufalloc += 1024;
479                 cbuffer = xrealloc(cbuffer, cbufalloc * sizeof(cbuffer[0]));
480                 if(cbufalloc > 65536)
481                         parser_warning("Reallocating string buffer larger than 64kB\n");
482         }
483         cbuffer[cbufidx++] = c;
486 static char *get_buffered_cstring(void)
488         addcchar(0);
489         return xstrdup(cbuffer);
492 void pop_import(void)
494         int ptr = import_stack_ptr-1;
496         fclose(yyin);
497         yy_delete_buffer( YY_CURRENT_BUFFER );
498         yy_switch_to_buffer( import_stack[ptr].state );
499         if (temp_name) {
500                 unlink(temp_name);
501                 free(temp_name);
502         }
503         temp_name = import_stack[ptr].temp_name;
504         input_name = import_stack[ptr].input_name;
505         line_number = import_stack[ptr].line_number;
506         import_stack_ptr--;
509 struct imports {
510     char *name;
511     struct imports *next;
512 } *first_import;
514 int do_import(char *fname)
516     FILE *f;
517     char *path, *name;
518     struct imports *import;
519     int ptr = import_stack_ptr;
520     int ret, fd;
522     import = first_import;
523     while (import && strcmp(import->name, fname))
524         import = import->next;
525     if (import) return 0; /* already imported */
527     import = xmalloc(sizeof(struct imports));
528     import->name = xstrdup(fname);
529     import->next = first_import;
530     first_import = import;
532     /* don't search for a file name with a path in the include directories,
533      * for compatibility with MIDL */
534     if (strchr( fname, '/' ) || strchr( fname, '\\' ))
535         path = xstrdup( fname );
536     else if (!(path = wpp_find_include( fname, input_name )))
537         error_loc("Unable to open include file %s\n", fname);
539     if (import_stack_ptr == MAX_IMPORT_DEPTH)
540         error_loc("Exceeded max import depth\n");
542     import_stack[ptr].temp_name = temp_name;
543     import_stack[ptr].input_name = input_name;
544     import_stack[ptr].line_number = line_number;
545     import_stack_ptr++;
546     input_name = path;
547     line_number = 1;
549     name = xstrdup( "widl.XXXXXX" );
550     if((fd = mkstemps( name, 0 )) == -1)
551         error("Could not generate a temp name from %s\n", name);
553     temp_name = name;
554     if (!(f = fdopen(fd, "wt")))
555         error("Could not open fd %s for writing\n", name);
557     ret = wpp_parse( path, f );
558     fclose( f );
559     if (ret) exit(1);
561     if((f = fopen(temp_name, "r")) == NULL)
562         error_loc("Unable to open %s\n", temp_name);
564     import_stack[ptr].state = YY_CURRENT_BUFFER;
565     yy_switch_to_buffer(yy_create_buffer(f, YY_BUF_SIZE));
566     return 1;
569 void abort_import(void)
571         int ptr;
573         for (ptr=0; ptr<import_stack_ptr; ptr++)
574                 unlink(import_stack[ptr].temp_name);
577 static void switch_to_acf(void)
579     int ptr = import_stack_ptr;
580     int ret, fd;
581     char *name;
582     FILE *f;
584     assert(import_stack_ptr == 0);
586     input_name = acf_name;
587     acf_name = NULL;
588     line_number = 1;
590     name = xstrdup( "widl.XXXXXX" );
591     if((fd = mkstemps( name, 0 )) == -1)
592         error("Could not generate a temp name from %s\n", name);
594     temp_name = name;
595     if (!(f = fdopen(fd, "wt")))
596         error("Could not open fd %s for writing\n", name);
598     ret = wpp_parse(input_name, f);
599     fclose(f);
600     if (ret) exit(1);
602     if((f = fopen(temp_name, "r")) == NULL)
603         error_loc("Unable to open %s\n", temp_name);
605     import_stack[ptr].state = YY_CURRENT_BUFFER;
606     yy_switch_to_buffer(yy_create_buffer(f, YY_BUF_SIZE));
609 static void warning_disable(int warning)
611     warning_t *warning_entry;
612     LIST_FOR_EACH_ENTRY(warning_entry, disabled_warnings, warning_t, entry)
613         if(warning_entry->num == warning)
614             return;
615     warning_entry = xmalloc( sizeof(*warning_entry) );
616     warning_entry->num = warning;
617     list_add_tail(disabled_warnings, &warning_entry->entry);
620 static void warning_enable(int warning)
622     warning_t *warning_entry;
623     LIST_FOR_EACH_ENTRY(warning_entry, disabled_warnings, warning_t, entry)
624         if(warning_entry->num == warning)
625         {
626             list_remove(&warning_entry->entry);
627             free(warning_entry);
628             break;
629         }
632 int do_warning(char *toggle, warning_list_t *wnum)
634     warning_t *warning, *next;
635     int ret = 1;
636     if(!disabled_warnings)
637     {
638         disabled_warnings = xmalloc( sizeof(*disabled_warnings) );
639         list_init( disabled_warnings );
640     }
642     if(!strcmp(toggle, "disable"))
643         LIST_FOR_EACH_ENTRY(warning, wnum, warning_t, entry)
644             warning_disable(warning->num);
645     else if(!strcmp(toggle, "enable"))
646         LIST_FOR_EACH_ENTRY(warning, wnum, warning_t, entry)
647             warning_enable(warning->num);
648     else
649         ret = 0;
651     LIST_FOR_EACH_ENTRY_SAFE(warning, next, wnum, warning_t, entry)
652         free(warning);
653     return ret;
656 int is_warning_enabled(int warning)
658     warning_t *warning_entry;
659     if(!disabled_warnings)
660         return 1;
661     LIST_FOR_EACH_ENTRY(warning_entry, disabled_warnings, warning_t, entry)
662         if(warning_entry->num == warning)
663             return 0;
664     return 1;