4 * Copyright 2000 Alexandre Julliard
14 #include "wine/library.h"
18 #include "debugtools.h"
26 void (*func
)( const char *arg
);
31 struct options Options
=
33 FALSE
/* Managed windows */
36 const char *argv0
; /* the original argv[0] */
37 const char *full_argv0
; /* the full path of argv[0] (if known) */
39 static char *inherit_str
; /* options to pass to child processes */
41 static void out_of_memory(void) WINE_NORETURN
;
42 static void out_of_memory(void)
44 MESSAGE( "Virtual memory exhausted\n" );
48 static void do_debugmsg( const char *arg
);
49 static void do_help( const char *arg
);
50 static void do_managed( const char *arg
);
51 static void do_version( const char *arg
);
53 static const struct option_descr option_table
[] =
55 { "debugmsg", 0, 1, 1, do_debugmsg
,
56 "--debugmsg name Turn debugging-messages on or off" },
57 { "dll", 0, 1, 1, MODULE_AddLoadOrderOption
,
58 "--dll name Enable or disable built-in DLLs" },
59 { "dosver", 0, 1, 1, VERSION_ParseDosVersion
,
60 "--dosver x.xx DOS version to imitate (e.g. 6.22)\n"
61 " Only valid with --winver win31" },
62 { "help", 'h', 0, 0, do_help
,
63 "--help,-h Show this help message" },
64 { "managed", 0, 0, 0, do_managed
,
65 "--managed Allow the window manager to manage created windows" },
66 { "version", 'v', 0, 0, do_version
,
67 "--version,-v Display the Wine version" },
68 { "winver", 0, 1, 1, VERSION_ParseWinVersion
,
69 "--winver Version to imitate (win95,win98,winme,nt351,nt40,win2k,winxp,win20,win30,win31)" },
70 { NULL
, 0, 0, 0, NULL
, NULL
} /* terminator */
74 static void do_help( const char *arg
)
79 static void do_version( const char *arg
)
81 MESSAGE( "%s\n", WINE_RELEASE_INFO
);
85 static void do_managed( const char *arg
)
87 Options
.managed
= TRUE
;
90 static void do_debugmsg( const char *arg
)
92 static const char * const debug_class_names
[__DBCL_COUNT
] = { "fixme", "err", "warn", "trace" };
94 char *opt
, *options
= strdup(arg
);
96 /* defined in relay32/relay386.c */
97 extern char **debug_relay_includelist
;
98 extern char **debug_relay_excludelist
;
99 /* defined in relay32/snoop.c */
100 extern char **debug_snoop_includelist
;
101 extern char **debug_snoop_excludelist
;
103 if (!(opt
= strtok( options
, "," ))) goto error
;
106 unsigned char set
= 0, clear
= 0;
107 char *p
= strchr( opt
, '+' );
108 if (!p
) p
= strchr( opt
, '-' );
109 if (!p
|| !p
[1]) goto error
;
112 for (i
= 0; i
< __DBCL_COUNT
; i
++)
114 int len
= strlen(debug_class_names
[i
]);
115 if (len
!= (p
- opt
)) continue;
116 if (!memcmp( opt
, debug_class_names
[i
], len
)) /* found it */
118 if (*p
== '+') set
|= 1 << i
;
119 else clear
|= 1 << i
;
123 if (i
== __DBCL_COUNT
) goto error
; /* class name not found */
127 if (*p
== '+') set
= ~0;
129 if (!strncasecmp(p
+1, "relay=", 6) ||
130 !strncasecmp(p
+1, "snoop=", 6))
133 char *s
, *s2
, ***output
, c
;
141 output
= (*p
== '+') ?
143 &debug_relay_includelist
:
144 &debug_snoop_includelist
) :
146 &debug_relay_excludelist
:
147 &debug_snoop_excludelist
);
149 /* if there are n ':', there are n+1 modules, and we need
150 n+2 slots, last one being for the sentinel (NULL) */
152 while((s
= strchr(s
, ':'))) i
++, s
++;
153 *output
= malloc(sizeof(char **) * i
);
156 while((s2
= strchr(s
, ':'))) {
159 *((*output
)+i
) = _strupr(strdup(s
));
166 *((*output
)+i
) = _strupr(strdup(s
));
168 *((*output
)+i
+1) = NULL
;
173 if (!strcmp( p
, "all" )) p
= ""; /* empty string means all */
174 wine_dbg_add_option( p
, set
, clear
);
175 opt
= strtok( NULL
, "," );
182 MESSAGE("wine: Syntax: --debugmsg [class]+xxx,... or "
183 "-debugmsg [class]-xxx,...\n");
184 MESSAGE("Example: --debugmsg +all,warn-heap\n"
185 " turn on all messages except warning heap messages\n");
186 MESSAGE("Available message classes:\n");
187 for( i
= 0; i
< __DBCL_COUNT
; i
++) MESSAGE( "%-9s", debug_class_names
[i
] );
193 static void remove_options( char *argv
[], int pos
, int count
, int inherit
)
198 for (i
= 0; i
< count
; i
++) len
+= strlen(argv
[pos
+i
]) + 1;
201 if (!(inherit_str
= realloc( inherit_str
, strlen(inherit_str
) + 1 + len
)))
203 strcat( inherit_str
, " " );
207 if (!(inherit_str
= malloc( len
))) out_of_memory();
210 for (i
= 0; i
< count
; i
++)
212 strcat( inherit_str
, argv
[pos
+i
] );
213 if (i
< count
-1) strcat( inherit_str
, " " );
216 while ((argv
[pos
] = argv
[pos
+count
])) pos
++;
219 /* parse options from the argv array and remove all the recognized ones */
220 static void parse_options( char *argv
[] )
222 const struct option_descr
*opt
;
225 for (i
= 0; argv
[i
]; i
++)
227 const char *equalarg
= NULL
;
229 if (*p
++ != '-') continue; /* not an option */
230 if (*p
&& !p
[1]) /* short name */
232 if (*p
== '-') break; /* "--" option */
233 for (opt
= option_table
; opt
->longname
; opt
++) if (opt
->shortname
== *p
) break;
237 const char *equal
= strchr (p
, '=');
239 /* check for the long name */
240 for (opt
= option_table
; opt
->longname
; opt
++) {
242 if (!strcmp( p
, opt
->longname
)) break;
247 strlen (opt
->longname
) == equal
- p
&&
248 !strncmp (p
, opt
->longname
, equal
- p
)) {
249 equalarg
= equal
+ 1;
254 if (!opt
->longname
) continue;
258 opt
->func( equalarg
);
259 remove_options( argv
, i
, 1, opt
->inherit
);
261 else if (opt
->has_arg
&& argv
[i
+1])
263 opt
->func( argv
[i
+1] );
264 remove_options( argv
, i
, 2, opt
->inherit
);
269 remove_options( argv
, i
, 1, opt
->inherit
);
275 /* inherit options from WINEOPTIONS variable */
276 static void inherit_options( char *buffer
)
281 char *p
= strtok( buffer
, " \t" );
282 for (n
= 0; n
< sizeof(argv
)/sizeof(argv
[0])-1 && p
; n
++)
285 p
= strtok( NULL
, " \t" );
288 parse_options( argv
);
289 if (argv
[0]) /* an option remains */
291 MESSAGE( "Unknown option '%s' in WINEOPTIONS variable\n\n", argv
[0] );
296 /***********************************************************************
299 void OPTIONS_Usage(void)
301 const struct option_descr
*opt
;
302 MESSAGE( "%s\n\n", WINE_RELEASE_INFO
);
303 MESSAGE( "Usage: %s [options] [--] program_name [arguments]\n", argv0
);
304 MESSAGE("The -- has to be used if you specify arguments (of the program)\n\n");
305 MESSAGE( "Options:\n" );
306 for (opt
= option_table
; opt
->longname
; opt
++) MESSAGE( " %s\n", opt
->usage
);
310 /***********************************************************************
311 * OPTIONS_ParseOptions
313 void OPTIONS_ParseOptions( char *argv
[] )
318 if (GetEnvironmentVariableA( "WINEOPTIONS", buffer
, sizeof(buffer
) ) && buffer
[0])
319 inherit_options( buffer
);
321 parse_options( argv
+ 1 );
323 SetEnvironmentVariableA( "WINEOPTIONS", inherit_str
);
325 /* check if any option remains */
326 for (i
= 1; argv
[i
]; i
++)
328 if (!strcmp( argv
[i
], "--" ))
330 remove_options( argv
, i
, 1, 0 );
333 if (argv
[i
][0] == '-')
335 MESSAGE( "Unknown option '%s'\n\n", argv
[i
] );