4 * Copyright 2000 Alexandre Julliard
14 #include "debugtools.h"
21 void (*func)( const char *arg );
25 static void do_config( const char *arg );
26 static void do_desktop( const char *arg );
27 static void do_display( const char *arg );
28 static void do_dll( const char *arg );
29 static void do_help( const char *arg );
30 static void do_managed( const char *arg );
31 static void do_synchronous( const char *arg );
32 static void do_version( const char *arg );
34 static const struct option option_table[] =
36 { "config", 0, 1, do_config,
37 "--config name Specify config file to use" },
38 { "debugmsg", 0, 1, MAIN_ParseDebugOptions,
39 "--debugmsg name Turn debugging-messages on or off" },
40 { "desktop", 0, 1, do_desktop,
41 "--desktop geom Use a desktop window of the given geometry" },
42 { "display", 0, 1, do_display,
43 "--display name Use the specified display" },
44 { "dll", 0, 1, do_dll,
45 "--dll name Enable or disable built-in DLLs" },
46 { "dosver", 0, 1, VERSION_ParseDosVersion,
47 "--dosver x.xx DOS version to imitate (e.g. 6.22). Only valid with --winver win31" },
48 { "help", 'h', 0, do_help,
49 "--help,-h Show this help message" },
50 { "language", 0, 1, MAIN_ParseLanguageOption,
51 "--language xx Set the language (one of Br,Ca,Cs,Cy,Da,De,En,Eo,Es,Fi,Fr,Ga,Gd,Gv\n"
52 " Hu,It,Ja,Ko,Kw,Nl,No,Pl,Pt,Sk,Sv,Ru,Wa)" },
53 { "managed", 0, 0, do_managed,
54 "--managed Allow the window manager to manage created windows" },
55 { "synchronous", 0, 0, do_synchronous,
56 "--synchronous Turn on synchronous display mode" },
57 { "version", 'v', 0, do_version,
58 "--version,-v Display the Wine version" },
59 { "winver", 0, 1, VERSION_ParseWinVersion,
60 "--winver Version to imitate (one of win31,win95,nt351,nt40)" },
61 { NULL, } /* terminator */
65 static void do_help( const char *arg )
70 static void do_version( const char *arg )
72 MESSAGE( "%s\n", WINE_RELEASE_INFO );
76 static void do_synchronous( const char *arg )
78 Options.synchronous = TRUE;
81 static void do_desktop( const char *arg )
83 Options.desktopGeometry = strdup( arg );
86 static void do_display( const char *arg )
88 Options.display = strdup( arg );
91 static void do_dll( const char *arg )
95 /* don't overwrite previous value. Should we
96 * automatically add the ',' between multiple DLLs ?
98 MESSAGE("Only one -dll flag is allowed. Use ',' between multiple DLLs\n");
101 Options.dllFlags = strdup( arg );
104 static void do_managed( const char *arg )
106 Options.managed = TRUE;
109 static void do_config( const char *arg )
111 Options.configFileName = strdup( arg );
114 static inline void remove_options( int *argc, char *argv[], int pos, int count )
116 while ((argv[pos] = argv[pos+count])) pos++;
120 /***********************************************************************
123 void OPTIONS_Usage(void)
125 const struct option *opt;
126 MESSAGE( "Usage: %s [options] \"program_name [arguments]\"\n\n", argv0 );
127 MESSAGE( "Options:\n" );
128 for (opt = option_table; opt->longname; opt++) MESSAGE( " %s\n", opt->usage );
132 /***********************************************************************
133 * OPTIONS_ParseOptions
135 void OPTIONS_ParseOptions( int argc, char *argv[] )
137 const struct option *opt;
140 for (i = 1; argv[i]; i++)
143 if (*p++ != '-') continue; /* not an option */
144 if (*p && !p[1]) /* short name */
146 if (*p == '-') break; /* "--" option */
147 for (opt = option_table; opt->longname; opt++) if (opt->shortname == *p) break;
152 /* check for the long name */
153 for (opt = option_table; opt->longname; opt++)
154 if (!strcmp( p, opt->longname )) break;
156 if (!opt->longname) continue;
158 if (opt->has_arg && argv[i+1])
160 opt->func( argv[i+1] );
161 remove_options( &argc, argv, i, 2 );
166 remove_options( &argc, argv, i, 1 );
171 /* check if any option remains */
172 for (i = 1; argv[i]; i++)
174 if (!strcmp( argv[i], "--" ))
176 remove_options( &argc, argv, i, 1 );
179 if (argv[i][0] == '-')
181 MESSAGE( "Unknown option '%s'\n", argv[i] );