Mercurial > mplayer.hg
annotate subopt-helper.c @ 36963:e539d330c7be
Remove unnecessary bounds checks in Win32 GUI.
The checks that the rendered potmeter button
doesn't exceed the bounds is not necessary as
the item value is already limited within the
range of 0 to 100.
Patch by Hans-Dieter Kosch, hdkosch kabelbw de.
author | ib |
---|---|
date | Mon, 24 Mar 2014 12:52:01 +0000 |
parents | 389d43c448b3 |
children |
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 /** |
33882 | 20 * \file |
14281 | 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> | |
35903 | 43 #include <strings.h> |
14538
00c3c4111017
New suboption type: malloc'ed, zero terminated string
reimar
parents:
14294
diff
changeset
|
44 #include <limits.h> |
14281 | 45 #include <assert.h> |
46 | |
47 #ifndef MPDEBUG | |
48 #define NDEBUG | |
49 #endif | |
50 | |
32335
fdf3f93c2828
Move some code around to avoid forward declarations in top-level .c files.
diego
parents:
30633
diff
changeset
|
51 |
fdf3f93c2828
Move some code around to avoid forward declarations in top-level .c files.
diego
parents:
30633
diff
changeset
|
52 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
|
53 { |
fdf3f93c2828
Move some code around to avoid forward declarations in top-level .c files.
diego
parents:
30633
diff
changeset
|
54 char * endp; |
fdf3f93c2828
Move some code around to avoid forward declarations in top-level .c files.
diego
parents:
30633
diff
changeset
|
55 |
fdf3f93c2828
Move some code around to avoid forward declarations in top-level .c files.
diego
parents:
30633
diff
changeset
|
56 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
|
57 |
fdf3f93c2828
Move some code around to avoid forward declarations in top-level .c files.
diego
parents:
30633
diff
changeset
|
58 *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
|
59 |
fdf3f93c2828
Move some code around to avoid forward declarations in top-level .c files.
diego
parents:
30633
diff
changeset
|
60 /* nothing was converted */ |
fdf3f93c2828
Move some code around to avoid forward declarations in top-level .c files.
diego
parents:
30633
diff
changeset
|
61 if ( str == endp ) { return NULL; } |
fdf3f93c2828
Move some code around to avoid forward declarations in top-level .c files.
diego
parents:
30633
diff
changeset
|
62 |
fdf3f93c2828
Move some code around to avoid forward declarations in top-level .c files.
diego
parents:
30633
diff
changeset
|
63 return endp; |
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 |
fdf3f93c2828
Move some code around to avoid forward declarations in top-level .c files.
diego
parents:
30633
diff
changeset
|
66 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
|
67 { |
fdf3f93c2828
Move some code around to avoid forward declarations in top-level .c files.
diego
parents:
30633
diff
changeset
|
68 char * endp; |
fdf3f93c2828
Move some code around to avoid forward declarations in top-level .c files.
diego
parents:
30633
diff
changeset
|
69 |
fdf3f93c2828
Move some code around to avoid forward declarations in top-level .c files.
diego
parents:
30633
diff
changeset
|
70 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
|
71 |
fdf3f93c2828
Move some code around to avoid forward declarations in top-level .c files.
diego
parents:
30633
diff
changeset
|
72 *valp = strtod( str, &endp ); |
fdf3f93c2828
Move some code around to avoid forward declarations in top-level .c files.
diego
parents:
30633
diff
changeset
|
73 |
fdf3f93c2828
Move some code around to avoid forward declarations in top-level .c files.
diego
parents:
30633
diff
changeset
|
74 /* nothing was converted */ |
fdf3f93c2828
Move some code around to avoid forward declarations in top-level .c files.
diego
parents:
30633
diff
changeset
|
75 if ( str == endp ) { return NULL; } |
fdf3f93c2828
Move some code around to avoid forward declarations in top-level .c files.
diego
parents:
30633
diff
changeset
|
76 |
fdf3f93c2828
Move some code around to avoid forward declarations in top-level .c files.
diego
parents:
30633
diff
changeset
|
77 return endp; |
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 |
fdf3f93c2828
Move some code around to avoid forward declarations in top-level .c files.
diego
parents:
30633
diff
changeset
|
80 #define QUOTE_CHAR '%' |
fdf3f93c2828
Move some code around to avoid forward declarations in top-level .c files.
diego
parents:
30633
diff
changeset
|
81 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
|
82 { |
fdf3f93c2828
Move some code around to avoid forward declarations in top-level .c files.
diego
parents:
30633
diff
changeset
|
83 char const * match = strchr( str, ':' ); |
fdf3f93c2828
Move some code around to avoid forward declarations in top-level .c files.
diego
parents:
30633
diff
changeset
|
84 |
fdf3f93c2828
Move some code around to avoid forward declarations in top-level .c files.
diego
parents:
30633
diff
changeset
|
85 if (str[0] == QUOTE_CHAR) { |
fdf3f93c2828
Move some code around to avoid forward declarations in top-level .c files.
diego
parents:
30633
diff
changeset
|
86 int len = 0; |
fdf3f93c2828
Move some code around to avoid forward declarations in top-level .c files.
diego
parents:
30633
diff
changeset
|
87 str = &str[1]; |
fdf3f93c2828
Move some code around to avoid forward declarations in top-level .c files.
diego
parents:
30633
diff
changeset
|
88 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
|
89 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
|
90 return NULL; |
fdf3f93c2828
Move some code around to avoid forward declarations in top-level .c files.
diego
parents:
30633
diff
changeset
|
91 str = &str[1]; |
fdf3f93c2828
Move some code around to avoid forward declarations in top-level .c files.
diego
parents:
30633
diff
changeset
|
92 match = &str[len]; |
fdf3f93c2828
Move some code around to avoid forward declarations in top-level .c files.
diego
parents:
30633
diff
changeset
|
93 } |
fdf3f93c2828
Move some code around to avoid forward declarations in top-level .c files.
diego
parents:
30633
diff
changeset
|
94 else |
fdf3f93c2828
Move some code around to avoid forward declarations in top-level .c files.
diego
parents:
30633
diff
changeset
|
95 if (str[0] == '"') { |
fdf3f93c2828
Move some code around to avoid forward declarations in top-level .c files.
diego
parents:
30633
diff
changeset
|
96 str = &str[1]; |
fdf3f93c2828
Move some code around to avoid forward declarations in top-level .c files.
diego
parents:
30633
diff
changeset
|
97 match = strchr(str, '"'); |
fdf3f93c2828
Move some code around to avoid forward declarations in top-level .c files.
diego
parents:
30633
diff
changeset
|
98 if (!match) |
fdf3f93c2828
Move some code around to avoid forward declarations in top-level .c files.
diego
parents:
30633
diff
changeset
|
99 return NULL; |
fdf3f93c2828
Move some code around to avoid forward declarations in top-level .c files.
diego
parents:
30633
diff
changeset
|
100 valp->len = match - str; |
fdf3f93c2828
Move some code around to avoid forward declarations in top-level .c files.
diego
parents:
30633
diff
changeset
|
101 valp->str = str; |
fdf3f93c2828
Move some code around to avoid forward declarations in top-level .c files.
diego
parents:
30633
diff
changeset
|
102 return &match[1]; |
fdf3f93c2828
Move some code around to avoid forward declarations in top-level .c files.
diego
parents:
30633
diff
changeset
|
103 } |
fdf3f93c2828
Move some code around to avoid forward declarations in top-level .c files.
diego
parents:
30633
diff
changeset
|
104 if ( !match ) |
fdf3f93c2828
Move some code around to avoid forward declarations in top-level .c files.
diego
parents:
30633
diff
changeset
|
105 match = &str[strlen(str)]; |
fdf3f93c2828
Move some code around to avoid forward declarations in top-level .c files.
diego
parents:
30633
diff
changeset
|
106 |
fdf3f93c2828
Move some code around to avoid forward declarations in top-level .c files.
diego
parents:
30633
diff
changeset
|
107 // empty string or too long |
fdf3f93c2828
Move some code around to avoid forward declarations in top-level .c files.
diego
parents:
30633
diff
changeset
|
108 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
|
109 return NULL; |
fdf3f93c2828
Move some code around to avoid forward declarations in top-level .c files.
diego
parents:
30633
diff
changeset
|
110 |
fdf3f93c2828
Move some code around to avoid forward declarations in top-level .c files.
diego
parents:
30633
diff
changeset
|
111 valp->len = match - str; |
fdf3f93c2828
Move some code around to avoid forward declarations in top-level .c files.
diego
parents:
30633
diff
changeset
|
112 valp->str = str; |
fdf3f93c2828
Move some code around to avoid forward declarations in top-level .c files.
diego
parents:
30633
diff
changeset
|
113 |
fdf3f93c2828
Move some code around to avoid forward declarations in top-level .c files.
diego
parents:
30633
diff
changeset
|
114 return match; |
fdf3f93c2828
Move some code around to avoid forward declarations in top-level .c files.
diego
parents:
30633
diff
changeset
|
115 } |
fdf3f93c2828
Move some code around to avoid forward declarations in top-level .c files.
diego
parents:
30633
diff
changeset
|
116 |
14281 | 117 |
118 /** | |
119 * \brief Try to parse all options in str and fail if it was not possible. | |
120 * | |
121 * \param str Pointer to the zero terminated string to be parsed. | |
122 * \param opts Pointer to a options array. The array must be terminated | |
123 * with an element having set name to NULL in its opt_t structure. | |
124 * | |
125 * \return The return value is zero if the string could be parsed | |
126 * else a non-zero value is returned. | |
127 * | |
128 */ | |
28827
2b021e3e1000
Get rid of the "set" member of the subopt-parser struct, it made
reimar
parents:
22283
diff
changeset
|
129 int subopt_parse( char const * const str, const opt_t * opts ) |
14281 | 130 { |
131 int parse_err = 0, idx; | |
132 unsigned int parse_pos = 0; | |
133 | |
134 if ( str ) | |
135 { | |
136 while ( str[parse_pos] && !parse_err ) | |
137 { | |
138 int next = 0; | |
139 | |
140 idx = 0; // reset index for the below loop | |
141 while ( opts[idx].name ) | |
142 { | |
143 int opt_len; | |
144 int substr_len; | |
145 | |
146 // get length of the option we test against */ | |
147 opt_len = strlen( opts[idx].name ); | |
148 | |
149 // get length of the current substring of str */ | |
150 { | |
151 char * delim, * arg_delim; | |
152 | |
29252 | 153 /* search nearest delimiter ( option or argument delimiter ) */ |
14281 | 154 delim = strchr( &str[parse_pos], ':' ); |
155 arg_delim = strchr( &str[parse_pos], '=' ); | |
156 | |
157 if ( ( delim && arg_delim && delim > arg_delim ) || | |
158 delim == NULL ) | |
159 { | |
160 delim = strchr( &str[parse_pos], '=' ); | |
161 } | |
29252 | 162 |
14281 | 163 substr_len = delim ? // is a delim present |
164 delim - &str[parse_pos] : // yes | |
165 strlen( &str[parse_pos] ); // no, end of string | |
166 } | |
167 | |
168 //printf( "substr_len=%d, opt_len=%d\n", substr_len, opt_len ); | |
169 | |
170 /* Check if the length of the current option matches the * | |
171 * length of the option we want to test again. */ | |
172 if ( substr_len == opt_len ) | |
173 { | |
174 /* check if option was activated/deactivated */ | |
175 if( strncmp( &str[parse_pos], opts[idx].name, opt_len ) == 0 ) | |
176 { | |
177 /* option was found */ | |
28827
2b021e3e1000
Get rid of the "set" member of the subopt-parser struct, it made
reimar
parents:
22283
diff
changeset
|
178 next = 1; |
14281 | 179 |
180 assert( opts[idx].valp && "Need a pointer to store the arg!" ); | |
181 | |
182 /* type specific code */ | |
183 if ( opts[idx].type == OPT_ARG_BOOL ) | |
184 { | |
22283
bc9e95184521
cosmetics: Fix some common typos, sepErate --> sepArate, deciSSion --> deciSion.
diego
parents:
19104
diff
changeset
|
185 /* Handle OPT_ARG_BOOL separately so * |
14281 | 186 * the others can share code. */ |
187 | |
188 /* set option to true */ | |
189 *((int *)(opts[idx].valp)) = 1; | |
190 | |
191 /* increment position */ | |
192 parse_pos += opt_len; | |
193 } | |
194 else | |
195 { | |
196 /* Type is not OPT_ARG_BOOL, means we have to parse * | |
197 * for the arg delimiter character and eventually * | |
198 * call a test function. */ | |
199 char const * last; | |
200 | |
201 /* increment position to check for arg */ | |
202 parse_pos += opt_len; | |
203 | |
204 if ( str[parse_pos] != '=' ) | |
205 { | |
206 parse_err = 1; break; | |
207 } | |
208 | |
209 /* '=' char was there, so let's move after it */ | |
210 ++parse_pos; | |
211 | |
212 switch ( opts[idx].type ) | |
213 { | |
214 case OPT_ARG_INT: | |
215 last = parse_int( &str[parse_pos], | |
216 (int *)opts[idx].valp ); | |
217 | |
218 break; | |
219 case OPT_ARG_STR: | |
220 last = parse_str( &str[parse_pos], | |
221 (strarg_t *)opts[idx].valp ); | |
222 break; | |
14538
00c3c4111017
New suboption type: malloc'ed, zero terminated string
reimar
parents:
14294
diff
changeset
|
223 case OPT_ARG_MSTRZ: |
00c3c4111017
New suboption type: malloc'ed, zero terminated string
reimar
parents:
14294
diff
changeset
|
224 { |
00c3c4111017
New suboption type: malloc'ed, zero terminated string
reimar
parents:
14294
diff
changeset
|
225 char **valp = opts[idx].valp; |
00c3c4111017
New suboption type: malloc'ed, zero terminated string
reimar
parents:
14294
diff
changeset
|
226 strarg_t tmp; |
00c3c4111017
New suboption type: malloc'ed, zero terminated string
reimar
parents:
14294
diff
changeset
|
227 tmp.str = NULL; |
00c3c4111017
New suboption type: malloc'ed, zero terminated string
reimar
parents:
14294
diff
changeset
|
228 tmp.len = 0; |
00c3c4111017
New suboption type: malloc'ed, zero terminated string
reimar
parents:
14294
diff
changeset
|
229 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
|
230 free(*valp); |
14538
00c3c4111017
New suboption type: malloc'ed, zero terminated string
reimar
parents:
14294
diff
changeset
|
231 *valp = NULL; |
00c3c4111017
New suboption type: malloc'ed, zero terminated string
reimar
parents:
14294
diff
changeset
|
232 if (tmp.str && tmp.len > 0) { |
00c3c4111017
New suboption type: malloc'ed, zero terminated string
reimar
parents:
14294
diff
changeset
|
233 *valp = malloc(tmp.len + 1); |
00c3c4111017
New suboption type: malloc'ed, zero terminated string
reimar
parents:
14294
diff
changeset
|
234 memcpy(*valp, tmp.str, tmp.len); |
14572 | 235 (*valp)[tmp.len] = 0; |
14538
00c3c4111017
New suboption type: malloc'ed, zero terminated string
reimar
parents:
14294
diff
changeset
|
236 } |
00c3c4111017
New suboption type: malloc'ed, zero terminated string
reimar
parents:
14294
diff
changeset
|
237 break; |
00c3c4111017
New suboption type: malloc'ed, zero terminated string
reimar
parents:
14294
diff
changeset
|
238 } |
16720 | 239 case OPT_ARG_FLOAT: |
240 last = parse_float( &str[parse_pos], | |
241 (float *)opts[idx].valp ); | |
242 break; | |
14281 | 243 default: |
244 assert( 0 && "Arg type of suboption doesn't exist!" ); | |
245 last = NULL; // break parsing! | |
246 } | |
247 | |
248 /* was the conversion succesful? */ | |
249 if ( !last ) | |
250 { | |
251 parse_err = 1; break; | |
252 } | |
253 | |
254 /* make test if supplied */ | |
255 if ( opts[idx].test && !opts[idx].test( opts[idx].valp ) ) | |
256 { | |
257 parse_err = 1; break; | |
258 } | |
259 | |
260 /* we succeded, set position */ | |
261 parse_pos = last - str; | |
262 } | |
263 } | |
264 } | |
265 else if ( substr_len == opt_len+2 ) | |
266 { | |
267 if ( opts[idx].type == OPT_ARG_BOOL && // check for no<opt> | |
268 strncmp( &str[parse_pos], "no", 2 ) == 0 && | |
269 strncmp( &str[parse_pos+2], opts[idx].name, opt_len ) == 0 ) | |
270 { | |
271 /* 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
|
272 next = 1; |
14281 | 273 |
274 /* set arg to false */ | |
275 *((int *)(opts[idx].valp)) = 0; | |
276 | |
277 /* increment position */ | |
278 parse_pos += opt_len+2; | |
279 } | |
280 } | |
281 | |
282 ++idx; // test against next option | |
283 | |
284 /* break out of the loop, if this subopt is processed */ | |
285 if ( next ) { break; } | |
286 } | |
29252 | 287 |
14281 | 288 /* if we had a valid suboption the current pos should * |
289 * equal the delimiter char, which should be ':' for * | |
290 * suboptions. */ | |
291 if ( !parse_err && str[parse_pos] == ':' ) { ++parse_pos; } | |
292 else if ( str[parse_pos] ) { parse_err = 1; } | |
293 } | |
294 } | |
295 | |
296 /* if an error was encountered */ | |
297 if (parse_err) | |
298 { | |
299 unsigned int i; | |
300 mp_msg( MSGT_VO, MSGL_FATAL, "Could not parse arguments at the position indicated below:\n%s\n", str ); | |
301 for ( i = 0; i < parse_pos; ++i ) | |
302 { | |
303 mp_msg(MSGT_VO, MSGL_FATAL, " "); | |
304 } | |
305 mp_msg(MSGT_VO, MSGL_FATAL, "^\n"); | |
306 | |
307 return -1; | |
308 } | |
309 | |
310 /* we could parse everything */ | |
311 return 0; | |
312 } | |
313 | |
14736 | 314 |
315 /*** common test functions ***/ | |
316 | |
317 /** \brief Test if i is not negative */ | |
30122
1772a5171ac7
Fix function declarations to avoid casting function pointers.
reimar
parents:
29252
diff
changeset
|
318 int int_non_neg(void *iptr) |
14736 | 319 { |
30122
1772a5171ac7
Fix function declarations to avoid casting function pointers.
reimar
parents:
29252
diff
changeset
|
320 int *i = iptr; |
30123
0f5f75b4a015
Simplify range-checking functions for subopt parsing.
reimar
parents:
30122
diff
changeset
|
321 return *i >= 0; |
14736 | 322 } |
323 /** \brief Test if i is positive. */ | |
30122
1772a5171ac7
Fix function declarations to avoid casting function pointers.
reimar
parents:
29252
diff
changeset
|
324 int int_pos(void *iptr) |
14736 | 325 { |
30122
1772a5171ac7
Fix function declarations to avoid casting function pointers.
reimar
parents:
29252
diff
changeset
|
326 int *i = iptr; |
30123
0f5f75b4a015
Simplify range-checking functions for subopt parsing.
reimar
parents:
30122
diff
changeset
|
327 return *i > 0; |
14736 | 328 } |
15734
7e4fa8fc255c
helper functions for comparing strarg_t "strings".
reimar
parents:
15733
diff
changeset
|
329 |
7e4fa8fc255c
helper functions for comparing strarg_t "strings".
reimar
parents:
15733
diff
changeset
|
330 /*** little helpers */ |
7e4fa8fc255c
helper functions for comparing strarg_t "strings".
reimar
parents:
15733
diff
changeset
|
331 |
7e4fa8fc255c
helper functions for comparing strarg_t "strings".
reimar
parents:
15733
diff
changeset
|
332 /** \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
|
333 int strargcmp(strarg_t *arg, const char *str) { |
15734
7e4fa8fc255c
helper functions for comparing strarg_t "strings".
reimar
parents:
15733
diff
changeset
|
334 int res = strncmp(arg->str, str, arg->len); |
7e4fa8fc255c
helper functions for comparing strarg_t "strings".
reimar
parents:
15733
diff
changeset
|
335 if (!res && arg->len != strlen(str)) |
7e4fa8fc255c
helper functions for comparing strarg_t "strings".
reimar
parents:
15733
diff
changeset
|
336 res = arg->len - strlen(str); |
7e4fa8fc255c
helper functions for comparing strarg_t "strings".
reimar
parents:
15733
diff
changeset
|
337 return res; |
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 |
7e4fa8fc255c
helper functions for comparing strarg_t "strings".
reimar
parents:
15733
diff
changeset
|
340 /** \brief compare the stings just as strcasecmp does */ |
7e4fa8fc255c
helper functions for comparing strarg_t "strings".
reimar
parents:
15733
diff
changeset
|
341 int strargcasecmp(strarg_t *arg, char *str) { |
7e4fa8fc255c
helper functions for comparing strarg_t "strings".
reimar
parents:
15733
diff
changeset
|
342 int res = strncasecmp(arg->str, str, arg->len); |
7e4fa8fc255c
helper functions for comparing strarg_t "strings".
reimar
parents:
15733
diff
changeset
|
343 if (!res && arg->len != strlen(str)) |
7e4fa8fc255c
helper functions for comparing strarg_t "strings".
reimar
parents:
15733
diff
changeset
|
344 res = arg->len - strlen(str); |
7e4fa8fc255c
helper functions for comparing strarg_t "strings".
reimar
parents:
15733
diff
changeset
|
345 return res; |
7e4fa8fc255c
helper functions for comparing strarg_t "strings".
reimar
parents:
15733
diff
changeset
|
346 } |