ReactOS 0.4.15-dev-7928-g68a8619
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#include "wine/port.h"
24
25#include <errno.h>
26#include <limits.h>
27#include <stdio.h>
28#include <stdlib.h>
29#ifdef HAVE_UNISTD_H
30# include <unistd.h>
31#endif
32#include <string.h>
33#include <assert.h>
34#include <ctype.h>
35#include <signal.h>
36#ifdef HAVE_GETOPT_H
37# include <getopt.h>
38#endif
39
40#include "widl.h"
41#include "utils.h"
42#include "parser.h"
43#include "wine/wpp.h"
44#include "header.h"
45
46static const char usage[] =
47"Usage: widl [options...] infile.idl\n"
48" or: widl [options...] --dlldata-only name1 [name2...]\n"
49" --acf=file Use ACF file\n"
50" -app_config Ignored, present for midl compatibility\n"
51" -b arch Set the target architecture\n"
52" -c Generate client stub\n"
53" -d n Set debug level to 'n'\n"
54" -D id[=val] Define preprocessor identifier id=val\n"
55" -E Preprocess only\n"
56" --help Display this help and exit\n"
57" -h Generate headers\n"
58" -H file Name of header file (default is infile.h)\n"
59" -I path Set include search dir to path (multiple -I allowed)\n"
60" --local-stubs=file Write empty stubs for call_as/local methods to file\n"
61" -m32, -m64 Set the target architecture (Win32 or Win64)\n"
62" -N Do not preprocess input\n"
63" --oldnames Use old naming conventions\n"
64" --oldtlb Use old typelib (SLTG) format\n"
65" -o, --output=NAME Set the output file name\n"
66" -Otype Type of stubs to generate (-Os, -Oi, -Oif)\n"
67" -p Generate proxy\n"
68" --prefix-all=p Prefix names of client stubs / server functions with 'p'\n"
69" --prefix-client=p Prefix names of client stubs with 'p'\n"
70" --prefix-server=p Prefix names of server functions with 'p'\n"
71" -r Generate registration script\n"
72" -robust Ignored, present for midl compatibility\n"
73" --winrt Enable Windows Runtime mode\n"
74" --ns_prefix Prefix namespaces with ABI namespace\n"
75" -s Generate server stub\n"
76" -t Generate typelib\n"
77" -u Generate interface identifiers file\n"
78" -V Print version and exit\n"
79" -W Enable pedantic warnings\n"
80" --win32, --win64 Set the target architecture (Win32 or Win64)\n"
81" --win32-align n Set win32 structure alignment to 'n'\n"
82" --win64-align n Set win64 structure alignment to 'n'\n"
83"Debug level 'n' is a bitmask with following meaning:\n"
84" * 0x01 Tell which resource is parsed (verbose mode)\n"
85" * 0x02 Dump internal structures\n"
86" * 0x04 Create a parser trace (yydebug=1)\n"
87" * 0x08 Preprocessor messages\n"
88" * 0x10 Preprocessor lex messages\n"
89" * 0x20 Preprocessor yacc trace\n"
90;
91
92static const char version_string[] = "Wine IDL Compiler version " PACKAGE_VERSION "\n"
93 "Copyright 2002 Ove Kaaven\n";
94
95// __REACTOS__!! We must use TARGET_ macros here!
96#ifdef TARGET_i386
98#elif defined(TARGET_amd64)
100#elif defined(TARGET_ppc)
102#elif defined(TARGET_arm)
104#elif defined(TARGET_arm64)
106#else
107#error Unsupported CPU
108#endif
109
112
113int pedantic = 0;
115static int preprocess_only = 0;
116int do_header = 0;
120int do_client = 0;
121int do_server = 0;
123int do_idfile = 0;
125static int no_preprocess = 0;
126int old_names = 0;
132
149static char *idfile_name;
151const char *prefix_client = "";
152const char *prefix_server = "";
153
155
156static FILE *idfile;
157
158unsigned int pointer_size = 0;
159
161
162enum {
182
183static const char short_options[] =
184 "b:cC:d:D:EhH:I:m:No:O:pP:rsS:tT:uU:VW";
185static const struct option long_options[] = {
186 { "acf", 1, NULL, ACF_OPTION },
187 { "app_config", 0, NULL, APP_CONFIG_OPTION },
188 { "dlldata", 1, NULL, DLLDATA_OPTION },
189 { "dlldata-only", 0, NULL, DLLDATA_ONLY_OPTION },
190 { "help", 0, NULL, PRINT_HELP },
191 { "local-stubs", 1, NULL, LOCAL_STUBS_OPTION },
192 { "ns_prefix", 0, NULL, RT_NS_PREFIX },
193 { "oldnames", 0, NULL, OLDNAMES_OPTION },
194 { "oldtlb", 0, NULL, OLD_TYPELIB_OPTION },
195 { "output", 0, NULL, 'o' },
196 { "prefix-all", 1, NULL, PREFIX_ALL_OPTION },
197 { "prefix-client", 1, NULL, PREFIX_CLIENT_OPTION },
198 { "prefix-server", 1, NULL, PREFIX_SERVER_OPTION },
199 { "robust", 0, NULL, ROBUST_OPTION },
200 { "target", 0, NULL, 'b' },
201 { "winrt", 0, NULL, RT_OPTION },
202 { "win32", 0, NULL, WIN32_OPTION },
203 { "win64", 0, NULL, WIN64_OPTION },
204 { "win32-align", 1, NULL, WIN32_ALIGN_OPTION },
205 { "win64-align", 1, NULL, WIN64_ALIGN_OPTION },
206 { NULL, 0, NULL, 0 }
207};
208
209static void rm_tempfile(void);
210
212{
213 /* old-style interpreted stubs are not supported on 64-bit */
214 if (stub_mode == MODE_Oi && pointer_size == 8) return MODE_Oif;
215 return stub_mode;
216}
217
218static char *make_token(const char *name)
219{
220 char *token;
221 char *slash;
222 int i;
223
224 slash = strrchr(name, '/');
225 if(!slash)
226 slash = strrchr(name, '\\');
227
228 if (slash) name = slash + 1;
229
230 token = xstrdup(name);
231 for (i=0; token[i]; i++) {
232 if (!isalnum(token[i])) token[i] = '_';
233 else token[i] = tolower(token[i]);
234 }
235 return token;
236}
237
238/* duplicate a basename into a valid C token */
239static char *dup_basename_token(const char *name, const char *ext)
240{
241 char *p, *ret = dup_basename( name, ext );
242 /* map invalid characters to '_' */
243 for (p = ret; *p; p++) if (!isalnum(*p)) *p = '_';
244 return ret;
245}
246
247static void add_widl_version_define(void)
248{
249 unsigned int version;
250 const char *p = PACKAGE_VERSION;
251
252 /* major */
253 version = atoi(p) * 0x10000;
254 p = strchr(p, '.');
255
256 /* minor */
257 if (p)
258 {
259 version += atoi(p + 1) * 0x100;
260 p = strchr(p + 1, '.');
261 }
262
263 /* build */
264 if (p)
265 version += atoi(p + 1);
266
267 if (version != 0)
268 {
269 char version_str[11];
270 snprintf(version_str, sizeof(version_str), "0x%x", version);
271 wpp_add_define("__WIDL__", version_str);
272 }
273 else
274 wpp_add_define("__WIDL__", NULL);
275}
276
277/* set the target platform */
278static void set_target( const char *target )
279{
280 static const struct
281 {
282 const char *name;
283 enum target_cpu cpu;
284 } cpu_names[] =
285 {
286 { "i386", CPU_x86 },
287 { "i486", CPU_x86 },
288 { "i586", CPU_x86 },
289 { "i686", CPU_x86 },
290 { "i786", CPU_x86 },
291 { "amd64", CPU_x86_64 },
292 { "x86_64", CPU_x86_64 },
293 { "powerpc", CPU_POWERPC },
294 { "arm", CPU_ARM },
295 { "armv5", CPU_ARM },
296 { "armv6", CPU_ARM },
297 { "armv7", CPU_ARM },
298 { "arm64", CPU_ARM64 },
299 { "aarch64", CPU_ARM64 },
300 };
301
302 unsigned int i;
303 char *p, *spec = xstrdup( target );
304
305 /* target specification is in the form CPU-MANUFACTURER-OS or CPU-MANUFACTURER-KERNEL-OS */
306
307 if (!(p = strchr( spec, '-' ))) error( "Invalid target specification '%s'\n", target );
308 *p++ = 0;
309 for (i = 0; i < sizeof(cpu_names)/sizeof(cpu_names[0]); i++)
310 {
311 if (!strcmp( cpu_names[i].name, spec ))
312 {
313 target_cpu = cpu_names[i].cpu;
314 free( spec );
315 return;
316 }
317 }
318 error( "Unrecognized CPU '%s'\n", spec );
319}
320
321/* clean things up when aborting on a signal */
322static void exit_on_signal( int sig )
323{
324 exit(1); /* this will call the atexit functions */
325}
326
327static void set_everything(int x)
328{
329 do_header = x;
330 do_typelib = x;
332 do_proxies = x;
333 do_client = x;
334 do_server = x;
335 do_regscript = x;
336 do_idfile = x;
337 do_dlldata = x;
338}
339
341{
342 fprintf(fp, "#ifdef __cplusplus\n");
343 fprintf(fp, "extern \"C\" {\n");
344 fprintf(fp, "#endif\n\n");
345}
346
348{
349 fprintf(fp, "#ifdef __cplusplus\n");
350 fprintf(fp, "}\n");
351 fprintf(fp, "#endif\n\n");
352}
353
354typedef struct
355{
356 char *filename;
357 struct list link;
359
360static void add_filename_node(struct list *list, const char *name)
361{
362 filename_node_t *node = xmalloc(sizeof *node);
363 node->filename = dup_basename( name, ".idl" );
364 list_add_tail(list, &node->link);
365}
366
367static void free_filename_nodes(struct list *list)
368{
371 list_remove(&node->link);
372 free(node->filename);
373 free(node);
374 }
375}
376
377static void write_dlldata_list(struct list *filenames, int define_proxy_delegation)
378{
379 FILE *dlldata;
381
382 dlldata = fopen(dlldata_name, "w");
383 if (!dlldata)
384 error("couldn't open %s: %s\n", dlldata_name, strerror(errno));
385
386 fprintf(dlldata, "/*** Autogenerated by WIDL %s ", PACKAGE_VERSION);
387 fprintf(dlldata, "- Do not edit ***/\n\n");
388 if (define_proxy_delegation)
389 fprintf(dlldata, "#define PROXY_DELEGATION\n");
390
391 fprintf(dlldata, "#ifdef __REACTOS__\n");
392 fprintf(dlldata, "#define WIN32_NO_STATUS\n");
393 fprintf(dlldata, "#define WIN32_LEAN_AND_MEAN\n");
394 fprintf(dlldata, "#endif\n\n");
395
396 fprintf(dlldata, "#include <objbase.h>\n");
397 fprintf(dlldata, "#include <rpcproxy.h>\n\n");
398 start_cplusplus_guard(dlldata);
399
401 fprintf(dlldata, "EXTERN_PROXY_FILE(%s)\n", node->filename);
402
403 fprintf(dlldata, "\nPROXYFILE_LIST_START\n");
404 fprintf(dlldata, "/* Start of list */\n");
406 fprintf(dlldata, " REFERENCE_PROXY_FILE(%s),\n", node->filename);
407 fprintf(dlldata, "/* End of list */\n");
408 fprintf(dlldata, "PROXYFILE_LIST_END\n\n");
409
410 fprintf(dlldata, "DLLDATA_ROUTINES(aProxyFileList, GET_DLL_CLSID)\n\n");
411 end_cplusplus_guard(dlldata);
412 fclose(dlldata);
413}
414
415static char *eat_space(char *s)
416{
417 while (isspace((unsigned char) *s))
418 ++s;
419 return s;
420}
421
423{
424 struct list filenames = LIST_INIT(filenames);
425 int define_proxy_delegation = 0;
427 FILE *dlldata;
428
429 if (!do_dlldata || !need_proxy_file(stmts))
430 return;
431
432 define_proxy_delegation = need_proxy_delegation(stmts);
433
434 dlldata = fopen(dlldata_name, "r");
435 if (dlldata) {
436 static const char marker[] = "REFERENCE_PROXY_FILE";
437 static const char delegation_define[] = "#define PROXY_DELEGATION";
438 char *line = NULL;
439 size_t len = 0;
440
441 while (widl_getline(&line, &len, dlldata)) {
442 char *start, *end;
444 if (strncmp(start, marker, sizeof marker - 1) == 0) {
445 start = eat_space(start + sizeof marker - 1);
446 if (*start != '(')
447 continue;
448 end = start = eat_space(start + 1);
449 while (*end && *end != ')')
450 ++end;
451 if (*end != ')')
452 continue;
453 while (isspace((unsigned char) end[-1]))
454 --end;
455 *end = '\0';
456 if (start < end)
457 add_filename_node(&filenames, start);
458 }else if (!define_proxy_delegation && strncmp(start, delegation_define, sizeof(delegation_define)-1)) {
459 define_proxy_delegation = 1;
460 }
461 }
462
463 if (ferror(dlldata))
464 error("couldn't read from %s: %s\n", dlldata_name, strerror(errno));
465
466 free(line);
467 fclose(dlldata);
468 }
469
471 if (strcmp(proxy_token, node->filename) == 0) {
472 /* We're already in the list, no need to regenerate this file. */
473 free_filename_nodes(&filenames);
474 return;
475 }
476
477 add_filename_node(&filenames, proxy_token);
478 write_dlldata_list(&filenames, define_proxy_delegation);
479 free_filename_nodes(&filenames);
480}
481
482static void write_id_guid(FILE *f, const char *type, const char *guid_prefix, const char *name, const UUID *uuid)
483{
484 if (!uuid) return;
485 fprintf(f, "MIDL_DEFINE_GUID(%s, %s_%s, 0x%08x, 0x%04x, 0x%04x, 0x%02x,0x%02x, 0x%02x,"
486 "0x%02x,0x%02x,0x%02x,0x%02x,0x%02x);\n",
487 type, guid_prefix, name, uuid->Data1, uuid->Data2, uuid->Data3, uuid->Data4[0],
488 uuid->Data4[1], uuid->Data4[2], uuid->Data4[3], uuid->Data4[4], uuid->Data4[5],
489 uuid->Data4[6], uuid->Data4[7]);
490}
491
492static void write_id_data_stmts(const statement_list_t *stmts)
493{
494 const statement_t *stmt;
495 if (stmts) LIST_FOR_EACH_ENTRY( stmt, stmts, const statement_t, entry )
496 {
497 if (stmt->type == STMT_TYPE)
498 {
499 const type_t *type = stmt->u.type;
501 {
502 const UUID *uuid;
503 if (!is_object(type) && !is_attr(type->attrs, ATTR_DISPINTERFACE))
504 continue;
505 uuid = get_attrp(type->attrs, ATTR_UUID);
506 write_id_guid(idfile, "IID", is_attr(type->attrs, ATTR_DISPINTERFACE) ? "DIID" : "IID",
507 type->name, uuid);
508 if (type->details.iface->async_iface)
509 {
510 uuid = get_attrp(type->details.iface->async_iface->attrs, ATTR_UUID);
511 write_id_guid(idfile, "IID", "IID", type->details.iface->async_iface->name, uuid);
512 }
513 }
514 else if (type_get_type(type) == TYPE_COCLASS)
515 {
516 const UUID *uuid = get_attrp(type->attrs, ATTR_UUID);
517 write_id_guid(idfile, "CLSID", "CLSID", type->name, uuid);
518 }
519 }
520 else if (stmt->type == STMT_LIBRARY)
521 {
522 const UUID *uuid = get_attrp(stmt->u.lib->attrs, ATTR_UUID);
523 write_id_guid(idfile, "IID", "LIBID", stmt->u.lib->name, uuid);
525 }
526 }
527}
528
530{
531 if (!do_idfile) return;
532
533 idfile = fopen(idfile_name, "w");
534 if (! idfile) {
535 error("Could not open %s for output\n", idfile_name);
536 return;
537 }
538
539 fprintf(idfile, "/*** Autogenerated by WIDL %s ", PACKAGE_VERSION);
540 fprintf(idfile, "from %s - Do not edit ***/\n\n", input_idl_name);
541
542 fprintf(idfile, "#ifdef __REACTOS__\n");
543 fprintf(idfile, "#define WIN32_NO_STATUS\n");
544 fprintf(idfile, "#define WIN32_LEAN_AND_MEAN\n");
545 fprintf(idfile, "#endif\n\n");
546
547 fprintf(idfile, "#include <rpc.h>\n");
548 fprintf(idfile, "#include <rpcndr.h>\n\n");
549
550 fprintf(idfile, "#ifdef _MIDL_USE_GUIDDEF_\n\n");
551
552 fprintf(idfile, "#ifndef INITGUID\n");
553 fprintf(idfile, "#define INITGUID\n");
554 fprintf(idfile, "#include <guiddef.h>\n");
555 fprintf(idfile, "#undef INITGUID\n");
556 fprintf(idfile, "#else\n");
557 fprintf(idfile, "#include <guiddef.h>\n");
558 fprintf(idfile, "#endif\n\n");
559
560 fprintf(idfile, "#define MIDL_DEFINE_GUID(type,name,l,w1,w2,b1,b2,b3,b4,b5,b6,b7,b8) \\\n");
561 fprintf(idfile, " DEFINE_GUID(name,l,w1,w2,b1,b2,b3,b4,b5,b6,b7,b8)\n\n");
562
563 fprintf(idfile, "#elif defined(__cplusplus)\n\n");
564
565 fprintf(idfile, "#define MIDL_DEFINE_GUID(type,name,l,w1,w2,b1,b2,b3,b4,b5,b6,b7,b8) \\\n");
566 fprintf(idfile, " EXTERN_C const type DECLSPEC_SELECTANY name = {l,w1,w2,{b1,b2,b3,b4,b5,b6,b7,b8}}\n\n");
567
568 fprintf(idfile, "#else\n\n");
569
570 fprintf(idfile, "#define MIDL_DEFINE_GUID(type,name,l,w1,w2,b1,b2,b3,b4,b5,b6,b7,b8) \\\n");
571 fprintf(idfile, " const type DECLSPEC_SELECTANY name = {l,w1,w2,{b1,b2,b3,b4,b5,b6,b7,b8}}\n\n");
572
573 fprintf(idfile, "#endif\n\n");
575
576 write_id_data_stmts(stmts);
577
578 fprintf(idfile, "\n");
580 fprintf(idfile, "#undef MIDL_DEFINE_GUID\n" );
581
582 fclose(idfile);
583}
584
585int main(int argc,char *argv[])
586{
587 int optc;
588 int ret = 0;
589 int opti = 0;
590 char *output_name = NULL;
591
594#ifdef SIGHUP
596#endif
597
598 now = time(NULL);
599
600 while((optc = getopt_long_only(argc, argv, short_options, long_options, &opti)) != EOF) {
601 switch(optc) {
602 case DLLDATA_OPTION:
604 break;
606 do_everything = 0;
607 do_dlldata = 1;
608 break;
610 do_everything = 0;
612 break;
613 case OLDNAMES_OPTION:
614 old_names = 1;
615 break;
619 break;
622 break;
625 break;
626 case PRINT_HELP:
627 fprintf(stderr, "%s", usage);
628 return 0;
629 case RT_OPTION:
630 winrt_mode = 1;
631 break;
632 case RT_NS_PREFIX:
634 break;
635 case WIN32_OPTION:
636 pointer_size = 4;
637 break;
638 case WIN64_OPTION:
639 pointer_size = 8;
640 break;
643 if(win32_packing != 2 && win32_packing != 4 && win32_packing != 8)
644 error("Packing must be one of 2, 4 or 8\n");
645 break;
648 if(win64_packing != 2 && win64_packing != 4 && win64_packing != 8)
649 error("Packing must be one of 2, 4 or 8\n");
650 break;
651 case ACF_OPTION:
653 break;
655 /* widl does not distinguish between app_mode and default mode,
656 but we ignore this option for midl compatibility */
657 break;
658 case ROBUST_OPTION:
659 /* FIXME: Support robust option */
660 break;
661 case 'b':
663 break;
664 case 'c':
665 do_everything = 0;
666 do_client = 1;
667 break;
668 case 'C':
670 break;
671 case 'd':
673 break;
674 case 'D':
676 break;
677 case 'E':
678 do_everything = 0;
679 preprocess_only = 1;
680 break;
681 case 'h':
682 do_everything = 0;
683 do_header = 1;
684 break;
685 case 'H':
687 break;
688 case 'I':
690 break;
691 case 'm':
692 if (!strcmp( optarg, "32" )) pointer_size = 4;
693 else if (!strcmp( optarg, "64" )) pointer_size = 8;
694 break;
695 case 'N':
696 no_preprocess = 1;
697 break;
698 case 'o':
699 output_name = xstrdup(optarg);
700 break;
701 case 'O':
702 if (!strcmp( optarg, "s" )) stub_mode = MODE_Os;
703 else if (!strcmp( optarg, "i" )) stub_mode = MODE_Oi;
704 else if (!strcmp( optarg, "ic" )) stub_mode = MODE_Oif;
705 else if (!strcmp( optarg, "if" )) stub_mode = MODE_Oif;
706 else if (!strcmp( optarg, "icf" )) stub_mode = MODE_Oif;
707 else error( "Invalid argument '-O%s'\n", optarg );
708 break;
709 case 'p':
710 do_everything = 0;
711 do_proxies = 1;
712 break;
713 case 'P':
715 break;
716 case 'r':
717 do_everything = 0;
718 do_regscript = 1;
719 break;
720 case 's':
721 do_everything = 0;
722 do_server = 1;
723 break;
724 case 'S':
726 break;
727 case 't':
728 do_everything = 0;
729 do_typelib = 1;
730 break;
732 do_old_typelib = 1;
733 break;
734 case 'T':
736 break;
737 case 'u':
738 do_everything = 0;
739 do_idfile = 1;
740 break;
741 case 'U':
743 break;
744 case 'V':
745 printf("%s", version_string);
746 return 0;
747 case 'W':
748 pedantic = 1;
749 break;
750 default:
751 fprintf(stderr, "%s", usage);
752 return 1;
753 }
754 }
755
756#ifdef DEFAULT_INCLUDE_DIR
757 wpp_add_include_path(DEFAULT_INCLUDE_DIR);
758#endif
759
760 switch (target_cpu)
761 {
762 case CPU_x86:
764 else pointer_size = 4;
765 break;
766 case CPU_x86_64:
767 if (pointer_size == 4) target_cpu = CPU_x86;
768 else pointer_size = 8;
769 break;
770 case CPU_ARM64:
771 if (pointer_size == 4) error( "Cannot build 32-bit code for this CPU\n" );
772 pointer_size = 8;
773 break;
774 default:
775 if (pointer_size == 8) error( "Cannot build 64-bit code for this CPU\n" );
776 pointer_size = 4;
777 break;
778 }
779
780 /* if nothing specified, try to guess output type from the output file name */
781 if (output_name && do_everything && !do_header && !do_typelib && !do_proxies &&
783 {
784 do_everything = 0;
785 if (strendswith( output_name, ".h" )) do_header = 1;
786 else if (strendswith( output_name, ".tlb" )) do_typelib = 1;
787 else if (strendswith( output_name, "_p.c" )) do_proxies = 1;
788 else if (strendswith( output_name, "_c.c" )) do_client = 1;
789 else if (strendswith( output_name, "_s.c" )) do_server = 1;
790 else if (strendswith( output_name, "_i.c" )) do_idfile = 1;
791 else if (strendswith( output_name, "_r.res" )) do_regscript = 1;
792 else if (strendswith( output_name, "_t.res" )) do_typelib = 1;
793 else if (strendswith( output_name, "dlldata.c" )) do_dlldata = 1;
794 else do_everything = 1;
795 }
796
797 if(do_everything) {
799 }
800
801 if (!output_name) output_name = dup_basename(input_name, ".idl");
802
805 {
806 if (do_header) header_name = output_name;
807 else if (do_typelib) typelib_name = output_name;
808 else if (do_proxies) proxy_name = output_name;
809 else if (do_client) client_name = output_name;
810 else if (do_server) server_name = output_name;
811 else if (do_regscript) regscript_name = output_name;
812 else if (do_idfile) idfile_name = output_name;
813 else if (do_dlldata) dlldata_name = output_name;
814 }
815
816 if (!dlldata_name && do_dlldata)
817 dlldata_name = xstrdup("dlldata.c");
818
819 if(optind < argc) {
820 if (do_dlldata && !do_everything) {
821 struct list filenames = LIST_INIT(filenames);
822 for ( ; optind < argc; ++optind)
823 add_filename_node(&filenames, argv[optind]);
824
825 write_dlldata_list(&filenames, 0 /* FIXME */ );
826 free_filename_nodes(&filenames);
827 return 0;
828 }
829 else if (optind != argc - 1) {
830 fprintf(stderr, "%s", usage);
831 return 1;
832 }
833 else
835 }
836 else {
837 fprintf(stderr, "%s", usage);
838 return 1;
839 }
840
841 if(debuglevel)
842 {
845 }
846
849
852 (debuglevel & DEBUGLEVEL_PPMSG) != 0 );
853
854 if (!header_name) {
856 strcat(header_name, ".h");
857 }
858
859 if (!typelib_name && do_typelib) {
861 strcat(typelib_name, ".tlb");
862 }
863
864 if (!proxy_name && do_proxies) {
866 strcat(proxy_name, "_p.c");
867 }
868
869 if (!client_name && do_client) {
871 strcat(client_name, "_c.c");
872 }
873
874 if (!server_name && do_server) {
876 strcat(server_name, "_s.c");
877 }
878
881 strcat(regscript_name, "_r.rgs");
882 }
883
884 if (!idfile_name && do_idfile) {
886 strcat(idfile_name, "_i.c");
887 }
888
893
895 wpp_add_define("_WIN32", NULL);
896
898 if (!no_preprocess)
899 {
900 chat("Starting preprocess\n");
901
902 if (!preprocess_only)
903 {
904 FILE *output;
905 int fd;
906 char *name = xmalloc( strlen(header_name) + 8 );
907
909 strcat( name, ".XXXXXX" );
910
911 if ((fd = mkstemps( name, 0 )) == -1)
912 error("Could not generate a temp name from %s\n", name);
913
914 temp_name = name;
915 if (!(output = fdopen(fd, "wt")))
916 error("Could not open fd %s for writing\n", name);
917
918 ret = wpp_parse( input_name, output );
919 fclose( output );
920 }
921 else
922 {
924 }
925
926 if(ret) exit(1);
927 if(preprocess_only) exit(0);
928 if(!(parser_in = fopen(temp_name, "r"))) {
929 fprintf(stderr, "Could not open %s for input\n", temp_name);
930 return 1;
931 }
932 }
933 else {
934 if(!(parser_in = fopen(input_name, "r"))) {
935 fprintf(stderr, "Could not open %s for input\n", input_name);
936 return 1;
937 }
938 }
939
941
942 init_types();
943 ret = parser_parse();
944
946
947 if(ret) {
948 exit(1);
949 }
950
951 /* Everything has been done successfully, don't delete any files. */
954
955 return 0;
956}
957
958static void rm_tempfile(void)
959{
960 abort_import();
961 if(temp_name)
963 if (do_header)
967 if (do_client)
969 if (do_server)
971 if (do_regscript)
973 if (do_idfile)
975 if (do_proxies)
977 if (do_typelib)
979}
static int argc
Definition: ServiceArgs.c:12
#define isspace(c)
Definition: acclib.h:69
char * strcat(char *DstString, const char *SrcString)
Definition: utclib.c:568
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 * strcpy(char *DstString, const char *SrcString)
Definition: utclib.c:388
char * strchr(const char *String, int ch)
Definition: utclib.c:501
char * xstrdup(const char *s)
Definition: uimain.c:768
void * xmalloc(int size)
Definition: uimain.c:747
const char * optarg
Definition: getopt.c:49
int optind
Definition: getopt.c:47
static void list_remove(struct list_entry *entry)
Definition: list.h:90
static void list_add_tail(struct list_entry *head, struct list_entry *entry)
Definition: list.h:83
Definition: list.h:37
int wpp_add_define(const char *name, const char *value)
Definition: compiler.c:377
int wpp_parse(const char *input, FILE *output)
Definition: compiler.c:437
#define SIGHUP
Definition: signal.h:22
#define SIGINT
Definition: signal.h:23
#define SIGTERM
Definition: signal.h:39
const WCHAR * link
Definition: db.cpp:997
#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 getopt_long_only(optarg_ctx *o, int argc, WCHAR *const *argv, const WCHAR *shortopts, const struct option *longopts, int *longind)
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
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
GLenum target
Definition: glext.h:7315
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
int need_proxy_delegation(const statement_list_t *stmts)
Definition: proxy.c:814
int need_proxy_file(const statement_list_t *stmts)
Definition: proxy.c:809
_Check_return_ _CRTIMP int __cdecl isalnum(_In_ int _C)
#define CHAR_MAX
Definition: limits.h:32
#define stdout
Definition: stdio.h:99
_Check_return_ _CRTIMP int __cdecl ferror(_In_ FILE *_File)
#define EOF
Definition: stdio.h:24
#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 fdopen(_In_ int _FileHandle, _In_z_ 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)
_Check_return_ int __cdecl atoi(_In_z_ const char *_Str)
int __cdecl atexit(void(__cdecl *)(void))
Definition: atonexit.c:97
_Check_return_ long __cdecl strtol(_In_z_ const char *_Str, _Out_opt_ _Deref_post_z_ char **_EndPtr, _In_ int _Radix)
Definition: msctf.idl:550
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
int mkstemps(char *template, int suffix_len)
Definition: mkstemps.c:73
const char * strerror(int err)
Definition: compat_str.c:23
#define argv
Definition: mplay32.c:18
static unsigned __int64 next
Definition: rand_nt.c:6
int wpp_add_cmdline_define(const char *value)
Definition: wpp.c:153
void wpp_set_debug(int lex_debug, int parser_debug, int msg_debug)
Definition: wpp.c:168
int wpp_add_include_path(const char *path)
Definition: preproc.c:460
#define errno
Definition: errno.h:18
_Check_return_ _CRTIMP _CONST_RETURN char *__cdecl strrchr(_In_z_ const char *_Str, _In_ int _Ch)
#define LIST_FOR_EACH_ENTRY(elem, list, type, field)
Definition: list.h:198
#define LIST_FOR_EACH_ENTRY_SAFE(cursor, cursor2, list, type, field)
Definition: list.h:204
#define exit(n)
Definition: config.h:202
int signal
Definition: except.c:82
static int fd
Definition: io.c:51
int is_attr(const attr_list_t *list, enum attr_type t)
Definition: header.c:99
void * get_attrp(const attr_list_t *list, enum attr_type t)
Definition: header.c:107
int is_object(const type_t *iface)
Definition: header.c:928
int parser_parse(void)
FILE * parser_in
void abort_import(void)
size_t widl_getline(char **linep, size_t *lenp, FILE *fp)
Definition: utils.c:172
void chat(const char *s,...)
Definition: utils.c:131
int strendswith(const char *str, const char *end)
Definition: utils.c:238
char * dup_basename(const char *name, const char *ext)
Definition: utils.c:143
statement_type_t type
Definition: parser.h:124
typelib_t * lib
Definition: widltypes.h:540
union _statement_t::@5030 u
statement_list_t * stmts
Definition: widltypes.h:518
const attr_list_t * attrs
Definition: widltypes.h:516
char * name
Definition: widltypes.h:515
char * filename
Definition: widl.c:356
Definition: parser.c:49
Definition: name.c:39
Definition: getopt.h:109
WCHAR * name
Definition: getopt.h:110
#define LIST_INIT(head)
Definition: queue.h:197
static enum type_type type_get_type(const type_t *type)
Definition: typetree.h:68
Definition: dlist.c:348
int ret
void start_cplusplus_guard(FILE *fp)
Definition: widl.c:340
char * acf_name
Definition: widl.c:135
int do_header
Definition: widl.c:116
const char * prefix_server
Definition: widl.c:152
int use_abi_namespace
Definition: widl.c:130
static const char short_options[]
Definition: widl.c:183
int parser_debug
Definition: widl.c:111
int do_idfile
Definition: widl.c:123
static void free_filename_nodes(struct list *list)
Definition: widl.c:367
int do_regscript
Definition: widl.c:122
char * client_token
Definition: widl.c:144
time_t now
Definition: widl.c:160
char * typelib_name
Definition: widl.c:139
static void rm_tempfile(void)
Definition: widl.c:958
unsigned int pointer_size
Definition: widl.c:158
int do_server
Definition: widl.c:121
char * dlldata_name
Definition: widl.c:140
char * server_name
Definition: widl.c:145
@ DLLDATA_ONLY_OPTION
Definition: widl.c:167
@ LOCAL_STUBS_OPTION
Definition: widl.c:168
@ WIN32_ALIGN_OPTION
Definition: widl.c:179
@ OLD_TYPELIB_OPTION
Definition: widl.c:169
@ OLDNAMES_OPTION
Definition: widl.c:163
@ ACF_OPTION
Definition: widl.c:164
@ WIN64_ALIGN_OPTION
Definition: widl.c:180
@ RT_NS_PREFIX
Definition: widl.c:174
@ APP_CONFIG_OPTION
Definition: widl.c:165
@ PREFIX_SERVER_OPTION
Definition: widl.c:172
@ PREFIX_ALL_OPTION
Definition: widl.c:170
@ ROBUST_OPTION
Definition: widl.c:176
@ PREFIX_CLIENT_OPTION
Definition: widl.c:171
@ PRINT_HELP
Definition: widl.c:173
@ WIN64_OPTION
Definition: widl.c:178
@ DLLDATA_OPTION
Definition: widl.c:166
@ WIN32_OPTION
Definition: widl.c:177
@ RT_OPTION
Definition: widl.c:175
static void set_target(const char *target)
Definition: widl.c:278
int do_everything
Definition: widl.c:114
char * proxy_name
Definition: widl.c:141
static enum stub_mode stub_mode
Definition: widl.c:131
static void exit_on_signal(int sig)
Definition: widl.c:322
static void write_id_guid(FILE *f, const char *type, const char *guid_prefix, const char *name, const UUID *uuid)
Definition: widl.c:482
char * input_idl_name
Definition: widl.c:134
char * local_stubs_name
Definition: widl.c:137
int yy_flex_debug
Definition: widl.c:111
char * regscript_name
Definition: widl.c:147
static void add_filename_node(struct list *list, const char *name)
Definition: widl.c:360
char * header_token
Definition: widl.c:138
int do_typelib
Definition: widl.c:117
static const char version_string[]
Definition: widl.c:92
static char * eat_space(char *s)
Definition: widl.c:415
static char * dup_basename_token(const char *name, const char *ext)
Definition: widl.c:239
int old_names
Definition: widl.c:126
char * server_token
Definition: widl.c:146
int win64_packing
Definition: widl.c:128
int winrt_mode
Definition: widl.c:129
int win32_packing
Definition: widl.c:127
int do_old_typelib
Definition: widl.c:118
static void write_id_data_stmts(const statement_list_t *stmts)
Definition: widl.c:492
static const struct option long_options[]
Definition: widl.c:185
static void add_widl_version_define(void)
Definition: widl.c:247
int do_proxies
Definition: widl.c:119
char * regscript_token
Definition: widl.c:148
void write_dlldata(const statement_list_t *stmts)
Definition: widl.c:422
char * client_name
Definition: widl.c:143
void end_cplusplus_guard(FILE *fp)
Definition: widl.c:347
static int no_preprocess
Definition: widl.c:125
char * proxy_token
Definition: widl.c:142
static char * make_token(const char *name)
Definition: widl.c:218
static FILE * idfile
Definition: widl.c:156
int line_number
Definition: widl.c:154
static void set_everything(int x)
Definition: widl.c:327
void write_id_data(const statement_list_t *stmts)
Definition: widl.c:529
static char * idfile_name
Definition: widl.c:149
static void write_dlldata_list(struct list *filenames, int define_proxy_delegation)
Definition: widl.c:377
enum stub_mode get_stub_mode(void)
Definition: widl.c:211
int do_client
Definition: widl.c:120
int debuglevel
Definition: widl.c:110
int pedantic
Definition: widl.c:113
int do_dlldata
Definition: widl.c:124
static int preprocess_only
Definition: widl.c:115
char * header_name
Definition: widl.c:136
char * input_name
Definition: widl.c:133
const char * prefix_client
Definition: widl.c:151
char * temp_name
Definition: widl.c:150
#define DEBUGLEVEL_PPMSG
Definition: widl.h:33
#define DEBUGLEVEL_NONE
Definition: widl.h:29
#define DEBUGLEVEL_PPTRACE
Definition: widl.h:35
stub_mode
Definition: widl.h:86
@ MODE_Os
Definition: widl.h:87
@ MODE_Oif
Definition: widl.h:89
@ MODE_Oi
Definition: widl.h:88
target_cpu
Definition: widl.h:79
@ CPU_ARM
Definition: widl.h:80
@ CPU_x86_64
Definition: widl.h:80
@ CPU_x86
Definition: widl.h:80
@ CPU_ARM64
Definition: widl.h:80
@ CPU_POWERPC
Definition: widl.h:80
#define DEBUGLEVEL_PPLEX
Definition: widl.h:34
#define DEBUGLEVEL_TRACE
Definition: widl.h:32
@ TYPE_COCLASS
Definition: widltypes.h:410
@ TYPE_INTERFACE
Definition: widltypes.h:412
@ ATTR_UUID
Definition: widltypes.h:166
@ ATTR_DISPINTERFACE
Definition: widltypes.h:94
@ STMT_TYPE
Definition: widltypes.h:242
@ STMT_LIBRARY
Definition: widltypes.h:240
void init_types(void)
#define snprintf
Definition: wintirpc.h:48