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 Turn debugging-messages on or off" },
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
)
75 if (wine_dbg_parse_options( arg
))
77 MESSAGE("wine: Syntax: --debugmsg [class]+xxx,... or -debugmsg [class]-xxx,...\n");
78 MESSAGE("Example: --debugmsg +all,warn-heap\n"
79 " turn on all messages except warning heap messages\n");
80 MESSAGE("Available message classes: err, warn, fixme, trace\n\n");
83 MESSAGE("Warning: the --debugmsg option is deprecated. You should use\n");
84 MESSAGE("the WINEDEBUG environment variable instead, like this:\n\n");
85 MESSAGE(" WINEDEBUG=%s wine ...\n\n", arg
);
87 /* append the argument to WINEDEBUG so that it gets inherited */
88 if (GetEnvironmentVariableA( "WINEDEBUG", buffer
, sizeof(buffer
)-1 ) && buffer
[0])
90 char *p
= buffer
+ strlen(buffer
);
92 lstrcpynA( p
, arg
, buffer
+ sizeof(buffer
) - p
);
93 SetEnvironmentVariableA( "WINEDEBUG", buffer
);
95 else SetEnvironmentVariableA( "WINEDEBUG", arg
);
98 static inline void remove_options( char *argv
[], int pos
, int count
)
100 while ((argv
[pos
] = argv
[pos
+count
])) pos
++;
103 /* parse options from the argv array and remove all the recognized ones */
104 static void parse_options( char *argv
[] )
106 const struct option_descr
*opt
;
109 for (i
= 0; argv
[i
]; i
++)
111 const char *equalarg
= NULL
;
113 if (*p
++ != '-') continue; /* not an option */
114 if (*p
&& !p
[1]) /* short name */
116 if (*p
== '-') break; /* "--" option */
117 for (opt
= option_table
; opt
->longname
; opt
++) if (opt
->shortname
== *p
) break;
121 const char *equal
= strchr (p
, '=');
123 /* check for the long name */
124 for (opt
= option_table
; opt
->longname
; opt
++) {
126 if (!strcmp( p
, opt
->longname
)) break;
131 strlen (opt
->longname
) == equal
- p
&&
132 !strncmp (p
, opt
->longname
, equal
- p
)) {
133 equalarg
= equal
+ 1;
138 if (!opt
->longname
) continue;
142 opt
->func( equalarg
);
143 remove_options( argv
, i
, 1 );
145 else if (opt
->has_arg
&& argv
[i
+1])
147 opt
->func( argv
[i
+1] );
148 remove_options( argv
, i
, 2 );
153 remove_options( argv
, i
, 1 );
159 /***********************************************************************
162 void OPTIONS_Usage(void)
164 const struct option_descr
*opt
;
165 MESSAGE( "%s\n\n", PACKAGE_STRING
);
166 MESSAGE( "Usage: wine [options] [--] program_name [arguments]\n" );
167 MESSAGE("The -- has to be used if you specify arguments (of the program)\n\n");
168 MESSAGE( "Options:\n" );
169 for (opt
= option_table
; opt
->longname
; opt
++) MESSAGE( " %s\n", opt
->usage
);
173 /***********************************************************************
174 * OPTIONS_ParseOptions
176 void OPTIONS_ParseOptions( char *argv
[] )
180 parse_options( argv
+ 1 );
182 /* check if any option remains */
183 for (i
= 1; argv
[i
]; i
++)
185 if (!strcmp( argv
[i
], "--" ))
187 remove_options( argv
, i
, 1 );
190 if (argv
[i
][0] == '-')
192 MESSAGE( "Unknown option '%s'\n\n", argv
[i
] );