Mercurial > mplayer.hg
annotate subopt-helper.c @ 33323:d4af28753ec8
Remove unused variables.
author | reimar |
---|---|
date | Sat, 07 May 2011 19:44:05 +0000 |
parents | b39155e98ac3 |
children | 08a90b0e44e1 |
rev | line source |
---|---|
30429
c1a3f1bbba26
Add license header to all top-level files missing them.
diego
parents:
30123
diff
changeset
|
1 /* |
c1a3f1bbba26
Add license header to all top-level files missing them.
diego
parents:
30123
diff
changeset
|
2 * This file is part of MPlayer. |
c1a3f1bbba26
Add license header to all top-level files missing them.
diego
parents:
30123
diff
changeset
|
3 * |
c1a3f1bbba26
Add license header to all top-level files missing them.
diego
parents:
30123
diff
changeset
|
4 * MPlayer is free software; you can redistribute it and/or modify |
c1a3f1bbba26
Add license header to all top-level files missing them.
diego
parents:
30123
diff
changeset
|
5 * it under the terms of the GNU General Public License as published by |
c1a3f1bbba26
Add license header to all top-level files missing them.
diego
parents:
30123
diff
changeset
|
6 * the Free Software Foundation; either version 2 of the License, or |
c1a3f1bbba26
Add license header to all top-level files missing them.
diego
parents:
30123
diff
changeset
|
7 * (at your option) any later version. |
c1a3f1bbba26
Add license header to all top-level files missing them.
diego
parents:
30123
diff
changeset
|
8 * |
c1a3f1bbba26
Add license header to all top-level files missing them.
diego
parents:
30123
diff
changeset
|
9 * MPlayer is distributed in the hope that it will be useful, |
c1a3f1bbba26
Add license header to all top-level files missing them.
diego
parents:
30123
diff
changeset
|
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of |
c1a3f1bbba26
Add license header to all top-level files missing them.
diego
parents:
30123
diff
changeset
|
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
c1a3f1bbba26
Add license header to all top-level files missing them.
diego
parents:
30123
diff
changeset
|
12 * GNU General Public License for more details. |
c1a3f1bbba26
Add license header to all top-level files missing them.
diego
parents:
30123
diff
changeset
|
13 * |
c1a3f1bbba26
Add license header to all top-level files missing them.
diego
parents:
30123
diff
changeset
|
14 * You should have received a copy of the GNU General Public License along |
c1a3f1bbba26
Add license header to all top-level files missing them.
diego
parents:
30123
diff
changeset
|
15 * with MPlayer; if not, write to the Free Software Foundation, Inc., |
c1a3f1bbba26
Add license header to all top-level files missing them.
diego
parents:
30123
diff
changeset
|
16 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. |
c1a3f1bbba26
Add license header to all top-level files missing them.
diego
parents:
30123
diff
changeset
|
17 */ |
c1a3f1bbba26
Add license header to all top-level files missing them.
diego
parents:
30123
diff
changeset
|
18 |
29252 | 19 /** |
14281 | 20 * \file subopt-helper.c |
21 * | |
22 * \brief Compensates the suboption parsing code duplication a bit. | |
23 * | |
24 * The routines defined below are there to help you with the | |
25 * suboption parsing. Meaning extracting the options and their | |
26 * values for you and also outputting generic help message if | |
27 * a parse error is encountered. | |
28 * | |
29 * Most stuff happens in the subopt_parse function: if you call it | |
30 * it parses for the passed opts in the passed string. It calls some | |
31 * extra functions for explicit argument parsing ( where the option | |
32 * itself isn't the argument but a value given after the argument | |
33 * delimiter ('='). It also calls your test function if you supplied | |
34 * one. | |
35 * | |
36 */ | |
37 | |
38 #include "subopt-helper.h" | |
39 #include "mp_msg.h" | |
40 | |
41 #include <stdlib.h> | |
42 #include <string.h> | |
14538
00c3c4111017
New suboption type: malloc'ed, zero terminated string
reimar
parents:
14294
diff
changeset
|
43 #include <limits.h> |
14281 | 44 #include <assert.h> |
45 | |
46 #ifndef MPDEBUG | |
47 #define NDEBUG | |
48 #endif | |
49 | |
32335
fdf3f93c2828
Move some code around to avoid forward declarations in top-level .c files.
diego
parents:
30633
diff
changeset
|
50 |
fdf3f93c2828
Move some code around to avoid forward declarations in top-level .c files.
diego
parents:
30633
diff
changeset
|
51 static char const * parse_int( char const * const str, int * const valp ) |
fdf3f93c2828
Move some code around to avoid forward declarations in top-level .c files.
diego
parents:
30633
diff
changeset
|
52 { |
fdf3f93c2828
Move some code around to avoid forward declarations in top-level .c files.
diego
parents:
30633
diff
changeset
|
53 char * endp; |
fdf3f93c2828
Move some code around to avoid forward declarations in top-level .c files.
diego
parents:
30633
diff
changeset
|
54 |
fdf3f93c2828
Move some code around to avoid forward declarations in top-level .c files.
diego
parents:
30633
diff
changeset
|
55 assert( str && "parse_int(): str == NULL" ); |
fdf3f93c2828
Move some code around to avoid forward declarations in top-level .c files.
diego
parents:
30633
diff
changeset
|
56 |
fdf3f93c2828
Move some code around to avoid forward declarations in top-level .c files.
diego
parents:
30633
diff
changeset
|
57 *valp = (int)strtol( str, &endp, 0 ); |
fdf3f93c2828
Move some code around to avoid forward declarations in top-level .c files.
diego
parents:
30633
diff
changeset
|
58 |
fdf3f93c2828
Move some code around to avoid forward declarations in top-level .c files.
diego
parents:
30633
diff
changeset
|
59 /* nothing was converted */ |
fdf3f93c2828
Move some code around to avoid forward declarations in top-level .c files.
diego
parents:
30633
diff
changeset
|
60 if ( str == endp ) { return NULL; } |
fdf3f93c2828
Move some code around to avoid forward declarations in top-level .c files.
diego
parents:
30633
diff
changeset
|
61 |
fdf3f93c2828
Move some code around to avoid forward declarations in top-level .c files.
diego
parents:
30633
diff
changeset
|
62 return endp; |
fdf3f93c2828
Move some code around to avoid forward declarations in top-level .c files.
diego
parents:
30633
diff
changeset
|
63 } |
fdf3f93c2828
Move some code around to avoid forward declarations in top-level .c files.
diego
parents:
30633
diff
changeset
|
64 |
fdf3f93c2828
Move some code around to avoid forward declarations in top-level .c files.
diego
parents:
30633
diff
changeset
|
65 static char const * parse_float( char const * const str, float * const valp ) |
fdf3f93c2828
Move some code around to avoid forward declarations in top-level .c files.
diego
parents:
30633
diff
changeset
|
66 { |
fdf3f93c2828
Move some code around to avoid forward declarations in top-level .c files.
diego
parents:
30633
diff
changeset
|
67 char * endp; |
fdf3f93c2828
Move some code around to avoid forward declarations in top-level .c files.
diego
parents:
30633
diff
changeset
|
68 |
fdf3f93c2828
Move some code around to avoid forward declarations in top-level .c files.
diego
parents:
30633
diff
changeset
|
69 assert( str && "parse_float(): str == NULL" ); |
fdf3f93c2828
Move some code around to avoid forward declarations in top-level .c files.
diego
parents:
30633
diff
changeset
|
70 |
fdf3f93c2828
Move some code around to avoid forward declarations in top-level .c files.
diego
parents:
30633
diff
changeset
|
71 *valp = strtod( str, &endp ); |
fdf3f93c2828
Move some code around to avoid forward declarations in top-level .c files.
diego
parents:
30633
diff
changeset
|
72 |
fdf3f93c2828
Move some code around to avoid forward declarations in top-level .c files.
diego
parents:
30633
diff
changeset
|
73 /* nothing was converted */ |
fdf3f93c2828
Move some code around to avoid forward declarations in top-level .c files.
diego
parents:
30633
diff
changeset
|
74 if ( str == endp ) { return NULL; } |
fdf3f93c2828
Move some code around to avoid forward declarations in top-level .c files.
diego
parents:
30633
diff
changeset
|
75 |
fdf3f93c2828
Move some code around to avoid forward declarations in top-level .c files.
diego
parents:
30633
diff
changeset
|
76 return endp; |
fdf3f93c2828
Move some code around to avoid forward declarations in top-level .c files.
diego
parents:
30633
diff
changeset
|
77 } |
fdf3f93c2828
Move some code around to avoid forward declarations in top-level .c files.
diego
parents:
30633
diff
changeset
|
78 |
fdf3f93c2828
Move some code around to avoid forward declarations in top-level .c files.
diego
parents:
30633
diff
changeset
|
79 #define QUOTE_CHAR '%' |
fdf3f93c2828
Move some code around to avoid forward declarations in top-level .c files.
diego
parents:
30633
diff
changeset
|
80 static char const * parse_str( char const * str, strarg_t * const valp ) |
fdf3f93c2828
Move some code around to avoid forward declarations in top-level .c files.
diego
parents:
30633
diff
changeset
|
81 { |
fdf3f93c2828
Move some code around to avoid forward declarations in top-level .c files.
diego
parents:
30633
diff
changeset
|
82 char const * match = strchr( str, ':' ); |
fdf3f93c2828
Move some code around to avoid forward declarations in top-level .c files.
diego
parents:
30633
diff
changeset
|
83 |
fdf3f93c2828
Move some code around to avoid forward declarations in top-level .c files.
diego
parents:
30633
diff
changeset
|
84 if (str[0] == QUOTE_CHAR) { |
fdf3f93c2828
Move some code around to avoid forward declarations in top-level .c files.
diego
parents:
30633
diff
changeset
|
85 int len = 0; |
fdf3f93c2828
Move some code around to avoid forward declarations in top-level .c files.
diego
parents:
30633
diff
changeset
|
86 str = &str[1]; |
fdf3f93c2828
Move some code around to avoid forward declarations in top-level .c files.
diego
parents:
30633
diff
changeset
|
87 len = (int)strtol(str, (char **)&str, 0); |
fdf3f93c2828
Move some code around to avoid forward declarations in top-level .c files.
diego
parents:
30633
diff
changeset
|
88 if (!str || str[0] != QUOTE_CHAR || (len > strlen(str) - 1)) |
fdf3f93c2828
Move some code around to avoid forward declarations in top-level .c files.
diego
parents:
30633
diff
changeset
|
89 return NULL; |
fdf3f93c2828
Move some code around to avoid forward declarations in top-level .c files.
diego
parents:
30633
diff
changeset
|
90 str = &str[1]; |
fdf3f93c2828
Move some code around to avoid forward declarations in top-level .c files.
diego
parents:
30633
diff
changeset
|
91 match = &str[len]; |
fdf3f93c2828
Move some code around to avoid forward declarations in top-level .c files.
diego
parents:
30633
diff
changeset
|
92 } |
fdf3f93c2828
Move some code around to avoid forward declarations in top-level .c files.
diego
parents:
30633
diff
changeset
|
93 else |
fdf3f93c2828
Move some code around to avoid forward declarations in top-level .c files.
diego
parents:
30633
diff
changeset
|
94 if (str[0] == '"') { |
fdf3f93c2828
Move some code around to avoid forward declarations in top-level .c files.
diego
parents:
30633
diff
changeset
|
95 str = &str[1]; |
fdf3f93c2828
Move some code around to avoid forward declarations in top-level .c files.
diego
parents:
30633
diff
changeset
|
96 match = strchr(str, '"'); |
fdf3f93c2828
Move some code around to avoid forward declarations in top-level .c files.
diego
parents:
30633
diff
changeset
|
97 if (!match) |
fdf3f93c2828
Move some code around to avoid forward declarations in top-level .c files.
diego
parents:
30633
diff
changeset
|
98 return NULL; |
fdf3f93c2828
Move some code around to avoid forward declarations in top-level .c files.
diego
parents:
30633
diff
changeset
|
99 valp->len = match - str; |
fdf3f93c2828
Move some code around to avoid forward declarations in top-level .c files.
diego
parents:
30633
diff
changeset
|
100 valp->str = str; |
fdf3f93c2828
Move some code around to avoid forward declarations in top-level .c files.
diego
parents:
30633
diff
changeset
|
101 return &match[1]; |
fdf3f93c2828
Move some code around to avoid forward declarations in top-level .c files.
diego
parents:
30633
diff
changeset
|
102 } |
fdf3f93c2828
Move some code around to avoid forward declarations in top-level .c files.
diego
parents:
30633
diff
changeset
|
103 if ( !match ) |
fdf3f93c2828
Move some code around to avoid forward declarations in top-level .c files.
diego
parents:
30633
diff
changeset
|
104 match = &str[strlen(str)]; |
fdf3f93c2828
Move some code around to avoid forward declarations in top-level .c files.
diego
parents:
30633
diff
changeset
|
105 |
fdf3f93c2828
Move some code around to avoid forward declarations in top-level .c files.
diego
parents:
30633
diff
changeset
|
106 // empty string or too long |
fdf3f93c2828
Move some code around to avoid forward declarations in top-level .c files.
diego
parents:
30633
diff
changeset
|
107 if ((match == str) || (match - str > INT_MAX)) |
fdf3f93c2828
Move some code around to avoid forward declarations in top-level .c files.
diego
parents:
30633
diff
changeset
|
108 return NULL; |
fdf3f93c2828
Move some code around to avoid forward declarations in top-level .c files.
diego
parents:
30633
diff
changeset
|
109 |
fdf3f93c2828
Move some code around to avoid forward declarations in top-level .c files.
diego
parents:
30633
diff
changeset
|
110 valp->len = match - str; |
fdf3f93c2828
Move some code around to avoid forward declarations in top-level .c files.
diego
parents:
30633
diff
changeset
|
111 valp->str = str; |
fdf3f93c2828
Move some code around to avoid forward declarations in top-level .c files.
diego
parents:
30633
diff
changeset
|
112 |
fdf3f93c2828
Move some code around to avoid forward declarations in top-level .c files.
diego
parents:
30633
diff
changeset
|
113 return match; |
fdf3f93c2828
Move some code around to avoid forward declarations in top-level .c files.
diego
parents:
30633
diff
changeset
|
114 } |
fdf3f93c2828
Move some code around to avoid forward declarations in top-level .c files.
diego
parents:
30633
diff
changeset
|
115 |
14281 | 116 |
117 /** | |
118 * \brief Try to parse all options in str and fail if it was not possible. | |
119 * | |
120 * \param str Pointer to the zero terminated string to be parsed. | |
121 * \param opts Pointer to a options array. The array must be terminated | |
122 * with an element having set name to NULL in its opt_t structure. | |
123 * | |
124 * \return The return value is zero if the string could be parsed | |
125 * else a non-zero value is returned. | |
126 * | |
127 */ | |
28827
2b021e3e1000
Get rid of the "set" member of the subopt-parser struct, it made
reimar
parents:
22283
diff
changeset
|
128 int subopt_parse( char const * const str, const opt_t * opts ) |
14281 | 129 { |
130 int parse_err = 0, idx; | |
131 unsigned int parse_pos = 0; | |
132 | |
133 if ( str ) | |
134 { | |
135 while ( str[parse_pos] && !parse_err ) | |
136 { | |
137 int next = 0; | |
138 | |
139 idx = 0; // reset index for the below loop | |
140 while ( opts[idx].name ) | |
141 { | |
142 int opt_len; | |
143 int substr_len; | |
144 | |
145 // get length of the option we test against */ | |
146 opt_len = strlen( opts[idx].name ); | |
147 | |
148 // get length of the current substring of str */ | |
149 { | |
150 char * delim, * arg_delim; | |
151 | |
29252 | 152 /* search nearest delimiter ( option or argument delimiter ) */ |
14281 | 153 delim = strchr( &str[parse_pos], ':' ); |
154 arg_delim = strchr( &str[parse_pos], '=' ); | |
155 | |
156 if ( ( delim && arg_delim && delim > arg_delim ) || | |
157 delim == NULL ) | |
158 { | |
159 delim = strchr( &str[parse_pos], '=' ); | |
160 } | |
29252 | 161 |
14281 | 162 substr_len = delim ? // is a delim present |
163 delim - &str[parse_pos] : // yes | |
164 strlen( &str[parse_pos] ); // no, end of string | |
165 } | |
166 | |
167 //printf( "substr_len=%d, opt_len=%d\n", substr_len, opt_len ); | |
168 | |
169 /* Check if the length of the current option matches the * | |
170 * length of the option we want to test again. */ | |
171 if ( substr_len == opt_len ) | |
172 { | |
173 /* check if option was activated/deactivated */ | |
174 if( strncmp( &str[parse_pos], opts[idx].name, opt_len ) == 0 ) | |
175 { | |
176 /* option was found */ | |
28827
2b021e3e1000
Get rid of the "set" member of the subopt-parser struct, it made
reimar
parents:
22283
diff
changeset
|
177 next = 1; |
14281 | 178 |
179 assert( opts[idx].valp && "Need a pointer to store the arg!" ); | |
180 | |
181 /* type specific code */ | |
182 if ( opts[idx].type == OPT_ARG_BOOL ) | |
183 { | |
22283
bc9e95184521
cosmetics: Fix some common typos, sepErate --> sepArate, deciSSion --> deciSion.
diego
parents:
19104
diff
changeset
|
184 /* Handle OPT_ARG_BOOL separately so * |
14281 | 185 * the others can share code. */ |
186 | |
187 /* set option to true */ | |
188 *((int *)(opts[idx].valp)) = 1; | |
189 | |
190 /* increment position */ | |
191 parse_pos += opt_len; | |
192 } | |
193 else | |
194 { | |
195 /* Type is not OPT_ARG_BOOL, means we have to parse * | |
196 * for the arg delimiter character and eventually * | |
197 * call a test function. */ | |
198 char const * last; | |
199 | |
200 /* increment position to check for arg */ | |
201 parse_pos += opt_len; | |
202 | |
203 if ( str[parse_pos] != '=' ) | |
204 { | |
205 parse_err = 1; break; | |
206 } | |
207 | |
208 /* '=' char was there, so let's move after it */ | |
209 ++parse_pos; | |
210 | |
211 switch ( opts[idx].type ) | |
212 { | |
213 case OPT_ARG_INT: | |
214 last = parse_int( &str[parse_pos], | |
215 (int *)opts[idx].valp ); | |
216 | |
217 break; | |
218 case OPT_ARG_STR: | |
219 last = parse_str( &str[parse_pos], | |
220 (strarg_t *)opts[idx].valp ); | |
221 break; | |
14538
00c3c4111017
New suboption type: malloc'ed, zero terminated string
reimar
parents:
14294
diff
changeset
|
222 case OPT_ARG_MSTRZ: |
00c3c4111017
New suboption type: malloc'ed, zero terminated string
reimar
parents:
14294
diff
changeset
|
223 { |
00c3c4111017
New suboption type: malloc'ed, zero terminated string
reimar
parents:
14294
diff
changeset
|
224 char **valp = opts[idx].valp; |
00c3c4111017
New suboption type: malloc'ed, zero terminated string
reimar
parents:
14294
diff
changeset
|
225 strarg_t tmp; |
00c3c4111017
New suboption type: malloc'ed, zero terminated string
reimar
parents:
14294
diff
changeset
|
226 tmp.str = NULL; |
00c3c4111017
New suboption type: malloc'ed, zero terminated string
reimar
parents:
14294
diff
changeset
|
227 tmp.len = 0; |
00c3c4111017
New suboption type: malloc'ed, zero terminated string
reimar
parents:
14294
diff
changeset
|
228 last = parse_str( &str[parse_pos], &tmp ); |
32511
b39155e98ac3
Remove some useless NULL pointer checks before invoking free() on the pointer.
diego
parents:
32335
diff
changeset
|
229 free(*valp); |
14538
00c3c4111017
New suboption type: malloc'ed, zero terminated string
reimar
parents:
14294
diff
changeset
|
230 *valp = NULL; |
00c3c4111017
New suboption type: malloc'ed, zero terminated string
reimar
parents:
14294
diff
changeset
|
231 if (tmp.str && tmp.len > 0) { |
00c3c4111017
New suboption type: malloc'ed, zero terminated string
reimar
parents:
14294
diff
changeset
|
232 *valp = malloc(tmp.len + 1); |
00c3c4111017
New suboption type: malloc'ed, zero terminated string
reimar
parents:
14294
diff
changeset
|
233 memcpy(*valp, tmp.str, tmp.len); |
14572 | 234 (*valp)[tmp.len] = 0; |
14538
00c3c4111017
New suboption type: malloc'ed, zero terminated string
reimar
parents:
14294
diff
changeset
|
235 } |
00c3c4111017
New suboption type: malloc'ed, zero terminated string
reimar
parents:
14294
diff
changeset
|
236 break; |
00c3c4111017
New suboption type: malloc'ed, zero terminated string
reimar
parents:
14294
diff
changeset
|
237 } |
16720 | 238 case OPT_ARG_FLOAT: |
239 last = parse_float( &str[parse_pos], | |
240 (float *)opts[idx].valp ); | |
241 break; | |
14281 | 242 default: |
243 assert( 0 && "Arg type of suboption doesn't exist!" ); | |
244 last = NULL; // break parsing! | |
245 } | |
246 | |
247 /* was the conversion succesful? */ | |
248 if ( !last ) | |
249 { | |
250 parse_err = 1; break; | |
251 } | |
252 | |
253 /* make test if supplied */ | |
254 if ( opts[idx].test && !opts[idx].test( opts[idx].valp ) ) | |
255 { | |
256 parse_err = 1; break; | |
257 } | |
258 | |
259 /* we succeded, set position */ | |
260 parse_pos = last - str; | |
261 } | |
262 } | |
263 } | |
264 else if ( substr_len == opt_len+2 ) | |
265 { | |
266 if ( opts[idx].type == OPT_ARG_BOOL && // check for no<opt> | |
267 strncmp( &str[parse_pos], "no", 2 ) == 0 && | |
268 strncmp( &str[parse_pos+2], opts[idx].name, opt_len ) == 0 ) | |
269 { | |
270 /* option was found but negated */ | |
28827
2b021e3e1000
Get rid of the "set" member of the subopt-parser struct, it made
reimar
parents:
22283
diff
changeset
|
271 next = 1; |
14281 | 272 |
273 /* set arg to false */ | |
274 *((int *)(opts[idx].valp)) = 0; | |
275 | |
276 /* increment position */ | |
277 parse_pos += opt_len+2; | |
278 } | |
279 } | |
280 | |
281 ++idx; // test against next option | |
282 | |
283 /* break out of the loop, if this subopt is processed */ | |
284 if ( next ) { break; } | |
285 } | |
29252 | 286 |
14281 | 287 /* if we had a valid suboption the current pos should * |
288 * equal the delimiter char, which should be ':' for * | |
289 * suboptions. */ | |
290 if ( !parse_err && str[parse_pos] == ':' ) { ++parse_pos; } | |
291 else if ( str[parse_pos] ) { parse_err = 1; } | |
292 } | |
293 } | |
294 | |
295 /* if an error was encountered */ | |
296 if (parse_err) | |
297 { | |
298 unsigned int i; | |
299 mp_msg( MSGT_VO, MSGL_FATAL, "Could not parse arguments at the position indicated below:\n%s\n", str ); | |
300 for ( i = 0; i < parse_pos; ++i ) | |
301 { | |
302 mp_msg(MSGT_VO, MSGL_FATAL, " "); | |
303 } | |
304 mp_msg(MSGT_VO, MSGL_FATAL, "^\n"); | |
305 | |
306 return -1; | |
307 } | |
308 | |
309 /* we could parse everything */ | |
310 return 0; | |
311 } | |
312 | |
14736 | 313 |
314 /*** common test functions ***/ | |
315 | |
316 /** \brief Test if i is not negative */ | |
30122
1772a5171ac7
Fix function declarations to avoid casting function pointers.
reimar
parents:
29252
diff
changeset
|
317 int int_non_neg(void *iptr) |
14736 | 318 { |
30122
1772a5171ac7
Fix function declarations to avoid casting function pointers.
reimar
parents:
29252
diff
changeset
|
319 int *i = iptr; |
30123
0f5f75b4a015
Simplify range-checking functions for subopt parsing.
reimar
parents:
30122
diff
changeset
|
320 return *i >= 0; |
14736 | 321 } |
322 /** \brief Test if i is positive. */ | |
30122
1772a5171ac7
Fix function declarations to avoid casting function pointers.
reimar
parents:
29252
diff
changeset
|
323 int int_pos(void *iptr) |
14736 | 324 { |
30122
1772a5171ac7
Fix function declarations to avoid casting function pointers.
reimar
parents:
29252
diff
changeset
|
325 int *i = iptr; |
30123
0f5f75b4a015
Simplify range-checking functions for subopt parsing.
reimar
parents:
30122
diff
changeset
|
326 return *i > 0; |
14736 | 327 } |
15734
7e4fa8fc255c
helper functions for comparing strarg_t "strings".
reimar
parents:
15733
diff
changeset
|
328 |
7e4fa8fc255c
helper functions for comparing strarg_t "strings".
reimar
parents:
15733
diff
changeset
|
329 /*** little helpers */ |
7e4fa8fc255c
helper functions for comparing strarg_t "strings".
reimar
parents:
15733
diff
changeset
|
330 |
7e4fa8fc255c
helper functions for comparing strarg_t "strings".
reimar
parents:
15733
diff
changeset
|
331 /** \brief compare the stings just as strcmp does */ |
19104
2ec2301183cd
marks several read-only string parameters which aren't modified inside the called function as const. Patch by Stefan Huehner, stefan AT huehner-org
reynaldo
parents:
16725
diff
changeset
|
332 int strargcmp(strarg_t *arg, const char *str) { |
15734
7e4fa8fc255c
helper functions for comparing strarg_t "strings".
reimar
parents:
15733
diff
changeset
|
333 int res = strncmp(arg->str, str, arg->len); |
7e4fa8fc255c
helper functions for comparing strarg_t "strings".
reimar
parents:
15733
diff
changeset
|
334 if (!res && arg->len != strlen(str)) |
7e4fa8fc255c
helper functions for comparing strarg_t "strings".
reimar
parents:
15733
diff
changeset
|
335 res = arg->len - strlen(str); |
7e4fa8fc255c
helper functions for comparing strarg_t "strings".
reimar
parents:
15733
diff
changeset
|
336 return res; |
7e4fa8fc255c
helper functions for comparing strarg_t "strings".
reimar
parents:
15733
diff
changeset
|
337 } |
7e4fa8fc255c
helper functions for comparing strarg_t "strings".
reimar
parents:
15733
diff
changeset
|
338 |
7e4fa8fc255c
helper functions for comparing strarg_t "strings".
reimar
parents:
15733
diff
changeset
|
339 /** \brief compare the stings just as strcasecmp does */ |
7e4fa8fc255c
helper functions for comparing strarg_t "strings".
reimar
parents:
15733
diff
changeset
|
340 int strargcasecmp(strarg_t *arg, char *str) { |
7e4fa8fc255c
helper functions for comparing strarg_t "strings".
reimar
parents:
15733
diff
changeset
|
341 int res = strncasecmp(arg->str, str, arg->len); |
7e4fa8fc255c
helper functions for comparing strarg_t "strings".
reimar
parents:
15733
diff
changeset
|
342 if (!res && arg->len != strlen(str)) |
7e4fa8fc255c
helper functions for comparing strarg_t "strings".
reimar
parents:
15733
diff
changeset
|
343 res = arg->len - strlen(str); |
7e4fa8fc255c
helper functions for comparing strarg_t "strings".
reimar
parents:
15733
diff
changeset
|
344 return res; |
7e4fa8fc255c
helper functions for comparing strarg_t "strings".
reimar
parents:
15733
diff
changeset
|
345 } |