4 * Copyright 2000 Alexandre Julliard
12 #include "wine/library.h"
16 #include "debugtools.h"
24 void (*func
)( const char *arg
);
28 /* Most Windows C/C++ compilers use something like this to */
29 /* access argc and argv globally: */
34 struct options Options
=
36 NULL
, /* desktopGeometry */
39 FALSE
, /* synchronous */
40 FALSE
, /* Managed windows */
41 NULL
/* Alternate config file name */
44 const char *argv0
; /* the original argv[0] */
45 const char *full_argv0
; /* the full path of argv[0] (if known) */
47 static char *inherit_str
; /* options to pass to child processes */
49 static void out_of_memory(void) WINE_NORETURN
;
50 static void out_of_memory(void)
52 MESSAGE( "Virtual memory exhausted\n" );
56 static char *xstrdup( const char *str
)
58 char *ret
= strdup( str
);
59 if (!ret
) out_of_memory();
63 static void do_config( const char *arg
);
64 static void do_debugmsg( const char *arg
);
65 static void do_desktop( const char *arg
);
66 static void do_display( const char *arg
);
67 static void do_dll( const char *arg
);
68 static void do_help( const char *arg
);
69 static void do_language( const char *arg
);
70 static void do_managed( const char *arg
);
71 static void do_synchronous( const char *arg
);
72 static void do_version( const char *arg
);
74 static const struct option option_table
[] =
76 { "config", 0, 1, 0, do_config
,
77 "--config name Specify config file to use" },
78 { "debugmsg", 0, 1, 1, do_debugmsg
,
79 "--debugmsg name Turn debugging-messages on or off" },
80 { "desktop", 0, 1, 1, do_desktop
,
81 "--desktop geom Use a desktop window of the given geometry" },
82 { "display", 0, 1, 0, do_display
,
83 "--display name Use the specified display" },
84 { "dll", 0, 1, 1, do_dll
,
85 "--dll name Enable or disable built-in DLLs" },
86 { "dosver", 0, 1, 1, VERSION_ParseDosVersion
,
87 "--dosver x.xx DOS version to imitate (e.g. 6.22). Only valid with --winver win31" },
88 { "help", 'h', 0, 0, do_help
,
89 "--help,-h Show this help message" },
90 { "language", 0, 1, 1, do_language
,
91 "--language xx Set the language (one of Br,Ca,Cs,Cy,Da,De,En,Eo,Es,Fi,Fr,Ga,Gd,Gv,\n"
92 " Hr,Hu,It,Ja,Ko,Kw,Nl,No,Pl,Pt,Sk,Sv,Ru,Wa)" },
93 { "managed", 0, 0, 0, do_managed
,
94 "--managed Allow the window manager to manage created windows" },
95 { "synchronous", 0, 0, 1, do_synchronous
,
96 "--synchronous Turn on synchronous display mode" },
97 { "version", 'v', 0, 0, do_version
,
98 "--version,-v Display the Wine version" },
99 { "winver", 0, 1, 1, VERSION_ParseWinVersion
,
100 "--winver Version to imitate (one of win31,win95,nt351,nt40)" },
101 { NULL
, 0, 0, 0, NULL
, NULL
} /* terminator */
105 static void do_help( const char *arg
)
110 static void do_version( const char *arg
)
112 MESSAGE( "%s\n", WINE_RELEASE_INFO
);
116 static void do_synchronous( const char *arg
)
118 Options
.synchronous
= TRUE
;
121 static void do_desktop( const char *arg
)
123 Options
.desktopGeometry
= xstrdup( arg
);
126 static void do_display( const char *arg
)
128 Options
.display
= xstrdup( arg
);
131 static void do_dll( const char *arg
)
133 if (Options
.dllFlags
)
135 Options
.dllFlags
= (char *) realloc ( Options
.dllFlags
,
136 strlen ( Options
.dllFlags
) + strlen ( arg
) + 2 );
137 if ( !Options
.dllFlags
) out_of_memory();
138 strcat ( Options
.dllFlags
, "+" );
139 strcat ( Options
.dllFlags
, arg
);
143 Options
.dllFlags
= xstrdup( arg
);
147 static void do_language( const char *arg
)
149 SetEnvironmentVariableA( "LANGUAGE", arg
);
152 static void do_managed( const char *arg
)
154 Options
.managed
= TRUE
;
157 static void do_config( const char *arg
)
159 Options
.configFileName
= xstrdup( arg
);
162 static void do_debugmsg( const char *arg
)
164 static const char * const debug_class_names
[__DBCL_COUNT
] = { "fixme", "err", "warn", "trace" };
166 char *opt
, *options
= strdup(arg
);
169 if (!(opt
= strtok( options
, "," ))) goto error
;
172 unsigned char set
= 0, clear
= 0;
173 char *p
= strchr( opt
, '+' );
174 if (!p
) p
= strchr( opt
, '-' );
175 if (!p
|| !p
[1]) goto error
;
178 for (i
= 0; i
< __DBCL_COUNT
; i
++)
180 int len
= strlen(debug_class_names
[i
]);
181 if (len
!= (p
- opt
)) continue;
182 if (!memcmp( opt
, debug_class_names
[i
], len
)) /* found it */
184 if (*p
== '+') set
|= 1 << i
;
185 else clear
|= 1 << i
;
189 if (i
== __DBCL_COUNT
) goto error
; /* class name not found */
193 if (*p
== '+') set
= ~0;
197 if (!strcmp( p
, "all" )) p
= ""; /* empty string means all */
198 wine_dbg_add_option( p
, set
, clear
);
199 opt
= strtok( NULL
, "," );
206 MESSAGE("wine: Syntax: --debugmsg [class]+xxx,... or "
207 "-debugmsg [class]-xxx,...\n");
208 MESSAGE("Example: --debugmsg +all,warn-heap\n"
209 " turn on all messages except warning heap messages\n");
210 MESSAGE("Available message classes:\n");
211 for( i
= 0; i
< __DBCL_COUNT
; i
++) MESSAGE( "%-9s", debug_class_names
[i
] );
217 static void remove_options( char *argv
[], int pos
, int count
, int inherit
)
222 for (i
= 0; i
< count
; i
++) len
+= strlen(argv
[pos
+i
]) + 1;
225 if (!(inherit_str
= realloc( inherit_str
, strlen(inherit_str
) + 1 + len
)))
227 strcat( inherit_str
, " " );
231 if (!(inherit_str
= malloc( len
))) out_of_memory();
234 for (i
= 0; i
< count
; i
++)
236 strcat( inherit_str
, argv
[pos
+i
] );
237 if (i
< count
-1) strcat( inherit_str
, " " );
240 while ((argv
[pos
] = argv
[pos
+count
])) pos
++;
243 /* parse options from the argv array and remove all the recognized ones */
244 static void parse_options( char *argv
[] )
246 const struct option
*opt
;
249 for (i
= 0; argv
[i
]; i
++)
252 if (*p
++ != '-') continue; /* not an option */
253 if (*p
&& !p
[1]) /* short name */
255 if (*p
== '-') break; /* "--" option */
256 for (opt
= option_table
; opt
->longname
; opt
++) if (opt
->shortname
== *p
) break;
261 /* check for the long name */
262 for (opt
= option_table
; opt
->longname
; opt
++)
263 if (!strcmp( p
, opt
->longname
)) break;
265 if (!opt
->longname
) continue;
267 if (opt
->has_arg
&& argv
[i
+1])
269 opt
->func( argv
[i
+1] );
270 remove_options( argv
, i
, 2, opt
->inherit
);
275 remove_options( argv
, i
, 1, opt
->inherit
);
281 /* inherit options from WINEOPTIONS variable */
282 static void inherit_options( char *buffer
)
287 char *p
= strtok( buffer
, " \t" );
288 for (n
= 0; n
< sizeof(argv
)/sizeof(argv
[0])-1 && p
; n
++)
291 p
= strtok( NULL
, " \t" );
294 parse_options( argv
);
295 if (argv
[0]) /* an option remains */
297 MESSAGE( "Unknown option '%s' in WINEOPTIONS variable\n\n", argv
[0] );
302 /***********************************************************************
305 void OPTIONS_Usage(void)
307 const struct option
*opt
;
308 MESSAGE( "Usage: %s [options] program_name [arguments]\n\n", argv0
);
309 MESSAGE( "Options:\n" );
310 for (opt
= option_table
; opt
->longname
; opt
++) MESSAGE( " %s\n", opt
->usage
);
314 /***********************************************************************
315 * OPTIONS_ParseOptions
317 void OPTIONS_ParseOptions( char *argv
[] )
322 if (GetEnvironmentVariableA( "WINEOPTIONS", buffer
, sizeof(buffer
) ) && buffer
[0])
323 inherit_options( buffer
);
325 parse_options( argv
+ 1 );
327 SetEnvironmentVariableA( "WINEOPTIONS", inherit_str
);
329 /* check if any option remains */
330 for (i
= 1; argv
[i
]; i
++)
332 if (!strcmp( argv
[i
], "--" ))
334 remove_options( argv
, i
, 1, 0 );
337 if (argv
[i
][0] == '-')
339 MESSAGE( "Unknown option '%s'\n\n", argv
[i
] );
344 /* count the resulting arguments */
347 while (argv
[_ARGC
]) _ARGC
++;