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 { "failreadonly", 0, 0, do_failreadonly
,
53 "--failreadonly Read only files may not be opened in write mode" },
54 { "help", 'h', 0, do_help
,
55 "--help,-h Show this help message" },
56 { "language", 0, 1, MAIN_ParseLanguageOption
,
57 "--language xx Set the language (one of Br,Ca,Cs,Cy,Da,De,En,Eo,Es,Fi,Fr,Ga,Gd,Gv\n"
58 " Hu,It,Ja,Ko,Kw,Nl,No,Pl,Pt,Sk,Sv,Ru,Wa)" },
59 { "managed", 0, 0, do_managed
,
60 "--managed Allow the window manager to manage created windows" },
61 { "synchronous", 0, 0, do_synchronous
,
62 "--synchronous Turn on synchronous display mode" },
63 { "version", 'v', 0, do_version
,
64 "--version,-v Display the Wine version" },
65 { "winver", 0, 1, VERSION_ParseWinVersion
,
66 "--winver Version to imitate (one of win31,win95,nt351,nt40)" },
67 { NULL
, } /* terminator */
71 static void do_help( const char *arg
)
76 static void do_version( const char *arg
)
78 MESSAGE( "%s\n", WINE_RELEASE_INFO
);
82 static void do_synchronous( const char *arg
)
84 Options
.synchronous
= TRUE
;
87 static void do_debug( const char *arg
)
92 static void do_failreadonly( const char *arg
)
94 Options
.failReadOnly
= TRUE
;
97 static void do_desktop( const char *arg
)
99 Options
.desktopGeometry
= strdup( arg
);
102 static void do_display( const char *arg
)
104 Options
.display
= strdup( arg
);
107 static void do_dll( const char *arg
)
109 if (Options
.dllFlags
)
111 /* don't overwrite previous value. Should we
112 * automatically add the ',' between multiple DLLs ?
114 MESSAGE("Only one -dll flag is allowed. Use ',' between multiple DLLs\n");
117 Options
.dllFlags
= strdup( arg
);
120 static void do_managed( const char *arg
)
122 Options
.managed
= TRUE
;
125 static void do_config( const char *arg
)
127 Options
.configFileName
= strdup( arg
);
130 static inline void remove_options( int *argc
, char *argv
[], int pos
, int count
)
132 while ((argv
[pos
] = argv
[pos
+count
])) pos
++;
136 /***********************************************************************
139 void OPTIONS_Usage(void)
141 const struct option
*opt
;
142 MESSAGE( "Usage: %s [options] \"program_name [arguments]\"\n\n", argv0
);
143 MESSAGE( "Options:\n" );
144 for (opt
= option_table
; opt
->longname
; opt
++) MESSAGE( " %s\n", opt
->usage
);
148 /***********************************************************************
149 * OPTIONS_ParseOptions
151 void OPTIONS_ParseOptions( int argc
, char *argv
[] )
153 const struct option
*opt
;
156 for (i
= 1; argv
[i
]; i
++)
159 if (*p
++ != '-') continue; /* not an option */
160 if (*p
&& !p
[1]) /* short name */
162 if (*p
== '-') break; /* "--" option */
163 for (opt
= option_table
; opt
->longname
; opt
++) if (opt
->shortname
== *p
) break;
168 /* check for the long name */
169 for (opt
= option_table
; opt
->longname
; opt
++)
170 if (!strcmp( p
, opt
->longname
)) break;
172 if (!opt
->longname
) continue;
174 if (opt
->has_arg
&& argv
[i
+1])
176 opt
->func( argv
[i
+1] );
177 remove_options( &argc
, argv
, i
, 2 );
182 remove_options( &argc
, argv
, i
, 1 );
187 /* check if any option remains */
188 for (i
= 1; argv
[i
]; i
++)
190 if (!strcmp( argv
[i
], "--" ))
192 remove_options( &argc
, argv
, i
, 1 );
195 if (argv
[i
][0] == '-')
197 MESSAGE( "Unknown option '%s'\n", argv
[i
] );