src/SDL_error.c
branchSDL-1.3
changeset 1668 4da1ee79c9af
parent 1662 782fd950bd46
     1.1 --- a/src/SDL_error.c	Mon May 29 03:53:21 2006 +0000
     1.2 +++ b/src/SDL_error.c	Mon May 29 04:04:35 2006 +0000
     1.3 @@ -32,7 +32,7 @@
     1.4  static SDL_error SDL_global_error;
     1.5  #define SDL_GetErrBuf()	(&SDL_global_error)
     1.6  #else
     1.7 -extern SDL_error *SDL_GetErrBuf (void);
     1.8 +extern SDL_error *SDL_GetErrBuf(void);
     1.9  #endif /* SDL_THREADS_DISABLED */
    1.10  
    1.11  #define SDL_ERRBUFIZE	1024
    1.12 @@ -40,7 +40,7 @@
    1.13  /* Private functions */
    1.14  
    1.15  static const char *
    1.16 -SDL_LookupString (const char *key)
    1.17 +SDL_LookupString(const char *key)
    1.18  {
    1.19      /* FIXME: Add code to lookup key in language string hash-table */
    1.20      return key;
    1.21 @@ -49,17 +49,17 @@
    1.22  /* Public functions */
    1.23  
    1.24  void
    1.25 -SDL_SetError (const char *fmt, ...)
    1.26 +SDL_SetError(const char *fmt, ...)
    1.27  {
    1.28      va_list ap;
    1.29      SDL_error *error;
    1.30  
    1.31      /* Copy in the key, mark error as valid */
    1.32 -    error = SDL_GetErrBuf ();
    1.33 +    error = SDL_GetErrBuf();
    1.34      error->error = 1;
    1.35 -    SDL_strlcpy ((char *) error->key, fmt, sizeof (error->key));
    1.36 +    SDL_strlcpy((char *) error->key, fmt, sizeof(error->key));
    1.37  
    1.38 -    va_start (ap, fmt);
    1.39 +    va_start(ap, fmt);
    1.40      error->argc = 0;
    1.41      while (*fmt) {
    1.42          if (*fmt++ == '%') {
    1.43 @@ -77,22 +77,22 @@
    1.44              case 'o':
    1.45              case 'x':
    1.46              case 'X':
    1.47 -                error->args[error->argc++].value_i = va_arg (ap, int);
    1.48 +                error->args[error->argc++].value_i = va_arg(ap, int);
    1.49                  break;
    1.50              case 'f':
    1.51 -                error->args[error->argc++].value_f = va_arg (ap, double);
    1.52 +                error->args[error->argc++].value_f = va_arg(ap, double);
    1.53                  break;
    1.54              case 'p':
    1.55 -                error->args[error->argc++].value_ptr = va_arg (ap, void *);
    1.56 +                error->args[error->argc++].value_ptr = va_arg(ap, void *);
    1.57                  break;
    1.58              case 's':
    1.59                  {
    1.60                      int i = error->argc;
    1.61 -                    const char *str = va_arg (ap, const char *);
    1.62 +                    const char *str = va_arg(ap, const char *);
    1.63                      if (str == NULL)
    1.64                          str = "(null)";
    1.65 -                    SDL_strlcpy ((char *) error->args[i].buf, str,
    1.66 -                                 ERR_MAX_STRLEN);
    1.67 +                    SDL_strlcpy((char *) error->args[i].buf, str,
    1.68 +                                ERR_MAX_STRLEN);
    1.69                      error->argc++;
    1.70                  }
    1.71                  break;
    1.72 @@ -104,11 +104,11 @@
    1.73              }
    1.74          }
    1.75      }
    1.76 -    va_end (ap);
    1.77 +    va_end(ap);
    1.78  
    1.79      /* If we are in debug mode, print out an error message */
    1.80  #ifdef DEBUG_ERROR
    1.81 -    fprintf (stderr, "SDL_SetError: %s\n", SDL_GetError ());
    1.82 +    fprintf(stderr, "SDL_SetError: %s\n", SDL_GetError());
    1.83  #endif
    1.84  }
    1.85  
    1.86 @@ -116,7 +116,7 @@
    1.87     so that it supports internationalization and thread-safe errors.
    1.88  */
    1.89  char *
    1.90 -SDL_GetErrorMsg (char *errstr, unsigned int maxlen)
    1.91 +SDL_GetErrorMsg(char *errstr, unsigned int maxlen)
    1.92  {
    1.93      SDL_error *error;
    1.94  
    1.95 @@ -125,21 +125,21 @@
    1.96      --maxlen;
    1.97  
    1.98      /* Get the thread-safe error, and print it out */
    1.99 -    error = SDL_GetErrBuf ();
   1.100 +    error = SDL_GetErrBuf();
   1.101      if (error->error) {
   1.102          const char *fmt;
   1.103          char *msg = errstr;
   1.104          int len;
   1.105          int argi;
   1.106  
   1.107 -        fmt = SDL_LookupString (error->key);
   1.108 +        fmt = SDL_LookupString(error->key);
   1.109          argi = 0;
   1.110          while (*fmt && (maxlen > 0)) {
   1.111              if (*fmt == '%') {
   1.112                  char tmp[32], *spot = tmp;
   1.113                  *spot++ = *fmt++;
   1.114                  while ((*fmt == '.' || (*fmt >= '0' && *fmt <= '9'))
   1.115 -                       && spot < (tmp + SDL_arraysize (tmp) - 2)) {
   1.116 +                       && spot < (tmp + SDL_arraysize(tmp) - 2)) {
   1.117                      *spot++ = *fmt++;
   1.118                  }
   1.119                  *spot++ = *fmt++;
   1.120 @@ -157,30 +157,30 @@
   1.121                  case 'x':
   1.122                  case 'X':
   1.123                      len =
   1.124 -                        SDL_snprintf (msg, maxlen, tmp,
   1.125 -                                      error->args[argi++].value_i);
   1.126 +                        SDL_snprintf(msg, maxlen, tmp,
   1.127 +                                     error->args[argi++].value_i);
   1.128                      msg += len;
   1.129                      maxlen -= len;
   1.130                      break;
   1.131                  case 'f':
   1.132                      len =
   1.133 -                        SDL_snprintf (msg, maxlen, tmp,
   1.134 -                                      error->args[argi++].value_f);
   1.135 +                        SDL_snprintf(msg, maxlen, tmp,
   1.136 +                                     error->args[argi++].value_f);
   1.137                      msg += len;
   1.138                      maxlen -= len;
   1.139                      break;
   1.140                  case 'p':
   1.141                      len =
   1.142 -                        SDL_snprintf (msg, maxlen, tmp,
   1.143 -                                      error->args[argi++].value_ptr);
   1.144 +                        SDL_snprintf(msg, maxlen, tmp,
   1.145 +                                     error->args[argi++].value_ptr);
   1.146                      msg += len;
   1.147                      maxlen -= len;
   1.148                      break;
   1.149                  case 's':
   1.150                      len =
   1.151 -                        SDL_snprintf (msg, maxlen, tmp,
   1.152 -                                      SDL_LookupString (error->
   1.153 -                                                        args[argi++].buf));
   1.154 +                        SDL_snprintf(msg, maxlen, tmp,
   1.155 +                                     SDL_LookupString(error->
   1.156 +                                                      args[argi++].buf));
   1.157                      msg += len;
   1.158                      maxlen -= len;
   1.159                      break;
   1.160 @@ -197,59 +197,59 @@
   1.161  
   1.162  /* Available for backwards compatibility */
   1.163  char *
   1.164 -SDL_GetError (void)
   1.165 +SDL_GetError(void)
   1.166  {
   1.167      static char errmsg[SDL_ERRBUFIZE];
   1.168  
   1.169 -    return ((char *) SDL_GetErrorMsg (errmsg, SDL_ERRBUFIZE));
   1.170 +    return ((char *) SDL_GetErrorMsg(errmsg, SDL_ERRBUFIZE));
   1.171  }
   1.172  
   1.173  void
   1.174 -SDL_ClearError (void)
   1.175 +SDL_ClearError(void)
   1.176  {
   1.177      SDL_error *error;
   1.178  
   1.179 -    error = SDL_GetErrBuf ();
   1.180 +    error = SDL_GetErrBuf();
   1.181      error->error = 0;
   1.182  }
   1.183  
   1.184  /* Very common errors go here */
   1.185  void
   1.186 -SDL_Error (SDL_errorcode code)
   1.187 +SDL_Error(SDL_errorcode code)
   1.188  {
   1.189      switch (code) {
   1.190      case SDL_ENOMEM:
   1.191 -        SDL_SetError ("Out of memory");
   1.192 +        SDL_SetError("Out of memory");
   1.193          break;
   1.194      case SDL_EFREAD:
   1.195 -        SDL_SetError ("Error reading from datastream");
   1.196 +        SDL_SetError("Error reading from datastream");
   1.197          break;
   1.198      case SDL_EFWRITE:
   1.199 -        SDL_SetError ("Error writing to datastream");
   1.200 +        SDL_SetError("Error writing to datastream");
   1.201          break;
   1.202      case SDL_EFSEEK:
   1.203 -        SDL_SetError ("Error seeking in datastream");
   1.204 +        SDL_SetError("Error seeking in datastream");
   1.205          break;
   1.206      default:
   1.207 -        SDL_SetError ("Unknown SDL error");
   1.208 +        SDL_SetError("Unknown SDL error");
   1.209          break;
   1.210      }
   1.211  }
   1.212  
   1.213  #ifdef TEST_ERROR
   1.214  int
   1.215 -main (int argc, char *argv[])
   1.216 +main(int argc, char *argv[])
   1.217  {
   1.218      char buffer[BUFSIZ + 1];
   1.219  
   1.220 -    SDL_SetError ("Hi there!");
   1.221 -    printf ("Error 1: %s\n", SDL_GetError ());
   1.222 -    SDL_ClearError ();
   1.223 -    SDL_memset (buffer, '1', BUFSIZ);
   1.224 +    SDL_SetError("Hi there!");
   1.225 +    printf("Error 1: %s\n", SDL_GetError());
   1.226 +    SDL_ClearError();
   1.227 +    SDL_memset(buffer, '1', BUFSIZ);
   1.228      buffer[BUFSIZ] = 0;
   1.229 -    SDL_SetError ("This is the error: %s (%f)", buffer, 1.0);
   1.230 -    printf ("Error 2: %s\n", SDL_GetError ());
   1.231 -    exit (0);
   1.232 +    SDL_SetError("This is the error: %s (%f)", buffer, 1.0);
   1.233 +    printf("Error 2: %s\n", SDL_GetError());
   1.234 +    exit(0);
   1.235  }
   1.236  #endif
   1.237  /* vi: set ts=4 sw=4 expandtab: */