2000-03-18 21:56:10 +00:00
|
|
|
/*
|
|
|
|
* Option parsing
|
|
|
|
*
|
|
|
|
* Copyright 2000 Alexandre Julliard
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "config.h"
|
|
|
|
#include <string.h>
|
2000-05-30 17:51:44 +00:00
|
|
|
#include <stdlib.h>
|
2000-03-18 21:56:10 +00:00
|
|
|
|
|
|
|
#include "winbase.h"
|
2000-12-15 03:38:11 +00:00
|
|
|
#include "winnls.h"
|
2001-01-04 19:37:37 +00:00
|
|
|
#include "ntddk.h"
|
2000-11-08 04:28:54 +00:00
|
|
|
#include "wine/library.h"
|
2002-02-14 19:48:16 +00:00
|
|
|
#include "wine/version.h"
|
2000-03-18 21:56:10 +00:00
|
|
|
#include "options.h"
|
2001-07-23 00:04:00 +00:00
|
|
|
#include "module.h"
|
2000-03-18 21:56:10 +00:00
|
|
|
#include "debugtools.h"
|
|
|
|
|
2001-01-10 23:56:59 +00:00
|
|
|
struct option_descr
|
2000-03-18 21:56:10 +00:00
|
|
|
{
|
|
|
|
const char *longname;
|
|
|
|
char shortname;
|
|
|
|
int has_arg;
|
2000-05-30 17:51:44 +00:00
|
|
|
int inherit;
|
2000-03-18 21:56:10 +00:00
|
|
|
void (*func)( const char *arg );
|
|
|
|
const char *usage;
|
|
|
|
};
|
|
|
|
|
2000-05-29 21:25:10 +00:00
|
|
|
/* default options */
|
|
|
|
struct options Options =
|
|
|
|
{
|
2001-01-10 23:56:59 +00:00
|
|
|
FALSE /* Managed windows */
|
2000-05-29 21:25:10 +00:00
|
|
|
};
|
|
|
|
|
2000-07-16 18:21:34 +00:00
|
|
|
const char *argv0; /* the original argv[0] */
|
|
|
|
const char *full_argv0; /* the full path of argv[0] (if known) */
|
2000-05-29 21:25:10 +00:00
|
|
|
|
2000-05-30 17:51:44 +00:00
|
|
|
static char *inherit_str; /* options to pass to child processes */
|
|
|
|
|
|
|
|
static void out_of_memory(void) WINE_NORETURN;
|
|
|
|
static void out_of_memory(void)
|
|
|
|
{
|
|
|
|
MESSAGE( "Virtual memory exhausted\n" );
|
|
|
|
ExitProcess(1);
|
|
|
|
}
|
|
|
|
|
2000-11-05 04:51:34 +00:00
|
|
|
static void do_debugmsg( const char *arg );
|
2000-03-18 21:56:10 +00:00
|
|
|
static void do_help( const char *arg );
|
|
|
|
static void do_managed( const char *arg );
|
|
|
|
static void do_version( const char *arg );
|
|
|
|
|
2001-01-10 23:56:59 +00:00
|
|
|
static const struct option_descr option_table[] =
|
2000-03-18 21:56:10 +00:00
|
|
|
{
|
2000-11-05 04:51:34 +00:00
|
|
|
{ "debugmsg", 0, 1, 1, do_debugmsg,
|
2000-03-18 21:56:10 +00:00
|
|
|
"--debugmsg name Turn debugging-messages on or off" },
|
2001-03-20 02:11:08 +00:00
|
|
|
{ "dll", 0, 1, 1, MODULE_AddLoadOrderOption,
|
2000-03-18 21:56:10 +00:00
|
|
|
"--dll name Enable or disable built-in DLLs" },
|
2000-05-30 17:51:44 +00:00
|
|
|
{ "dosver", 0, 1, 1, VERSION_ParseDosVersion,
|
2000-11-27 01:39:05 +00:00
|
|
|
"--dosver x.xx DOS version to imitate (e.g. 6.22)\n"
|
|
|
|
" Only valid with --winver win31" },
|
2000-05-30 17:51:44 +00:00
|
|
|
{ "help", 'h', 0, 0, do_help,
|
2000-03-18 21:56:10 +00:00
|
|
|
"--help,-h Show this help message" },
|
2000-05-30 17:51:44 +00:00
|
|
|
{ "managed", 0, 0, 0, do_managed,
|
2000-03-18 21:56:10 +00:00
|
|
|
"--managed Allow the window manager to manage created windows" },
|
2000-05-30 17:51:44 +00:00
|
|
|
{ "version", 'v', 0, 0, do_version,
|
2000-03-18 21:56:10 +00:00
|
|
|
"--version,-v Display the Wine version" },
|
2000-05-30 17:51:44 +00:00
|
|
|
{ "winver", 0, 1, 1, VERSION_ParseWinVersion,
|
2001-11-06 00:49:48 +00:00
|
|
|
"--winver Version to imitate (win95,win98,winme,nt351,nt40,win2k,winxp,win20,win30,win31)" },
|
2000-10-24 02:22:16 +00:00
|
|
|
{ NULL, 0, 0, 0, NULL, NULL } /* terminator */
|
2000-03-18 21:56:10 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
static void do_help( const char *arg )
|
|
|
|
{
|
|
|
|
OPTIONS_Usage();
|
|
|
|
}
|
|
|
|
|
|
|
|
static void do_version( const char *arg )
|
|
|
|
{
|
|
|
|
MESSAGE( "%s\n", WINE_RELEASE_INFO );
|
|
|
|
ExitProcess(0);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void do_managed( const char *arg )
|
|
|
|
{
|
|
|
|
Options.managed = TRUE;
|
|
|
|
}
|
|
|
|
|
2000-11-05 04:51:34 +00:00
|
|
|
static void do_debugmsg( const char *arg )
|
|
|
|
{
|
2002-01-21 23:39:36 +00:00
|
|
|
static const char * const debug_class_names[__WINE_DBCL_COUNT] = { "fixme", "err", "warn", "trace" };
|
2000-11-05 04:51:34 +00:00
|
|
|
|
|
|
|
char *opt, *options = strdup(arg);
|
|
|
|
int i;
|
2001-01-04 19:37:37 +00:00
|
|
|
/* defined in relay32/relay386.c */
|
|
|
|
extern char **debug_relay_includelist;
|
|
|
|
extern char **debug_relay_excludelist;
|
|
|
|
/* defined in relay32/snoop.c */
|
|
|
|
extern char **debug_snoop_includelist;
|
|
|
|
extern char **debug_snoop_excludelist;
|
2000-11-05 04:51:34 +00:00
|
|
|
|
|
|
|
if (!(opt = strtok( options, "," ))) goto error;
|
|
|
|
do
|
|
|
|
{
|
|
|
|
unsigned char set = 0, clear = 0;
|
|
|
|
char *p = strchr( opt, '+' );
|
|
|
|
if (!p) p = strchr( opt, '-' );
|
|
|
|
if (!p || !p[1]) goto error;
|
|
|
|
if (p > opt)
|
|
|
|
{
|
2002-01-21 23:39:36 +00:00
|
|
|
for (i = 0; i < __WINE_DBCL_COUNT; i++)
|
2000-11-05 04:51:34 +00:00
|
|
|
{
|
|
|
|
int len = strlen(debug_class_names[i]);
|
|
|
|
if (len != (p - opt)) continue;
|
|
|
|
if (!memcmp( opt, debug_class_names[i], len )) /* found it */
|
|
|
|
{
|
|
|
|
if (*p == '+') set |= 1 << i;
|
|
|
|
else clear |= 1 << i;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2002-01-21 23:39:36 +00:00
|
|
|
if (i == __WINE_DBCL_COUNT) goto error; /* class name not found */
|
2000-11-05 04:51:34 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if (*p == '+') set = ~0;
|
|
|
|
else clear = ~0;
|
2001-01-04 19:37:37 +00:00
|
|
|
if (!strncasecmp(p+1, "relay=", 6) ||
|
|
|
|
!strncasecmp(p+1, "snoop=", 6))
|
|
|
|
{
|
|
|
|
int i, l;
|
|
|
|
char *s, *s2, ***output, c;
|
|
|
|
|
|
|
|
if (strchr(p,','))
|
|
|
|
l=strchr(p,',')-p;
|
|
|
|
else
|
|
|
|
l=strlen(p);
|
|
|
|
set = ~0;
|
|
|
|
clear = 0;
|
|
|
|
output = (*p == '+') ?
|
|
|
|
((*(p+1) == 'r') ?
|
|
|
|
&debug_relay_includelist :
|
|
|
|
&debug_snoop_includelist) :
|
|
|
|
((*(p+1) == 'r') ?
|
|
|
|
&debug_relay_excludelist :
|
|
|
|
&debug_snoop_excludelist);
|
|
|
|
s = p + 7;
|
|
|
|
/* if there are n ':', there are n+1 modules, and we need
|
|
|
|
n+2 slots, last one being for the sentinel (NULL) */
|
|
|
|
i = 2;
|
|
|
|
while((s = strchr(s, ':'))) i++, s++;
|
|
|
|
*output = malloc(sizeof(char **) * i);
|
|
|
|
i = 0;
|
|
|
|
s = p + 7;
|
|
|
|
while((s2 = strchr(s, ':'))) {
|
|
|
|
c = *s2;
|
|
|
|
*s2 = '\0';
|
|
|
|
*((*output)+i) = _strupr(strdup(s));
|
|
|
|
*s2 = c;
|
|
|
|
s = s2 + 1;
|
|
|
|
i++;
|
|
|
|
}
|
|
|
|
c = *(p + l);
|
|
|
|
*(p + l) = '\0';
|
|
|
|
*((*output)+i) = _strupr(strdup(s));
|
|
|
|
*(p + l) = c;
|
|
|
|
*((*output)+i+1) = NULL;
|
|
|
|
*(p + 6) = '\0';
|
|
|
|
}
|
2000-11-05 04:51:34 +00:00
|
|
|
}
|
|
|
|
p++;
|
|
|
|
if (!strcmp( p, "all" )) p = ""; /* empty string means all */
|
|
|
|
wine_dbg_add_option( p, set, clear );
|
|
|
|
opt = strtok( NULL, "," );
|
|
|
|
} while(opt);
|
|
|
|
|
|
|
|
free( options );
|
|
|
|
return;
|
|
|
|
|
|
|
|
error:
|
|
|
|
MESSAGE("wine: Syntax: --debugmsg [class]+xxx,... or "
|
|
|
|
"-debugmsg [class]-xxx,...\n");
|
|
|
|
MESSAGE("Example: --debugmsg +all,warn-heap\n"
|
|
|
|
" turn on all messages except warning heap messages\n");
|
|
|
|
MESSAGE("Available message classes:\n");
|
2002-01-21 23:39:36 +00:00
|
|
|
for( i = 0; i < __WINE_DBCL_COUNT; i++) MESSAGE( "%-9s", debug_class_names[i] );
|
2000-11-05 04:51:34 +00:00
|
|
|
MESSAGE("\n\n");
|
|
|
|
ExitProcess(1);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2000-05-30 17:51:44 +00:00
|
|
|
static void remove_options( char *argv[], int pos, int count, int inherit )
|
2000-03-18 21:56:10 +00:00
|
|
|
{
|
2000-05-30 17:51:44 +00:00
|
|
|
if (inherit)
|
|
|
|
{
|
|
|
|
int i, len = 0;
|
|
|
|
for (i = 0; i < count; i++) len += strlen(argv[pos+i]) + 1;
|
|
|
|
if (inherit_str)
|
|
|
|
{
|
2000-06-07 02:03:54 +00:00
|
|
|
if (!(inherit_str = realloc( inherit_str, strlen(inherit_str) + 1 + len )))
|
2000-05-30 17:51:44 +00:00
|
|
|
out_of_memory();
|
|
|
|
strcat( inherit_str, " " );
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if (!(inherit_str = malloc( len ))) out_of_memory();
|
|
|
|
inherit_str[0] = 0;
|
|
|
|
}
|
|
|
|
for (i = 0; i < count; i++)
|
|
|
|
{
|
|
|
|
strcat( inherit_str, argv[pos+i] );
|
|
|
|
if (i < count-1) strcat( inherit_str, " " );
|
|
|
|
}
|
|
|
|
}
|
2000-03-18 21:56:10 +00:00
|
|
|
while ((argv[pos] = argv[pos+count])) pos++;
|
|
|
|
}
|
|
|
|
|
2000-05-30 17:51:44 +00:00
|
|
|
/* parse options from the argv array and remove all the recognized ones */
|
|
|
|
static void parse_options( char *argv[] )
|
2000-03-18 21:56:10 +00:00
|
|
|
{
|
2001-01-10 23:56:59 +00:00
|
|
|
const struct option_descr *opt;
|
2000-03-18 21:56:10 +00:00
|
|
|
int i;
|
|
|
|
|
2000-05-30 17:51:44 +00:00
|
|
|
for (i = 0; argv[i]; i++)
|
2000-03-18 21:56:10 +00:00
|
|
|
{
|
2000-12-18 03:49:49 +00:00
|
|
|
const char *equalarg = NULL;
|
2000-03-18 21:56:10 +00:00
|
|
|
char *p = argv[i];
|
|
|
|
if (*p++ != '-') continue; /* not an option */
|
|
|
|
if (*p && !p[1]) /* short name */
|
|
|
|
{
|
|
|
|
if (*p == '-') break; /* "--" option */
|
|
|
|
for (opt = option_table; opt->longname; opt++) if (opt->shortname == *p) break;
|
|
|
|
}
|
|
|
|
else /* long name */
|
|
|
|
{
|
2000-12-18 03:49:49 +00:00
|
|
|
const char *equal = strchr (p, '=');
|
2000-03-18 21:56:10 +00:00
|
|
|
if (*p == '-') p++;
|
|
|
|
/* check for the long name */
|
2000-12-18 03:49:49 +00:00
|
|
|
for (opt = option_table; opt->longname; opt++) {
|
|
|
|
/* Plain --option */
|
2000-03-18 21:56:10 +00:00
|
|
|
if (!strcmp( p, opt->longname )) break;
|
2000-12-18 03:49:49 +00:00
|
|
|
|
|
|
|
/* --option=value */
|
|
|
|
if (opt->has_arg &&
|
|
|
|
equal &&
|
|
|
|
strlen (opt->longname) == equal - p &&
|
|
|
|
!strncmp (p, opt->longname, equal - p)) {
|
|
|
|
equalarg = equal + 1;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2000-03-18 21:56:10 +00:00
|
|
|
}
|
|
|
|
if (!opt->longname) continue;
|
|
|
|
|
2000-12-18 03:49:49 +00:00
|
|
|
if (equalarg)
|
|
|
|
{
|
|
|
|
opt->func( equalarg );
|
|
|
|
remove_options( argv, i, 1, opt->inherit );
|
|
|
|
}
|
|
|
|
else if (opt->has_arg && argv[i+1])
|
2000-03-18 21:56:10 +00:00
|
|
|
{
|
|
|
|
opt->func( argv[i+1] );
|
2000-05-30 17:51:44 +00:00
|
|
|
remove_options( argv, i, 2, opt->inherit );
|
2000-03-18 21:56:10 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
opt->func( "" );
|
2000-05-30 17:51:44 +00:00
|
|
|
remove_options( argv, i, 1, opt->inherit );
|
2000-03-18 21:56:10 +00:00
|
|
|
}
|
|
|
|
i--;
|
|
|
|
}
|
2000-05-30 17:51:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* inherit options from WINEOPTIONS variable */
|
|
|
|
static void inherit_options( char *buffer )
|
|
|
|
{
|
|
|
|
char *argv[256];
|
2000-11-01 03:11:12 +00:00
|
|
|
unsigned int n;
|
2000-05-30 17:51:44 +00:00
|
|
|
|
|
|
|
char *p = strtok( buffer, " \t" );
|
2000-11-01 03:11:12 +00:00
|
|
|
for (n = 0; n < sizeof(argv)/sizeof(argv[0])-1 && p; n++)
|
2000-05-30 17:51:44 +00:00
|
|
|
{
|
2000-11-01 03:11:12 +00:00
|
|
|
argv[n] = p;
|
2000-05-30 17:51:44 +00:00
|
|
|
p = strtok( NULL, " \t" );
|
|
|
|
}
|
2000-11-01 03:11:12 +00:00
|
|
|
argv[n] = NULL;
|
2000-05-30 17:51:44 +00:00
|
|
|
parse_options( argv );
|
|
|
|
if (argv[0]) /* an option remains */
|
|
|
|
{
|
|
|
|
MESSAGE( "Unknown option '%s' in WINEOPTIONS variable\n\n", argv[0] );
|
|
|
|
OPTIONS_Usage();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/***********************************************************************
|
|
|
|
* OPTIONS_Usage
|
|
|
|
*/
|
|
|
|
void OPTIONS_Usage(void)
|
|
|
|
{
|
2001-01-10 23:56:59 +00:00
|
|
|
const struct option_descr *opt;
|
2001-03-23 23:45:45 +00:00
|
|
|
MESSAGE( "%s\n\n", WINE_RELEASE_INFO );
|
2000-12-15 21:28:47 +00:00
|
|
|
MESSAGE( "Usage: %s [options] [--] program_name [arguments]\n", argv0 );
|
|
|
|
MESSAGE("The -- has to be used if you specify arguments (of the program)\n\n");
|
2000-05-30 17:51:44 +00:00
|
|
|
MESSAGE( "Options:\n" );
|
|
|
|
for (opt = option_table; opt->longname; opt++) MESSAGE( " %s\n", opt->usage );
|
|
|
|
ExitProcess(0);
|
|
|
|
}
|
|
|
|
|
|
|
|
/***********************************************************************
|
|
|
|
* OPTIONS_ParseOptions
|
|
|
|
*/
|
|
|
|
void OPTIONS_ParseOptions( char *argv[] )
|
|
|
|
{
|
|
|
|
char buffer[1024];
|
|
|
|
int i;
|
|
|
|
|
|
|
|
if (GetEnvironmentVariableA( "WINEOPTIONS", buffer, sizeof(buffer) ) && buffer[0])
|
|
|
|
inherit_options( buffer );
|
|
|
|
|
|
|
|
parse_options( argv + 1 );
|
|
|
|
|
|
|
|
SetEnvironmentVariableA( "WINEOPTIONS", inherit_str );
|
2000-03-18 21:56:10 +00:00
|
|
|
|
|
|
|
/* check if any option remains */
|
|
|
|
for (i = 1; argv[i]; i++)
|
|
|
|
{
|
|
|
|
if (!strcmp( argv[i], "--" ))
|
|
|
|
{
|
2000-05-30 17:51:44 +00:00
|
|
|
remove_options( argv, i, 1, 0 );
|
2000-03-18 21:56:10 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
if (argv[i][0] == '-')
|
|
|
|
{
|
2000-05-30 17:51:44 +00:00
|
|
|
MESSAGE( "Unknown option '%s'\n\n", argv[i] );
|
2000-03-18 21:56:10 +00:00
|
|
|
OPTIONS_Usage();
|
|
|
|
}
|
|
|
|
}
|
2000-12-15 03:38:11 +00:00
|
|
|
}
|