msvcp90: Sync spec files.
[wine/multimedia.git] / tools / widl / widl.c
blob85d66d76cc1612181a834670b63fc4dcd14a38d4
1 /*
2 * IDL Compiler
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
22 #include "config.h"
23 #include "wine/port.h"
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
40 #include "widl.h"
41 #include "utils.h"
42 #include "parser.h"
43 #include "wine/wpp.h"
44 #include "header.h"
46 /* future options to reserve characters for: */
47 /* A = ACF input filename */
48 /* J = do not search standard include path */
49 /* w = select win16/win32 output (?) */
51 static const char usage[] =
52 "Usage: widl [options...] infile.idl\n"
53 " or: widl [options...] --dlldata-only name1 [name2...]\n"
54 " -b arch Set the target architecture\n"
55 " -c Generate client stub\n"
56 " -d n Set debug level to 'n'\n"
57 " -D id[=val] Define preprocessor identifier id=val\n"
58 " -E Preprocess only\n"
59 " --help Display this help and exit\n"
60 " -h Generate headers\n"
61 " -H file Name of header file (default is infile.h)\n"
62 " -I path Set include search dir to path (multiple -I allowed)\n"
63 " --local-stubs=file Write empty stubs for call_as/local methods to file\n"
64 " -m32, -m64 Set the kind of typelib to build (Win32 or Win64)\n"
65 " -N Do not preprocess input\n"
66 " --oldnames Use old naming conventions\n"
67 " -o, --output=NAME Set the output file name\n"
68 " -Otype Type of stubs to generate (-Os, -Oi, -Oif)\n"
69 " -p Generate proxy\n"
70 " --prefix-all=p Prefix names of client stubs / server functions with 'p'\n"
71 " --prefix-client=p Prefix names of client stubs with 'p'\n"
72 " --prefix-server=p Prefix names of server functions with 'p'\n"
73 " -r Generate registration script\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 Only generate 32-bit code\n"
80 " --win64 Only generate 64-bit code\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"
92 static const char version_string[] = "Wine IDL Compiler version " PACKAGE_VERSION "\n"
93 "Copyright 2002 Ove Kaaven\n";
95 int debuglevel = DEBUGLEVEL_NONE;
96 int parser_debug, yy_flex_debug;
98 int pedantic = 0;
99 int do_everything = 1;
100 static int preprocess_only = 0;
101 int do_header = 0;
102 int do_typelib = 0;
103 int do_proxies = 0;
104 int do_client = 0;
105 int do_server = 0;
106 int do_regscript = 0;
107 int do_idfile = 0;
108 int do_dlldata = 0;
109 static int no_preprocess = 0;
110 int old_names = 0;
111 int do_win32 = 1;
112 int do_win64 = 1;
113 int win32_packing = 8;
114 int win64_packing = 8;
115 static enum stub_mode stub_mode = MODE_Os;
117 char *input_name;
118 char *header_name;
119 char *local_stubs_name;
120 char *header_token;
121 char *typelib_name;
122 char *dlldata_name;
123 char *proxy_name;
124 char *proxy_token;
125 char *client_name;
126 char *client_token;
127 char *server_name;
128 char *server_token;
129 char *regscript_name;
130 char *regscript_token;
131 static char *idfile_name;
132 char *temp_name;
133 const char *prefix_client = "";
134 const char *prefix_server = "";
136 int line_number = 1;
138 static FILE *idfile;
140 unsigned int pointer_size = 0;
141 syskind_t typelib_kind = sizeof(void*) == 8 ? SYS_WIN64 : SYS_WIN32;
143 time_t now;
145 enum {
146 OLDNAMES_OPTION = CHAR_MAX + 1,
147 DLLDATA_OPTION,
148 DLLDATA_ONLY_OPTION,
149 LOCAL_STUBS_OPTION,
150 PREFIX_ALL_OPTION,
151 PREFIX_CLIENT_OPTION,
152 PREFIX_SERVER_OPTION,
153 PRINT_HELP,
154 WIN32_OPTION,
155 WIN64_OPTION,
156 WIN32_ALIGN_OPTION,
157 WIN64_ALIGN_OPTION
160 static const char short_options[] =
161 "b:cC:d:D:EhH:I:m:No:O:pP:rsS:tT:uU:VW";
162 static const struct option long_options[] = {
163 { "dlldata", 1, NULL, DLLDATA_OPTION },
164 { "dlldata-only", 0, NULL, DLLDATA_ONLY_OPTION },
165 { "help", 0, NULL, PRINT_HELP },
166 { "local-stubs", 1, NULL, LOCAL_STUBS_OPTION },
167 { "oldnames", 0, NULL, OLDNAMES_OPTION },
168 { "output", 0, NULL, 'o' },
169 { "prefix-all", 1, NULL, PREFIX_ALL_OPTION },
170 { "prefix-client", 1, NULL, PREFIX_CLIENT_OPTION },
171 { "prefix-server", 1, NULL, PREFIX_SERVER_OPTION },
172 { "win32", 0, NULL, WIN32_OPTION },
173 { "win64", 0, NULL, WIN64_OPTION },
174 { "win32-align", 1, NULL, WIN32_ALIGN_OPTION },
175 { "win64-align", 1, NULL, WIN64_ALIGN_OPTION },
176 { NULL, 0, NULL, 0 }
179 static void rm_tempfile(void);
181 enum stub_mode get_stub_mode(void)
183 /* old-style interpreted stubs are not supported on 64-bit */
184 if (stub_mode == MODE_Oi && pointer_size == 8) return MODE_Oif;
185 return stub_mode;
188 static char *make_token(const char *name)
190 char *token;
191 char *slash;
192 int i;
194 slash = strrchr(name, '/');
195 if(!slash)
196 slash = strrchr(name, '\\');
198 if (slash) name = slash + 1;
200 token = xstrdup(name);
201 for (i=0; token[i]; i++) {
202 if (!isalnum(token[i])) token[i] = '_';
203 else token[i] = tolower(token[i]);
205 return token;
208 /* duplicate a basename into a valid C token */
209 static char *dup_basename_token(const char *name, const char *ext)
211 char *p, *ret = dup_basename( name, ext );
212 /* map invalid characters to '_' */
213 for (p = ret; *p; p++) if (!isalnum(*p)) *p = '_';
214 return ret;
217 static void add_widl_version_define(void)
219 unsigned int version;
220 const char *p = PACKAGE_VERSION;
222 /* major */
223 version = atoi(p) * 0x10000;
224 p = strchr(p, '.');
226 /* minor */
227 if (p)
229 version += atoi(p + 1) * 0x100;
230 p = strchr(p + 1, '.');
233 /* build */
234 if (p)
235 version += atoi(p + 1);
237 if (version != 0)
239 char version_str[11];
240 snprintf(version_str, sizeof(version_str), "0x%x", version);
241 wpp_add_define("__WIDL__", version_str);
243 else
244 wpp_add_define("__WIDL__", NULL);
247 /* set the target platform */
248 static void set_target( const char *target )
250 static const struct
252 const char *name;
253 syskind_t kind;
254 } cpu_names[] =
256 { "i386", SYS_WIN32 },
257 { "i486", SYS_WIN32 },
258 { "i586", SYS_WIN32 },
259 { "i686", SYS_WIN32 },
260 { "i786", SYS_WIN32 },
261 { "amd64", SYS_WIN64 },
262 { "x86_64", SYS_WIN64 },
263 { "sparc", SYS_WIN32 },
264 { "alpha", SYS_WIN32 },
265 { "powerpc", SYS_WIN32 },
266 { "arm", SYS_WIN32 }
269 unsigned int i;
270 char *p, *spec = xstrdup( target );
272 /* target specification is in the form CPU-MANUFACTURER-OS or CPU-MANUFACTURER-KERNEL-OS */
274 if (!(p = strchr( spec, '-' ))) error( "Invalid target specification '%s'\n", target );
275 *p++ = 0;
276 for (i = 0; i < sizeof(cpu_names)/sizeof(cpu_names[0]); i++)
278 if (!strcmp( cpu_names[i].name, spec ))
280 typelib_kind = cpu_names[i].kind;
281 free( spec );
282 return;
285 error( "Unrecognized CPU '%s'\n", spec );
288 /* clean things up when aborting on a signal */
289 static void exit_on_signal( int sig )
291 exit(1); /* this will call the atexit functions */
294 static void set_everything(int x)
296 do_header = x;
297 do_typelib = x;
298 do_proxies = x;
299 do_client = x;
300 do_server = x;
301 do_regscript = x;
302 do_idfile = x;
303 do_dlldata = x;
306 void start_cplusplus_guard(FILE *fp)
308 fprintf(fp, "#ifdef __cplusplus\n");
309 fprintf(fp, "extern \"C\" {\n");
310 fprintf(fp, "#endif\n\n");
313 void end_cplusplus_guard(FILE *fp)
315 fprintf(fp, "#ifdef __cplusplus\n");
316 fprintf(fp, "}\n");
317 fprintf(fp, "#endif\n\n");
320 typedef struct
322 char *filename;
323 struct list link;
324 } filename_node_t;
326 static void add_filename_node(struct list *list, const char *name)
328 filename_node_t *node = xmalloc(sizeof *node);
329 node->filename = dup_basename( name, ".idl" );
330 list_add_tail(list, &node->link);
333 static void free_filename_nodes(struct list *list)
335 filename_node_t *node, *next;
336 LIST_FOR_EACH_ENTRY_SAFE(node, next, list, filename_node_t, link) {
337 list_remove(&node->link);
338 free(node->filename);
339 free(node);
343 static void write_dlldata_list(struct list *filenames)
345 FILE *dlldata;
346 filename_node_t *node;
348 dlldata = fopen(dlldata_name, "w");
349 if (!dlldata)
350 error("couldn't open %s: %s\n", dlldata_name, strerror(errno));
352 fprintf(dlldata, "/*** Autogenerated by WIDL %s ", PACKAGE_VERSION);
353 fprintf(dlldata, "- Do not edit ***/\n\n");
354 fprintf(dlldata, "#include <objbase.h>\n");
355 fprintf(dlldata, "#include <rpcproxy.h>\n\n");
356 start_cplusplus_guard(dlldata);
358 LIST_FOR_EACH_ENTRY(node, filenames, filename_node_t, link)
359 fprintf(dlldata, "EXTERN_PROXY_FILE(%s)\n", node->filename);
361 fprintf(dlldata, "\nPROXYFILE_LIST_START\n");
362 fprintf(dlldata, "/* Start of list */\n");
363 LIST_FOR_EACH_ENTRY(node, filenames, filename_node_t, link)
364 fprintf(dlldata, " REFERENCE_PROXY_FILE(%s),\n", node->filename);
365 fprintf(dlldata, "/* End of list */\n");
366 fprintf(dlldata, "PROXYFILE_LIST_END\n\n");
368 fprintf(dlldata, "DLLDATA_ROUTINES(aProxyFileList, GET_DLL_CLSID)\n\n");
369 end_cplusplus_guard(dlldata);
370 fclose(dlldata);
373 static char *eat_space(char *s)
375 while (isspace((unsigned char) *s))
376 ++s;
377 return s;
380 void write_dlldata(const statement_list_t *stmts)
382 struct list filenames = LIST_INIT(filenames);
383 filename_node_t *node;
384 FILE *dlldata;
386 if (!do_dlldata || !need_proxy_file(stmts))
387 return;
389 dlldata = fopen(dlldata_name, "r");
390 if (dlldata) {
391 static char marker[] = "REFERENCE_PROXY_FILE";
392 char *line = NULL;
393 size_t len = 0;
395 while (widl_getline(&line, &len, dlldata)) {
396 char *start, *end;
397 start = eat_space(line);
398 if (strncmp(start, marker, sizeof marker - 1) == 0) {
399 start = eat_space(start + sizeof marker - 1);
400 if (*start != '(')
401 continue;
402 end = start = eat_space(start + 1);
403 while (*end && *end != ')')
404 ++end;
405 if (*end != ')')
406 continue;
407 while (isspace((unsigned char) end[-1]))
408 --end;
409 *end = '\0';
410 if (start < end)
411 add_filename_node(&filenames, start);
415 if (ferror(dlldata))
416 error("couldn't read from %s: %s\n", dlldata_name, strerror(errno));
418 free(line);
419 fclose(dlldata);
422 LIST_FOR_EACH_ENTRY(node, &filenames, filename_node_t, link)
423 if (strcmp(proxy_token, node->filename) == 0) {
424 /* We're already in the list, no need to regenerate this file. */
425 free_filename_nodes(&filenames);
426 return;
429 add_filename_node(&filenames, proxy_token);
430 write_dlldata_list(&filenames);
431 free_filename_nodes(&filenames);
434 static void write_id_data_stmts(const statement_list_t *stmts)
436 const statement_t *stmt;
437 if (stmts) LIST_FOR_EACH_ENTRY( stmt, stmts, const statement_t, entry )
439 if (stmt->type == STMT_TYPE)
441 const type_t *type = stmt->u.type;
442 if (type_get_type(type) == TYPE_INTERFACE)
444 const UUID *uuid;
445 if (!is_object(type) && !is_attr(type->attrs, ATTR_DISPINTERFACE))
446 continue;
447 uuid = get_attrp(type->attrs, ATTR_UUID);
448 write_guid(idfile, is_attr(type->attrs, ATTR_DISPINTERFACE) ? "DIID" : "IID",
449 type->name, uuid);
451 else if (type_get_type(type) == TYPE_COCLASS)
453 const UUID *uuid = get_attrp(type->attrs, ATTR_UUID);
454 write_guid(idfile, "CLSID", type->name, uuid);
457 else if (stmt->type == STMT_LIBRARY)
459 const UUID *uuid = get_attrp(stmt->u.lib->attrs, ATTR_UUID);
460 write_guid(idfile, "LIBID", stmt->u.lib->name, uuid);
461 write_id_data_stmts(stmt->u.lib->stmts);
466 void write_id_data(const statement_list_t *stmts)
468 if (!do_idfile) return;
470 idfile = fopen(idfile_name, "w");
471 if (! idfile) {
472 error("Could not open %s for output\n", idfile_name);
473 return;
476 fprintf(idfile, "/*** Autogenerated by WIDL %s ", PACKAGE_VERSION);
477 fprintf(idfile, "from %s - Do not edit ***/\n\n", input_name);
478 fprintf(idfile, "#include <rpc.h>\n");
479 fprintf(idfile, "#include <rpcndr.h>\n\n");
480 fprintf(idfile, "#include <initguid.h>\n\n");
481 start_cplusplus_guard(idfile);
483 write_id_data_stmts(stmts);
485 fprintf(idfile, "\n");
486 end_cplusplus_guard(idfile);
488 fclose(idfile);
491 int main(int argc,char *argv[])
493 int optc;
494 int ret = 0;
495 int opti = 0;
496 char *output_name = NULL;
498 signal( SIGTERM, exit_on_signal );
499 signal( SIGINT, exit_on_signal );
500 #ifdef SIGHUP
501 signal( SIGHUP, exit_on_signal );
502 #endif
504 now = time(NULL);
506 while((optc = getopt_long(argc, argv, short_options, long_options, &opti)) != EOF) {
507 switch(optc) {
508 case DLLDATA_OPTION:
509 dlldata_name = xstrdup(optarg);
510 break;
511 case DLLDATA_ONLY_OPTION:
512 do_everything = 0;
513 do_dlldata = 1;
514 break;
515 case LOCAL_STUBS_OPTION:
516 do_everything = 0;
517 local_stubs_name = xstrdup(optarg);
518 break;
519 case OLDNAMES_OPTION:
520 old_names = 1;
521 break;
522 case PREFIX_ALL_OPTION:
523 prefix_client = xstrdup(optarg);
524 prefix_server = xstrdup(optarg);
525 break;
526 case PREFIX_CLIENT_OPTION:
527 prefix_client = xstrdup(optarg);
528 break;
529 case PREFIX_SERVER_OPTION:
530 prefix_server = xstrdup(optarg);
531 break;
532 case PRINT_HELP:
533 fprintf(stderr, "%s", usage);
534 return 0;
535 case WIN32_OPTION:
536 do_win32 = 1;
537 do_win64 = 0;
538 break;
539 case WIN64_OPTION:
540 do_win32 = 0;
541 do_win64 = 1;
542 break;
543 case WIN32_ALIGN_OPTION:
544 win32_packing = strtol(optarg, NULL, 0);
545 if(win32_packing != 2 && win32_packing != 4 && win32_packing != 8)
546 error("Packing must be one of 2, 4 or 8\n");
547 break;
548 case WIN64_ALIGN_OPTION:
549 win64_packing = strtol(optarg, NULL, 0);
550 if(win64_packing != 2 && win64_packing != 4 && win64_packing != 8)
551 error("Packing must be one of 2, 4 or 8\n");
552 break;
553 case 'b':
554 set_target( optarg );
555 break;
556 case 'c':
557 do_everything = 0;
558 do_client = 1;
559 break;
560 case 'C':
561 client_name = xstrdup(optarg);
562 break;
563 case 'd':
564 debuglevel = strtol(optarg, NULL, 0);
565 break;
566 case 'D':
567 wpp_add_cmdline_define(optarg);
568 break;
569 case 'E':
570 do_everything = 0;
571 preprocess_only = 1;
572 break;
573 case 'h':
574 do_everything = 0;
575 do_header = 1;
576 break;
577 case 'H':
578 header_name = xstrdup(optarg);
579 break;
580 case 'I':
581 wpp_add_include_path(optarg);
582 break;
583 case 'm':
584 if (!strcmp( optarg, "32" )) typelib_kind = SYS_WIN32;
585 else if (!strcmp( optarg, "64" )) typelib_kind = SYS_WIN64;
586 else error( "Invalid -m argument '%s'\n", optarg );
587 break;
588 case 'N':
589 no_preprocess = 1;
590 break;
591 case 'o':
592 output_name = xstrdup(optarg);
593 break;
594 case 'O':
595 if (!strcmp( optarg, "s" )) stub_mode = MODE_Os;
596 else if (!strcmp( optarg, "i" )) stub_mode = MODE_Oi;
597 else if (!strcmp( optarg, "ic" )) stub_mode = MODE_Oif;
598 else if (!strcmp( optarg, "if" )) stub_mode = MODE_Oif;
599 else if (!strcmp( optarg, "icf" )) stub_mode = MODE_Oif;
600 else error( "Invalid argument '-O%s'\n", optarg );
601 break;
602 case 'p':
603 do_everything = 0;
604 do_proxies = 1;
605 break;
606 case 'P':
607 proxy_name = xstrdup(optarg);
608 break;
609 case 'r':
610 do_everything = 0;
611 do_regscript = 1;
612 break;
613 case 's':
614 do_everything = 0;
615 do_server = 1;
616 break;
617 case 'S':
618 server_name = xstrdup(optarg);
619 break;
620 case 't':
621 do_everything = 0;
622 do_typelib = 1;
623 break;
624 case 'T':
625 typelib_name = xstrdup(optarg);
626 break;
627 case 'u':
628 do_everything = 0;
629 do_idfile = 1;
630 break;
631 case 'U':
632 idfile_name = xstrdup(optarg);
633 break;
634 case 'V':
635 printf("%s", version_string);
636 return 0;
637 case 'W':
638 pedantic = 1;
639 break;
640 default:
641 fprintf(stderr, "%s", usage);
642 return 1;
646 if(do_everything) {
647 set_everything(TRUE);
650 if (!output_name) output_name = dup_basename(input_name, ".idl");
652 if (!do_everything &&
653 do_header + do_typelib + do_proxies + do_client +
654 do_server + do_regscript + do_idfile + do_dlldata == 1)
656 if (do_header) header_name = output_name;
657 else if (do_typelib) typelib_name = output_name;
658 else if (do_proxies) proxy_name = output_name;
659 else if (do_client) client_name = output_name;
660 else if (do_server) server_name = output_name;
661 else if (do_regscript) regscript_name = output_name;
662 else if (do_idfile) idfile_name = output_name;
663 else if (do_dlldata) dlldata_name = output_name;
666 if (!dlldata_name && do_dlldata)
667 dlldata_name = xstrdup("dlldata.c");
669 if(optind < argc) {
670 if (do_dlldata && !do_everything) {
671 struct list filenames = LIST_INIT(filenames);
672 for ( ; optind < argc; ++optind)
673 add_filename_node(&filenames, argv[optind]);
675 write_dlldata_list(&filenames);
676 free_filename_nodes(&filenames);
677 return 0;
679 else if (optind != argc - 1) {
680 fprintf(stderr, "%s", usage);
681 return 1;
683 else
684 input_name = xstrdup(argv[optind]);
686 else {
687 fprintf(stderr, "%s", usage);
688 return 1;
691 if(debuglevel)
693 setbuf(stdout, NULL);
694 setbuf(stderr, NULL);
697 parser_debug = debuglevel & DEBUGLEVEL_TRACE ? 1 : 0;
698 yy_flex_debug = debuglevel & DEBUGLEVEL_TRACE ? 1 : 0;
700 wpp_set_debug( (debuglevel & DEBUGLEVEL_PPLEX) != 0,
701 (debuglevel & DEBUGLEVEL_PPTRACE) != 0,
702 (debuglevel & DEBUGLEVEL_PPMSG) != 0 );
704 if (!header_name) {
705 header_name = dup_basename(input_name, ".idl");
706 strcat(header_name, ".h");
709 if (!typelib_name && do_typelib) {
710 typelib_name = dup_basename(input_name, ".idl");
711 strcat(typelib_name, ".tlb");
714 if (!proxy_name && do_proxies) {
715 proxy_name = dup_basename(input_name, ".idl");
716 strcat(proxy_name, "_p.c");
719 if (!client_name && do_client) {
720 client_name = dup_basename(input_name, ".idl");
721 strcat(client_name, "_c.c");
724 if (!server_name && do_server) {
725 server_name = dup_basename(input_name, ".idl");
726 strcat(server_name, "_s.c");
729 if (!regscript_name && do_regscript) {
730 regscript_name = dup_basename(input_name, ".idl");
731 strcat(regscript_name, "_r.rgs");
734 if (!idfile_name && do_idfile) {
735 idfile_name = dup_basename(input_name, ".idl");
736 strcat(idfile_name, "_i.c");
739 if (do_proxies) proxy_token = dup_basename_token(proxy_name,"_p.c");
740 if (do_client) client_token = dup_basename_token(client_name,"_c.c");
741 if (do_server) server_token = dup_basename_token(server_name,"_s.c");
742 if (do_regscript) regscript_token = dup_basename_token(regscript_name,"_r.rgs");
744 add_widl_version_define();
745 wpp_add_define("_WIN32", NULL);
747 atexit(rm_tempfile);
748 if (!no_preprocess)
750 chat("Starting preprocess\n");
752 if (!preprocess_only)
754 FILE *output;
755 int fd;
756 char *name = xmalloc( strlen(header_name) + 8 );
758 strcpy( name, header_name );
759 strcat( name, ".XXXXXX" );
761 if ((fd = mkstemps( name, 0 )) == -1)
762 error("Could not generate a temp name from %s\n", name);
764 temp_name = name;
765 if (!(output = fdopen(fd, "wt")))
766 error("Could not open fd %s for writing\n", name);
768 ret = wpp_parse( input_name, output );
769 fclose( output );
771 else
773 ret = wpp_parse( input_name, stdout );
776 if(ret) exit(1);
777 if(preprocess_only) exit(0);
778 if(!(parser_in = fopen(temp_name, "r"))) {
779 fprintf(stderr, "Could not open %s for input\n", temp_name);
780 return 1;
783 else {
784 if(!(parser_in = fopen(input_name, "r"))) {
785 fprintf(stderr, "Could not open %s for input\n", input_name);
786 return 1;
790 header_token = make_token(header_name);
792 init_types();
793 ret = parser_parse();
795 fclose(parser_in);
797 if(ret) {
798 exit(1);
801 /* Everything has been done successfully, don't delete any files. */
802 set_everything(FALSE);
803 local_stubs_name = NULL;
805 return 0;
808 static void rm_tempfile(void)
810 abort_import();
811 if(temp_name)
812 unlink(temp_name);
813 if (do_header)
814 unlink(header_name);
815 if (local_stubs_name)
816 unlink(local_stubs_name);
817 if (do_client)
818 unlink(client_name);
819 if (do_server)
820 unlink(server_name);
821 if (do_regscript)
822 unlink(regscript_name);
823 if (do_idfile)
824 unlink(idfile_name);
825 if (do_proxies)
826 unlink(proxy_name);
827 if (do_typelib)
828 unlink(typelib_name);