2000-03-18 22:56:10 +01:00
|
|
|
/*
|
|
|
|
* Option parsing
|
|
|
|
*
|
|
|
|
* Copyright 2000 Alexandre Julliard
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "config.h"
|
|
|
|
#include <string.h>
|
2000-05-30 19:51:44 +02:00
|
|
|
#include <stdlib.h>
|
2000-03-18 22:56:10 +01:00
|
|
|
|
|
|
|
#include "winbase.h"
|
|
|
|
#include "main.h"
|
|
|
|
#include "options.h"
|
|
|
|
#include "version.h"
|
|
|
|
#include "debugtools.h"
|
|
|
|
|
|
|
|
struct option
|
|
|
|
{
|
|
|
|
const char *longname;
|
|
|
|
char shortname;
|
|
|
|
int has_arg;
|
2000-05-30 19:51:44 +02:00
|
|
|
int inherit;
|
2000-03-18 22:56:10 +01:00
|
|
|
void (*func)( const char *arg );
|
|
|
|
const char *usage;
|
|
|
|
};
|
|
|
|
|
2000-04-15 23:00:55 +02:00
|
|
|
/* Most Windows C/C++ compilers use something like this to */
|
|
|
|
/* access argc and argv globally: */
|
|
|
|
int _ARGC;
|
|
|
|
char **_ARGV;
|
|
|
|
|
2000-05-29 23:25:10 +02:00
|
|
|
/* default options */
|
|
|
|
struct options Options =
|
|
|
|
{
|
|
|
|
NULL, /* desktopGeometry */
|
|
|
|
NULL, /* display */
|
|
|
|
NULL, /* dllFlags */
|
|
|
|
FALSE, /* synchronous */
|
|
|
|
FALSE, /* Managed windows */
|
|
|
|
NULL /* Alternate config file name */
|
|
|
|
};
|
|
|
|
|
|
|
|
const char *argv0;
|
|
|
|
|
2000-05-30 19:51:44 +02: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);
|
|
|
|
}
|
|
|
|
|
|
|
|
static char *xstrdup( const char *str )
|
|
|
|
{
|
|
|
|
char *ret = strdup( str );
|
|
|
|
if (!ret) out_of_memory();
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2000-03-18 22:56:10 +01:00
|
|
|
static void do_config( const char *arg );
|
|
|
|
static void do_desktop( const char *arg );
|
|
|
|
static void do_display( const char *arg );
|
|
|
|
static void do_dll( const char *arg );
|
|
|
|
static void do_help( const char *arg );
|
2000-07-15 21:59:10 +02:00
|
|
|
static void do_language( const char *arg );
|
2000-03-18 22:56:10 +01:00
|
|
|
static void do_managed( const char *arg );
|
|
|
|
static void do_synchronous( const char *arg );
|
|
|
|
static void do_version( const char *arg );
|
|
|
|
|
|
|
|
static const struct option option_table[] =
|
|
|
|
{
|
2000-05-30 19:51:44 +02:00
|
|
|
{ "config", 0, 1, 0, do_config,
|
2000-03-18 22:56:10 +01:00
|
|
|
"--config name Specify config file to use" },
|
2000-05-30 19:51:44 +02:00
|
|
|
{ "debugmsg", 0, 1, 1, MAIN_ParseDebugOptions,
|
2000-03-18 22:56:10 +01:00
|
|
|
"--debugmsg name Turn debugging-messages on or off" },
|
2000-05-30 19:51:44 +02:00
|
|
|
{ "desktop", 0, 1, 1, do_desktop,
|
2000-03-18 22:56:10 +01:00
|
|
|
"--desktop geom Use a desktop window of the given geometry" },
|
2000-05-30 19:51:44 +02:00
|
|
|
{ "display", 0, 1, 0, do_display,
|
2000-03-18 22:56:10 +01:00
|
|
|
"--display name Use the specified display" },
|
2000-05-30 19:51:44 +02:00
|
|
|
{ "dll", 0, 1, 1, do_dll,
|
2000-03-18 22:56:10 +01:00
|
|
|
"--dll name Enable or disable built-in DLLs" },
|
2000-05-30 19:51:44 +02:00
|
|
|
{ "dosver", 0, 1, 1, VERSION_ParseDosVersion,
|
2000-03-18 22:56:10 +01:00
|
|
|
"--dosver x.xx DOS version to imitate (e.g. 6.22). Only valid with --winver win31" },
|
2000-05-30 19:51:44 +02:00
|
|
|
{ "help", 'h', 0, 0, do_help,
|
2000-03-18 22:56:10 +01:00
|
|
|
"--help,-h Show this help message" },
|
2000-07-15 21:59:10 +02:00
|
|
|
{ "language", 0, 1, 1, do_language,
|
2000-05-30 19:51:44 +02:00
|
|
|
"--language xx Set the language (one of Br,Ca,Cs,Cy,Da,De,En,Eo,Es,Fi,Fr,Ga,Gd,Gv,\n"
|
|
|
|
" Hr,Hu,It,Ja,Ko,Kw,Nl,No,Pl,Pt,Sk,Sv,Ru,Wa)" },
|
|
|
|
{ "managed", 0, 0, 0, do_managed,
|
2000-03-18 22:56:10 +01:00
|
|
|
"--managed Allow the window manager to manage created windows" },
|
2000-05-30 19:51:44 +02:00
|
|
|
{ "synchronous", 0, 0, 1, do_synchronous,
|
2000-03-18 22:56:10 +01:00
|
|
|
"--synchronous Turn on synchronous display mode" },
|
2000-05-30 19:51:44 +02:00
|
|
|
{ "version", 'v', 0, 0, do_version,
|
2000-03-18 22:56:10 +01:00
|
|
|
"--version,-v Display the Wine version" },
|
2000-05-30 19:51:44 +02:00
|
|
|
{ "winver", 0, 1, 1, VERSION_ParseWinVersion,
|
2000-03-18 22:56:10 +01:00
|
|
|
"--winver Version to imitate (one of win31,win95,nt351,nt40)" },
|
|
|
|
{ NULL, } /* terminator */
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
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_synchronous( const char *arg )
|
|
|
|
{
|
|
|
|
Options.synchronous = TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void do_desktop( const char *arg )
|
|
|
|
{
|
2000-05-30 19:51:44 +02:00
|
|
|
Options.desktopGeometry = xstrdup( arg );
|
2000-03-18 22:56:10 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
static void do_display( const char *arg )
|
|
|
|
{
|
2000-05-30 19:51:44 +02:00
|
|
|
Options.display = xstrdup( arg );
|
2000-03-18 22:56:10 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
static void do_dll( const char *arg )
|
|
|
|
{
|
|
|
|
if (Options.dllFlags)
|
|
|
|
{
|
|
|
|
/* don't overwrite previous value. Should we
|
|
|
|
* automatically add the ',' between multiple DLLs ?
|
|
|
|
*/
|
|
|
|
MESSAGE("Only one -dll flag is allowed. Use ',' between multiple DLLs\n");
|
|
|
|
ExitProcess(1);
|
|
|
|
}
|
2000-05-30 19:51:44 +02:00
|
|
|
Options.dllFlags = xstrdup( arg );
|
2000-03-18 22:56:10 +01:00
|
|
|
}
|
|
|
|
|
2000-07-15 21:59:10 +02:00
|
|
|
static void do_language( const char *arg )
|
|
|
|
{
|
|
|
|
SetEnvironmentVariableA( "LANGUAGE", arg );
|
|
|
|
}
|
|
|
|
|
2000-03-18 22:56:10 +01:00
|
|
|
static void do_managed( const char *arg )
|
|
|
|
{
|
|
|
|
Options.managed = TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void do_config( const char *arg )
|
|
|
|
{
|
2000-05-30 19:51:44 +02:00
|
|
|
Options.configFileName = xstrdup( arg );
|
2000-03-18 22:56:10 +01:00
|
|
|
}
|
|
|
|
|
2000-05-30 19:51:44 +02:00
|
|
|
static void remove_options( char *argv[], int pos, int count, int inherit )
|
2000-03-18 22:56:10 +01:00
|
|
|
{
|
2000-05-30 19:51:44 +02: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 04:03:54 +02:00
|
|
|
if (!(inherit_str = realloc( inherit_str, strlen(inherit_str) + 1 + len )))
|
2000-05-30 19:51:44 +02: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 22:56:10 +01:00
|
|
|
while ((argv[pos] = argv[pos+count])) pos++;
|
|
|
|
}
|
|
|
|
|
2000-05-30 19:51:44 +02:00
|
|
|
/* parse options from the argv array and remove all the recognized ones */
|
|
|
|
static void parse_options( char *argv[] )
|
2000-03-18 22:56:10 +01:00
|
|
|
{
|
|
|
|
const struct option *opt;
|
|
|
|
int i;
|
|
|
|
|
2000-05-30 19:51:44 +02:00
|
|
|
for (i = 0; argv[i]; i++)
|
2000-03-18 22:56:10 +01: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 */
|
|
|
|
{
|
|
|
|
if (*p == '-') p++;
|
|
|
|
/* check for the long name */
|
|
|
|
for (opt = option_table; opt->longname; opt++)
|
|
|
|
if (!strcmp( p, opt->longname )) break;
|
|
|
|
}
|
|
|
|
if (!opt->longname) continue;
|
|
|
|
|
|
|
|
if (opt->has_arg && argv[i+1])
|
|
|
|
{
|
|
|
|
opt->func( argv[i+1] );
|
2000-05-30 19:51:44 +02:00
|
|
|
remove_options( argv, i, 2, opt->inherit );
|
2000-03-18 22:56:10 +01:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
opt->func( "" );
|
2000-05-30 19:51:44 +02:00
|
|
|
remove_options( argv, i, 1, opt->inherit );
|
2000-03-18 22:56:10 +01:00
|
|
|
}
|
|
|
|
i--;
|
|
|
|
}
|
2000-05-30 19:51:44 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/* inherit options from WINEOPTIONS variable */
|
|
|
|
static void inherit_options( char *buffer )
|
|
|
|
{
|
|
|
|
char *argv[256];
|
|
|
|
int i;
|
|
|
|
|
|
|
|
char *p = strtok( buffer, " \t" );
|
|
|
|
for (i = 0; i < sizeof(argv)/sizeof(argv[0])-1 && p; i++)
|
|
|
|
{
|
|
|
|
argv[i] = p;
|
|
|
|
p = strtok( NULL, " \t" );
|
|
|
|
}
|
|
|
|
argv[i] = NULL;
|
|
|
|
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)
|
|
|
|
{
|
|
|
|
const struct option *opt;
|
|
|
|
MESSAGE( "Usage: %s [options] program_name [arguments]\n\n", argv0 );
|
|
|
|
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 22:56:10 +01:00
|
|
|
|
|
|
|
/* check if any option remains */
|
|
|
|
for (i = 1; argv[i]; i++)
|
|
|
|
{
|
|
|
|
if (!strcmp( argv[i], "--" ))
|
|
|
|
{
|
2000-05-30 19:51:44 +02:00
|
|
|
remove_options( argv, i, 1, 0 );
|
2000-03-18 22:56:10 +01:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
if (argv[i][0] == '-')
|
|
|
|
{
|
2000-05-30 19:51:44 +02:00
|
|
|
MESSAGE( "Unknown option '%s'\n\n", argv[i] );
|
2000-03-18 22:56:10 +01:00
|
|
|
OPTIONS_Usage();
|
|
|
|
}
|
|
|
|
}
|
2000-05-29 23:25:10 +02:00
|
|
|
|
|
|
|
/* count the resulting arguments */
|
2000-04-15 23:00:55 +02:00
|
|
|
_ARGV = argv;
|
2000-05-29 23:25:10 +02:00
|
|
|
_ARGC = 0;
|
|
|
|
while (argv[_ARGC]) _ARGC++;
|
2000-03-18 22:56:10 +01:00
|
|
|
}
|