annotate subopt-helper.c @ 14456:cf6d4eb322b4

synced with 1.851
author paszczi
date Mon, 10 Jan 2005 22:12:05 +0000
parents 90bcd37dba7f
children 00c3c4111017
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
14281
577c16f551ad suboption parser for vo and ao modules
al
parents:
diff changeset
1 /**
577c16f551ad suboption parser for vo and ao modules
al
parents:
diff changeset
2 * \file subopt-helper.c
577c16f551ad suboption parser for vo and ao modules
al
parents:
diff changeset
3 *
577c16f551ad suboption parser for vo and ao modules
al
parents:
diff changeset
4 * \brief Compensates the suboption parsing code duplication a bit.
577c16f551ad suboption parser for vo and ao modules
al
parents:
diff changeset
5 *
577c16f551ad suboption parser for vo and ao modules
al
parents:
diff changeset
6 * The routines defined below are there to help you with the
577c16f551ad suboption parser for vo and ao modules
al
parents:
diff changeset
7 * suboption parsing. Meaning extracting the options and their
577c16f551ad suboption parser for vo and ao modules
al
parents:
diff changeset
8 * values for you and also outputting generic help message if
577c16f551ad suboption parser for vo and ao modules
al
parents:
diff changeset
9 * a parse error is encountered.
577c16f551ad suboption parser for vo and ao modules
al
parents:
diff changeset
10 *
577c16f551ad suboption parser for vo and ao modules
al
parents:
diff changeset
11 * Most stuff happens in the subopt_parse function: if you call it
577c16f551ad suboption parser for vo and ao modules
al
parents:
diff changeset
12 * it parses for the passed opts in the passed string. It calls some
577c16f551ad suboption parser for vo and ao modules
al
parents:
diff changeset
13 * extra functions for explicit argument parsing ( where the option
577c16f551ad suboption parser for vo and ao modules
al
parents:
diff changeset
14 * itself isn't the argument but a value given after the argument
577c16f551ad suboption parser for vo and ao modules
al
parents:
diff changeset
15 * delimiter ('='). It also calls your test function if you supplied
577c16f551ad suboption parser for vo and ao modules
al
parents:
diff changeset
16 * one.
577c16f551ad suboption parser for vo and ao modules
al
parents:
diff changeset
17 *
577c16f551ad suboption parser for vo and ao modules
al
parents:
diff changeset
18 */
577c16f551ad suboption parser for vo and ao modules
al
parents:
diff changeset
19
577c16f551ad suboption parser for vo and ao modules
al
parents:
diff changeset
20 #include "subopt-helper.h"
577c16f551ad suboption parser for vo and ao modules
al
parents:
diff changeset
21 #include "mp_msg.h"
577c16f551ad suboption parser for vo and ao modules
al
parents:
diff changeset
22
577c16f551ad suboption parser for vo and ao modules
al
parents:
diff changeset
23 #include <stdlib.h>
577c16f551ad suboption parser for vo and ao modules
al
parents:
diff changeset
24 #include <string.h>
577c16f551ad suboption parser for vo and ao modules
al
parents:
diff changeset
25 #include <assert.h>
577c16f551ad suboption parser for vo and ao modules
al
parents:
diff changeset
26
577c16f551ad suboption parser for vo and ao modules
al
parents:
diff changeset
27 #ifndef MPDEBUG
577c16f551ad suboption parser for vo and ao modules
al
parents:
diff changeset
28 #define NDEBUG
577c16f551ad suboption parser for vo and ao modules
al
parents:
diff changeset
29 #endif
577c16f551ad suboption parser for vo and ao modules
al
parents:
diff changeset
30
577c16f551ad suboption parser for vo and ao modules
al
parents:
diff changeset
31 /* prototypes for argument parsing */
577c16f551ad suboption parser for vo and ao modules
al
parents:
diff changeset
32 static char const * parse_int( char const * const str, int * const valp );
577c16f551ad suboption parser for vo and ao modules
al
parents:
diff changeset
33 static char const * parse_str( char const * const str, strarg_t * const valp );
577c16f551ad suboption parser for vo and ao modules
al
parents:
diff changeset
34
577c16f551ad suboption parser for vo and ao modules
al
parents:
diff changeset
35 /**
577c16f551ad suboption parser for vo and ao modules
al
parents:
diff changeset
36 * \brief Try to parse all options in str and fail if it was not possible.
577c16f551ad suboption parser for vo and ao modules
al
parents:
diff changeset
37 *
577c16f551ad suboption parser for vo and ao modules
al
parents:
diff changeset
38 * \param str Pointer to the zero terminated string to be parsed.
577c16f551ad suboption parser for vo and ao modules
al
parents:
diff changeset
39 * \param opts Pointer to a options array. The array must be terminated
577c16f551ad suboption parser for vo and ao modules
al
parents:
diff changeset
40 * with an element having set name to NULL in its opt_t structure.
577c16f551ad suboption parser for vo and ao modules
al
parents:
diff changeset
41 *
577c16f551ad suboption parser for vo and ao modules
al
parents:
diff changeset
42 * \return The return value is zero if the string could be parsed
577c16f551ad suboption parser for vo and ao modules
al
parents:
diff changeset
43 * else a non-zero value is returned.
577c16f551ad suboption parser for vo and ao modules
al
parents:
diff changeset
44 *
577c16f551ad suboption parser for vo and ao modules
al
parents:
diff changeset
45 */
577c16f551ad suboption parser for vo and ao modules
al
parents:
diff changeset
46 int subopt_parse( char const * const str, opt_t * opts )
577c16f551ad suboption parser for vo and ao modules
al
parents:
diff changeset
47 {
577c16f551ad suboption parser for vo and ao modules
al
parents:
diff changeset
48 int parse_err = 0, idx;
577c16f551ad suboption parser for vo and ao modules
al
parents:
diff changeset
49 unsigned int parse_pos = 0;
577c16f551ad suboption parser for vo and ao modules
al
parents:
diff changeset
50
577c16f551ad suboption parser for vo and ao modules
al
parents:
diff changeset
51 /* Initialize set member to false. *
577c16f551ad suboption parser for vo and ao modules
al
parents:
diff changeset
52 * It is set to true if it was found in str */
577c16f551ad suboption parser for vo and ao modules
al
parents:
diff changeset
53 for ( idx=0; opts[idx].name; ++idx )
577c16f551ad suboption parser for vo and ao modules
al
parents:
diff changeset
54 {
577c16f551ad suboption parser for vo and ao modules
al
parents:
diff changeset
55 opts[idx].set = 0;
577c16f551ad suboption parser for vo and ao modules
al
parents:
diff changeset
56 }
577c16f551ad suboption parser for vo and ao modules
al
parents:
diff changeset
57
577c16f551ad suboption parser for vo and ao modules
al
parents:
diff changeset
58 if ( str )
577c16f551ad suboption parser for vo and ao modules
al
parents:
diff changeset
59 {
577c16f551ad suboption parser for vo and ao modules
al
parents:
diff changeset
60 while ( str[parse_pos] && !parse_err )
577c16f551ad suboption parser for vo and ao modules
al
parents:
diff changeset
61 {
577c16f551ad suboption parser for vo and ao modules
al
parents:
diff changeset
62 int next = 0;
577c16f551ad suboption parser for vo and ao modules
al
parents:
diff changeset
63
577c16f551ad suboption parser for vo and ao modules
al
parents:
diff changeset
64 idx = 0; // reset index for the below loop
577c16f551ad suboption parser for vo and ao modules
al
parents:
diff changeset
65 while ( opts[idx].name )
577c16f551ad suboption parser for vo and ao modules
al
parents:
diff changeset
66 {
577c16f551ad suboption parser for vo and ao modules
al
parents:
diff changeset
67 int opt_len;
577c16f551ad suboption parser for vo and ao modules
al
parents:
diff changeset
68 int substr_len;
577c16f551ad suboption parser for vo and ao modules
al
parents:
diff changeset
69
577c16f551ad suboption parser for vo and ao modules
al
parents:
diff changeset
70 // get length of the option we test against */
577c16f551ad suboption parser for vo and ao modules
al
parents:
diff changeset
71 opt_len = strlen( opts[idx].name );
577c16f551ad suboption parser for vo and ao modules
al
parents:
diff changeset
72
577c16f551ad suboption parser for vo and ao modules
al
parents:
diff changeset
73 // get length of the current substring of str */
577c16f551ad suboption parser for vo and ao modules
al
parents:
diff changeset
74 {
577c16f551ad suboption parser for vo and ao modules
al
parents:
diff changeset
75 char * delim, * arg_delim;
577c16f551ad suboption parser for vo and ao modules
al
parents:
diff changeset
76
577c16f551ad suboption parser for vo and ao modules
al
parents:
diff changeset
77 /* search nearest delimiter ( option or argument delimiter ) */
577c16f551ad suboption parser for vo and ao modules
al
parents:
diff changeset
78 delim = strchr( &str[parse_pos], ':' );
577c16f551ad suboption parser for vo and ao modules
al
parents:
diff changeset
79 arg_delim = strchr( &str[parse_pos], '=' );
577c16f551ad suboption parser for vo and ao modules
al
parents:
diff changeset
80
577c16f551ad suboption parser for vo and ao modules
al
parents:
diff changeset
81 if ( ( delim && arg_delim && delim > arg_delim ) ||
577c16f551ad suboption parser for vo and ao modules
al
parents:
diff changeset
82 delim == NULL )
577c16f551ad suboption parser for vo and ao modules
al
parents:
diff changeset
83 {
577c16f551ad suboption parser for vo and ao modules
al
parents:
diff changeset
84 delim = strchr( &str[parse_pos], '=' );
577c16f551ad suboption parser for vo and ao modules
al
parents:
diff changeset
85 }
577c16f551ad suboption parser for vo and ao modules
al
parents:
diff changeset
86
577c16f551ad suboption parser for vo and ao modules
al
parents:
diff changeset
87 substr_len = delim ? // is a delim present
577c16f551ad suboption parser for vo and ao modules
al
parents:
diff changeset
88 delim - &str[parse_pos] : // yes
577c16f551ad suboption parser for vo and ao modules
al
parents:
diff changeset
89 strlen( &str[parse_pos] ); // no, end of string
577c16f551ad suboption parser for vo and ao modules
al
parents:
diff changeset
90 }
577c16f551ad suboption parser for vo and ao modules
al
parents:
diff changeset
91
577c16f551ad suboption parser for vo and ao modules
al
parents:
diff changeset
92 //printf( "substr_len=%d, opt_len=%d\n", substr_len, opt_len );
577c16f551ad suboption parser for vo and ao modules
al
parents:
diff changeset
93
577c16f551ad suboption parser for vo and ao modules
al
parents:
diff changeset
94 /* Check if the length of the current option matches the *
577c16f551ad suboption parser for vo and ao modules
al
parents:
diff changeset
95 * length of the option we want to test again. */
577c16f551ad suboption parser for vo and ao modules
al
parents:
diff changeset
96 if ( substr_len == opt_len )
577c16f551ad suboption parser for vo and ao modules
al
parents:
diff changeset
97 {
577c16f551ad suboption parser for vo and ao modules
al
parents:
diff changeset
98 /* check if option was activated/deactivated */
577c16f551ad suboption parser for vo and ao modules
al
parents:
diff changeset
99 if( strncmp( &str[parse_pos], opts[idx].name, opt_len ) == 0 )
577c16f551ad suboption parser for vo and ao modules
al
parents:
diff changeset
100 {
577c16f551ad suboption parser for vo and ao modules
al
parents:
diff changeset
101 /* option was found */
577c16f551ad suboption parser for vo and ao modules
al
parents:
diff changeset
102 opts[idx].set = 1; next = 1;
577c16f551ad suboption parser for vo and ao modules
al
parents:
diff changeset
103
577c16f551ad suboption parser for vo and ao modules
al
parents:
diff changeset
104 assert( opts[idx].valp && "Need a pointer to store the arg!" );
577c16f551ad suboption parser for vo and ao modules
al
parents:
diff changeset
105
577c16f551ad suboption parser for vo and ao modules
al
parents:
diff changeset
106 /* type specific code */
577c16f551ad suboption parser for vo and ao modules
al
parents:
diff changeset
107 if ( opts[idx].type == OPT_ARG_BOOL )
577c16f551ad suboption parser for vo and ao modules
al
parents:
diff changeset
108 {
577c16f551ad suboption parser for vo and ao modules
al
parents:
diff changeset
109 /* Handle OPT_ARG_BOOL seperately so *
577c16f551ad suboption parser for vo and ao modules
al
parents:
diff changeset
110 * the others can share code. */
577c16f551ad suboption parser for vo and ao modules
al
parents:
diff changeset
111
577c16f551ad suboption parser for vo and ao modules
al
parents:
diff changeset
112 /* set option to true */
577c16f551ad suboption parser for vo and ao modules
al
parents:
diff changeset
113 *((int *)(opts[idx].valp)) = 1;
577c16f551ad suboption parser for vo and ao modules
al
parents:
diff changeset
114
577c16f551ad suboption parser for vo and ao modules
al
parents:
diff changeset
115 /* increment position */
577c16f551ad suboption parser for vo and ao modules
al
parents:
diff changeset
116 parse_pos += opt_len;
577c16f551ad suboption parser for vo and ao modules
al
parents:
diff changeset
117 }
577c16f551ad suboption parser for vo and ao modules
al
parents:
diff changeset
118 else
577c16f551ad suboption parser for vo and ao modules
al
parents:
diff changeset
119 {
577c16f551ad suboption parser for vo and ao modules
al
parents:
diff changeset
120 /* Type is not OPT_ARG_BOOL, means we have to parse *
577c16f551ad suboption parser for vo and ao modules
al
parents:
diff changeset
121 * for the arg delimiter character and eventually *
577c16f551ad suboption parser for vo and ao modules
al
parents:
diff changeset
122 * call a test function. */
577c16f551ad suboption parser for vo and ao modules
al
parents:
diff changeset
123 char const * last;
577c16f551ad suboption parser for vo and ao modules
al
parents:
diff changeset
124
577c16f551ad suboption parser for vo and ao modules
al
parents:
diff changeset
125 /* increment position to check for arg */
577c16f551ad suboption parser for vo and ao modules
al
parents:
diff changeset
126 parse_pos += opt_len;
577c16f551ad suboption parser for vo and ao modules
al
parents:
diff changeset
127
577c16f551ad suboption parser for vo and ao modules
al
parents:
diff changeset
128 if ( str[parse_pos] != '=' )
577c16f551ad suboption parser for vo and ao modules
al
parents:
diff changeset
129 {
577c16f551ad suboption parser for vo and ao modules
al
parents:
diff changeset
130 parse_err = 1; break;
577c16f551ad suboption parser for vo and ao modules
al
parents:
diff changeset
131 }
577c16f551ad suboption parser for vo and ao modules
al
parents:
diff changeset
132
577c16f551ad suboption parser for vo and ao modules
al
parents:
diff changeset
133 /* '=' char was there, so let's move after it */
577c16f551ad suboption parser for vo and ao modules
al
parents:
diff changeset
134 ++parse_pos;
577c16f551ad suboption parser for vo and ao modules
al
parents:
diff changeset
135
577c16f551ad suboption parser for vo and ao modules
al
parents:
diff changeset
136 switch ( opts[idx].type )
577c16f551ad suboption parser for vo and ao modules
al
parents:
diff changeset
137 {
577c16f551ad suboption parser for vo and ao modules
al
parents:
diff changeset
138 case OPT_ARG_INT:
577c16f551ad suboption parser for vo and ao modules
al
parents:
diff changeset
139 last = parse_int( &str[parse_pos],
577c16f551ad suboption parser for vo and ao modules
al
parents:
diff changeset
140 (int *)opts[idx].valp );
577c16f551ad suboption parser for vo and ao modules
al
parents:
diff changeset
141
577c16f551ad suboption parser for vo and ao modules
al
parents:
diff changeset
142 break;
577c16f551ad suboption parser for vo and ao modules
al
parents:
diff changeset
143 case OPT_ARG_STR:
577c16f551ad suboption parser for vo and ao modules
al
parents:
diff changeset
144 last = parse_str( &str[parse_pos],
577c16f551ad suboption parser for vo and ao modules
al
parents:
diff changeset
145 (strarg_t *)opts[idx].valp );
577c16f551ad suboption parser for vo and ao modules
al
parents:
diff changeset
146 break;
577c16f551ad suboption parser for vo and ao modules
al
parents:
diff changeset
147 default:
577c16f551ad suboption parser for vo and ao modules
al
parents:
diff changeset
148 assert( 0 && "Arg type of suboption doesn't exist!" );
577c16f551ad suboption parser for vo and ao modules
al
parents:
diff changeset
149 last = NULL; // break parsing!
577c16f551ad suboption parser for vo and ao modules
al
parents:
diff changeset
150 }
577c16f551ad suboption parser for vo and ao modules
al
parents:
diff changeset
151
577c16f551ad suboption parser for vo and ao modules
al
parents:
diff changeset
152 /* was the conversion succesful? */
577c16f551ad suboption parser for vo and ao modules
al
parents:
diff changeset
153 if ( !last )
577c16f551ad suboption parser for vo and ao modules
al
parents:
diff changeset
154 {
577c16f551ad suboption parser for vo and ao modules
al
parents:
diff changeset
155 parse_err = 1; break;
577c16f551ad suboption parser for vo and ao modules
al
parents:
diff changeset
156 }
577c16f551ad suboption parser for vo and ao modules
al
parents:
diff changeset
157
577c16f551ad suboption parser for vo and ao modules
al
parents:
diff changeset
158 /* make test if supplied */
577c16f551ad suboption parser for vo and ao modules
al
parents:
diff changeset
159 if ( opts[idx].test && !opts[idx].test( opts[idx].valp ) )
577c16f551ad suboption parser for vo and ao modules
al
parents:
diff changeset
160 {
577c16f551ad suboption parser for vo and ao modules
al
parents:
diff changeset
161 parse_err = 1; break;
577c16f551ad suboption parser for vo and ao modules
al
parents:
diff changeset
162 }
577c16f551ad suboption parser for vo and ao modules
al
parents:
diff changeset
163
577c16f551ad suboption parser for vo and ao modules
al
parents:
diff changeset
164 /* we succeded, set position */
577c16f551ad suboption parser for vo and ao modules
al
parents:
diff changeset
165 parse_pos = last - str;
577c16f551ad suboption parser for vo and ao modules
al
parents:
diff changeset
166 }
577c16f551ad suboption parser for vo and ao modules
al
parents:
diff changeset
167 }
577c16f551ad suboption parser for vo and ao modules
al
parents:
diff changeset
168 }
577c16f551ad suboption parser for vo and ao modules
al
parents:
diff changeset
169 else if ( substr_len == opt_len+2 )
577c16f551ad suboption parser for vo and ao modules
al
parents:
diff changeset
170 {
577c16f551ad suboption parser for vo and ao modules
al
parents:
diff changeset
171 if ( opts[idx].type == OPT_ARG_BOOL && // check for no<opt>
577c16f551ad suboption parser for vo and ao modules
al
parents:
diff changeset
172 strncmp( &str[parse_pos], "no", 2 ) == 0 &&
577c16f551ad suboption parser for vo and ao modules
al
parents:
diff changeset
173 strncmp( &str[parse_pos+2], opts[idx].name, opt_len ) == 0 )
577c16f551ad suboption parser for vo and ao modules
al
parents:
diff changeset
174 {
577c16f551ad suboption parser for vo and ao modules
al
parents:
diff changeset
175 /* option was found but negated */
577c16f551ad suboption parser for vo and ao modules
al
parents:
diff changeset
176 opts[idx].set = 1; next = 1;
577c16f551ad suboption parser for vo and ao modules
al
parents:
diff changeset
177
577c16f551ad suboption parser for vo and ao modules
al
parents:
diff changeset
178 /* set arg to false */
577c16f551ad suboption parser for vo and ao modules
al
parents:
diff changeset
179 *((int *)(opts[idx].valp)) = 0;
577c16f551ad suboption parser for vo and ao modules
al
parents:
diff changeset
180
577c16f551ad suboption parser for vo and ao modules
al
parents:
diff changeset
181 /* increment position */
577c16f551ad suboption parser for vo and ao modules
al
parents:
diff changeset
182 parse_pos += opt_len+2;
577c16f551ad suboption parser for vo and ao modules
al
parents:
diff changeset
183 }
577c16f551ad suboption parser for vo and ao modules
al
parents:
diff changeset
184 }
577c16f551ad suboption parser for vo and ao modules
al
parents:
diff changeset
185
577c16f551ad suboption parser for vo and ao modules
al
parents:
diff changeset
186 ++idx; // test against next option
577c16f551ad suboption parser for vo and ao modules
al
parents:
diff changeset
187
577c16f551ad suboption parser for vo and ao modules
al
parents:
diff changeset
188 /* break out of the loop, if this subopt is processed */
577c16f551ad suboption parser for vo and ao modules
al
parents:
diff changeset
189 if ( next ) { break; }
577c16f551ad suboption parser for vo and ao modules
al
parents:
diff changeset
190 }
577c16f551ad suboption parser for vo and ao modules
al
parents:
diff changeset
191
577c16f551ad suboption parser for vo and ao modules
al
parents:
diff changeset
192 /* if we had a valid suboption the current pos should *
577c16f551ad suboption parser for vo and ao modules
al
parents:
diff changeset
193 * equal the delimiter char, which should be ':' for *
577c16f551ad suboption parser for vo and ao modules
al
parents:
diff changeset
194 * suboptions. */
577c16f551ad suboption parser for vo and ao modules
al
parents:
diff changeset
195 if ( !parse_err && str[parse_pos] == ':' ) { ++parse_pos; }
577c16f551ad suboption parser for vo and ao modules
al
parents:
diff changeset
196 else if ( str[parse_pos] ) { parse_err = 1; }
577c16f551ad suboption parser for vo and ao modules
al
parents:
diff changeset
197 }
577c16f551ad suboption parser for vo and ao modules
al
parents:
diff changeset
198 }
577c16f551ad suboption parser for vo and ao modules
al
parents:
diff changeset
199
577c16f551ad suboption parser for vo and ao modules
al
parents:
diff changeset
200 /* if an error was encountered */
577c16f551ad suboption parser for vo and ao modules
al
parents:
diff changeset
201 if (parse_err)
577c16f551ad suboption parser for vo and ao modules
al
parents:
diff changeset
202 {
577c16f551ad suboption parser for vo and ao modules
al
parents:
diff changeset
203 unsigned int i;
577c16f551ad suboption parser for vo and ao modules
al
parents:
diff changeset
204 mp_msg( MSGT_VO, MSGL_FATAL, "Could not parse arguments at the position indicated below:\n%s\n", str );
577c16f551ad suboption parser for vo and ao modules
al
parents:
diff changeset
205 for ( i = 0; i < parse_pos; ++i )
577c16f551ad suboption parser for vo and ao modules
al
parents:
diff changeset
206 {
577c16f551ad suboption parser for vo and ao modules
al
parents:
diff changeset
207 mp_msg(MSGT_VO, MSGL_FATAL, " ");
577c16f551ad suboption parser for vo and ao modules
al
parents:
diff changeset
208 }
577c16f551ad suboption parser for vo and ao modules
al
parents:
diff changeset
209 mp_msg(MSGT_VO, MSGL_FATAL, "^\n");
577c16f551ad suboption parser for vo and ao modules
al
parents:
diff changeset
210
577c16f551ad suboption parser for vo and ao modules
al
parents:
diff changeset
211 return -1;
577c16f551ad suboption parser for vo and ao modules
al
parents:
diff changeset
212 }
577c16f551ad suboption parser for vo and ao modules
al
parents:
diff changeset
213
577c16f551ad suboption parser for vo and ao modules
al
parents:
diff changeset
214 /* we could parse everything */
577c16f551ad suboption parser for vo and ao modules
al
parents:
diff changeset
215 return 0;
577c16f551ad suboption parser for vo and ao modules
al
parents:
diff changeset
216 }
577c16f551ad suboption parser for vo and ao modules
al
parents:
diff changeset
217
577c16f551ad suboption parser for vo and ao modules
al
parents:
diff changeset
218 static char const * parse_int( char const * const str, int * const valp )
577c16f551ad suboption parser for vo and ao modules
al
parents:
diff changeset
219 {
577c16f551ad suboption parser for vo and ao modules
al
parents:
diff changeset
220 char * endp;
577c16f551ad suboption parser for vo and ao modules
al
parents:
diff changeset
221
577c16f551ad suboption parser for vo and ao modules
al
parents:
diff changeset
222 assert( str && "parse_int(): str == NULL" );
577c16f551ad suboption parser for vo and ao modules
al
parents:
diff changeset
223
577c16f551ad suboption parser for vo and ao modules
al
parents:
diff changeset
224 *valp = (int)strtol( str, &endp, 0 );
577c16f551ad suboption parser for vo and ao modules
al
parents:
diff changeset
225
577c16f551ad suboption parser for vo and ao modules
al
parents:
diff changeset
226 /* nothing was converted */
577c16f551ad suboption parser for vo and ao modules
al
parents:
diff changeset
227 if ( str == endp ) { return NULL; }
577c16f551ad suboption parser for vo and ao modules
al
parents:
diff changeset
228
577c16f551ad suboption parser for vo and ao modules
al
parents:
diff changeset
229 return endp;
577c16f551ad suboption parser for vo and ao modules
al
parents:
diff changeset
230 }
577c16f551ad suboption parser for vo and ao modules
al
parents:
diff changeset
231
577c16f551ad suboption parser for vo and ao modules
al
parents:
diff changeset
232 static char const * parse_str( char const * const str, strarg_t * const valp )
577c16f551ad suboption parser for vo and ao modules
al
parents:
diff changeset
233 {
577c16f551ad suboption parser for vo and ao modules
al
parents:
diff changeset
234 char const * match = strchr( str, ':' );
577c16f551ad suboption parser for vo and ao modules
al
parents:
diff changeset
235
577c16f551ad suboption parser for vo and ao modules
al
parents:
diff changeset
236 if ( !match )
14294
90bcd37dba7f fix string argument parsing (e.g. one char strings were not accepted)
reimar
parents: 14281
diff changeset
237 match = &str[strlen(str)];
90bcd37dba7f fix string argument parsing (e.g. one char strings were not accepted)
reimar
parents: 14281
diff changeset
238
90bcd37dba7f fix string argument parsing (e.g. one char strings were not accepted)
reimar
parents: 14281
diff changeset
239 // empty string or too long
90bcd37dba7f fix string argument parsing (e.g. one char strings were not accepted)
reimar
parents: 14281
diff changeset
240 if ((match == str) || (match - str > 255))
90bcd37dba7f fix string argument parsing (e.g. one char strings were not accepted)
reimar
parents: 14281
diff changeset
241 return NULL;
14281
577c16f551ad suboption parser for vo and ao modules
al
parents:
diff changeset
242
577c16f551ad suboption parser for vo and ao modules
al
parents:
diff changeset
243 valp->len = match - str;
577c16f551ad suboption parser for vo and ao modules
al
parents:
diff changeset
244 valp->str = str;
577c16f551ad suboption parser for vo and ao modules
al
parents:
diff changeset
245
577c16f551ad suboption parser for vo and ao modules
al
parents:
diff changeset
246 return match;
577c16f551ad suboption parser for vo and ao modules
al
parents:
diff changeset
247 }