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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
23 #include "wine/port.h"
35 #define WIDL_FULLVERSION "0.1"
43 /* future options to reserve characters for: */
44 /* a = alignment of structures */
45 /* A = ACF input filename */
46 /* J = do not search standard include path */
47 /* O = generate interpreted stubs */
48 /* u = UUID file only? */
49 /* U = UUID filename */
50 /* w = select win16/win32 output (?) */
53 "Usage: widl [options...] infile.idl\n"
54 " -c Generate client stub\n"
55 " -C file Name of client stub file (default is infile_c.c)\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 " -h Generate headers\n"
60 " -H file Name of header file (default is infile.h)\n"
61 " -I path Set include search dir to path (multiple -I allowed)\n"
62 " -N Do not preprocess input\n"
63 " -p Generate proxy\n"
64 " -P file Name of proxy file (default is infile_p.c)\n"
65 " -s Generate server stub\n"
66 " -S file Name of server stub file (default is infile_s.c)\n"
67 " -t Generate typelib\n"
68 " -T file Name of typelib file (default is infile.tlb)\n"
69 " -V Print version and exit\n"
70 " -W Enable pedantic warnings\n"
71 "Debug level 'n' is a bitmask with following meaning:\n"
72 " * 0x01 Tell which resource is parsed (verbose mode)\n"
73 " * 0x02 Dump internal structures\n"
74 " * 0x04 Create a parser trace (yydebug=1)\n"
75 " * 0x08 Preprocessor messages\n"
76 " * 0x10 Preprocessor lex messages\n"
77 " * 0x20 Preprocessor yacc trace\n"
80 static const char version_string
[] = "Wine IDL Compiler Version " WIDL_FULLVERSION
"\n"
81 "Copyright 2002 Ove Kaaven\n";
84 int debuglevel
= DEBUGLEVEL_NONE
;
87 static int do_everything
= 1;
88 int preprocess_only
= 0;
94 int no_preprocess
= 0;
115 int getopt (int argc
, char *const *argv
, const char *optstring
);
116 static void rm_tempfile(void);
117 static void segvhandler(int sig
);
119 static char *make_token(const char *name
)
125 slash
= strrchr(name
, '/');
126 if (slash
) name
= slash
+ 1;
128 token
= xstrdup(name
);
129 for (i
=0; token
[i
]; i
++) {
130 if (!isalnum(token
[i
])) token
[i
] = '_';
131 else token
[i
] = toupper(token
[i
]);
136 int main(int argc
,char *argv
[])
143 signal(SIGSEGV
, segvhandler
);
147 while((optc
= getopt(argc
, argv
, "cC:d:D:EhH:I:NpP:sS:tT:VW")) != EOF
) {
154 client_name
= strdup(optarg
);
157 debuglevel
= strtol(optarg
, NULL
, 0);
160 wpp_add_cmdline_define(optarg
);
171 header_name
= strdup(optarg
);
174 wpp_add_include_path(optarg
);
184 proxy_name
= strdup(optarg
);
191 server_name
= strdup(optarg
);
198 typelib_name
= strdup(optarg
);
201 printf(version_string
);
207 fprintf(stderr
, usage
);
213 do_header
= do_typelib
= do_proxies
= do_client
= do_server
= 1;
216 input_name
= xstrdup(argv
[optind
]);
219 fprintf(stderr
, usage
);
229 yydebug
= debuglevel
& DEBUGLEVEL_TRACE
? 1 : 0;
230 yy_flex_debug
= debuglevel
& DEBUGLEVEL_TRACE
? 1 : 0;
232 wpp_set_debug( (debuglevel
& DEBUGLEVEL_PPLEX
) != 0,
233 (debuglevel
& DEBUGLEVEL_PPTRACE
) != 0,
234 (debuglevel
& DEBUGLEVEL_PPMSG
) != 0 );
237 header_name
= dup_basename(input_name
, ".idl");
238 strcat(header_name
, ".h");
241 if (!typelib_name
&& do_typelib
) {
242 typelib_name
= dup_basename(input_name
, ".idl");
243 strcat(typelib_name
, ".tlb");
246 if (!proxy_name
&& do_proxies
) {
247 proxy_name
= dup_basename(input_name
, ".idl");
248 proxy_token
= xstrdup(proxy_name
);
249 strcat(proxy_name
, "_p.c");
252 if (!client_name
&& do_client
) {
253 client_name
= dup_basename(input_name
, ".idl");
254 client_token
= xstrdup(client_name
);
255 strcat(client_name
, "_c.c");
258 if (!server_name
&& do_server
) {
259 server_name
= dup_basename(input_name
, ".idl");
260 server_token
= xstrdup(server_name
);
261 strcat(server_name
, "_s.c");
264 wpp_add_cmdline_define("__WIDL__");
269 chat("Starting preprocess\n");
271 if (!preprocess_only
)
273 ret
= wpp_parse_temp( input_name
, header_name
, &temp_name
);
277 ret
= wpp_parse( input_name
, stdout
);
281 if(preprocess_only
) exit(0);
282 if(!(yyin
= fopen(temp_name
, "r"))) {
283 fprintf(stderr
, "Could not open %s for input\n", temp_name
);
288 if(!(yyin
= fopen(input_name
, "r"))) {
289 fprintf(stderr
, "Could not open %s for input\n", input_name
);
295 header_token
= make_token(header_name
);
297 if(!(header
= fopen(header_name
, "w"))) {
298 fprintf(stderr
, "Could not open %s for output\n", header_name
);
301 fprintf(header
, "/*** Autogenerated by WIDL %s from %s - Do not edit ***/\n", WIDL_FULLVERSION
, input_name
);
302 fprintf(header
, "#include <rpc.h>\n" );
303 fprintf(header
, "#include <rpcndr.h>\n\n" );
304 fprintf(header
, "#ifndef __WIDL_%s\n", header_token
);
305 fprintf(header
, "#define __WIDL_%s\n", header_token
);
306 fprintf(header
, "#ifdef __cplusplus\n");
307 fprintf(header
, "extern \"C\" {\n");
308 fprintf(header
, "#endif\n");
314 fprintf(header
, "/* Begin additional prototypes for all interfaces */\n");
315 fprintf(header
, "\n");
317 fprintf(header
, "\n");
318 fprintf(header
, "/* End additional prototypes */\n");
319 fprintf(header
, "\n");
320 fprintf(header
, "#ifdef __cplusplus\n");
321 fprintf(header
, "}\n");
322 fprintf(header
, "#endif\n");
323 fprintf(header
, "#endif /* __WIDL_%s */\n", header_token
);
338 static void rm_tempfile(void)
351 static void segvhandler(int sig
)
353 fprintf(stderr
, "\n%s:%d: Oops, segment violation\n", input_name
, line_number
);