Improved Winelib apps initialisation code. No longer need to link
[wine/multimedia.git] / misc / options.c
blobff471768538017fdc9e9407e899dcf08587b95f6
1 /*
2 * Option parsing
4 * Copyright 2000 Alexandre Julliard
5 */
7 #include "config.h"
8 #include <string.h>
10 #include "winbase.h"
11 #include "main.h"
12 #include "options.h"
13 #include "version.h"
14 #include "debugtools.h"
16 struct option
18 const char *longname;
19 char shortname;
20 int has_arg;
21 void (*func)( const char *arg );
22 const char *usage;
25 /* Most Windows C/C++ compilers use something like this to */
26 /* access argc and argv globally: */
27 int _ARGC;
28 char **_ARGV;
30 static void do_config( const char *arg );
31 static void do_desktop( const char *arg );
32 static void do_display( const char *arg );
33 static void do_dll( const char *arg );
34 static void do_help( const char *arg );
35 static void do_managed( const char *arg );
36 static void do_synchronous( const char *arg );
37 static void do_version( const char *arg );
39 static const struct option option_table[] =
41 { "config", 0, 1, do_config,
42 "--config name Specify config file to use" },
43 { "debugmsg", 0, 1, MAIN_ParseDebugOptions,
44 "--debugmsg name Turn debugging-messages on or off" },
45 { "desktop", 0, 1, do_desktop,
46 "--desktop geom Use a desktop window of the given geometry" },
47 { "display", 0, 1, do_display,
48 "--display name Use the specified display" },
49 { "dll", 0, 1, do_dll,
50 "--dll name Enable or disable built-in DLLs" },
51 { "dosver", 0, 1, VERSION_ParseDosVersion,
52 "--dosver x.xx DOS version to imitate (e.g. 6.22). Only valid with --winver win31" },
53 { "help", 'h', 0, do_help,
54 "--help,-h Show this help message" },
55 { "language", 0, 1, MAIN_ParseLanguageOption,
56 "--language xx Set the language (one of Br,Ca,Cs,Cy,Da,De,En,Eo,Es,Fi,Fr,Ga,Gd,Gv\n"
57 " Hu,It,Ja,Ko,Kw,Nl,No,Pl,Pt,Sk,Sv,Ru,Wa)" },
58 { "managed", 0, 0, do_managed,
59 "--managed Allow the window manager to manage created windows" },
60 { "synchronous", 0, 0, do_synchronous,
61 "--synchronous Turn on synchronous display mode" },
62 { "version", 'v', 0, do_version,
63 "--version,-v Display the Wine version" },
64 { "winver", 0, 1, VERSION_ParseWinVersion,
65 "--winver Version to imitate (one of win31,win95,nt351,nt40)" },
66 { NULL, } /* terminator */
70 static void do_help( const char *arg )
72 OPTIONS_Usage();
75 static void do_version( const char *arg )
77 MESSAGE( "%s\n", WINE_RELEASE_INFO );
78 ExitProcess(0);
81 static void do_synchronous( const char *arg )
83 Options.synchronous = TRUE;
86 static void do_desktop( const char *arg )
88 Options.desktopGeometry = strdup( arg );
91 static void do_display( const char *arg )
93 Options.display = strdup( arg );
96 static void do_dll( const char *arg )
98 if (Options.dllFlags)
100 /* don't overwrite previous value. Should we
101 * automatically add the ',' between multiple DLLs ?
103 MESSAGE("Only one -dll flag is allowed. Use ',' between multiple DLLs\n");
104 ExitProcess(1);
106 Options.dllFlags = strdup( arg );
109 static void do_managed( const char *arg )
111 Options.managed = TRUE;
114 static void do_config( const char *arg )
116 Options.configFileName = strdup( arg );
119 static inline void remove_options( int *argc, char *argv[], int pos, int count )
121 while ((argv[pos] = argv[pos+count])) pos++;
122 *argc -= count;
125 /***********************************************************************
126 * OPTIONS_Usage
128 void OPTIONS_Usage(void)
130 const struct option *opt;
131 MESSAGE( "Usage: %s [options] \"program_name [arguments]\"\n\n", argv0 );
132 MESSAGE( "Options:\n" );
133 for (opt = option_table; opt->longname; opt++) MESSAGE( " %s\n", opt->usage );
134 ExitProcess(0);
137 /***********************************************************************
138 * OPTIONS_ParseOptions
140 void OPTIONS_ParseOptions( int argc, char *argv[] )
142 const struct option *opt;
143 int i;
145 for (i = 1; argv[i]; i++)
147 char *p = argv[i];
148 if (*p++ != '-') continue; /* not an option */
149 if (*p && !p[1]) /* short name */
151 if (*p == '-') break; /* "--" option */
152 for (opt = option_table; opt->longname; opt++) if (opt->shortname == *p) break;
154 else /* long name */
156 if (*p == '-') p++;
157 /* check for the long name */
158 for (opt = option_table; opt->longname; opt++)
159 if (!strcmp( p, opt->longname )) break;
161 if (!opt->longname) continue;
163 if (opt->has_arg && argv[i+1])
165 opt->func( argv[i+1] );
166 remove_options( &argc, argv, i, 2 );
168 else
170 opt->func( "" );
171 remove_options( &argc, argv, i, 1 );
173 i--;
176 /* check if any option remains */
177 for (i = 1; argv[i]; i++)
179 if (!strcmp( argv[i], "--" ))
181 remove_options( &argc, argv, i, 1 );
182 break;
184 if (argv[i][0] == '-')
186 MESSAGE( "Unknown option '%s'\n", argv[i] );
187 OPTIONS_Usage();
190 Options.argc = argc;
191 Options.argv = argv;
192 _ARGC = argc;
193 _ARGV = argv;