2002-07-16 05:20:45 +02:00
|
|
|
/*
|
|
|
|
* IDL Compiler
|
|
|
|
*
|
|
|
|
* Copyright 2002 Ove Kaaven
|
|
|
|
* based on WRC code by Bertho Stultiens
|
|
|
|
*
|
|
|
|
* This library is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU Lesser General Public
|
|
|
|
* License as published by the Free Software Foundation; either
|
|
|
|
* version 2.1 of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This library is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
* Lesser General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Lesser General Public
|
|
|
|
* License along with this library; if not, write to the Free Software
|
2006-05-18 14:49:52 +02:00
|
|
|
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
|
2002-07-16 05:20:45 +02:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include "config.h"
|
2005-08-03 23:25:10 +02:00
|
|
|
#include "wine/port.h"
|
2002-07-16 05:20:45 +02:00
|
|
|
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
2002-08-17 20:28:43 +02:00
|
|
|
#ifdef HAVE_UNISTD_H
|
|
|
|
# include <unistd.h>
|
|
|
|
#endif
|
2002-07-16 05:20:45 +02:00
|
|
|
#include <string.h>
|
|
|
|
#include <assert.h>
|
|
|
|
#include <ctype.h>
|
|
|
|
#include <signal.h>
|
2006-04-22 21:52:51 +02:00
|
|
|
#ifdef HAVE_GETOPT_H
|
|
|
|
# include <getopt.h>
|
|
|
|
#endif
|
2002-07-16 05:20:45 +02:00
|
|
|
|
|
|
|
#include "widl.h"
|
|
|
|
#include "utils.h"
|
|
|
|
#include "parser.h"
|
2003-05-01 05:16:21 +02:00
|
|
|
#include "wine/wpp.h"
|
2005-09-12 22:13:40 +02:00
|
|
|
#include "header.h"
|
2002-07-16 05:20:45 +02:00
|
|
|
|
2002-12-15 04:01:20 +01:00
|
|
|
/* future options to reserve characters for: */
|
|
|
|
/* a = alignment of structures */
|
|
|
|
/* A = ACF input filename */
|
|
|
|
/* J = do not search standard include path */
|
|
|
|
/* O = generate interpreted stubs */
|
|
|
|
/* u = UUID file only? */
|
|
|
|
/* U = UUID filename */
|
|
|
|
/* w = select win16/win32 output (?) */
|
|
|
|
|
2002-07-16 05:20:45 +02:00
|
|
|
static char usage[] =
|
|
|
|
"Usage: widl [options...] infile.idl\n"
|
2005-02-23 21:31:07 +01:00
|
|
|
" -c Generate client stub\n"
|
|
|
|
" -C file Name of client stub file (default is infile_c.c)\n"
|
2002-07-16 05:20:45 +02:00
|
|
|
" -d n Set debug level to 'n'\n"
|
|
|
|
" -D id[=val] Define preprocessor identifier id=val\n"
|
|
|
|
" -E Preprocess only\n"
|
2005-01-26 20:40:47 +01:00
|
|
|
" -h Generate headers\n"
|
2002-07-16 05:20:45 +02:00
|
|
|
" -H file Name of header file (default is infile.h)\n"
|
|
|
|
" -I path Set include search dir to path (multiple -I allowed)\n"
|
|
|
|
" -N Do not preprocess input\n"
|
2006-04-22 21:52:51 +02:00
|
|
|
" --oldnames Use old naming conventions\n"
|
2005-02-23 21:31:07 +01:00
|
|
|
" -p Generate proxy\n"
|
|
|
|
" -P file Name of proxy file (default is infile_p.c)\n"
|
|
|
|
" -s Generate server stub\n"
|
|
|
|
" -S file Name of server stub file (default is infile_s.c)\n"
|
2005-01-26 20:40:47 +01:00
|
|
|
" -t Generate typelib\n"
|
2004-01-07 05:21:27 +01:00
|
|
|
" -T file Name of typelib file (default is infile.tlb)\n"
|
2002-07-16 05:20:45 +02:00
|
|
|
" -V Print version and exit\n"
|
|
|
|
" -W Enable pedantic warnings\n"
|
|
|
|
"Debug level 'n' is a bitmask with following meaning:\n"
|
|
|
|
" * 0x01 Tell which resource is parsed (verbose mode)\n"
|
|
|
|
" * 0x02 Dump internal structures\n"
|
|
|
|
" * 0x04 Create a parser trace (yydebug=1)\n"
|
|
|
|
" * 0x08 Preprocessor messages\n"
|
|
|
|
" * 0x10 Preprocessor lex messages\n"
|
|
|
|
" * 0x20 Preprocessor yacc trace\n"
|
|
|
|
;
|
|
|
|
|
2005-10-08 12:37:09 +02:00
|
|
|
static const char version_string[] = "Wine IDL Compiler version " PACKAGE_VERSION "\n"
|
2002-07-16 05:20:45 +02:00
|
|
|
"Copyright 2002 Ove Kaaven\n";
|
|
|
|
|
|
|
|
int win32 = 1;
|
|
|
|
int debuglevel = DEBUGLEVEL_NONE;
|
2006-01-03 15:11:46 +01:00
|
|
|
int yy_flex_debug;
|
2002-07-16 05:20:45 +02:00
|
|
|
|
|
|
|
int pedantic = 0;
|
2005-01-26 20:40:47 +01:00
|
|
|
static int do_everything = 1;
|
2002-07-16 05:20:45 +02:00
|
|
|
int preprocess_only = 0;
|
2005-01-26 20:40:47 +01:00
|
|
|
int do_header = 0;
|
|
|
|
int do_typelib = 0;
|
|
|
|
int do_proxies = 0;
|
2005-02-23 21:31:07 +01:00
|
|
|
int do_client = 0;
|
|
|
|
int do_server = 0;
|
2002-07-16 05:20:45 +02:00
|
|
|
int no_preprocess = 0;
|
2006-04-22 21:52:51 +02:00
|
|
|
int old_names = 0;
|
2002-07-16 05:20:45 +02:00
|
|
|
|
|
|
|
char *input_name;
|
|
|
|
char *header_name;
|
2002-11-12 03:12:35 +01:00
|
|
|
char *header_token;
|
2004-01-07 05:21:27 +01:00
|
|
|
char *typelib_name;
|
2002-07-16 05:20:45 +02:00
|
|
|
char *proxy_name;
|
2002-12-03 20:12:07 +01:00
|
|
|
char *proxy_token;
|
2005-02-23 21:31:07 +01:00
|
|
|
char *client_name;
|
|
|
|
char *client_token;
|
|
|
|
char *server_name;
|
|
|
|
char *server_token;
|
2002-07-16 05:20:45 +02:00
|
|
|
char *temp_name;
|
|
|
|
|
|
|
|
int line_number = 1;
|
|
|
|
|
|
|
|
FILE *header;
|
|
|
|
FILE *proxy;
|
|
|
|
|
|
|
|
time_t now;
|
|
|
|
|
2006-04-22 21:52:51 +02:00
|
|
|
static const char *short_options =
|
|
|
|
"cC:d:D:EhH:I:NpP:sS:tT:VW";
|
|
|
|
static struct option long_options[] = {
|
|
|
|
{ "oldnames", 0, 0, 1 },
|
|
|
|
{ 0, 0, 0, 0 }
|
|
|
|
};
|
|
|
|
|
2002-07-16 05:20:45 +02:00
|
|
|
static void rm_tempfile(void);
|
|
|
|
static void segvhandler(int sig);
|
|
|
|
|
2002-11-12 03:12:35 +01:00
|
|
|
static char *make_token(const char *name)
|
|
|
|
{
|
|
|
|
char *token;
|
|
|
|
char *slash;
|
|
|
|
int i;
|
|
|
|
|
|
|
|
slash = strrchr(name, '/');
|
|
|
|
if (slash) name = slash + 1;
|
|
|
|
|
|
|
|
token = xstrdup(name);
|
|
|
|
for (i=0; token[i]; i++) {
|
|
|
|
if (!isalnum(token[i])) token[i] = '_';
|
|
|
|
else token[i] = toupper(token[i]);
|
|
|
|
}
|
|
|
|
return token;
|
|
|
|
}
|
|
|
|
|
2006-02-02 13:22:47 +01:00
|
|
|
/* duplicate a basename into a valid C token */
|
|
|
|
static char *dup_basename_token(const char *name, const char *ext)
|
|
|
|
{
|
|
|
|
char *p, *ret = dup_basename( name, ext );
|
|
|
|
/* map invalid characters to '_' */
|
|
|
|
for (p = ret; *p; p++) if (!isalnum(*p)) *p = '_';
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2006-05-27 13:23:47 +02:00
|
|
|
/* clean things up when aborting on a signal */
|
|
|
|
static void exit_on_signal( int sig )
|
|
|
|
{
|
|
|
|
exit(1); /* this will call the atexit functions */
|
|
|
|
}
|
|
|
|
|
2002-07-16 05:20:45 +02:00
|
|
|
int main(int argc,char *argv[])
|
|
|
|
{
|
|
|
|
extern char* optarg;
|
|
|
|
extern int optind;
|
|
|
|
int optc;
|
2004-12-27 18:13:25 +01:00
|
|
|
int ret = 0;
|
2006-04-22 21:52:51 +02:00
|
|
|
int opti = 0;
|
2002-07-16 05:20:45 +02:00
|
|
|
|
|
|
|
signal(SIGSEGV, segvhandler);
|
2006-05-27 13:23:47 +02:00
|
|
|
signal( SIGTERM, exit_on_signal );
|
|
|
|
signal( SIGINT, exit_on_signal );
|
|
|
|
#ifdef SIGHUP
|
|
|
|
signal( SIGHUP, exit_on_signal );
|
|
|
|
#endif
|
2002-07-16 05:20:45 +02:00
|
|
|
|
|
|
|
now = time(NULL);
|
|
|
|
|
2006-04-22 21:52:51 +02:00
|
|
|
while((optc = getopt_long(argc, argv, short_options, long_options, &opti)) != EOF) {
|
2002-07-16 05:20:45 +02:00
|
|
|
switch(optc) {
|
2006-04-22 21:52:51 +02:00
|
|
|
case 1:
|
|
|
|
old_names = 1;
|
|
|
|
break;
|
2005-02-23 21:31:07 +01:00
|
|
|
case 'c':
|
|
|
|
do_everything = 0;
|
|
|
|
do_client = 1;
|
|
|
|
break;
|
|
|
|
case 'C':
|
|
|
|
client_name = strdup(optarg);
|
|
|
|
break;
|
2002-07-16 05:20:45 +02:00
|
|
|
case 'd':
|
|
|
|
debuglevel = strtol(optarg, NULL, 0);
|
|
|
|
break;
|
|
|
|
case 'D':
|
|
|
|
wpp_add_cmdline_define(optarg);
|
|
|
|
break;
|
|
|
|
case 'E':
|
2004-01-07 05:21:27 +01:00
|
|
|
do_everything = 0;
|
2002-07-16 05:20:45 +02:00
|
|
|
preprocess_only = 1;
|
|
|
|
break;
|
2002-11-21 01:02:38 +01:00
|
|
|
case 'h':
|
2004-01-07 05:21:27 +01:00
|
|
|
do_everything = 0;
|
2005-01-26 20:40:47 +01:00
|
|
|
do_header = 1;
|
2002-11-21 01:02:38 +01:00
|
|
|
break;
|
2002-07-16 05:20:45 +02:00
|
|
|
case 'H':
|
|
|
|
header_name = strdup(optarg);
|
|
|
|
break;
|
|
|
|
case 'I':
|
|
|
|
wpp_add_include_path(optarg);
|
|
|
|
break;
|
|
|
|
case 'N':
|
|
|
|
no_preprocess = 1;
|
|
|
|
break;
|
2005-02-23 21:31:07 +01:00
|
|
|
case 'p':
|
|
|
|
do_everything = 0;
|
|
|
|
do_proxies = 1;
|
|
|
|
break;
|
|
|
|
case 'P':
|
|
|
|
proxy_name = strdup(optarg);
|
|
|
|
break;
|
|
|
|
case 's':
|
|
|
|
do_everything = 0;
|
|
|
|
do_server = 1;
|
|
|
|
break;
|
|
|
|
case 'S':
|
|
|
|
server_name = strdup(optarg);
|
|
|
|
break;
|
2004-01-07 05:21:27 +01:00
|
|
|
case 't':
|
|
|
|
do_everything = 0;
|
2005-01-26 20:40:47 +01:00
|
|
|
do_typelib = 1;
|
2004-01-07 05:21:27 +01:00
|
|
|
break;
|
|
|
|
case 'T':
|
|
|
|
typelib_name = strdup(optarg);
|
|
|
|
break;
|
2002-07-16 05:20:45 +02:00
|
|
|
case 'V':
|
|
|
|
printf(version_string);
|
|
|
|
return 0;
|
|
|
|
case 'W':
|
|
|
|
pedantic = 1;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
fprintf(stderr, usage);
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2005-01-26 20:40:47 +01:00
|
|
|
if(do_everything) {
|
2005-02-23 21:31:07 +01:00
|
|
|
do_header = do_typelib = do_proxies = do_client = do_server = 1;
|
2005-01-26 20:40:47 +01:00
|
|
|
}
|
2002-07-16 05:20:45 +02:00
|
|
|
if(optind < argc) {
|
2003-03-17 00:52:24 +01:00
|
|
|
input_name = xstrdup(argv[optind]);
|
2002-07-16 05:20:45 +02:00
|
|
|
}
|
|
|
|
else {
|
|
|
|
fprintf(stderr, usage);
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
if(debuglevel)
|
|
|
|
{
|
|
|
|
setbuf(stdout,0);
|
|
|
|
setbuf(stderr,0);
|
|
|
|
}
|
|
|
|
|
|
|
|
yydebug = debuglevel & DEBUGLEVEL_TRACE ? 1 : 0;
|
|
|
|
yy_flex_debug = debuglevel & DEBUGLEVEL_TRACE ? 1 : 0;
|
|
|
|
|
|
|
|
wpp_set_debug( (debuglevel & DEBUGLEVEL_PPLEX) != 0,
|
|
|
|
(debuglevel & DEBUGLEVEL_PPTRACE) != 0,
|
|
|
|
(debuglevel & DEBUGLEVEL_PPMSG) != 0 );
|
|
|
|
|
2005-04-18 18:54:54 +02:00
|
|
|
if (!header_name) {
|
2002-07-16 05:20:45 +02:00
|
|
|
header_name = dup_basename(input_name, ".idl");
|
|
|
|
strcat(header_name, ".h");
|
|
|
|
}
|
|
|
|
|
2005-01-26 20:40:47 +01:00
|
|
|
if (!typelib_name && do_typelib) {
|
2004-01-07 05:21:27 +01:00
|
|
|
typelib_name = dup_basename(input_name, ".idl");
|
|
|
|
strcat(typelib_name, ".tlb");
|
|
|
|
}
|
|
|
|
|
2005-01-26 20:40:47 +01:00
|
|
|
if (!proxy_name && do_proxies) {
|
2002-07-16 05:20:45 +02:00
|
|
|
proxy_name = dup_basename(input_name, ".idl");
|
|
|
|
strcat(proxy_name, "_p.c");
|
|
|
|
}
|
|
|
|
|
2005-02-23 21:31:07 +01:00
|
|
|
if (!client_name && do_client) {
|
|
|
|
client_name = dup_basename(input_name, ".idl");
|
|
|
|
strcat(client_name, "_c.c");
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!server_name && do_server) {
|
|
|
|
server_name = dup_basename(input_name, ".idl");
|
|
|
|
strcat(server_name, "_s.c");
|
|
|
|
}
|
|
|
|
|
2006-02-02 13:22:47 +01:00
|
|
|
if (do_proxies) proxy_token = dup_basename_token(proxy_name,"_p.c");
|
|
|
|
if (do_client) client_token = dup_basename_token(client_name,"_c.c");
|
|
|
|
if (do_server) server_token = dup_basename_token(server_name,"_s.c");
|
|
|
|
|
2003-01-09 02:05:54 +01:00
|
|
|
wpp_add_cmdline_define("__WIDL__");
|
|
|
|
|
2002-07-16 05:20:45 +02:00
|
|
|
atexit(rm_tempfile);
|
|
|
|
if (!no_preprocess)
|
|
|
|
{
|
2005-01-05 18:30:37 +01:00
|
|
|
chat("Starting preprocess\n");
|
2002-07-16 05:20:45 +02:00
|
|
|
|
|
|
|
if (!preprocess_only)
|
|
|
|
{
|
2002-08-28 00:29:26 +02:00
|
|
|
ret = wpp_parse_temp( input_name, header_name, &temp_name );
|
2002-07-16 05:20:45 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
ret = wpp_parse( input_name, stdout );
|
|
|
|
}
|
|
|
|
|
|
|
|
if(ret) exit(1);
|
|
|
|
if(preprocess_only) exit(0);
|
2002-11-12 03:12:35 +01:00
|
|
|
if(!(yyin = fopen(temp_name, "r"))) {
|
|
|
|
fprintf(stderr, "Could not open %s for input\n", temp_name);
|
|
|
|
return 1;
|
|
|
|
}
|
2002-07-16 05:20:45 +02:00
|
|
|
}
|
2002-11-12 03:12:35 +01:00
|
|
|
else {
|
|
|
|
if(!(yyin = fopen(input_name, "r"))) {
|
|
|
|
fprintf(stderr, "Could not open %s for input\n", input_name);
|
|
|
|
return 1;
|
|
|
|
}
|
2002-07-16 05:20:45 +02:00
|
|
|
}
|
|
|
|
|
2005-01-26 20:40:47 +01:00
|
|
|
if(do_header) {
|
2004-12-27 18:13:25 +01:00
|
|
|
header_token = make_token(header_name);
|
2002-11-12 03:12:35 +01:00
|
|
|
|
2004-12-27 18:13:25 +01:00
|
|
|
if(!(header = fopen(header_name, "w"))) {
|
|
|
|
fprintf(stderr, "Could not open %s for output\n", header_name);
|
|
|
|
return 1;
|
|
|
|
}
|
2005-10-08 12:37:09 +02:00
|
|
|
fprintf(header, "/*** Autogenerated by WIDL %s from %s - Do not edit ***/\n", PACKAGE_VERSION, input_name);
|
2004-12-27 18:13:25 +01:00
|
|
|
fprintf(header, "#include <rpc.h>\n" );
|
|
|
|
fprintf(header, "#include <rpcndr.h>\n\n" );
|
|
|
|
fprintf(header, "#ifndef __WIDL_%s\n", header_token);
|
|
|
|
fprintf(header, "#define __WIDL_%s\n", header_token);
|
|
|
|
fprintf(header, "#ifdef __cplusplus\n");
|
|
|
|
fprintf(header, "extern \"C\" {\n");
|
|
|
|
fprintf(header, "#endif\n");
|
2005-01-26 20:40:47 +01:00
|
|
|
}
|
2004-12-27 18:13:25 +01:00
|
|
|
|
2005-01-26 20:40:47 +01:00
|
|
|
ret = yyparse();
|
2004-12-27 18:13:25 +01:00
|
|
|
|
2005-01-26 20:40:47 +01:00
|
|
|
if(do_header) {
|
2005-09-12 22:13:40 +02:00
|
|
|
fprintf(header, "/* Begin additional prototypes for all interfaces */\n");
|
|
|
|
fprintf(header, "\n");
|
|
|
|
write_user_types();
|
|
|
|
fprintf(header, "\n");
|
|
|
|
fprintf(header, "/* End additional prototypes */\n");
|
|
|
|
fprintf(header, "\n");
|
2004-12-27 18:13:25 +01:00
|
|
|
fprintf(header, "#ifdef __cplusplus\n");
|
|
|
|
fprintf(header, "}\n");
|
|
|
|
fprintf(header, "#endif\n");
|
|
|
|
fprintf(header, "#endif /* __WIDL_%s */\n", header_token);
|
|
|
|
fclose(header);
|
2004-10-11 21:54:37 +02:00
|
|
|
}
|
2004-12-27 18:13:25 +01:00
|
|
|
|
2002-07-16 05:20:45 +02:00
|
|
|
fclose(yyin);
|
|
|
|
|
|
|
|
if(ret) {
|
|
|
|
exit(1);
|
|
|
|
}
|
2003-03-17 00:52:24 +01:00
|
|
|
header_name = NULL;
|
2005-02-23 21:31:07 +01:00
|
|
|
client_name = NULL;
|
|
|
|
server_name = NULL;
|
2002-07-16 05:20:45 +02:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void rm_tempfile(void)
|
|
|
|
{
|
|
|
|
abort_import();
|
|
|
|
if(temp_name)
|
|
|
|
unlink(temp_name);
|
2003-03-17 00:52:24 +01:00
|
|
|
if (header_name)
|
2005-02-23 21:31:07 +01:00
|
|
|
unlink(header_name);
|
|
|
|
if (client_name)
|
|
|
|
unlink(client_name);
|
|
|
|
if (server_name)
|
|
|
|
unlink(server_name);
|
2002-07-16 05:20:45 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
static void segvhandler(int sig)
|
|
|
|
{
|
|
|
|
fprintf(stderr, "\n%s:%d: Oops, segment violation\n", input_name, line_number);
|
|
|
|
fflush(stdout);
|
|
|
|
fflush(stderr);
|
|
|
|
abort();
|
|
|
|
}
|