4 * Copyright 2000 Alexandre Julliard
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
28 #include "wine/library.h"
29 #include "wine/version.h"
32 #include "wine/debug.h"
40 void (*func)( const char *arg );
45 struct options Options =
47 FALSE /* Managed windows */
50 const char *argv0; /* the original argv[0] */
51 const char *full_argv0; /* the full path of argv[0] (if known) */
53 static char *inherit_str; /* options to pass to child processes */
55 static void out_of_memory(void) WINE_NORETURN;
56 static void out_of_memory(void)
58 MESSAGE( "Virtual memory exhausted\n" );
62 static void do_debugmsg( const char *arg );
63 static void do_help( const char *arg );
64 static void do_managed( const char *arg );
65 static void do_version( const char *arg );
67 static const struct option_descr option_table[] =
69 { "debugmsg", 0, 1, 1, do_debugmsg,
70 "--debugmsg name Turn debugging-messages on or off" },
71 { "dll", 0, 1, 1, MODULE_AddLoadOrderOption,
72 "--dll name Enable or disable built-in DLLs" },
73 { "dosver", 0, 1, 1, VERSION_ParseDosVersion,
74 "--dosver x.xx DOS version to imitate (e.g. 6.22)\n"
75 " Only valid with --winver win31" },
76 { "help", 'h', 0, 0, do_help,
77 "--help,-h Show this help message" },
78 { "managed", 0, 0, 0, do_managed,
79 "--managed Allow the window manager to manage created windows" },
80 { "version", 'v', 0, 0, do_version,
81 "--version,-v Display the Wine version" },
82 { "winver", 0, 1, 1, VERSION_ParseWinVersion,
83 "--winver Version to imitate (win95,win98,winme,nt351,nt40,win2k,winxp,win20,win30,win31)" },
84 { NULL, 0, 0, 0, NULL, NULL } /* terminator */
88 static void do_help( const char *arg )
93 static void do_version( const char *arg )
95 MESSAGE( "%s\n", WINE_RELEASE_INFO );
99 static void do_managed( const char *arg )
101 Options.managed = TRUE;
104 static void do_debugmsg( const char *arg )
106 static const char * const debug_class_names[__WINE_DBCL_COUNT] = { "fixme", "err", "warn", "trace" };
108 char *opt, *options = strdup(arg);
110 /* defined in relay32/relay386.c */
111 extern char **debug_relay_includelist;
112 extern char **debug_relay_excludelist;
113 /* defined in relay32/snoop.c */
114 extern char **debug_snoop_includelist;
115 extern char **debug_snoop_excludelist;
117 if (!(opt = strtok( options, "," ))) goto error;
120 unsigned char set = 0, clear = 0;
121 char *p = strchr( opt, '+' );
122 if (!p) p = strchr( opt, '-' );
123 if (!p || !p[1]) goto error;
126 for (i = 0; i < __WINE_DBCL_COUNT; i++)
128 int len = strlen(debug_class_names[i]);
129 if (len != (p - opt)) continue;
130 if (!memcmp( opt, debug_class_names[i], len )) /* found it */
132 if (*p == '+') set |= 1 << i;
133 else clear |= 1 << i;
137 if (i == __WINE_DBCL_COUNT) goto error; /* class name not found */
141 if (*p == '+') set = ~0;
143 if (!strncasecmp(p+1, "relay=", 6) ||
144 !strncasecmp(p+1, "snoop=", 6))
147 char *s, *s2, ***output, c;
155 output = (*p == '+') ?
157 &debug_relay_includelist :
158 &debug_snoop_includelist) :
160 &debug_relay_excludelist :
161 &debug_snoop_excludelist);
163 /* if there are n ':', there are n+1 modules, and we need
164 n+2 slots, last one being for the sentinel (NULL) */
166 while((s = strchr(s, ':'))) i++, s++;
167 *output = malloc(sizeof(char **) * i);
170 while((s2 = strchr(s, ':'))) {
173 *((*output)+i) = _strupr(strdup(s));
180 *((*output)+i) = _strupr(strdup(s));
182 *((*output)+i+1) = NULL;
187 if (!strcmp( p, "all" )) p = ""; /* empty string means all */
188 wine_dbg_add_option( p, set, clear );
189 opt = strtok( NULL, "," );
196 MESSAGE("wine: Syntax: --debugmsg [class]+xxx,... or "
197 "-debugmsg [class]-xxx,...\n");
198 MESSAGE("Example: --debugmsg +all,warn-heap\n"
199 " turn on all messages except warning heap messages\n");
200 MESSAGE("Available message classes:\n");
201 for( i = 0; i < __WINE_DBCL_COUNT; i++) MESSAGE( "%-9s", debug_class_names[i] );
207 static void remove_options( char *argv[], int pos, int count, int inherit )
212 for (i = 0; i < count; i++) len += strlen(argv[pos+i]) + 1;
215 if (!(inherit_str = realloc( inherit_str, strlen(inherit_str) + 1 + len )))
217 strcat( inherit_str, " " );
221 if (!(inherit_str = malloc( len ))) out_of_memory();
224 for (i = 0; i < count; i++)
226 strcat( inherit_str, argv[pos+i] );
227 if (i < count-1) strcat( inherit_str, " " );
230 while ((argv[pos] = argv[pos+count])) pos++;
233 /* parse options from the argv array and remove all the recognized ones */
234 static void parse_options( char *argv[] )
236 const struct option_descr *opt;
239 for (i = 0; argv[i]; i++)
241 const char *equalarg = NULL;
243 if (*p++ != '-') continue; /* not an option */
244 if (*p && !p[1]) /* short name */
246 if (*p == '-') break; /* "--" option */
247 for (opt = option_table; opt->longname; opt++) if (opt->shortname == *p) break;
251 const char *equal = strchr (p, '=');
253 /* check for the long name */
254 for (opt = option_table; opt->longname; opt++) {
256 if (!strcmp( p, opt->longname )) break;
261 strlen (opt->longname) == equal - p &&
262 !strncmp (p, opt->longname, equal - p)) {
263 equalarg = equal + 1;
268 if (!opt->longname) continue;
272 opt->func( equalarg );
273 remove_options( argv, i, 1, opt->inherit );
275 else if (opt->has_arg && argv[i+1])
277 opt->func( argv[i+1] );
278 remove_options( argv, i, 2, opt->inherit );
283 remove_options( argv, i, 1, opt->inherit );
289 /* inherit options from WINEOPTIONS variable */
290 static void inherit_options( char *buffer )
295 char *p = strtok( buffer, " \t" );
296 for (n = 0; n < sizeof(argv)/sizeof(argv[0])-1 && p; n++)
299 p = strtok( NULL, " \t" );
302 parse_options( argv );
303 if (argv[0]) /* an option remains */
305 MESSAGE( "Unknown option '%s' in WINEOPTIONS variable\n\n", argv[0] );
310 /***********************************************************************
313 void OPTIONS_Usage(void)
315 const struct option_descr *opt;
316 MESSAGE( "%s\n\n", WINE_RELEASE_INFO );
317 MESSAGE( "Usage: %s [options] [--] program_name [arguments]\n", argv0 );
318 MESSAGE("The -- has to be used if you specify arguments (of the program)\n\n");
319 MESSAGE( "Options:\n" );
320 for (opt = option_table; opt->longname; opt++) MESSAGE( " %s\n", opt->usage );
324 /***********************************************************************
325 * OPTIONS_ParseOptions
327 void OPTIONS_ParseOptions( char *argv[] )
332 if (GetEnvironmentVariableA( "WINEOPTIONS", buffer, sizeof(buffer) ) && buffer[0])
333 inherit_options( buffer );
335 parse_options( argv + 1 );
337 SetEnvironmentVariableA( "WINEOPTIONS", inherit_str );
339 /* check if any option remains */
340 for (i = 1; argv[i]; i++)
342 if (!strcmp( argv[i], "--" ))
344 remove_options( argv, i, 1, 0 );
347 if (argv[i][0] == '-')
349 MESSAGE( "Unknown option '%s'\n\n", argv[i] );