src/stdlib/SDL_string.c
branchSDL-1.3
changeset 1662 782fd950bd46
parent 1659 14717b52abc0
child 1668 4da1ee79c9af
     1.1 --- a/src/stdlib/SDL_string.c	Sun May 21 17:27:13 2006 +0000
     1.2 +++ b/src/stdlib/SDL_string.c	Sun May 28 13:04:16 2006 +0000
     1.3 @@ -30,26 +30,27 @@
     1.4  #define SDL_islowerhex(X)   (((X) >= 'a') && ((X) <= 'f'))
     1.5  
     1.6  #if !defined(HAVE_SSCANF) || !defined(HAVE_STRTOL)
     1.7 -static size_t SDL_ScanLong(const char *text, int radix, long *valuep)
     1.8 +static size_t
     1.9 +SDL_ScanLong (const char *text, int radix, long *valuep)
    1.10  {
    1.11      const char *textstart = text;
    1.12      long value = 0;
    1.13      SDL_bool negative = SDL_FALSE;
    1.14  
    1.15 -    if ( *text == '-' ) {
    1.16 +    if (*text == '-') {
    1.17          negative = SDL_TRUE;
    1.18          ++text;
    1.19      }
    1.20 -    if ( radix == 16 && SDL_strncmp(text, "0x", 2) == 0 ) {
    1.21 +    if (radix == 16 && SDL_strncmp (text, "0x", 2) == 0) {
    1.22          text += 2;
    1.23      }
    1.24 -    for ( ; ; ) {
    1.25 +    for (;;) {
    1.26          int v;
    1.27 -        if ( SDL_isdigit(*text) ) {
    1.28 +        if (SDL_isdigit (*text)) {
    1.29              v = *text - '0';
    1.30 -        } else if ( radix == 16 && SDL_isupperhex(*text) ) {
    1.31 +        } else if (radix == 16 && SDL_isupperhex (*text)) {
    1.32              v = 10 + (*text - 'A');
    1.33 -        } else if ( radix == 16 && SDL_islowerhex(*text) ) {
    1.34 +        } else if (radix == 16 && SDL_islowerhex (*text)) {
    1.35              v = 10 + (*text - 'a');
    1.36          } else {
    1.37              break;
    1.38 @@ -58,8 +59,8 @@
    1.39          value += v;
    1.40          ++text;
    1.41      }
    1.42 -    if ( valuep ) {
    1.43 -        if ( negative && value ) {
    1.44 +    if (valuep) {
    1.45 +        if (negative && value) {
    1.46              *valuep = -value;
    1.47          } else {
    1.48              *valuep = value;
    1.49 @@ -70,21 +71,22 @@
    1.50  #endif
    1.51  
    1.52  #if !defined(HAVE_SSCANF) || !defined(HAVE_STRTOUL) || !defined(HAVE_STRTOD)
    1.53 -static size_t SDL_ScanUnsignedLong(const char *text, int radix, unsigned long *valuep)
    1.54 +static size_t
    1.55 +SDL_ScanUnsignedLong (const char *text, int radix, unsigned long *valuep)
    1.56  {
    1.57      const char *textstart = text;
    1.58      unsigned long value = 0;
    1.59  
    1.60 -    if ( radix == 16 && SDL_strncmp(text, "0x", 2) == 0 ) {
    1.61 +    if (radix == 16 && SDL_strncmp (text, "0x", 2) == 0) {
    1.62          text += 2;
    1.63      }
    1.64 -    for ( ; ; ) {
    1.65 +    for (;;) {
    1.66          int v;
    1.67 -        if ( SDL_isdigit(*text) ) {
    1.68 +        if (SDL_isdigit (*text)) {
    1.69              v = *text - '0';
    1.70 -        } else if ( radix == 16 && SDL_isupperhex(*text) ) {
    1.71 +        } else if (radix == 16 && SDL_isupperhex (*text)) {
    1.72              v = 10 + (*text - 'A');
    1.73 -        } else if ( radix == 16 && SDL_islowerhex(*text) ) {
    1.74 +        } else if (radix == 16 && SDL_islowerhex (*text)) {
    1.75              v = 10 + (*text - 'a');
    1.76          } else {
    1.77              break;
    1.78 @@ -93,7 +95,7 @@
    1.79          value += v;
    1.80          ++text;
    1.81      }
    1.82 -    if ( valuep ) {
    1.83 +    if (valuep) {
    1.84          *valuep = value;
    1.85      }
    1.86      return (text - textstart);
    1.87 @@ -101,21 +103,22 @@
    1.88  #endif
    1.89  
    1.90  #ifndef HAVE_SSCANF
    1.91 -static size_t SDL_ScanUintPtrT(const char *text, int radix, uintptr_t *valuep)
    1.92 +static size_t
    1.93 +SDL_ScanUintPtrT (const char *text, int radix, uintptr_t * valuep)
    1.94  {
    1.95      const char *textstart = text;
    1.96      uintptr_t value = 0;
    1.97  
    1.98 -    if ( radix == 16 && SDL_strncmp(text, "0x", 2) == 0 ) {
    1.99 +    if (radix == 16 && SDL_strncmp (text, "0x", 2) == 0) {
   1.100          text += 2;
   1.101      }
   1.102 -    for ( ; ; ) {
   1.103 +    for (;;) {
   1.104          int v;
   1.105 -        if ( SDL_isdigit(*text) ) {
   1.106 +        if (SDL_isdigit (*text)) {
   1.107              v = *text - '0';
   1.108 -        } else if ( radix == 16 && SDL_isupperhex(*text) ) {
   1.109 +        } else if (radix == 16 && SDL_isupperhex (*text)) {
   1.110              v = 10 + (*text - 'A');
   1.111 -        } else if ( radix == 16 && SDL_islowerhex(*text) ) {
   1.112 +        } else if (radix == 16 && SDL_islowerhex (*text)) {
   1.113              v = 10 + (*text - 'a');
   1.114          } else {
   1.115              break;
   1.116 @@ -124,7 +127,7 @@
   1.117          value += v;
   1.118          ++text;
   1.119      }
   1.120 -    if ( valuep ) {
   1.121 +    if (valuep) {
   1.122          *valuep = value;
   1.123      }
   1.124      return (text - textstart);
   1.125 @@ -133,26 +136,27 @@
   1.126  
   1.127  #ifdef SDL_HAS_64BIT_TYPE
   1.128  #if !defined(HAVE_SSCANF) || !defined(HAVE_STRTOLL)
   1.129 -static size_t SDL_ScanLongLong(const char *text, int radix, Sint64 *valuep)
   1.130 +static size_t
   1.131 +SDL_ScanLongLong (const char *text, int radix, Sint64 * valuep)
   1.132  {
   1.133      const char *textstart = text;
   1.134      Sint64 value = 0;
   1.135      SDL_bool negative = SDL_FALSE;
   1.136  
   1.137 -    if ( *text == '-' ) {
   1.138 +    if (*text == '-') {
   1.139          negative = SDL_TRUE;
   1.140          ++text;
   1.141      }
   1.142 -    if ( radix == 16 && SDL_strncmp(text, "0x", 2) == 0 ) {
   1.143 +    if (radix == 16 && SDL_strncmp (text, "0x", 2) == 0) {
   1.144          text += 2;
   1.145      }
   1.146 -    for ( ; ; ) {
   1.147 +    for (;;) {
   1.148          int v;
   1.149 -        if ( SDL_isdigit(*text) ) {
   1.150 +        if (SDL_isdigit (*text)) {
   1.151              v = *text - '0';
   1.152 -        } else if ( radix == 16 && SDL_isupperhex(*text) ) {
   1.153 +        } else if (radix == 16 && SDL_isupperhex (*text)) {
   1.154              v = 10 + (*text - 'A');
   1.155 -        } else if ( radix == 16 && SDL_islowerhex(*text) ) {
   1.156 +        } else if (radix == 16 && SDL_islowerhex (*text)) {
   1.157              v = 10 + (*text - 'a');
   1.158          } else {
   1.159              break;
   1.160 @@ -161,8 +165,8 @@
   1.161          value += v;
   1.162          ++text;
   1.163      }
   1.164 -    if ( valuep ) {
   1.165 -        if ( negative && value ) {
   1.166 +    if (valuep) {
   1.167 +        if (negative && value) {
   1.168              *valuep = -value;
   1.169          } else {
   1.170              *valuep = value;
   1.171 @@ -173,21 +177,22 @@
   1.172  #endif
   1.173  
   1.174  #if !defined(HAVE_SSCANF) || !defined(HAVE_STRTOULL)
   1.175 -static size_t SDL_ScanUnsignedLongLong(const char *text, int radix, Uint64 *valuep)
   1.176 +static size_t
   1.177 +SDL_ScanUnsignedLongLong (const char *text, int radix, Uint64 * valuep)
   1.178  {
   1.179      const char *textstart = text;
   1.180      Uint64 value = 0;
   1.181  
   1.182 -    if ( radix == 16 && SDL_strncmp(text, "0x", 2) == 0 ) {
   1.183 +    if (radix == 16 && SDL_strncmp (text, "0x", 2) == 0) {
   1.184          text += 2;
   1.185      }
   1.186 -    for ( ; ; ) {
   1.187 +    for (;;) {
   1.188          int v;
   1.189 -        if ( SDL_isdigit(*text) ) {
   1.190 +        if (SDL_isdigit (*text)) {
   1.191              v = *text - '0';
   1.192 -        } else if ( radix == 16 && SDL_isupperhex(*text) ) {
   1.193 +        } else if (radix == 16 && SDL_isupperhex (*text)) {
   1.194              v = 10 + (*text - 'A');
   1.195 -        } else if ( radix == 16 && SDL_islowerhex(*text) ) {
   1.196 +        } else if (radix == 16 && SDL_islowerhex (*text)) {
   1.197              v = 10 + (*text - 'a');
   1.198          } else {
   1.199              break;
   1.200 @@ -196,7 +201,7 @@
   1.201          value += v;
   1.202          ++text;
   1.203      }
   1.204 -    if ( valuep ) {
   1.205 +    if (valuep) {
   1.206          *valuep = value;
   1.207      }
   1.208      return (text - textstart);
   1.209 @@ -205,31 +210,32 @@
   1.210  #endif /* SDL_HAS_64BIT_TYPE */
   1.211  
   1.212  #if !defined(HAVE_SSCANF) || !defined(HAVE_STRTOD)
   1.213 -static size_t SDL_ScanFloat(const char *text, double *valuep)
   1.214 +static size_t
   1.215 +SDL_ScanFloat (const char *text, double *valuep)
   1.216  {
   1.217      const char *textstart = text;
   1.218      unsigned long lvalue = 0;
   1.219      double value = 0.0;
   1.220      SDL_bool negative = SDL_FALSE;
   1.221  
   1.222 -    if ( *text == '-' ) {
   1.223 +    if (*text == '-') {
   1.224          negative = SDL_TRUE;
   1.225          ++text;
   1.226      }
   1.227 -    text += SDL_ScanUnsignedLong(text, 10, &lvalue);
   1.228 +    text += SDL_ScanUnsignedLong (text, 10, &lvalue);
   1.229      value += lvalue;
   1.230 -    if ( *text == '.' ) {
   1.231 +    if (*text == '.') {
   1.232          int mult = 10;
   1.233          ++text;
   1.234 -        while ( SDL_isdigit(*text) ) {
   1.235 +        while (SDL_isdigit (*text)) {
   1.236              lvalue = *text - '0';
   1.237 -            value += (double)lvalue / mult;
   1.238 +            value += (double) lvalue / mult;
   1.239              mult *= 10;
   1.240              ++text;
   1.241          }
   1.242      }
   1.243 -    if ( valuep ) {
   1.244 -        if ( negative && value ) {
   1.245 +    if (valuep) {
   1.246 +        if (negative && value) {
   1.247              *valuep = -value;
   1.248          } else {
   1.249              *valuep = value;
   1.250 @@ -240,31 +246,32 @@
   1.251  #endif
   1.252  
   1.253  #ifndef SDL_memset
   1.254 -void *SDL_memset(void *dst, int c, size_t len)
   1.255 +void *
   1.256 +SDL_memset (void *dst, int c, size_t len)
   1.257  {
   1.258      size_t left = (len % 4);
   1.259 -    if ( len >= 4 ) {
   1.260 +    if (len >= 4) {
   1.261          Uint32 value = 0;
   1.262 -        Uint32 *dstp = (Uint32 *)dst;
   1.263 +        Uint32 *dstp = (Uint32 *) dst;
   1.264          int i;
   1.265          for (i = 0; i < 4; ++i) {
   1.266              value <<= 8;
   1.267              value |= c;
   1.268          }
   1.269          len /= 4;
   1.270 -        while ( len-- ) {
   1.271 +        while (len--) {
   1.272              *dstp++ = value;
   1.273          }
   1.274      }
   1.275 -    if ( left > 0 ) {
   1.276 -        Uint8 value = (Uint8)c;
   1.277 -        Uint8 *dstp = (Uint8 *)dst;
   1.278 -	switch(left) {
   1.279 -	case 3:
   1.280 +    if (left > 0) {
   1.281 +        Uint8 value = (Uint8) c;
   1.282 +        Uint8 *dstp = (Uint8 *) dst;
   1.283 +        switch (left) {
   1.284 +        case 3:
   1.285              *dstp++ = value;
   1.286 -	case 2:
   1.287 +        case 2:
   1.288              *dstp++ = value;
   1.289 -	case 1:
   1.290 +        case 1:
   1.291              *dstp++ = value;
   1.292          }
   1.293      }
   1.294 @@ -273,11 +280,12 @@
   1.295  #endif
   1.296  
   1.297  #ifndef SDL_memcpy
   1.298 -void *SDL_memcpy(void *dst, const void *src, size_t len)
   1.299 +void *
   1.300 +SDL_memcpy (void *dst, const void *src, size_t len)
   1.301  {
   1.302 -    char *srcp = (char *)src;
   1.303 -    char *dstp = (char *)dst;
   1.304 -    while ( len-- ) {
   1.305 +    char *srcp = (char *) src;
   1.306 +    char *dstp = (char *) dst;
   1.307 +    while (len--) {
   1.308          *dstp++ = *srcp++;
   1.309      }
   1.310      return dst;
   1.311 @@ -285,13 +293,14 @@
   1.312  #endif
   1.313  
   1.314  #ifndef SDL_revcpy
   1.315 -void *SDL_revcpy(void *dst, const void *src, size_t len)
   1.316 +void *
   1.317 +SDL_revcpy (void *dst, const void *src, size_t len)
   1.318  {
   1.319 -    char *srcp = (char *)src;
   1.320 -    char *dstp = (char *)dst;
   1.321 +    char *srcp = (char *) src;
   1.322 +    char *dstp = (char *) dst;
   1.323      srcp += len;
   1.324      dstp += len;
   1.325 -    while ( len-- ) {
   1.326 +    while (len--) {
   1.327          *dstp-- = *srcp--;
   1.328      }
   1.329      return dst;
   1.330 @@ -299,26 +308,28 @@
   1.331  #endif
   1.332  
   1.333  #ifndef SDL_memcmp
   1.334 -int SDL_memcmp(const void *s1, const void *s2, size_t len)
   1.335 +int
   1.336 +SDL_memcmp (const void *s1, const void *s2, size_t len)
   1.337  {
   1.338 -    char *s1p = (char *)s1;
   1.339 -    char *s2p = (char *)s2;
   1.340 -    while ( len-- ) {
   1.341 -        if ( *s1p != *s2p ) {
   1.342 +    char *s1p = (char *) s1;
   1.343 +    char *s2p = (char *) s2;
   1.344 +    while (len--) {
   1.345 +        if (*s1p != *s2p) {
   1.346              return (*s1p - *s2p);
   1.347 -    }
   1.348 -    ++s1p;
   1.349 -    ++s2p;
   1.350 +        }
   1.351 +        ++s1p;
   1.352 +        ++s2p;
   1.353      }
   1.354      return 0;
   1.355  }
   1.356  #endif
   1.357  
   1.358  #ifndef HAVE_STRLEN
   1.359 -size_t SDL_strlen(const char *string)
   1.360 +size_t
   1.361 +SDL_strlen (const char *string)
   1.362  {
   1.363      size_t len = 0;
   1.364 -    while ( *string++ ) {
   1.365 +    while (*string++) {
   1.366          ++len;
   1.367      }
   1.368      return len;
   1.369 @@ -326,12 +337,13 @@
   1.370  #endif
   1.371  
   1.372  #ifndef HAVE_STRLCPY
   1.373 -size_t SDL_strlcpy(char *dst, const char *src, size_t maxlen)
   1.374 +size_t
   1.375 +SDL_strlcpy (char *dst, const char *src, size_t maxlen)
   1.376  {
   1.377 -    size_t srclen = SDL_strlen(src);
   1.378 -    if ( maxlen > 0 ) {
   1.379 -        size_t len = SDL_min(srclen, maxlen-1);
   1.380 -        SDL_memcpy(dst, src, len);
   1.381 +    size_t srclen = SDL_strlen (src);
   1.382 +    if (maxlen > 0) {
   1.383 +        size_t len = SDL_min (srclen, maxlen - 1);
   1.384 +        SDL_memcpy (dst, src, len);
   1.385          dst[len] = '\0';
   1.386      }
   1.387      return srclen;
   1.388 @@ -339,37 +351,40 @@
   1.389  #endif
   1.390  
   1.391  #ifndef HAVE_STRLCAT
   1.392 -size_t SDL_strlcat(char *dst, const char *src, size_t maxlen)
   1.393 +size_t
   1.394 +SDL_strlcat (char *dst, const char *src, size_t maxlen)
   1.395  {
   1.396 -    size_t dstlen = SDL_strlen(dst);
   1.397 -    size_t srclen = SDL_strlen(src);
   1.398 -    if ( dstlen < maxlen ) {
   1.399 -        SDL_strlcpy(dst+dstlen, src, maxlen-dstlen);
   1.400 +    size_t dstlen = SDL_strlen (dst);
   1.401 +    size_t srclen = SDL_strlen (src);
   1.402 +    if (dstlen < maxlen) {
   1.403 +        SDL_strlcpy (dst + dstlen, src, maxlen - dstlen);
   1.404      }
   1.405 -    return dstlen+srclen;
   1.406 +    return dstlen + srclen;
   1.407  }
   1.408  #endif
   1.409  
   1.410  #ifndef HAVE_STRDUP
   1.411 -char *SDL_strdup(const char *string)
   1.412 +char *
   1.413 +SDL_strdup (const char *string)
   1.414  {
   1.415 -    size_t len = SDL_strlen(string)+1;
   1.416 -    char *newstr = SDL_malloc(len);
   1.417 -    if ( newstr ) {
   1.418 -        SDL_strlcpy(newstr, string, len);
   1.419 +    size_t len = SDL_strlen (string) + 1;
   1.420 +    char *newstr = SDL_malloc (len);
   1.421 +    if (newstr) {
   1.422 +        SDL_strlcpy (newstr, string, len);
   1.423      }
   1.424      return newstr;
   1.425  }
   1.426  #endif
   1.427  
   1.428  #ifndef HAVE__STRREV
   1.429 -char *SDL_strrev(char *string)
   1.430 +char *
   1.431 +SDL_strrev (char *string)
   1.432  {
   1.433 -    size_t len = SDL_strlen(string);
   1.434 +    size_t len = SDL_strlen (string);
   1.435      char *a = &string[0];
   1.436 -    char *b = &string[len-1];
   1.437 +    char *b = &string[len - 1];
   1.438      len /= 2;
   1.439 -    while ( len-- ) {
   1.440 +    while (len--) {
   1.441          char c = *a;
   1.442          *a++ = *b;
   1.443          *b-- = c;
   1.444 @@ -379,65 +394,70 @@
   1.445  #endif
   1.446  
   1.447  #ifndef HAVE__STRUPR
   1.448 -char *SDL_strupr(char *string)
   1.449 +char *
   1.450 +SDL_strupr (char *string)
   1.451  {
   1.452      char *bufp = string;
   1.453 -    while ( *bufp ) {
   1.454 -        *bufp = SDL_toupper(*bufp);
   1.455 -	++bufp;
   1.456 +    while (*bufp) {
   1.457 +        *bufp = SDL_toupper (*bufp);
   1.458 +        ++bufp;
   1.459      }
   1.460      return string;
   1.461  }
   1.462  #endif
   1.463  
   1.464  #ifndef HAVE__STRLWR
   1.465 -char *SDL_strlwr(char *string)
   1.466 +char *
   1.467 +SDL_strlwr (char *string)
   1.468  {
   1.469      char *bufp = string;
   1.470 -    while ( *bufp ) {
   1.471 -        *bufp = SDL_tolower(*bufp);
   1.472 -	++bufp;
   1.473 +    while (*bufp) {
   1.474 +        *bufp = SDL_tolower (*bufp);
   1.475 +        ++bufp;
   1.476      }
   1.477      return string;
   1.478  }
   1.479  #endif
   1.480  
   1.481  #ifndef HAVE_STRCHR
   1.482 -char *SDL_strchr(const char *string, int c)
   1.483 +char *
   1.484 +SDL_strchr (const char *string, int c)
   1.485  {
   1.486 -    while ( *string ) {
   1.487 -        if ( *string == c ) {
   1.488 -            return (char *)string;
   1.489 +    while (*string) {
   1.490 +        if (*string == c) {
   1.491 +            return (char *) string;
   1.492          }
   1.493 -	++string;
   1.494 +        ++string;
   1.495      }
   1.496      return NULL;
   1.497  }
   1.498  #endif
   1.499  
   1.500  #ifndef HAVE_STRRCHR
   1.501 -char *SDL_strrchr(const char *string, int c)
   1.502 +char *
   1.503 +SDL_strrchr (const char *string, int c)
   1.504  {
   1.505 -    const char *bufp = string + SDL_strlen(string) - 1;
   1.506 -    while ( bufp >= string ) {
   1.507 -        if ( *bufp == c ) {
   1.508 -            return (char *)bufp;
   1.509 +    const char *bufp = string + SDL_strlen (string) - 1;
   1.510 +    while (bufp >= string) {
   1.511 +        if (*bufp == c) {
   1.512 +            return (char *) bufp;
   1.513          }
   1.514 -	--bufp;
   1.515 +        --bufp;
   1.516      }
   1.517      return NULL;
   1.518  }
   1.519  #endif
   1.520  
   1.521  #ifndef HAVE_STRSTR
   1.522 -char *SDL_strstr(const char *haystack, const char *needle)
   1.523 +char *
   1.524 +SDL_strstr (const char *haystack, const char *needle)
   1.525  {
   1.526 -    size_t length = SDL_strlen(needle);
   1.527 -    while ( *haystack ) {
   1.528 -        if ( SDL_strncmp(haystack, needle, length) == 0 ) {
   1.529 -            return (char *)haystack;
   1.530 +    size_t length = SDL_strlen (needle);
   1.531 +    while (*haystack) {
   1.532 +        if (SDL_strncmp (haystack, needle, length) == 0) {
   1.533 +            return (char *) haystack;
   1.534          }
   1.535 -	++haystack;
   1.536 +        ++haystack;
   1.537      }
   1.538      return NULL;
   1.539  }
   1.540 @@ -454,16 +474,17 @@
   1.541  #endif /* ntoa() conversion table */
   1.542  
   1.543  #ifndef HAVE__LTOA
   1.544 -char *SDL_ltoa(long value, char *string, int radix)
   1.545 +char *
   1.546 +SDL_ltoa (long value, char *string, int radix)
   1.547  {
   1.548      char *bufp = string;
   1.549  
   1.550 -    if ( value < 0 ) {
   1.551 +    if (value < 0) {
   1.552          *bufp++ = '-';
   1.553          value = -value;
   1.554      }
   1.555 -    if ( value ) {
   1.556 -        while ( value > 0 ) {
   1.557 +    if (value) {
   1.558 +        while (value > 0) {
   1.559              *bufp++ = ntoa_table[value % radix];
   1.560              value /= radix;
   1.561          }
   1.562 @@ -473,10 +494,10 @@
   1.563      *bufp = '\0';
   1.564  
   1.565      /* The numbers went into the string backwards. :) */
   1.566 -    if ( *string == '-' ) {
   1.567 -        SDL_strrev(string+1);
   1.568 +    if (*string == '-') {
   1.569 +        SDL_strrev (string + 1);
   1.570      } else {
   1.571 -        SDL_strrev(string);
   1.572 +        SDL_strrev (string);
   1.573      }
   1.574  
   1.575      return string;
   1.576 @@ -484,12 +505,13 @@
   1.577  #endif
   1.578  
   1.579  #ifndef HAVE__ULTOA
   1.580 -char *SDL_ultoa(unsigned long value, char *string, int radix)
   1.581 +char *
   1.582 +SDL_ultoa (unsigned long value, char *string, int radix)
   1.583  {
   1.584      char *bufp = string;
   1.585  
   1.586 -    if ( value ) {
   1.587 -        while ( value > 0 ) {
   1.588 +    if (value) {
   1.589 +        while (value > 0) {
   1.590              *bufp++ = ntoa_table[value % radix];
   1.591              value /= radix;
   1.592          }
   1.593 @@ -499,35 +521,37 @@
   1.594      *bufp = '\0';
   1.595  
   1.596      /* The numbers went into the string backwards. :) */
   1.597 -    SDL_strrev(string);
   1.598 +    SDL_strrev (string);
   1.599  
   1.600      return string;
   1.601  }
   1.602  #endif
   1.603  
   1.604  #ifndef HAVE_STRTOL
   1.605 -long SDL_strtol(const char *string, char **endp, int base)
   1.606 +long
   1.607 +SDL_strtol (const char *string, char **endp, int base)
   1.608  {
   1.609      size_t len;
   1.610      long value;
   1.611  
   1.612 -    len = SDL_ScanLong(string, base ? base : 10, &value);
   1.613 -    if ( endp ) {
   1.614 -        *endp = (char *)string + len;
   1.615 +    len = SDL_ScanLong (string, base ? base : 10, &value);
   1.616 +    if (endp) {
   1.617 +        *endp = (char *) string + len;
   1.618      }
   1.619      return value;
   1.620  }
   1.621  #endif
   1.622  
   1.623  #ifndef HAVE_STRTOUL
   1.624 -unsigned long SDL_strtoul(const char *string, char **endp, int base)
   1.625 +unsigned long
   1.626 +SDL_strtoul (const char *string, char **endp, int base)
   1.627  {
   1.628      size_t len;
   1.629      unsigned long value;
   1.630  
   1.631 -    len = SDL_ScanUnsignedLong(string, base ? base : 10, &value);
   1.632 -    if ( endp ) {
   1.633 -        *endp = (char *)string + len;
   1.634 +    len = SDL_ScanUnsignedLong (string, base ? base : 10, &value);
   1.635 +    if (endp) {
   1.636 +        *endp = (char *) string + len;
   1.637      }
   1.638      return value;
   1.639  }
   1.640 @@ -536,16 +560,17 @@
   1.641  #ifdef SDL_HAS_64BIT_TYPE
   1.642  
   1.643  #ifndef HAVE__I64TOA
   1.644 -char *SDL_lltoa(Sint64 value, char *string, int radix)
   1.645 +char *
   1.646 +SDL_lltoa (Sint64 value, char *string, int radix)
   1.647  {
   1.648      char *bufp = string;
   1.649  
   1.650 -    if ( value < 0 ) {
   1.651 +    if (value < 0) {
   1.652          *bufp++ = '-';
   1.653          value = -value;
   1.654      }
   1.655 -    if ( value ) {
   1.656 -        while ( value > 0 ) {
   1.657 +    if (value) {
   1.658 +        while (value > 0) {
   1.659              *bufp++ = ntoa_table[value % radix];
   1.660              value /= radix;
   1.661          }
   1.662 @@ -555,10 +580,10 @@
   1.663      *bufp = '\0';
   1.664  
   1.665      /* The numbers went into the string backwards. :) */
   1.666 -    if ( *string == '-' ) {
   1.667 -        SDL_strrev(string+1);
   1.668 +    if (*string == '-') {
   1.669 +        SDL_strrev (string + 1);
   1.670      } else {
   1.671 -        SDL_strrev(string);
   1.672 +        SDL_strrev (string);
   1.673      }
   1.674  
   1.675      return string;
   1.676 @@ -566,12 +591,13 @@
   1.677  #endif
   1.678  
   1.679  #ifndef HAVE__UI64TOA
   1.680 -char *SDL_ulltoa(Uint64 value, char *string, int radix)
   1.681 +char *
   1.682 +SDL_ulltoa (Uint64 value, char *string, int radix)
   1.683  {
   1.684      char *bufp = string;
   1.685  
   1.686 -    if ( value ) {
   1.687 -        while ( value > 0 ) {
   1.688 +    if (value) {
   1.689 +        while (value > 0) {
   1.690              *bufp++ = ntoa_table[value % radix];
   1.691              value /= radix;
   1.692          }
   1.693 @@ -581,35 +607,37 @@
   1.694      *bufp = '\0';
   1.695  
   1.696      /* The numbers went into the string backwards. :) */
   1.697 -    SDL_strrev(string);
   1.698 +    SDL_strrev (string);
   1.699  
   1.700      return string;
   1.701  }
   1.702  #endif
   1.703  
   1.704  #ifndef HAVE_STRTOLL
   1.705 -Sint64 SDL_strtoll(const char *string, char **endp, int base)
   1.706 +Sint64
   1.707 +SDL_strtoll (const char *string, char **endp, int base)
   1.708  {
   1.709      size_t len;
   1.710      Sint64 value;
   1.711  
   1.712 -    len = SDL_ScanLongLong(string, base ? base : 10, &value);
   1.713 -    if ( endp ) {
   1.714 -        *endp = (char *)string + len;
   1.715 +    len = SDL_ScanLongLong (string, base ? base : 10, &value);
   1.716 +    if (endp) {
   1.717 +        *endp = (char *) string + len;
   1.718      }
   1.719      return value;
   1.720  }
   1.721  #endif
   1.722  
   1.723  #ifndef HAVE_STRTOULL
   1.724 -Uint64 SDL_strtoull(const char *string, char **endp, int base)
   1.725 +Uint64
   1.726 +SDL_strtoull (const char *string, char **endp, int base)
   1.727  {
   1.728      size_t len;
   1.729      Uint64 value;
   1.730  
   1.731 -    len = SDL_ScanUnsignedLongLong(string, base ? base : 10, &value);
   1.732 -    if ( endp ) {
   1.733 -        *endp = (char *)string + len;
   1.734 +    len = SDL_ScanUnsignedLongLong (string, base ? base : 10, &value);
   1.735 +    if (endp) {
   1.736 +        *endp = (char *) string + len;
   1.737      }
   1.738      return value;
   1.739  }
   1.740 @@ -618,104 +646,111 @@
   1.741  #endif /* SDL_HAS_64BIT_TYPE */
   1.742  
   1.743  #ifndef HAVE_STRTOD
   1.744 -double SDL_strtod(const char *string, char **endp)
   1.745 +double
   1.746 +SDL_strtod (const char *string, char **endp)
   1.747  {
   1.748      size_t len;
   1.749      double value;
   1.750  
   1.751 -    len = SDL_ScanFloat(string, &value);
   1.752 -    if ( endp ) {
   1.753 -        *endp = (char *)string + len;
   1.754 +    len = SDL_ScanFloat (string, &value);
   1.755 +    if (endp) {
   1.756 +        *endp = (char *) string + len;
   1.757      }
   1.758      return value;
   1.759  }
   1.760  #endif
   1.761  
   1.762  #ifndef HAVE_STRCMP
   1.763 -int SDL_strcmp(const char *str1, const char *str2)
   1.764 +int
   1.765 +SDL_strcmp (const char *str1, const char *str2)
   1.766  {
   1.767      while (*str1 && *str2) {
   1.768 -        if ( *str1 != *str2 )
   1.769 +        if (*str1 != *str2)
   1.770              break;
   1.771          ++str1;
   1.772          ++str2;
   1.773      }
   1.774 -    return (int)((unsigned char)*str1 - (unsigned char)*str2);
   1.775 +    return (int) ((unsigned char) *str1 - (unsigned char) *str2);
   1.776  }
   1.777  #endif
   1.778  
   1.779  #ifndef HAVE_STRNCMP
   1.780 -int SDL_strncmp(const char *str1, const char *str2, size_t maxlen)
   1.781 +int
   1.782 +SDL_strncmp (const char *str1, const char *str2, size_t maxlen)
   1.783  {
   1.784 -    while ( *str1 && *str2 && maxlen ) {
   1.785 -        if ( *str1 != *str2 )
   1.786 +    while (*str1 && *str2 && maxlen) {
   1.787 +        if (*str1 != *str2)
   1.788              break;
   1.789          ++str1;
   1.790          ++str2;
   1.791          --maxlen;
   1.792      }
   1.793 -    if ( ! maxlen ) {
   1.794 +    if (!maxlen) {
   1.795          return 0;
   1.796      }
   1.797 -    return (int)((unsigned char)*str1 - (unsigned char)*str2);
   1.798 +    return (int) ((unsigned char) *str1 - (unsigned char) *str2);
   1.799  }
   1.800  #endif
   1.801  
   1.802  #if !defined(HAVE_STRCASECMP) && !defined(HAVE__STRICMP)
   1.803 -int SDL_strcasecmp(const char *str1, const char *str2)
   1.804 +int
   1.805 +SDL_strcasecmp (const char *str1, const char *str2)
   1.806  {
   1.807      char a = 0;
   1.808      char b = 0;
   1.809 -    while ( *str1 && *str2 ) {
   1.810 -        a = SDL_tolower(*str1);
   1.811 -        b = SDL_tolower(*str2);
   1.812 -        if ( a != b )
   1.813 +    while (*str1 && *str2) {
   1.814 +        a = SDL_tolower (*str1);
   1.815 +        b = SDL_tolower (*str2);
   1.816 +        if (a != b)
   1.817              break;
   1.818          ++str1;
   1.819          ++str2;
   1.820      }
   1.821 -    return (int)((unsigned char)a - (unsigned char)b);
   1.822 +    return (int) ((unsigned char) a - (unsigned char) b);
   1.823  }
   1.824  #endif
   1.825  
   1.826  #if !defined(HAVE_STRNCASECMP) && !defined(HAVE__STRNICMP)
   1.827 -int SDL_strncasecmp(const char *str1, const char *str2, size_t maxlen)
   1.828 +int
   1.829 +SDL_strncasecmp (const char *str1, const char *str2, size_t maxlen)
   1.830  {
   1.831      char a = 0;
   1.832      char b = 0;
   1.833 -    while ( *str1 && *str2 && maxlen ) {
   1.834 -        a = SDL_tolower(*str1);
   1.835 -        b = SDL_tolower(*str2);
   1.836 -        if ( a != b )
   1.837 +    while (*str1 && *str2 && maxlen) {
   1.838 +        a = SDL_tolower (*str1);
   1.839 +        b = SDL_tolower (*str2);
   1.840 +        if (a != b)
   1.841              break;
   1.842          ++str1;
   1.843          ++str2;
   1.844          --maxlen;
   1.845      }
   1.846 -    return (int)((unsigned char)a - (unsigned char)b);
   1.847 +    return (int) ((unsigned char) a - (unsigned char) b);
   1.848  }
   1.849  #endif
   1.850  
   1.851  #ifndef HAVE_SSCANF
   1.852 -int SDL_sscanf(const char *text, const char *fmt, ...)
   1.853 +int
   1.854 +SDL_sscanf (const char *text, const char *fmt, ...)
   1.855  {
   1.856      va_list ap;
   1.857      int retval = 0;
   1.858  
   1.859 -    va_start(ap, fmt);
   1.860 -    while ( *fmt ) {
   1.861 -        if ( *fmt == ' ' ) {
   1.862 -            while ( SDL_isspace(*text) ) {
   1.863 +    va_start (ap, fmt);
   1.864 +    while (*fmt) {
   1.865 +        if (*fmt == ' ') {
   1.866 +            while (SDL_isspace (*text)) {
   1.867                  ++text;
   1.868              }
   1.869              ++fmt;
   1.870              continue;
   1.871          }
   1.872 -        if ( *fmt == '%' ) {
   1.873 +        if (*fmt == '%') {
   1.874              SDL_bool done = SDL_FALSE;
   1.875              long count = 0;
   1.876              int radix = 10;
   1.877 -            enum {
   1.878 +            enum
   1.879 +            {
   1.880                  DO_SHORT,
   1.881                  DO_INT,
   1.882                  DO_LONG,
   1.883 @@ -724,31 +759,31 @@
   1.884              SDL_bool suppress = SDL_FALSE;
   1.885  
   1.886              ++fmt;
   1.887 -            if ( *fmt == '%' ) {
   1.888 -                if ( *text == '%' ) {
   1.889 +            if (*fmt == '%') {
   1.890 +                if (*text == '%') {
   1.891                      ++text;
   1.892                      ++fmt;
   1.893                      continue;
   1.894                  }
   1.895                  break;
   1.896              }
   1.897 -            if ( *fmt == '*' ) {
   1.898 +            if (*fmt == '*') {
   1.899                  suppress = SDL_TRUE;
   1.900                  ++fmt;
   1.901              }
   1.902 -            fmt += SDL_ScanLong(fmt, 10, &count);
   1.903 +            fmt += SDL_ScanLong (fmt, 10, &count);
   1.904  
   1.905 -            if ( *fmt == 'c' ) {
   1.906 -                if ( ! count ) {
   1.907 +            if (*fmt == 'c') {
   1.908 +                if (!count) {
   1.909                      count = 1;
   1.910                  }
   1.911 -                if ( suppress ) {
   1.912 -                    while ( count-- ) {
   1.913 +                if (suppress) {
   1.914 +                    while (count--) {
   1.915                          ++text;
   1.916                      }
   1.917                  } else {
   1.918 -                    char *valuep = va_arg(ap, char*);
   1.919 -                    while ( count-- ) {
   1.920 +                    char *valuep = va_arg (ap, char *);
   1.921 +                    while (count--) {
   1.922                          *valuep++ = *text++;
   1.923                      }
   1.924                      ++retval;
   1.925 @@ -756,200 +791,205 @@
   1.926                  continue;
   1.927              }
   1.928  
   1.929 -            while ( SDL_isspace(*text) ) {
   1.930 +            while (SDL_isspace (*text)) {
   1.931                  ++text;
   1.932              }
   1.933  
   1.934              /* FIXME: implement more of the format specifiers */
   1.935              while (!done) {
   1.936 -                switch(*fmt) {
   1.937 -                    case '*':
   1.938 -                        suppress = SDL_TRUE;
   1.939 -                        break;
   1.940 -                    case 'h':
   1.941 -                        if ( inttype > DO_SHORT ) {
   1.942 -                            ++inttype;
   1.943 +                switch (*fmt) {
   1.944 +                case '*':
   1.945 +                    suppress = SDL_TRUE;
   1.946 +                    break;
   1.947 +                case 'h':
   1.948 +                    if (inttype > DO_SHORT) {
   1.949 +                        ++inttype;
   1.950 +                    }
   1.951 +                    break;
   1.952 +                case 'l':
   1.953 +                    if (inttype < DO_LONGLONG) {
   1.954 +                        ++inttype;
   1.955 +                    }
   1.956 +                    break;
   1.957 +                case 'I':
   1.958 +                    if (SDL_strncmp (fmt, "I64", 3) == 0) {
   1.959 +                        fmt += 2;
   1.960 +                        inttype = DO_LONGLONG;
   1.961 +                    }
   1.962 +                    break;
   1.963 +                case 'i':
   1.964 +                    {
   1.965 +                        int index = 0;
   1.966 +                        if (text[index] == '-') {
   1.967 +                            ++index;
   1.968 +                        }
   1.969 +                        if (text[index] == '0') {
   1.970 +                            if (SDL_tolower (text[index + 1]) == 'x') {
   1.971 +                                radix = 16;
   1.972 +                            } else {
   1.973 +                                radix = 8;
   1.974 +                            }
   1.975                          }
   1.976 -                        break;
   1.977 -                    case 'l':
   1.978 -                        if ( inttype < DO_LONGLONG ) {
   1.979 -                            ++inttype;
   1.980 +                    }
   1.981 +                    /* Fall through to %d handling */
   1.982 +                case 'd':
   1.983 +#ifdef SDL_HAS_64BIT_TYPE
   1.984 +                    if (inttype == DO_LONGLONG) {
   1.985 +                        Sint64 value;
   1.986 +                        text += SDL_ScanLongLong (text, radix, &value);
   1.987 +                        if (!suppress) {
   1.988 +                            Sint64 *valuep = va_arg (ap, Sint64 *);
   1.989 +                            *valuep = value;
   1.990 +                            ++retval;
   1.991 +                        }
   1.992 +                    } else
   1.993 +#endif /* SDL_HAS_64BIT_TYPE */
   1.994 +                    {
   1.995 +                        long value;
   1.996 +                        text += SDL_ScanLong (text, radix, &value);
   1.997 +                        if (!suppress) {
   1.998 +                            switch (inttype) {
   1.999 +                            case DO_SHORT:
  1.1000 +                                {
  1.1001 +                                    short *valuep = va_arg (ap, short *);
  1.1002 +                                    *valuep = (short) value;
  1.1003 +                                }
  1.1004 +                                break;
  1.1005 +                            case DO_INT:
  1.1006 +                                {
  1.1007 +                                    int *valuep = va_arg (ap, int *);
  1.1008 +                                    *valuep = (int) value;
  1.1009 +                                }
  1.1010 +                                break;
  1.1011 +                            case DO_LONG:
  1.1012 +                                {
  1.1013 +                                    long *valuep = va_arg (ap, long *);
  1.1014 +                                    *valuep = value;
  1.1015 +                                }
  1.1016 +                                break;
  1.1017 +                            case DO_LONGLONG:
  1.1018 +                                /* Handled above */
  1.1019 +                                break;
  1.1020 +                            }
  1.1021 +                            ++retval;
  1.1022                          }
  1.1023 -                        break;
  1.1024 -                    case 'I':
  1.1025 -                        if ( SDL_strncmp(fmt, "I64", 3) == 0 ) {
  1.1026 -                            fmt += 2;
  1.1027 -                            inttype = DO_LONGLONG;
  1.1028 +                    }
  1.1029 +                    done = SDL_TRUE;
  1.1030 +                    break;
  1.1031 +                case 'o':
  1.1032 +                    if (radix == 10) {
  1.1033 +                        radix = 8;
  1.1034 +                    }
  1.1035 +                    /* Fall through to unsigned handling */
  1.1036 +                case 'x':
  1.1037 +                case 'X':
  1.1038 +                    if (radix == 10) {
  1.1039 +                        radix = 16;
  1.1040 +                    }
  1.1041 +                    /* Fall through to unsigned handling */
  1.1042 +                case 'u':
  1.1043 +#ifdef SDL_HAS_64BIT_TYPE
  1.1044 +                    if (inttype == DO_LONGLONG) {
  1.1045 +                        Uint64 value;
  1.1046 +                        text +=
  1.1047 +                            SDL_ScanUnsignedLongLong (text, radix, &value);
  1.1048 +                        if (!suppress) {
  1.1049 +                            Uint64 *valuep = va_arg (ap, Uint64 *);
  1.1050 +                            *valuep = value;
  1.1051 +                            ++retval;
  1.1052                          }
  1.1053 -                        break;
  1.1054 -                    case 'i':
  1.1055 -                        {
  1.1056 -                            int index = 0;
  1.1057 -                            if ( text[index] == '-' ) {
  1.1058 -                                ++index;
  1.1059 +                    } else
  1.1060 +#endif /* SDL_HAS_64BIT_TYPE */
  1.1061 +                    {
  1.1062 +                        unsigned long value;
  1.1063 +                        text += SDL_ScanUnsignedLong (text, radix, &value);
  1.1064 +                        if (!suppress) {
  1.1065 +                            switch (inttype) {
  1.1066 +                            case DO_SHORT:
  1.1067 +                                {
  1.1068 +                                    short *valuep = va_arg (ap, short *);
  1.1069 +                                    *valuep = (short) value;
  1.1070 +                                }
  1.1071 +                                break;
  1.1072 +                            case DO_INT:
  1.1073 +                                {
  1.1074 +                                    int *valuep = va_arg (ap, int *);
  1.1075 +                                    *valuep = (int) value;
  1.1076 +                                }
  1.1077 +                                break;
  1.1078 +                            case DO_LONG:
  1.1079 +                                {
  1.1080 +                                    long *valuep = va_arg (ap, long *);
  1.1081 +                                    *valuep = value;
  1.1082 +                                }
  1.1083 +                                break;
  1.1084 +                            case DO_LONGLONG:
  1.1085 +                                /* Handled above */
  1.1086 +                                break;
  1.1087                              }
  1.1088 -                            if ( text[index] == '0' ) {
  1.1089 -                                if ( SDL_tolower(text[index+1]) == 'x' ) {
  1.1090 -                                    radix = 16;
  1.1091 -                                } else {
  1.1092 -                                    radix = 8;
  1.1093 +                            ++retval;
  1.1094 +                        }
  1.1095 +                    }
  1.1096 +                    done = SDL_TRUE;
  1.1097 +                    break;
  1.1098 +                case 'p':
  1.1099 +                    {
  1.1100 +                        uintptr_t value;
  1.1101 +                        text += SDL_ScanUintPtrT (text, 16, &value);
  1.1102 +                        if (!suppress) {
  1.1103 +                            void **valuep = va_arg (ap, void **);
  1.1104 +                            *valuep = (void *) value;
  1.1105 +                            ++retval;
  1.1106 +                        }
  1.1107 +                    }
  1.1108 +                    done = SDL_TRUE;
  1.1109 +                    break;
  1.1110 +                case 'f':
  1.1111 +                    {
  1.1112 +                        double value;
  1.1113 +                        text += SDL_ScanFloat (text, &value);
  1.1114 +                        if (!suppress) {
  1.1115 +                            float *valuep = va_arg (ap, float *);
  1.1116 +                            *valuep = (float) value;
  1.1117 +                            ++retval;
  1.1118 +                        }
  1.1119 +                    }
  1.1120 +                    done = SDL_TRUE;
  1.1121 +                    break;
  1.1122 +                case 's':
  1.1123 +                    if (suppress) {
  1.1124 +                        while (!SDL_isspace (*text)) {
  1.1125 +                            ++text;
  1.1126 +                            if (count) {
  1.1127 +                                if (--count == 0) {
  1.1128 +                                    break;
  1.1129                                  }
  1.1130                              }
  1.1131                          }
  1.1132 -                        /* Fall through to %d handling */
  1.1133 -                    case 'd':
  1.1134 -#ifdef SDL_HAS_64BIT_TYPE
  1.1135 -                        if ( inttype == DO_LONGLONG ) {
  1.1136 -                            Sint64 value;
  1.1137 -                            text += SDL_ScanLongLong(text, radix, &value);
  1.1138 -                            if ( ! suppress ) {
  1.1139 -                                Sint64 *valuep = va_arg(ap, Sint64*);
  1.1140 -                                *valuep = value;
  1.1141 -                                ++retval;
  1.1142 -                            }
  1.1143 -                        }
  1.1144 -                        else
  1.1145 -#endif /* SDL_HAS_64BIT_TYPE */
  1.1146 -                        {
  1.1147 -                            long value;
  1.1148 -                            text += SDL_ScanLong(text, radix, &value);
  1.1149 -                            if ( ! suppress ) {
  1.1150 -                                switch (inttype) {
  1.1151 -                                    case DO_SHORT:
  1.1152 -                                        { short* valuep = va_arg(ap, short*);
  1.1153 -                                            *valuep = (short)value;
  1.1154 -                                        }
  1.1155 -                                        break;
  1.1156 -                                    case DO_INT:
  1.1157 -                                        { int* valuep = va_arg(ap, int*);
  1.1158 -                                            *valuep = (int)value;
  1.1159 -                                        }
  1.1160 -                                        break;
  1.1161 -                                    case DO_LONG:
  1.1162 -                                        { long* valuep = va_arg(ap, long*);
  1.1163 -                                            *valuep = value;
  1.1164 -                                        }
  1.1165 -                                        break;
  1.1166 -                                    case DO_LONGLONG:
  1.1167 -                                        /* Handled above */
  1.1168 -                                        break;
  1.1169 +                    } else {
  1.1170 +                        char *valuep = va_arg (ap, char *);
  1.1171 +                        while (!SDL_isspace (*text)) {
  1.1172 +                            *valuep++ = *text++;
  1.1173 +                            if (count) {
  1.1174 +                                if (--count == 0) {
  1.1175 +                                    break;
  1.1176                                  }
  1.1177 -                                ++retval;
  1.1178 -                            }
  1.1179 -                        }
  1.1180 -                        done = SDL_TRUE;
  1.1181 -                        break;
  1.1182 -                    case 'o':
  1.1183 -                        if ( radix == 10 ) {
  1.1184 -                            radix = 8;
  1.1185 -                        }
  1.1186 -                        /* Fall through to unsigned handling */
  1.1187 -                    case 'x':
  1.1188 -                    case 'X':
  1.1189 -                        if ( radix == 10 ) {
  1.1190 -                            radix = 16;
  1.1191 -                        }
  1.1192 -                        /* Fall through to unsigned handling */
  1.1193 -                    case 'u':
  1.1194 -#ifdef SDL_HAS_64BIT_TYPE
  1.1195 -                        if ( inttype == DO_LONGLONG ) {
  1.1196 -                            Uint64 value;
  1.1197 -                            text += SDL_ScanUnsignedLongLong(text, radix, &value);
  1.1198 -                            if ( ! suppress ) {
  1.1199 -                                Uint64 *valuep = va_arg(ap, Uint64*);
  1.1200 -                                *valuep = value;
  1.1201 -                                ++retval;
  1.1202                              }
  1.1203                          }
  1.1204 -                        else
  1.1205 -#endif /* SDL_HAS_64BIT_TYPE */
  1.1206 -                        {
  1.1207 -                            unsigned long value;
  1.1208 -                            text += SDL_ScanUnsignedLong(text, radix, &value);
  1.1209 -                            if ( ! suppress ) {
  1.1210 -                                switch (inttype) {
  1.1211 -                                    case DO_SHORT:
  1.1212 -                                        { short* valuep = va_arg(ap, short*);
  1.1213 -                                            *valuep = (short)value;
  1.1214 -                                        }
  1.1215 -                                        break;
  1.1216 -                                    case DO_INT:
  1.1217 -                                        { int* valuep = va_arg(ap, int*);
  1.1218 -                                            *valuep = (int)value;
  1.1219 -                                        }
  1.1220 -                                        break;
  1.1221 -                                    case DO_LONG:
  1.1222 -                                        { long* valuep = va_arg(ap, long*);
  1.1223 -                                            *valuep = value;
  1.1224 -                                        }
  1.1225 -                                        break;
  1.1226 -                                    case DO_LONGLONG:
  1.1227 -                                        /* Handled above */
  1.1228 -                                        break;
  1.1229 -                                }
  1.1230 -                                ++retval;
  1.1231 -                            }
  1.1232 -                        }
  1.1233 -                        done = SDL_TRUE;
  1.1234 -                        break;
  1.1235 -                    case 'p':
  1.1236 -                        {
  1.1237 -                            uintptr_t value;
  1.1238 -                            text += SDL_ScanUintPtrT(text, 16, &value);
  1.1239 -                            if ( ! suppress ) {
  1.1240 -                                void** valuep = va_arg(ap, void**);
  1.1241 -                                *valuep = (void*)value;
  1.1242 -                                ++retval;
  1.1243 -                            }
  1.1244 -                        }
  1.1245 -                        done = SDL_TRUE;
  1.1246 -                        break;
  1.1247 -                    case 'f':
  1.1248 -                        {
  1.1249 -                            double value;
  1.1250 -                            text += SDL_ScanFloat(text, &value);
  1.1251 -                            if ( ! suppress ) {
  1.1252 -                                float* valuep = va_arg(ap, float*);
  1.1253 -                                *valuep = (float)value;
  1.1254 -                                ++retval;
  1.1255 -                            }
  1.1256 -                        }
  1.1257 -                        done = SDL_TRUE;
  1.1258 -                        break;
  1.1259 -                    case 's':
  1.1260 -                        if ( suppress ) {
  1.1261 -                            while ( !SDL_isspace(*text) ) {
  1.1262 -                                ++text;
  1.1263 -                                if ( count ) {
  1.1264 -                                    if ( --count == 0 ) {
  1.1265 -                                        break;
  1.1266 -                                    }
  1.1267 -                                }
  1.1268 -                            }
  1.1269 -                        } else {
  1.1270 -                            char *valuep = va_arg(ap, char*);
  1.1271 -                            while ( !SDL_isspace(*text) ) {
  1.1272 -                                *valuep++ = *text++;
  1.1273 -                                if ( count ) {
  1.1274 -                                    if ( --count == 0 ) {
  1.1275 -                                        break;
  1.1276 -                                    }
  1.1277 -                                }
  1.1278 -                            }
  1.1279 -                            *valuep = '\0';
  1.1280 -                            ++retval;
  1.1281 -                        }
  1.1282 -                        done = SDL_TRUE;
  1.1283 -                        break;
  1.1284 -                    default:
  1.1285 -                        done = SDL_TRUE;
  1.1286 -                        break;
  1.1287 +                        *valuep = '\0';
  1.1288 +                        ++retval;
  1.1289 +                    }
  1.1290 +                    done = SDL_TRUE;
  1.1291 +                    break;
  1.1292 +                default:
  1.1293 +                    done = SDL_TRUE;
  1.1294 +                    break;
  1.1295                  }
  1.1296                  ++fmt;
  1.1297              }
  1.1298              continue;
  1.1299          }
  1.1300 -        if ( *text == *fmt ) {
  1.1301 +        if (*text == *fmt) {
  1.1302              ++text;
  1.1303              ++fmt;
  1.1304              continue;
  1.1305 @@ -957,113 +997,123 @@
  1.1306          /* Text didn't match format specifier */
  1.1307          break;
  1.1308      }
  1.1309 -    va_end(ap);
  1.1310 +    va_end (ap);
  1.1311  
  1.1312      return retval;
  1.1313  }
  1.1314  #endif
  1.1315  
  1.1316  #ifndef HAVE_SNPRINTF
  1.1317 -int SDL_snprintf(char *text, size_t maxlen, const char *fmt, ...)
  1.1318 +int
  1.1319 +SDL_snprintf (char *text, size_t maxlen, const char *fmt, ...)
  1.1320  {
  1.1321      va_list ap;
  1.1322      int retval;
  1.1323  
  1.1324 -    va_start(ap, fmt);
  1.1325 -    retval = SDL_vsnprintf(text, maxlen, fmt, ap);
  1.1326 -    va_end(ap);
  1.1327 +    va_start (ap, fmt);
  1.1328 +    retval = SDL_vsnprintf (text, maxlen, fmt, ap);
  1.1329 +    va_end (ap);
  1.1330  
  1.1331      return retval;
  1.1332  }
  1.1333  #endif
  1.1334  
  1.1335  #ifndef HAVE_VSNPRINTF
  1.1336 -static size_t SDL_PrintLong(char *text, long value, int radix, size_t maxlen)
  1.1337 +static size_t
  1.1338 +SDL_PrintLong (char *text, long value, int radix, size_t maxlen)
  1.1339  {
  1.1340      char num[130];
  1.1341      size_t size;
  1.1342  
  1.1343 -    SDL_ltoa(value, num, radix);
  1.1344 -    size = SDL_strlen(num);
  1.1345 -    if ( size >= maxlen ) {
  1.1346 -        size = maxlen-1;
  1.1347 +    SDL_ltoa (value, num, radix);
  1.1348 +    size = SDL_strlen (num);
  1.1349 +    if (size >= maxlen) {
  1.1350 +        size = maxlen - 1;
  1.1351      }
  1.1352 -    SDL_strlcpy(text, num, size+1);
  1.1353 +    SDL_strlcpy (text, num, size + 1);
  1.1354  
  1.1355      return size;
  1.1356  }
  1.1357 -static size_t SDL_PrintUnsignedLong(char *text, unsigned long value, int radix, size_t maxlen)
  1.1358 +
  1.1359 +static size_t
  1.1360 +SDL_PrintUnsignedLong (char *text, unsigned long value, int radix,
  1.1361 +                       size_t maxlen)
  1.1362  {
  1.1363      char num[130];
  1.1364      size_t size;
  1.1365  
  1.1366 -    SDL_ultoa(value, num, radix);
  1.1367 -    size = SDL_strlen(num);
  1.1368 -    if ( size >= maxlen ) {
  1.1369 -        size = maxlen-1;
  1.1370 +    SDL_ultoa (value, num, radix);
  1.1371 +    size = SDL_strlen (num);
  1.1372 +    if (size >= maxlen) {
  1.1373 +        size = maxlen - 1;
  1.1374      }
  1.1375 -    SDL_strlcpy(text, num, size+1);
  1.1376 +    SDL_strlcpy (text, num, size + 1);
  1.1377  
  1.1378      return size;
  1.1379  }
  1.1380 +
  1.1381  #ifdef SDL_HAS_64BIT_TYPE
  1.1382 -static size_t SDL_PrintLongLong(char *text, Sint64 value, int radix, size_t maxlen)
  1.1383 +static size_t
  1.1384 +SDL_PrintLongLong (char *text, Sint64 value, int radix, size_t maxlen)
  1.1385  {
  1.1386      char num[130];
  1.1387      size_t size;
  1.1388  
  1.1389 -    SDL_lltoa(value, num, radix);
  1.1390 -    size = SDL_strlen(num);
  1.1391 -    if ( size >= maxlen ) {
  1.1392 -        size = maxlen-1;
  1.1393 +    SDL_lltoa (value, num, radix);
  1.1394 +    size = SDL_strlen (num);
  1.1395 +    if (size >= maxlen) {
  1.1396 +        size = maxlen - 1;
  1.1397      }
  1.1398 -    SDL_strlcpy(text, num, size+1);
  1.1399 +    SDL_strlcpy (text, num, size + 1);
  1.1400  
  1.1401      return size;
  1.1402  }
  1.1403 -static size_t SDL_PrintUnsignedLongLong(char *text, Uint64 value, int radix, size_t maxlen)
  1.1404 +
  1.1405 +static size_t
  1.1406 +SDL_PrintUnsignedLongLong (char *text, Uint64 value, int radix, size_t maxlen)
  1.1407  {
  1.1408      char num[130];
  1.1409      size_t size;
  1.1410  
  1.1411 -    SDL_ulltoa(value, num, radix);
  1.1412 -    size = SDL_strlen(num);
  1.1413 -    if ( size >= maxlen ) {
  1.1414 -        size = maxlen-1;
  1.1415 +    SDL_ulltoa (value, num, radix);
  1.1416 +    size = SDL_strlen (num);
  1.1417 +    if (size >= maxlen) {
  1.1418 +        size = maxlen - 1;
  1.1419      }
  1.1420 -    SDL_strlcpy(text, num, size+1);
  1.1421 +    SDL_strlcpy (text, num, size + 1);
  1.1422  
  1.1423      return size;
  1.1424  }
  1.1425  #endif /* SDL_HAS_64BIT_TYPE */
  1.1426 -static size_t SDL_PrintFloat(char *text, double arg, size_t maxlen)
  1.1427 +static size_t
  1.1428 +SDL_PrintFloat (char *text, double arg, size_t maxlen)
  1.1429  {
  1.1430      char *textstart = text;
  1.1431 -    if ( arg ) {
  1.1432 +    if (arg) {
  1.1433          /* This isn't especially accurate, but hey, it's easy. :) */
  1.1434          const double precision = 0.00000001;
  1.1435          size_t len;
  1.1436          unsigned long value;
  1.1437  
  1.1438 -        if ( arg < 0 ) {
  1.1439 +        if (arg < 0) {
  1.1440              *text++ = '-';
  1.1441              --maxlen;
  1.1442              arg = -arg;
  1.1443          }
  1.1444 -        value = (unsigned long)arg;
  1.1445 -        len = SDL_PrintUnsignedLong(text, value, 10, maxlen);
  1.1446 +        value = (unsigned long) arg;
  1.1447 +        len = SDL_PrintUnsignedLong (text, value, 10, maxlen);
  1.1448          text += len;
  1.1449          maxlen -= len;
  1.1450          arg -= value;
  1.1451 -        if ( arg > precision && maxlen ) {
  1.1452 +        if (arg > precision && maxlen) {
  1.1453              int mult = 10;
  1.1454              *text++ = '.';
  1.1455 -            while ( (arg > precision) && maxlen ) {
  1.1456 -                value = (unsigned long)(arg * mult);
  1.1457 -                len = SDL_PrintUnsignedLong(text, value, 10, maxlen);
  1.1458 +            while ((arg > precision) && maxlen) {
  1.1459 +                value = (unsigned long) (arg * mult);
  1.1460 +                len = SDL_PrintUnsignedLong (text, value, 10, maxlen);
  1.1461                  text += len;
  1.1462                  maxlen -= len;
  1.1463 -                arg -= (double)value / mult;
  1.1464 +                arg -= (double) value / mult;
  1.1465                  mult *= 10;
  1.1466              }
  1.1467          }
  1.1468 @@ -1072,28 +1122,33 @@
  1.1469      }
  1.1470      return (text - textstart);
  1.1471  }
  1.1472 -static size_t SDL_PrintString(char *text, const char *string, size_t maxlen)
  1.1473 +
  1.1474 +static size_t
  1.1475 +SDL_PrintString (char *text, const char *string, size_t maxlen)
  1.1476  {
  1.1477      char *textstart = text;
  1.1478 -    while ( *string && maxlen-- ) {
  1.1479 +    while (*string && maxlen--) {
  1.1480          *text++ = *string++;
  1.1481      }
  1.1482      return (text - textstart);
  1.1483  }
  1.1484 -int SDL_vsnprintf(char *text, size_t maxlen, const char *fmt, va_list ap)
  1.1485 +
  1.1486 +int
  1.1487 +SDL_vsnprintf (char *text, size_t maxlen, const char *fmt, va_list ap)
  1.1488  {
  1.1489      char *textstart = text;
  1.1490 -    if ( maxlen <= 0 ) {
  1.1491 +    if (maxlen <= 0) {
  1.1492          return 0;
  1.1493      }
  1.1494 -    --maxlen; /* For the trailing '\0' */
  1.1495 -    while ( *fmt && maxlen ) {
  1.1496 -        if ( *fmt == '%' ) {
  1.1497 +    --maxlen;                   /* For the trailing '\0' */
  1.1498 +    while (*fmt && maxlen) {
  1.1499 +        if (*fmt == '%') {
  1.1500              SDL_bool done = SDL_FALSE;
  1.1501              size_t len = 0;
  1.1502              SDL_bool do_lowercase = SDL_FALSE;
  1.1503              int radix = 10;
  1.1504 -            enum {
  1.1505 +            enum
  1.1506 +            {
  1.1507                  DO_INT,
  1.1508                  DO_LONG,
  1.1509                  DO_LONGLONG
  1.1510 @@ -1101,104 +1156,132 @@
  1.1511  
  1.1512              ++fmt;
  1.1513              /* FIXME: implement more of the format specifiers */
  1.1514 -            while ( *fmt == '.' || (*fmt >= '0' && *fmt <= '9') ) {
  1.1515 +            while (*fmt == '.' || (*fmt >= '0' && *fmt <= '9')) {
  1.1516                  ++fmt;
  1.1517              }
  1.1518              while (!done) {
  1.1519 -                switch(*fmt) {
  1.1520 -                    case '%':
  1.1521 -                        *text = '%';
  1.1522 -                        len = 1;
  1.1523 -                        done = SDL_TRUE;
  1.1524 -                        break;
  1.1525 -                    case 'c':
  1.1526 -                        /* char is promoted to int when passed through (...) */
  1.1527 -                        *text = (char)va_arg(ap, int);
  1.1528 -                        len = 1;
  1.1529 -                        done = SDL_TRUE;
  1.1530 -                        break;
  1.1531 -                    case 'h':
  1.1532 -                        /* short is promoted to int when passed through (...) */
  1.1533 -                        break;
  1.1534 -                    case 'l':
  1.1535 -                        if ( inttype < DO_LONGLONG ) {
  1.1536 -                            ++inttype;
  1.1537 -                        }
  1.1538 +                switch (*fmt) {
  1.1539 +                case '%':
  1.1540 +                    *text = '%';
  1.1541 +                    len = 1;
  1.1542 +                    done = SDL_TRUE;
  1.1543 +                    break;
  1.1544 +                case 'c':
  1.1545 +                    /* char is promoted to int when passed through (...) */
  1.1546 +                    *text = (char) va_arg (ap, int);
  1.1547 +                    len = 1;
  1.1548 +                    done = SDL_TRUE;
  1.1549 +                    break;
  1.1550 +                case 'h':
  1.1551 +                    /* short is promoted to int when passed through (...) */
  1.1552 +                    break;
  1.1553 +                case 'l':
  1.1554 +                    if (inttype < DO_LONGLONG) {
  1.1555 +                        ++inttype;
  1.1556 +                    }
  1.1557 +                    break;
  1.1558 +                case 'I':
  1.1559 +                    if (SDL_strncmp (fmt, "I64", 3) == 0) {
  1.1560 +                        fmt += 2;
  1.1561 +                        inttype = DO_LONGLONG;
  1.1562 +                    }
  1.1563 +                    break;
  1.1564 +                case 'i':
  1.1565 +                case 'd':
  1.1566 +                    switch (inttype) {
  1.1567 +                    case DO_INT:
  1.1568 +                        len =
  1.1569 +                            SDL_PrintLong (text,
  1.1570 +                                           (long) va_arg (ap, int),
  1.1571 +                                           radix, maxlen);
  1.1572                          break;
  1.1573 -                    case 'I':
  1.1574 -                        if ( SDL_strncmp(fmt, "I64", 3) == 0 ) {
  1.1575 -                            fmt += 2;
  1.1576 -                            inttype = DO_LONGLONG;
  1.1577 -                        }
  1.1578 +                    case DO_LONG:
  1.1579 +                        len =
  1.1580 +                            SDL_PrintLong (text, va_arg (ap, long),
  1.1581 +                                           radix, maxlen);
  1.1582                          break;
  1.1583 -                    case 'i':
  1.1584 -                    case 'd':
  1.1585 -                        switch (inttype) {
  1.1586 -                            case DO_INT:
  1.1587 -                                len = SDL_PrintLong(text, (long)va_arg(ap, int), radix, maxlen);
  1.1588 -                                break;
  1.1589 -                            case DO_LONG:
  1.1590 -                                len = SDL_PrintLong(text, va_arg(ap, long), radix, maxlen);
  1.1591 -                                break;
  1.1592 -                            case DO_LONGLONG:
  1.1593 +                    case DO_LONGLONG:
  1.1594  #ifdef SDL_HAS_64BIT_TYPE
  1.1595 -                                len = SDL_PrintLongLong(text, va_arg(ap, Sint64), radix, maxlen);
  1.1596 +                        len =
  1.1597 +                            SDL_PrintLongLong (text,
  1.1598 +                                               va_arg (ap, Sint64),
  1.1599 +                                               radix, maxlen);
  1.1600  #else
  1.1601 -                                len = SDL_PrintLong(text, va_arg(ap, long), radix, maxlen);
  1.1602 +                        len =
  1.1603 +                            SDL_PrintLong (text, va_arg (ap, long),
  1.1604 +                                           radix, maxlen);
  1.1605  #endif
  1.1606 -                                break;
  1.1607 -                        }
  1.1608 -                        done = SDL_TRUE;
  1.1609                          break;
  1.1610 -                    case 'p':
  1.1611 -                    case 'x':
  1.1612 -                        do_lowercase = SDL_TRUE;
  1.1613 -                        /* Fall through to 'X' handling */
  1.1614 -                    case 'X':
  1.1615 -                        if ( radix == 10 ) {
  1.1616 -                            radix = 16;
  1.1617 -                        }
  1.1618 -                        if ( *fmt == 'p' ) {
  1.1619 -                            inttype = DO_LONG;
  1.1620 -                        }
  1.1621 -                        /* Fall through to unsigned handling */
  1.1622 -                    case 'o':
  1.1623 -                        if ( radix == 10 ) {
  1.1624 -                            radix = 8;
  1.1625 -                        }
  1.1626 -                        /* Fall through to unsigned handling */
  1.1627 -                    case 'u':
  1.1628 -                        switch (inttype) {
  1.1629 -                            case DO_INT:
  1.1630 -                                len = SDL_PrintUnsignedLong(text, (unsigned long)va_arg(ap, unsigned int), radix, maxlen);
  1.1631 -                                break;
  1.1632 -                            case DO_LONG:
  1.1633 -                                len = SDL_PrintUnsignedLong(text, va_arg(ap, unsigned long), radix, maxlen);
  1.1634 -                                break;
  1.1635 -                            case DO_LONGLONG:
  1.1636 +                    }
  1.1637 +                    done = SDL_TRUE;
  1.1638 +                    break;
  1.1639 +                case 'p':
  1.1640 +                case 'x':
  1.1641 +                    do_lowercase = SDL_TRUE;
  1.1642 +                    /* Fall through to 'X' handling */
  1.1643 +                case 'X':
  1.1644 +                    if (radix == 10) {
  1.1645 +                        radix = 16;
  1.1646 +                    }
  1.1647 +                    if (*fmt == 'p') {
  1.1648 +                        inttype = DO_LONG;
  1.1649 +                    }
  1.1650 +                    /* Fall through to unsigned handling */
  1.1651 +                case 'o':
  1.1652 +                    if (radix == 10) {
  1.1653 +                        radix = 8;
  1.1654 +                    }
  1.1655 +                    /* Fall through to unsigned handling */
  1.1656 +                case 'u':
  1.1657 +                    switch (inttype) {
  1.1658 +                    case DO_INT:
  1.1659 +                        len = SDL_PrintUnsignedLong (text, (unsigned long)
  1.1660 +                                                     va_arg (ap,
  1.1661 +                                                             unsigned
  1.1662 +                                                             int),
  1.1663 +                                                     radix, maxlen);
  1.1664 +                        break;
  1.1665 +                    case DO_LONG:
  1.1666 +                        len =
  1.1667 +                            SDL_PrintUnsignedLong (text,
  1.1668 +                                                   va_arg (ap,
  1.1669 +                                                           unsigned
  1.1670 +                                                           long),
  1.1671 +                                                   radix, maxlen);
  1.1672 +                        break;
  1.1673 +                    case DO_LONGLONG:
  1.1674  #ifdef SDL_HAS_64BIT_TYPE
  1.1675 -                                len = SDL_PrintUnsignedLongLong(text, va_arg(ap, Uint64), radix, maxlen);
  1.1676 +                        len =
  1.1677 +                            SDL_PrintUnsignedLongLong (text,
  1.1678 +                                                       va_arg (ap,
  1.1679 +                                                               Uint64),
  1.1680 +                                                       radix, maxlen);
  1.1681  #else
  1.1682 -                                len = SDL_PrintUnsignedLong(text, va_arg(ap, unsigned long), radix, maxlen);
  1.1683 +                        len =
  1.1684 +                            SDL_PrintUnsignedLong (text,
  1.1685 +                                                   va_arg (ap,
  1.1686 +                                                           unsigned
  1.1687 +                                                           long),
  1.1688 +                                                   radix, maxlen);
  1.1689  #endif
  1.1690 -                                break;
  1.1691 -                        }
  1.1692 -                        if ( do_lowercase ) {
  1.1693 -                            SDL_strlwr(text);
  1.1694 -                        }
  1.1695 -                        done = SDL_TRUE;
  1.1696                          break;
  1.1697 -                    case 'f':
  1.1698 -                        len = SDL_PrintFloat(text, va_arg(ap, double), maxlen);
  1.1699 -                        done = SDL_TRUE;
  1.1700 -                        break;
  1.1701 -                    case 's':
  1.1702 -                        len = SDL_PrintString(text, va_arg(ap, char*), maxlen);
  1.1703 -                        done = SDL_TRUE;
  1.1704 -                        break;
  1.1705 -                    default:
  1.1706 -                        done = SDL_TRUE;
  1.1707 -                        break;
  1.1708 +                    }
  1.1709 +                    if (do_lowercase) {
  1.1710 +                        SDL_strlwr (text);
  1.1711 +                    }
  1.1712 +                    done = SDL_TRUE;
  1.1713 +                    break;
  1.1714 +                case 'f':
  1.1715 +                    len = SDL_PrintFloat (text, va_arg (ap, double), maxlen);
  1.1716 +                    done = SDL_TRUE;
  1.1717 +                    break;
  1.1718 +                case 's':
  1.1719 +                    len = SDL_PrintString (text, va_arg (ap, char *), maxlen);
  1.1720 +                    done = SDL_TRUE;
  1.1721 +                    break;
  1.1722 +                default:
  1.1723 +                    done = SDL_TRUE;
  1.1724 +                    break;
  1.1725                  }
  1.1726                  ++fmt;
  1.1727              }
  1.1728 @@ -1214,3 +1297,4 @@
  1.1729      return (text - textstart);
  1.1730  }
  1.1731  #endif
  1.1732 +/* vi: set ts=4 sw=4 expandtab: */