Mercurial > sdl-ios-xcode
comparison src/stdlib/SDL_string.c @ 1354:22f39393668a
Fixed build problem with SDL_string.c
Officially deprecated SDL_byteorder.h, SDL_getenv.h and SDL_types.h
Moved endian-related SDL_rwops code into SDL_rwops.c
author | Sam Lantinga <slouken@libsdl.org> |
---|---|
date | Thu, 09 Feb 2006 09:38:05 +0000 |
parents | d5c4f8f6855e |
children | c71e05b4dc2e |
comparison
equal
deleted
inserted
replaced
1353:7ba544e2888d | 1354:22f39393668a |
---|---|
21 */ | 21 */ |
22 | 22 |
23 | 23 |
24 /* This file contains portable string manipulation functions for SDL */ | 24 /* This file contains portable string manipulation functions for SDL */ |
25 | 25 |
26 #include "SDL_types.h" | 26 #include "SDL_stdinc.h" |
27 #include "SDL_ctype.h" | 27 |
28 #include "SDL_stdlib.h" | 28 |
29 #include "SDL_string.h" | 29 #define SDL_isupperhex(X) (((X) >= 'A') && ((X) <= 'F')) |
30 | 30 #define SDL_islowerhex(X) (((X) >= 'a') && ((X) <= 'f')) |
31 | |
32 #define isupperhex(X) (((X) >= 'A') && ((X) <= 'F')) | |
33 #define islowerhex(X) (((X) >= 'a') && ((X) <= 'f')) | |
34 | 31 |
35 #if !defined(HAVE_SSCANF) || !defined(HAVE_STRTOL) | 32 #if !defined(HAVE_SSCANF) || !defined(HAVE_STRTOL) |
36 static size_t SDL_ScanLong(const char *text, int radix, long *valuep) | 33 static size_t SDL_ScanLong(const char *text, int radix, long *valuep) |
37 { | 34 { |
38 const char *textstart = text; | 35 const char *textstart = text; |
46 if ( radix == 16 && SDL_strncmp(text, "0x", 2) == 0 ) { | 43 if ( radix == 16 && SDL_strncmp(text, "0x", 2) == 0 ) { |
47 text += 2; | 44 text += 2; |
48 } | 45 } |
49 for ( ; ; ) { | 46 for ( ; ; ) { |
50 int v; | 47 int v; |
51 if ( isdigit(*text) ) { | 48 if ( SDL_isdigit(*text) ) { |
52 v = *text - '0'; | 49 v = *text - '0'; |
53 } else if ( radix == 16 && isupperhex(*text) ) { | 50 } else if ( radix == 16 && SDL_isupperhex(*text) ) { |
54 v = 10 + (*text - 'A'); | 51 v = 10 + (*text - 'A'); |
55 } else if ( radix == 16 && islowerhex(*text) ) { | 52 } else if ( radix == 16 && SDL_islowerhex(*text) ) { |
56 v = 10 + (*text - 'a'); | 53 v = 10 + (*text - 'a'); |
57 } else { | 54 } else { |
58 break; | 55 break; |
59 } | 56 } |
60 value *= radix; | 57 value *= radix; |
81 if ( radix == 16 && SDL_strncmp(text, "0x", 2) == 0 ) { | 78 if ( radix == 16 && SDL_strncmp(text, "0x", 2) == 0 ) { |
82 text += 2; | 79 text += 2; |
83 } | 80 } |
84 for ( ; ; ) { | 81 for ( ; ; ) { |
85 int v; | 82 int v; |
86 if ( isdigit(*text) ) { | 83 if ( SDL_isdigit(*text) ) { |
87 v = *text - '0'; | 84 v = *text - '0'; |
88 } else if ( radix == 16 && isupperhex(*text) ) { | 85 } else if ( radix == 16 && SDL_isupperhex(*text) ) { |
89 v = 10 + (*text - 'A'); | 86 v = 10 + (*text - 'A'); |
90 } else if ( radix == 16 && islowerhex(*text) ) { | 87 } else if ( radix == 16 && SDL_islowerhex(*text) ) { |
91 v = 10 + (*text - 'a'); | 88 v = 10 + (*text - 'a'); |
92 } else { | 89 } else { |
93 break; | 90 break; |
94 } | 91 } |
95 value *= radix; | 92 value *= radix; |
118 if ( radix == 16 && SDL_strncmp(text, "0x", 2) == 0 ) { | 115 if ( radix == 16 && SDL_strncmp(text, "0x", 2) == 0 ) { |
119 text += 2; | 116 text += 2; |
120 } | 117 } |
121 for ( ; ; ) { | 118 for ( ; ; ) { |
122 int v; | 119 int v; |
123 if ( isdigit(*text) ) { | 120 if ( SDL_isdigit(*text) ) { |
124 v = *text - '0'; | 121 v = *text - '0'; |
125 } else if ( radix == 16 && isupperhex(*text) ) { | 122 } else if ( radix == 16 && SDL_isupperhex(*text) ) { |
126 v = 10 + (*text - 'A'); | 123 v = 10 + (*text - 'A'); |
127 } else if ( radix == 16 && islowerhex(*text) ) { | 124 } else if ( radix == 16 && SDL_islowerhex(*text) ) { |
128 v = 10 + (*text - 'a'); | 125 v = 10 + (*text - 'a'); |
129 } else { | 126 } else { |
130 break; | 127 break; |
131 } | 128 } |
132 value *= radix; | 129 value *= radix; |
153 if ( radix == 16 && SDL_strncmp(text, "0x", 2) == 0 ) { | 150 if ( radix == 16 && SDL_strncmp(text, "0x", 2) == 0 ) { |
154 text += 2; | 151 text += 2; |
155 } | 152 } |
156 for ( ; ; ) { | 153 for ( ; ; ) { |
157 int v; | 154 int v; |
158 if ( isdigit(*text) ) { | 155 if ( SDL_isdigit(*text) ) { |
159 v = *text - '0'; | 156 v = *text - '0'; |
160 } else if ( radix == 16 && isupperhex(*text) ) { | 157 } else if ( radix == 16 && SDL_isupperhex(*text) ) { |
161 v = 10 + (*text - 'A'); | 158 v = 10 + (*text - 'A'); |
162 } else if ( radix == 16 && islowerhex(*text) ) { | 159 } else if ( radix == 16 && SDL_islowerhex(*text) ) { |
163 v = 10 + (*text - 'a'); | 160 v = 10 + (*text - 'a'); |
164 } else { | 161 } else { |
165 break; | 162 break; |
166 } | 163 } |
167 value *= radix; | 164 value *= radix; |
191 text += SDL_ScanUnsignedLong(text, 10, &lvalue); | 188 text += SDL_ScanUnsignedLong(text, 10, &lvalue); |
192 value += lvalue; | 189 value += lvalue; |
193 if ( *text == '.' ) { | 190 if ( *text == '.' ) { |
194 int mult = 10; | 191 int mult = 10; |
195 ++text; | 192 ++text; |
196 while ( isdigit(*text) ) { | 193 while ( SDL_isdigit(*text) ) { |
197 lvalue = *text - '0'; | 194 lvalue = *text - '0'; |
198 value += (double)lvalue / mult; | 195 value += (double)lvalue / mult; |
199 mult *= 10; | 196 mult *= 10; |
200 ++text; | 197 ++text; |
201 } | 198 } |
630 int retval = 0; | 627 int retval = 0; |
631 | 628 |
632 va_start(ap, fmt); | 629 va_start(ap, fmt); |
633 while ( *fmt ) { | 630 while ( *fmt ) { |
634 if ( *fmt == ' ' ) { | 631 if ( *fmt == ' ' ) { |
635 while ( isspace(*text) ) { | 632 while ( SDL_isspace(*text) ) { |
636 ++text; | 633 ++text; |
637 } | 634 } |
638 ++fmt; | 635 ++fmt; |
639 continue; | 636 continue; |
640 } | 637 } |
681 ++retval; | 678 ++retval; |
682 } | 679 } |
683 continue; | 680 continue; |
684 } | 681 } |
685 | 682 |
686 while ( isspace(*text) ) { | 683 while ( SDL_isspace(*text) ) { |
687 ++text; | 684 ++text; |
688 } | 685 } |
689 | 686 |
690 /* FIXME: implement more of the format specifiers */ | 687 /* FIXME: implement more of the format specifiers */ |
691 while (!done) { | 688 while (!done) { |
843 } | 840 } |
844 done = SDL_TRUE; | 841 done = SDL_TRUE; |
845 break; | 842 break; |
846 case 's': | 843 case 's': |
847 if ( suppress ) { | 844 if ( suppress ) { |
848 while ( !isspace(*text) ) { | 845 while ( !SDL_isspace(*text) ) { |
849 ++text; | 846 ++text; |
850 if ( count ) { | 847 if ( count ) { |
851 if ( --count == 0 ) { | 848 if ( --count == 0 ) { |
852 break; | 849 break; |
853 } | 850 } |
854 } | 851 } |
855 } | 852 } |
856 } else { | 853 } else { |
857 char *valuep = va_arg(ap, char*); | 854 char *valuep = va_arg(ap, char*); |
858 while ( !isspace(*text) ) { | 855 while ( !SDL_isspace(*text) ) { |
859 *valuep++ = *text++; | 856 *valuep++ = *text++; |
860 if ( count ) { | 857 if ( count ) { |
861 if ( --count == 0 ) { | 858 if ( --count == 0 ) { |
862 break; | 859 break; |
863 } | 860 } |