ReactOS 0.4.16-dev-1946-g52006dd
widl.c
Go to the documentation of this file.
1/*
2 * IDL Compiler
3 *
4 * Copyright 2002 Ove Kaaven
5 * based on WRC code by Bertho Stultiens
6 *
7 * This library is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Lesser General Public
9 * License as published by the Free Software Foundation; either
10 * version 2.1 of the License, or (at your option) any later version.
11 *
12 * This library is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Lesser General Public License for more details.
16 *
17 * You should have received a copy of the GNU Lesser General Public
18 * License along with this library; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
20 */
21
22#include "config.h"
23
24#include <errno.h>
25#include <limits.h>
26#include <stdio.h>
27#include <stdlib.h>
28#include <string.h>
29#include <assert.h>
30#include <ctype.h>
31#include <limits.h>
32#include <sys/types.h>
33
34#include "widl.h"
35#include "utils.h"
36#include "parser.h"
37#include "wpp_private.h"
38#include "header.h"
39
40static const char usage[] =
41"Usage: widl [options...] infile.idl\n"
42" or: widl [options...] --dlldata-only name1 [name2...]\n"
43" --acf=file Use ACF file\n"
44" --align=n Set structure packing to 'n'\n"
45" -app_config Ignored, present for midl compatibility\n"
46" -b arch Set the target architecture\n"
47" -c Generate client stub\n"
48" -d n Set debug level to 'n'\n"
49" -D id[=val] Define preprocessor identifier id=val\n"
50" -E Preprocess only\n"
51" --help Display this help and exit\n"
52" -h Generate headers\n"
53" -H file Name of header file (default is infile.h)\n"
54" -I directory Add directory to the include search path (multiple -I allowed)\n"
55" -L directory Add directory to the library search path (multiple -L allowed)\n"
56" --local-stubs=file Write empty stubs for call_as/local methods to file\n"
57" -m32, -m64 Set the target architecture (Win32 or Win64)\n"
58" -N Do not preprocess input\n"
59" --nostdinc Do not search the standard include path\n"
60" --ns_prefix Prefix namespaces with ABI namespace\n"
61" --oldnames Use old naming conventions\n"
62" --oldtlb Generate typelib in the old format (SLTG)\n"
63" -o, --output=NAME Set the output file name\n"
64" -Otype Type of stubs to generate (-Os, -Oi, -Oif)\n"
65" -p Generate proxy\n"
66" --packing=n Set structure packing to 'n'\n"
67" --prefix-all=p Prefix names of client stubs / server functions with 'p'\n"
68" --prefix-client=p Prefix names of client stubs with 'p'\n"
69" --prefix-server=p Prefix names of server functions with 'p'\n"
70" -r Generate registration script\n"
71" -robust Ignored, present for midl compatibility\n"
72" --sysroot=DIR Prefix include paths with DIR\n"
73" -s Generate server stub\n"
74" -t Generate typelib\n"
75" -u Generate interface identifiers file\n"
76" -V Print version and exit\n"
77" -W Enable pedantic warnings\n"
78" --win32, --win64 Set the target architecture (Win32 or Win64)\n"
79" --winrt Enable Windows Runtime mode\n"
80"Debug level 'n' is a bitmask with following meaning:\n"
81" * 0x01 Tell which resource is parsed (verbose mode)\n"
82" * 0x02 Dump internal structures\n"
83" * 0x04 Create a parser trace (yydebug=1)\n"
84" * 0x08 Preprocessor messages\n"
85" * 0x10 Preprocessor lex messages\n"
86" * 0x20 Preprocessor yacc trace\n"
87;
88
89static const char version_string[] = "Wine IDL Compiler version " PACKAGE_VERSION "\n"
90 "Copyright 2002 Ove Kaaven\n";
91
92struct target target = { 0 };
93
96
97int pedantic = 0;
99static int preprocess_only = 0;
100int do_header = 0;
103int do_client = 0;
104int do_server = 0;
106int do_idfile = 0;
108static int no_preprocess = 0;
109int old_names = 0;
114static int stdinc = 1;
115
132static char *idfile_name;
133struct strarray temp_files = { 0 };
134const char *temp_dir = NULL;
135const char *prefix_client = "";
136const char *prefix_server = "";
137static const char *bindir;
138static const char *libdir;
139static const char *includedir;
140static struct strarray dlldirs;
141static char *output_name;
142static const char *sysroot = "";
143
144static FILE *idfile;
145
146unsigned int packing = 8;
147unsigned int pointer_size = 0;
148
150
151enum {
171};
172
173static const char short_options[] =
174 "b:cC:d:D:EhH:I:L:m:No:O:pP:rsS:tT:uU:VW";
175static const struct long_option long_options[] = {
176 { "acf", 1, ACF_OPTION },
177 { "align", 1, PACKING_OPTION },
178 { "app_config", 0, APP_CONFIG_OPTION },
179 { "dlldata", 1, DLLDATA_OPTION },
180 { "dlldata-only", 0, DLLDATA_ONLY_OPTION },
181 { "help", 0, PRINT_HELP },
182 { "local-stubs", 1, LOCAL_STUBS_OPTION },
183 { "nostdinc", 0, NOSTDINC_OPTION },
184 { "ns_prefix", 0, RT_NS_PREFIX },
185 { "oldnames", 0, OLDNAMES_OPTION },
186 { "oldtlb", 0, OLD_TYPELIB_OPTION },
187 { "output", 0, 'o' },
188 { "packing", 1, PACKING_OPTION },
189 { "prefix-all", 1, PREFIX_ALL_OPTION },
190 { "prefix-client", 1, PREFIX_CLIENT_OPTION },
191 { "prefix-server", 1, PREFIX_SERVER_OPTION },
192 { "robust", 0, ROBUST_OPTION },
193 { "sysroot", 1, SYSROOT_OPTION },
194 { "target", 0, 'b' },
195 { "winrt", 0, RT_OPTION },
196 { "win32", 0, WIN32_OPTION },
197 { "win64", 0, WIN64_OPTION },
198 { NULL }
199};
200
201static void rm_tempfile(void);
202
203static char *make_token(const char *name)
204{
205 char *token;
206 int i;
207
209 for (i=0; token[i]; i++) {
210 if (!isalnum(token[i])) token[i] = '_';
211 else token[i] = tolower(token[i]);
212 }
213 return token;
214}
215
216/* duplicate a basename into a valid C token */
217static char *dup_basename_token(const char *name, const char *ext)
218{
219 char *p, *ret = replace_extension( get_basename(name), ext, "" );
220 /* map invalid characters to '_' */
221 for (p = ret; *p; p++) if (!isalnum(*p)) *p = '_';
222 return ret;
223}
224
225static void add_widl_version_define(void)
226{
227 char version_str[32];
228 unsigned int version;
229 const char *p = PACKAGE_VERSION;
230
231 /* major */
232 version = atoi(p) * 0x10000;
233 p = strchr(p, '.');
234
235 /* minor */
236 if (p)
237 {
238 version += atoi(p + 1) * 0x100;
239 p = strchr(p + 1, '.');
240 }
241
242 /* build */
243 if (p)
244 version += atoi(p + 1);
245
246 snprintf(version_str, sizeof(version_str), "__WIDL__=0x%x", version);
247 wpp_add_cmdline_define(version_str);
248}
249
250/* clean things up when aborting on a signal */
251static void exit_on_signal( int sig )
252{
253 exit(1); /* this will call the atexit functions */
254}
255
256static void set_everything(int x)
257{
258 do_header = x;
259 do_typelib = x;
260 do_proxies = x;
261 do_client = x;
262 do_server = x;
263 do_regscript = x;
264 do_idfile = x;
265 do_dlldata = x;
266}
267
269{
270 fprintf(fp, "#ifdef __cplusplus\n");
271 fprintf(fp, "extern \"C\" {\n");
272 fprintf(fp, "#endif\n\n");
273}
274
276{
277 fprintf(fp, "#ifdef __cplusplus\n");
278 fprintf(fp, "}\n");
279 fprintf(fp, "#endif\n\n");
280}
281
282static void write_dlldata_list( struct strarray filenames, int define_proxy_delegation)
283{
284 FILE *dlldata;
285 unsigned int i;
286
287 dlldata = fopen(dlldata_name, "w");
288 if (!dlldata)
289 error("couldn't open %s: %s\n", dlldata_name, strerror(errno));
290
291 fprintf(dlldata, "/*** Autogenerated by WIDL %s ", PACKAGE_VERSION);
292 fprintf(dlldata, "- Do not edit ***/\n\n");
293 if (define_proxy_delegation)
294 fprintf(dlldata, "#define PROXY_DELEGATION\n");
295
296#ifdef __REACTOS__
297 fprintf(dlldata, "#ifdef __REACTOS__\n");
298 fprintf(dlldata, "#define WIN32_NO_STATUS\n");
299 fprintf(dlldata, "#define WIN32_LEAN_AND_MEAN\n");
300 fprintf(dlldata, "#endif\n\n");
301#endif
302
303 fprintf(dlldata, "#include <objbase.h>\n");
304 fprintf(dlldata, "#include <rpcproxy.h>\n\n");
305 start_cplusplus_guard(dlldata);
306
307 for (i = 0; i < filenames.count; i++)
308 fprintf(dlldata, "EXTERN_PROXY_FILE(%s)\n", filenames.str[i]);
309
310 fprintf(dlldata, "\nPROXYFILE_LIST_START\n");
311 fprintf(dlldata, "/* Start of list */\n");
312 for (i = 0; i < filenames.count; i++)
313 fprintf(dlldata, " REFERENCE_PROXY_FILE(%s),\n", filenames.str[i]);
314 fprintf(dlldata, "/* End of list */\n");
315 fprintf(dlldata, "PROXYFILE_LIST_END\n\n");
316
317 fprintf(dlldata, "DLLDATA_ROUTINES(aProxyFileList, GET_DLL_CLSID)\n\n");
318 end_cplusplus_guard(dlldata);
319 fclose(dlldata);
320}
321
322static char *eat_space(char *s)
323{
324 while (isspace((unsigned char) *s))
325 ++s;
326 return s;
327}
328
330{
331 struct strarray filenames = empty_strarray;
332 int define_proxy_delegation = 0;
333 FILE *dlldata;
334
335 if (!do_dlldata || !need_proxy_file(stmts))
336 return;
337
338 define_proxy_delegation = need_proxy_delegation(stmts);
339
340 dlldata = fopen(dlldata_name, "r");
341 if (dlldata) {
342 static const char marker[] = "REFERENCE_PROXY_FILE";
343 static const char delegation_define[] = "#define PROXY_DELEGATION";
344 char *line = NULL;
345 size_t len = 0;
346
347 while (widl_getline(&line, &len, dlldata)) {
348 char *start, *end;
350 if (strncmp(start, marker, sizeof marker - 1) == 0) {
351 start = eat_space(start + sizeof marker - 1);
352 if (*start != '(')
353 continue;
354 end = start = eat_space(start + 1);
355 while (*end && *end != ')')
356 ++end;
357 if (*end != ')')
358 continue;
359 while (isspace((unsigned char) end[-1]))
360 --end;
361 *end = '\0';
362 if (start < end)
363 strarray_add(&filenames, replace_extension( get_basename( start ), ".idl", "" ));
364 }else if (!define_proxy_delegation && strncmp(start, delegation_define, sizeof(delegation_define)-1)) {
365 define_proxy_delegation = 1;
366 }
367 }
368
369 if (ferror(dlldata))
370 error("couldn't read from %s: %s\n", dlldata_name, strerror(errno));
371
372 free(line);
373 fclose(dlldata);
374 }
375
376 if (strarray_exists( &filenames, proxy_token ))
377 /* We're already in the list, no need to regenerate this file. */
378 return;
379
380 strarray_add(&filenames, proxy_token);
381 write_dlldata_list(filenames, define_proxy_delegation);
382}
383
384static void write_id_guid(FILE *f, const char *type, const char *guid_prefix, const char *name, const struct uuid *uuid)
385{
386 if (!uuid) return;
387 fprintf(f, "MIDL_DEFINE_GUID(%s, %s_%s, 0x%08x, 0x%04x, 0x%04x, 0x%02x,0x%02x, 0x%02x,"
388 "0x%02x,0x%02x,0x%02x,0x%02x,0x%02x);\n",
389 type, guid_prefix, name, uuid->Data1, uuid->Data2, uuid->Data3, uuid->Data4[0],
390 uuid->Data4[1], uuid->Data4[2], uuid->Data4[3], uuid->Data4[4], uuid->Data4[5],
391 uuid->Data4[6], uuid->Data4[7]);
392}
393
394static void write_id_data_stmts(const statement_list_t *stmts)
395{
396 const statement_t *stmt;
397 if (stmts) LIST_FOR_EACH_ENTRY( stmt, stmts, const statement_t, entry )
398 {
399 if (stmt->type == STMT_TYPE)
400 {
401 const type_t *type = stmt->u.type;
403 {
404 const struct uuid *uuid;
405 if (!is_object(type) && !is_attr(type->attrs, ATTR_DISPINTERFACE))
406 continue;
407 uuid = get_attrp(type->attrs, ATTR_UUID);
408 write_id_guid(idfile, "IID", is_attr(type->attrs, ATTR_DISPINTERFACE) ? "DIID" : "IID",
409 type->name, uuid);
411 {
414 }
415 }
416 else if (type_get_type(type) == TYPE_COCLASS)
417 {
418 const struct uuid *uuid = get_attrp(type->attrs, ATTR_UUID);
419 write_id_guid(idfile, "CLSID", "CLSID", type->name, uuid);
420 }
421 }
422 else if (stmt->type == STMT_LIBRARY)
423 {
424 const struct uuid *uuid = get_attrp(stmt->u.lib->attrs, ATTR_UUID);
425 write_id_guid(idfile, "IID", "LIBID", stmt->u.lib->name, uuid);
427 }
428 }
429}
430
432{
433 if (!do_idfile) return;
434
435 idfile = fopen(idfile_name, "w");
436 if (! idfile) {
437 error("Could not open %s for output\n", idfile_name);
438 return;
439 }
440
441 fprintf(idfile, "/*** Autogenerated by WIDL %s ", PACKAGE_VERSION);
442 fprintf(idfile, "from %s - Do not edit ***/\n\n", idl_name);
443#ifdef __REACTOS__
444 fprintf(idfile, "#ifdef __REACTOS__\n");
445 fprintf(idfile, "#define WIN32_NO_STATUS\n");
446 fprintf(idfile, "#define WIN32_LEAN_AND_MEAN\n");
447 fprintf(idfile, "#endif\n\n");
448#endif
449 fprintf(idfile, "#include <rpc.h>\n");
450 fprintf(idfile, "#include <rpcndr.h>\n\n");
451
452 fprintf(idfile, "#ifdef _MIDL_USE_GUIDDEF_\n\n");
453
454 fprintf(idfile, "#ifndef INITGUID\n");
455 fprintf(idfile, "#define INITGUID\n");
456 fprintf(idfile, "#include <guiddef.h>\n");
457 fprintf(idfile, "#undef INITGUID\n");
458 fprintf(idfile, "#else\n");
459 fprintf(idfile, "#include <guiddef.h>\n");
460 fprintf(idfile, "#endif\n\n");
461
462 fprintf(idfile, "#define MIDL_DEFINE_GUID(type,name,l,w1,w2,b1,b2,b3,b4,b5,b6,b7,b8) \\\n");
463 fprintf(idfile, " DEFINE_GUID(name,l,w1,w2,b1,b2,b3,b4,b5,b6,b7,b8)\n\n");
464
465 fprintf(idfile, "#elif defined(__cplusplus)\n\n");
466
467 fprintf(idfile, "#define MIDL_DEFINE_GUID(type,name,l,w1,w2,b1,b2,b3,b4,b5,b6,b7,b8) \\\n");
468 fprintf(idfile, " EXTERN_C const type DECLSPEC_SELECTANY name = {l,w1,w2,{b1,b2,b3,b4,b5,b6,b7,b8}}\n\n");
469
470 fprintf(idfile, "#else\n\n");
471
472 fprintf(idfile, "#define MIDL_DEFINE_GUID(type,name,l,w1,w2,b1,b2,b3,b4,b5,b6,b7,b8) \\\n");
473 fprintf(idfile, " const type DECLSPEC_SELECTANY name = {l,w1,w2,{b1,b2,b3,b4,b5,b6,b7,b8}}\n\n");
474
475 fprintf(idfile, "#endif\n\n");
477
478 write_id_data_stmts(stmts);
479
480 fprintf(idfile, "\n");
482 fprintf(idfile, "#undef MIDL_DEFINE_GUID\n" );
483
484 fclose(idfile);
485}
486
487static void option_callback( int optc, char *optarg )
488{
489 switch (optc)
490 {
491 case DLLDATA_OPTION:
493 break;
495 do_everything = 0;
496 do_dlldata = 1;
497 break;
499 do_everything = 0;
501 break;
502 case NOSTDINC_OPTION:
503 stdinc = 0;
504 break;
505 case OLDNAMES_OPTION:
506 old_names = 1;
507 break;
511 break;
514 break;
517 break;
518 case PRINT_HELP:
519 fprintf(stderr, "%s", usage);
520 exit(0);
521 case RT_OPTION:
522 winrt_mode = 1;
523 break;
524 case RT_NS_PREFIX:
526 break;
527 case SYSROOT_OPTION:
529 break;
530 case WIN32_OPTION:
531 pointer_size = 4;
532 break;
533 case WIN64_OPTION:
534 pointer_size = 8;
535 break;
536 case PACKING_OPTION:
537 packing = strtol(optarg, NULL, 0);
538 if(packing != 2 && packing != 4 && packing != 8)
539 error("Structure packing must be one of 2, 4 or 8\n");
540 break;
541 case ACF_OPTION:
543 break;
545 /* widl does not distinguish between app_mode and default mode,
546 but we ignore this option for midl compatibility */
547 break;
548 case ROBUST_OPTION:
549 /* FIXME: Support robust option */
550 break;
551 case 'b':
552 if (!parse_target( optarg, &target ))
553 error( "Invalid target specification '%s'\n", optarg );
554 break;
555 case 'c':
556 do_everything = 0;
557 do_client = 1;
558 break;
559 case 'C':
561 break;
562 case 'd':
564 break;
565 case 'D':
567 break;
568 case 'E':
569 do_everything = 0;
570 preprocess_only = 1;
571 break;
572 case 'h':
573 do_everything = 0;
574 do_header = 1;
575 break;
576 case 'H':
578 break;
579 case 'I':
581 break;
582 case 'L':
584 break;
585 case 'm':
586 if (!strcmp( optarg, "32" )) pointer_size = 4;
587 else if (!strcmp( optarg, "64" )) pointer_size = 8;
588 break;
589 case 'N':
590 no_preprocess = 1;
591 break;
592 case 'o':
594 break;
595 case 'O':
596 if (!strcmp( optarg, "s" )) interpreted_mode = 0;
597 else if (!strcmp( optarg, "i" )) interpreted_mode = 1;
598 else if (!strcmp( optarg, "ic" )) interpreted_mode = 1;
599 else if (!strcmp( optarg, "if" )) interpreted_mode = 1;
600 else if (!strcmp( optarg, "icf" )) interpreted_mode = 1;
601 else error( "Invalid argument '-O%s'\n", optarg );
602 break;
603 case 'p':
604 do_everything = 0;
605 do_proxies = 1;
606 break;
607 case 'P':
609 break;
610 case 'r':
611 do_everything = 0;
612 do_regscript = 1;
613 break;
614 case 's':
615 do_everything = 0;
616 do_server = 1;
617 break;
618 case 'S':
620 break;
621 case 't':
622 do_everything = 0;
623 do_typelib = 1;
624 break;
626 old_typelib = 1;
627 break;
628 case 'T':
630 break;
631 case 'u':
632 do_everything = 0;
633 do_idfile = 1;
634 break;
635 case 'U':
637 break;
638 case 'V':
639 printf("%s", version_string);
640 exit(0);
641 case 'W':
642 pedantic = 1;
643 break;
644 case '?':
645 fprintf(stderr, "widl: %s\n\n%s", optarg, usage);
646 exit(1);
647 }
648}
649
650int open_typelib( const char *name )
651{
652#ifndef __REACTOS__
653 static const char *default_dirs[] = { LIBDIR "/wine", "/usr/lib/wine", "/usr/local/lib/wine" };
654#endif
655 struct target win_target = { target.cpu, PLATFORM_WINDOWS };
656 const char *pe_dir = get_arch_dir( win_target );
657 int fd;
658 unsigned int i;
659
660#define TRYOPEN(str) do { \
661 char *file = str; \
662 if ((fd = open( file, O_RDONLY | O_BINARY )) != -1) return fd; \
663 free( file ); } while(0)
664
665 for (i = 0; i < dlldirs.count; i++)
666 {
667 if (strendswith( dlldirs.str[i], "/*" )) /* special case for wine build tree */
668 {
669 int namelen = strlen( name );
670 if (strendswith( name, ".dll" )) namelen -= 4;
671 TRYOPEN( strmake( "%.*s/%.*s%s/%s", (int)strlen(dlldirs.str[i]) - 2, dlldirs.str[i],
672 namelen, name, pe_dir, name ));
673 }
674 else
675 {
676 TRYOPEN( strmake( "%s%s/%s", dlldirs.str[i], pe_dir, name ));
677 TRYOPEN( strmake( "%s/%s", dlldirs.str[i], name ));
678 }
679 }
680
681#ifndef __REACTOS__
682 if (stdinc)
683 {
684 if (libdir)
685 {
686 TRYOPEN( strmake( "%s/wine%s/%s", libdir, pe_dir, name ));
687 TRYOPEN( strmake( "%s/wine/%s", libdir, name ));
688 }
689 for (i = 0; i < ARRAY_SIZE(default_dirs); i++)
690 {
691 if (i && !strcmp( default_dirs[i], default_dirs[0] )) continue;
692 TRYOPEN( strmake( "%s%s/%s", default_dirs[i], pe_dir, name ));
693 }
694 }
695#endif
696
697 error( "cannot find %s\n", name );
698#undef TRYOPEN
699
700#ifdef __REACTOS__
701 return 1;
702#endif
703}
704
705int main(int argc,char *argv[])
706{
707 int i;
708 int ret = 0;
709 struct strarray files;
710
712 bindir = get_bindir( argv[0] );
713 libdir = get_libdir( bindir );
714 includedir = get_includedir( bindir );
716
717 now = time(NULL);
718
720
721#ifndef __REACTOS__
722 if (stdinc)
723 {
724 static const char *incl_dirs[] = { INCLUDEDIR, "/usr/include", "/usr/local/include" };
725
726 if (includedir)
727 {
728 wpp_add_include_path( strmake( "%s/wine/msvcrt", includedir ));
729 wpp_add_include_path( strmake( "%s/wine/windows", includedir ));
730 }
731 for (i = 0; i < ARRAY_SIZE(incl_dirs); i++)
732 {
733 if (i && !strcmp( incl_dirs[i], incl_dirs[0] )) continue;
734 wpp_add_include_path( strmake( "%s%s/wine/msvcrt", sysroot, incl_dirs[i] ));
735 wpp_add_include_path( strmake( "%s%s/wine/windows", sysroot, incl_dirs[i] ));
736 }
737 }
738#endif
739
740 if (pointer_size)
742 else
744
745 /* if nothing specified, try to guess output type from the output file name */
748 {
749 do_everything = 0;
750 if (strendswith( output_name, ".h" )) do_header = 1;
751 else if (strendswith( output_name, ".tlb" )) do_typelib = 1;
752 else if (strendswith( output_name, "_p.c" )) do_proxies = 1;
753 else if (strendswith( output_name, "_c.c" )) do_client = 1;
754 else if (strendswith( output_name, "_s.c" )) do_server = 1;
755 else if (strendswith( output_name, "_i.c" )) do_idfile = 1;
756 else if (strendswith( output_name, "_r.res" )) do_regscript = 1;
757 else if (strendswith( output_name, "_t.res" )) do_typelib = 1;
758 else if (strendswith( output_name, "_l.res" )) do_typelib = 1;
759 else if (strendswith( output_name, "dlldata.c" )) do_dlldata = 1;
760 else do_everything = 1;
761 }
762
763 if(do_everything) {
765 }
766
769 {
778 }
779
780 if (!dlldata_name && do_dlldata)
781 dlldata_name = xstrdup("dlldata.c");
782
783 if (files.count) {
784 if (do_dlldata && !do_everything) {
785 struct strarray filenames = empty_strarray;
786 for (i = 0; i < files.count; i++)
787 strarray_add(&filenames, replace_extension( get_basename( files.str[i] ), ".idl", "" ));
788
789 write_dlldata_list(filenames, 0 /* FIXME */ );
790 return 0;
791 }
792 else if (files.count > 1) {
793 fprintf(stderr, "%s", usage);
794 return 1;
795 }
796 else
797 {
798 input_name = xstrdup( files.str[0] );
800 }
801 }
802 else {
803 fprintf(stderr, "%s", usage);
804 return 1;
805 }
806
807 if(debuglevel)
808 {
811 }
812
815
818 (debuglevel & DEBUGLEVEL_PPMSG) != 0 );
819
820 if (!header_name)
822
823 if (!typelib_name && do_typelib)
825
826 if (!proxy_name && do_proxies)
828
829 if (!client_name && do_client)
831
832 if (!server_name && do_server)
834
837
838 if (!idfile_name && do_idfile)
840
845
847 wpp_add_cmdline_define("_WIN32=1");
848
852
854
855 init_types();
856 ret = parser_parse();
858 if (ret) exit(1);
859
860 /* Everything has been done successfully, don't delete any files. */
863
864 return 0;
865}
866
867static void rm_tempfile(void)
868{
869 if (do_header)
873 if (do_client)
875 if (do_server)
877 if (do_regscript)
879 if (do_idfile)
881 if (do_proxies)
883 if (do_typelib)
886}
887
888char *find_input_file( const char *name, const char *parent )
889{
890 char *path;
891
892 /* don't search for a file name with a path in the include directories, for compatibility with MIDL */
893 if (strchr( name, '/' ) || strchr( name, '\\' )) path = xstrdup( name );
894 else if (!(path = wpp_find_include( name, parent ))) error_loc( "Unable to open include file %s\n", name );
895
896 return path;
897}
898
899FILE *open_input_file( const char *path )
900{
901 FILE *file;
902 char *name;
903 int ret;
904
905 if (no_preprocess)
906 {
907 if (!(file = fopen( path, "r" ))) error_loc( "Unable to open %s\n", path );
908 return file;
909 }
910
911 name = make_temp_file( "widl", NULL );
912 if (!(file = fopen( name, "wt" ))) error_loc( "Could not open %s for writing\n", name );
913 ret = wpp_parse( path, file );
914 fclose( file );
915 if (ret) exit( 1 );
916
917 if (!(file = fopen( name, "r" ))) error_loc( "Unable to open %s\n", name );
918 return file;
919}
static int argc
Definition: ServiceArgs.c:12
#define isspace(c)
Definition: acclib.h:69
int strcmp(const char *String1, const char *String2)
Definition: utclib.c:469
ACPI_SIZE strlen(const char *String)
Definition: utclib.c:269
int strncmp(const char *String1, const char *String2, ACPI_SIZE Count)
Definition: utclib.c:534
int tolower(int c)
Definition: utclib.c:902
char * strchr(const char *String, int ch)
Definition: utclib.c:501
char * xstrdup(const char *s)
Definition: uimain.c:768
const char * optarg
Definition: getopt.c:49
#define ARRAY_SIZE(A)
Definition: main.h:20
void parse_options(struct packet *)
Definition: options.c:59
Definition: list.h:37
int wpp_parse(const char *input, FILE *output)
Definition: compiler.c:437
#define LIBDIR
Definition: create_nls.c:23
#define free
Definition: debug_ros.c:5
#define NULL
Definition: types.h:112
#define TRUE
Definition: types.h:120
#define FALSE
Definition: types.h:117
static const WCHAR *const ext[]
Definition: module.c:53
static const WCHAR version[]
Definition: asmname.c:66
int __cdecl atexit(void(__cdecl *function)(void))
Definition: stubs.c:10
return ret
Definition: mutex.c:146
r parent
Definition: btrfs.c:3010
int main()
Definition: test.c:6
__kernel_time_t time_t
Definition: linux.h:252
#define printf
Definition: freeldr.h:97
GLuint start
Definition: gl.h:1545
GLint GLint GLint GLint GLint x
Definition: gl.h:1548
GLuint GLuint GLsizei GLenum type
Definition: gl.h:1545
GLdouble s
Definition: gl.h:2039
GLuint GLuint end
Definition: gl.h:1545
GLint namelen
Definition: glext.h:7232
GLfloat f
Definition: glext.h:7540
GLfloat GLfloat p
Definition: glext.h:8902
GLenum GLsizei len
Definition: glext.h:6722
GLsizeiptr const GLvoid GLenum usage
Definition: glext.h:5919
GLsizei GLenum const GLvoid GLsizei GLenum GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLint GLint GLint GLshort GLshort GLshort GLubyte GLubyte GLubyte GLuint GLuint GLuint GLushort GLushort GLushort GLbyte GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLfloat GLint GLint GLint GLint GLshort GLshort GLshort GLshort GLubyte GLubyte GLubyte GLubyte GLuint GLuint GLuint GLuint GLushort GLushort GLushort GLushort GLboolean const GLdouble const GLfloat const GLint const GLshort const GLbyte const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLdouble const GLfloat const GLfloat const GLint const GLint const GLshort const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort GLenum GLenum GLenum GLfloat GLenum GLint GLenum GLenum GLenum GLfloat GLenum GLenum GLint GLenum GLfloat GLenum GLint GLint GLushort GLenum GLenum GLfloat GLenum GLenum GLint GLfloat const GLubyte GLenum GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLint GLint GLsizei GLsizei GLint GLenum GLenum const GLvoid GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLenum const GLdouble GLenum GLenum const GLfloat GLenum GLenum const GLint GLsizei GLuint GLfloat GLuint GLbitfield GLfloat GLint GLuint GLboolean GLenum GLfloat GLenum GLbitfield GLenum GLfloat GLfloat GLint GLint const GLfloat GLenum GLfloat GLfloat GLint GLint GLfloat GLfloat GLint GLint const GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat const GLdouble const GLfloat const GLdouble const GLfloat GLint i
Definition: glfuncs.h:248
GLsizei GLenum const GLvoid GLsizei GLenum GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLint GLint GLint GLshort GLshort GLshort GLubyte GLubyte GLubyte GLuint GLuint GLuint GLushort GLushort GLushort GLbyte GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLfloat GLint GLint GLint GLint GLshort GLshort GLshort GLshort GLubyte GLubyte GLubyte GLubyte GLuint GLuint GLuint GLuint GLushort GLushort GLushort GLushort GLboolean const GLdouble const GLfloat const GLint const GLshort const GLbyte const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLdouble const GLfloat const GLfloat const GLint const GLint const GLshort const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort GLenum GLenum GLenum GLfloat GLenum GLint GLenum GLenum GLenum GLfloat GLenum GLenum GLint GLenum GLfloat GLenum GLint GLint GLushort GLenum GLenum GLfloat GLenum GLenum GLint GLfloat const GLubyte GLenum GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLint GLint GLsizei GLsizei GLint GLenum GLenum const GLvoid GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLenum const GLdouble GLenum GLenum const GLfloat GLenum GLenum const GLint GLsizei GLuint GLfloat token
Definition: glfuncs.h:210
_Check_return_ _CRTIMP int __cdecl isalnum(_In_ int _C)
#define stdout
Definition: stdio.h:99
_Check_return_ _CRTIMP int __cdecl ferror(_In_ FILE *_File)
#define stderr
Definition: stdio.h:100
_Check_return_opt_ _CRTIMP int __cdecl fprintf(_Inout_ FILE *_File, _In_z_ _Printf_format_string_ const char *_Format,...)
_Check_return_ _CRTIMP FILE *__cdecl fopen(_In_z_ const char *_Filename, _In_z_ const char *_Mode)
_Check_return_opt_ _CRTIMP int __cdecl fclose(_Inout_ FILE *_File)
_CRTIMP void __cdecl setbuf(_Inout_ FILE *_File, _Inout_updates_opt_(BUFSIZ) _Post_readable_size_(0) char *_Buffer)
#define CHAR_MAX
Definition: limits.h:32
Definition: msctf.idl:532
unsigned short Data3
Definition: widltypes.h:34
unsigned int Data1
Definition: widltypes.h:32
unsigned char Data4[8]
Definition: widltypes.h:35
unsigned short Data2
Definition: widltypes.h:33
uint32_t entry
Definition: isohybrid.c:63
int marker
Definition: jpeglib.h:1030
#define unlink
Definition: syshdrs.h:54
__u16 time
Definition: mkdosfs.c:8
#define error(str)
Definition: mkdosfs.c:1605
#define PACKAGE_VERSION
Definition: config.h:835
const char * strerror(int err)
Definition: compat_str.c:23
char * strmake(size_t *lenp,...)
Definition: util.c:82
#define argv
Definition: mplay32.c:18
#define errno
Definition: errno.h:18
_Check_return_ int __cdecl atoi(_In_z_ const char *_Str)
_Check_return_ long __cdecl strtol(_In_z_ const char *_Str, _Out_opt_ _Deref_post_z_ char **_EndPtr, _In_ int _Radix)
#define LIST_FOR_EACH_ENTRY(elem, list, type, field)
Definition: list.h:198
#define exit(n)
Definition: config.h:202
static int fd
Definition: io.c:51
static void strarray_add(struct strarray *array, const char *str)
Definition: tools.h:183
static char * get_bindir(const char *argv0)
Definition: tools.h:702
static int strendswith(const char *str, const char *end)
Definition: tools.h:145
static char * get_basename(const char *file)
Definition: tools.h:307
static void set_target_ptr_size(struct target *target, unsigned int size)
Definition: tools.h:538
static const struct strarray empty_strarray
Definition: tools.h:181
static const char * get_arch_dir(struct target target)
Definition: tools.h:616
static char * make_temp_file(const char *prefix, const char *suffix)
Definition: tools.h:407
static int parse_target(const char *name, struct target *target)
Definition: tools.h:640
static void remove_temp_files(void)
Definition: tools.h:446
static void init_signals(void(*cleanup)(int))
Definition: tools.h:455
static unsigned int get_target_ptr_size(struct target target)
Definition: tools.h:524
static char * replace_extension(const char *name, const char *old_ext, const char *new_ext)
Definition: tools.h:328
static int strarray_exists(const struct strarray *array, const char *str)
Definition: tools.h:201
static struct target init_argv0_target(const char *argv0)
Definition: tools.h:689
void * get_attrp(const attr_list_t *list, enum attr_type attr_type)
Definition: attribute.c:87
int is_attr(const attr_list_t *list, enum attr_type attr_type)
Definition: attribute.c:45
int is_object(const type_t *iface)
Definition: header.c:972
int need_proxy_delegation(const statement_list_t *stmts)
Definition: proxy.c:809
int need_proxy_file(const statement_list_t *stmts)
Definition: proxy.c:804
int parser_parse(void)
FILE * parser_in
void close_all_inputs(void)
size_t widl_getline(char **linep, size_t *lenp, FILE *fp)
Definition: utils.c:91
#define error_loc(...)
Definition: utils.h:29
statement_type_t type
Definition: parser.h:124
typelib_t * lib
Definition: widltypes.h:632
union _statement_t::@5358 u
statement_list_t * stmts
Definition: widltypes.h:613
const attr_list_t * attrs
Definition: widltypes.h:611
char * name
Definition: widltypes.h:610
Definition: fci.c:127
Definition: parser.c:49
Definition: name.c:39
unsigned int count
Definition: tools.h:176
const char ** str
Definition: tools.h:178
Definition: tools.h:99
@ PLATFORM_WINDOWS
Definition: tools.h:110
enum target::@5352 cpu
static enum type_type type_get_type(const type_t *type)
Definition: typetree.h:113
static type_t * type_iface_get_async_iface(const type_t *type)
Definition: typetree.h:222
unsigned int packing
Definition: widl.c:146
void start_cplusplus_guard(FILE *fp)
Definition: widl.c:268
static struct strarray dlldirs
Definition: widl.c:140
static void write_dlldata_list(struct strarray filenames, int define_proxy_delegation)
Definition: widl.c:282
@ DLLDATA_ONLY_OPTION
Definition: widl.c:156
@ LOCAL_STUBS_OPTION
Definition: widl.c:157
@ OLD_TYPELIB_OPTION
Definition: widl.c:159
@ OLDNAMES_OPTION
Definition: widl.c:152
@ ACF_OPTION
Definition: widl.c:153
@ RT_NS_PREFIX
Definition: widl.c:165
@ APP_CONFIG_OPTION
Definition: widl.c:154
@ NOSTDINC_OPTION
Definition: widl.c:158
@ PREFIX_SERVER_OPTION
Definition: widl.c:163
@ PREFIX_ALL_OPTION
Definition: widl.c:161
@ ROBUST_OPTION
Definition: widl.c:167
@ PREFIX_CLIENT_OPTION
Definition: widl.c:162
@ PRINT_HELP
Definition: widl.c:164
@ WIN64_OPTION
Definition: widl.c:170
@ SYSROOT_OPTION
Definition: widl.c:168
@ DLLDATA_OPTION
Definition: widl.c:155
@ WIN32_OPTION
Definition: widl.c:169
@ RT_OPTION
Definition: widl.c:166
@ PACKING_OPTION
Definition: widl.c:160
char * acf_name
Definition: widl.c:118
int do_header
Definition: widl.c:100
const char * prefix_server
Definition: widl.c:136
int use_abi_namespace
Definition: widl.c:113
static const char short_options[]
Definition: widl.c:173
int interpreted_mode
Definition: widl.c:112
int parser_debug
Definition: widl.c:95
static const char * bindir
Definition: widl.c:137
int do_idfile
Definition: widl.c:106
static const char * libdir
Definition: widl.c:138
static const char * sysroot
Definition: widl.c:142
int do_regscript
Definition: widl.c:105
static void write_id_guid(FILE *f, const char *type, const char *guid_prefix, const char *name, const struct uuid *uuid)
Definition: widl.c:384
char * client_token
Definition: widl.c:127
time_t now
Definition: widl.c:149
char * typelib_name
Definition: widl.c:122
static void rm_tempfile(void)
Definition: widl.c:867
unsigned int pointer_size
Definition: widl.c:147
int do_server
Definition: widl.c:104
char * dlldata_name
Definition: widl.c:123
char * server_name
Definition: widl.c:128
int do_everything
Definition: widl.c:98
const char * temp_dir
Definition: widl.c:134
char * proxy_name
Definition: widl.c:124
static void exit_on_signal(int sig)
Definition: widl.c:251
static const char * includedir
Definition: widl.c:139
static char * output_name
Definition: widl.c:141
static void option_callback(int optc, char *optarg)
Definition: widl.c:487
static int stdinc
Definition: widl.c:114
FILE * open_input_file(const char *path)
Definition: widl.c:899
char * local_stubs_name
Definition: widl.c:120
int yy_flex_debug
Definition: widl.c:95
char * regscript_name
Definition: widl.c:130
char * header_token
Definition: widl.c:121
int do_typelib
Definition: widl.c:101
static const char version_string[]
Definition: widl.c:89
static char * eat_space(char *s)
Definition: widl.c:322
static char * dup_basename_token(const char *name, const char *ext)
Definition: widl.c:217
char * idl_name
Definition: widl.c:117
int old_names
Definition: widl.c:109
static const struct long_option long_options[]
Definition: widl.c:175
char * find_input_file(const char *name, const char *parent)
Definition: widl.c:888
char * server_token
Definition: widl.c:129
int winrt_mode
Definition: widl.c:111
int old_typelib
Definition: widl.c:110
static void write_id_data_stmts(const statement_list_t *stmts)
Definition: widl.c:394
static void add_widl_version_define(void)
Definition: widl.c:225
struct strarray temp_files
Definition: widl.c:133
int do_proxies
Definition: widl.c:102
char * regscript_token
Definition: widl.c:131
void write_dlldata(const statement_list_t *stmts)
Definition: widl.c:329
char * client_name
Definition: widl.c:126
void end_cplusplus_guard(FILE *fp)
Definition: widl.c:275
static int no_preprocess
Definition: widl.c:108
char * proxy_token
Definition: widl.c:125
static char * make_token(const char *name)
Definition: widl.c:203
static FILE * idfile
Definition: widl.c:144
#define TRYOPEN(str)
static void set_everything(int x)
Definition: widl.c:256
void write_id_data(const statement_list_t *stmts)
Definition: widl.c:431
static char * idfile_name
Definition: widl.c:132
int do_client
Definition: widl.c:103
int debuglevel
Definition: widl.c:94
int pedantic
Definition: widl.c:97
int do_dlldata
Definition: widl.c:107
static int preprocess_only
Definition: widl.c:99
char * header_name
Definition: widl.c:119
char * input_name
Definition: widl.c:116
const char * prefix_client
Definition: widl.c:135
int open_typelib(const char *name)
Definition: widl.c:650
#define DEBUGLEVEL_PPMSG
Definition: widl.h:34
#define DEBUGLEVEL_NONE
Definition: widl.h:30
#define DEBUGLEVEL_PPTRACE
Definition: widl.h:36
#define DEBUGLEVEL_PPLEX
Definition: widl.h:35
#define DEBUGLEVEL_TRACE
Definition: widl.h:33
@ TYPE_COCLASS
Definition: widltypes.h:486
@ TYPE_INTERFACE
Definition: widltypes.h:488
@ ATTR_UUID
Definition: widltypes.h:182
@ ATTR_DISPINTERFACE
Definition: widltypes.h:103
@ STMT_TYPE
Definition: widltypes.h:267
@ STMT_LIBRARY
Definition: widltypes.h:265
void init_types(void)
int wpp_add_cmdline_define(const char *value)
Definition: wpp.c:588
void wpp_set_debug(int lex_debug, int parser_debug, int msg_debug)
Definition: wpp.c:601
char * wpp_find_include(const char *name, const char *parent_name)
Definition: wpp.c:315
int wpp_add_include_path(const char *path)
Definition: wpp.c:298
#define snprintf
Definition: wintirpc.h:48