test/testhaptic.c
changeset 2748 5668c3dfe7bc
parent 2713 0906692aa6a4
child 3338 9de326b3099c
     1.1 --- a/test/testhaptic.c	Tue Sep 02 20:27:47 2008 +0000
     1.2 +++ b/test/testhaptic.c	Thu Sep 04 13:43:39 2008 +0000
     1.3 @@ -19,7 +19,7 @@
     1.4  
     1.5  #include <stdio.h>              /* printf */
     1.6  #include <string.h>             /* strstr */
     1.7 -
     1.8 +#include <ctype.h>              /* isdigit */
     1.9  
    1.10  
    1.11  static SDL_Haptic *haptic;
    1.12 @@ -42,20 +42,29 @@
    1.13  {
    1.14      int i;
    1.15      char *name;
    1.16 +    int index;
    1.17      SDL_HapticEffect efx[5];
    1.18      int id[5];
    1.19      int nefx;
    1.20      unsigned int supported;
    1.21  
    1.22      name = NULL;
    1.23 +    index = -1;
    1.24      if (argc > 1) {
    1.25          name = argv[1];
    1.26          if ((strcmp(name, "--help") == 0) || (strcmp(name, "-h") == 0)) {
    1.27 -            printf("USAGE: %s [device name]\n"
    1.28 -                   "If device name is specified, it will try to find a device whose name\n"
    1.29 -                   "contains device name for testing.\n", argv[0]);
    1.30 +            printf("USAGE: %s [device]\n"
    1.31 +                   "If device is a two-digit number it'll use it as an index, otherwise\n"
    1.32 +                   "it'll use it as if it were part of the device's name.\n",
    1.33 +                   argv[0]);
    1.34              return 0;
    1.35          }
    1.36 +
    1.37 +        i = strlen(name);
    1.38 +        if ((i < 3) && isdigit(name[0]) && ((i == 1) || isdigit(name[1]))) {
    1.39 +            index = atoi(name);
    1.40 +            name = NULL;
    1.41 +        }
    1.42      }
    1.43  
    1.44      /* Initialize the force feedbackness */
    1.45 @@ -63,9 +72,9 @@
    1.46               SDL_INIT_HAPTIC);
    1.47      printf("%d Haptic devices detected.\n", SDL_NumHaptics());
    1.48      if (SDL_NumHaptics() > 0) {
    1.49 -        /* We'll just use the first force feedback device found */
    1.50 +        /* We'll just use index or the first force feedback device found */
    1.51          if (name == NULL) {
    1.52 -            i = 0;
    1.53 +            i = (index != -1) ? index : 0;
    1.54          }
    1.55          /* Try to find matching device */
    1.56          else {
    1.57 @@ -83,7 +92,8 @@
    1.58  
    1.59          haptic = SDL_HapticOpen(i);
    1.60          if (haptic == NULL) {
    1.61 -            perror("Unable to create the haptic device");
    1.62 +            printf("Unable to create the haptic device: %s\n",
    1.63 +                   SDL_GetError());
    1.64              return 1;
    1.65          }
    1.66          printf("Device: %s\n", SDL_HapticName(i));