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 = strtoul(u, NULL, 16);
84 uuid->Data2 = strtoul(u+9, NULL, 16);
85 uuid->Data3 = strtoul(u+14, NULL, 16);
87 memcpy(b, u+19, 2); uuid->Data4[0] = strtoul(b, NULL, 16);
88 memcpy(b, u+21, 2); uuid->Data4[1] = strtoul(b, NULL, 16);
89 memcpy(b, u+24, 2); uuid->Data4[2] = strtoul(b, NULL, 16);
90 memcpy(b, u+26, 2); uuid->Data4[3] = strtoul(b, NULL, 16);
91 memcpy(b, u+28, 2); uuid->Data4[4] = strtoul(b, NULL, 16);
92 memcpy(b, u+30, 2); uuid->Data4[5] = strtoul(b, NULL, 16);
93 memcpy(b, u+32, 2); uuid->Data4[6] = strtoul(b, NULL, 16);
94 memcpy(b, u+34, 2); uuid->Data4[7] = strtoul(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);
122 yylval.num = strtol(yytext, NULL, 0);
126 yylval.num = strtol(yytext, NULL, 0);
129 {cident} return kw_token(yytext);
136 if (import_stack_ptr) {
151 static struct keyword {
158 {"__stdcall", tSTDCALL},
159 {"_stdcall", tSTDCALL},
160 {"aggregatable", tAGGREGATABLE},
161 {"allocate", tALLOCATE},
162 {"appobject", tAPPOBJECT},
165 {"async_uuid", tASYNCUUID},
166 {"auto_handle", tAUTOHANDLE},
167 {"bindable", tBINDABLE},
168 {"boolean", tBOOLEAN},
169 {"broadcast", tBROADCAST},
171 {"byte_count", tBYTECOUNT},
172 {"call_as", tCALLAS},
173 {"callback", tCALLBACK},
176 {"coclass", tCOCLASS},
178 {"comm_status", tCOMMSTATUS},
180 {"context_handle", tCONTEXTHANDLE},
181 {"context_handle_noserialize", tCONTEXTHANDLENOSERIALIZE},
182 {"context_handle_serialize", tCONTEXTHANDLENOSERIALIZE},
183 {"control", tCONTROL},
184 {"cpp_quote", tCPPQUOTE},
186 {"default", tDEFAULT},
191 {"error_status_t", tERRORSTATUST},
197 {"handle_t", tHANDLET},
201 {"idempotent", tIDEMPOTENT},
206 {"importlib", tIMPORTLIB},
208 {"include", tINCLUDE},
209 {"in_line", tINLINE},
212 {"interface", tINTERFACE},
214 {"length_is", tLENGTHIS},
221 {"oleautomation", tOLEAUTOMATION},
225 {"pointer_default", tPOINTERDEFAULT},
231 {"size_is", tSIZEIS},
237 {"switch_is", tSWITCHIS},
238 {"switch_type", tSWITCHTYPE},
240 {"typedef", tTYPEDEF},
244 {"unsigned", tUNSIGNED},
247 {"v1_enum", tV1ENUM},
249 {"version", tVERSION},
252 {"wire_marshal", tWIREMARSHAL}
254 #define NKEYWORDS (sizeof(keywords)/sizeof(keywords[0]))
255 #define KWP(p) ((struct keyword *)(p))
257 static int kw_cmp_func(const void *s1, const void *s2)
259 return strcmp(KWP(s1)->kw, KWP(s2)->kw);
263 static int kw_token(const char *kw)
265 struct keyword key, *kwp;
268 kwp = bsearch(&key, keywords, NKEYWORDS, sizeof(keywords[0]), kw_cmp_func);
272 for (kwp=NULL, i=0; i < NKEYWORDS; i++)
273 if (!kw_cmp_func(&key, &keywords[i])) {
280 yylval.str = (char*)kwp->kw;
283 yylval.str = xstrdup(kw);
284 return is_type(kw) ? aKNOWNTYPE : aIDENTIFIER;
287 static void addcchar(char c)
289 if(cbufidx >= cbufalloc)
292 cbuffer = xrealloc(cbuffer, cbufalloc * sizeof(cbuffer[0]));
293 if(cbufalloc > 65536)
294 yywarning("Reallocating string buffer larger than 64kB");
296 cbuffer[cbufidx++] = c;
299 static char *get_buffered_cstring(void)
302 return xstrdup(cbuffer);
305 static void pop_import(void)
307 int ptr = import_stack_ptr-1;
310 yy_delete_buffer( YY_CURRENT_BUFFER );
311 yy_switch_to_buffer( import_stack[ptr].state );
316 temp_name = import_stack[ptr].temp_name;
322 struct imports *next;
325 int do_import(char *fname)
329 struct imports *import;
330 int ptr = import_stack_ptr;
334 hname = dup_basename(fname, ".idl");
337 fprintf(header, "#include \"%s\"\n", hname);
341 import = first_import;
342 while (import && strcmp(import->name, fname))
343 import = import->next;
344 if (import) return 0; /* already imported */
346 import = xmalloc(sizeof(struct imports));
347 import->name = xstrdup(fname);
348 import->next = first_import;
349 first_import = import;
351 if (!(path = wpp_find_include( fname, 1 )))
352 yyerror("Unable to open include file %s", fname);
354 import_stack[ptr].temp_name = temp_name;
357 ret = wpp_parse_temp( path, NULL, &temp_name );
361 if((f = fopen(temp_name, "r")) == NULL)
362 yyerror("Unable to open %s", temp_name);
364 import_stack[ptr].state = YY_CURRENT_BUFFER;
365 yy_switch_to_buffer(yy_create_buffer(f, YY_BUF_SIZE));
369 void abort_import(void)
373 for (ptr=0; ptr<import_stack_ptr; ptr++)
374 unlink(import_stack[ptr].temp_name);