4 * Copyright 2000 Alexandre Julliard
15 #include "debugtools.h"
23 void (*func
)( const char *arg
);
27 /* Most Windows C/C++ compilers use something like this to */
28 /* access argc and argv globally: */
33 struct options Options
=
35 NULL
, /* desktopGeometry */
38 FALSE
, /* synchronous */
40 FALSE
, /* Managed windows */
41 NULL
/* Alternate config file name */
46 static char *inherit_str
; /* options to pass to child processes */
48 static void out_of_memory(void) WINE_NORETURN
;
49 static void out_of_memory(void)
51 MESSAGE( "Virtual memory exhausted\n" );
55 static char *xstrdup( const char *str
)
57 char *ret
= strdup( str
);
58 if (!ret
) out_of_memory();
62 static void do_config( const char *arg
);
63 static void do_desktop( const char *arg
);
64 static void do_display( const char *arg
);
65 static void do_dll( const char *arg
);
66 static void do_help( const char *arg
);
67 static void do_managed( const char *arg
);
68 static void do_synchronous( const char *arg
);
69 static void do_version( const char *arg
);
71 static const struct option option_table
[] =
73 { "config", 0, 1, 0, do_config
,
74 "--config name Specify config file to use" },
75 { "debugmsg", 0, 1, 1, MAIN_ParseDebugOptions
,
76 "--debugmsg name Turn debugging-messages on or off" },
77 { "desktop", 0, 1, 1, do_desktop
,
78 "--desktop geom Use a desktop window of the given geometry" },
79 { "display", 0, 1, 0, do_display
,
80 "--display name Use the specified display" },
81 { "dll", 0, 1, 1, do_dll
,
82 "--dll name Enable or disable built-in DLLs" },
83 { "dosver", 0, 1, 1, VERSION_ParseDosVersion
,
84 "--dosver x.xx DOS version to imitate (e.g. 6.22). Only valid with --winver win31" },
85 { "help", 'h', 0, 0, do_help
,
86 "--help,-h Show this help message" },
87 { "language", 0, 1, 1, MAIN_ParseLanguageOption
,
88 "--language xx Set the language (one of Br,Ca,Cs,Cy,Da,De,En,Eo,Es,Fi,Fr,Ga,Gd,Gv,\n"
89 " Hr,Hu,It,Ja,Ko,Kw,Nl,No,Pl,Pt,Sk,Sv,Ru,Wa)" },
90 { "managed", 0, 0, 0, do_managed
,
91 "--managed Allow the window manager to manage created windows" },
92 { "synchronous", 0, 0, 1, do_synchronous
,
93 "--synchronous Turn on synchronous display mode" },
94 { "version", 'v', 0, 0, do_version
,
95 "--version,-v Display the Wine version" },
96 { "winver", 0, 1, 1, VERSION_ParseWinVersion
,
97 "--winver Version to imitate (one of win31,win95,nt351,nt40)" },
98 { NULL
, } /* terminator */
102 static void do_help( const char *arg
)
107 static void do_version( const char *arg
)
109 MESSAGE( "%s\n", WINE_RELEASE_INFO
);
113 static void do_synchronous( const char *arg
)
115 Options
.synchronous
= TRUE
;
118 static void do_desktop( const char *arg
)
120 Options
.desktopGeometry
= xstrdup( arg
);
123 static void do_display( const char *arg
)
125 Options
.display
= xstrdup( arg
);
128 static void do_dll( const char *arg
)
130 if (Options
.dllFlags
)
132 /* don't overwrite previous value. Should we
133 * automatically add the ',' between multiple DLLs ?
135 MESSAGE("Only one -dll flag is allowed. Use ',' between multiple DLLs\n");
138 Options
.dllFlags
= xstrdup( arg
);
141 static void do_managed( const char *arg
)
143 Options
.managed
= TRUE
;
146 static void do_config( const char *arg
)
148 Options
.configFileName
= xstrdup( arg
);
151 static void remove_options( char *argv
[], int pos
, int count
, int inherit
)
156 for (i
= 0; i
< count
; i
++) len
+= strlen(argv
[pos
+i
]) + 1;
159 if (!(inherit_str
= realloc( inherit_str
, strlen(inherit_str
) + 1 + len
)))
161 strcat( inherit_str
, " " );
165 if (!(inherit_str
= malloc( len
))) out_of_memory();
168 for (i
= 0; i
< count
; i
++)
170 strcat( inherit_str
, argv
[pos
+i
] );
171 if (i
< count
-1) strcat( inherit_str
, " " );
174 while ((argv
[pos
] = argv
[pos
+count
])) pos
++;
177 /* parse options from the argv array and remove all the recognized ones */
178 static void parse_options( char *argv
[] )
180 const struct option
*opt
;
183 for (i
= 0; argv
[i
]; i
++)
186 if (*p
++ != '-') continue; /* not an option */
187 if (*p
&& !p
[1]) /* short name */
189 if (*p
== '-') break; /* "--" option */
190 for (opt
= option_table
; opt
->longname
; opt
++) if (opt
->shortname
== *p
) break;
195 /* check for the long name */
196 for (opt
= option_table
; opt
->longname
; opt
++)
197 if (!strcmp( p
, opt
->longname
)) break;
199 if (!opt
->longname
) continue;
201 if (opt
->has_arg
&& argv
[i
+1])
203 opt
->func( argv
[i
+1] );
204 remove_options( argv
, i
, 2, opt
->inherit
);
209 remove_options( argv
, i
, 1, opt
->inherit
);
215 /* inherit options from WINEOPTIONS variable */
216 static void inherit_options( char *buffer
)
221 char *p
= strtok( buffer
, " \t" );
222 for (i
= 0; i
< sizeof(argv
)/sizeof(argv
[0])-1 && p
; i
++)
225 p
= strtok( NULL
, " \t" );
228 parse_options( argv
);
229 if (argv
[0]) /* an option remains */
231 MESSAGE( "Unknown option '%s' in WINEOPTIONS variable\n\n", argv
[0] );
236 /***********************************************************************
239 void OPTIONS_Usage(void)
241 const struct option
*opt
;
242 MESSAGE( "Usage: %s [options] program_name [arguments]\n\n", argv0
);
243 MESSAGE( "Options:\n" );
244 for (opt
= option_table
; opt
->longname
; opt
++) MESSAGE( " %s\n", opt
->usage
);
248 /***********************************************************************
249 * OPTIONS_ParseOptions
251 void OPTIONS_ParseOptions( char *argv
[] )
256 if (GetEnvironmentVariableA( "WINEOPTIONS", buffer
, sizeof(buffer
) ) && buffer
[0])
257 inherit_options( buffer
);
259 parse_options( argv
+ 1 );
261 SetEnvironmentVariableA( "WINEOPTIONS", inherit_str
);
263 /* check if any option remains */
264 for (i
= 1; argv
[i
]; i
++)
266 if (!strcmp( argv
[i
], "--" ))
268 remove_options( argv
, i
, 1, 0 );
271 if (argv
[i
][0] == '-')
273 MESSAGE( "Unknown option '%s'\n\n", argv
[i
] );
278 /* count the resulting arguments */
281 while (argv
[_ARGC
]) _ARGC
++;