4 * Copyright 2002 Ove Kaaven
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.
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.
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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
22 %option never-interactive
26 cident [a-zA-Z_][0-9a-zA-Z_]*
30 uuid {hexd}{8}-{hexd}{4}-{hexd}{4}-{hexd}{4}-{hexd}{12}
46 #include "../wpp/wpp.h"
52 #define YY_NO_TOP_STATE
54 extern char *temp_name;
56 static void addcchar(char c);
57 static char *get_buffered_cstring(void);
61 static int cbufalloc = 0;
63 static int kw_token(const char *kw);
65 #define MAX_IMPORT_DEPTH 10
67 YY_BUFFER_STATE state;
69 } import_stack[MAX_IMPORT_DEPTH];
70 int import_stack_ptr = 0;
72 static void pop_import(void);
77 **************************************************************************
78 * The flexer starts here
79 **************************************************************************
83 \" yy_push_state(QUOTE); cbufidx = 0;
86 yylval.str = get_buffered_cstring();
90 <QUOTE>\\\" addcchar(yytext[1]);
91 <QUOTE>\\. addcchar('\\'); addcchar(yytext[1]);
92 <QUOTE>. addcchar(yytext[0]);
96 {cident} return kw_token(yytext);
103 if (import_stack_ptr) pop_import();
122 {"__stdcall", tSTDCALL},
123 {"_stdcall", tSTDCALL},
124 {"aggregatable", tAGGREGATABLE},
125 {"allocate", tALLOCATE},
126 {"appobject", tAPPOBJECT},
129 {"async_uuid", tASYNCUUID},
130 {"auto_handle", tAUTOHANDLE},
131 {"bindable", tBINDABLE},
132 {"boolean", tBOOLEAN},
133 {"broadcast", tBROADCAST},
135 {"byte_count", tBYTECOUNT},
136 {"call_as", tCALLAS},
137 {"callback", tCALLBACK},
140 {"coclass", tCOCLASS},
142 {"comm_status", tCOMMSTATUS},
144 {"context_handle", tCONTEXTHANDLE},
145 {"context_handle_noserialize", tCONTEXTHANDLENOSERIALIZE},
146 {"context_handle_serialize", tCONTEXTHANDLENOSERIALIZE},
147 {"control", tCONTROL},
148 {"cpp_quote", tCPPQUOTE},
150 {"default", tDEFAULT},
165 {"importlib", tIMPORTLIB},
167 {"include", tINCLUDE},
168 {"in_line", tINLINE},
171 {"interface", tINTERFACE},
173 {"length_is", tLENGTHIS},
180 {"oleautomation", tOLEAUTOMATION},
184 {"pointer_default", tPOINTERDEFAULT},
190 {"size_is", tSIZEIS},
196 {"switch_is", tSWITCHIS},
197 {"switch_type", tSWITCHTYPE},
199 {"typedef", tTYPEDEF},
203 {"unsigned", tUNSIGNED},
206 {"v1_enum", tV1ENUM},
208 {"version", tVERSION},
211 {"wire_marshal", tWIREMARSHAL},
215 static int kw_token(const char *kw)
218 for (i=0; keywords[i].kw; i++)
219 if (strcmp(kw, keywords[i].kw) == 0)
220 return keywords[i].token;
221 yylval.str = xstrdup(kw);
222 return is_type(kw) ? aKNOWNTYPE : aIDENTIFIER;
225 static void addcchar(char c)
227 if(cbufidx >= cbufalloc)
230 cbuffer = xrealloc(cbuffer, cbufalloc * sizeof(cbuffer[0]));
231 if(cbufalloc > 65536)
232 yywarning("Reallocating string buffer larger than 64kB");
234 cbuffer[cbufidx++] = c;
237 static char *get_buffered_cstring(void)
240 return xstrdup(cbuffer);
243 static void pop_import(void)
245 int ptr = import_stack_ptr-1;
248 yy_delete_buffer( YY_CURRENT_BUFFER );
249 yy_switch_to_buffer( import_stack[ptr].state );
254 temp_name = import_stack[ptr].temp_name;
260 struct imports *next;
263 void do_import(char *fname)
267 struct imports *import;
268 int ptr = import_stack_ptr;
272 hname = dup_basename(fname, ".idl");
275 fprintf(header, "#include \"%s\"\n", hname);
279 import = first_import;
280 while (import && strcmp(import->name, fname))
281 import = import->next;
282 if (import) return; /* already imported */
284 import = xmalloc(sizeof(struct imports));
285 import->name = xstrdup(fname);
286 import->next = first_import;
287 first_import = import;
289 if (!(path = wpp_find_include( fname, 1 )))
290 yyerror("Unable to open include file %s", fname);
292 import_stack[ptr].temp_name = temp_name;
295 ret = wpp_parse_temp( path, &temp_name );
299 if((f = fopen(temp_name, "r")) == NULL)
300 yyerror("Unable to open %s", temp_name);
302 import_stack[ptr].state = YY_CURRENT_BUFFER;
303 yy_switch_to_buffer(yy_create_buffer(f, YY_BUF_SIZE));
306 void abort_import(void)
310 for (ptr=0; ptr<import_stack_ptr; ptr++)
311 unlink(import_stack[ptr].temp_name);