src/stdlib/SDL_string.c
changeset 1895 c121d94672cb
parent 1867 887c3600826b
child 1901 f1828a500391
     1.1 --- a/src/stdlib/SDL_string.c	Thu Jul 06 18:01:37 2006 +0000
     1.2 +++ b/src/stdlib/SDL_string.c	Mon Jul 10 21:04:37 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      value += lvalue;
   1.229 -    if ( *text == '.' ) {
   1.230 +    if (*text == '.') {
   1.231          int mult = 10;
   1.232          ++text;
   1.233 -        while ( SDL_isdigit(*text) ) {
   1.234 +        while (SDL_isdigit(*text)) {
   1.235              lvalue = *text - '0';
   1.236 -            value += (double)lvalue / mult;
   1.237 +            value += (double) lvalue / mult;
   1.238              mult *= 10;
   1.239              ++text;
   1.240          }
   1.241      }
   1.242 -    if ( valuep ) {
   1.243 -        if ( negative && value ) {
   1.244 +    if (valuep) {
   1.245 +        if (negative && value) {
   1.246              *valuep = -value;
   1.247          } else {
   1.248              *valuep = value;
   1.249 @@ -240,31 +246,32 @@
   1.250  #endif
   1.251  
   1.252  #ifndef SDL_memset
   1.253 -void *SDL_memset(void *dst, int c, size_t len)
   1.254 +void *
   1.255 +SDL_memset(void *dst, int c, size_t len)
   1.256  {
   1.257      size_t left = (len % 4);
   1.258 -    if ( len >= 4 ) {
   1.259 +    if (len >= 4) {
   1.260          Uint32 value = 0;
   1.261 -        Uint32 *dstp = (Uint32 *)dst;
   1.262 +        Uint32 *dstp = (Uint32 *) dst;
   1.263          int i;
   1.264          for (i = 0; i < 4; ++i) {
   1.265              value <<= 8;
   1.266              value |= c;
   1.267          }
   1.268          len /= 4;
   1.269 -        while ( len-- ) {
   1.270 +        while (len--) {
   1.271              *dstp++ = value;
   1.272          }
   1.273      }
   1.274 -    if ( left > 0 ) {
   1.275 -        Uint8 value = (Uint8)c;
   1.276 -        Uint8 *dstp = (Uint8 *)dst;
   1.277 -	switch(left) {
   1.278 -	case 3:
   1.279 +    if (left > 0) {
   1.280 +        Uint8 value = (Uint8) c;
   1.281 +        Uint8 *dstp = (Uint8 *) dst;
   1.282 +        switch (left) {
   1.283 +        case 3:
   1.284              *dstp++ = value;
   1.285 -	case 2:
   1.286 +        case 2:
   1.287              *dstp++ = value;
   1.288 -	case 1:
   1.289 +        case 1:
   1.290              *dstp++ = value;
   1.291          }
   1.292      }
   1.293 @@ -273,11 +280,12 @@
   1.294  #endif
   1.295  
   1.296  #ifndef SDL_memcpy
   1.297 -void *SDL_memcpy(void *dst, const void *src, size_t len)
   1.298 +void *
   1.299 +SDL_memcpy(void *dst, const void *src, size_t len)
   1.300  {
   1.301 -    char *srcp = (char *)src;
   1.302 -    char *dstp = (char *)dst;
   1.303 -    while ( len-- ) {
   1.304 +    char *srcp = (char *) src;
   1.305 +    char *dstp = (char *) dst;
   1.306 +    while (len--) {
   1.307          *dstp++ = *srcp++;
   1.308      }
   1.309      return dst;
   1.310 @@ -285,13 +293,14 @@
   1.311  #endif
   1.312  
   1.313  #ifndef SDL_revcpy
   1.314 -void *SDL_revcpy(void *dst, const void *src, size_t len)
   1.315 +void *
   1.316 +SDL_revcpy(void *dst, const void *src, size_t len)
   1.317  {
   1.318 -    char *srcp = (char *)src;
   1.319 -    char *dstp = (char *)dst;
   1.320 +    char *srcp = (char *) src;
   1.321 +    char *dstp = (char *) dst;
   1.322      srcp += len;
   1.323      dstp += len;
   1.324 -    while ( len-- ) {
   1.325 +    while (len--) {
   1.326          *dstp-- = *srcp--;
   1.327      }
   1.328      return dst;
   1.329 @@ -299,26 +308,28 @@
   1.330  #endif
   1.331  
   1.332  #ifndef SDL_memcmp
   1.333 -int SDL_memcmp(const void *s1, const void *s2, size_t len)
   1.334 +int
   1.335 +SDL_memcmp(const void *s1, const void *s2, size_t len)
   1.336  {
   1.337 -    char *s1p = (char *)s1;
   1.338 -    char *s2p = (char *)s2;
   1.339 -    while ( len-- ) {
   1.340 -        if ( *s1p != *s2p ) {
   1.341 +    char *s1p = (char *) s1;
   1.342 +    char *s2p = (char *) s2;
   1.343 +    while (len--) {
   1.344 +        if (*s1p != *s2p) {
   1.345              return (*s1p - *s2p);
   1.346 -    }
   1.347 -    ++s1p;
   1.348 -    ++s2p;
   1.349 +        }
   1.350 +        ++s1p;
   1.351 +        ++s2p;
   1.352      }
   1.353      return 0;
   1.354  }
   1.355  #endif
   1.356  
   1.357  #ifndef HAVE_STRLEN
   1.358 -size_t SDL_strlen(const char *string)
   1.359 +size_t
   1.360 +SDL_strlen(const char *string)
   1.361  {
   1.362      size_t len = 0;
   1.363 -    while ( *string++ ) {
   1.364 +    while (*string++) {
   1.365          ++len;
   1.366      }
   1.367      return len;
   1.368 @@ -326,11 +337,12 @@
   1.369  #endif
   1.370  
   1.371  #ifndef HAVE_STRLCPY
   1.372 -size_t SDL_strlcpy(char *dst, const char *src, size_t maxlen)
   1.373 +size_t
   1.374 +SDL_strlcpy(char *dst, const char *src, size_t maxlen)
   1.375  {
   1.376      size_t srclen = SDL_strlen(src);
   1.377 -    if ( maxlen > 0 ) {
   1.378 -        size_t len = SDL_min(srclen, maxlen-1);
   1.379 +    if (maxlen > 0) {
   1.380 +        size_t len = SDL_min(srclen, maxlen - 1);
   1.381          SDL_memcpy(dst, src, len);
   1.382          dst[len] = '\0';
   1.383      }
   1.384 @@ -339,23 +351,25 @@
   1.385  #endif
   1.386  
   1.387  #ifndef HAVE_STRLCAT
   1.388 -size_t SDL_strlcat(char *dst, const char *src, size_t maxlen)
   1.389 +size_t
   1.390 +SDL_strlcat(char *dst, const char *src, size_t maxlen)
   1.391  {
   1.392      size_t dstlen = SDL_strlen(dst);
   1.393      size_t srclen = SDL_strlen(src);
   1.394 -    if ( dstlen < maxlen ) {
   1.395 -        SDL_strlcpy(dst+dstlen, src, maxlen-dstlen);
   1.396 +    if (dstlen < maxlen) {
   1.397 +        SDL_strlcpy(dst + dstlen, src, maxlen - dstlen);
   1.398      }
   1.399 -    return dstlen+srclen;
   1.400 +    return dstlen + srclen;
   1.401  }
   1.402  #endif
   1.403  
   1.404  #ifndef HAVE_STRDUP
   1.405 -char *SDL_strdup(const char *string)
   1.406 +char *
   1.407 +SDL_strdup(const char *string)
   1.408  {
   1.409 -    size_t len = SDL_strlen(string)+1;
   1.410 +    size_t len = SDL_strlen(string) + 1;
   1.411      char *newstr = SDL_malloc(len);
   1.412 -    if ( newstr ) {
   1.413 +    if (newstr) {
   1.414          SDL_strlcpy(newstr, string, len);
   1.415      }
   1.416      return newstr;
   1.417 @@ -363,13 +377,14 @@
   1.418  #endif
   1.419  
   1.420  #ifndef HAVE__STRREV
   1.421 -char *SDL_strrev(char *string)
   1.422 +char *
   1.423 +SDL_strrev(char *string)
   1.424  {
   1.425      size_t len = SDL_strlen(string);
   1.426      char *a = &string[0];
   1.427 -    char *b = &string[len-1];
   1.428 +    char *b = &string[len - 1];
   1.429      len /= 2;
   1.430 -    while ( len-- ) {
   1.431 +    while (len--) {
   1.432          char c = *a;
   1.433          *a++ = *b;
   1.434          *b-- = c;
   1.435 @@ -379,65 +394,70 @@
   1.436  #endif
   1.437  
   1.438  #ifndef HAVE__STRUPR
   1.439 -char *SDL_strupr(char *string)
   1.440 +char *
   1.441 +SDL_strupr(char *string)
   1.442  {
   1.443      char *bufp = string;
   1.444 -    while ( *bufp ) {
   1.445 +    while (*bufp) {
   1.446          *bufp = SDL_toupper(*bufp);
   1.447 -	++bufp;
   1.448 +        ++bufp;
   1.449      }
   1.450      return string;
   1.451  }
   1.452  #endif
   1.453  
   1.454  #ifndef HAVE__STRLWR
   1.455 -char *SDL_strlwr(char *string)
   1.456 +char *
   1.457 +SDL_strlwr(char *string)
   1.458  {
   1.459      char *bufp = string;
   1.460 -    while ( *bufp ) {
   1.461 +    while (*bufp) {
   1.462          *bufp = SDL_tolower(*bufp);
   1.463 -	++bufp;
   1.464 +        ++bufp;
   1.465      }
   1.466      return string;
   1.467  }
   1.468  #endif
   1.469  
   1.470  #ifndef HAVE_STRCHR
   1.471 -char *SDL_strchr(const char *string, int c)
   1.472 +char *
   1.473 +SDL_strchr(const char *string, int c)
   1.474  {
   1.475 -    while ( *string ) {
   1.476 -        if ( *string == c ) {
   1.477 -            return (char *)string;
   1.478 +    while (*string) {
   1.479 +        if (*string == c) {
   1.480 +            return (char *) string;
   1.481          }
   1.482 -	++string;
   1.483 +        ++string;
   1.484      }
   1.485      return NULL;
   1.486  }
   1.487  #endif
   1.488  
   1.489  #ifndef HAVE_STRRCHR
   1.490 -char *SDL_strrchr(const char *string, int c)
   1.491 +char *
   1.492 +SDL_strrchr(const char *string, int c)
   1.493  {
   1.494      const char *bufp = string + SDL_strlen(string) - 1;
   1.495 -    while ( bufp >= string ) {
   1.496 -        if ( *bufp == c ) {
   1.497 -            return (char *)bufp;
   1.498 +    while (bufp >= string) {
   1.499 +        if (*bufp == c) {
   1.500 +            return (char *) bufp;
   1.501          }
   1.502 -	--bufp;
   1.503 +        --bufp;
   1.504      }
   1.505      return NULL;
   1.506  }
   1.507  #endif
   1.508  
   1.509  #ifndef HAVE_STRSTR
   1.510 -char *SDL_strstr(const char *haystack, const char *needle)
   1.511 +char *
   1.512 +SDL_strstr(const char *haystack, const char *needle)
   1.513  {
   1.514      size_t length = SDL_strlen(needle);
   1.515 -    while ( *haystack ) {
   1.516 -        if ( SDL_strncmp(haystack, needle, length) == 0 ) {
   1.517 -            return (char *)haystack;
   1.518 +    while (*haystack) {
   1.519 +        if (SDL_strncmp(haystack, needle, length) == 0) {
   1.520 +            return (char *) haystack;
   1.521          }
   1.522 -	++haystack;
   1.523 +        ++haystack;
   1.524      }
   1.525      return NULL;
   1.526  }
   1.527 @@ -454,16 +474,17 @@
   1.528  #endif /* ntoa() conversion table */
   1.529  
   1.530  #ifndef HAVE__LTOA
   1.531 -char *SDL_ltoa(long value, char *string, int radix)
   1.532 +char *
   1.533 +SDL_ltoa(long value, char *string, int radix)
   1.534  {
   1.535      char *bufp = string;
   1.536  
   1.537 -    if ( value < 0 ) {
   1.538 +    if (value < 0) {
   1.539          *bufp++ = '-';
   1.540          value = -value;
   1.541      }
   1.542 -    if ( value ) {
   1.543 -        while ( value > 0 ) {
   1.544 +    if (value) {
   1.545 +        while (value > 0) {
   1.546              *bufp++ = ntoa_table[value % radix];
   1.547              value /= radix;
   1.548          }
   1.549 @@ -473,8 +494,8 @@
   1.550      *bufp = '\0';
   1.551  
   1.552      /* The numbers went into the string backwards. :) */
   1.553 -    if ( *string == '-' ) {
   1.554 -        SDL_strrev(string+1);
   1.555 +    if (*string == '-') {
   1.556 +        SDL_strrev(string + 1);
   1.557      } else {
   1.558          SDL_strrev(string);
   1.559      }
   1.560 @@ -484,12 +505,13 @@
   1.561  #endif
   1.562  
   1.563  #ifndef HAVE__ULTOA
   1.564 -char *SDL_ultoa(unsigned long value, char *string, int radix)
   1.565 +char *
   1.566 +SDL_ultoa(unsigned long value, char *string, int radix)
   1.567  {
   1.568      char *bufp = string;
   1.569  
   1.570 -    if ( value ) {
   1.571 -        while ( value > 0 ) {
   1.572 +    if (value) {
   1.573 +        while (value > 0) {
   1.574              *bufp++ = ntoa_table[value % radix];
   1.575              value /= radix;
   1.576          }
   1.577 @@ -506,13 +528,14 @@
   1.578  #endif
   1.579  
   1.580  #ifndef HAVE_STRTOL
   1.581 -long SDL_strtol(const char *string, char **endp, int base)
   1.582 +long
   1.583 +SDL_strtol(const char *string, char **endp, int base)
   1.584  {
   1.585      size_t len;
   1.586      long value;
   1.587  
   1.588 -    if ( !base ) {
   1.589 -        if ( (SDL_strlen(string) > 2) && (SDL_strncmp(string, "0x", 2) == 0) ) {
   1.590 +    if (!base) {
   1.591 +        if ((SDL_strlen(string) > 2) && (SDL_strncmp(string, "0x", 2) == 0)) {
   1.592              base = 16;
   1.593          } else {
   1.594              base = 10;
   1.595 @@ -520,21 +543,22 @@
   1.596      }
   1.597  
   1.598      len = SDL_ScanLong(string, base, &value);
   1.599 -    if ( endp ) {
   1.600 -        *endp = (char *)string + len;
   1.601 +    if (endp) {
   1.602 +        *endp = (char *) string + len;
   1.603      }
   1.604      return value;
   1.605  }
   1.606  #endif
   1.607  
   1.608  #ifndef HAVE_STRTOUL
   1.609 -unsigned long SDL_strtoul(const char *string, char **endp, int base)
   1.610 +unsigned long
   1.611 +SDL_strtoul(const char *string, char **endp, int base)
   1.612  {
   1.613      size_t len;
   1.614      unsigned long value;
   1.615  
   1.616 -    if ( !base ) {
   1.617 -        if ( (SDL_strlen(string) > 2) && (SDL_strncmp(string, "0x", 2) == 0) ) {
   1.618 +    if (!base) {
   1.619 +        if ((SDL_strlen(string) > 2) && (SDL_strncmp(string, "0x", 2) == 0)) {
   1.620              base = 16;
   1.621          } else {
   1.622              base = 10;
   1.623 @@ -542,8 +566,8 @@
   1.624      }
   1.625  
   1.626      len = SDL_ScanUnsignedLong(string, base, &value);
   1.627 -    if ( endp ) {
   1.628 -        *endp = (char *)string + len;
   1.629 +    if (endp) {
   1.630 +        *endp = (char *) string + len;
   1.631      }
   1.632      return value;
   1.633  }
   1.634 @@ -552,16 +576,17 @@
   1.635  #ifdef SDL_HAS_64BIT_TYPE
   1.636  
   1.637  #ifndef HAVE__I64TOA
   1.638 -char *SDL_lltoa(Sint64 value, char *string, int radix)
   1.639 +char *
   1.640 +SDL_lltoa(Sint64 value, char *string, int radix)
   1.641  {
   1.642      char *bufp = string;
   1.643  
   1.644 -    if ( value < 0 ) {
   1.645 +    if (value < 0) {
   1.646          *bufp++ = '-';
   1.647          value = -value;
   1.648      }
   1.649 -    if ( value ) {
   1.650 -        while ( value > 0 ) {
   1.651 +    if (value) {
   1.652 +        while (value > 0) {
   1.653              *bufp++ = ntoa_table[value % radix];
   1.654              value /= radix;
   1.655          }
   1.656 @@ -571,8 +596,8 @@
   1.657      *bufp = '\0';
   1.658  
   1.659      /* The numbers went into the string backwards. :) */
   1.660 -    if ( *string == '-' ) {
   1.661 -        SDL_strrev(string+1);
   1.662 +    if (*string == '-') {
   1.663 +        SDL_strrev(string + 1);
   1.664      } else {
   1.665          SDL_strrev(string);
   1.666      }
   1.667 @@ -582,12 +607,13 @@
   1.668  #endif
   1.669  
   1.670  #ifndef HAVE__UI64TOA
   1.671 -char *SDL_ulltoa(Uint64 value, char *string, int radix)
   1.672 +char *
   1.673 +SDL_ulltoa(Uint64 value, char *string, int radix)
   1.674  {
   1.675      char *bufp = string;
   1.676  
   1.677 -    if ( value ) {
   1.678 -        while ( value > 0 ) {
   1.679 +    if (value) {
   1.680 +        while (value > 0) {
   1.681              *bufp++ = ntoa_table[value % radix];
   1.682              value /= radix;
   1.683          }
   1.684 @@ -604,13 +630,14 @@
   1.685  #endif
   1.686  
   1.687  #ifndef HAVE_STRTOLL
   1.688 -Sint64 SDL_strtoll(const char *string, char **endp, int base)
   1.689 +Sint64
   1.690 +SDL_strtoll(const char *string, char **endp, int base)
   1.691  {
   1.692      size_t len;
   1.693      Sint64 value;
   1.694  
   1.695 -    if ( !base ) {
   1.696 -        if ( (SDL_strlen(string) > 2) && (SDL_strncmp(string, "0x", 2) == 0) ) {
   1.697 +    if (!base) {
   1.698 +        if ((SDL_strlen(string) > 2) && (SDL_strncmp(string, "0x", 2) == 0)) {
   1.699              base = 16;
   1.700          } else {
   1.701              base = 10;
   1.702 @@ -618,21 +645,22 @@
   1.703      }
   1.704  
   1.705      len = SDL_ScanLongLong(string, base, &value);
   1.706 -    if ( endp ) {
   1.707 -        *endp = (char *)string + len;
   1.708 +    if (endp) {
   1.709 +        *endp = (char *) string + len;
   1.710      }
   1.711      return value;
   1.712  }
   1.713  #endif
   1.714  
   1.715  #ifndef HAVE_STRTOULL
   1.716 -Uint64 SDL_strtoull(const char *string, char **endp, int base)
   1.717 +Uint64
   1.718 +SDL_strtoull(const char *string, char **endp, int base)
   1.719  {
   1.720      size_t len;
   1.721      Uint64 value;
   1.722  
   1.723 -    if ( !base ) {
   1.724 -        if ( (SDL_strlen(string) > 2) && (SDL_strncmp(string, "0x", 2) == 0) ) {
   1.725 +    if (!base) {
   1.726 +        if ((SDL_strlen(string) > 2) && (SDL_strncmp(string, "0x", 2) == 0)) {
   1.727              base = 16;
   1.728          } else {
   1.729              base = 10;
   1.730 @@ -640,8 +668,8 @@
   1.731      }
   1.732  
   1.733      len = SDL_ScanUnsignedLongLong(string, base, &value);
   1.734 -    if ( endp ) {
   1.735 -        *endp = (char *)string + len;
   1.736 +    if (endp) {
   1.737 +        *endp = (char *) string + len;
   1.738      }
   1.739      return value;
   1.740  }
   1.741 @@ -650,104 +678,111 @@
   1.742  #endif /* SDL_HAS_64BIT_TYPE */
   1.743  
   1.744  #ifndef HAVE_STRTOD
   1.745 -double SDL_strtod(const char *string, char **endp)
   1.746 +double
   1.747 +SDL_strtod(const char *string, char **endp)
   1.748  {
   1.749      size_t len;
   1.750      double value;
   1.751  
   1.752      len = SDL_ScanFloat(string, &value);
   1.753 -    if ( endp ) {
   1.754 -        *endp = (char *)string + len;
   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 +    while (*str1 && *str2) {
   1.811          a = SDL_tolower(*str1);
   1.812          b = SDL_tolower(*str2);
   1.813 -        if ( a != b )
   1.814 +        if (a != b)
   1.815              break;
   1.816          ++str1;
   1.817          ++str2;
   1.818      }
   1.819 -    return (int)((unsigned char)a - (unsigned char)b);
   1.820 +    return (int) ((unsigned char) a - (unsigned char) b);
   1.821  }
   1.822  #endif
   1.823  
   1.824  #if !defined(HAVE_STRNCASECMP) && !defined(HAVE__STRNICMP)
   1.825 -int SDL_strncasecmp(const char *str1, const char *str2, size_t maxlen)
   1.826 +int
   1.827 +SDL_strncasecmp(const char *str1, const char *str2, size_t maxlen)
   1.828  {
   1.829      char a = 0;
   1.830      char b = 0;
   1.831 -    while ( *str1 && *str2 && maxlen ) {
   1.832 +    while (*str1 && *str2 && maxlen) {
   1.833          a = SDL_tolower(*str1);
   1.834          b = SDL_tolower(*str2);
   1.835 -        if ( a != b )
   1.836 +        if (a != b)
   1.837              break;
   1.838          ++str1;
   1.839          ++str2;
   1.840          --maxlen;
   1.841      }
   1.842 -    return (int)((unsigned char)a - (unsigned char)b);
   1.843 +    return (int) ((unsigned char) a - (unsigned char) b);
   1.844  }
   1.845  #endif
   1.846  
   1.847  #ifndef HAVE_SSCANF
   1.848 -int SDL_sscanf(const char *text, const char *fmt, ...)
   1.849 +int
   1.850 +SDL_sscanf(const char *text, const char *fmt, ...)
   1.851  {
   1.852      va_list ap;
   1.853      int retval = 0;
   1.854  
   1.855      va_start(ap, fmt);
   1.856 -    while ( *fmt ) {
   1.857 -        if ( *fmt == ' ' ) {
   1.858 -            while ( SDL_isspace(*text) ) {
   1.859 +    while (*fmt) {
   1.860 +        if (*fmt == ' ') {
   1.861 +            while (SDL_isspace(*text)) {
   1.862                  ++text;
   1.863              }
   1.864              ++fmt;
   1.865              continue;
   1.866          }
   1.867 -        if ( *fmt == '%' ) {
   1.868 +        if (*fmt == '%') {
   1.869              SDL_bool done = SDL_FALSE;
   1.870              long count = 0;
   1.871              int radix = 10;
   1.872 -            enum {
   1.873 +            enum
   1.874 +            {
   1.875                  DO_SHORT,
   1.876                  DO_INT,
   1.877                  DO_LONG,
   1.878 @@ -756,31 +791,31 @@
   1.879              SDL_bool suppress = SDL_FALSE;
   1.880  
   1.881              ++fmt;
   1.882 -            if ( *fmt == '%' ) {
   1.883 -                if ( *text == '%' ) {
   1.884 +            if (*fmt == '%') {
   1.885 +                if (*text == '%') {
   1.886                      ++text;
   1.887                      ++fmt;
   1.888                      continue;
   1.889                  }
   1.890                  break;
   1.891              }
   1.892 -            if ( *fmt == '*' ) {
   1.893 +            if (*fmt == '*') {
   1.894                  suppress = SDL_TRUE;
   1.895                  ++fmt;
   1.896              }
   1.897              fmt += SDL_ScanLong(fmt, 10, &count);
   1.898  
   1.899 -            if ( *fmt == 'c' ) {
   1.900 -                if ( ! count ) {
   1.901 +            if (*fmt == 'c') {
   1.902 +                if (!count) {
   1.903                      count = 1;
   1.904                  }
   1.905 -                if ( suppress ) {
   1.906 -                    while ( count-- ) {
   1.907 +                if (suppress) {
   1.908 +                    while (count--) {
   1.909                          ++text;
   1.910                      }
   1.911                  } else {
   1.912 -                    char *valuep = va_arg(ap, char*);
   1.913 -                    while ( count-- ) {
   1.914 +                    char *valuep = va_arg(ap, char *);
   1.915 +                    while (count--) {
   1.916                          *valuep++ = *text++;
   1.917                      }
   1.918                      ++retval;
   1.919 @@ -788,200 +823,204 @@
   1.920                  continue;
   1.921              }
   1.922  
   1.923 -            while ( SDL_isspace(*text) ) {
   1.924 +            while (SDL_isspace(*text)) {
   1.925                  ++text;
   1.926              }
   1.927  
   1.928              /* FIXME: implement more of the format specifiers */
   1.929              while (!done) {
   1.930 -                switch(*fmt) {
   1.931 -                    case '*':
   1.932 -                        suppress = SDL_TRUE;
   1.933 -                        break;
   1.934 -                    case 'h':
   1.935 -                        if ( inttype > DO_SHORT ) {
   1.936 -                            ++inttype;
   1.937 +                switch (*fmt) {
   1.938 +                case '*':
   1.939 +                    suppress = SDL_TRUE;
   1.940 +                    break;
   1.941 +                case 'h':
   1.942 +                    if (inttype > DO_SHORT) {
   1.943 +                        ++inttype;
   1.944 +                    }
   1.945 +                    break;
   1.946 +                case 'l':
   1.947 +                    if (inttype < DO_LONGLONG) {
   1.948 +                        ++inttype;
   1.949 +                    }
   1.950 +                    break;
   1.951 +                case 'I':
   1.952 +                    if (SDL_strncmp(fmt, "I64", 3) == 0) {
   1.953 +                        fmt += 2;
   1.954 +                        inttype = DO_LONGLONG;
   1.955 +                    }
   1.956 +                    break;
   1.957 +                case 'i':
   1.958 +                    {
   1.959 +                        int index = 0;
   1.960 +                        if (text[index] == '-') {
   1.961 +                            ++index;
   1.962 +                        }
   1.963 +                        if (text[index] == '0') {
   1.964 +                            if (SDL_tolower(text[index + 1]) == 'x') {
   1.965 +                                radix = 16;
   1.966 +                            } else {
   1.967 +                                radix = 8;
   1.968 +                            }
   1.969                          }
   1.970 -                        break;
   1.971 -                    case 'l':
   1.972 -                        if ( inttype < DO_LONGLONG ) {
   1.973 -                            ++inttype;
   1.974 +                    }
   1.975 +                    /* Fall through to %d handling */
   1.976 +                case 'd':
   1.977 +#ifdef SDL_HAS_64BIT_TYPE
   1.978 +                    if (inttype == DO_LONGLONG) {
   1.979 +                        Sint64 value;
   1.980 +                        text += SDL_ScanLongLong(text, radix, &value);
   1.981 +                        if (!suppress) {
   1.982 +                            Sint64 *valuep = va_arg(ap, Sint64 *);
   1.983 +                            *valuep = value;
   1.984 +                            ++retval;
   1.985 +                        }
   1.986 +                    } else
   1.987 +#endif /* SDL_HAS_64BIT_TYPE */
   1.988 +                    {
   1.989 +                        long value;
   1.990 +                        text += SDL_ScanLong(text, radix, &value);
   1.991 +                        if (!suppress) {
   1.992 +                            switch (inttype) {
   1.993 +                            case DO_SHORT:
   1.994 +                                {
   1.995 +                                    short *valuep = va_arg(ap, short *);
   1.996 +                                    *valuep = (short) value;
   1.997 +                                }
   1.998 +                                break;
   1.999 +                            case DO_INT:
  1.1000 +                                {
  1.1001 +                                    int *valuep = va_arg(ap, int *);
  1.1002 +                                    *valuep = (int) value;
  1.1003 +                                }
  1.1004 +                                break;
  1.1005 +                            case DO_LONG:
  1.1006 +                                {
  1.1007 +                                    long *valuep = va_arg(ap, long *);
  1.1008 +                                    *valuep = value;
  1.1009 +                                }
  1.1010 +                                break;
  1.1011 +                            case DO_LONGLONG:
  1.1012 +                                /* Handled above */
  1.1013 +                                break;
  1.1014 +                            }
  1.1015 +                            ++retval;
  1.1016                          }
  1.1017 -                        break;
  1.1018 -                    case 'I':
  1.1019 -                        if ( SDL_strncmp(fmt, "I64", 3) == 0 ) {
  1.1020 -                            fmt += 2;
  1.1021 -                            inttype = DO_LONGLONG;
  1.1022 +                    }
  1.1023 +                    done = SDL_TRUE;
  1.1024 +                    break;
  1.1025 +                case 'o':
  1.1026 +                    if (radix == 10) {
  1.1027 +                        radix = 8;
  1.1028 +                    }
  1.1029 +                    /* Fall through to unsigned handling */
  1.1030 +                case 'x':
  1.1031 +                case 'X':
  1.1032 +                    if (radix == 10) {
  1.1033 +                        radix = 16;
  1.1034 +                    }
  1.1035 +                    /* Fall through to unsigned handling */
  1.1036 +                case 'u':
  1.1037 +#ifdef SDL_HAS_64BIT_TYPE
  1.1038 +                    if (inttype == DO_LONGLONG) {
  1.1039 +                        Uint64 value;
  1.1040 +                        text += SDL_ScanUnsignedLongLong(text, radix, &value);
  1.1041 +                        if (!suppress) {
  1.1042 +                            Uint64 *valuep = va_arg(ap, Uint64 *);
  1.1043 +                            *valuep = value;
  1.1044 +                            ++retval;
  1.1045                          }
  1.1046 -                        break;
  1.1047 -                    case 'i':
  1.1048 -                        {
  1.1049 -                            int index = 0;
  1.1050 -                            if ( text[index] == '-' ) {
  1.1051 -                                ++index;
  1.1052 +                    } else
  1.1053 +#endif /* SDL_HAS_64BIT_TYPE */
  1.1054 +                    {
  1.1055 +                        unsigned long value;
  1.1056 +                        text += SDL_ScanUnsignedLong(text, radix, &value);
  1.1057 +                        if (!suppress) {
  1.1058 +                            switch (inttype) {
  1.1059 +                            case DO_SHORT:
  1.1060 +                                {
  1.1061 +                                    short *valuep = va_arg(ap, short *);
  1.1062 +                                    *valuep = (short) value;
  1.1063 +                                }
  1.1064 +                                break;
  1.1065 +                            case DO_INT:
  1.1066 +                                {
  1.1067 +                                    int *valuep = va_arg(ap, int *);
  1.1068 +                                    *valuep = (int) value;
  1.1069 +                                }
  1.1070 +                                break;
  1.1071 +                            case DO_LONG:
  1.1072 +                                {
  1.1073 +                                    long *valuep = va_arg(ap, long *);
  1.1074 +                                    *valuep = value;
  1.1075 +                                }
  1.1076 +                                break;
  1.1077 +                            case DO_LONGLONG:
  1.1078 +                                /* Handled above */
  1.1079 +                                break;
  1.1080                              }
  1.1081 -                            if ( text[index] == '0' ) {
  1.1082 -                                if ( SDL_tolower(text[index+1]) == 'x' ) {
  1.1083 -                                    radix = 16;
  1.1084 -                                } else {
  1.1085 -                                    radix = 8;
  1.1086 +                            ++retval;
  1.1087 +                        }
  1.1088 +                    }
  1.1089 +                    done = SDL_TRUE;
  1.1090 +                    break;
  1.1091 +                case 'p':
  1.1092 +                    {
  1.1093 +                        uintptr_t value;
  1.1094 +                        text += SDL_ScanUintPtrT(text, 16, &value);
  1.1095 +                        if (!suppress) {
  1.1096 +                            void **valuep = va_arg(ap, void **);
  1.1097 +                            *valuep = (void *) value;
  1.1098 +                            ++retval;
  1.1099 +                        }
  1.1100 +                    }
  1.1101 +                    done = SDL_TRUE;
  1.1102 +                    break;
  1.1103 +                case 'f':
  1.1104 +                    {
  1.1105 +                        double value;
  1.1106 +                        text += SDL_ScanFloat(text, &value);
  1.1107 +                        if (!suppress) {
  1.1108 +                            float *valuep = va_arg(ap, float *);
  1.1109 +                            *valuep = (float) value;
  1.1110 +                            ++retval;
  1.1111 +                        }
  1.1112 +                    }
  1.1113 +                    done = SDL_TRUE;
  1.1114 +                    break;
  1.1115 +                case 's':
  1.1116 +                    if (suppress) {
  1.1117 +                        while (!SDL_isspace(*text)) {
  1.1118 +                            ++text;
  1.1119 +                            if (count) {
  1.1120 +                                if (--count == 0) {
  1.1121 +                                    break;
  1.1122                                  }
  1.1123                              }
  1.1124                          }
  1.1125 -                        /* Fall through to %d handling */
  1.1126 -                    case 'd':
  1.1127 -#ifdef SDL_HAS_64BIT_TYPE
  1.1128 -                        if ( inttype == DO_LONGLONG ) {
  1.1129 -                            Sint64 value;
  1.1130 -                            text += SDL_ScanLongLong(text, radix, &value);
  1.1131 -                            if ( ! suppress ) {
  1.1132 -                                Sint64 *valuep = va_arg(ap, Sint64*);
  1.1133 -                                *valuep = value;
  1.1134 -                                ++retval;
  1.1135 -                            }
  1.1136 -                        }
  1.1137 -                        else
  1.1138 -#endif /* SDL_HAS_64BIT_TYPE */
  1.1139 -                        {
  1.1140 -                            long value;
  1.1141 -                            text += SDL_ScanLong(text, radix, &value);
  1.1142 -                            if ( ! suppress ) {
  1.1143 -                                switch (inttype) {
  1.1144 -                                    case DO_SHORT:
  1.1145 -                                        { short* valuep = va_arg(ap, short*);
  1.1146 -                                            *valuep = (short)value;
  1.1147 -                                        }
  1.1148 -                                        break;
  1.1149 -                                    case DO_INT:
  1.1150 -                                        { int* valuep = va_arg(ap, int*);
  1.1151 -                                            *valuep = (int)value;
  1.1152 -                                        }
  1.1153 -                                        break;
  1.1154 -                                    case DO_LONG:
  1.1155 -                                        { long* valuep = va_arg(ap, long*);
  1.1156 -                                            *valuep = value;
  1.1157 -                                        }
  1.1158 -                                        break;
  1.1159 -                                    case DO_LONGLONG:
  1.1160 -                                        /* Handled above */
  1.1161 -                                        break;
  1.1162 +                    } else {
  1.1163 +                        char *valuep = va_arg(ap, char *);
  1.1164 +                        while (!SDL_isspace(*text)) {
  1.1165 +                            *valuep++ = *text++;
  1.1166 +                            if (count) {
  1.1167 +                                if (--count == 0) {
  1.1168 +                                    break;
  1.1169                                  }
  1.1170 -                                ++retval;
  1.1171 -                            }
  1.1172 -                        }
  1.1173 -                        done = SDL_TRUE;
  1.1174 -                        break;
  1.1175 -                    case 'o':
  1.1176 -                        if ( radix == 10 ) {
  1.1177 -                            radix = 8;
  1.1178 -                        }
  1.1179 -                        /* Fall through to unsigned handling */
  1.1180 -                    case 'x':
  1.1181 -                    case 'X':
  1.1182 -                        if ( radix == 10 ) {
  1.1183 -                            radix = 16;
  1.1184 -                        }
  1.1185 -                        /* Fall through to unsigned handling */
  1.1186 -                    case 'u':
  1.1187 -#ifdef SDL_HAS_64BIT_TYPE
  1.1188 -                        if ( inttype == DO_LONGLONG ) {
  1.1189 -                            Uint64 value;
  1.1190 -                            text += SDL_ScanUnsignedLongLong(text, radix, &value);
  1.1191 -                            if ( ! suppress ) {
  1.1192 -                                Uint64 *valuep = va_arg(ap, Uint64*);
  1.1193 -                                *valuep = value;
  1.1194 -                                ++retval;
  1.1195                              }
  1.1196                          }
  1.1197 -                        else
  1.1198 -#endif /* SDL_HAS_64BIT_TYPE */
  1.1199 -                        {
  1.1200 -                            unsigned long value;
  1.1201 -                            text += SDL_ScanUnsignedLong(text, radix, &value);
  1.1202 -                            if ( ! suppress ) {
  1.1203 -                                switch (inttype) {
  1.1204 -                                    case DO_SHORT:
  1.1205 -                                        { short* valuep = va_arg(ap, short*);
  1.1206 -                                            *valuep = (short)value;
  1.1207 -                                        }
  1.1208 -                                        break;
  1.1209 -                                    case DO_INT:
  1.1210 -                                        { int* valuep = va_arg(ap, int*);
  1.1211 -                                            *valuep = (int)value;
  1.1212 -                                        }
  1.1213 -                                        break;
  1.1214 -                                    case DO_LONG:
  1.1215 -                                        { long* valuep = va_arg(ap, long*);
  1.1216 -                                            *valuep = value;
  1.1217 -                                        }
  1.1218 -                                        break;
  1.1219 -                                    case DO_LONGLONG:
  1.1220 -                                        /* Handled above */
  1.1221 -                                        break;
  1.1222 -                                }
  1.1223 -                                ++retval;
  1.1224 -                            }
  1.1225 -                        }
  1.1226 -                        done = SDL_TRUE;
  1.1227 -                        break;
  1.1228 -                    case 'p':
  1.1229 -                        {
  1.1230 -                            uintptr_t value;
  1.1231 -                            text += SDL_ScanUintPtrT(text, 16, &value);
  1.1232 -                            if ( ! suppress ) {
  1.1233 -                                void** valuep = va_arg(ap, void**);
  1.1234 -                                *valuep = (void*)value;
  1.1235 -                                ++retval;
  1.1236 -                            }
  1.1237 -                        }
  1.1238 -                        done = SDL_TRUE;
  1.1239 -                        break;
  1.1240 -                    case 'f':
  1.1241 -                        {
  1.1242 -                            double value;
  1.1243 -                            text += SDL_ScanFloat(text, &value);
  1.1244 -                            if ( ! suppress ) {
  1.1245 -                                float* valuep = va_arg(ap, float*);
  1.1246 -                                *valuep = (float)value;
  1.1247 -                                ++retval;
  1.1248 -                            }
  1.1249 -                        }
  1.1250 -                        done = SDL_TRUE;
  1.1251 -                        break;
  1.1252 -                    case 's':
  1.1253 -                        if ( suppress ) {
  1.1254 -                            while ( !SDL_isspace(*text) ) {
  1.1255 -                                ++text;
  1.1256 -                                if ( count ) {
  1.1257 -                                    if ( --count == 0 ) {
  1.1258 -                                        break;
  1.1259 -                                    }
  1.1260 -                                }
  1.1261 -                            }
  1.1262 -                        } else {
  1.1263 -                            char *valuep = va_arg(ap, char*);
  1.1264 -                            while ( !SDL_isspace(*text) ) {
  1.1265 -                                *valuep++ = *text++;
  1.1266 -                                if ( count ) {
  1.1267 -                                    if ( --count == 0 ) {
  1.1268 -                                        break;
  1.1269 -                                    }
  1.1270 -                                }
  1.1271 -                            }
  1.1272 -                            *valuep = '\0';
  1.1273 -                            ++retval;
  1.1274 -                        }
  1.1275 -                        done = SDL_TRUE;
  1.1276 -                        break;
  1.1277 -                    default:
  1.1278 -                        done = SDL_TRUE;
  1.1279 -                        break;
  1.1280 +                        *valuep = '\0';
  1.1281 +                        ++retval;
  1.1282 +                    }
  1.1283 +                    done = SDL_TRUE;
  1.1284 +                    break;
  1.1285 +                default:
  1.1286 +                    done = SDL_TRUE;
  1.1287 +                    break;
  1.1288                  }
  1.1289                  ++fmt;
  1.1290              }
  1.1291              continue;
  1.1292          }
  1.1293 -        if ( *text == *fmt ) {
  1.1294 +        if (*text == *fmt) {
  1.1295              ++text;
  1.1296              ++fmt;
  1.1297              continue;
  1.1298 @@ -996,7 +1035,8 @@
  1.1299  #endif
  1.1300  
  1.1301  #ifndef HAVE_SNPRINTF
  1.1302 -int SDL_snprintf(char *text, size_t maxlen, const char *fmt, ...)
  1.1303 +int
  1.1304 +SDL_snprintf(char *text, size_t maxlen, const char *fmt, ...)
  1.1305  {
  1.1306      va_list ap;
  1.1307      int retval;
  1.1308 @@ -1010,92 +1050,101 @@
  1.1309  #endif
  1.1310  
  1.1311  #ifndef HAVE_VSNPRINTF
  1.1312 -static size_t SDL_PrintLong(char *text, long value, int radix, size_t maxlen)
  1.1313 +static size_t
  1.1314 +SDL_PrintLong(char *text, long value, int radix, size_t maxlen)
  1.1315  {
  1.1316      char num[130];
  1.1317      size_t size;
  1.1318  
  1.1319      SDL_ltoa(value, num, radix);
  1.1320      size = SDL_strlen(num);
  1.1321 -    if ( size >= maxlen ) {
  1.1322 -        size = maxlen-1;
  1.1323 +    if (size >= maxlen) {
  1.1324 +        size = maxlen - 1;
  1.1325      }
  1.1326 -    SDL_strlcpy(text, num, size+1);
  1.1327 +    SDL_strlcpy(text, num, size + 1);
  1.1328  
  1.1329      return size;
  1.1330  }
  1.1331 -static size_t SDL_PrintUnsignedLong(char *text, unsigned long value, int radix, size_t maxlen)
  1.1332 +
  1.1333 +static size_t
  1.1334 +SDL_PrintUnsignedLong(char *text, unsigned long value, int radix,
  1.1335 +                      size_t maxlen)
  1.1336  {
  1.1337      char num[130];
  1.1338      size_t size;
  1.1339  
  1.1340      SDL_ultoa(value, num, radix);
  1.1341      size = SDL_strlen(num);
  1.1342 -    if ( size >= maxlen ) {
  1.1343 -        size = maxlen-1;
  1.1344 +    if (size >= maxlen) {
  1.1345 +        size = maxlen - 1;
  1.1346      }
  1.1347 -    SDL_strlcpy(text, num, size+1);
  1.1348 +    SDL_strlcpy(text, num, size + 1);
  1.1349  
  1.1350      return size;
  1.1351  }
  1.1352 +
  1.1353  #ifdef SDL_HAS_64BIT_TYPE
  1.1354 -static size_t SDL_PrintLongLong(char *text, Sint64 value, int radix, size_t maxlen)
  1.1355 +static size_t
  1.1356 +SDL_PrintLongLong(char *text, Sint64 value, int radix, size_t maxlen)
  1.1357  {
  1.1358      char num[130];
  1.1359      size_t size;
  1.1360  
  1.1361      SDL_lltoa(value, num, radix);
  1.1362      size = SDL_strlen(num);
  1.1363 -    if ( size >= maxlen ) {
  1.1364 -        size = maxlen-1;
  1.1365 +    if (size >= maxlen) {
  1.1366 +        size = maxlen - 1;
  1.1367      }
  1.1368 -    SDL_strlcpy(text, num, size+1);
  1.1369 +    SDL_strlcpy(text, num, size + 1);
  1.1370  
  1.1371      return size;
  1.1372  }
  1.1373 -static size_t SDL_PrintUnsignedLongLong(char *text, Uint64 value, int radix, size_t maxlen)
  1.1374 +
  1.1375 +static size_t
  1.1376 +SDL_PrintUnsignedLongLong(char *text, Uint64 value, int radix, size_t maxlen)
  1.1377  {
  1.1378      char num[130];
  1.1379      size_t size;
  1.1380  
  1.1381      SDL_ulltoa(value, num, radix);
  1.1382      size = SDL_strlen(num);
  1.1383 -    if ( size >= maxlen ) {
  1.1384 -        size = maxlen-1;
  1.1385 +    if (size >= maxlen) {
  1.1386 +        size = maxlen - 1;
  1.1387      }
  1.1388 -    SDL_strlcpy(text, num, size+1);
  1.1389 +    SDL_strlcpy(text, num, size + 1);
  1.1390  
  1.1391      return size;
  1.1392  }
  1.1393  #endif /* SDL_HAS_64BIT_TYPE */
  1.1394 -static size_t SDL_PrintFloat(char *text, double arg, size_t maxlen)
  1.1395 +static size_t
  1.1396 +SDL_PrintFloat(char *text, double arg, size_t maxlen)
  1.1397  {
  1.1398      char *textstart = text;
  1.1399 -    if ( arg ) {
  1.1400 +    if (arg) {
  1.1401          /* This isn't especially accurate, but hey, it's easy. :) */
  1.1402          const double precision = 0.00000001;
  1.1403          size_t len;
  1.1404          unsigned long value;
  1.1405  
  1.1406 -        if ( arg < 0 ) {
  1.1407 +        if (arg < 0) {
  1.1408              *text++ = '-';
  1.1409              --maxlen;
  1.1410              arg = -arg;
  1.1411          }
  1.1412 -        value = (unsigned long)arg;
  1.1413 +        value = (unsigned long) arg;
  1.1414          len = SDL_PrintUnsignedLong(text, value, 10, maxlen);
  1.1415          text += len;
  1.1416          maxlen -= len;
  1.1417          arg -= value;
  1.1418 -        if ( arg > precision && maxlen ) {
  1.1419 +        if (arg > precision && maxlen) {
  1.1420              int mult = 10;
  1.1421              *text++ = '.';
  1.1422 -            while ( (arg > precision) && maxlen ) {
  1.1423 -                value = (unsigned long)(arg * mult);
  1.1424 +            while ((arg > precision) && maxlen) {
  1.1425 +                value = (unsigned long) (arg * mult);
  1.1426                  len = SDL_PrintUnsignedLong(text, value, 10, maxlen);
  1.1427                  text += len;
  1.1428                  maxlen -= len;
  1.1429 -                arg -= (double)value / mult;
  1.1430 +                arg -= (double) value / mult;
  1.1431                  mult *= 10;
  1.1432              }
  1.1433          }
  1.1434 @@ -1104,28 +1153,33 @@
  1.1435      }
  1.1436      return (text - textstart);
  1.1437  }
  1.1438 -static size_t SDL_PrintString(char *text, const char *string, size_t maxlen)
  1.1439 +
  1.1440 +static size_t
  1.1441 +SDL_PrintString(char *text, const char *string, size_t maxlen)
  1.1442  {
  1.1443      char *textstart = text;
  1.1444 -    while ( *string && maxlen-- ) {
  1.1445 +    while (*string && maxlen--) {
  1.1446          *text++ = *string++;
  1.1447      }
  1.1448      return (text - textstart);
  1.1449  }
  1.1450 -int SDL_vsnprintf(char *text, size_t maxlen, const char *fmt, va_list ap)
  1.1451 +
  1.1452 +int
  1.1453 +SDL_vsnprintf(char *text, size_t maxlen, const char *fmt, va_list ap)
  1.1454  {
  1.1455      char *textstart = text;
  1.1456 -    if ( maxlen <= 0 ) {
  1.1457 +    if (maxlen <= 0) {
  1.1458          return 0;
  1.1459      }
  1.1460 -    --maxlen; /* For the trailing '\0' */
  1.1461 -    while ( *fmt && maxlen ) {
  1.1462 -        if ( *fmt == '%' ) {
  1.1463 +    --maxlen;                   /* For the trailing '\0' */
  1.1464 +    while (*fmt && maxlen) {
  1.1465 +        if (*fmt == '%') {
  1.1466              SDL_bool done = SDL_FALSE;
  1.1467              size_t len = 0;
  1.1468              SDL_bool do_lowercase = SDL_FALSE;
  1.1469              int radix = 10;
  1.1470 -            enum {
  1.1471 +            enum
  1.1472 +            {
  1.1473                  DO_INT,
  1.1474                  DO_LONG,
  1.1475                  DO_LONGLONG
  1.1476 @@ -1133,104 +1187,132 @@
  1.1477  
  1.1478              ++fmt;
  1.1479              /* FIXME: implement more of the format specifiers */
  1.1480 -            while ( *fmt == '.' || (*fmt >= '0' && *fmt <= '9') ) {
  1.1481 +            while (*fmt == '.' || (*fmt >= '0' && *fmt <= '9')) {
  1.1482                  ++fmt;
  1.1483              }
  1.1484              while (!done) {
  1.1485 -                switch(*fmt) {
  1.1486 -                    case '%':
  1.1487 -                        *text = '%';
  1.1488 -                        len = 1;
  1.1489 -                        done = SDL_TRUE;
  1.1490 -                        break;
  1.1491 -                    case 'c':
  1.1492 -                        /* char is promoted to int when passed through (...) */
  1.1493 -                        *text = (char)va_arg(ap, int);
  1.1494 -                        len = 1;
  1.1495 -                        done = SDL_TRUE;
  1.1496 -                        break;
  1.1497 -                    case 'h':
  1.1498 -                        /* short is promoted to int when passed through (...) */
  1.1499 -                        break;
  1.1500 -                    case 'l':
  1.1501 -                        if ( inttype < DO_LONGLONG ) {
  1.1502 -                            ++inttype;
  1.1503 -                        }
  1.1504 +                switch (*fmt) {
  1.1505 +                case '%':
  1.1506 +                    *text = '%';
  1.1507 +                    len = 1;
  1.1508 +                    done = SDL_TRUE;
  1.1509 +                    break;
  1.1510 +                case 'c':
  1.1511 +                    /* char is promoted to int when passed through (...) */
  1.1512 +                    *text = (char) va_arg(ap, int);
  1.1513 +                    len = 1;
  1.1514 +                    done = SDL_TRUE;
  1.1515 +                    break;
  1.1516 +                case 'h':
  1.1517 +                    /* short is promoted to int when passed through (...) */
  1.1518 +                    break;
  1.1519 +                case 'l':
  1.1520 +                    if (inttype < DO_LONGLONG) {
  1.1521 +                        ++inttype;
  1.1522 +                    }
  1.1523 +                    break;
  1.1524 +                case 'I':
  1.1525 +                    if (SDL_strncmp(fmt, "I64", 3) == 0) {
  1.1526 +                        fmt += 2;
  1.1527 +                        inttype = DO_LONGLONG;
  1.1528 +                    }
  1.1529 +                    break;
  1.1530 +                case 'i':
  1.1531 +                case 'd':
  1.1532 +                    switch (inttype) {
  1.1533 +                    case DO_INT:
  1.1534 +                        len =
  1.1535 +                            SDL_PrintLong(text,
  1.1536 +                                          (long) va_arg(ap, int),
  1.1537 +                                          radix, maxlen);
  1.1538                          break;
  1.1539 -                    case 'I':
  1.1540 -                        if ( SDL_strncmp(fmt, "I64", 3) == 0 ) {
  1.1541 -                            fmt += 2;
  1.1542 -                            inttype = DO_LONGLONG;
  1.1543 -                        }
  1.1544 +                    case DO_LONG:
  1.1545 +                        len =
  1.1546 +                            SDL_PrintLong(text, va_arg(ap, long),
  1.1547 +                                          radix, maxlen);
  1.1548                          break;
  1.1549 -                    case 'i':
  1.1550 -                    case 'd':
  1.1551 -                        switch (inttype) {
  1.1552 -                            case DO_INT:
  1.1553 -                                len = SDL_PrintLong(text, (long)va_arg(ap, int), radix, maxlen);
  1.1554 -                                break;
  1.1555 -                            case DO_LONG:
  1.1556 -                                len = SDL_PrintLong(text, va_arg(ap, long), radix, maxlen);
  1.1557 -                                break;
  1.1558 -                            case DO_LONGLONG:
  1.1559 +                    case DO_LONGLONG:
  1.1560  #ifdef SDL_HAS_64BIT_TYPE
  1.1561 -                                len = SDL_PrintLongLong(text, va_arg(ap, Sint64), radix, maxlen);
  1.1562 +                        len =
  1.1563 +                            SDL_PrintLongLong(text,
  1.1564 +                                              va_arg(ap, Sint64),
  1.1565 +                                              radix, maxlen);
  1.1566  #else
  1.1567 -                                len = SDL_PrintLong(text, va_arg(ap, long), radix, maxlen);
  1.1568 +                        len =
  1.1569 +                            SDL_PrintLong(text, va_arg(ap, long),
  1.1570 +                                          radix, maxlen);
  1.1571  #endif
  1.1572 -                                break;
  1.1573 -                        }
  1.1574 -                        done = SDL_TRUE;
  1.1575                          break;
  1.1576 -                    case 'p':
  1.1577 -                    case 'x':
  1.1578 -                        do_lowercase = SDL_TRUE;
  1.1579 -                        /* Fall through to 'X' handling */
  1.1580 -                    case 'X':
  1.1581 -                        if ( radix == 10 ) {
  1.1582 -                            radix = 16;
  1.1583 -                        }
  1.1584 -                        if ( *fmt == 'p' ) {
  1.1585 -                            inttype = DO_LONG;
  1.1586 -                        }
  1.1587 -                        /* Fall through to unsigned handling */
  1.1588 -                    case 'o':
  1.1589 -                        if ( radix == 10 ) {
  1.1590 -                            radix = 8;
  1.1591 -                        }
  1.1592 -                        /* Fall through to unsigned handling */
  1.1593 -                    case 'u':
  1.1594 -                        switch (inttype) {
  1.1595 -                            case DO_INT:
  1.1596 -                                len = SDL_PrintUnsignedLong(text, (unsigned long)va_arg(ap, unsigned int), radix, maxlen);
  1.1597 -                                break;
  1.1598 -                            case DO_LONG:
  1.1599 -                                len = SDL_PrintUnsignedLong(text, va_arg(ap, unsigned long), radix, maxlen);
  1.1600 -                                break;
  1.1601 -                            case DO_LONGLONG:
  1.1602 +                    }
  1.1603 +                    done = SDL_TRUE;
  1.1604 +                    break;
  1.1605 +                case 'p':
  1.1606 +                case 'x':
  1.1607 +                    do_lowercase = SDL_TRUE;
  1.1608 +                    /* Fall through to 'X' handling */
  1.1609 +                case 'X':
  1.1610 +                    if (radix == 10) {
  1.1611 +                        radix = 16;
  1.1612 +                    }
  1.1613 +                    if (*fmt == 'p') {
  1.1614 +                        inttype = DO_LONG;
  1.1615 +                    }
  1.1616 +                    /* Fall through to unsigned handling */
  1.1617 +                case 'o':
  1.1618 +                    if (radix == 10) {
  1.1619 +                        radix = 8;
  1.1620 +                    }
  1.1621 +                    /* Fall through to unsigned handling */
  1.1622 +                case 'u':
  1.1623 +                    switch (inttype) {
  1.1624 +                    case DO_INT:
  1.1625 +                        len = SDL_PrintUnsignedLong(text, (unsigned long)
  1.1626 +                                                    va_arg(ap,
  1.1627 +                                                           unsigned
  1.1628 +                                                           int),
  1.1629 +                                                    radix, maxlen);
  1.1630 +                        break;
  1.1631 +                    case DO_LONG:
  1.1632 +                        len =
  1.1633 +                            SDL_PrintUnsignedLong(text,
  1.1634 +                                                  va_arg(ap,
  1.1635 +                                                         unsigned
  1.1636 +                                                         long),
  1.1637 +                                                  radix, maxlen);
  1.1638 +                        break;
  1.1639 +                    case DO_LONGLONG:
  1.1640  #ifdef SDL_HAS_64BIT_TYPE
  1.1641 -                                len = SDL_PrintUnsignedLongLong(text, va_arg(ap, Uint64), radix, maxlen);
  1.1642 +                        len =
  1.1643 +                            SDL_PrintUnsignedLongLong(text,
  1.1644 +                                                      va_arg(ap,
  1.1645 +                                                             Uint64),
  1.1646 +                                                      radix, maxlen);
  1.1647  #else
  1.1648 -                                len = SDL_PrintUnsignedLong(text, va_arg(ap, unsigned long), radix, maxlen);
  1.1649 +                        len =
  1.1650 +                            SDL_PrintUnsignedLong(text,
  1.1651 +                                                  va_arg(ap,
  1.1652 +                                                         unsigned
  1.1653 +                                                         long),
  1.1654 +                                                  radix, maxlen);
  1.1655  #endif
  1.1656 -                                break;
  1.1657 -                        }
  1.1658 -                        if ( do_lowercase ) {
  1.1659 -                            SDL_strlwr(text);
  1.1660 -                        }
  1.1661 -                        done = SDL_TRUE;
  1.1662                          break;
  1.1663 -                    case 'f':
  1.1664 -                        len = SDL_PrintFloat(text, va_arg(ap, double), maxlen);
  1.1665 -                        done = SDL_TRUE;
  1.1666 -                        break;
  1.1667 -                    case 's':
  1.1668 -                        len = SDL_PrintString(text, va_arg(ap, char*), maxlen);
  1.1669 -                        done = SDL_TRUE;
  1.1670 -                        break;
  1.1671 -                    default:
  1.1672 -                        done = SDL_TRUE;
  1.1673 -                        break;
  1.1674 +                    }
  1.1675 +                    if (do_lowercase) {
  1.1676 +                        SDL_strlwr(text);
  1.1677 +                    }
  1.1678 +                    done = SDL_TRUE;
  1.1679 +                    break;
  1.1680 +                case 'f':
  1.1681 +                    len = SDL_PrintFloat(text, va_arg(ap, double), maxlen);
  1.1682 +                    done = SDL_TRUE;
  1.1683 +                    break;
  1.1684 +                case 's':
  1.1685 +                    len = SDL_PrintString(text, va_arg(ap, char *), maxlen);
  1.1686 +                    done = SDL_TRUE;
  1.1687 +                    break;
  1.1688 +                default:
  1.1689 +                    done = SDL_TRUE;
  1.1690 +                    break;
  1.1691                  }
  1.1692                  ++fmt;
  1.1693              }
  1.1694 @@ -1246,3 +1328,4 @@
  1.1695      return (text - textstart);
  1.1696  }
  1.1697  #endif
  1.1698 +/* vi: set ts=4 sw=4 expandtab: */