src/joystick/linux/SDL_sysjoystick.c
branchSDL-1.3
changeset 1668 4da1ee79c9af
parent 1662 782fd950bd46
     1.1 --- a/src/joystick/linux/SDL_sysjoystick.c	Mon May 29 03:53:21 2006 +0000
     1.2 +++ b/src/joystick/linux/SDL_sysjoystick.c	Mon May 29 04:04:35 2006 +0000
     1.3 @@ -309,7 +309,7 @@
     1.4  #ifndef NO_LOGICAL_JOYSTICKS
     1.5  
     1.6  static int
     1.7 -CountLogicalJoysticks (int max)
     1.8 +CountLogicalJoysticks(int max)
     1.9  {
    1.10      register int i, j, k, ret, prev;
    1.11      const char *name;
    1.12 @@ -319,23 +319,23 @@
    1.13      ret = 0;
    1.14  
    1.15      for (i = 0; i < max; i++) {
    1.16 -        name = SDL_SYS_JoystickName (i);
    1.17 +        name = SDL_SYS_JoystickName(i);
    1.18  
    1.19 -        fd = open (SDL_joylist[i].fname, O_RDONLY, 0);
    1.20 +        fd = open(SDL_joylist[i].fname, O_RDONLY, 0);
    1.21          if (fd >= 0) {
    1.22 -            if (ioctl (fd, JSIOCGBUTTONS, &n) < 0) {
    1.23 +            if (ioctl(fd, JSIOCGBUTTONS, &n) < 0) {
    1.24                  nbuttons = -1;
    1.25              } else {
    1.26                  nbuttons = n;
    1.27              }
    1.28 -            close (fd);
    1.29 +            close(fd);
    1.30          } else {
    1.31              nbuttons = -1;
    1.32          }
    1.33  
    1.34          if (name) {
    1.35 -            for (j = 0; j < SDL_arraysize (joystick_logicalmap); j++) {
    1.36 -                if (!SDL_strcmp (name, joystick_logicalmap[j].name)
    1.37 +            for (j = 0; j < SDL_arraysize(joystick_logicalmap); j++) {
    1.38 +                if (!SDL_strcmp(name, joystick_logicalmap[j].name)
    1.39                      && (nbuttons == -1
    1.40                          || nbuttons == joystick_logicalmap[j].nbuttons)) {
    1.41                      prev = i;
    1.42 @@ -361,16 +361,16 @@
    1.43  }
    1.44  
    1.45  static void
    1.46 -LogicalSuffix (int logicalno, char *namebuf, int len)
    1.47 +LogicalSuffix(int logicalno, char *namebuf, int len)
    1.48  {
    1.49      register int slen;
    1.50      const static char suffixs[] =
    1.51          "01020304050607080910111213141516171819" "20212223242526272829303132";
    1.52      const char *suffix;
    1.53 -    slen = SDL_strlen (namebuf);
    1.54 +    slen = SDL_strlen(namebuf);
    1.55      suffix = NULL;
    1.56  
    1.57 -    if (logicalno * 2 < sizeof (suffixs))
    1.58 +    if (logicalno * 2 < sizeof(suffixs))
    1.59          suffix = suffixs + (logicalno * 2);
    1.60  
    1.61      if (slen + 4 < len && suffix) {
    1.62 @@ -389,21 +389,21 @@
    1.63  	(((1UL << ((nr) & 31)) & (((const unsigned int *) addr)[(nr) >> 5])) != 0)
    1.64  
    1.65  static int
    1.66 -EV_IsJoystick (int fd)
    1.67 +EV_IsJoystick(int fd)
    1.68  {
    1.69      unsigned long evbit[40];
    1.70      unsigned long keybit[40];
    1.71      unsigned long absbit[40];
    1.72  
    1.73 -    if ((ioctl (fd, EVIOCGBIT (0, sizeof (evbit)), evbit) < 0) ||
    1.74 -        (ioctl (fd, EVIOCGBIT (EV_KEY, sizeof (keybit)), keybit) < 0) ||
    1.75 -        (ioctl (fd, EVIOCGBIT (EV_ABS, sizeof (absbit)), absbit) < 0)) {
    1.76 +    if ((ioctl(fd, EVIOCGBIT(0, sizeof(evbit)), evbit) < 0) ||
    1.77 +        (ioctl(fd, EVIOCGBIT(EV_KEY, sizeof(keybit)), keybit) < 0) ||
    1.78 +        (ioctl(fd, EVIOCGBIT(EV_ABS, sizeof(absbit)), absbit) < 0)) {
    1.79          return (0);
    1.80      }
    1.81 -    if (!(test_bit (EV_KEY, evbit) && test_bit (EV_ABS, evbit) &&
    1.82 -          test_bit (ABS_X, absbit) && test_bit (ABS_Y, absbit) &&
    1.83 -          (test_bit (BTN_TRIGGER, keybit) || test_bit (BTN_A, keybit)
    1.84 -           || test_bit (BTN_1, keybit))))
    1.85 +    if (!(test_bit(EV_KEY, evbit) && test_bit(EV_ABS, evbit) &&
    1.86 +          test_bit(ABS_X, absbit) && test_bit(ABS_Y, absbit) &&
    1.87 +          (test_bit(BTN_TRIGGER, keybit) || test_bit(BTN_A, keybit)
    1.88 +           || test_bit(BTN_1, keybit))))
    1.89          return 0;
    1.90      return (1);
    1.91  }
    1.92 @@ -412,7 +412,7 @@
    1.93  
    1.94  /* Function to scan the system for joysticks */
    1.95  int
    1.96 -SDL_SYS_JoystickInit (void)
    1.97 +SDL_SYS_JoystickInit(void)
    1.98  {
    1.99      /* The base path of the joystick devices */
   1.100      const char *joydev_pattern[] = {
   1.101 @@ -433,31 +433,31 @@
   1.102      numjoysticks = 0;
   1.103  
   1.104      /* First see if the user specified a joystick to use */
   1.105 -    if (SDL_getenv ("SDL_JOYSTICK_DEVICE") != NULL) {
   1.106 -        SDL_strlcpy (path, SDL_getenv ("SDL_JOYSTICK_DEVICE"), sizeof (path));
   1.107 -        if (stat (path, &sb) == 0) {
   1.108 -            fd = open (path, O_RDONLY, 0);
   1.109 +    if (SDL_getenv("SDL_JOYSTICK_DEVICE") != NULL) {
   1.110 +        SDL_strlcpy(path, SDL_getenv("SDL_JOYSTICK_DEVICE"), sizeof(path));
   1.111 +        if (stat(path, &sb) == 0) {
   1.112 +            fd = open(path, O_RDONLY, 0);
   1.113              if (fd >= 0) {
   1.114                  /* Assume the user knows what they're doing. */
   1.115 -                SDL_joylist[numjoysticks].fname = SDL_strdup (path);
   1.116 +                SDL_joylist[numjoysticks].fname = SDL_strdup(path);
   1.117                  if (SDL_joylist[numjoysticks].fname) {
   1.118                      dev_nums[numjoysticks] = sb.st_rdev;
   1.119                      ++numjoysticks;
   1.120                  }
   1.121 -                close (fd);
   1.122 +                close(fd);
   1.123              }
   1.124          }
   1.125      }
   1.126  
   1.127 -    for (i = 0; i < SDL_arraysize (joydev_pattern); ++i) {
   1.128 +    for (i = 0; i < SDL_arraysize(joydev_pattern); ++i) {
   1.129          for (j = 0; j < MAX_JOYSTICKS; ++j) {
   1.130 -            SDL_snprintf (path, SDL_arraysize (path), joydev_pattern[i], j);
   1.131 +            SDL_snprintf(path, SDL_arraysize(path), joydev_pattern[i], j);
   1.132  
   1.133              /* rcg06302000 replaced access(F_OK) call with stat().
   1.134               * stat() will fail if the file doesn't exist, so it's
   1.135               * equivalent behaviour.
   1.136               */
   1.137 -            if (stat (path, &sb) == 0) {
   1.138 +            if (stat(path, &sb) == 0) {
   1.139                  /* Check to make sure it's not already in list.
   1.140                   * This happens when we see a stick via symlink.
   1.141                   */
   1.142 @@ -471,23 +471,23 @@
   1.143                      continue;
   1.144                  }
   1.145  
   1.146 -                fd = open (path, O_RDONLY, 0);
   1.147 +                fd = open(path, O_RDONLY, 0);
   1.148                  if (fd < 0) {
   1.149                      continue;
   1.150                  }
   1.151  #if SDL_INPUT_LINUXEV
   1.152  #ifdef DEBUG_INPUT_EVENTS
   1.153 -                printf ("Checking %s\n", path);
   1.154 +                printf("Checking %s\n", path);
   1.155  #endif
   1.156 -                if ((i == 0) && !EV_IsJoystick (fd)) {
   1.157 -                    close (fd);
   1.158 +                if ((i == 0) && !EV_IsJoystick(fd)) {
   1.159 +                    close(fd);
   1.160                      continue;
   1.161                  }
   1.162  #endif
   1.163 -                close (fd);
   1.164 +                close(fd);
   1.165  
   1.166                  /* We're fine, add this joystick */
   1.167 -                SDL_joylist[numjoysticks].fname = SDL_strdup (path);
   1.168 +                SDL_joylist[numjoysticks].fname = SDL_strdup(path);
   1.169                  if (SDL_joylist[numjoysticks].fname) {
   1.170                      dev_nums[numjoysticks] = sb.st_rdev;
   1.171                      ++numjoysticks;
   1.172 @@ -509,7 +509,7 @@
   1.173  #endif
   1.174      }
   1.175  #ifndef NO_LOGICAL_JOYSTICKS
   1.176 -    numjoysticks += CountLogicalJoysticks (numjoysticks);
   1.177 +    numjoysticks += CountLogicalJoysticks(numjoysticks);
   1.178  #endif
   1.179  
   1.180      return (numjoysticks);
   1.181 @@ -517,35 +517,35 @@
   1.182  
   1.183  /* Function to get the device-dependent name of a joystick */
   1.184  const char *
   1.185 -SDL_SYS_JoystickName (int index)
   1.186 +SDL_SYS_JoystickName(int index)
   1.187  {
   1.188      int fd;
   1.189      static char namebuf[128];
   1.190      char *name;
   1.191 -    SDL_logical_joydecl (int oindex = index);
   1.192 +    SDL_logical_joydecl(int oindex = index);
   1.193  
   1.194  #ifndef NO_LOGICAL_JOYSTICKS
   1.195 -    SDL_joylist_head (index, index);
   1.196 +    SDL_joylist_head(index, index);
   1.197  #endif
   1.198      name = NULL;
   1.199 -    fd = open (SDL_joylist[index].fname, O_RDONLY, 0);
   1.200 +    fd = open(SDL_joylist[index].fname, O_RDONLY, 0);
   1.201      if (fd >= 0) {
   1.202          if (
   1.203  #if SDL_INPUT_LINUXEV
   1.204 -               (ioctl (fd, EVIOCGNAME (sizeof (namebuf)), namebuf) <= 0) &&
   1.205 +               (ioctl(fd, EVIOCGNAME(sizeof(namebuf)), namebuf) <= 0) &&
   1.206  #endif
   1.207 -               (ioctl (fd, JSIOCGNAME (sizeof (namebuf)), namebuf) <= 0)) {
   1.208 +               (ioctl(fd, JSIOCGNAME(sizeof(namebuf)), namebuf) <= 0)) {
   1.209              name = SDL_joylist[index].fname;
   1.210          } else {
   1.211              name = namebuf;
   1.212          }
   1.213 -        close (fd);
   1.214 +        close(fd);
   1.215  
   1.216  
   1.217  #ifndef NO_LOGICAL_JOYSTICKS
   1.218          if (SDL_joylist[oindex].prev || SDL_joylist[oindex].next
   1.219              || index != oindex) {
   1.220 -            LogicalSuffix (SDL_joylist[oindex].logicalno, namebuf, 128);
   1.221 +            LogicalSuffix(SDL_joylist[oindex].logicalno, namebuf, 128);
   1.222          }
   1.223  #endif
   1.224      }
   1.225 @@ -553,13 +553,13 @@
   1.226  }
   1.227  
   1.228  static int
   1.229 -allocate_hatdata (SDL_Joystick * joystick)
   1.230 +allocate_hatdata(SDL_Joystick * joystick)
   1.231  {
   1.232      int i;
   1.233  
   1.234      joystick->hwdata->hats =
   1.235 -        (struct hwdata_hat *) SDL_malloc (joystick->nhats *
   1.236 -                                          sizeof (struct hwdata_hat));
   1.237 +        (struct hwdata_hat *) SDL_malloc(joystick->nhats *
   1.238 +                                         sizeof(struct hwdata_hat));
   1.239      if (joystick->hwdata->hats == NULL) {
   1.240          return (-1);
   1.241      }
   1.242 @@ -571,13 +571,13 @@
   1.243  }
   1.244  
   1.245  static int
   1.246 -allocate_balldata (SDL_Joystick * joystick)
   1.247 +allocate_balldata(SDL_Joystick * joystick)
   1.248  {
   1.249      int i;
   1.250  
   1.251      joystick->hwdata->balls =
   1.252 -        (struct hwdata_ball *) SDL_malloc (joystick->nballs *
   1.253 -                                           sizeof (struct hwdata_ball));
   1.254 +        (struct hwdata_ball *) SDL_malloc(joystick->nballs *
   1.255 +                                          sizeof(struct hwdata_ball));
   1.256      if (joystick->hwdata->balls == NULL) {
   1.257          return (-1);
   1.258      }
   1.259 @@ -589,7 +589,7 @@
   1.260  }
   1.261  
   1.262  static SDL_bool
   1.263 -JS_ConfigJoystick (SDL_Joystick * joystick, int fd)
   1.264 +JS_ConfigJoystick(SDL_Joystick * joystick, int fd)
   1.265  {
   1.266      SDL_bool handled;
   1.267      unsigned char n;
   1.268 @@ -601,24 +601,24 @@
   1.269      handled = SDL_FALSE;
   1.270  
   1.271      /* Default joystick device settings */
   1.272 -    if (ioctl (fd, JSIOCGAXES, &n) < 0) {
   1.273 +    if (ioctl(fd, JSIOCGAXES, &n) < 0) {
   1.274          joystick->naxes = 2;
   1.275      } else {
   1.276          joystick->naxes = n;
   1.277      }
   1.278 -    if (ioctl (fd, JSIOCGBUTTONS, &n) < 0) {
   1.279 +    if (ioctl(fd, JSIOCGBUTTONS, &n) < 0) {
   1.280          joystick->nbuttons = 2;
   1.281      } else {
   1.282          joystick->nbuttons = n;
   1.283      }
   1.284  
   1.285 -    name = SDL_SYS_JoystickName (joystick->index);
   1.286 +    name = SDL_SYS_JoystickName(joystick->index);
   1.287      old_axes = joystick->naxes;
   1.288  
   1.289      /* Generic analog joystick support */
   1.290 -    if (SDL_strstr (name, "Analog") == name && SDL_strstr (name, "-hat")) {
   1.291 -        if (SDL_sscanf (name, "Analog %d-axis %*d-button %d-hat",
   1.292 -                        &tmp_naxes, &tmp_nhats) == 2) {
   1.293 +    if (SDL_strstr(name, "Analog") == name && SDL_strstr(name, "-hat")) {
   1.294 +        if (SDL_sscanf(name, "Analog %d-axis %*d-button %d-hat",
   1.295 +                       &tmp_naxes, &tmp_nhats) == 2) {
   1.296  
   1.297              joystick->naxes = tmp_naxes;
   1.298              joystick->nhats = tmp_nhats;
   1.299 @@ -628,8 +628,8 @@
   1.300      }
   1.301  
   1.302      /* Special joystick support */
   1.303 -    for (i = 0; i < SDL_arraysize (special_joysticks); ++i) {
   1.304 -        if (SDL_strcmp (name, special_joysticks[i].name) == 0) {
   1.305 +    for (i = 0; i < SDL_arraysize(special_joysticks); ++i) {
   1.306 +        if (SDL_strcmp(name, special_joysticks[i].name) == 0) {
   1.307  
   1.308              joystick->naxes = special_joysticks[i].naxes;
   1.309              joystick->nhats = special_joysticks[i].nhats;
   1.310 @@ -641,17 +641,17 @@
   1.311      }
   1.312  
   1.313      /* User environment joystick support */
   1.314 -    if ((env = SDL_getenv ("SDL_LINUX_JOYSTICK"))) {
   1.315 +    if ((env = SDL_getenv("SDL_LINUX_JOYSTICK"))) {
   1.316          *env_name = '\0';
   1.317 -        if (*env == '\'' && SDL_sscanf (env, "'%[^']s'", env_name) == 1)
   1.318 -            env += SDL_strlen (env_name) + 2;
   1.319 -        else if (SDL_sscanf (env, "%s", env_name) == 1)
   1.320 -            env += SDL_strlen (env_name);
   1.321 +        if (*env == '\'' && SDL_sscanf(env, "'%[^']s'", env_name) == 1)
   1.322 +            env += SDL_strlen(env_name) + 2;
   1.323 +        else if (SDL_sscanf(env, "%s", env_name) == 1)
   1.324 +            env += SDL_strlen(env_name);
   1.325  
   1.326 -        if (SDL_strcmp (name, env_name) == 0) {
   1.327 +        if (SDL_strcmp(name, env_name) == 0) {
   1.328  
   1.329 -            if (SDL_sscanf (env, "%d %d %d", &tmp_naxes, &tmp_nhats,
   1.330 -                            &tmp_nballs) == 3) {
   1.331 +            if (SDL_sscanf(env, "%d %d %d", &tmp_naxes, &tmp_nhats,
   1.332 +                           &tmp_nballs) == 3) {
   1.333  
   1.334                  joystick->naxes = tmp_naxes;
   1.335                  joystick->nhats = tmp_nhats;
   1.336 @@ -665,12 +665,12 @@
   1.337      /* Remap hats and balls */
   1.338      if (handled) {
   1.339          if (joystick->nhats > 0) {
   1.340 -            if (allocate_hatdata (joystick) < 0) {
   1.341 +            if (allocate_hatdata(joystick) < 0) {
   1.342                  joystick->nhats = 0;
   1.343              }
   1.344          }
   1.345          if (joystick->nballs > 0) {
   1.346 -            if (allocate_balldata (joystick) < 0) {
   1.347 +            if (allocate_balldata(joystick) < 0) {
   1.348                  joystick->nballs = 0;
   1.349              }
   1.350          }
   1.351 @@ -682,7 +682,7 @@
   1.352  #if SDL_INPUT_LINUXEV
   1.353  
   1.354  static SDL_bool
   1.355 -EV_ConfigJoystick (SDL_Joystick * joystick, int fd)
   1.356 +EV_ConfigJoystick(SDL_Joystick * joystick, int fd)
   1.357  {
   1.358      int i, t;
   1.359      unsigned long keybit[40];
   1.360 @@ -690,25 +690,25 @@
   1.361      unsigned long relbit[40];
   1.362  
   1.363      /* See if this device uses the new unified event API */
   1.364 -    if ((ioctl (fd, EVIOCGBIT (EV_KEY, sizeof (keybit)), keybit) >= 0) &&
   1.365 -        (ioctl (fd, EVIOCGBIT (EV_ABS, sizeof (absbit)), absbit) >= 0) &&
   1.366 -        (ioctl (fd, EVIOCGBIT (EV_REL, sizeof (relbit)), relbit) >= 0)) {
   1.367 +    if ((ioctl(fd, EVIOCGBIT(EV_KEY, sizeof(keybit)), keybit) >= 0) &&
   1.368 +        (ioctl(fd, EVIOCGBIT(EV_ABS, sizeof(absbit)), absbit) >= 0) &&
   1.369 +        (ioctl(fd, EVIOCGBIT(EV_REL, sizeof(relbit)), relbit) >= 0)) {
   1.370          joystick->hwdata->is_hid = SDL_TRUE;
   1.371  
   1.372          /* Get the number of buttons, axes, and other thingamajigs */
   1.373          for (i = BTN_JOYSTICK; i < KEY_MAX; ++i) {
   1.374 -            if (test_bit (i, keybit)) {
   1.375 +            if (test_bit(i, keybit)) {
   1.376  #ifdef DEBUG_INPUT_EVENTS
   1.377 -                printf ("Joystick has button: 0x%x\n", i);
   1.378 +                printf("Joystick has button: 0x%x\n", i);
   1.379  #endif
   1.380                  joystick->hwdata->key_map[i - BTN_MISC] = joystick->nbuttons;
   1.381                  ++joystick->nbuttons;
   1.382              }
   1.383          }
   1.384          for (i = BTN_MISC; i < BTN_JOYSTICK; ++i) {
   1.385 -            if (test_bit (i, keybit)) {
   1.386 +            if (test_bit(i, keybit)) {
   1.387  #ifdef DEBUG_INPUT_EVENTS
   1.388 -                printf ("Joystick has button: 0x%x\n", i);
   1.389 +                printf("Joystick has button: 0x%x\n", i);
   1.390  #endif
   1.391                  joystick->hwdata->key_map[i - BTN_MISC] = joystick->nbuttons;
   1.392                  ++joystick->nbuttons;
   1.393 @@ -720,16 +720,15 @@
   1.394                  i = ABS_HAT3Y;
   1.395                  continue;
   1.396              }
   1.397 -            if (test_bit (i, absbit)) {
   1.398 +            if (test_bit(i, absbit)) {
   1.399                  int values[5];
   1.400  
   1.401 -                if (ioctl (fd, EVIOCGABS (i), values) < 0)
   1.402 +                if (ioctl(fd, EVIOCGABS(i), values) < 0)
   1.403                      continue;
   1.404  #ifdef DEBUG_INPUT_EVENTS
   1.405 -                printf ("Joystick has absolute axis: %x\n", i);
   1.406 -                printf ("Values = { %d, %d, %d, %d, %d }\n",
   1.407 -                        values[0], values[1],
   1.408 -                        values[2], values[3], values[4]);
   1.409 +                printf("Joystick has absolute axis: %x\n", i);
   1.410 +                printf("Values = { %d, %d, %d, %d, %d }\n",
   1.411 +                       values[0], values[1], values[2], values[3], values[4]);
   1.412  #endif /* DEBUG_INPUT_EVENTS */
   1.413                  joystick->hwdata->abs_map[i] = joystick->naxes;
   1.414                  if (values[1] == values[2]) {
   1.415 @@ -752,25 +751,25 @@
   1.416              }
   1.417          }
   1.418          for (i = ABS_HAT0X; i <= ABS_HAT3Y; i += 2) {
   1.419 -            if (test_bit (i, absbit) || test_bit (i + 1, absbit)) {
   1.420 +            if (test_bit(i, absbit) || test_bit(i + 1, absbit)) {
   1.421  #ifdef DEBUG_INPUT_EVENTS
   1.422 -                printf ("Joystick has hat %d\n", (i - ABS_HAT0X) / 2);
   1.423 +                printf("Joystick has hat %d\n", (i - ABS_HAT0X) / 2);
   1.424  #endif
   1.425                  ++joystick->nhats;
   1.426              }
   1.427          }
   1.428 -        if (test_bit (REL_X, relbit) || test_bit (REL_Y, relbit)) {
   1.429 +        if (test_bit(REL_X, relbit) || test_bit(REL_Y, relbit)) {
   1.430              ++joystick->nballs;
   1.431          }
   1.432  
   1.433          /* Allocate data to keep track of these thingamajigs */
   1.434          if (joystick->nhats > 0) {
   1.435 -            if (allocate_hatdata (joystick) < 0) {
   1.436 +            if (allocate_hatdata(joystick) < 0) {
   1.437                  joystick->nhats = 0;
   1.438              }
   1.439          }
   1.440          if (joystick->nballs > 0) {
   1.441 -            if (allocate_balldata (joystick) < 0) {
   1.442 +            if (allocate_balldata(joystick) < 0) {
   1.443                  joystick->nballs = 0;
   1.444              }
   1.445          }
   1.446 @@ -782,7 +781,7 @@
   1.447  
   1.448  #ifndef NO_LOGICAL_JOYSTICKS
   1.449  static void
   1.450 -ConfigLogicalJoystick (SDL_Joystick * joystick)
   1.451 +ConfigLogicalJoystick(SDL_Joystick * joystick)
   1.452  {
   1.453      struct joystick_logical_layout *layout;
   1.454  
   1.455 @@ -803,17 +802,17 @@
   1.456     It returns 0, or -1 if there is an error.
   1.457   */
   1.458  int
   1.459 -SDL_SYS_JoystickOpen (SDL_Joystick * joystick)
   1.460 +SDL_SYS_JoystickOpen(SDL_Joystick * joystick)
   1.461  {
   1.462      int fd;
   1.463 -    SDL_logical_joydecl (int realindex);
   1.464 -    SDL_logical_joydecl (SDL_Joystick * realjoy = NULL);
   1.465 +    SDL_logical_joydecl(int realindex);
   1.466 +    SDL_logical_joydecl(SDL_Joystick * realjoy = NULL);
   1.467  
   1.468      /* Open the joystick and set the joystick file descriptor */
   1.469  #ifndef NO_LOGICAL_JOYSTICKS
   1.470      if (SDL_joylist[joystick->index].fname == NULL) {
   1.471 -        SDL_joylist_head (realindex, joystick->index);
   1.472 -        realjoy = SDL_JoystickOpen (realindex);
   1.473 +        SDL_joylist_head(realindex, joystick->index);
   1.474 +        realjoy = SDL_JoystickOpen(realindex);
   1.475  
   1.476          if (realjoy == NULL)
   1.477              return (-1);
   1.478 @@ -821,40 +820,40 @@
   1.479          fd = realjoy->hwdata->fd;
   1.480  
   1.481      } else {
   1.482 -        fd = open (SDL_joylist[joystick->index].fname, O_RDONLY, 0);
   1.483 +        fd = open(SDL_joylist[joystick->index].fname, O_RDONLY, 0);
   1.484      }
   1.485      SDL_joylist[joystick->index].joy = joystick;
   1.486  #else
   1.487 -    fd = open (SDL_joylist[joystick->index].fname, O_RDONLY, 0);
   1.488 +    fd = open(SDL_joylist[joystick->index].fname, O_RDONLY, 0);
   1.489  #endif
   1.490  
   1.491      if (fd < 0) {
   1.492 -        SDL_SetError ("Unable to open %s\n", SDL_joylist[joystick->index]);
   1.493 +        SDL_SetError("Unable to open %s\n", SDL_joylist[joystick->index]);
   1.494          return (-1);
   1.495      }
   1.496      joystick->hwdata = (struct joystick_hwdata *)
   1.497 -        SDL_malloc (sizeof (*joystick->hwdata));
   1.498 +        SDL_malloc(sizeof(*joystick->hwdata));
   1.499      if (joystick->hwdata == NULL) {
   1.500 -        SDL_OutOfMemory ();
   1.501 -        close (fd);
   1.502 +        SDL_OutOfMemory();
   1.503 +        close(fd);
   1.504          return (-1);
   1.505      }
   1.506 -    SDL_memset (joystick->hwdata, 0, sizeof (*joystick->hwdata));
   1.507 +    SDL_memset(joystick->hwdata, 0, sizeof(*joystick->hwdata));
   1.508      joystick->hwdata->fd = fd;
   1.509  
   1.510      /* Set the joystick to non-blocking read mode */
   1.511 -    fcntl (fd, F_SETFL, O_NONBLOCK);
   1.512 +    fcntl(fd, F_SETFL, O_NONBLOCK);
   1.513  
   1.514      /* Get the number of buttons and axes on the joystick */
   1.515  #ifndef NO_LOGICAL_JOYSTICKS
   1.516      if (realjoy)
   1.517 -        ConfigLogicalJoystick (joystick);
   1.518 +        ConfigLogicalJoystick(joystick);
   1.519      else
   1.520  #endif
   1.521  #if SDL_INPUT_LINUXEV
   1.522 -    if (!EV_ConfigJoystick (joystick, fd))
   1.523 +    if (!EV_ConfigJoystick(joystick, fd))
   1.524  #endif
   1.525 -        JS_ConfigJoystick (joystick, fd);
   1.526 +        JS_ConfigJoystick(joystick, fd);
   1.527  
   1.528      return (0);
   1.529  }
   1.530 @@ -862,8 +861,8 @@
   1.531  #ifndef NO_LOGICAL_JOYSTICKS
   1.532  
   1.533  static SDL_Joystick *
   1.534 -FindLogicalJoystick (SDL_Joystick * joystick,
   1.535 -                     struct joystick_logical_mapping *v)
   1.536 +FindLogicalJoystick(SDL_Joystick * joystick,
   1.537 +                    struct joystick_logical_mapping *v)
   1.538  {
   1.539      SDL_Joystick *logicaljoy;
   1.540      register int i;
   1.541 @@ -891,7 +890,7 @@
   1.542  }
   1.543  
   1.544  static int
   1.545 -LogicalJoystickButton (SDL_Joystick * joystick, Uint8 button, Uint8 state)
   1.546 +LogicalJoystickButton(SDL_Joystick * joystick, Uint8 button, Uint8 state)
   1.547  {
   1.548      struct joystick_logical_mapping *buttons;
   1.549      SDL_Joystick *logicaljoy = NULL;
   1.550 @@ -904,18 +903,18 @@
   1.551      /* get the logical joystick that will receive the event
   1.552       */
   1.553      buttons = SDL_joylist[joystick->index].map->buttonmap + button;
   1.554 -    logicaljoy = FindLogicalJoystick (joystick, buttons);
   1.555 +    logicaljoy = FindLogicalJoystick(joystick, buttons);
   1.556  
   1.557      if (logicaljoy == NULL)
   1.558          return 1;
   1.559  
   1.560 -    SDL_PrivateJoystickButton (logicaljoy, buttons->nthing, state);
   1.561 +    SDL_PrivateJoystickButton(logicaljoy, buttons->nthing, state);
   1.562  
   1.563      return 1;
   1.564  }
   1.565  
   1.566  static int
   1.567 -LogicalJoystickAxis (SDL_Joystick * joystick, Uint8 axis, Sint16 value)
   1.568 +LogicalJoystickAxis(SDL_Joystick * joystick, Uint8 axis, Sint16 value)
   1.569  {
   1.570      struct joystick_logical_mapping *axes;
   1.571      SDL_Joystick *logicaljoy = NULL;
   1.572 @@ -928,19 +927,19 @@
   1.573      /* get the logical joystick that will receive the event
   1.574       */
   1.575      axes = SDL_joylist[joystick->index].map->axismap + axis;
   1.576 -    logicaljoy = FindLogicalJoystick (joystick, axes);
   1.577 +    logicaljoy = FindLogicalJoystick(joystick, axes);
   1.578  
   1.579      if (logicaljoy == NULL)
   1.580          return 1;
   1.581  
   1.582 -    SDL_PrivateJoystickAxis (logicaljoy, axes->nthing, value);
   1.583 +    SDL_PrivateJoystickAxis(logicaljoy, axes->nthing, value);
   1.584  
   1.585      return 1;
   1.586  }
   1.587  #endif /* USE_LOGICAL_JOYSTICKS */
   1.588  
   1.589  static __inline__ void
   1.590 -HandleHat (SDL_Joystick * stick, Uint8 hat, int axis, int value)
   1.591 +HandleHat(SDL_Joystick * stick, Uint8 hat, int axis, int value)
   1.592  {
   1.593      struct hwdata_hat *the_hat;
   1.594      const Uint8 position_map[3][3] = {
   1.595 @@ -948,8 +947,8 @@
   1.596          {SDL_HAT_LEFT, SDL_HAT_CENTERED, SDL_HAT_RIGHT},
   1.597          {SDL_HAT_LEFTDOWN, SDL_HAT_DOWN, SDL_HAT_RIGHTDOWN}
   1.598      };
   1.599 -    SDL_logical_joydecl (SDL_Joystick * logicaljoy = NULL);
   1.600 -    SDL_logical_joydecl (struct joystick_logical_mapping *hats = NULL);
   1.601 +    SDL_logical_joydecl(SDL_Joystick * logicaljoy = NULL);
   1.602 +    SDL_logical_joydecl(struct joystick_logical_mapping *hats = NULL);
   1.603  
   1.604      the_hat = &stick->hwdata->hats[hat];
   1.605      if (value < 0) {
   1.606 @@ -970,7 +969,7 @@
   1.607              /* get the fake joystick that will receive the event
   1.608               */
   1.609              hats = SDL_joylist[stick->index].map->hatmap + hat;
   1.610 -            logicaljoy = FindLogicalJoystick (stick, hats);
   1.611 +            logicaljoy = FindLogicalJoystick(stick, hats);
   1.612          }
   1.613  
   1.614          if (logicaljoy) {
   1.615 @@ -979,14 +978,14 @@
   1.616          }
   1.617  #endif /* USE_LOGICAL_JOYSTICKS */
   1.618  
   1.619 -        SDL_PrivateJoystickHat (stick, hat,
   1.620 -                                position_map[the_hat->axis[1]][the_hat->
   1.621 -                                                               axis[0]]);
   1.622 +        SDL_PrivateJoystickHat(stick, hat,
   1.623 +                               position_map[the_hat->axis[1]][the_hat->
   1.624 +                                                              axis[0]]);
   1.625      }
   1.626  }
   1.627  
   1.628  static __inline__ void
   1.629 -HandleBall (SDL_Joystick * stick, Uint8 ball, int axis, int value)
   1.630 +HandleBall(SDL_Joystick * stick, Uint8 ball, int axis, int value)
   1.631  {
   1.632      stick->hwdata->balls[ball].axis[axis] += value;
   1.633  }
   1.634 @@ -997,7 +996,7 @@
   1.635   * and update joystick device state.
   1.636   */
   1.637  static __inline__ void
   1.638 -JS_HandleEvents (SDL_Joystick * joystick)
   1.639 +JS_HandleEvents(SDL_Joystick * joystick)
   1.640  {
   1.641      struct js_event events[32];
   1.642      int i, len;
   1.643 @@ -1005,52 +1004,51 @@
   1.644  
   1.645  #ifndef NO_LOGICAL_JOYSTICKS
   1.646      if (SDL_joylist[joystick->index].fname == NULL) {
   1.647 -        SDL_joylist_head (i, joystick->index);
   1.648 -        JS_HandleEvents (SDL_joylist[i].joy);
   1.649 +        SDL_joylist_head(i, joystick->index);
   1.650 +        JS_HandleEvents(SDL_joylist[i].joy);
   1.651          return;
   1.652      }
   1.653  #endif
   1.654  
   1.655 -    while ((len = read (joystick->hwdata->fd, events, (sizeof events))) > 0) {
   1.656 -        len /= sizeof (events[0]);
   1.657 +    while ((len = read(joystick->hwdata->fd, events, (sizeof events))) > 0) {
   1.658 +        len /= sizeof(events[0]);
   1.659          for (i = 0; i < len; ++i) {
   1.660              switch (events[i].type & ~JS_EVENT_INIT) {
   1.661              case JS_EVENT_AXIS:
   1.662                  if (events[i].number < joystick->naxes) {
   1.663  #ifndef NO_LOGICAL_JOYSTICKS
   1.664 -                    if (!LogicalJoystickAxis (joystick,
   1.665 -                                              events[i].number,
   1.666 -                                              events[i].value))
   1.667 +                    if (!LogicalJoystickAxis(joystick,
   1.668 +                                             events[i].number,
   1.669 +                                             events[i].value))
   1.670  #endif
   1.671 -                        SDL_PrivateJoystickAxis (joystick,
   1.672 -                                                 events[i].number,
   1.673 -                                                 events[i].value);
   1.674 +                        SDL_PrivateJoystickAxis(joystick,
   1.675 +                                                events[i].number,
   1.676 +                                                events[i].value);
   1.677                      break;
   1.678                  }
   1.679                  events[i].number -= joystick->naxes;
   1.680                  other_axis = (events[i].number / 2);
   1.681                  if (other_axis < joystick->nhats) {
   1.682 -                    HandleHat (joystick, other_axis,
   1.683 -                               events[i].number % 2, events[i].value);
   1.684 +                    HandleHat(joystick, other_axis,
   1.685 +                              events[i].number % 2, events[i].value);
   1.686                      break;
   1.687                  }
   1.688                  events[i].number -= joystick->nhats * 2;
   1.689                  other_axis = (events[i].number / 2);
   1.690                  if (other_axis < joystick->nballs) {
   1.691 -                    HandleBall (joystick, other_axis,
   1.692 -                                events[i].number % 2, events[i].value);
   1.693 +                    HandleBall(joystick, other_axis,
   1.694 +                               events[i].number % 2, events[i].value);
   1.695                      break;
   1.696                  }
   1.697                  break;
   1.698              case JS_EVENT_BUTTON:
   1.699  #ifndef NO_LOGICAL_JOYSTICKS
   1.700 -                if (!LogicalJoystickButton (joystick,
   1.701 -                                            events[i].number,
   1.702 -                                            events[i].value))
   1.703 +                if (!LogicalJoystickButton(joystick,
   1.704 +                                           events[i].number, events[i].value))
   1.705  #endif
   1.706 -                    SDL_PrivateJoystickButton (joystick,
   1.707 -                                               events[i].number,
   1.708 -                                               events[i].value);
   1.709 +                    SDL_PrivateJoystickButton(joystick,
   1.710 +                                              events[i].number,
   1.711 +                                              events[i].value);
   1.712                  break;
   1.713              default:
   1.714                  /* ?? */
   1.715 @@ -1062,7 +1060,7 @@
   1.716  
   1.717  #if SDL_INPUT_LINUXEV
   1.718  static __inline__ int
   1.719 -EV_AxisCorrect (SDL_Joystick * joystick, int which, int value)
   1.720 +EV_AxisCorrect(SDL_Joystick * joystick, int which, int value)
   1.721  {
   1.722      struct axis_correct *correct;
   1.723  
   1.724 @@ -1090,7 +1088,7 @@
   1.725  }
   1.726  
   1.727  static __inline__ void
   1.728 -EV_HandleEvents (SDL_Joystick * joystick)
   1.729 +EV_HandleEvents(SDL_Joystick * joystick)
   1.730  {
   1.731      struct input_event events[32];
   1.732      int i, len;
   1.733 @@ -1098,13 +1096,13 @@
   1.734  
   1.735  #ifndef NO_LOGICAL_JOYSTICKS
   1.736      if (SDL_joylist[joystick->index].fname == NULL) {
   1.737 -        SDL_joylist_head (i, joystick->index);
   1.738 -        return EV_HandleEvents (SDL_joylist[i].joy);
   1.739 +        SDL_joylist_head(i, joystick->index);
   1.740 +        return EV_HandleEvents(SDL_joylist[i].joy);
   1.741      }
   1.742  #endif
   1.743  
   1.744 -    while ((len = read (joystick->hwdata->fd, events, (sizeof events))) > 0) {
   1.745 -        len /= sizeof (events[0]);
   1.746 +    while ((len = read(joystick->hwdata->fd, events, (sizeof events))) > 0) {
   1.747 +        len /= sizeof(events[0]);
   1.748          for (i = 0; i < len; ++i) {
   1.749              code = events[i].code;
   1.750              switch (events[i].type) {
   1.751 @@ -1112,15 +1110,15 @@
   1.752                  if (code >= BTN_MISC) {
   1.753                      code -= BTN_MISC;
   1.754  #ifndef NO_LOGICAL_JOYSTICKS
   1.755 -                    if (!LogicalJoystickButton (joystick,
   1.756 -                                                joystick->hwdata->
   1.757 -                                                key_map[code],
   1.758 -                                                events[i].value))
   1.759 +                    if (!LogicalJoystickButton(joystick,
   1.760 +                                               joystick->hwdata->
   1.761 +                                               key_map[code],
   1.762 +                                               events[i].value))
   1.763  #endif
   1.764 -                        SDL_PrivateJoystickButton (joystick,
   1.765 -                                                   joystick->hwdata->
   1.766 -                                                   key_map[code],
   1.767 -                                                   events[i].value);
   1.768 +                        SDL_PrivateJoystickButton(joystick,
   1.769 +                                                  joystick->hwdata->
   1.770 +                                                  key_map[code],
   1.771 +                                                  events[i].value);
   1.772                  }
   1.773                  break;
   1.774              case EV_ABS:
   1.775 @@ -1134,20 +1132,20 @@
   1.776                  case ABS_HAT3X:
   1.777                  case ABS_HAT3Y:
   1.778                      code -= ABS_HAT0X;
   1.779 -                    HandleHat (joystick, code / 2, code % 2, events[i].value);
   1.780 +                    HandleHat(joystick, code / 2, code % 2, events[i].value);
   1.781                      break;
   1.782                  default:
   1.783                      events[i].value =
   1.784 -                        EV_AxisCorrect (joystick, code, events[i].value);
   1.785 +                        EV_AxisCorrect(joystick, code, events[i].value);
   1.786  #ifndef NO_LOGICAL_JOYSTICKS
   1.787 -                    if (!LogicalJoystickAxis (joystick,
   1.788 -                                              joystick->hwdata->
   1.789 -                                              abs_map[code], events[i].value))
   1.790 +                    if (!LogicalJoystickAxis(joystick,
   1.791 +                                             joystick->hwdata->
   1.792 +                                             abs_map[code], events[i].value))
   1.793  #endif
   1.794 -                        SDL_PrivateJoystickAxis (joystick,
   1.795 -                                                 joystick->hwdata->
   1.796 -                                                 abs_map[code],
   1.797 -                                                 events[i].value);
   1.798 +                        SDL_PrivateJoystickAxis(joystick,
   1.799 +                                                joystick->hwdata->
   1.800 +                                                abs_map[code],
   1.801 +                                                events[i].value);
   1.802                      break;
   1.803                  }
   1.804                  break;
   1.805 @@ -1156,8 +1154,7 @@
   1.806                  case REL_X:
   1.807                  case REL_Y:
   1.808                      code -= REL_X;
   1.809 -                    HandleBall (joystick, code / 2, code % 2,
   1.810 -                                events[i].value);
   1.811 +                    HandleBall(joystick, code / 2, code % 2, events[i].value);
   1.812                      break;
   1.813                  default:
   1.814                      break;
   1.815 @@ -1172,16 +1169,16 @@
   1.816  #endif /* SDL_INPUT_LINUXEV */
   1.817  
   1.818  void
   1.819 -SDL_SYS_JoystickUpdate (SDL_Joystick * joystick)
   1.820 +SDL_SYS_JoystickUpdate(SDL_Joystick * joystick)
   1.821  {
   1.822      int i;
   1.823  
   1.824  #if SDL_INPUT_LINUXEV
   1.825      if (joystick->hwdata->is_hid)
   1.826 -        EV_HandleEvents (joystick);
   1.827 +        EV_HandleEvents(joystick);
   1.828      else
   1.829  #endif
   1.830 -        JS_HandleEvents (joystick);
   1.831 +        JS_HandleEvents(joystick);
   1.832  
   1.833      /* Deliver ball motion updates */
   1.834      for (i = 0; i < joystick->nballs; ++i) {
   1.835 @@ -1192,20 +1189,20 @@
   1.836          if (xrel || yrel) {
   1.837              joystick->hwdata->balls[i].axis[0] = 0;
   1.838              joystick->hwdata->balls[i].axis[1] = 0;
   1.839 -            SDL_PrivateJoystickBall (joystick, (Uint8) i, xrel, yrel);
   1.840 +            SDL_PrivateJoystickBall(joystick, (Uint8) i, xrel, yrel);
   1.841          }
   1.842      }
   1.843  }
   1.844  
   1.845  /* Function to close a joystick after use */
   1.846  void
   1.847 -SDL_SYS_JoystickClose (SDL_Joystick * joystick)
   1.848 +SDL_SYS_JoystickClose(SDL_Joystick * joystick)
   1.849  {
   1.850  #ifndef NO_LOGICAL_JOYSTICKS
   1.851      register int i;
   1.852      if (SDL_joylist[joystick->index].fname == NULL) {
   1.853 -        SDL_joylist_head (i, joystick->index);
   1.854 -        SDL_JoystickClose (SDL_joylist[i].joy);
   1.855 +        SDL_joylist_head(i, joystick->index);
   1.856 +        SDL_JoystickClose(SDL_joylist[i].joy);
   1.857      }
   1.858  #endif
   1.859  
   1.860 @@ -1213,26 +1210,26 @@
   1.861  #ifndef NO_LOGICAL_JOYSTICKS
   1.862          if (SDL_joylist[joystick->index].fname != NULL)
   1.863  #endif
   1.864 -            close (joystick->hwdata->fd);
   1.865 +            close(joystick->hwdata->fd);
   1.866          if (joystick->hwdata->hats) {
   1.867 -            SDL_free (joystick->hwdata->hats);
   1.868 +            SDL_free(joystick->hwdata->hats);
   1.869          }
   1.870          if (joystick->hwdata->balls) {
   1.871 -            SDL_free (joystick->hwdata->balls);
   1.872 +            SDL_free(joystick->hwdata->balls);
   1.873          }
   1.874 -        SDL_free (joystick->hwdata);
   1.875 +        SDL_free(joystick->hwdata);
   1.876          joystick->hwdata = NULL;
   1.877      }
   1.878  }
   1.879  
   1.880  /* Function to perform any system-specific joystick related cleanup */
   1.881  void
   1.882 -SDL_SYS_JoystickQuit (void)
   1.883 +SDL_SYS_JoystickQuit(void)
   1.884  {
   1.885      int i;
   1.886  
   1.887      for (i = 0; SDL_joylist[i].fname; ++i) {
   1.888 -        SDL_free (SDL_joylist[i].fname);
   1.889 +        SDL_free(SDL_joylist[i].fname);
   1.890      }
   1.891      SDL_joylist[0].fname = NULL;
   1.892  }