4 * Copyright 2000 Alexandre Julliard
14 #include "debugtools.h"
21 void (*func
)( const char *arg
);
25 /* Most Windows C/C++ compilers use something like this to */
26 /* access argc and argv globally: */
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
)
75 static void do_version( const char *arg
)
77 MESSAGE( "%s\n", WINE_RELEASE_INFO
);
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
)
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");
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
++;
125 /***********************************************************************
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
);
137 /***********************************************************************
138 * OPTIONS_ParseOptions
140 void OPTIONS_ParseOptions( int argc
, char *argv
[] )
142 const struct option
*opt
;
145 for (i
= 1; argv
[i
]; 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;
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 );
171 remove_options( &argc
, argv
, i
, 1 );
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 );
184 if (argv
[i
][0] == '-')
186 MESSAGE( "Unknown option '%s'\n", argv
[i
] );