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_debug( const char *arg );
27 static void do_desktop( const char *arg );
28 static void do_display( const char *arg );
29 static void do_dll( const char *arg );
30 static void do_failreadonly( const char *arg );
31 static void do_help( const char *arg );
32 static void do_managed( const char *arg );
33 static void do_synchronous( const char *arg );
34 static void do_version( const char *arg );
36 static const struct option option_table[] =
38 { "config", 0, 1, do_config,
39 "--config name Specify config file to use" },
40 { "debug", 0, 0, do_debug,
41 "--debug Enter debugger before starting application" },
42 { "debugmsg", 0, 1, MAIN_ParseDebugOptions,
43 "--debugmsg name Turn debugging-messages on or off" },
44 { "desktop", 0, 1, do_desktop,
45 "--desktop geom Use a desktop window of the given geometry" },
46 { "display", 0, 1, do_display,
47 "--display name Use the specified display" },
48 { "dll", 0, 1, do_dll,
49 "--dll name Enable or disable built-in DLLs" },
50 { "dosver", 0, 1, VERSION_ParseDosVersion,
51 "--dosver x.xx DOS version to imitate (e.g. 6.22). Only valid with --winver win31" },
52 { "help", 'h', 0, do_help,
53 "--help,-h Show this help message" },
54 { "language", 0, 1, MAIN_ParseLanguageOption,
55 "--language xx Set the language (one of Br,Ca,Cs,Cy,Da,De,En,Eo,Es,Fi,Fr,Ga,Gd,Gv\n"
56 " Hu,It,Ja,Ko,Kw,Nl,No,Pl,Pt,Sk,Sv,Ru,Wa)" },
57 { "managed", 0, 0, do_managed,
58 "--managed Allow the window manager to manage created windows" },
59 { "synchronous", 0, 0, do_synchronous,
60 "--synchronous Turn on synchronous display mode" },
61 { "version", 'v', 0, do_version,
62 "--version,-v Display the Wine version" },
63 { "winver", 0, 1, VERSION_ParseWinVersion,
64 "--winver Version to imitate (one of win31,win95,nt351,nt40)" },
65 { NULL, } /* terminator */
69 static void do_help( const char *arg )
74 static void do_version( const char *arg )
76 MESSAGE( "%s\n", WINE_RELEASE_INFO );
80 static void do_synchronous( const char *arg )
82 Options.synchronous = TRUE;
85 static void do_debug( const char *arg )
90 static void do_desktop( const char *arg )
92 Options.desktopGeometry = strdup( arg );
95 static void do_display( const char *arg )
97 Options.display = strdup( arg );
100 static void do_dll( const char *arg )
102 if (Options.dllFlags)
104 /* don't overwrite previous value. Should we
105 * automatically add the ',' between multiple DLLs ?
107 MESSAGE("Only one -dll flag is allowed. Use ',' between multiple DLLs\n");
110 Options.dllFlags = strdup( arg );
113 static void do_managed( const char *arg )
115 Options.managed = TRUE;
118 static void do_config( const char *arg )
120 Options.configFileName = strdup( arg );
123 static inline void remove_options( int *argc, char *argv[], int pos, int count )
125 while ((argv[pos] = argv[pos+count])) pos++;
129 /***********************************************************************
132 void OPTIONS_Usage(void)
134 const struct option *opt;
135 MESSAGE( "Usage: %s [options] \"program_name [arguments]\"\n\n", argv0 );
136 MESSAGE( "Options:\n" );
137 for (opt = option_table; opt->longname; opt++) MESSAGE( " %s\n", opt->usage );
141 /***********************************************************************
142 * OPTIONS_ParseOptions
144 void OPTIONS_ParseOptions( int argc, char *argv[] )
146 const struct option *opt;
149 for (i = 1; argv[i]; i++)
152 if (*p++ != '-') continue; /* not an option */
153 if (*p && !p[1]) /* short name */
155 if (*p == '-') break; /* "--" option */
156 for (opt = option_table; opt->longname; opt++) if (opt->shortname == *p) break;
161 /* check for the long name */
162 for (opt = option_table; opt->longname; opt++)
163 if (!strcmp( p, opt->longname )) break;
165 if (!opt->longname) continue;
167 if (opt->has_arg && argv[i+1])
169 opt->func( argv[i+1] );
170 remove_options( &argc, argv, i, 2 );
175 remove_options( &argc, argv, i, 1 );
180 /* check if any option remains */
181 for (i = 1; argv[i]; i++)
183 if (!strcmp( argv[i], "--" ))
185 remove_options( &argc, argv, i, 1 );
188 if (argv[i][0] == '-')
190 MESSAGE( "Unknown option '%s'\n", argv[i] );