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
33 #include <sys/types.h>
34 #ifdef HAVE_SYS_SYSCTL_H
35 # include <sys/sysctl.h>
41 #include "wpp_private.h"
44 static const char usage
[] =
45 "Usage: widl [options...] infile.idl\n"
46 " or: widl [options...] --dlldata-only name1 [name2...]\n"
47 " --acf=file Use ACF file\n"
48 " -app_config Ignored, present for midl compatibility\n"
49 " -b arch Set the target architecture\n"
50 " -c Generate client stub\n"
51 " -d n Set debug level to 'n'\n"
52 " -D id[=val] Define preprocessor identifier id=val\n"
53 " -E Preprocess only\n"
54 " --help Display this help and exit\n"
55 " -h Generate headers\n"
56 " -H file Name of header file (default is infile.h)\n"
57 " -I directory Add directory to the include search path (multiple -I allowed)\n"
58 " -L directory Add directory to the library search path (multiple -L allowed)\n"
59 " --local-stubs=file Write empty stubs for call_as/local methods to file\n"
60 " -m32, -m64 Set the target architecture (Win32 or Win64)\n"
61 " -N Do not preprocess input\n"
62 " --nostdinc Do not search the standard include path\n"
63 " --ns_prefix Prefix namespaces with ABI namespace\n"
64 " --oldnames Use old naming conventions\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 " --sysroot=DIR Prefix include paths with DIR\n"
74 " -s Generate server stub\n"
75 " -t Generate typelib\n"
76 " -u Generate interface identifiers file\n"
77 " -V Print version and exit\n"
78 " -W Enable pedantic warnings\n"
79 " --win32, --win64 Set the target architecture (Win32 or Win64)\n"
80 " --win32-align n Set win32 structure alignment to 'n'\n"
81 " --win64-align n Set win64 structure alignment to 'n'\n"
82 " --winrt Enable Windows Runtime mode\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"
92 static const char version_string
[] = "Wine IDL Compiler version " PACKAGE_VERSION
"\n"
93 "Copyright 2002 Ove Kaaven\n";
95 static struct target target
;
97 int debuglevel
= DEBUGLEVEL_NONE
;
98 int parser_debug
, yy_flex_debug
;
101 int do_everything
= 1;
102 static int preprocess_only
= 0;
108 int do_regscript
= 0;
111 static int no_preprocess
= 0;
113 int win32_packing
= 8;
114 int win64_packing
= 8;
116 int use_abi_namespace
= 0;
117 static int stdinc
= 1;
118 static enum stub_mode stub_mode
= MODE_Os
;
121 char *input_idl_name
;
124 char *local_stubs_name
;
134 char *regscript_name
;
135 char *regscript_token
;
136 static char *idfile_name
;
138 const char *prefix_client
= "";
139 const char *prefix_server
= "";
140 static const char *includedir
;
141 static const char *dlldir
;
142 static struct strarray dlldirs
;
143 static char *output_name
;
144 static const char *sysroot
= "";
150 unsigned int pointer_size
= 0;
155 OLDNAMES_OPTION
= CHAR_MAX
+ 1,
163 PREFIX_CLIENT_OPTION
,
164 PREFIX_SERVER_OPTION
,
176 static const char short_options
[] =
177 "b:cC:d:D:EhH:I:L:m:No:O:pP:rsS:tT:uU:VW";
178 static const struct long_option long_options
[] = {
179 { "acf", 1, ACF_OPTION
},
180 { "app_config", 0, APP_CONFIG_OPTION
},
181 { "dlldata", 1, DLLDATA_OPTION
},
182 { "dlldata-only", 0, DLLDATA_ONLY_OPTION
},
183 { "help", 0, PRINT_HELP
},
184 { "local-stubs", 1, LOCAL_STUBS_OPTION
},
185 { "nostdinc", 0, NOSTDINC_OPTION
},
186 { "ns_prefix", 0, RT_NS_PREFIX
},
187 { "oldnames", 0, OLDNAMES_OPTION
},
188 { "output", 0, 'o' },
189 { "prefix-all", 1, PREFIX_ALL_OPTION
},
190 { "prefix-client", 1, PREFIX_CLIENT_OPTION
},
191 { "prefix-server", 1, PREFIX_SERVER_OPTION
},
192 { "robust", 0, ROBUST_OPTION
},
193 { "sysroot", 1, SYSROOT_OPTION
},
194 { "target", 0, 'b' },
195 { "winrt", 0, RT_OPTION
},
196 { "win32", 0, WIN32_OPTION
},
197 { "win64", 0, WIN64_OPTION
},
198 { "win32-align", 1, WIN32_ALIGN_OPTION
},
199 { "win64-align", 1, WIN64_ALIGN_OPTION
},
203 static void rm_tempfile(void);
205 enum stub_mode
get_stub_mode(void)
207 /* old-style interpreted stubs are not supported on 64-bit */
208 if (stub_mode
== MODE_Oi
&& pointer_size
== 8) return MODE_Oif
;
212 static char *make_token(const char *name
)
217 token
= get_basename( name
);
218 for (i
=0; token
[i
]; i
++) {
219 if (!isalnum(token
[i
])) token
[i
] = '_';
220 else token
[i
] = tolower(token
[i
]);
225 /* duplicate a basename into a valid C token */
226 static char *dup_basename_token(const char *name
, const char *ext
)
228 char *p
, *ret
= replace_extension( get_basename(name
), ext
, "" );
229 /* map invalid characters to '_' */
230 for (p
= ret
; *p
; p
++) if (!isalnum(*p
)) *p
= '_';
234 static void add_widl_version_define(void)
236 char version_str
[32];
237 unsigned int version
;
238 const char *p
= PACKAGE_VERSION
;
241 version
= atoi(p
) * 0x10000;
247 version
+= atoi(p
+ 1) * 0x100;
248 p
= strchr(p
+ 1, '.');
253 version
+= atoi(p
+ 1);
255 sprintf(version_str
, "__WIDL__=0x%x", version
);
256 wpp_add_cmdline_define(version_str
);
259 /* clean things up when aborting on a signal */
260 static void exit_on_signal( int sig
)
262 exit(1); /* this will call the atexit functions */
265 static void set_everything(int x
)
277 void start_cplusplus_guard(FILE *fp
)
279 fprintf(fp
, "#ifdef __cplusplus\n");
280 fprintf(fp
, "extern \"C\" {\n");
281 fprintf(fp
, "#endif\n\n");
284 void end_cplusplus_guard(FILE *fp
)
286 fprintf(fp
, "#ifdef __cplusplus\n");
288 fprintf(fp
, "#endif\n\n");
291 static void write_dlldata_list( struct strarray filenames
, int define_proxy_delegation
)
296 dlldata
= fopen(dlldata_name
, "w");
298 error("couldn't open %s: %s\n", dlldata_name
, strerror(errno
));
300 fprintf(dlldata
, "/*** Autogenerated by WIDL %s ", PACKAGE_VERSION
);
301 fprintf(dlldata
, "- Do not edit ***/\n\n");
302 if (define_proxy_delegation
)
303 fprintf(dlldata
, "#define PROXY_DELEGATION\n");
304 fprintf(dlldata
, "#include <objbase.h>\n");
305 fprintf(dlldata
, "#include <rpcproxy.h>\n\n");
306 start_cplusplus_guard(dlldata
);
308 for (i
= 0; i
< filenames
.count
; i
++)
309 fprintf(dlldata
, "EXTERN_PROXY_FILE(%s)\n", filenames
.str
[i
]);
311 fprintf(dlldata
, "\nPROXYFILE_LIST_START\n");
312 fprintf(dlldata
, "/* Start of list */\n");
313 for (i
= 0; i
< filenames
.count
; i
++)
314 fprintf(dlldata
, " REFERENCE_PROXY_FILE(%s),\n", filenames
.str
[i
]);
315 fprintf(dlldata
, "/* End of list */\n");
316 fprintf(dlldata
, "PROXYFILE_LIST_END\n\n");
318 fprintf(dlldata
, "DLLDATA_ROUTINES(aProxyFileList, GET_DLL_CLSID)\n\n");
319 end_cplusplus_guard(dlldata
);
323 static char *eat_space(char *s
)
325 while (isspace((unsigned char) *s
))
330 void write_dlldata(const statement_list_t
*stmts
)
332 struct strarray filenames
= empty_strarray
;
333 int define_proxy_delegation
= 0;
336 if (!do_dlldata
|| !need_proxy_file(stmts
))
339 define_proxy_delegation
= need_proxy_delegation(stmts
);
341 dlldata
= fopen(dlldata_name
, "r");
343 static const char marker
[] = "REFERENCE_PROXY_FILE";
344 static const char delegation_define
[] = "#define PROXY_DELEGATION";
348 while (widl_getline(&line
, &len
, dlldata
)) {
350 start
= eat_space(line
);
351 if (strncmp(start
, marker
, sizeof marker
- 1) == 0) {
352 start
= eat_space(start
+ sizeof marker
- 1);
355 end
= start
= eat_space(start
+ 1);
356 while (*end
&& *end
!= ')')
360 while (isspace((unsigned char) end
[-1]))
364 strarray_add(&filenames
, replace_extension( get_basename( start
), ".idl", "" ));
365 }else if (!define_proxy_delegation
&& strncmp(start
, delegation_define
, sizeof(delegation_define
)-1)) {
366 define_proxy_delegation
= 1;
371 error("couldn't read from %s: %s\n", dlldata_name
, strerror(errno
));
377 if (strarray_exists( &filenames
, proxy_token
))
378 /* We're already in the list, no need to regenerate this file. */
381 strarray_add(&filenames
, proxy_token
);
382 write_dlldata_list(filenames
, define_proxy_delegation
);
385 static void write_id_guid(FILE *f
, const char *type
, const char *guid_prefix
, const char *name
, const UUID
*uuid
)
388 fprintf(f
, "MIDL_DEFINE_GUID(%s, %s_%s, 0x%08x, 0x%04x, 0x%04x, 0x%02x,0x%02x, 0x%02x,"
389 "0x%02x,0x%02x,0x%02x,0x%02x,0x%02x);\n",
390 type
, guid_prefix
, name
, uuid
->Data1
, uuid
->Data2
, uuid
->Data3
, uuid
->Data4
[0],
391 uuid
->Data4
[1], uuid
->Data4
[2], uuid
->Data4
[3], uuid
->Data4
[4], uuid
->Data4
[5],
392 uuid
->Data4
[6], uuid
->Data4
[7]);
395 static void write_id_data_stmts(const statement_list_t
*stmts
)
397 const statement_t
*stmt
;
398 if (stmts
) LIST_FOR_EACH_ENTRY( stmt
, stmts
, const statement_t
, entry
)
400 if (stmt
->type
== STMT_TYPE
)
402 const type_t
*type
= stmt
->u
.type
;
403 if (type_get_type(type
) == TYPE_INTERFACE
)
406 if (!is_object(type
) && !is_attr(type
->attrs
, ATTR_DISPINTERFACE
))
408 uuid
= get_attrp(type
->attrs
, ATTR_UUID
);
409 write_id_guid(idfile
, "IID", is_attr(type
->attrs
, ATTR_DISPINTERFACE
) ? "DIID" : "IID",
411 if (type_iface_get_async_iface(type
))
413 uuid
= get_attrp(type_iface_get_async_iface(type
)->attrs
, ATTR_UUID
);
414 write_id_guid(idfile
, "IID", "IID", type_iface_get_async_iface(type
)->name
, uuid
);
417 else if (type_get_type(type
) == TYPE_COCLASS
)
419 const UUID
*uuid
= get_attrp(type
->attrs
, ATTR_UUID
);
420 write_id_guid(idfile
, "CLSID", "CLSID", type
->name
, uuid
);
423 else if (stmt
->type
== STMT_LIBRARY
)
425 const UUID
*uuid
= get_attrp(stmt
->u
.lib
->attrs
, ATTR_UUID
);
426 write_id_guid(idfile
, "IID", "LIBID", stmt
->u
.lib
->name
, uuid
);
427 write_id_data_stmts(stmt
->u
.lib
->stmts
);
432 void write_id_data(const statement_list_t
*stmts
)
434 if (!do_idfile
) return;
436 idfile
= fopen(idfile_name
, "w");
438 error("Could not open %s for output\n", idfile_name
);
442 fprintf(idfile
, "/*** Autogenerated by WIDL %s ", PACKAGE_VERSION
);
443 fprintf(idfile
, "from %s - Do not edit ***/\n\n", input_idl_name
);
444 fprintf(idfile
, "#include <rpc.h>\n");
445 fprintf(idfile
, "#include <rpcndr.h>\n\n");
447 fprintf(idfile
, "#ifdef _MIDL_USE_GUIDDEF_\n\n");
449 fprintf(idfile
, "#ifndef INITGUID\n");
450 fprintf(idfile
, "#define INITGUID\n");
451 fprintf(idfile
, "#include <guiddef.h>\n");
452 fprintf(idfile
, "#undef INITGUID\n");
453 fprintf(idfile
, "#else\n");
454 fprintf(idfile
, "#include <guiddef.h>\n");
455 fprintf(idfile
, "#endif\n\n");
457 fprintf(idfile
, "#define MIDL_DEFINE_GUID(type,name,l,w1,w2,b1,b2,b3,b4,b5,b6,b7,b8) \\\n");
458 fprintf(idfile
, " DEFINE_GUID(name,l,w1,w2,b1,b2,b3,b4,b5,b6,b7,b8)\n\n");
460 fprintf(idfile
, "#elif defined(__cplusplus)\n\n");
462 fprintf(idfile
, "#define MIDL_DEFINE_GUID(type,name,l,w1,w2,b1,b2,b3,b4,b5,b6,b7,b8) \\\n");
463 fprintf(idfile
, " EXTERN_C const type DECLSPEC_SELECTANY name = {l,w1,w2,{b1,b2,b3,b4,b5,b6,b7,b8}}\n\n");
465 fprintf(idfile
, "#else\n\n");
467 fprintf(idfile
, "#define MIDL_DEFINE_GUID(type,name,l,w1,w2,b1,b2,b3,b4,b5,b6,b7,b8) \\\n");
468 fprintf(idfile
, " const type DECLSPEC_SELECTANY name = {l,w1,w2,{b1,b2,b3,b4,b5,b6,b7,b8}}\n\n");
470 fprintf(idfile
, "#endif\n\n");
471 start_cplusplus_guard(idfile
);
473 write_id_data_stmts(stmts
);
475 fprintf(idfile
, "\n");
476 end_cplusplus_guard(idfile
);
477 fprintf(idfile
, "#undef MIDL_DEFINE_GUID\n" );
482 static void init_argv0_dir( const char *argv0
)
487 #if defined(__linux__) || defined(__FreeBSD_kernel__) || defined(__NetBSD__)
488 dir
= realpath( "/proc/self/exe", NULL
);
489 #elif defined (__FreeBSD__) || defined(__DragonFly__)
490 static int pathname
[] = { CTL_KERN
, KERN_PROC
, KERN_PROC_PATHNAME
, -1 };
491 size_t path_size
= PATH_MAX
;
492 char *path
= malloc( path_size
);
493 if (path
&& !sysctl( pathname
, sizeof(pathname
)/sizeof(pathname
[0]), path
, &path_size
, NULL
, 0 ))
494 dir
= realpath( path
, NULL
);
497 dir
= realpath( argv0
, NULL
);
500 includedir
= strmake( "%s/%s", get_dirname( dir
), BIN_TO_INCLUDEDIR
);
501 dlldir
= strmake( "%s/%s", get_dirname( dir
), BIN_TO_DLLDIR
);
505 static void option_callback( int optc
, char *optarg
)
510 dlldata_name
= xstrdup(optarg
);
512 case DLLDATA_ONLY_OPTION
:
516 case LOCAL_STUBS_OPTION
:
518 local_stubs_name
= xstrdup(optarg
);
520 case NOSTDINC_OPTION
:
523 case OLDNAMES_OPTION
:
526 case PREFIX_ALL_OPTION
:
527 prefix_client
= xstrdup(optarg
);
528 prefix_server
= xstrdup(optarg
);
530 case PREFIX_CLIENT_OPTION
:
531 prefix_client
= xstrdup(optarg
);
533 case PREFIX_SERVER_OPTION
:
534 prefix_server
= xstrdup(optarg
);
537 fprintf(stderr
, "%s", usage
);
543 use_abi_namespace
= 1;
546 sysroot
= xstrdup(optarg
);
554 case WIN32_ALIGN_OPTION
:
555 win32_packing
= strtol(optarg
, NULL
, 0);
556 if(win32_packing
!= 2 && win32_packing
!= 4 && win32_packing
!= 8)
557 error("Packing must be one of 2, 4 or 8\n");
559 case WIN64_ALIGN_OPTION
:
560 win64_packing
= strtol(optarg
, NULL
, 0);
561 if(win64_packing
!= 2 && win64_packing
!= 4 && win64_packing
!= 8)
562 error("Packing must be one of 2, 4 or 8\n");
565 acf_name
= xstrdup(optarg
);
567 case APP_CONFIG_OPTION
:
568 /* widl does not distinguish between app_mode and default mode,
569 but we ignore this option for midl compatibility */
572 /* FIXME: Support robust option */
575 if (!parse_target( optarg
, &target
))
576 error( "Invalid target specification '%s'\n", optarg
);
583 client_name
= xstrdup(optarg
);
586 debuglevel
= strtol(optarg
, NULL
, 0);
589 wpp_add_cmdline_define(optarg
);
600 header_name
= xstrdup(optarg
);
603 wpp_add_include_path(optarg
);
606 strarray_add( &dlldirs
, optarg
);
609 if (!strcmp( optarg
, "32" )) pointer_size
= 4;
610 else if (!strcmp( optarg
, "64" )) pointer_size
= 8;
616 output_name
= xstrdup(optarg
);
619 if (!strcmp( optarg
, "s" )) stub_mode
= MODE_Os
;
620 else if (!strcmp( optarg
, "i" )) stub_mode
= MODE_Oi
;
621 else if (!strcmp( optarg
, "ic" )) stub_mode
= MODE_Oif
;
622 else if (!strcmp( optarg
, "if" )) stub_mode
= MODE_Oif
;
623 else if (!strcmp( optarg
, "icf" )) stub_mode
= MODE_Oif
;
624 else error( "Invalid argument '-O%s'\n", optarg
);
631 proxy_name
= xstrdup(optarg
);
642 server_name
= xstrdup(optarg
);
649 typelib_name
= xstrdup(optarg
);
656 idfile_name
= xstrdup(optarg
);
659 printf("%s", version_string
);
665 fprintf(stderr
, "widl: %s\n\n%s", optarg
, usage
);
670 int open_typelib( const char *name
)
672 static const char *default_dirs
[] = { DLLDIR
, "/usr/lib/wine", "/usr/local/lib/wine" };
673 struct target win_target
= { target
.cpu
, PLATFORM_WINDOWS
};
674 const char *pe_dir
= get_arch_dir( win_target
);
678 #define TRYOPEN(str) do { \
680 if ((fd = open( file, O_RDONLY | O_BINARY )) != -1) return fd; \
681 free( file ); } while(0)
683 for (i
= 0; i
< dlldirs
.count
; i
++)
685 if (strendswith( dlldirs
.str
[i
], "/*" )) /* special case for wine build tree */
687 int namelen
= strlen( name
);
688 if (strendswith( name
, ".dll" )) namelen
-= 4;
689 TRYOPEN( strmake( "%.*s/%.*s/%s", (int)strlen(dlldirs
.str
[i
]) - 2, dlldirs
.str
[i
],
690 namelen
, name
, name
));
694 TRYOPEN( strmake( "%s%s/%s", dlldirs
.str
[i
], pe_dir
, name
));
695 TRYOPEN( strmake( "%s/%s", dlldirs
.str
[i
], name
));
703 TRYOPEN( strmake( "%s%s/%s", dlldir
, pe_dir
, name
));
704 TRYOPEN( strmake( "%s/%s", dlldir
, name
));
706 for (i
= 0; i
< ARRAY_SIZE(default_dirs
); i
++)
708 if (i
&& !strcmp( default_dirs
[i
], default_dirs
[0] )) continue;
709 TRYOPEN( strmake( "%s%s/%s", default_dirs
[i
], pe_dir
, name
));
712 error( "cannot find %s\n", name
);
716 int main(int argc
,char *argv
[])
720 struct strarray files
;
722 signal( SIGTERM
, exit_on_signal
);
723 signal( SIGINT
, exit_on_signal
);
725 signal( SIGHUP
, exit_on_signal
);
727 init_argv0_dir( argv
[0] );
728 target
= init_argv0_target( argv
[0] );
732 files
= parse_options( argc
, argv
, short_options
, long_options
, 1, option_callback
);
736 static const char *incl_dirs
[] = { INCLUDEDIR
, "/usr/include", "/usr/local/include" };
740 wpp_add_include_path( strmake( "%s/wine/msvcrt", includedir
));
741 wpp_add_include_path( strmake( "%s/wine/windows", includedir
));
743 for (i
= 0; i
< ARRAY_SIZE(incl_dirs
); i
++)
745 if (i
&& !strcmp( incl_dirs
[i
], incl_dirs
[0] )) continue;
746 wpp_add_include_path( strmake( "%s%s/wine/msvcrt", sysroot
, incl_dirs
[i
] ));
747 wpp_add_include_path( strmake( "%s%s/wine/windows", sysroot
, incl_dirs
[i
] ));
752 set_target_ptr_size( &target
, pointer_size
);
754 pointer_size
= get_target_ptr_size( target
);
756 /* if nothing specified, try to guess output type from the output file name */
757 if (output_name
&& do_everything
&& !do_header
&& !do_typelib
&& !do_proxies
&&
758 !do_client
&& !do_server
&& !do_regscript
&& !do_idfile
&& !do_dlldata
)
761 if (strendswith( output_name
, ".h" )) do_header
= 1;
762 else if (strendswith( output_name
, ".tlb" )) do_typelib
= 1;
763 else if (strendswith( output_name
, "_p.c" )) do_proxies
= 1;
764 else if (strendswith( output_name
, "_c.c" )) do_client
= 1;
765 else if (strendswith( output_name
, "_s.c" )) do_server
= 1;
766 else if (strendswith( output_name
, "_i.c" )) do_idfile
= 1;
767 else if (strendswith( output_name
, "_r.res" )) do_regscript
= 1;
768 else if (strendswith( output_name
, "_t.res" )) do_typelib
= 1;
769 else if (strendswith( output_name
, "_l.res" )) do_typelib
= 1;
770 else if (strendswith( output_name
, "dlldata.c" )) do_dlldata
= 1;
771 else do_everything
= 1;
775 set_everything(TRUE
);
778 if (do_header
+ do_typelib
+ do_proxies
+ do_client
+
779 do_server
+ do_regscript
+ do_idfile
+ do_dlldata
== 1 && output_name
)
781 if (do_header
&& !header_name
) header_name
= output_name
;
782 else if (do_typelib
&& !typelib_name
) typelib_name
= output_name
;
783 else if (do_proxies
&& !proxy_name
) proxy_name
= output_name
;
784 else if (do_client
&& !client_name
) client_name
= output_name
;
785 else if (do_server
&& !server_name
) server_name
= output_name
;
786 else if (do_regscript
&& !regscript_name
) regscript_name
= output_name
;
787 else if (do_idfile
&& !idfile_name
) idfile_name
= output_name
;
788 else if (do_dlldata
&& !dlldata_name
) dlldata_name
= output_name
;
791 if (!dlldata_name
&& do_dlldata
)
792 dlldata_name
= xstrdup("dlldata.c");
795 if (do_dlldata
&& !do_everything
) {
796 struct strarray filenames
= empty_strarray
;
797 for (i
= 0; i
< files
.count
; i
++)
798 strarray_add(&filenames
, replace_extension( get_basename( files
.str
[i
] ), ".idl", "" ));
800 write_dlldata_list(filenames
, 0 /* FIXME */ );
803 else if (files
.count
> 1) {
804 fprintf(stderr
, "%s", usage
);
808 input_idl_name
= input_name
= xstrdup(files
.str
[0]);
811 fprintf(stderr
, "%s", usage
);
817 setbuf(stdout
, NULL
);
818 setbuf(stderr
, NULL
);
821 parser_debug
= debuglevel
& DEBUGLEVEL_TRACE
? 1 : 0;
822 yy_flex_debug
= debuglevel
& DEBUGLEVEL_TRACE
? 1 : 0;
824 wpp_set_debug( (debuglevel
& DEBUGLEVEL_PPLEX
) != 0,
825 (debuglevel
& DEBUGLEVEL_PPTRACE
) != 0,
826 (debuglevel
& DEBUGLEVEL_PPMSG
) != 0 );
829 header_name
= replace_extension( get_basename(input_name
), ".idl", ".h" );
831 if (!typelib_name
&& do_typelib
)
832 typelib_name
= replace_extension( get_basename(input_name
), ".idl", ".tlb" );
834 if (!proxy_name
&& do_proxies
)
835 proxy_name
= replace_extension( get_basename(input_name
), ".idl", "_p.c" );
837 if (!client_name
&& do_client
)
838 client_name
= replace_extension( get_basename(input_name
), ".idl", "_c.c" );
840 if (!server_name
&& do_server
)
841 server_name
= replace_extension( get_basename(input_name
), ".idl", "_s.c" );
843 if (!regscript_name
&& do_regscript
)
844 regscript_name
= replace_extension( get_basename(input_name
), ".idl", "_r.rgs" );
846 if (!idfile_name
&& do_idfile
)
847 idfile_name
= replace_extension( get_basename(input_name
), ".idl", "_i.c" );
849 if (do_proxies
) proxy_token
= dup_basename_token(proxy_name
,"_p.c");
850 if (do_client
) client_token
= dup_basename_token(client_name
,"_c.c");
851 if (do_server
) server_token
= dup_basename_token(server_name
,"_s.c");
852 if (do_regscript
) regscript_token
= dup_basename_token(regscript_name
,"_r.rgs");
854 add_widl_version_define();
855 wpp_add_cmdline_define("_WIN32=1");
860 chat("Starting preprocess\n");
862 if (!preprocess_only
)
868 fd
= make_temp_file( header_name
, NULL
, &name
);
870 if (!(output
= fdopen(fd
, "wt")))
871 error("Could not open fd %s for writing\n", name
);
873 ret
= wpp_parse( input_name
, output
);
878 ret
= wpp_parse( input_name
, stdout
);
882 if(preprocess_only
) exit(0);
883 if(!(parser_in
= fopen(temp_name
, "r"))) {
884 fprintf(stderr
, "Could not open %s for input\n", temp_name
);
889 if(!(parser_in
= fopen(input_name
, "r"))) {
890 fprintf(stderr
, "Could not open %s for input\n", input_name
);
895 header_token
= make_token(header_name
);
898 ret
= parser_parse();
906 /* Everything has been done successfully, don't delete any files. */
907 set_everything(FALSE
);
908 local_stubs_name
= NULL
;
913 static void rm_tempfile(void)
920 if (local_stubs_name
)
921 unlink(local_stubs_name
);
927 unlink(regscript_name
);
933 unlink(typelib_name
);