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}
50 #include "../wpp/wpp.h"
56 #define YY_NO_TOP_STATE
58 extern char *temp_name;
60 static void addcchar(char c);
61 static char *get_buffered_cstring(void);
65 static int cbufalloc = 0;
67 static int kw_token(const char *kw);
69 #define MAX_IMPORT_DEPTH 10
71 YY_BUFFER_STATE state;
73 } import_stack[MAX_IMPORT_DEPTH];
74 int import_stack_ptr = 0;
76 static void pop_import(void);
78 static UUID* parse_uuid(const char*u)
80 UUID* uuid = xmalloc(sizeof(UUID));
82 /* it would be nice to use UuidFromStringA */
83 uuid->Data1 = strtol(u, NULL, 16);
84 uuid->Data2 = strtol(u+9, NULL, 16);
85 uuid->Data3 = strtol(u+14, NULL, 16);
87 memcpy(b, u+19, 2); uuid->Data4[0] = strtol(b, NULL, 16);
88 memcpy(b, u+21, 2); uuid->Data4[1] = strtol(b, NULL, 16);
89 memcpy(b, u+24, 2); uuid->Data4[2] = strtol(b, NULL, 16);
90 memcpy(b, u+26, 2); uuid->Data4[3] = strtol(b, NULL, 16);
91 memcpy(b, u+28, 2); uuid->Data4[4] = strtol(b, NULL, 16);
92 memcpy(b, u+30, 2); uuid->Data4[5] = strtol(b, NULL, 16);
93 memcpy(b, u+32, 2); uuid->Data4[6] = strtol(b, NULL, 16);
94 memcpy(b, u+34, 2); uuid->Data4[7] = strtol(b, NULL, 16);
101 **************************************************************************
102 * The flexer starts here
103 **************************************************************************
107 \" yy_push_state(QUOTE); cbufidx = 0;
110 yylval.str = get_buffered_cstring();
114 <QUOTE>\\\" addcchar(yytext[1]);
115 <QUOTE>\\. addcchar('\\'); addcchar(yytext[1]);
116 <QUOTE>. addcchar(yytext[0]);
118 yylval.uuid = parse_uuid(yytext);
123 yylval.num = strtol(yytext, NULL, 0);
126 {cident} return kw_token(yytext);
133 if (import_stack_ptr) pop_import();
152 {"__stdcall", tSTDCALL},
153 {"_stdcall", tSTDCALL},
154 {"aggregatable", tAGGREGATABLE},
155 {"allocate", tALLOCATE},
156 {"appobject", tAPPOBJECT},
159 {"async_uuid", tASYNCUUID},
160 {"auto_handle", tAUTOHANDLE},
161 {"bindable", tBINDABLE},
162 {"boolean", tBOOLEAN},
163 {"broadcast", tBROADCAST},
165 {"byte_count", tBYTECOUNT},
166 {"call_as", tCALLAS},
167 {"callback", tCALLBACK},
170 {"coclass", tCOCLASS},
172 {"comm_status", tCOMMSTATUS},
174 {"context_handle", tCONTEXTHANDLE},
175 {"context_handle_noserialize", tCONTEXTHANDLENOSERIALIZE},
176 {"context_handle_serialize", tCONTEXTHANDLENOSERIALIZE},
177 {"control", tCONTROL},
178 {"cpp_quote", tCPPQUOTE},
180 {"default", tDEFAULT},
195 {"importlib", tIMPORTLIB},
197 {"include", tINCLUDE},
198 {"in_line", tINLINE},
201 {"interface", tINTERFACE},
203 {"length_is", tLENGTHIS},
210 {"oleautomation", tOLEAUTOMATION},
214 {"pointer_default", tPOINTERDEFAULT},
220 {"size_is", tSIZEIS},
226 {"switch_is", tSWITCHIS},
227 {"switch_type", tSWITCHTYPE},
229 {"typedef", tTYPEDEF},
233 {"unsigned", tUNSIGNED},
236 {"v1_enum", tV1ENUM},
238 {"version", tVERSION},
241 {"wire_marshal", tWIREMARSHAL},
245 static int kw_token(const char *kw)
248 for (i=0; keywords[i].kw; i++)
249 if (strcmp(kw, keywords[i].kw) == 0)
250 return keywords[i].token;
251 yylval.str = xstrdup(kw);
252 return is_type(kw) ? aKNOWNTYPE : aIDENTIFIER;
255 static void addcchar(char c)
257 if(cbufidx >= cbufalloc)
260 cbuffer = xrealloc(cbuffer, cbufalloc * sizeof(cbuffer[0]));
261 if(cbufalloc > 65536)
262 yywarning("Reallocating string buffer larger than 64kB");
264 cbuffer[cbufidx++] = c;
267 static char *get_buffered_cstring(void)
270 return xstrdup(cbuffer);
273 static void pop_import(void)
275 int ptr = import_stack_ptr-1;
278 yy_delete_buffer( YY_CURRENT_BUFFER );
279 yy_switch_to_buffer( import_stack[ptr].state );
284 temp_name = import_stack[ptr].temp_name;
290 struct imports *next;
293 void do_import(char *fname)
297 struct imports *import;
298 int ptr = import_stack_ptr;
302 hname = dup_basename(fname, ".idl");
305 fprintf(header, "#include \"%s\"\n", hname);
309 import = first_import;
310 while (import && strcmp(import->name, fname))
311 import = import->next;
312 if (import) return; /* already imported */
314 import = xmalloc(sizeof(struct imports));
315 import->name = xstrdup(fname);
316 import->next = first_import;
317 first_import = import;
319 if (!(path = wpp_find_include( fname, 1 )))
320 yyerror("Unable to open include file %s", fname);
322 import_stack[ptr].temp_name = temp_name;
325 ret = wpp_parse_temp( path, NULL, &temp_name );
329 if((f = fopen(temp_name, "r")) == NULL)
330 yyerror("Unable to open %s", temp_name);
332 import_stack[ptr].state = YY_CURRENT_BUFFER;
333 yy_switch_to_buffer(yy_create_buffer(f, YY_BUF_SIZE));
336 void abort_import(void)
340 for (ptr=0; ptr<import_stack_ptr; ptr++)
341 unlink(import_stack[ptr].temp_name);