Patch the fragment size if it does not match the current sound
[wine/multimedia.git] / misc / options.c
blob94a98cba9e7b06a2c655f14326b5aa670f3bd911
1 /*
2 * Option parsing
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
21 #include "config.h"
22 #include <stdarg.h>
23 #include <string.h>
24 #include <stdlib.h>
26 #include "windef.h"
27 #include "winbase.h"
28 #include "winnls.h"
29 #include "winreg.h"
30 #include "winternl.h"
31 #include "wine/library.h"
32 #include "options.h"
33 #include "wine/debug.h"
35 struct option_descr
37 const char *longname;
38 char shortname;
39 int has_arg;
40 void (*func)( const char *arg );
41 const char *usage;
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 )
62 OPTIONS_Usage();
65 static void do_version( const char *arg )
67 MESSAGE( "%s\n", PACKAGE_STRING );
68 ExitProcess(0);
71 static void do_debugmsg( const char *arg )
73 char buffer[1024];
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");
81 ExitProcess(1);
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);
91 *p++ = ',';
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;
107 int i;
109 for (i = 0; argv[i]; i++)
111 const char *equalarg = NULL;
112 char *p = argv[i];
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;
119 else /* long name */
121 const char *equal = strchr (p, '=');
122 if (*p == '-') p++;
123 /* check for the long name */
124 for (opt = option_table; opt->longname; opt++) {
125 /* Plain --option */
126 if (!strcmp( p, opt->longname )) break;
128 /* --option=value */
129 if (opt->has_arg &&
130 equal &&
131 strlen (opt->longname) == equal - p &&
132 !strncmp (p, opt->longname, equal - p)) {
133 equalarg = equal + 1;
134 break;
138 if (!opt->longname) continue;
140 if (equalarg)
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 );
150 else
152 opt->func( "" );
153 remove_options( argv, i, 1 );
155 i--;
159 /***********************************************************************
160 * OPTIONS_Usage
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 );
170 ExitProcess(0);
173 /***********************************************************************
174 * OPTIONS_ParseOptions
176 void OPTIONS_ParseOptions( char *argv[] )
178 int i;
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 );
188 break;
190 if (argv[i][0] == '-')
192 MESSAGE( "Unknown option '%s'\n\n", argv[i] );
193 OPTIONS_Usage();