ReactOS 0.4.16-dev-853-g88d9285
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#ifdef __i386__
97#elif defined(__x86_64__)
99#elif defined(__powerpc__)
101#elif defined(__arm__)
103#elif defined(__aarch64__)
105#else
106#error Unsupported CPU
107#endif
108
111
112int pedantic = 0;
114static int preprocess_only = 0;
115int do_header = 0;
119int do_client = 0;
120int do_server = 0;
122int do_idfile = 0;
124static int no_preprocess = 0;
125int old_names = 0;
131
148static char *idfile_name;
150const char *prefix_client = "";
151const char *prefix_server = "";
152
154
155static FILE *idfile;
156
157unsigned int pointer_size = 0;
158
160
161enum {
181
182static const char short_options[] =
183 "b:cC:d:D:EhH:I:m:No:O:pP:rsS:tT:uU:VW";
184static const struct option long_options[] = {
185 { "acf", 1, NULL, ACF_OPTION },
186 { "app_config", 0, NULL, APP_CONFIG_OPTION },
187 { "dlldata", 1, NULL, DLLDATA_OPTION },
188 { "dlldata-only", 0, NULL, DLLDATA_ONLY_OPTION },
189 { "help", 0, NULL, PRINT_HELP },
190 { "local-stubs", 1, NULL, LOCAL_STUBS_OPTION },
191 { "ns_prefix", 0, NULL, RT_NS_PREFIX },
192 { "oldnames", 0, NULL, OLDNAMES_OPTION },
193 { "oldtlb", 0, NULL, OLD_TYPELIB_OPTION },
194 { "output", 0, NULL, 'o' },
195 { "prefix-all", 1, NULL, PREFIX_ALL_OPTION },
196 { "prefix-client", 1, NULL, PREFIX_CLIENT_OPTION },
197 { "prefix-server", 1, NULL, PREFIX_SERVER_OPTION },
198 { "robust", 0, NULL, ROBUST_OPTION },
199 { "target", 0, NULL, 'b' },
200 { "winrt", 0, NULL, RT_OPTION },
201 { "win32", 0, NULL, WIN32_OPTION },
202 { "win64", 0, NULL, WIN64_OPTION },
203 { "win32-align", 1, NULL, WIN32_ALIGN_OPTION },
204 { "win64-align", 1, NULL, WIN64_ALIGN_OPTION },
205 { NULL, 0, NULL, 0 }
206};
207
208static void rm_tempfile(void);
209
211{
212 /* old-style interpreted stubs are not supported on 64-bit */
213 if (stub_mode == MODE_Oi && pointer_size == 8) return MODE_Oif;
214 return stub_mode;
215}
216
217static char *make_token(const char *name)
218{
219 char *token;
220 char *slash;
221 int i;
222
223 slash = strrchr(name, '/');
224 if(!slash)
225 slash = strrchr(name, '\\');
226
227 if (slash) name = slash + 1;
228
229 token = xstrdup(name);
230 for (i=0; token[i]; i++) {
231 if (!isalnum(token[i])) token[i] = '_';
232 else token[i] = tolower(token[i]);
233 }
234 return token;
235}
236
237/* duplicate a basename into a valid C token */
238static char *dup_basename_token(const char *name, const char *ext)
239{
240 char *p, *ret = dup_basename( name, ext );
241 /* map invalid characters to '_' */
242 for (p = ret; *p; p++) if (!isalnum(*p)) *p = '_';
243 return ret;
244}
245
246static void add_widl_version_define(void)
247{
248 unsigned int version;
249 const char *p = PACKAGE_VERSION;
250
251 /* major */
252 version = atoi(p) * 0x10000;
253 p = strchr(p, '.');
254
255 /* minor */
256 if (p)
257 {
258 version += atoi(p + 1) * 0x100;
259 p = strchr(p + 1, '.');
260 }
261
262 /* build */
263 if (p)
264 version += atoi(p + 1);
265
266 if (version != 0)
267 {
268 char version_str[11];
269 snprintf(version_str, sizeof(version_str), "0x%x", version);
270 wpp_add_define("__WIDL__", version_str);
271 }
272 else
273 wpp_add_define("__WIDL__", NULL);
274}
275
276/* set the target platform */
277static void set_target( const char *target )
278{
279 static const struct
280 {
281 const char *name;
282 enum target_cpu cpu;
283 } cpu_names[] =
284 {
285 { "i386", CPU_x86 },
286 { "i486", CPU_x86 },
287 { "i586", CPU_x86 },
288 { "i686", CPU_x86 },
289 { "i786", CPU_x86 },
290 { "amd64", CPU_x86_64 },
291 { "x86_64", CPU_x86_64 },
292 { "powerpc", CPU_POWERPC },
293 { "arm", CPU_ARM },
294 { "armv5", CPU_ARM },
295 { "armv6", CPU_ARM },
296 { "armv7", CPU_ARM },
297 { "arm64", CPU_ARM64 },
298 { "aarch64", CPU_ARM64 },
299 };
300
301 unsigned int i;
302 char *p, *spec = xstrdup( target );
303
304 /* target specification is in the form CPU-MANUFACTURER-OS or CPU-MANUFACTURER-KERNEL-OS */
305
306 if (!(p = strchr( spec, '-' ))) error( "Invalid target specification '%s'\n", target );
307 *p++ = 0;
308 for (i = 0; i < sizeof(cpu_names)/sizeof(cpu_names[0]); i++)
309 {
310 if (!strcmp( cpu_names[i].name, spec ))
311 {
312 target_cpu = cpu_names[i].cpu;
313 free( spec );
314 return;
315 }
316 }
317 error( "Unrecognized CPU '%s'\n", spec );
318}
319
320/* clean things up when aborting on a signal */
321static void exit_on_signal( int sig )
322{
323 exit(1); /* this will call the atexit functions */
324}
325
326static void set_everything(int x)
327{
328 do_header = x;
329 do_typelib = x;
331 do_proxies = x;
332 do_client = x;
333 do_server = x;
334 do_regscript = x;
335 do_idfile = x;
336 do_dlldata = x;
337}
338
340{
341 fprintf(fp, "#ifdef __cplusplus\n");
342 fprintf(fp, "extern \"C\" {\n");
343 fprintf(fp, "#endif\n\n");
344}
345
347{
348 fprintf(fp, "#ifdef __cplusplus\n");
349 fprintf(fp, "}\n");
350 fprintf(fp, "#endif\n\n");
351}
352
353typedef struct
354{
355 char *filename;
356 struct list link;
358
359static void add_filename_node(struct list *list, const char *name)
360{
361 filename_node_t *node = xmalloc(sizeof *node);
362 node->filename = dup_basename( name, ".idl" );
363 list_add_tail(list, &node->link);
364}
365
366static void free_filename_nodes(struct list *list)
367{
370 list_remove(&node->link);
371 free(node->filename);
372 free(node);
373 }
374}
375
376static void write_dlldata_list(struct list *filenames, int define_proxy_delegation)
377{
378 FILE *dlldata;
380
381 dlldata = fopen(dlldata_name, "w");
382 if (!dlldata)
383 error("couldn't open %s: %s\n", dlldata_name, strerror(errno));
384
385 fprintf(dlldata, "/*** Autogenerated by WIDL %s ", PACKAGE_VERSION);
386 fprintf(dlldata, "- Do not edit ***/\n\n");
387 if (define_proxy_delegation)
388 fprintf(dlldata, "#define PROXY_DELEGATION\n");
389
390 fprintf(dlldata, "#ifdef __REACTOS__\n");
391 fprintf(dlldata, "#define WIN32_NO_STATUS\n");
392 fprintf(dlldata, "#define WIN32_LEAN_AND_MEAN\n");
393 fprintf(dlldata, "#endif\n\n");
394
395 fprintf(dlldata, "#include <objbase.h>\n");
396 fprintf(dlldata, "#include <rpcproxy.h>\n\n");
397 start_cplusplus_guard(dlldata);
398
400 fprintf(dlldata, "EXTERN_PROXY_FILE(%s)\n", node->filename);
401
402 fprintf(dlldata, "\nPROXYFILE_LIST_START\n");
403 fprintf(dlldata, "/* Start of list */\n");
405 fprintf(dlldata, " REFERENCE_PROXY_FILE(%s),\n", node->filename);
406 fprintf(dlldata, "/* End of list */\n");
407 fprintf(dlldata, "PROXYFILE_LIST_END\n\n");
408
409 fprintf(dlldata, "DLLDATA_ROUTINES(aProxyFileList, GET_DLL_CLSID)\n\n");
410 end_cplusplus_guard(dlldata);
411 fclose(dlldata);
412}
413
414static char *eat_space(char *s)
415{
416 while (isspace((unsigned char) *s))
417 ++s;
418 return s;
419}
420
422{
423 struct list filenames = LIST_INIT(filenames);
424 int define_proxy_delegation = 0;
426 FILE *dlldata;
427
428 if (!do_dlldata || !need_proxy_file(stmts))
429 return;
430
431 define_proxy_delegation = need_proxy_delegation(stmts);
432
433 dlldata = fopen(dlldata_name, "r");
434 if (dlldata) {
435 static const char marker[] = "REFERENCE_PROXY_FILE";
436 static const char delegation_define[] = "#define PROXY_DELEGATION";
437 char *line = NULL;
438 size_t len = 0;
439
440 while (widl_getline(&line, &len, dlldata)) {
441 char *start, *end;
443 if (strncmp(start, marker, sizeof marker - 1) == 0) {
444 start = eat_space(start + sizeof marker - 1);
445 if (*start != '(')
446 continue;
447 end = start = eat_space(start + 1);
448 while (*end && *end != ')')
449 ++end;
450 if (*end != ')')
451 continue;
452 while (isspace((unsigned char) end[-1]))
453 --end;
454 *end = '\0';
455 if (start < end)
456 add_filename_node(&filenames, start);
457 }else if (!define_proxy_delegation && strncmp(start, delegation_define, sizeof(delegation_define)-1)) {
458 define_proxy_delegation = 1;
459 }
460 }
461
462 if (ferror(dlldata))
463 error("couldn't read from %s: %s\n", dlldata_name, strerror(errno));
464
465 free(line);
466 fclose(dlldata);
467 }
468
470 if (strcmp(proxy_token, node->filename) == 0) {
471 /* We're already in the list, no need to regenerate this file. */
472 free_filename_nodes(&filenames);
473 return;
474 }
475
476 add_filename_node(&filenames, proxy_token);
477 write_dlldata_list(&filenames, define_proxy_delegation);
478 free_filename_nodes(&filenames);
479}
480
481static void write_id_guid(FILE *f, const char *type, const char *guid_prefix, const char *name, const UUID *uuid)
482{
483 if (!uuid) return;
484 fprintf(f, "MIDL_DEFINE_GUID(%s, %s_%s, 0x%08x, 0x%04x, 0x%04x, 0x%02x,0x%02x, 0x%02x,"
485 "0x%02x,0x%02x,0x%02x,0x%02x,0x%02x);\n",
486 type, guid_prefix, name, uuid->Data1, uuid->Data2, uuid->Data3, uuid->Data4[0],
487 uuid->Data4[1], uuid->Data4[2], uuid->Data4[3], uuid->Data4[4], uuid->Data4[5],
488 uuid->Data4[6], uuid->Data4[7]);
489}
490
491static void write_id_data_stmts(const statement_list_t *stmts)
492{
493 const statement_t *stmt;
494 if (stmts) LIST_FOR_EACH_ENTRY( stmt, stmts, const statement_t, entry )
495 {
496 if (stmt->type == STMT_TYPE)
497 {
498 const type_t *type = stmt->u.type;
500 {
501 const UUID *uuid;
502 if (!is_object(type) && !is_attr(type->attrs, ATTR_DISPINTERFACE))
503 continue;
504 uuid = get_attrp(type->attrs, ATTR_UUID);
505 write_id_guid(idfile, "IID", is_attr(type->attrs, ATTR_DISPINTERFACE) ? "DIID" : "IID",
506 type->name, uuid);
507 if (type->details.iface->async_iface)
508 {
509 uuid = get_attrp(type->details.iface->async_iface->attrs, ATTR_UUID);
510 write_id_guid(idfile, "IID", "IID", type->details.iface->async_iface->name, uuid);
511 }
512 }
513 else if (type_get_type(type) == TYPE_COCLASS)
514 {
515 const UUID *uuid = get_attrp(type->attrs, ATTR_UUID);
516 write_id_guid(idfile, "CLSID", "CLSID", type->name, uuid);
517 }
518 }
519 else if (stmt->type == STMT_LIBRARY)
520 {
521 const UUID *uuid = get_attrp(stmt->u.lib->attrs, ATTR_UUID);
522 write_id_guid(idfile, "IID", "LIBID", stmt->u.lib->name, uuid);
524 }
525 }
526}
527
529{
530 if (!do_idfile) return;
531
532 idfile = fopen(idfile_name, "w");
533 if (! idfile) {
534 error("Could not open %s for output\n", idfile_name);
535 return;
536 }
537
538 fprintf(idfile, "/*** Autogenerated by WIDL %s ", PACKAGE_VERSION);
539 fprintf(idfile, "from %s - Do not edit ***/\n\n", input_idl_name);
540
541 fprintf(idfile, "#ifdef __REACTOS__\n");
542 fprintf(idfile, "#define WIN32_NO_STATUS\n");
543 fprintf(idfile, "#define WIN32_LEAN_AND_MEAN\n");
544 fprintf(idfile, "#endif\n\n");
545
546 fprintf(idfile, "#include <rpc.h>\n");
547 fprintf(idfile, "#include <rpcndr.h>\n\n");
548
549 fprintf(idfile, "#ifdef _MIDL_USE_GUIDDEF_\n\n");
550
551 fprintf(idfile, "#ifndef INITGUID\n");
552 fprintf(idfile, "#define INITGUID\n");
553 fprintf(idfile, "#include <guiddef.h>\n");
554 fprintf(idfile, "#undef INITGUID\n");
555 fprintf(idfile, "#else\n");
556 fprintf(idfile, "#include <guiddef.h>\n");
557 fprintf(idfile, "#endif\n\n");
558
559 fprintf(idfile, "#define MIDL_DEFINE_GUID(type,name,l,w1,w2,b1,b2,b3,b4,b5,b6,b7,b8) \\\n");
560 fprintf(idfile, " DEFINE_GUID(name,l,w1,w2,b1,b2,b3,b4,b5,b6,b7,b8)\n\n");
561
562 fprintf(idfile, "#elif defined(__cplusplus)\n\n");
563
564 fprintf(idfile, "#define MIDL_DEFINE_GUID(type,name,l,w1,w2,b1,b2,b3,b4,b5,b6,b7,b8) \\\n");
565 fprintf(idfile, " EXTERN_C const type DECLSPEC_SELECTANY name = {l,w1,w2,{b1,b2,b3,b4,b5,b6,b7,b8}}\n\n");
566
567 fprintf(idfile, "#else\n\n");
568
569 fprintf(idfile, "#define MIDL_DEFINE_GUID(type,name,l,w1,w2,b1,b2,b3,b4,b5,b6,b7,b8) \\\n");
570 fprintf(idfile, " const type DECLSPEC_SELECTANY name = {l,w1,w2,{b1,b2,b3,b4,b5,b6,b7,b8}}\n\n");
571
572 fprintf(idfile, "#endif\n\n");
574
575 write_id_data_stmts(stmts);
576
577 fprintf(idfile, "\n");
579 fprintf(idfile, "#undef MIDL_DEFINE_GUID\n" );
580
581 fclose(idfile);
582}
583
584int main(int argc,char *argv[])
585{
586 int optc;
587 int ret = 0;
588 int opti = 0;
589 char *output_name = NULL;
590
593#ifdef SIGHUP
595#endif
596
597 now = time(NULL);
598
599 while((optc = getopt_long_only(argc, argv, short_options, long_options, &opti)) != EOF) {
600 switch(optc) {
601 case DLLDATA_OPTION:
603 break;
605 do_everything = 0;
606 do_dlldata = 1;
607 break;
609 do_everything = 0;
611 break;
612 case OLDNAMES_OPTION:
613 old_names = 1;
614 break;
618 break;
621 break;
624 break;
625 case PRINT_HELP:
626 fprintf(stderr, "%s", usage);
627 return 0;
628 case RT_OPTION:
629 winrt_mode = 1;
630 break;
631 case RT_NS_PREFIX:
633 break;
634 case WIN32_OPTION:
635 pointer_size = 4;
636 break;
637 case WIN64_OPTION:
638 pointer_size = 8;
639 break;
642 if(win32_packing != 2 && win32_packing != 4 && win32_packing != 8)
643 error("Packing must be one of 2, 4 or 8\n");
644 break;
647 if(win64_packing != 2 && win64_packing != 4 && win64_packing != 8)
648 error("Packing must be one of 2, 4 or 8\n");
649 break;
650 case ACF_OPTION:
652 break;
654 /* widl does not distinguish between app_mode and default mode,
655 but we ignore this option for midl compatibility */
656 break;
657 case ROBUST_OPTION:
658 /* FIXME: Support robust option */
659 break;
660 case 'b':
662 break;
663 case 'c':
664 do_everything = 0;
665 do_client = 1;
666 break;
667 case 'C':
669 break;
670 case 'd':
672 break;
673 case 'D':
675 break;
676 case 'E':
677 do_everything = 0;
678 preprocess_only = 1;
679 break;
680 case 'h':
681 do_everything = 0;
682 do_header = 1;
683 break;
684 case 'H':
686 break;
687 case 'I':
689 break;
690 case 'm':
691 if (!strcmp( optarg, "32" )) pointer_size = 4;
692 else if (!strcmp( optarg, "64" )) pointer_size = 8;
693 break;
694 case 'N':
695 no_preprocess = 1;
696 break;
697 case 'o':
698 output_name = xstrdup(optarg);
699 break;
700 case 'O':
701 if (!strcmp( optarg, "s" )) stub_mode = MODE_Os;
702 else if (!strcmp( optarg, "i" )) stub_mode = MODE_Oi;
703 else if (!strcmp( optarg, "ic" )) stub_mode = MODE_Oif;
704 else if (!strcmp( optarg, "if" )) stub_mode = MODE_Oif;
705 else if (!strcmp( optarg, "icf" )) stub_mode = MODE_Oif;
706 else error( "Invalid argument '-O%s'\n", optarg );
707 break;
708 case 'p':
709 do_everything = 0;
710 do_proxies = 1;
711 break;
712 case 'P':
714 break;
715 case 'r':
716 do_everything = 0;
717 do_regscript = 1;
718 break;
719 case 's':
720 do_everything = 0;
721 do_server = 1;
722 break;
723 case 'S':
725 break;
726 case 't':
727 do_everything = 0;
728 do_typelib = 1;
729 break;
731 do_old_typelib = 1;
732 break;
733 case 'T':
735 break;
736 case 'u':
737 do_everything = 0;
738 do_idfile = 1;
739 break;
740 case 'U':
742 break;
743 case 'V':
744 printf("%s", version_string);
745 return 0;
746 case 'W':
747 pedantic = 1;
748 break;
749 default:
750 fprintf(stderr, "%s", usage);
751 return 1;
752 }
753 }
754
755#ifdef DEFAULT_INCLUDE_DIR
756 wpp_add_include_path(DEFAULT_INCLUDE_DIR);
757#endif
758
759 switch (target_cpu)
760 {
761 case CPU_x86:
763 else pointer_size = 4;
764 break;
765 case CPU_x86_64:
766 if (pointer_size == 4) target_cpu = CPU_x86;
767 else pointer_size = 8;
768 break;
769 case CPU_ARM64:
770 if (pointer_size == 4) error( "Cannot build 32-bit code for this CPU\n" );
771 pointer_size = 8;
772 break;
773 default:
774 if (pointer_size == 8) error( "Cannot build 64-bit code for this CPU\n" );
775 pointer_size = 4;
776 break;
777 }
778
779 /* if nothing specified, try to guess output type from the output file name */
780 if (output_name && do_everything && !do_header && !do_typelib && !do_proxies &&
782 {
783 do_everything = 0;
784 if (strendswith( output_name, ".h" )) do_header = 1;
785 else if (strendswith( output_name, ".tlb" )) do_typelib = 1;
786 else if (strendswith( output_name, "_p.c" )) do_proxies = 1;
787 else if (strendswith( output_name, "_c.c" )) do_client = 1;
788 else if (strendswith( output_name, "_s.c" )) do_server = 1;
789 else if (strendswith( output_name, "_i.c" )) do_idfile = 1;
790 else if (strendswith( output_name, "_r.res" )) do_regscript = 1;
791 else if (strendswith( output_name, "_t.res" )) do_typelib = 1;
792 else if (strendswith( output_name, "dlldata.c" )) do_dlldata = 1;
793 else do_everything = 1;
794 }
795
796 if(do_everything) {
798 }
799
800 if (!output_name) output_name = dup_basename(input_name, ".idl");
801
804 {
805 if (do_header) header_name = output_name;
806 else if (do_typelib) typelib_name = output_name;
807 else if (do_proxies) proxy_name = output_name;
808 else if (do_client) client_name = output_name;
809 else if (do_server) server_name = output_name;
810 else if (do_regscript) regscript_name = output_name;
811 else if (do_idfile) idfile_name = output_name;
812 else if (do_dlldata) dlldata_name = output_name;
813 }
814
815 if (!dlldata_name && do_dlldata)
816 dlldata_name = xstrdup("dlldata.c");
817
818 if(optind < argc) {
819 if (do_dlldata && !do_everything) {
820 struct list filenames = LIST_INIT(filenames);
821 for ( ; optind < argc; ++optind)
822 add_filename_node(&filenames, argv[optind]);
823
824 write_dlldata_list(&filenames, 0 /* FIXME */ );
825 free_filename_nodes(&filenames);
826 return 0;
827 }
828 else if (optind != argc - 1) {
829 fprintf(stderr, "%s", usage);
830 return 1;
831 }
832 else
834 }
835 else {
836 fprintf(stderr, "%s", usage);
837 return 1;
838 }
839
840 if(debuglevel)
841 {
844 }
845
848
851 (debuglevel & DEBUGLEVEL_PPMSG) != 0 );
852
853 if (!header_name) {
855 strcat(header_name, ".h");
856 }
857
858 if (!typelib_name && do_typelib) {
860 strcat(typelib_name, ".tlb");
861 }
862
863 if (!proxy_name && do_proxies) {
865 strcat(proxy_name, "_p.c");
866 }
867
868 if (!client_name && do_client) {
870 strcat(client_name, "_c.c");
871 }
872
873 if (!server_name && do_server) {
875 strcat(server_name, "_s.c");
876 }
877
880 strcat(regscript_name, "_r.rgs");
881 }
882
883 if (!idfile_name && do_idfile) {
885 strcat(idfile_name, "_i.c");
886 }
887
892
894 wpp_add_define("_WIN32", NULL);
895
897 if (!no_preprocess)
898 {
899 chat("Starting preprocess\n");
900
901 if (!preprocess_only)
902 {
903 FILE *output;
904 int fd;
905 char *name = xmalloc( strlen(header_name) + 8 );
906
908 strcat( name, ".XXXXXX" );
909
910 if ((fd = mkstemps( name, 0 )) == -1)
911 error("Could not generate a temp name from %s\n", name);
912
913 temp_name = name;
914 if (!(output = fdopen(fd, "wt")))
915 error("Could not open fd %s for writing\n", name);
916
917 ret = wpp_parse( input_name, output );
918 fclose( output );
919 }
920 else
921 {
923 }
924
925 if(ret) exit(1);
926 if(preprocess_only) exit(0);
927 if(!(parser_in = fopen(temp_name, "r"))) {
928 fprintf(stderr, "Could not open %s for input\n", temp_name);
929 return 1;
930 }
931 }
932 else {
933 if(!(parser_in = fopen(input_name, "r"))) {
934 fprintf(stderr, "Could not open %s for input\n", input_name);
935 return 1;
936 }
937 }
938
940
941 init_types();
942 ret = parser_parse();
943
945
946 if(ret) {
947 exit(1);
948 }
949
950 /* Everything has been done successfully, don't delete any files. */
953
954 return 0;
955}
956
957static void rm_tempfile(void)
958{
959 abort_import();
960 if(temp_name)
962 if (do_header)
966 if (do_client)
968 if (do_server)
970 if (do_regscript)
972 if (do_idfile)
974 if (do_proxies)
976 if (do_typelib)
978}
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
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 __cdecl atexit(void(__cdecl *function)(void))
Definition: stubs.c:7
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 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)
_Check_return_ long __cdecl strtol(_In_z_ const char *_Str, _Out_opt_ _Deref_post_z_ char **_EndPtr, _In_ int _Radix)
#define CHAR_MAX
Definition: limits.h:32
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
_CRT_RESTORE_GCC_WARNINGS _CRT_DISABLE_GCC_WARNINGS _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
strcat
Definition: string.h:92
strcpy
Definition: string.h:131
#define exit(n)
Definition: config.h:202
int signal
Definition: except.c:84
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::@5154 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:355
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:339
char * acf_name
Definition: widl.c:134
int do_header
Definition: widl.c:115
const char * prefix_server
Definition: widl.c:151
int use_abi_namespace
Definition: widl.c:129
static const char short_options[]
Definition: widl.c:182
int parser_debug
Definition: widl.c:110
int do_idfile
Definition: widl.c:122
static void free_filename_nodes(struct list *list)
Definition: widl.c:366
int do_regscript
Definition: widl.c:121
char * client_token
Definition: widl.c:143
time_t now
Definition: widl.c:159
char * typelib_name
Definition: widl.c:138
static void rm_tempfile(void)
Definition: widl.c:957
unsigned int pointer_size
Definition: widl.c:157
int do_server
Definition: widl.c:120
char * dlldata_name
Definition: widl.c:139
char * server_name
Definition: widl.c:144
static void set_target(const char *target)
Definition: widl.c:277
int do_everything
Definition: widl.c:113
char * proxy_name
Definition: widl.c:140
static enum stub_mode stub_mode
Definition: widl.c:130
static void exit_on_signal(int sig)
Definition: widl.c:321
static void write_id_guid(FILE *f, const char *type, const char *guid_prefix, const char *name, const UUID *uuid)
Definition: widl.c:481
char * input_idl_name
Definition: widl.c:133
char * local_stubs_name
Definition: widl.c:136
int yy_flex_debug
Definition: widl.c:110
char * regscript_name
Definition: widl.c:146
static void add_filename_node(struct list *list, const char *name)
Definition: widl.c:359
char * header_token
Definition: widl.c:137
int do_typelib
Definition: widl.c:116
static const char version_string[]
Definition: widl.c:92
static char * eat_space(char *s)
Definition: widl.c:414
static char * dup_basename_token(const char *name, const char *ext)
Definition: widl.c:238
int old_names
Definition: widl.c:125
char * server_token
Definition: widl.c:145
int win64_packing
Definition: widl.c:127
int winrt_mode
Definition: widl.c:128
int win32_packing
Definition: widl.c:126
int do_old_typelib
Definition: widl.c:117
static void write_id_data_stmts(const statement_list_t *stmts)
Definition: widl.c:491
static const struct option long_options[]
Definition: widl.c:184
static void add_widl_version_define(void)
Definition: widl.c:246
int do_proxies
Definition: widl.c:118
char * regscript_token
Definition: widl.c:147
void write_dlldata(const statement_list_t *stmts)
Definition: widl.c:421
char * client_name
Definition: widl.c:142
void end_cplusplus_guard(FILE *fp)
Definition: widl.c:346
static int no_preprocess
Definition: widl.c:124
char * proxy_token
Definition: widl.c:141
static char * make_token(const char *name)
Definition: widl.c:217
static FILE * idfile
Definition: widl.c:155
int line_number
Definition: widl.c:153
static void set_everything(int x)
Definition: widl.c:326
void write_id_data(const statement_list_t *stmts)
Definition: widl.c:528
@ DLLDATA_ONLY_OPTION
Definition: widl.c:166
@ LOCAL_STUBS_OPTION
Definition: widl.c:167
@ WIN32_ALIGN_OPTION
Definition: widl.c:178
@ OLD_TYPELIB_OPTION
Definition: widl.c:168
@ OLDNAMES_OPTION
Definition: widl.c:162
@ ACF_OPTION
Definition: widl.c:163
@ WIN64_ALIGN_OPTION
Definition: widl.c:179
@ RT_NS_PREFIX
Definition: widl.c:173
@ APP_CONFIG_OPTION
Definition: widl.c:164
@ PREFIX_SERVER_OPTION
Definition: widl.c:171
@ PREFIX_ALL_OPTION
Definition: widl.c:169
@ ROBUST_OPTION
Definition: widl.c:175
@ PREFIX_CLIENT_OPTION
Definition: widl.c:170
@ PRINT_HELP
Definition: widl.c:172
@ WIN64_OPTION
Definition: widl.c:177
@ DLLDATA_OPTION
Definition: widl.c:165
@ WIN32_OPTION
Definition: widl.c:176
@ RT_OPTION
Definition: widl.c:174
static char * idfile_name
Definition: widl.c:148
static void write_dlldata_list(struct list *filenames, int define_proxy_delegation)
Definition: widl.c:376
enum stub_mode get_stub_mode(void)
Definition: widl.c:210
int do_client
Definition: widl.c:119
int debuglevel
Definition: widl.c:109
int pedantic
Definition: widl.c:112
int do_dlldata
Definition: widl.c:123
static int preprocess_only
Definition: widl.c:114
char * header_name
Definition: widl.c:135
char * input_name
Definition: widl.c:132
const char * prefix_client
Definition: widl.c:150
char * temp_name
Definition: widl.c:149
#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