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"
31 #include "wine/debug.h"
39 void (*func
)( const char *arg
);
44 struct options Options
=
46 FALSE
/* Managed windows */
49 const char *argv0
; /* the original argv[0] */
50 const char *full_argv0
; /* the full path of argv[0] (if known) */
52 static char *inherit_str
; /* options to pass to child processes */
54 static void out_of_memory(void) WINE_NORETURN
;
55 static void out_of_memory(void)
57 MESSAGE( "Virtual memory exhausted\n" );
61 static void do_debugmsg( const char *arg
);
62 static void do_help( const char *arg
);
63 static void do_managed( const char *arg
);
64 static void do_version( const char *arg
);
66 static const struct option_descr option_table
[] =
68 { "debugmsg", 0, 1, 1, do_debugmsg
,
69 "--debugmsg name Turn debugging-messages on or off" },
70 { "dll", 0, 1, 1, MODULE_AddLoadOrderOption
,
71 "--dll name Enable or disable built-in DLLs" },
72 { "dosver", 0, 1, 1, VERSION_ParseDosVersion
,
73 "--dosver x.xx DOS version to imitate (e.g. 6.22)\n"
74 " Only valid with --winver win31" },
75 { "help", 'h', 0, 0, do_help
,
76 "--help,-h Show this help message" },
77 { "managed", 0, 0, 0, do_managed
,
78 "--managed Allow the window manager to manage created windows" },
79 { "version", 'v', 0, 0, do_version
,
80 "--version,-v Display the Wine version" },
81 { "winver", 0, 1, 1, VERSION_ParseWinVersion
,
82 "--winver Version to imitate (win95,win98,winme,nt351,nt40,win2k,winxp,win20,win30,win31)" },
83 { NULL
, 0, 0, 0, NULL
, NULL
} /* terminator */
87 static void do_help( const char *arg
)
92 static void do_version( const char *arg
)
94 MESSAGE( "%s\n", PACKAGE_STRING
);
98 static void do_managed( const char *arg
)
100 Options
.managed
= TRUE
;
103 static void do_debugmsg( const char *arg
)
105 static const char * const debug_class_names
[__WINE_DBCL_COUNT
] = { "fixme", "err", "warn", "trace" };
107 char *opt
, *options
= strdup(arg
);
109 /* defined in relay32/relay386.c */
110 extern char **debug_relay_includelist
;
111 extern char **debug_relay_excludelist
;
112 /* defined in relay32/snoop.c */
113 extern char **debug_snoop_includelist
;
114 extern char **debug_snoop_excludelist
;
116 if (!(opt
= strtok( options
, "," ))) goto error
;
119 unsigned char set
= 0, clear
= 0;
120 char *p
= strchr( opt
, '+' );
121 if (!p
) p
= strchr( opt
, '-' );
122 if (!p
|| !p
[1]) goto error
;
125 for (i
= 0; i
< __WINE_DBCL_COUNT
; i
++)
127 int len
= strlen(debug_class_names
[i
]);
128 if (len
!= (p
- opt
)) continue;
129 if (!memcmp( opt
, debug_class_names
[i
], len
)) /* found it */
131 if (*p
== '+') set
|= 1 << i
;
132 else clear
|= 1 << i
;
136 if (i
== __WINE_DBCL_COUNT
) goto error
; /* class name not found */
140 if (*p
== '+') set
= ~0;
142 if (!strncasecmp(p
+1, "relay=", 6) ||
143 !strncasecmp(p
+1, "snoop=", 6))
146 char *s
, *s2
, ***output
, c
;
154 output
= (*p
== '+') ?
156 &debug_relay_includelist
:
157 &debug_snoop_includelist
) :
159 &debug_relay_excludelist
:
160 &debug_snoop_excludelist
);
162 /* if there are n ':', there are n+1 modules, and we need
163 n+2 slots, last one being for the sentinel (NULL) */
165 while((s
= strchr(s
, ':'))) i
++, s
++;
166 *output
= malloc(sizeof(char **) * i
);
169 while((s2
= strchr(s
, ':'))) {
172 *((*output
)+i
) = _strupr(strdup(s
));
179 *((*output
)+i
) = _strupr(strdup(s
));
181 *((*output
)+i
+1) = NULL
;
186 if (!strcmp( p
, "all" )) p
= ""; /* empty string means all */
187 wine_dbg_add_option( p
, set
, clear
);
188 opt
= strtok( NULL
, "," );
195 MESSAGE("wine: Syntax: --debugmsg [class]+xxx,... or "
196 "-debugmsg [class]-xxx,...\n");
197 MESSAGE("Example: --debugmsg +all,warn-heap\n"
198 " turn on all messages except warning heap messages\n");
199 MESSAGE("Available message classes:\n");
200 for( i
= 0; i
< __WINE_DBCL_COUNT
; i
++) MESSAGE( "%-9s", debug_class_names
[i
] );
206 static void remove_options( char *argv
[], int pos
, int count
, int inherit
)
211 for (i
= 0; i
< count
; i
++) len
+= strlen(argv
[pos
+i
]) + 1;
214 if (!(inherit_str
= realloc( inherit_str
, strlen(inherit_str
) + 1 + len
)))
216 strcat( inherit_str
, " " );
220 if (!(inherit_str
= malloc( len
))) out_of_memory();
223 for (i
= 0; i
< count
; i
++)
225 strcat( inherit_str
, argv
[pos
+i
] );
226 if (i
< count
-1) strcat( inherit_str
, " " );
229 while ((argv
[pos
] = argv
[pos
+count
])) pos
++;
232 /* parse options from the argv array and remove all the recognized ones */
233 static void parse_options( char *argv
[] )
235 const struct option_descr
*opt
;
238 for (i
= 0; argv
[i
]; i
++)
240 const char *equalarg
= NULL
;
242 if (*p
++ != '-') continue; /* not an option */
243 if (*p
&& !p
[1]) /* short name */
245 if (*p
== '-') break; /* "--" option */
246 for (opt
= option_table
; opt
->longname
; opt
++) if (opt
->shortname
== *p
) break;
250 const char *equal
= strchr (p
, '=');
252 /* check for the long name */
253 for (opt
= option_table
; opt
->longname
; opt
++) {
255 if (!strcmp( p
, opt
->longname
)) break;
260 strlen (opt
->longname
) == equal
- p
&&
261 !strncmp (p
, opt
->longname
, equal
- p
)) {
262 equalarg
= equal
+ 1;
267 if (!opt
->longname
) continue;
271 opt
->func( equalarg
);
272 remove_options( argv
, i
, 1, opt
->inherit
);
274 else if (opt
->has_arg
&& argv
[i
+1])
276 opt
->func( argv
[i
+1] );
277 remove_options( argv
, i
, 2, opt
->inherit
);
282 remove_options( argv
, i
, 1, opt
->inherit
);
288 /* inherit options from WINEOPTIONS variable */
289 static void inherit_options( char *buffer
)
294 char *p
= strtok( buffer
, " \t" );
295 for (n
= 0; n
< sizeof(argv
)/sizeof(argv
[0])-1 && p
; n
++)
298 p
= strtok( NULL
, " \t" );
301 parse_options( argv
);
302 if (argv
[0]) /* an option remains */
304 MESSAGE( "Unknown option '%s' in WINEOPTIONS variable\n\n", argv
[0] );
309 /***********************************************************************
312 void OPTIONS_Usage(void)
314 const struct option_descr
*opt
;
315 MESSAGE( "%s\n\n", PACKAGE_STRING
);
316 MESSAGE( "Usage: %s [options] [--] program_name [arguments]\n", argv0
);
317 MESSAGE("The -- has to be used if you specify arguments (of the program)\n\n");
318 MESSAGE( "Options:\n" );
319 for (opt
= option_table
; opt
->longname
; opt
++) MESSAGE( " %s\n", opt
->usage
);
323 /***********************************************************************
324 * OPTIONS_ParseOptions
326 void OPTIONS_ParseOptions( char *argv
[] )
331 if (GetEnvironmentVariableA( "WINEOPTIONS", buffer
, sizeof(buffer
) ) && buffer
[0])
332 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
] );