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"
44 /* future options to reserve characters for: */
45 /* a = alignment of structures */
46 /* A = ACF input filename */
47 /* J = do not search standard include path */
48 /* O = generate interpreted stubs */
49 /* u = UUID file only? */
50 /* U = UUID filename */
51 /* w = select win16/win32 output (?) */
54 "Usage: widl [options...] infile.idl\n"
55 " -c Generate client stub\n"
56 " -C file Name of client stub file (default is infile_c.c)\n"
57 " -d n Set debug level to 'n'\n"
58 " -D id[=val] Define preprocessor identifier id=val\n"
59 " -E Preprocess only\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 " -N Do not preprocess input\n"
64 " --oldnames Use old naming conventions\n"
65 " -p Generate proxy\n"
66 " -P file Name of proxy file (default is infile_p.c)\n"
67 " -s Generate server stub\n"
68 " -S file Name of server stub file (default is infile_s.c)\n"
69 " -t Generate typelib\n"
70 " -T file Name of typelib file (default is infile.tlb)\n"
71 " -V Print version and exit\n"
72 " -W Enable pedantic warnings\n"
73 "Debug level 'n' is a bitmask with following meaning:\n"
74 " * 0x01 Tell which resource is parsed (verbose mode)\n"
75 " * 0x02 Dump internal structures\n"
76 " * 0x04 Create a parser trace (yydebug=1)\n"
77 " * 0x08 Preprocessor messages\n"
78 " * 0x10 Preprocessor lex messages\n"
79 " * 0x20 Preprocessor yacc trace\n"
82 static const char version_string[] = "Wine IDL Compiler version " PACKAGE_VERSION "\n"
83 "Copyright 2002 Ove Kaaven\n";
86 int debuglevel = DEBUGLEVEL_NONE;
90 static int do_everything = 1;
91 int preprocess_only = 0;
97 int no_preprocess = 0;
119 static const char *short_options =
120 "cC:d:D:EhH:I:NpP:sS:tT:VW";
121 static struct option long_options[] = {
122 { "oldnames", 0, 0, 1 },
126 static void rm_tempfile(void);
127 static void segvhandler(int sig);
129 static char *make_token(const char *name)
135 slash = strrchr(name, '/');
136 if (slash) name = slash + 1;
138 token = xstrdup(name);
139 for (i=0; token[i]; i++) {
140 if (!isalnum(token[i])) token[i] = '_';
141 else token[i] = toupper(token[i]);
146 /* duplicate a basename into a valid C token */
147 static char *dup_basename_token(const char *name, const char *ext)
149 char *p, *ret = dup_basename( name, ext );
150 /* map invalid characters to '_' */
151 for (p = ret; *p; p++) if (!isalnum(*p)) *p = '_';
155 int main(int argc,char *argv[])
163 signal(SIGSEGV, segvhandler);
167 while((optc = getopt_long(argc, argv, short_options, long_options, &opti)) != EOF) {
177 client_name = strdup(optarg);
180 debuglevel = strtol(optarg, NULL, 0);
183 wpp_add_cmdline_define(optarg);
194 header_name = strdup(optarg);
197 wpp_add_include_path(optarg);
207 proxy_name = strdup(optarg);
214 server_name = strdup(optarg);
221 typelib_name = strdup(optarg);
224 printf(version_string);
230 fprintf(stderr, usage);
236 do_header = do_typelib = do_proxies = do_client = do_server = 1;
239 input_name = xstrdup(argv[optind]);
242 fprintf(stderr, usage);
252 yydebug = debuglevel & DEBUGLEVEL_TRACE ? 1 : 0;
253 yy_flex_debug = debuglevel & DEBUGLEVEL_TRACE ? 1 : 0;
255 wpp_set_debug( (debuglevel & DEBUGLEVEL_PPLEX) != 0,
256 (debuglevel & DEBUGLEVEL_PPTRACE) != 0,
257 (debuglevel & DEBUGLEVEL_PPMSG) != 0 );
260 header_name = dup_basename(input_name, ".idl");
261 strcat(header_name, ".h");
264 if (!typelib_name && do_typelib) {
265 typelib_name = dup_basename(input_name, ".idl");
266 strcat(typelib_name, ".tlb");
269 if (!proxy_name && do_proxies) {
270 proxy_name = dup_basename(input_name, ".idl");
271 strcat(proxy_name, "_p.c");
274 if (!client_name && do_client) {
275 client_name = dup_basename(input_name, ".idl");
276 strcat(client_name, "_c.c");
279 if (!server_name && do_server) {
280 server_name = dup_basename(input_name, ".idl");
281 strcat(server_name, "_s.c");
284 if (do_proxies) proxy_token = dup_basename_token(proxy_name,"_p.c");
285 if (do_client) client_token = dup_basename_token(client_name,"_c.c");
286 if (do_server) server_token = dup_basename_token(server_name,"_s.c");
288 wpp_add_cmdline_define("__WIDL__");
293 chat("Starting preprocess\n");
295 if (!preprocess_only)
297 ret = wpp_parse_temp( input_name, header_name, &temp_name );
301 ret = wpp_parse( input_name, stdout );
305 if(preprocess_only) exit(0);
306 if(!(yyin = fopen(temp_name, "r"))) {
307 fprintf(stderr, "Could not open %s for input\n", temp_name);
312 if(!(yyin = fopen(input_name, "r"))) {
313 fprintf(stderr, "Could not open %s for input\n", input_name);
319 header_token = make_token(header_name);
321 if(!(header = fopen(header_name, "w"))) {
322 fprintf(stderr, "Could not open %s for output\n", header_name);
325 fprintf(header, "/*** Autogenerated by WIDL %s from %s - Do not edit ***/\n", PACKAGE_VERSION, input_name);
326 fprintf(header, "#include <rpc.h>\n" );
327 fprintf(header, "#include <rpcndr.h>\n\n" );
328 fprintf(header, "#ifndef __WIDL_%s\n", header_token);
329 fprintf(header, "#define __WIDL_%s\n", header_token);
330 fprintf(header, "#ifdef __cplusplus\n");
331 fprintf(header, "extern \"C\" {\n");
332 fprintf(header, "#endif\n");
338 fprintf(header, "/* Begin additional prototypes for all interfaces */\n");
339 fprintf(header, "\n");
341 fprintf(header, "\n");
342 fprintf(header, "/* End additional prototypes */\n");
343 fprintf(header, "\n");
344 fprintf(header, "#ifdef __cplusplus\n");
345 fprintf(header, "}\n");
346 fprintf(header, "#endif\n");
347 fprintf(header, "#endif /* __WIDL_%s */\n", header_token);
362 static void rm_tempfile(void)
375 static void segvhandler(int sig)
377 fprintf(stderr, "\n%s:%d: Oops, segment violation\n", input_name, line_number);