4 * Copyright 2000 Alexandre Julliard
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
31 #include "wine/library.h"
33 #include "wine/debug.h"
40 void (*func
)( const char *arg
);
44 static void do_debugmsg( const char *arg
);
45 static void do_help( const char *arg
);
46 static void do_version( const char *arg
);
48 static const struct option_descr option_table
[] =
50 { "debugmsg", 0, 1, do_debugmsg
,
51 "--debugmsg name No longer supported, use the WINEDEBUG variable instead" },
52 { "help", 'h', 0, do_help
,
53 "--help,-h Show this help message" },
54 { "version", 'v', 0, do_version
,
55 "--version,-v Display the Wine version" },
56 { NULL
, 0, 0, NULL
, NULL
} /* terminator */
60 static void do_help( const char *arg
)
65 static void do_version( const char *arg
)
67 MESSAGE( "%s\n", PACKAGE_STRING
);
71 static void do_debugmsg( const char *arg
)
73 MESSAGE("Error: the --debugmsg option is no longer supported. You should use\n");
74 MESSAGE("the WINEDEBUG environment variable instead, like this:\n\n");
75 MESSAGE(" WINEDEBUG=%s wine ...\n\n", arg
);
79 static inline void remove_options( char *argv
[], int pos
, int count
)
81 while ((argv
[pos
] = argv
[pos
+count
])) pos
++;
84 /* parse options from the argv array and remove all the recognized ones */
85 static void parse_options( char *argv
[] )
87 const struct option_descr
*opt
;
90 for (i
= 0; argv
[i
]; i
++)
92 const char *equalarg
= NULL
;
94 if (*p
++ != '-') continue; /* not an option */
95 if (*p
&& !p
[1]) /* short name */
97 if (*p
== '-') break; /* "--" option */
98 for (opt
= option_table
; opt
->longname
; opt
++) if (opt
->shortname
== *p
) break;
102 const char *equal
= strchr (p
, '=');
104 /* check for the long name */
105 for (opt
= option_table
; opt
->longname
; opt
++) {
107 if (!strcmp( p
, opt
->longname
)) break;
112 strlen (opt
->longname
) == equal
- p
&&
113 !strncmp (p
, opt
->longname
, equal
- p
)) {
114 equalarg
= equal
+ 1;
119 if (!opt
->longname
) continue;
123 opt
->func( equalarg
);
124 remove_options( argv
, i
, 1 );
126 else if (opt
->has_arg
&& argv
[i
+1])
128 opt
->func( argv
[i
+1] );
129 remove_options( argv
, i
, 2 );
134 remove_options( argv
, i
, 1 );
140 /***********************************************************************
143 void OPTIONS_Usage(void)
145 const struct option_descr
*opt
;
146 MESSAGE( "%s\n\n", PACKAGE_STRING
);
147 MESSAGE( "Usage: wine [options] [--] program_name [arguments]\n" );
148 MESSAGE("The -- has to be used if you specify arguments (of the program)\n\n");
149 MESSAGE( "Options:\n" );
150 for (opt
= option_table
; opt
->longname
; opt
++) MESSAGE( " %s\n", opt
->usage
);
154 /***********************************************************************
155 * OPTIONS_ParseOptions
157 void OPTIONS_ParseOptions( char *argv
[] )
161 parse_options( argv
+ 1 );
163 /* check if any option remains */
164 for (i
= 1; argv
[i
]; i
++)
166 if (!strcmp( argv
[i
], "--" ))
168 remove_options( argv
, i
, 1 );
171 if (argv
[i
][0] == '-')
173 MESSAGE( "Unknown option '%s'\n\n", argv
[i
] );