2000-03-18 22:56:10 +01:00
|
|
|
/*
|
|
|
|
* Option parsing
|
|
|
|
*
|
|
|
|
* Copyright 2000 Alexandre Julliard
|
2002-03-10 00:29:33 +01:00
|
|
|
*
|
|
|
|
* 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
|
|
|
|
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
2000-03-18 22:56:10 +01:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include "config.h"
|
2003-09-06 01:08:26 +02:00
|
|
|
#include <stdarg.h>
|
2000-03-18 22:56:10 +01:00
|
|
|
#include <string.h>
|
2000-05-30 19:51:44 +02:00
|
|
|
#include <stdlib.h>
|
2000-03-18 22:56:10 +01:00
|
|
|
|
2003-09-06 01:08:26 +02:00
|
|
|
#include "windef.h"
|
2000-03-18 22:56:10 +01:00
|
|
|
#include "winbase.h"
|
2000-12-15 04:38:11 +01:00
|
|
|
#include "winnls.h"
|
2003-09-06 01:08:26 +02:00
|
|
|
#include "winreg.h"
|
2002-09-13 00:07:02 +02:00
|
|
|
#include "winternl.h"
|
2000-11-08 05:28:54 +01:00
|
|
|
#include "wine/library.h"
|
2000-03-18 22:56:10 +01:00
|
|
|
#include "options.h"
|
2002-03-10 00:29:33 +01:00
|
|
|
#include "wine/debug.h"
|
2000-03-18 22:56:10 +01:00
|
|
|
|
2001-01-11 00:56:59 +01:00
|
|
|
struct option_descr
|
2000-03-18 22:56:10 +01:00
|
|
|
{
|
|
|
|
const char *longname;
|
|
|
|
char shortname;
|
|
|
|
int has_arg;
|
|
|
|
void (*func)( const char *arg );
|
|
|
|
const char *usage;
|
|
|
|
};
|
|
|
|
|
2000-11-05 05:51:34 +01:00
|
|
|
static void do_debugmsg( const char *arg );
|
2000-03-18 22:56:10 +01:00
|
|
|
static void do_help( const char *arg );
|
|
|
|
static void do_version( const char *arg );
|
|
|
|
|
2001-01-11 00:56:59 +01:00
|
|
|
static const struct option_descr option_table[] =
|
2000-03-18 22:56:10 +01:00
|
|
|
{
|
2004-03-12 00:22:29 +01:00
|
|
|
{ "debugmsg", 0, 1, do_debugmsg,
|
2000-03-18 22:56:10 +01:00
|
|
|
"--debugmsg name Turn debugging-messages on or off" },
|
2004-03-12 00:22:29 +01:00
|
|
|
{ "help", 'h', 0, do_help,
|
2000-03-18 22:56:10 +01:00
|
|
|
"--help,-h Show this help message" },
|
2004-03-12 00:22:29 +01:00
|
|
|
{ "version", 'v', 0, do_version,
|
2000-03-18 22:56:10 +01:00
|
|
|
"--version,-v Display the Wine version" },
|
2004-03-12 00:22:29 +01:00
|
|
|
{ NULL, 0, 0, NULL, NULL } /* terminator */
|
2000-03-18 22:56:10 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
static void do_help( const char *arg )
|
|
|
|
{
|
|
|
|
OPTIONS_Usage();
|
|
|
|
}
|
|
|
|
|
|
|
|
static void do_version( const char *arg )
|
|
|
|
{
|
2002-04-11 23:54:01 +02:00
|
|
|
MESSAGE( "%s\n", PACKAGE_STRING );
|
2000-03-18 22:56:10 +01:00
|
|
|
ExitProcess(0);
|
|
|
|
}
|
|
|
|
|
2000-11-05 05:51:34 +01:00
|
|
|
static void do_debugmsg( const char *arg )
|
|
|
|
{
|
2004-03-12 00:22:29 +01:00
|
|
|
char buffer[1024];
|
|
|
|
|
2002-06-04 19:48:41 +02:00
|
|
|
if (wine_dbg_parse_options( arg ))
|
2000-11-05 05:51:34 +01:00
|
|
|
{
|
2003-10-08 02:45:01 +02:00
|
|
|
MESSAGE("wine: Syntax: --debugmsg [class]+xxx,... or -debugmsg [class]-xxx,...\n");
|
2002-06-04 19:48:41 +02:00
|
|
|
MESSAGE("Example: --debugmsg +all,warn-heap\n"
|
|
|
|
" turn on all messages except warning heap messages\n");
|
|
|
|
MESSAGE("Available message classes: err, warn, fixme, trace\n\n");
|
|
|
|
ExitProcess(1);
|
|
|
|
}
|
2004-03-12 00:22:29 +01:00
|
|
|
MESSAGE("Warning: the --debugmsg option is deprecated. You should use\n");
|
|
|
|
MESSAGE("the WINEDEBUG environment variable instead, like this:\n\n");
|
|
|
|
MESSAGE(" WINEDEBUG=%s wine ...\n\n", arg );
|
2000-11-05 05:51:34 +01:00
|
|
|
|
2004-03-12 00:22:29 +01:00
|
|
|
/* append the argument to WINEDEBUG so that it gets inherited */
|
|
|
|
if (GetEnvironmentVariableA( "WINEDEBUG", buffer, sizeof(buffer)-1 ) && buffer[0])
|
|
|
|
{
|
|
|
|
char *p = buffer + strlen(buffer);
|
|
|
|
*p++ = ',';
|
|
|
|
lstrcpynA( p, arg, buffer + sizeof(buffer) - p );
|
|
|
|
SetEnvironmentVariableA( "WINEDEBUG", buffer );
|
|
|
|
}
|
|
|
|
else SetEnvironmentVariableA( "WINEDEBUG", arg );
|
2003-09-25 22:33:41 +02:00
|
|
|
}
|
2000-11-05 05:51:34 +01:00
|
|
|
|
2004-03-12 00:22:29 +01:00
|
|
|
static inline void remove_options( char *argv[], int pos, int count )
|
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
|
|
|
{
|
2001-01-11 00:56:59 +01:00
|
|
|
const struct option_descr *opt;
|
2000-03-18 22:56:10 +01:00
|
|
|
int i;
|
|
|
|
|
2000-05-30 19:51:44 +02:00
|
|
|
for (i = 0; argv[i]; i++)
|
2000-03-18 22:56:10 +01:00
|
|
|
{
|
2000-12-18 04:49:49 +01:00
|
|
|
const char *equalarg = NULL;
|
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 */
|
|
|
|
{
|
2000-12-18 04:49:49 +01:00
|
|
|
const char *equal = strchr (p, '=');
|
2000-03-18 22:56:10 +01:00
|
|
|
if (*p == '-') p++;
|
|
|
|
/* check for the long name */
|
2000-12-18 04:49:49 +01:00
|
|
|
for (opt = option_table; opt->longname; opt++) {
|
|
|
|
/* Plain --option */
|
2000-03-18 22:56:10 +01:00
|
|
|
if (!strcmp( p, opt->longname )) break;
|
2000-12-18 04:49:49 +01: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 22:56:10 +01:00
|
|
|
}
|
|
|
|
if (!opt->longname) continue;
|
|
|
|
|
2000-12-18 04:49:49 +01:00
|
|
|
if (equalarg)
|
|
|
|
{
|
|
|
|
opt->func( equalarg );
|
2004-03-12 00:22:29 +01:00
|
|
|
remove_options( argv, i, 1 );
|
2000-12-18 04:49:49 +01:00
|
|
|
}
|
|
|
|
else if (opt->has_arg && argv[i+1])
|
2000-03-18 22:56:10 +01:00
|
|
|
{
|
|
|
|
opt->func( argv[i+1] );
|
2004-03-12 00:22:29 +01:00
|
|
|
remove_options( argv, i, 2 );
|
2000-03-18 22:56:10 +01:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
opt->func( "" );
|
2004-03-12 00:22:29 +01:00
|
|
|
remove_options( argv, i, 1 );
|
2000-03-18 22:56:10 +01:00
|
|
|
}
|
|
|
|
i--;
|
|
|
|
}
|
2000-05-30 19:51:44 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/***********************************************************************
|
|
|
|
* OPTIONS_Usage
|
|
|
|
*/
|
|
|
|
void OPTIONS_Usage(void)
|
|
|
|
{
|
2001-01-11 00:56:59 +01:00
|
|
|
const struct option_descr *opt;
|
2002-04-11 23:54:01 +02:00
|
|
|
MESSAGE( "%s\n\n", PACKAGE_STRING );
|
2003-10-08 02:45:01 +02:00
|
|
|
MESSAGE( "Usage: wine [options] [--] program_name [arguments]\n" );
|
2000-12-15 22:28:47 +01:00
|
|
|
MESSAGE("The -- has to be used if you specify arguments (of the program)\n\n");
|
2000-05-30 19:51:44 +02: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[] )
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
|
|
|
|
parse_options( argv + 1 );
|
|
|
|
|
2000-03-18 22:56:10 +01:00
|
|
|
/* check if any option remains */
|
|
|
|
for (i = 1; argv[i]; i++)
|
|
|
|
{
|
|
|
|
if (!strcmp( argv[i], "--" ))
|
|
|
|
{
|
2004-03-12 00:22:29 +01:00
|
|
|
remove_options( argv, i, 1 );
|
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-12-15 04:38:11 +01:00
|
|
|
}
|