4 * Copyright 2002 Ove Kaaven
5 * based on WRC code by Bertho Stultiens
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.
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.
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
23 #include "wine/port.h"
46 static 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 " --nostdinc Do not search the standard include path\n"
64 " --ns_prefix Prefix namespaces with ABI namespace\n"
65 " --oldnames Use old naming conventions\n"
66 " -o, --output=NAME Set the output file name\n"
67 " -Otype Type of stubs to generate (-Os, -Oi, -Oif)\n"
68 " -p Generate proxy\n"
69 " --prefix-all=p Prefix names of client stubs / server functions with 'p'\n"
70 " --prefix-client=p Prefix names of client stubs with 'p'\n"
71 " --prefix-server=p Prefix names of server functions with 'p'\n"
72 " -r Generate registration script\n"
73 " -robust Ignored, present for midl compatibility\n"
74 " --sysroot=DIR Prefix include paths with DIR\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 " --winrt Enable Windows Runtime mode\n"
84 "Debug level 'n' is a bitmask with following meaning:\n"
85 " * 0x01 Tell which resource is parsed (verbose mode)\n"
86 " * 0x02 Dump internal structures\n"
87 " * 0x04 Create a parser trace (yydebug=1)\n"
88 " * 0x08 Preprocessor messages\n"
89 " * 0x10 Preprocessor lex messages\n"
90 " * 0x20 Preprocessor yacc trace\n"
93 static const char version_string
[] = "Wine IDL Compiler version " PACKAGE_VERSION
"\n"
94 "Copyright 2002 Ove Kaaven\n";
97 enum target_cpu target_cpu
= CPU_x86
;
98 #elif defined(__x86_64__)
99 enum target_cpu target_cpu
= CPU_x86_64
;
100 #elif defined(__powerpc__)
101 enum target_cpu target_cpu
= CPU_POWERPC
;
102 #elif defined(__arm__)
103 enum target_cpu target_cpu
= CPU_ARM
;
104 #elif defined(__aarch64__)
105 enum target_cpu target_cpu
= CPU_ARM64
;
107 #error Unsupported CPU
110 int debuglevel
= DEBUGLEVEL_NONE
;
111 int parser_debug
, yy_flex_debug
;
114 int do_everything
= 1;
115 static int preprocess_only
= 0;
121 int do_regscript
= 0;
124 static int no_preprocess
= 0;
126 int win32_packing
= 8;
127 int win64_packing
= 8;
129 int use_abi_namespace
= 0;
130 static int stdinc
= 1;
131 static enum stub_mode stub_mode
= MODE_Os
;
134 char *input_idl_name
;
137 char *local_stubs_name
;
147 char *regscript_name
;
148 char *regscript_token
;
149 static char *idfile_name
;
151 const char *prefix_client
= "";
152 const char *prefix_server
= "";
153 static const char *includedir
;
159 unsigned int pointer_size
= 0;
164 OLDNAMES_OPTION
= CHAR_MAX
+ 1,
172 PREFIX_CLIENT_OPTION
,
173 PREFIX_SERVER_OPTION
,
185 static const char short_options
[] =
186 "b:cC:d:D:EhH:I:m:No:O:pP:rsS:tT:uU:VW";
187 static const struct option long_options
[] = {
188 { "acf", 1, NULL
, ACF_OPTION
},
189 { "app_config", 0, NULL
, APP_CONFIG_OPTION
},
190 { "dlldata", 1, NULL
, DLLDATA_OPTION
},
191 { "dlldata-only", 0, NULL
, DLLDATA_ONLY_OPTION
},
192 { "help", 0, NULL
, PRINT_HELP
},
193 { "local-stubs", 1, NULL
, LOCAL_STUBS_OPTION
},
194 { "nostdinc", 0, NULL
, NOSTDINC_OPTION
},
195 { "ns_prefix", 0, NULL
, RT_NS_PREFIX
},
196 { "oldnames", 0, NULL
, OLDNAMES_OPTION
},
197 { "output", 0, NULL
, 'o' },
198 { "prefix-all", 1, NULL
, PREFIX_ALL_OPTION
},
199 { "prefix-client", 1, NULL
, PREFIX_CLIENT_OPTION
},
200 { "prefix-server", 1, NULL
, PREFIX_SERVER_OPTION
},
201 { "robust", 0, NULL
, ROBUST_OPTION
},
202 { "sysroot", 1, NULL
, SYSROOT_OPTION
},
203 { "target", 0, NULL
, 'b' },
204 { "winrt", 0, NULL
, RT_OPTION
},
205 { "win32", 0, NULL
, WIN32_OPTION
},
206 { "win64", 0, NULL
, WIN64_OPTION
},
207 { "win32-align", 1, NULL
, WIN32_ALIGN_OPTION
},
208 { "win64-align", 1, NULL
, WIN64_ALIGN_OPTION
},
212 static void rm_tempfile(void);
214 enum stub_mode
get_stub_mode(void)
216 /* old-style interpreted stubs are not supported on 64-bit */
217 if (stub_mode
== MODE_Oi
&& pointer_size
== 8) return MODE_Oif
;
221 static char *make_token(const char *name
)
227 slash
= strrchr(name
, '/');
229 slash
= strrchr(name
, '\\');
231 if (slash
) name
= slash
+ 1;
233 token
= xstrdup(name
);
234 for (i
=0; token
[i
]; i
++) {
235 if (!isalnum(token
[i
])) token
[i
] = '_';
236 else token
[i
] = tolower(token
[i
]);
241 /* duplicate a basename into a valid C token */
242 static char *dup_basename_token(const char *name
, const char *ext
)
244 char *p
, *ret
= dup_basename( name
, ext
);
245 /* map invalid characters to '_' */
246 for (p
= ret
; *p
; p
++) if (!isalnum(*p
)) *p
= '_';
250 static void add_widl_version_define(void)
252 unsigned int version
;
253 const char *p
= PACKAGE_VERSION
;
256 version
= atoi(p
) * 0x10000;
262 version
+= atoi(p
+ 1) * 0x100;
263 p
= strchr(p
+ 1, '.');
268 version
+= atoi(p
+ 1);
272 char version_str
[11];
273 snprintf(version_str
, sizeof(version_str
), "0x%x", version
);
274 wpp_add_define("__WIDL__", version_str
);
277 wpp_add_define("__WIDL__", NULL
);
280 /* set the target platform */
281 static void set_target( const char *target
)
294 { "amd64", CPU_x86_64
},
295 { "x86_64", CPU_x86_64
},
296 { "powerpc", CPU_POWERPC
},
298 { "armv5", CPU_ARM
},
299 { "armv6", CPU_ARM
},
300 { "armv7", CPU_ARM
},
301 { "armv7a", CPU_ARM
},
302 { "arm64", CPU_ARM64
},
303 { "aarch64", CPU_ARM64
},
307 char *p
, *spec
= xstrdup( target
);
309 /* target specification is in the form CPU-MANUFACTURER-OS or CPU-MANUFACTURER-KERNEL-OS */
311 if (!(p
= strchr( spec
, '-' ))) error( "Invalid target specification '%s'\n", target
);
313 for (i
= 0; i
< ARRAY_SIZE( cpu_names
); i
++)
315 if (!strcmp( cpu_names
[i
].name
, spec
))
317 target_cpu
= cpu_names
[i
].cpu
;
322 error( "Unrecognized CPU '%s'\n", spec
);
325 /* clean things up when aborting on a signal */
326 static void exit_on_signal( int sig
)
328 exit(1); /* this will call the atexit functions */
331 static void set_everything(int x
)
343 void start_cplusplus_guard(FILE *fp
)
345 fprintf(fp
, "#ifdef __cplusplus\n");
346 fprintf(fp
, "extern \"C\" {\n");
347 fprintf(fp
, "#endif\n\n");
350 void end_cplusplus_guard(FILE *fp
)
352 fprintf(fp
, "#ifdef __cplusplus\n");
354 fprintf(fp
, "#endif\n\n");
363 static void add_filename_node(struct list
*list
, const char *name
)
365 filename_node_t
*node
= xmalloc(sizeof *node
);
366 node
->filename
= dup_basename( name
, ".idl" );
367 list_add_tail(list
, &node
->link
);
370 static void free_filename_nodes(struct list
*list
)
372 filename_node_t
*node
, *next
;
373 LIST_FOR_EACH_ENTRY_SAFE(node
, next
, list
, filename_node_t
, link
) {
374 list_remove(&node
->link
);
375 free(node
->filename
);
380 static void write_dlldata_list(struct list
*filenames
, int define_proxy_delegation
)
383 filename_node_t
*node
;
385 dlldata
= fopen(dlldata_name
, "w");
387 error("couldn't open %s: %s\n", dlldata_name
, strerror(errno
));
389 fprintf(dlldata
, "/*** Autogenerated by WIDL %s ", PACKAGE_VERSION
);
390 fprintf(dlldata
, "- Do not edit ***/\n\n");
391 if (define_proxy_delegation
)
392 fprintf(dlldata
, "#define PROXY_DELEGATION\n");
393 fprintf(dlldata
, "#include <objbase.h>\n");
394 fprintf(dlldata
, "#include <rpcproxy.h>\n\n");
395 start_cplusplus_guard(dlldata
);
397 LIST_FOR_EACH_ENTRY(node
, filenames
, filename_node_t
, link
)
398 fprintf(dlldata
, "EXTERN_PROXY_FILE(%s)\n", node
->filename
);
400 fprintf(dlldata
, "\nPROXYFILE_LIST_START\n");
401 fprintf(dlldata
, "/* Start of list */\n");
402 LIST_FOR_EACH_ENTRY(node
, filenames
, filename_node_t
, link
)
403 fprintf(dlldata
, " REFERENCE_PROXY_FILE(%s),\n", node
->filename
);
404 fprintf(dlldata
, "/* End of list */\n");
405 fprintf(dlldata
, "PROXYFILE_LIST_END\n\n");
407 fprintf(dlldata
, "DLLDATA_ROUTINES(aProxyFileList, GET_DLL_CLSID)\n\n");
408 end_cplusplus_guard(dlldata
);
412 static char *eat_space(char *s
)
414 while (isspace((unsigned char) *s
))
419 void write_dlldata(const statement_list_t
*stmts
)
421 struct list filenames
= LIST_INIT(filenames
);
422 int define_proxy_delegation
= 0;
423 filename_node_t
*node
;
426 if (!do_dlldata
|| !need_proxy_file(stmts
))
429 define_proxy_delegation
= need_proxy_delegation(stmts
);
431 dlldata
= fopen(dlldata_name
, "r");
433 static const char marker
[] = "REFERENCE_PROXY_FILE";
434 static const char delegation_define
[] = "#define PROXY_DELEGATION";
438 while (widl_getline(&line
, &len
, dlldata
)) {
440 start
= eat_space(line
);
441 if (strncmp(start
, marker
, sizeof marker
- 1) == 0) {
442 start
= eat_space(start
+ sizeof marker
- 1);
445 end
= start
= eat_space(start
+ 1);
446 while (*end
&& *end
!= ')')
450 while (isspace((unsigned char) end
[-1]))
454 add_filename_node(&filenames
, start
);
455 }else if (!define_proxy_delegation
&& strncmp(start
, delegation_define
, sizeof(delegation_define
)-1)) {
456 define_proxy_delegation
= 1;
461 error("couldn't read from %s: %s\n", dlldata_name
, strerror(errno
));
467 LIST_FOR_EACH_ENTRY(node
, &filenames
, filename_node_t
, link
)
468 if (strcmp(proxy_token
, node
->filename
) == 0) {
469 /* We're already in the list, no need to regenerate this file. */
470 free_filename_nodes(&filenames
);
474 add_filename_node(&filenames
, proxy_token
);
475 write_dlldata_list(&filenames
, define_proxy_delegation
);
476 free_filename_nodes(&filenames
);
479 static void write_id_guid(FILE *f
, const char *type
, const char *guid_prefix
, const char *name
, const UUID
*uuid
)
482 fprintf(f
, "MIDL_DEFINE_GUID(%s, %s_%s, 0x%08x, 0x%04x, 0x%04x, 0x%02x,0x%02x, 0x%02x,"
483 "0x%02x,0x%02x,0x%02x,0x%02x,0x%02x);\n",
484 type
, guid_prefix
, name
, uuid
->Data1
, uuid
->Data2
, uuid
->Data3
, uuid
->Data4
[0],
485 uuid
->Data4
[1], uuid
->Data4
[2], uuid
->Data4
[3], uuid
->Data4
[4], uuid
->Data4
[5],
486 uuid
->Data4
[6], uuid
->Data4
[7]);
489 static void write_id_data_stmts(const statement_list_t
*stmts
)
491 const statement_t
*stmt
;
492 if (stmts
) LIST_FOR_EACH_ENTRY( stmt
, stmts
, const statement_t
, entry
)
494 if (stmt
->type
== STMT_TYPE
)
496 const type_t
*type
= stmt
->u
.type
;
497 if (type_get_type(type
) == TYPE_INTERFACE
)
500 if (!is_object(type
) && !is_attr(type
->attrs
, ATTR_DISPINTERFACE
))
502 uuid
= get_attrp(type
->attrs
, ATTR_UUID
);
503 write_id_guid(idfile
, "IID", is_attr(type
->attrs
, ATTR_DISPINTERFACE
) ? "DIID" : "IID",
505 if (type_iface_get_async_iface(type
))
507 uuid
= get_attrp(type_iface_get_async_iface(type
)->attrs
, ATTR_UUID
);
508 write_id_guid(idfile
, "IID", "IID", type_iface_get_async_iface(type
)->name
, uuid
);
511 else if (type_get_type(type
) == TYPE_COCLASS
)
513 const UUID
*uuid
= get_attrp(type
->attrs
, ATTR_UUID
);
514 write_id_guid(idfile
, "CLSID", "CLSID", type
->name
, uuid
);
517 else if (stmt
->type
== STMT_LIBRARY
)
519 const UUID
*uuid
= get_attrp(stmt
->u
.lib
->attrs
, ATTR_UUID
);
520 write_id_guid(idfile
, "IID", "LIBID", stmt
->u
.lib
->name
, uuid
);
521 write_id_data_stmts(stmt
->u
.lib
->stmts
);
526 void write_id_data(const statement_list_t
*stmts
)
528 if (!do_idfile
) return;
530 idfile
= fopen(idfile_name
, "w");
532 error("Could not open %s for output\n", idfile_name
);
536 fprintf(idfile
, "/*** Autogenerated by WIDL %s ", PACKAGE_VERSION
);
537 fprintf(idfile
, "from %s - Do not edit ***/\n\n", input_idl_name
);
538 fprintf(idfile
, "#include <rpc.h>\n");
539 fprintf(idfile
, "#include <rpcndr.h>\n\n");
541 fprintf(idfile
, "#ifdef _MIDL_USE_GUIDDEF_\n\n");
543 fprintf(idfile
, "#ifndef INITGUID\n");
544 fprintf(idfile
, "#define INITGUID\n");
545 fprintf(idfile
, "#include <guiddef.h>\n");
546 fprintf(idfile
, "#undef INITGUID\n");
547 fprintf(idfile
, "#else\n");
548 fprintf(idfile
, "#include <guiddef.h>\n");
549 fprintf(idfile
, "#endif\n\n");
551 fprintf(idfile
, "#define MIDL_DEFINE_GUID(type,name,l,w1,w2,b1,b2,b3,b4,b5,b6,b7,b8) \\\n");
552 fprintf(idfile
, " DEFINE_GUID(name,l,w1,w2,b1,b2,b3,b4,b5,b6,b7,b8)\n\n");
554 fprintf(idfile
, "#elif defined(__cplusplus)\n\n");
556 fprintf(idfile
, "#define MIDL_DEFINE_GUID(type,name,l,w1,w2,b1,b2,b3,b4,b5,b6,b7,b8) \\\n");
557 fprintf(idfile
, " EXTERN_C const type DECLSPEC_SELECTANY name = {l,w1,w2,{b1,b2,b3,b4,b5,b6,b7,b8}}\n\n");
559 fprintf(idfile
, "#else\n\n");
561 fprintf(idfile
, "#define MIDL_DEFINE_GUID(type,name,l,w1,w2,b1,b2,b3,b4,b5,b6,b7,b8) \\\n");
562 fprintf(idfile
, " const type DECLSPEC_SELECTANY name = {l,w1,w2,{b1,b2,b3,b4,b5,b6,b7,b8}}\n\n");
564 fprintf(idfile
, "#endif\n\n");
565 start_cplusplus_guard(idfile
);
567 write_id_data_stmts(stmts
);
569 fprintf(idfile
, "\n");
570 end_cplusplus_guard(idfile
);
571 fprintf(idfile
, "#undef MIDL_DEFINE_GUID\n" );
576 static void init_argv0_dir( const char *argv0
)
581 #if defined(__linux__) || defined(__FreeBSD_kernel__) || defined(__NetBSD__)
582 dir
= realpath( "/proc/self/exe", NULL
);
583 #elif defined (__FreeBSD__) || defined(__DragonFly__)
584 dir
= realpath( "/proc/curproc/file", NULL
);
586 dir
= realpath( argv0
, NULL
);
589 if (!(p
= strrchr( dir
, '/' ))) return;
592 includedir
= strmake( "%s/%s", dir
, BIN_TO_INCLUDEDIR
);
597 int main(int argc
,char *argv
[])
602 char *output_name
= NULL
;
603 const char *sysroot
= "";
605 signal( SIGTERM
, exit_on_signal
);
606 signal( SIGINT
, exit_on_signal
);
608 signal( SIGHUP
, exit_on_signal
);
610 init_argv0_dir( argv
[0] );
614 while((optc
= getopt_long_only(argc
, argv
, short_options
, long_options
, &opti
)) != EOF
) {
617 dlldata_name
= xstrdup(optarg
);
619 case DLLDATA_ONLY_OPTION
:
623 case LOCAL_STUBS_OPTION
:
625 local_stubs_name
= xstrdup(optarg
);
627 case NOSTDINC_OPTION
:
630 case OLDNAMES_OPTION
:
633 case PREFIX_ALL_OPTION
:
634 prefix_client
= xstrdup(optarg
);
635 prefix_server
= xstrdup(optarg
);
637 case PREFIX_CLIENT_OPTION
:
638 prefix_client
= xstrdup(optarg
);
640 case PREFIX_SERVER_OPTION
:
641 prefix_server
= xstrdup(optarg
);
644 fprintf(stderr
, "%s", usage
);
650 use_abi_namespace
= 1;
653 sysroot
= xstrdup(optarg
);
661 case WIN32_ALIGN_OPTION
:
662 win32_packing
= strtol(optarg
, NULL
, 0);
663 if(win32_packing
!= 2 && win32_packing
!= 4 && win32_packing
!= 8)
664 error("Packing must be one of 2, 4 or 8\n");
666 case WIN64_ALIGN_OPTION
:
667 win64_packing
= strtol(optarg
, NULL
, 0);
668 if(win64_packing
!= 2 && win64_packing
!= 4 && win64_packing
!= 8)
669 error("Packing must be one of 2, 4 or 8\n");
672 acf_name
= xstrdup(optarg
);
674 case APP_CONFIG_OPTION
:
675 /* widl does not distinguish between app_mode and default mode,
676 but we ignore this option for midl compatibility */
679 /* FIXME: Support robust option */
682 set_target( optarg
);
689 client_name
= xstrdup(optarg
);
692 debuglevel
= strtol(optarg
, NULL
, 0);
695 wpp_add_cmdline_define(optarg
);
706 header_name
= xstrdup(optarg
);
709 wpp_add_include_path(optarg
);
712 if (!strcmp( optarg
, "32" )) pointer_size
= 4;
713 else if (!strcmp( optarg
, "64" )) pointer_size
= 8;
719 output_name
= xstrdup(optarg
);
722 if (!strcmp( optarg
, "s" )) stub_mode
= MODE_Os
;
723 else if (!strcmp( optarg
, "i" )) stub_mode
= MODE_Oi
;
724 else if (!strcmp( optarg
, "ic" )) stub_mode
= MODE_Oif
;
725 else if (!strcmp( optarg
, "if" )) stub_mode
= MODE_Oif
;
726 else if (!strcmp( optarg
, "icf" )) stub_mode
= MODE_Oif
;
727 else error( "Invalid argument '-O%s'\n", optarg
);
734 proxy_name
= xstrdup(optarg
);
745 server_name
= xstrdup(optarg
);
752 typelib_name
= xstrdup(optarg
);
759 idfile_name
= xstrdup(optarg
);
762 printf("%s", version_string
);
768 fprintf(stderr
, "%s", usage
);
775 static const char *incl_dirs
[] = { INCLUDEDIR
, "/usr/include", "/usr/local/include" };
779 wpp_add_include_path( strmake( "%s/wine/msvcrt", includedir
));
780 wpp_add_include_path( strmake( "%s/wine/windows", includedir
));
782 for (i
= 0; i
< ARRAY_SIZE(incl_dirs
); i
++)
784 if (i
&& !strcmp( incl_dirs
[i
], incl_dirs
[0] )) continue;
785 wpp_add_include_path( strmake( "%s%s/wine/msvcrt", sysroot
, incl_dirs
[i
] ));
786 wpp_add_include_path( strmake( "%s%s/wine/windows", sysroot
, incl_dirs
[i
] ));
793 if (pointer_size
== 8) target_cpu
= CPU_x86_64
;
794 else pointer_size
= 4;
797 if (pointer_size
== 4) target_cpu
= CPU_x86
;
798 else pointer_size
= 8;
801 if (pointer_size
== 4) error( "Cannot build 32-bit code for this CPU\n" );
805 if (pointer_size
== 8) error( "Cannot build 64-bit code for this CPU\n" );
810 /* if nothing specified, try to guess output type from the output file name */
811 if (output_name
&& do_everything
&& !do_header
&& !do_typelib
&& !do_proxies
&&
812 !do_client
&& !do_server
&& !do_regscript
&& !do_idfile
&& !do_dlldata
)
815 if (strendswith( output_name
, ".h" )) do_header
= 1;
816 else if (strendswith( output_name
, ".tlb" )) do_typelib
= 1;
817 else if (strendswith( output_name
, "_p.c" )) do_proxies
= 1;
818 else if (strendswith( output_name
, "_c.c" )) do_client
= 1;
819 else if (strendswith( output_name
, "_s.c" )) do_server
= 1;
820 else if (strendswith( output_name
, "_i.c" )) do_idfile
= 1;
821 else if (strendswith( output_name
, "_r.res" )) do_regscript
= 1;
822 else if (strendswith( output_name
, "_t.res" )) do_typelib
= 1;
823 else if (strendswith( output_name
, "dlldata.c" )) do_dlldata
= 1;
824 else do_everything
= 1;
828 set_everything(TRUE
);
831 if (!output_name
) output_name
= dup_basename(input_name
, ".idl");
833 if (do_header
+ do_typelib
+ do_proxies
+ do_client
+
834 do_server
+ do_regscript
+ do_idfile
+ do_dlldata
== 1)
836 if (do_header
) header_name
= output_name
;
837 else if (do_typelib
) typelib_name
= output_name
;
838 else if (do_proxies
) proxy_name
= output_name
;
839 else if (do_client
) client_name
= output_name
;
840 else if (do_server
) server_name
= output_name
;
841 else if (do_regscript
) regscript_name
= output_name
;
842 else if (do_idfile
) idfile_name
= output_name
;
843 else if (do_dlldata
) dlldata_name
= output_name
;
846 if (!dlldata_name
&& do_dlldata
)
847 dlldata_name
= xstrdup("dlldata.c");
850 if (do_dlldata
&& !do_everything
) {
851 struct list filenames
= LIST_INIT(filenames
);
852 for ( ; optind
< argc
; ++optind
)
853 add_filename_node(&filenames
, argv
[optind
]);
855 write_dlldata_list(&filenames
, 0 /* FIXME */ );
856 free_filename_nodes(&filenames
);
859 else if (optind
!= argc
- 1) {
860 fprintf(stderr
, "%s", usage
);
864 input_idl_name
= input_name
= xstrdup(argv
[optind
]);
867 fprintf(stderr
, "%s", usage
);
873 setbuf(stdout
, NULL
);
874 setbuf(stderr
, NULL
);
877 parser_debug
= debuglevel
& DEBUGLEVEL_TRACE
? 1 : 0;
878 yy_flex_debug
= debuglevel
& DEBUGLEVEL_TRACE
? 1 : 0;
880 wpp_set_debug( (debuglevel
& DEBUGLEVEL_PPLEX
) != 0,
881 (debuglevel
& DEBUGLEVEL_PPTRACE
) != 0,
882 (debuglevel
& DEBUGLEVEL_PPMSG
) != 0 );
885 header_name
= dup_basename(input_name
, ".idl");
886 strcat(header_name
, ".h");
889 if (!typelib_name
&& do_typelib
) {
890 typelib_name
= dup_basename(input_name
, ".idl");
891 strcat(typelib_name
, ".tlb");
894 if (!proxy_name
&& do_proxies
) {
895 proxy_name
= dup_basename(input_name
, ".idl");
896 strcat(proxy_name
, "_p.c");
899 if (!client_name
&& do_client
) {
900 client_name
= dup_basename(input_name
, ".idl");
901 strcat(client_name
, "_c.c");
904 if (!server_name
&& do_server
) {
905 server_name
= dup_basename(input_name
, ".idl");
906 strcat(server_name
, "_s.c");
909 if (!regscript_name
&& do_regscript
) {
910 regscript_name
= dup_basename(input_name
, ".idl");
911 strcat(regscript_name
, "_r.rgs");
914 if (!idfile_name
&& do_idfile
) {
915 idfile_name
= dup_basename(input_name
, ".idl");
916 strcat(idfile_name
, "_i.c");
919 if (do_proxies
) proxy_token
= dup_basename_token(proxy_name
,"_p.c");
920 if (do_client
) client_token
= dup_basename_token(client_name
,"_c.c");
921 if (do_server
) server_token
= dup_basename_token(server_name
,"_s.c");
922 if (do_regscript
) regscript_token
= dup_basename_token(regscript_name
,"_r.rgs");
924 add_widl_version_define();
925 wpp_add_define("_WIN32", NULL
);
930 chat("Starting preprocess\n");
932 if (!preprocess_only
)
936 char *name
= xmalloc( strlen(header_name
) + 8 );
938 strcpy( name
, header_name
);
939 strcat( name
, ".XXXXXX" );
941 if ((fd
= mkstemps( name
, 0 )) == -1)
942 error("Could not generate a temp name from %s\n", name
);
945 if (!(output
= fdopen(fd
, "wt")))
946 error("Could not open fd %s for writing\n", name
);
948 ret
= wpp_parse( input_name
, output
);
953 ret
= wpp_parse( input_name
, stdout
);
957 if(preprocess_only
) exit(0);
958 if(!(parser_in
= fopen(temp_name
, "r"))) {
959 fprintf(stderr
, "Could not open %s for input\n", temp_name
);
964 if(!(parser_in
= fopen(input_name
, "r"))) {
965 fprintf(stderr
, "Could not open %s for input\n", input_name
);
970 header_token
= make_token(header_name
);
973 ret
= parser_parse();
981 /* Everything has been done successfully, don't delete any files. */
982 set_everything(FALSE
);
983 local_stubs_name
= NULL
;
988 static void rm_tempfile(void)
995 if (local_stubs_name
)
996 unlink(local_stubs_name
);
1000 unlink(server_name
);
1002 unlink(regscript_name
);
1004 unlink(idfile_name
);
1008 unlink(typelib_name
);