… | |
… | |
62 | return TRUE; |
62 | return TRUE; |
63 | } |
63 | } |
64 | #endif |
64 | #endif |
65 | #endif |
65 | #endif |
66 | |
66 | |
67 | char * fptools_id = "$Id: fptools.c,v 1.9 2009/08/24 04:38:23 root Exp $"; |
67 | char * fptools_id = "$Id: fptools.c,v 1.10 2009/08/24 06:15:00 root Exp $"; |
68 | |
68 | |
69 | /* |
69 | /* |
70 | * some versions of free can't handle a NULL pointer properly |
70 | * some versions of free can't handle a NULL pointer properly |
71 | * (ANSI says, free ignores a NULL pointer, but some machines |
71 | * (ANSI says, free ignores a NULL pointer, but some machines |
72 | * prefer to SIGSEGV on it) |
72 | * prefer to SIGSEGV on it) |
… | |
… | |
138 | |
138 | |
139 | /* |
139 | /* |
140 | * case-insensitive compare |
140 | * case-insensitive compare |
141 | */ |
141 | */ |
142 | |
142 | |
|
|
143 | #ifndef FP_stricmp |
143 | int TOOLEXPORT |
144 | int TOOLEXPORT |
144 | _FP_stricmp (char *str1, char *str2) |
145 | _FP_stricmp (char *str1, char *str2) |
145 | { |
146 | { |
146 | if (str1==NULL || str2==NULL) |
147 | if (str1==NULL || str2==NULL) |
147 | return -1; |
148 | return -1; |
… | |
… | |
152 | str1++; |
153 | str1++; |
153 | str2++; |
154 | str2++; |
154 | } |
155 | } |
155 | return (tolower (*str1) - tolower (*str2)); |
156 | return (tolower (*str1) - tolower (*str2)); |
156 | } |
157 | } |
|
|
158 | #endif |
157 | |
159 | |
|
|
160 | #ifndef FP_strnicmp |
158 | int TOOLEXPORT |
161 | int TOOLEXPORT |
159 | _FP_strnicmp (char *str1, char *str2, int count) |
162 | _FP_strnicmp (char *str1, char *str2, int count) |
160 | { |
163 | { |
161 | if (str1==NULL || str2==NULL) |
164 | if (str1==NULL || str2==NULL) |
162 | return -1; |
165 | return -1; |
… | |
… | |
168 | str2++; |
171 | str2++; |
169 | count--; |
172 | count--; |
170 | } |
173 | } |
171 | return count ? (tolower (*str1) - tolower (*str2)) : 0; |
174 | return count ? (tolower (*str1) - tolower (*str2)) : 0; |
172 | } |
175 | } |
173 | |
176 | #endif |
174 | /* |
|
|
175 | * autoconf says this function might be a compatibility problem |
|
|
176 | */ |
|
|
177 | |
|
|
178 | char * TOOLEXPORT |
|
|
179 | _FP_strstr (char *str1, char *str2) |
|
|
180 | { |
|
|
181 | char *ptr1, *ptr2; |
|
|
182 | |
|
|
183 | if (str1==NULL) |
|
|
184 | return NULL; |
|
|
185 | if (str2==NULL) |
|
|
186 | return str1; |
|
|
187 | |
|
|
188 | while (*(ptr1=str1)) { |
|
|
189 | for (ptr2=str2; |
|
|
190 | *ptr1 && *ptr2 && *ptr1==*ptr2; |
|
|
191 | ptr1++, ptr2++) |
|
|
192 | /* empty loop */ ; |
|
|
193 | |
|
|
194 | if (*ptr2 == '\0') |
|
|
195 | return str1; |
|
|
196 | str1++; |
|
|
197 | } |
|
|
198 | return NULL; |
|
|
199 | } |
|
|
200 | |
177 | |
201 | char * TOOLEXPORT |
178 | char * TOOLEXPORT |
202 | _FP_strpbrk (char *str, char *accept) |
179 | _FP_strpbrk (char *str, char *accept) |
203 | { |
180 | { |
204 | char *ptr; |
181 | char *ptr; |
… | |
… | |
255 | |
232 | |
256 | /* |
233 | /* |
257 | * case insensitive strstr. |
234 | * case insensitive strstr. |
258 | */ |
235 | */ |
259 | |
236 | |
|
|
237 | #ifndef FP_stristr |
260 | char * TOOLEXPORT |
238 | char * TOOLEXPORT |
261 | _FP_stristr (char *str1, char *str2) |
239 | _FP_stristr (char *str1, char *str2) |
262 | { |
240 | { |
263 | char *ptr1, *ptr2; |
241 | char *ptr1, *ptr2; |
264 | |
242 | |
… | |
… | |
277 | return str1; |
255 | return str1; |
278 | str1++; |
256 | str1++; |
279 | } |
257 | } |
280 | return NULL; |
258 | return NULL; |
281 | } |
259 | } |
|
|
260 | #endif |
282 | |
261 | |
283 | /* |
262 | /* |
284 | * Nice fake of the real (non-standard) one |
263 | * Nice fake of the real (non-standard) one |
285 | */ |
264 | */ |
286 | |
265 | |
… | |
… | |
427 | ptr = filename; |
406 | ptr = filename; |
428 | |
407 | |
429 | return ptr; |
408 | return ptr; |
430 | } |
409 | } |
431 | |
410 | |
432 | #if HAVE_FGETC_UNLOCKED |
|
|
433 | # define _FP_fgetc(s) fgetc_unlocked (s) |
|
|
434 | #else |
|
|
435 | # define _FP_fgetc(s) fgetc (s) |
|
|
436 | #endif |
|
|
437 | |
|
|
438 | /* |
411 | /* |
439 | * My own fgets function. It handles all kinds of line terminators |
412 | * My own fgets function. It handles all kinds of line terminators |
440 | * properly: LF (Unix), CRLF (DOS) and CR (Mac). |
413 | * properly: LF (Unix), CRLF (DOS) and CR (Mac). |
441 | */ |
414 | */ |
442 | /* (schmorp) the buffer is always written to, and no LF is stored at the end */ |
415 | /* (schmorp) the buffer is always written to, and no LF is stored at the end */ |
… | |
… | |
463 | res = fscanf (stream, format, buf); |
436 | res = fscanf (stream, format, buf); |
464 | |
437 | |
465 | if (res == EOF) |
438 | if (res == EOF) |
466 | return 0; /* an error occured */ |
439 | return 0; /* an error occured */ |
467 | |
440 | |
|
|
441 | /* skip line endings */ |
468 | for (;;) |
442 | for (;;) |
469 | { |
443 | { |
470 | c = _FP_fgetc (stream); |
444 | c = _FP_fgetc (stream); |
471 | |
445 | |
472 | if (c == '\012') /* LF */ |
446 | if (c == '\012') /* LF */ |