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
|
|
|
|
2007-10-18 03:03:57 +02:00
|
|
|
#include <errno.h>
|
2007-04-26 03:17:31 +02:00
|
|
|
#include <limits.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>
|
|
|
|
|
|
|
|
#include "widl.h"
|
|
|
|
#include "utils.h"
|
|
|
|
#include "parser.h"
|
2021-09-23 22:00:36 +02:00
|
|
|
#include "wpp_private.h"
|
2005-09-12 22:13:40 +02:00
|
|
|
#include "header.h"
|
2002-07-16 05:20:45 +02:00
|
|
|
|
2007-08-30 10:17:50 +02:00
|
|
|
static const char usage[] =
|
2002-07-16 05:20:45 +02:00
|
|
|
"Usage: widl [options...] infile.idl\n"
|
2007-10-18 03:03:57 +02:00
|
|
|
" or: widl [options...] --dlldata-only name1 [name2...]\n"
|
2018-11-09 14:16:51 +01:00
|
|
|
" --acf=file Use ACF file\n"
|
2012-11-07 11:25:21 +01:00
|
|
|
" -app_config Ignored, present for midl compatibility\n"
|
2009-05-21 11:37:34 +02:00
|
|
|
" -b arch Set the target architecture\n"
|
|
|
|
" -c Generate client stub\n"
|
|
|
|
" -d n Set debug level to 'n'\n"
|
|
|
|
" -D id[=val] Define preprocessor identifier id=val\n"
|
|
|
|
" -E Preprocess only\n"
|
2012-06-08 11:15:17 +02:00
|
|
|
" --help Display this help and exit\n"
|
2009-05-21 11:37:34 +02:00
|
|
|
" -h Generate headers\n"
|
|
|
|
" -H file Name of header file (default is infile.h)\n"
|
|
|
|
" -I path Set include search dir to path (multiple -I allowed)\n"
|
|
|
|
" --local-stubs=file Write empty stubs for call_as/local methods to file\n"
|
2018-11-14 18:18:17 +01:00
|
|
|
" -m32, -m64 Set the target architecture (Win32 or Win64)\n"
|
2009-05-21 11:37:34 +02:00
|
|
|
" -N Do not preprocess input\n"
|
2019-11-02 13:34:27 +01:00
|
|
|
" --nostdinc Do not search the standard include path\n"
|
|
|
|
" --ns_prefix Prefix namespaces with ABI namespace\n"
|
2009-05-21 11:37:34 +02:00
|
|
|
" --oldnames Use old naming conventions\n"
|
2010-11-27 12:33:05 +01:00
|
|
|
" -o, --output=NAME Set the output file name\n"
|
2011-06-01 21:00:56 +02:00
|
|
|
" -Otype Type of stubs to generate (-Os, -Oi, -Oif)\n"
|
2009-05-21 11:37:34 +02:00
|
|
|
" -p Generate proxy\n"
|
|
|
|
" --prefix-all=p Prefix names of client stubs / server functions with 'p'\n"
|
2007-04-26 03:17:31 +02:00
|
|
|
" --prefix-client=p Prefix names of client stubs with 'p'\n"
|
|
|
|
" --prefix-server=p Prefix names of server functions with 'p'\n"
|
2010-11-27 13:24:49 +01:00
|
|
|
" -r Generate registration script\n"
|
2018-11-01 15:02:42 +01:00
|
|
|
" -robust Ignored, present for midl compatibility\n"
|
2019-11-02 13:34:27 +01:00
|
|
|
" --sysroot=DIR Prefix include paths with DIR\n"
|
2009-05-21 11:37:34 +02:00
|
|
|
" -s Generate server stub\n"
|
|
|
|
" -t Generate typelib\n"
|
|
|
|
" -u Generate interface identifiers file\n"
|
|
|
|
" -V Print version and exit\n"
|
|
|
|
" -W Enable pedantic warnings\n"
|
2018-11-14 18:18:17 +01:00
|
|
|
" --win32, --win64 Set the target architecture (Win32 or Win64)\n"
|
2009-08-25 14:29:47 +02:00
|
|
|
" --win32-align n Set win32 structure alignment to 'n'\n"
|
|
|
|
" --win64-align n Set win64 structure alignment to 'n'\n"
|
2019-11-02 13:34:27 +01:00
|
|
|
" --winrt Enable Windows Runtime mode\n"
|
2002-07-16 05:20:45 +02:00
|
|
|
"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";
|
|
|
|
|
2018-11-14 18:18:17 +01:00
|
|
|
#ifdef __i386__
|
|
|
|
enum target_cpu target_cpu = CPU_x86;
|
|
|
|
#elif defined(__x86_64__)
|
|
|
|
enum target_cpu target_cpu = CPU_x86_64;
|
2021-01-31 18:34:15 +01:00
|
|
|
#elif defined(__powerpc64__)
|
|
|
|
enum target_cpu target_cpu = CPU_POWERPC64;
|
2018-11-14 18:18:17 +01:00
|
|
|
#elif defined(__powerpc__)
|
|
|
|
enum target_cpu target_cpu = CPU_POWERPC;
|
|
|
|
#elif defined(__arm__)
|
|
|
|
enum target_cpu target_cpu = CPU_ARM;
|
|
|
|
#elif defined(__aarch64__)
|
|
|
|
enum target_cpu target_cpu = CPU_ARM64;
|
|
|
|
#else
|
|
|
|
#error Unsupported CPU
|
|
|
|
#endif
|
|
|
|
|
2002-07-16 05:20:45 +02:00
|
|
|
int debuglevel = DEBUGLEVEL_NONE;
|
2006-09-12 09:05:07 +02:00
|
|
|
int parser_debug, yy_flex_debug;
|
2002-07-16 05:20:45 +02:00
|
|
|
|
|
|
|
int pedantic = 0;
|
2007-01-19 12:46:19 +01:00
|
|
|
int do_everything = 1;
|
2010-01-21 12:56:53 +01:00
|
|
|
static 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;
|
2010-11-27 13:24:49 +01:00
|
|
|
int do_regscript = 0;
|
2006-08-04 02:48:45 +02:00
|
|
|
int do_idfile = 0;
|
2007-10-18 03:03:57 +02:00
|
|
|
int do_dlldata = 0;
|
2010-01-21 12:56:53 +01:00
|
|
|
static int no_preprocess = 0;
|
2006-04-22 21:52:51 +02:00
|
|
|
int old_names = 0;
|
2009-08-25 14:29:47 +02:00
|
|
|
int win32_packing = 8;
|
|
|
|
int win64_packing = 8;
|
2015-07-30 14:14:57 +02:00
|
|
|
int winrt_mode = 0;
|
2015-08-05 12:52:15 +02:00
|
|
|
int use_abi_namespace = 0;
|
2019-11-02 13:34:27 +01:00
|
|
|
static int stdinc = 1;
|
2011-06-08 12:14:47 +02:00
|
|
|
static enum stub_mode stub_mode = MODE_Os;
|
2002-07-16 05:20:45 +02:00
|
|
|
|
|
|
|
char *input_name;
|
2013-08-29 15:09:21 +02:00
|
|
|
char *input_idl_name;
|
2018-11-09 14:16:51 +01:00
|
|
|
char *acf_name;
|
2002-07-16 05:20:45 +02:00
|
|
|
char *header_name;
|
2007-10-31 03:07:36 +01:00
|
|
|
char *local_stubs_name;
|
2002-11-12 03:12:35 +01:00
|
|
|
char *header_token;
|
2004-01-07 05:21:27 +01:00
|
|
|
char *typelib_name;
|
2007-10-18 03:03:57 +02:00
|
|
|
char *dlldata_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;
|
2010-11-27 13:24:49 +01:00
|
|
|
char *regscript_name;
|
|
|
|
char *regscript_token;
|
2010-01-21 12:56:53 +01:00
|
|
|
static char *idfile_name;
|
2002-07-16 05:20:45 +02:00
|
|
|
char *temp_name;
|
2007-04-26 03:17:31 +02:00
|
|
|
const char *prefix_client = "";
|
|
|
|
const char *prefix_server = "";
|
2020-01-30 11:33:13 +01:00
|
|
|
static const char *includedir;
|
2021-10-05 11:52:15 +02:00
|
|
|
static char *output_name;
|
|
|
|
static const char *sysroot = "";
|
2002-07-16 05:20:45 +02:00
|
|
|
|
|
|
|
int line_number = 1;
|
|
|
|
|
2010-01-21 12:56:53 +01:00
|
|
|
static FILE *idfile;
|
2002-07-16 05:20:45 +02:00
|
|
|
|
2011-05-26 21:34:51 +02:00
|
|
|
unsigned int pointer_size = 0;
|
2008-12-26 17:20:53 +01:00
|
|
|
|
2002-07-16 05:20:45 +02:00
|
|
|
time_t now;
|
|
|
|
|
2007-04-26 03:17:31 +02:00
|
|
|
enum {
|
|
|
|
OLDNAMES_OPTION = CHAR_MAX + 1,
|
2018-11-09 14:16:51 +01:00
|
|
|
ACF_OPTION,
|
|
|
|
APP_CONFIG_OPTION,
|
2007-10-18 03:03:57 +02:00
|
|
|
DLLDATA_OPTION,
|
|
|
|
DLLDATA_ONLY_OPTION,
|
2007-10-31 03:07:36 +01:00
|
|
|
LOCAL_STUBS_OPTION,
|
2019-11-02 13:34:27 +01:00
|
|
|
NOSTDINC_OPTION,
|
2007-04-26 03:17:31 +02:00
|
|
|
PREFIX_ALL_OPTION,
|
|
|
|
PREFIX_CLIENT_OPTION,
|
2008-12-26 17:21:12 +01:00
|
|
|
PREFIX_SERVER_OPTION,
|
2012-06-08 11:15:17 +02:00
|
|
|
PRINT_HELP,
|
2015-08-05 12:52:15 +02:00
|
|
|
RT_NS_PREFIX,
|
2013-08-08 12:29:33 +02:00
|
|
|
RT_OPTION,
|
2018-11-09 14:16:51 +01:00
|
|
|
ROBUST_OPTION,
|
2019-11-02 13:34:27 +01:00
|
|
|
SYSROOT_OPTION,
|
2008-12-26 17:21:12 +01:00
|
|
|
WIN32_OPTION,
|
2009-08-25 14:29:47 +02:00
|
|
|
WIN64_OPTION,
|
|
|
|
WIN32_ALIGN_OPTION,
|
2018-11-09 14:16:51 +01:00
|
|
|
WIN64_ALIGN_OPTION
|
2007-04-26 03:17:31 +02:00
|
|
|
};
|
|
|
|
|
2007-08-30 10:17:50 +02:00
|
|
|
static const char short_options[] =
|
2011-06-01 21:00:56 +02:00
|
|
|
"b:cC:d:D:EhH:I:m:No:O:pP:rsS:tT:uU:VW";
|
2021-10-05 11:52:15 +02:00
|
|
|
static const struct long_option long_options[] = {
|
|
|
|
{ "acf", 1, ACF_OPTION },
|
|
|
|
{ "app_config", 0, APP_CONFIG_OPTION },
|
|
|
|
{ "dlldata", 1, DLLDATA_OPTION },
|
|
|
|
{ "dlldata-only", 0, DLLDATA_ONLY_OPTION },
|
|
|
|
{ "help", 0, PRINT_HELP },
|
|
|
|
{ "local-stubs", 1, LOCAL_STUBS_OPTION },
|
|
|
|
{ "nostdinc", 0, NOSTDINC_OPTION },
|
|
|
|
{ "ns_prefix", 0, RT_NS_PREFIX },
|
|
|
|
{ "oldnames", 0, OLDNAMES_OPTION },
|
|
|
|
{ "output", 0, 'o' },
|
|
|
|
{ "prefix-all", 1, PREFIX_ALL_OPTION },
|
|
|
|
{ "prefix-client", 1, PREFIX_CLIENT_OPTION },
|
|
|
|
{ "prefix-server", 1, PREFIX_SERVER_OPTION },
|
|
|
|
{ "robust", 0, ROBUST_OPTION },
|
|
|
|
{ "sysroot", 1, SYSROOT_OPTION },
|
|
|
|
{ "target", 0, 'b' },
|
|
|
|
{ "winrt", 0, RT_OPTION },
|
|
|
|
{ "win32", 0, WIN32_OPTION },
|
|
|
|
{ "win64", 0, WIN64_OPTION },
|
|
|
|
{ "win32-align", 1, WIN32_ALIGN_OPTION },
|
|
|
|
{ "win64-align", 1, WIN64_ALIGN_OPTION },
|
|
|
|
{ NULL }
|
2006-04-22 21:52:51 +02:00
|
|
|
};
|
|
|
|
|
2021-05-16 23:22:42 +02:00
|
|
|
static const struct
|
|
|
|
{
|
|
|
|
const char *name;
|
|
|
|
enum target_cpu cpu;
|
|
|
|
} cpu_names[] =
|
|
|
|
{
|
|
|
|
{ "i386", CPU_x86 },
|
|
|
|
{ "i486", CPU_x86 },
|
|
|
|
{ "i586", CPU_x86 },
|
|
|
|
{ "i686", CPU_x86 },
|
|
|
|
{ "i786", CPU_x86 },
|
|
|
|
{ "amd64", CPU_x86_64 },
|
|
|
|
{ "x86_64", CPU_x86_64 },
|
|
|
|
{ "powerpc", CPU_POWERPC },
|
|
|
|
{ "powerpc64", CPU_POWERPC64 },
|
|
|
|
{ "powerpc64le", CPU_POWERPC64 },
|
|
|
|
{ "arm", CPU_ARM },
|
|
|
|
{ "armv5", CPU_ARM },
|
|
|
|
{ "armv6", CPU_ARM },
|
|
|
|
{ "armv7", CPU_ARM },
|
|
|
|
{ "armv7a", CPU_ARM },
|
|
|
|
{ "arm64", CPU_ARM64 },
|
|
|
|
{ "aarch64", CPU_ARM64 },
|
|
|
|
};
|
|
|
|
|
2002-07-16 05:20:45 +02:00
|
|
|
static void rm_tempfile(void);
|
|
|
|
|
2011-06-08 12:14:47 +02:00
|
|
|
enum stub_mode get_stub_mode(void)
|
|
|
|
{
|
|
|
|
/* old-style interpreted stubs are not supported on 64-bit */
|
|
|
|
if (stub_mode == MODE_Oi && pointer_size == 8) return MODE_Oif;
|
|
|
|
return stub_mode;
|
|
|
|
}
|
|
|
|
|
2002-11-12 03:12:35 +01:00
|
|
|
static char *make_token(const char *name)
|
|
|
|
{
|
|
|
|
char *token;
|
|
|
|
int i;
|
|
|
|
|
2021-09-29 11:13:36 +02:00
|
|
|
token = get_basename( name );
|
2002-11-12 03:12:35 +01:00
|
|
|
for (i=0; token[i]; i++) {
|
|
|
|
if (!isalnum(token[i])) token[i] = '_';
|
2012-03-08 14:52:21 +01:00
|
|
|
else token[i] = tolower(token[i]);
|
2002-11-12 03:12:35 +01:00
|
|
|
}
|
|
|
|
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)
|
|
|
|
{
|
2021-09-29 11:13:36 +02:00
|
|
|
char *p, *ret = replace_extension( get_basename(name), ext, "" );
|
2006-02-02 13:22:47 +01:00
|
|
|
/* map invalid characters to '_' */
|
|
|
|
for (p = ret; *p; p++) if (!isalnum(*p)) *p = '_';
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2009-03-26 14:31:25 +01:00
|
|
|
static void add_widl_version_define(void)
|
|
|
|
{
|
2020-12-03 14:17:14 +01:00
|
|
|
char version_str[32];
|
2009-03-26 14:31:25 +01:00
|
|
|
unsigned int version;
|
|
|
|
const char *p = PACKAGE_VERSION;
|
|
|
|
|
|
|
|
/* major */
|
|
|
|
version = atoi(p) * 0x10000;
|
|
|
|
p = strchr(p, '.');
|
|
|
|
|
|
|
|
/* minor */
|
|
|
|
if (p)
|
|
|
|
{
|
|
|
|
version += atoi(p + 1) * 0x100;
|
|
|
|
p = strchr(p + 1, '.');
|
|
|
|
}
|
|
|
|
|
|
|
|
/* build */
|
|
|
|
if (p)
|
|
|
|
version += atoi(p + 1);
|
|
|
|
|
2021-10-06 10:16:59 +02:00
|
|
|
sprintf(version_str, "__WIDL__=0x%x", version);
|
2020-12-03 14:17:14 +01:00
|
|
|
wpp_add_cmdline_define(version_str);
|
2009-03-26 14:31:25 +01:00
|
|
|
}
|
|
|
|
|
2021-05-16 23:22:42 +02:00
|
|
|
static void set_cpu( const char *cpu, int error_out )
|
2009-05-21 11:37:34 +02:00
|
|
|
{
|
2021-05-16 23:22:42 +02:00
|
|
|
unsigned int i;
|
|
|
|
for (i = 0; i < ARRAY_SIZE( cpu_names ); i++)
|
2009-05-21 11:37:34 +02:00
|
|
|
{
|
2021-05-16 23:22:42 +02:00
|
|
|
if (!strcmp( cpu_names[i].name, cpu ))
|
|
|
|
{
|
|
|
|
target_cpu = cpu_names[i].cpu;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (error_out)
|
|
|
|
error( "Unrecognized CPU '%s'\n", cpu );
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Set the target platform based on a potential prefix of the executable name.
|
|
|
|
* If not found, or not matching a known CPU name, just proceed silently. */
|
|
|
|
static void init_argv0_target( const char *argv0 )
|
|
|
|
{
|
2021-09-29 11:13:36 +02:00
|
|
|
char *p, *name = get_basename( argv0 );
|
2021-05-16 23:22:42 +02:00
|
|
|
|
|
|
|
if (!(p = strchr(name, '-')))
|
2009-05-21 11:37:34 +02:00
|
|
|
{
|
2021-05-16 23:22:42 +02:00
|
|
|
free( name );
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
*p = 0;
|
|
|
|
set_cpu( name, 0 );
|
|
|
|
free( name );
|
|
|
|
}
|
2009-05-21 11:37:34 +02:00
|
|
|
|
2021-05-16 23:22:42 +02:00
|
|
|
/* set the target platform */
|
|
|
|
static void set_target( const char *target )
|
|
|
|
{
|
2009-05-21 11:37:34 +02:00
|
|
|
char *p, *spec = xstrdup( target );
|
|
|
|
|
|
|
|
/* target specification is in the form CPU-MANUFACTURER-OS or CPU-MANUFACTURER-KERNEL-OS */
|
|
|
|
|
|
|
|
if (!(p = strchr( spec, '-' ))) error( "Invalid target specification '%s'\n", target );
|
|
|
|
*p++ = 0;
|
2021-05-16 23:22:42 +02:00
|
|
|
set_cpu( spec, 1 );
|
|
|
|
free( spec );
|
2009-05-21 11:37:34 +02:00
|
|
|
}
|
|
|
|
|
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 */
|
|
|
|
}
|
|
|
|
|
2007-10-18 03:03:25 +02:00
|
|
|
static void set_everything(int x)
|
|
|
|
{
|
|
|
|
do_header = x;
|
|
|
|
do_typelib = x;
|
|
|
|
do_proxies = x;
|
|
|
|
do_client = x;
|
|
|
|
do_server = x;
|
2010-11-27 13:24:49 +01:00
|
|
|
do_regscript = x;
|
2007-10-18 03:03:25 +02:00
|
|
|
do_idfile = x;
|
2007-10-18 03:03:57 +02:00
|
|
|
do_dlldata = x;
|
|
|
|
}
|
|
|
|
|
2008-12-29 13:06:35 +01:00
|
|
|
void start_cplusplus_guard(FILE *fp)
|
2007-10-18 03:03:57 +02:00
|
|
|
{
|
|
|
|
fprintf(fp, "#ifdef __cplusplus\n");
|
|
|
|
fprintf(fp, "extern \"C\" {\n");
|
|
|
|
fprintf(fp, "#endif\n\n");
|
|
|
|
}
|
|
|
|
|
2008-12-29 13:06:35 +01:00
|
|
|
void end_cplusplus_guard(FILE *fp)
|
2007-10-18 03:03:57 +02:00
|
|
|
{
|
|
|
|
fprintf(fp, "#ifdef __cplusplus\n");
|
|
|
|
fprintf(fp, "}\n");
|
|
|
|
fprintf(fp, "#endif\n\n");
|
|
|
|
}
|
|
|
|
|
2021-09-29 11:21:11 +02:00
|
|
|
static void write_dlldata_list( struct strarray filenames, int define_proxy_delegation)
|
2007-10-18 03:03:57 +02:00
|
|
|
{
|
|
|
|
FILE *dlldata;
|
2021-09-29 11:21:11 +02:00
|
|
|
unsigned int i;
|
2007-10-18 03:03:57 +02:00
|
|
|
|
|
|
|
dlldata = fopen(dlldata_name, "w");
|
|
|
|
if (!dlldata)
|
|
|
|
error("couldn't open %s: %s\n", dlldata_name, strerror(errno));
|
|
|
|
|
|
|
|
fprintf(dlldata, "/*** Autogenerated by WIDL %s ", PACKAGE_VERSION);
|
|
|
|
fprintf(dlldata, "- Do not edit ***/\n\n");
|
2012-11-01 12:27:32 +01:00
|
|
|
if (define_proxy_delegation)
|
|
|
|
fprintf(dlldata, "#define PROXY_DELEGATION\n");
|
2007-10-18 03:03:57 +02:00
|
|
|
fprintf(dlldata, "#include <objbase.h>\n");
|
|
|
|
fprintf(dlldata, "#include <rpcproxy.h>\n\n");
|
|
|
|
start_cplusplus_guard(dlldata);
|
|
|
|
|
2021-09-29 11:21:11 +02:00
|
|
|
for (i = 0; i < filenames.count; i++)
|
|
|
|
fprintf(dlldata, "EXTERN_PROXY_FILE(%s)\n", filenames.str[i]);
|
2007-10-18 03:03:57 +02:00
|
|
|
|
|
|
|
fprintf(dlldata, "\nPROXYFILE_LIST_START\n");
|
|
|
|
fprintf(dlldata, "/* Start of list */\n");
|
2021-09-29 11:21:11 +02:00
|
|
|
for (i = 0; i < filenames.count; i++)
|
|
|
|
fprintf(dlldata, " REFERENCE_PROXY_FILE(%s),\n", filenames.str[i]);
|
2007-10-18 03:03:57 +02:00
|
|
|
fprintf(dlldata, "/* End of list */\n");
|
|
|
|
fprintf(dlldata, "PROXYFILE_LIST_END\n\n");
|
|
|
|
|
|
|
|
fprintf(dlldata, "DLLDATA_ROUTINES(aProxyFileList, GET_DLL_CLSID)\n\n");
|
|
|
|
end_cplusplus_guard(dlldata);
|
|
|
|
fclose(dlldata);
|
|
|
|
}
|
|
|
|
|
|
|
|
static char *eat_space(char *s)
|
|
|
|
{
|
|
|
|
while (isspace((unsigned char) *s))
|
|
|
|
++s;
|
|
|
|
return s;
|
|
|
|
}
|
|
|
|
|
2008-04-24 20:06:28 +02:00
|
|
|
void write_dlldata(const statement_list_t *stmts)
|
2007-10-18 03:03:57 +02:00
|
|
|
{
|
2021-09-29 11:21:11 +02:00
|
|
|
struct strarray filenames = empty_strarray;
|
2012-11-01 12:27:32 +01:00
|
|
|
int define_proxy_delegation = 0;
|
2007-10-18 03:03:57 +02:00
|
|
|
FILE *dlldata;
|
|
|
|
|
2008-04-24 20:06:28 +02:00
|
|
|
if (!do_dlldata || !need_proxy_file(stmts))
|
2007-10-18 03:03:57 +02:00
|
|
|
return;
|
|
|
|
|
2012-11-01 12:27:32 +01:00
|
|
|
define_proxy_delegation = need_proxy_delegation(stmts);
|
|
|
|
|
2007-10-18 03:03:57 +02:00
|
|
|
dlldata = fopen(dlldata_name, "r");
|
|
|
|
if (dlldata) {
|
2013-12-19 22:25:14 +01:00
|
|
|
static const char marker[] = "REFERENCE_PROXY_FILE";
|
2012-11-01 12:27:32 +01:00
|
|
|
static const char delegation_define[] = "#define PROXY_DELEGATION";
|
2007-10-18 03:03:57 +02:00
|
|
|
char *line = NULL;
|
|
|
|
size_t len = 0;
|
|
|
|
|
|
|
|
while (widl_getline(&line, &len, dlldata)) {
|
|
|
|
char *start, *end;
|
|
|
|
start = eat_space(line);
|
|
|
|
if (strncmp(start, marker, sizeof marker - 1) == 0) {
|
|
|
|
start = eat_space(start + sizeof marker - 1);
|
|
|
|
if (*start != '(')
|
|
|
|
continue;
|
|
|
|
end = start = eat_space(start + 1);
|
|
|
|
while (*end && *end != ')')
|
|
|
|
++end;
|
|
|
|
if (*end != ')')
|
|
|
|
continue;
|
|
|
|
while (isspace((unsigned char) end[-1]))
|
|
|
|
--end;
|
|
|
|
*end = '\0';
|
|
|
|
if (start < end)
|
2021-09-29 11:21:11 +02:00
|
|
|
strarray_add(&filenames, replace_extension( get_basename( start ), ".idl", "" ));
|
2012-11-01 12:27:32 +01:00
|
|
|
}else if (!define_proxy_delegation && strncmp(start, delegation_define, sizeof(delegation_define)-1)) {
|
|
|
|
define_proxy_delegation = 1;
|
2007-10-18 03:03:57 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (ferror(dlldata))
|
|
|
|
error("couldn't read from %s: %s\n", dlldata_name, strerror(errno));
|
|
|
|
|
|
|
|
free(line);
|
|
|
|
fclose(dlldata);
|
|
|
|
}
|
|
|
|
|
2021-09-29 11:21:11 +02:00
|
|
|
if (strarray_exists( &filenames, proxy_token ))
|
2007-10-18 03:03:57 +02:00
|
|
|
/* We're already in the list, no need to regenerate this file. */
|
|
|
|
return;
|
|
|
|
|
2021-09-29 11:21:11 +02:00
|
|
|
strarray_add(&filenames, proxy_token);
|
|
|
|
write_dlldata_list(filenames, define_proxy_delegation);
|
2007-10-18 03:03:25 +02:00
|
|
|
}
|
|
|
|
|
2014-01-09 12:15:02 +01:00
|
|
|
static void write_id_guid(FILE *f, const char *type, const char *guid_prefix, const char *name, const UUID *uuid)
|
|
|
|
{
|
|
|
|
if (!uuid) return;
|
|
|
|
fprintf(f, "MIDL_DEFINE_GUID(%s, %s_%s, 0x%08x, 0x%04x, 0x%04x, 0x%02x,0x%02x, 0x%02x,"
|
|
|
|
"0x%02x,0x%02x,0x%02x,0x%02x,0x%02x);\n",
|
|
|
|
type, guid_prefix, name, uuid->Data1, uuid->Data2, uuid->Data3, uuid->Data4[0],
|
|
|
|
uuid->Data4[1], uuid->Data4[2], uuid->Data4[3], uuid->Data4[4], uuid->Data4[5],
|
|
|
|
uuid->Data4[6], uuid->Data4[7]);
|
|
|
|
}
|
|
|
|
|
2008-12-29 13:06:12 +01:00
|
|
|
static void write_id_data_stmts(const statement_list_t *stmts)
|
|
|
|
{
|
|
|
|
const statement_t *stmt;
|
|
|
|
if (stmts) LIST_FOR_EACH_ENTRY( stmt, stmts, const statement_t, entry )
|
|
|
|
{
|
|
|
|
if (stmt->type == STMT_TYPE)
|
|
|
|
{
|
|
|
|
const type_t *type = stmt->u.type;
|
2009-02-23 14:48:05 +01:00
|
|
|
if (type_get_type(type) == TYPE_INTERFACE)
|
2008-12-29 13:06:12 +01:00
|
|
|
{
|
|
|
|
const UUID *uuid;
|
2009-11-25 10:53:49 +01:00
|
|
|
if (!is_object(type) && !is_attr(type->attrs, ATTR_DISPINTERFACE))
|
2008-12-29 13:06:12 +01:00
|
|
|
continue;
|
|
|
|
uuid = get_attrp(type->attrs, ATTR_UUID);
|
2014-01-09 12:15:02 +01:00
|
|
|
write_id_guid(idfile, "IID", is_attr(type->attrs, ATTR_DISPINTERFACE) ? "DIID" : "IID",
|
2008-12-29 13:06:12 +01:00
|
|
|
type->name, uuid);
|
2019-08-15 04:45:46 +02:00
|
|
|
if (type_iface_get_async_iface(type))
|
2018-11-11 20:42:30 +01:00
|
|
|
{
|
2019-08-15 04:45:46 +02:00
|
|
|
uuid = get_attrp(type_iface_get_async_iface(type)->attrs, ATTR_UUID);
|
|
|
|
write_id_guid(idfile, "IID", "IID", type_iface_get_async_iface(type)->name, uuid);
|
2018-11-11 20:42:30 +01:00
|
|
|
}
|
2008-12-29 13:06:12 +01:00
|
|
|
}
|
2009-02-23 14:48:05 +01:00
|
|
|
else if (type_get_type(type) == TYPE_COCLASS)
|
2008-12-29 13:06:12 +01:00
|
|
|
{
|
|
|
|
const UUID *uuid = get_attrp(type->attrs, ATTR_UUID);
|
2014-01-09 12:15:02 +01:00
|
|
|
write_id_guid(idfile, "CLSID", "CLSID", type->name, uuid);
|
2008-12-29 13:06:12 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else if (stmt->type == STMT_LIBRARY)
|
|
|
|
{
|
|
|
|
const UUID *uuid = get_attrp(stmt->u.lib->attrs, ATTR_UUID);
|
2014-01-09 12:15:02 +01:00
|
|
|
write_id_guid(idfile, "IID", "LIBID", stmt->u.lib->name, uuid);
|
2008-12-29 13:06:12 +01:00
|
|
|
write_id_data_stmts(stmt->u.lib->stmts);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void write_id_data(const statement_list_t *stmts)
|
|
|
|
{
|
|
|
|
if (!do_idfile) return;
|
|
|
|
|
|
|
|
idfile = fopen(idfile_name, "w");
|
|
|
|
if (! idfile) {
|
|
|
|
error("Could not open %s for output\n", idfile_name);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
fprintf(idfile, "/*** Autogenerated by WIDL %s ", PACKAGE_VERSION);
|
2013-08-29 15:09:21 +02:00
|
|
|
fprintf(idfile, "from %s - Do not edit ***/\n\n", input_idl_name);
|
2008-12-29 13:06:12 +01:00
|
|
|
fprintf(idfile, "#include <rpc.h>\n");
|
|
|
|
fprintf(idfile, "#include <rpcndr.h>\n\n");
|
2014-01-09 12:15:02 +01:00
|
|
|
|
|
|
|
fprintf(idfile, "#ifdef _MIDL_USE_GUIDDEF_\n\n");
|
|
|
|
|
|
|
|
fprintf(idfile, "#ifndef INITGUID\n");
|
|
|
|
fprintf(idfile, "#define INITGUID\n");
|
|
|
|
fprintf(idfile, "#include <guiddef.h>\n");
|
|
|
|
fprintf(idfile, "#undef INITGUID\n");
|
|
|
|
fprintf(idfile, "#else\n");
|
|
|
|
fprintf(idfile, "#include <guiddef.h>\n");
|
|
|
|
fprintf(idfile, "#endif\n\n");
|
|
|
|
|
|
|
|
fprintf(idfile, "#define MIDL_DEFINE_GUID(type,name,l,w1,w2,b1,b2,b3,b4,b5,b6,b7,b8) \\\n");
|
|
|
|
fprintf(idfile, " DEFINE_GUID(name,l,w1,w2,b1,b2,b3,b4,b5,b6,b7,b8)\n\n");
|
|
|
|
|
2018-11-09 13:55:30 +01:00
|
|
|
fprintf(idfile, "#elif defined(__cplusplus)\n\n");
|
|
|
|
|
|
|
|
fprintf(idfile, "#define MIDL_DEFINE_GUID(type,name,l,w1,w2,b1,b2,b3,b4,b5,b6,b7,b8) \\\n");
|
|
|
|
fprintf(idfile, " EXTERN_C const type DECLSPEC_SELECTANY name = {l,w1,w2,{b1,b2,b3,b4,b5,b6,b7,b8}}\n\n");
|
|
|
|
|
2014-01-09 12:15:02 +01:00
|
|
|
fprintf(idfile, "#else\n\n");
|
|
|
|
|
|
|
|
fprintf(idfile, "#define MIDL_DEFINE_GUID(type,name,l,w1,w2,b1,b2,b3,b4,b5,b6,b7,b8) \\\n");
|
2018-11-09 13:55:30 +01:00
|
|
|
fprintf(idfile, " const type DECLSPEC_SELECTANY name = {l,w1,w2,{b1,b2,b3,b4,b5,b6,b7,b8}}\n\n");
|
2014-01-09 12:15:02 +01:00
|
|
|
|
|
|
|
fprintf(idfile, "#endif\n\n");
|
2008-12-29 13:06:12 +01:00
|
|
|
start_cplusplus_guard(idfile);
|
|
|
|
|
|
|
|
write_id_data_stmts(stmts);
|
|
|
|
|
|
|
|
fprintf(idfile, "\n");
|
|
|
|
end_cplusplus_guard(idfile);
|
2014-01-09 12:15:02 +01:00
|
|
|
fprintf(idfile, "#undef MIDL_DEFINE_GUID\n" );
|
2008-12-29 13:06:12 +01:00
|
|
|
|
|
|
|
fclose(idfile);
|
|
|
|
}
|
|
|
|
|
2020-01-30 11:33:13 +01:00
|
|
|
static void init_argv0_dir( const char *argv0 )
|
|
|
|
{
|
|
|
|
#ifndef _WIN32
|
2021-09-29 11:13:36 +02:00
|
|
|
char *dir;
|
2020-01-30 11:33:13 +01:00
|
|
|
|
|
|
|
#if defined(__linux__) || defined(__FreeBSD_kernel__) || defined(__NetBSD__)
|
|
|
|
dir = realpath( "/proc/self/exe", NULL );
|
|
|
|
#elif defined (__FreeBSD__) || defined(__DragonFly__)
|
|
|
|
dir = realpath( "/proc/curproc/file", NULL );
|
|
|
|
#else
|
|
|
|
dir = realpath( argv0, NULL );
|
|
|
|
#endif
|
|
|
|
if (!dir) return;
|
2021-09-29 11:13:36 +02:00
|
|
|
includedir = strmake( "%s/%s", get_dirname( dir ), BIN_TO_INCLUDEDIR );
|
2020-01-30 11:33:13 +01:00
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2021-10-05 11:52:15 +02:00
|
|
|
static void option_callback( int optc, char *optarg )
|
2002-07-16 05:20:45 +02:00
|
|
|
{
|
2021-10-05 11:52:15 +02:00
|
|
|
switch (optc)
|
|
|
|
{
|
2007-10-18 03:03:57 +02:00
|
|
|
case DLLDATA_OPTION:
|
|
|
|
dlldata_name = xstrdup(optarg);
|
|
|
|
break;
|
|
|
|
case DLLDATA_ONLY_OPTION:
|
|
|
|
do_everything = 0;
|
|
|
|
do_dlldata = 1;
|
|
|
|
break;
|
2007-10-31 03:07:36 +01:00
|
|
|
case LOCAL_STUBS_OPTION:
|
|
|
|
do_everything = 0;
|
|
|
|
local_stubs_name = xstrdup(optarg);
|
|
|
|
break;
|
2019-11-02 13:34:27 +01:00
|
|
|
case NOSTDINC_OPTION:
|
|
|
|
stdinc = 0;
|
|
|
|
break;
|
2007-04-26 03:17:31 +02:00
|
|
|
case OLDNAMES_OPTION:
|
2006-04-22 21:52:51 +02:00
|
|
|
old_names = 1;
|
|
|
|
break;
|
2007-04-26 03:17:31 +02:00
|
|
|
case PREFIX_ALL_OPTION:
|
|
|
|
prefix_client = xstrdup(optarg);
|
|
|
|
prefix_server = xstrdup(optarg);
|
|
|
|
break;
|
|
|
|
case PREFIX_CLIENT_OPTION:
|
|
|
|
prefix_client = xstrdup(optarg);
|
|
|
|
break;
|
|
|
|
case PREFIX_SERVER_OPTION:
|
|
|
|
prefix_server = xstrdup(optarg);
|
|
|
|
break;
|
2012-06-08 11:15:17 +02:00
|
|
|
case PRINT_HELP:
|
|
|
|
fprintf(stderr, "%s", usage);
|
2021-10-05 11:52:15 +02:00
|
|
|
exit(0);
|
2013-08-08 12:29:33 +02:00
|
|
|
case RT_OPTION:
|
2015-07-30 14:14:57 +02:00
|
|
|
winrt_mode = 1;
|
2013-08-08 12:29:33 +02:00
|
|
|
break;
|
2015-08-05 12:52:15 +02:00
|
|
|
case RT_NS_PREFIX:
|
|
|
|
use_abi_namespace = 1;
|
|
|
|
break;
|
2019-11-02 13:34:27 +01:00
|
|
|
case SYSROOT_OPTION:
|
|
|
|
sysroot = xstrdup(optarg);
|
|
|
|
break;
|
2008-12-26 17:21:12 +01:00
|
|
|
case WIN32_OPTION:
|
2018-11-14 18:18:17 +01:00
|
|
|
pointer_size = 4;
|
2008-12-26 17:21:12 +01:00
|
|
|
break;
|
|
|
|
case WIN64_OPTION:
|
2018-11-14 18:18:17 +01:00
|
|
|
pointer_size = 8;
|
2008-12-26 17:21:12 +01:00
|
|
|
break;
|
2009-08-25 14:29:47 +02:00
|
|
|
case WIN32_ALIGN_OPTION:
|
|
|
|
win32_packing = strtol(optarg, NULL, 0);
|
|
|
|
if(win32_packing != 2 && win32_packing != 4 && win32_packing != 8)
|
|
|
|
error("Packing must be one of 2, 4 or 8\n");
|
|
|
|
break;
|
|
|
|
case WIN64_ALIGN_OPTION:
|
|
|
|
win64_packing = strtol(optarg, NULL, 0);
|
|
|
|
if(win64_packing != 2 && win64_packing != 4 && win64_packing != 8)
|
2009-08-17 16:16:54 +02:00
|
|
|
error("Packing must be one of 2, 4 or 8\n");
|
|
|
|
break;
|
2018-11-09 14:16:51 +01:00
|
|
|
case ACF_OPTION:
|
|
|
|
acf_name = xstrdup(optarg);
|
|
|
|
break;
|
2012-11-07 11:25:21 +01:00
|
|
|
case APP_CONFIG_OPTION:
|
|
|
|
/* widl does not distinguish between app_mode and default mode,
|
|
|
|
but we ignore this option for midl compatibility */
|
2018-11-09 14:16:51 +01:00
|
|
|
break;
|
2018-11-01 15:02:42 +01:00
|
|
|
case ROBUST_OPTION:
|
|
|
|
/* FIXME: Support robust option */
|
|
|
|
break;
|
2009-05-21 11:37:34 +02:00
|
|
|
case 'b':
|
|
|
|
set_target( optarg );
|
|
|
|
break;
|
2005-02-23 21:31:07 +01:00
|
|
|
case 'c':
|
|
|
|
do_everything = 0;
|
|
|
|
do_client = 1;
|
|
|
|
break;
|
|
|
|
case 'C':
|
2006-08-04 20:06:54 +02:00
|
|
|
client_name = xstrdup(optarg);
|
2005-02-23 21:31:07 +01:00
|
|
|
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':
|
2006-08-04 20:06:54 +02:00
|
|
|
header_name = xstrdup(optarg);
|
2002-07-16 05:20:45 +02:00
|
|
|
break;
|
|
|
|
case 'I':
|
|
|
|
wpp_add_include_path(optarg);
|
|
|
|
break;
|
2009-05-21 11:37:34 +02:00
|
|
|
case 'm':
|
2018-11-14 18:18:17 +01:00
|
|
|
if (!strcmp( optarg, "32" )) pointer_size = 4;
|
|
|
|
else if (!strcmp( optarg, "64" )) pointer_size = 8;
|
2009-05-21 11:37:34 +02:00
|
|
|
break;
|
2002-07-16 05:20:45 +02:00
|
|
|
case 'N':
|
|
|
|
no_preprocess = 1;
|
|
|
|
break;
|
2010-11-27 12:33:05 +01:00
|
|
|
case 'o':
|
|
|
|
output_name = xstrdup(optarg);
|
|
|
|
break;
|
2011-06-01 21:00:56 +02:00
|
|
|
case 'O':
|
|
|
|
if (!strcmp( optarg, "s" )) stub_mode = MODE_Os;
|
|
|
|
else if (!strcmp( optarg, "i" )) stub_mode = MODE_Oi;
|
|
|
|
else if (!strcmp( optarg, "ic" )) stub_mode = MODE_Oif;
|
|
|
|
else if (!strcmp( optarg, "if" )) stub_mode = MODE_Oif;
|
|
|
|
else if (!strcmp( optarg, "icf" )) stub_mode = MODE_Oif;
|
|
|
|
else error( "Invalid argument '-O%s'\n", optarg );
|
|
|
|
break;
|
2005-02-23 21:31:07 +01:00
|
|
|
case 'p':
|
|
|
|
do_everything = 0;
|
|
|
|
do_proxies = 1;
|
|
|
|
break;
|
|
|
|
case 'P':
|
2006-08-04 20:06:54 +02:00
|
|
|
proxy_name = xstrdup(optarg);
|
2005-02-23 21:31:07 +01:00
|
|
|
break;
|
2010-11-27 13:24:49 +01:00
|
|
|
case 'r':
|
|
|
|
do_everything = 0;
|
|
|
|
do_regscript = 1;
|
|
|
|
break;
|
2005-02-23 21:31:07 +01:00
|
|
|
case 's':
|
|
|
|
do_everything = 0;
|
|
|
|
do_server = 1;
|
|
|
|
break;
|
|
|
|
case 'S':
|
2006-08-04 20:06:54 +02:00
|
|
|
server_name = xstrdup(optarg);
|
2005-02-23 21:31:07 +01:00
|
|
|
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':
|
2006-08-04 20:06:54 +02:00
|
|
|
typelib_name = xstrdup(optarg);
|
2004-01-07 05:21:27 +01:00
|
|
|
break;
|
2006-08-04 02:48:45 +02:00
|
|
|
case 'u':
|
|
|
|
do_everything = 0;
|
|
|
|
do_idfile = 1;
|
|
|
|
break;
|
|
|
|
case 'U':
|
2006-08-04 20:06:54 +02:00
|
|
|
idfile_name = xstrdup(optarg);
|
2006-08-04 02:48:45 +02:00
|
|
|
break;
|
2002-07-16 05:20:45 +02:00
|
|
|
case 'V':
|
2007-10-18 03:05:37 +02:00
|
|
|
printf("%s", version_string);
|
2021-10-05 11:52:15 +02:00
|
|
|
exit(0);
|
2002-07-16 05:20:45 +02:00
|
|
|
case 'W':
|
|
|
|
pedantic = 1;
|
|
|
|
break;
|
2021-10-05 11:52:15 +02:00
|
|
|
case '?':
|
|
|
|
fprintf(stderr, "widl: %s\n\n%s", optarg, usage);
|
|
|
|
exit(1);
|
2002-07-16 05:20:45 +02:00
|
|
|
}
|
2021-10-05 11:52:15 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
int main(int argc,char *argv[])
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
int ret = 0;
|
|
|
|
struct strarray files;
|
|
|
|
|
|
|
|
signal( SIGTERM, exit_on_signal );
|
|
|
|
signal( SIGINT, exit_on_signal );
|
|
|
|
#ifdef SIGHUP
|
|
|
|
signal( SIGHUP, exit_on_signal );
|
|
|
|
#endif
|
|
|
|
init_argv0_dir( argv[0] );
|
|
|
|
init_argv0_target( argv[0] );
|
|
|
|
|
|
|
|
now = time(NULL);
|
|
|
|
|
|
|
|
files = parse_options( argc, argv, short_options, long_options, 1, option_callback );
|
2002-07-16 05:20:45 +02:00
|
|
|
|
2019-11-02 13:34:27 +01:00
|
|
|
if (stdinc)
|
|
|
|
{
|
|
|
|
static const char *incl_dirs[] = { INCLUDEDIR, "/usr/include", "/usr/local/include" };
|
|
|
|
|
2020-01-30 11:33:13 +01:00
|
|
|
if (includedir)
|
|
|
|
{
|
|
|
|
wpp_add_include_path( strmake( "%s/wine/msvcrt", includedir ));
|
|
|
|
wpp_add_include_path( strmake( "%s/wine/windows", includedir ));
|
|
|
|
}
|
2019-11-02 13:34:27 +01:00
|
|
|
for (i = 0; i < ARRAY_SIZE(incl_dirs); i++)
|
|
|
|
{
|
|
|
|
if (i && !strcmp( incl_dirs[i], incl_dirs[0] )) continue;
|
|
|
|
wpp_add_include_path( strmake( "%s%s/wine/msvcrt", sysroot, incl_dirs[i] ));
|
|
|
|
wpp_add_include_path( strmake( "%s%s/wine/windows", sysroot, incl_dirs[i] ));
|
|
|
|
}
|
|
|
|
}
|
2012-07-23 11:38:23 +02:00
|
|
|
|
2018-11-14 18:18:17 +01:00
|
|
|
switch (target_cpu)
|
|
|
|
{
|
|
|
|
case CPU_x86:
|
|
|
|
if (pointer_size == 8) target_cpu = CPU_x86_64;
|
|
|
|
else pointer_size = 4;
|
|
|
|
break;
|
|
|
|
case CPU_x86_64:
|
|
|
|
if (pointer_size == 4) target_cpu = CPU_x86;
|
|
|
|
else pointer_size = 8;
|
|
|
|
break;
|
2021-05-16 22:57:57 +02:00
|
|
|
case CPU_ARM:
|
|
|
|
if (pointer_size == 8) target_cpu = CPU_ARM64;
|
|
|
|
else pointer_size = 4;
|
|
|
|
break;
|
2018-11-14 18:18:17 +01:00
|
|
|
case CPU_ARM64:
|
2021-05-16 22:57:57 +02:00
|
|
|
if (pointer_size == 4) target_cpu = CPU_ARM;
|
2018-11-14 18:18:17 +01:00
|
|
|
pointer_size = 8;
|
|
|
|
break;
|
2021-01-31 18:34:15 +01:00
|
|
|
case CPU_POWERPC64:
|
|
|
|
if (pointer_size == 4) error( "Cannot build 32-bit code for this CPU\n" );
|
|
|
|
pointer_size = 8;
|
|
|
|
break;
|
2018-11-14 18:18:17 +01:00
|
|
|
default:
|
|
|
|
if (pointer_size == 8) error( "Cannot build 64-bit code for this CPU\n" );
|
|
|
|
pointer_size = 4;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2013-12-24 21:11:44 +01:00
|
|
|
/* if nothing specified, try to guess output type from the output file name */
|
|
|
|
if (output_name && do_everything && !do_header && !do_typelib && !do_proxies &&
|
|
|
|
!do_client && !do_server && !do_regscript && !do_idfile && !do_dlldata)
|
|
|
|
{
|
|
|
|
do_everything = 0;
|
|
|
|
if (strendswith( output_name, ".h" )) do_header = 1;
|
|
|
|
else if (strendswith( output_name, ".tlb" )) do_typelib = 1;
|
|
|
|
else if (strendswith( output_name, "_p.c" )) do_proxies = 1;
|
|
|
|
else if (strendswith( output_name, "_c.c" )) do_client = 1;
|
|
|
|
else if (strendswith( output_name, "_s.c" )) do_server = 1;
|
|
|
|
else if (strendswith( output_name, "_i.c" )) do_idfile = 1;
|
|
|
|
else if (strendswith( output_name, "_r.res" )) do_regscript = 1;
|
|
|
|
else if (strendswith( output_name, "_t.res" )) do_typelib = 1;
|
|
|
|
else if (strendswith( output_name, "dlldata.c" )) do_dlldata = 1;
|
|
|
|
else do_everything = 1;
|
|
|
|
}
|
|
|
|
|
2005-01-26 20:40:47 +01:00
|
|
|
if(do_everything) {
|
2007-10-18 03:03:25 +02:00
|
|
|
set_everything(TRUE);
|
2005-01-26 20:40:47 +01:00
|
|
|
}
|
2007-10-18 03:03:57 +02:00
|
|
|
|
2013-12-24 21:11:44 +01:00
|
|
|
if (do_header + do_typelib + do_proxies + do_client +
|
2021-02-09 13:38:50 +01:00
|
|
|
do_server + do_regscript + do_idfile + do_dlldata == 1 && output_name)
|
2010-11-27 12:33:05 +01:00
|
|
|
{
|
2021-02-09 13:38:50 +01:00
|
|
|
if (do_header && !header_name) header_name = output_name;
|
|
|
|
else if (do_typelib && !typelib_name) typelib_name = output_name;
|
|
|
|
else if (do_proxies && !proxy_name) proxy_name = output_name;
|
|
|
|
else if (do_client && !client_name) client_name = output_name;
|
|
|
|
else if (do_server && !server_name) server_name = output_name;
|
|
|
|
else if (do_regscript && !regscript_name) regscript_name = output_name;
|
|
|
|
else if (do_idfile && !idfile_name) idfile_name = output_name;
|
|
|
|
else if (do_dlldata && !dlldata_name) dlldata_name = output_name;
|
2010-11-27 12:33:05 +01:00
|
|
|
}
|
|
|
|
|
2007-10-18 03:03:57 +02:00
|
|
|
if (!dlldata_name && do_dlldata)
|
|
|
|
dlldata_name = xstrdup("dlldata.c");
|
|
|
|
|
2021-10-05 11:52:15 +02:00
|
|
|
if (files.count) {
|
2007-10-18 03:03:57 +02:00
|
|
|
if (do_dlldata && !do_everything) {
|
2021-09-29 11:21:11 +02:00
|
|
|
struct strarray filenames = empty_strarray;
|
2021-10-05 11:52:15 +02:00
|
|
|
for (i = 0; i < files.count; i++)
|
|
|
|
strarray_add(&filenames, replace_extension( get_basename( files.str[i] ), ".idl", "" ));
|
2007-10-18 03:03:57 +02:00
|
|
|
|
2021-09-29 11:21:11 +02:00
|
|
|
write_dlldata_list(filenames, 0 /* FIXME */ );
|
2007-10-18 03:03:57 +02:00
|
|
|
return 0;
|
|
|
|
}
|
2021-10-05 11:52:15 +02:00
|
|
|
else if (files.count > 1) {
|
2007-10-18 03:03:57 +02:00
|
|
|
fprintf(stderr, "%s", usage);
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
else
|
2021-10-05 11:52:15 +02:00
|
|
|
input_idl_name = input_name = xstrdup(files.str[0]);
|
2002-07-16 05:20:45 +02:00
|
|
|
}
|
|
|
|
else {
|
2007-10-18 03:05:37 +02:00
|
|
|
fprintf(stderr, "%s", usage);
|
2002-07-16 05:20:45 +02:00
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
if(debuglevel)
|
|
|
|
{
|
2010-01-21 12:56:53 +01:00
|
|
|
setbuf(stdout, NULL);
|
|
|
|
setbuf(stderr, NULL);
|
2002-07-16 05:20:45 +02:00
|
|
|
}
|
|
|
|
|
2006-09-12 09:05:07 +02:00
|
|
|
parser_debug = debuglevel & DEBUGLEVEL_TRACE ? 1 : 0;
|
2002-07-16 05:20:45 +02:00
|
|
|
yy_flex_debug = debuglevel & DEBUGLEVEL_TRACE ? 1 : 0;
|
|
|
|
|
|
|
|
wpp_set_debug( (debuglevel & DEBUGLEVEL_PPLEX) != 0,
|
|
|
|
(debuglevel & DEBUGLEVEL_PPTRACE) != 0,
|
|
|
|
(debuglevel & DEBUGLEVEL_PPMSG) != 0 );
|
|
|
|
|
2021-09-29 11:13:36 +02:00
|
|
|
if (!header_name)
|
|
|
|
header_name = replace_extension( get_basename(input_name), ".idl", ".h" );
|
2002-07-16 05:20:45 +02:00
|
|
|
|
2021-09-29 11:13:36 +02:00
|
|
|
if (!typelib_name && do_typelib)
|
|
|
|
typelib_name = replace_extension( get_basename(input_name), ".idl", ".tlb" );
|
2004-01-07 05:21:27 +01:00
|
|
|
|
2021-09-29 11:13:36 +02:00
|
|
|
if (!proxy_name && do_proxies)
|
|
|
|
proxy_name = replace_extension( get_basename(input_name), ".idl", "_p.c" );
|
2002-07-16 05:20:45 +02:00
|
|
|
|
2021-09-29 11:13:36 +02:00
|
|
|
if (!client_name && do_client)
|
|
|
|
client_name = replace_extension( get_basename(input_name), ".idl", "_c.c" );
|
2005-02-23 21:31:07 +01:00
|
|
|
|
2021-09-29 11:13:36 +02:00
|
|
|
if (!server_name && do_server)
|
|
|
|
server_name = replace_extension( get_basename(input_name), ".idl", "_s.c" );
|
2005-02-23 21:31:07 +01:00
|
|
|
|
2021-09-29 11:13:36 +02:00
|
|
|
if (!regscript_name && do_regscript)
|
|
|
|
regscript_name = replace_extension( get_basename(input_name), ".idl", "_r.rgs" );
|
2010-11-27 13:24:49 +01:00
|
|
|
|
2021-09-29 11:13:36 +02:00
|
|
|
if (!idfile_name && do_idfile)
|
|
|
|
idfile_name = replace_extension( get_basename(input_name), ".idl", "_i.c" );
|
2006-08-04 02:48:45 +02:00
|
|
|
|
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");
|
2010-11-27 13:24:49 +01:00
|
|
|
if (do_regscript) regscript_token = dup_basename_token(regscript_name,"_r.rgs");
|
2006-02-02 13:22:47 +01:00
|
|
|
|
2009-03-26 14:31:25 +01:00
|
|
|
add_widl_version_define();
|
2020-12-03 14:17:14 +01:00
|
|
|
wpp_add_cmdline_define("_WIN32=1");
|
2003-01-09 02:05:54 +01:00
|
|
|
|
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)
|
|
|
|
{
|
2010-03-30 15:34:12 +02:00
|
|
|
FILE *output;
|
|
|
|
int fd;
|
2021-09-29 09:32:01 +02:00
|
|
|
char *name;
|
2010-03-30 15:34:12 +02:00
|
|
|
|
2021-09-29 09:32:01 +02:00
|
|
|
fd = make_temp_file( header_name, NULL, &name );
|
2010-03-30 15:34:12 +02:00
|
|
|
temp_name = name;
|
|
|
|
if (!(output = fdopen(fd, "wt")))
|
|
|
|
error("Could not open fd %s for writing\n", name);
|
|
|
|
|
|
|
|
ret = wpp_parse( input_name, output );
|
|
|
|
fclose( output );
|
2002-07-16 05:20:45 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
ret = wpp_parse( input_name, stdout );
|
|
|
|
}
|
|
|
|
|
|
|
|
if(ret) exit(1);
|
|
|
|
if(preprocess_only) exit(0);
|
2006-09-12 09:05:07 +02:00
|
|
|
if(!(parser_in = fopen(temp_name, "r"))) {
|
2002-11-12 03:12:35 +01:00
|
|
|
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 {
|
2006-09-12 09:05:07 +02:00
|
|
|
if(!(parser_in = fopen(input_name, "r"))) {
|
2002-11-12 03:12:35 +01:00
|
|
|
fprintf(stderr, "Could not open %s for input\n", input_name);
|
|
|
|
return 1;
|
|
|
|
}
|
2002-07-16 05:20:45 +02:00
|
|
|
}
|
|
|
|
|
2008-12-29 13:06:35 +01:00
|
|
|
header_token = make_token(header_name);
|
2004-12-27 18:13:25 +01:00
|
|
|
|
2006-08-25 03:01:18 +02:00
|
|
|
init_types();
|
2006-09-12 09:05:07 +02:00
|
|
|
ret = parser_parse();
|
2004-12-27 18:13:25 +01:00
|
|
|
|
2006-09-12 09:05:07 +02:00
|
|
|
fclose(parser_in);
|
2002-07-16 05:20:45 +02:00
|
|
|
|
|
|
|
if(ret) {
|
|
|
|
exit(1);
|
|
|
|
}
|
2007-10-18 03:03:25 +02:00
|
|
|
|
|
|
|
/* Everything has been done successfully, don't delete any files. */
|
|
|
|
set_everything(FALSE);
|
2007-10-31 03:07:36 +01:00
|
|
|
local_stubs_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);
|
2007-10-18 03:03:25 +02:00
|
|
|
if (do_header)
|
2005-02-23 21:31:07 +01:00
|
|
|
unlink(header_name);
|
2007-10-31 03:07:36 +01:00
|
|
|
if (local_stubs_name)
|
|
|
|
unlink(local_stubs_name);
|
2007-10-18 03:03:25 +02:00
|
|
|
if (do_client)
|
2005-02-23 21:31:07 +01:00
|
|
|
unlink(client_name);
|
2007-10-18 03:03:25 +02:00
|
|
|
if (do_server)
|
2005-02-23 21:31:07 +01:00
|
|
|
unlink(server_name);
|
2010-11-27 13:24:49 +01:00
|
|
|
if (do_regscript)
|
|
|
|
unlink(regscript_name);
|
2007-10-18 03:03:25 +02:00
|
|
|
if (do_idfile)
|
|
|
|
unlink(idfile_name);
|
|
|
|
if (do_proxies)
|
|
|
|
unlink(proxy_name);
|
|
|
|
if (do_typelib)
|
|
|
|
unlink(typelib_name);
|
2002-07-16 05:20:45 +02:00
|
|
|
}
|