test/testcdrom.c
branchSDL-1.3
changeset 1668 4da1ee79c9af
parent 1662 782fd950bd46
     1.1 --- a/test/testcdrom.c	Mon May 29 03:53:21 2006 +0000
     1.2 +++ b/test/testcdrom.c	Mon May 29 04:04:35 2006 +0000
     1.3 @@ -10,19 +10,19 @@
     1.4  
     1.5  /* Call this instead of exit(), so we can clean up SDL: atexit() is evil. */
     1.6  static void
     1.7 -quit (int rc)
     1.8 +quit(int rc)
     1.9  {
    1.10 -    SDL_Quit ();
    1.11 -    exit (rc);
    1.12 +    SDL_Quit();
    1.13 +    exit(rc);
    1.14  }
    1.15  
    1.16  static void
    1.17 -PrintStatus (int driveindex, SDL_CD * cdrom)
    1.18 +PrintStatus(int driveindex, SDL_CD * cdrom)
    1.19  {
    1.20      CDstatus status;
    1.21      char *status_str;
    1.22  
    1.23 -    status = SDL_CDStatus (cdrom);
    1.24 +    status = SDL_CDStatus(cdrom);
    1.25      switch (status) {
    1.26      case CD_TRAYEMPTY:
    1.27          status_str = "tray empty";
    1.28 @@ -40,26 +40,26 @@
    1.29          status_str = "error state";
    1.30          break;
    1.31      }
    1.32 -    printf ("Drive %d status: %s\n", driveindex, status_str);
    1.33 +    printf("Drive %d status: %s\n", driveindex, status_str);
    1.34      if (status >= CD_PLAYING) {
    1.35          int m, s, f;
    1.36 -        FRAMES_TO_MSF (cdrom->cur_frame, &m, &s, &f);
    1.37 -        printf ("Currently playing track %d, %d:%2.2d\n",
    1.38 -                cdrom->track[cdrom->cur_track].id, m, s);
    1.39 +        FRAMES_TO_MSF(cdrom->cur_frame, &m, &s, &f);
    1.40 +        printf("Currently playing track %d, %d:%2.2d\n",
    1.41 +               cdrom->track[cdrom->cur_track].id, m, s);
    1.42      }
    1.43  }
    1.44  
    1.45  static void
    1.46 -ListTracks (SDL_CD * cdrom)
    1.47 +ListTracks(SDL_CD * cdrom)
    1.48  {
    1.49      int i;
    1.50      int m, s, f;
    1.51      char *trtype;
    1.52  
    1.53 -    SDL_CDStatus (cdrom);
    1.54 -    printf ("Drive tracks: %d\n", cdrom->numtracks);
    1.55 +    SDL_CDStatus(cdrom);
    1.56 +    printf("Drive tracks: %d\n", cdrom->numtracks);
    1.57      for (i = 0; i < cdrom->numtracks; ++i) {
    1.58 -        FRAMES_TO_MSF (cdrom->track[i].length, &m, &s, &f);
    1.59 +        FRAMES_TO_MSF(cdrom->track[i].length, &m, &s, &f);
    1.60          if (f > 0)
    1.61              ++s;
    1.62          switch (cdrom->track[i].type) {
    1.63 @@ -73,61 +73,61 @@
    1.64              trtype = "unknown";
    1.65              break;
    1.66          }
    1.67 -        printf ("\tTrack (index %d) %d: %d:%2.2d / %d [%s track]\n", i,
    1.68 -                cdrom->track[i].id, m, s, cdrom->track[i].length, trtype);
    1.69 +        printf("\tTrack (index %d) %d: %d:%2.2d / %d [%s track]\n", i,
    1.70 +               cdrom->track[i].id, m, s, cdrom->track[i].length, trtype);
    1.71      }
    1.72  }
    1.73  
    1.74  static void
    1.75 -PrintUsage (char *argv0)
    1.76 +PrintUsage(char *argv0)
    1.77  {
    1.78 -    fprintf (stderr, "Usage: %s [drive#] [command] [command] ...\n", argv0);
    1.79 -    fprintf (stderr, "Where 'command' is one of:\n");
    1.80 -    fprintf (stderr, "	-status\n");
    1.81 -    fprintf (stderr, "	-list\n");
    1.82 -    fprintf (stderr,
    1.83 -             "	-play [first_track] [first_frame] [num_tracks] [num_frames]\n");
    1.84 -    fprintf (stderr, "	-pause\n");
    1.85 -    fprintf (stderr, "	-resume\n");
    1.86 -    fprintf (stderr, "	-stop\n");
    1.87 -    fprintf (stderr, "	-eject\n");
    1.88 -    fprintf (stderr, "	-sleep <milliseconds>\n");
    1.89 +    fprintf(stderr, "Usage: %s [drive#] [command] [command] ...\n", argv0);
    1.90 +    fprintf(stderr, "Where 'command' is one of:\n");
    1.91 +    fprintf(stderr, "	-status\n");
    1.92 +    fprintf(stderr, "	-list\n");
    1.93 +    fprintf(stderr,
    1.94 +            "	-play [first_track] [first_frame] [num_tracks] [num_frames]\n");
    1.95 +    fprintf(stderr, "	-pause\n");
    1.96 +    fprintf(stderr, "	-resume\n");
    1.97 +    fprintf(stderr, "	-stop\n");
    1.98 +    fprintf(stderr, "	-eject\n");
    1.99 +    fprintf(stderr, "	-sleep <milliseconds>\n");
   1.100  }
   1.101  
   1.102  int
   1.103 -main (int argc, char *argv[])
   1.104 +main(int argc, char *argv[])
   1.105  {
   1.106      int drive;
   1.107      int i;
   1.108      SDL_CD *cdrom;
   1.109  
   1.110      /* Initialize SDL first */
   1.111 -    if (SDL_Init (SDL_INIT_CDROM) < 0) {
   1.112 -        fprintf (stderr, "Couldn't initialize SDL: %s\n", SDL_GetError ());
   1.113 +    if (SDL_Init(SDL_INIT_CDROM) < 0) {
   1.114 +        fprintf(stderr, "Couldn't initialize SDL: %s\n", SDL_GetError());
   1.115          return (1);
   1.116      }
   1.117  
   1.118      /* Find out how many CD-ROM drives are connected to the system */
   1.119 -    if (SDL_CDNumDrives () == 0) {
   1.120 -        printf ("No CD-ROM devices detected\n");
   1.121 -        quit (0);
   1.122 +    if (SDL_CDNumDrives() == 0) {
   1.123 +        printf("No CD-ROM devices detected\n");
   1.124 +        quit(0);
   1.125      }
   1.126 -    printf ("Drives available: %d\n", SDL_CDNumDrives ());
   1.127 -    for (i = 0; i < SDL_CDNumDrives (); ++i) {
   1.128 -        printf ("Drive %d:  \"%s\"\n", i, SDL_CDName (i));
   1.129 +    printf("Drives available: %d\n", SDL_CDNumDrives());
   1.130 +    for (i = 0; i < SDL_CDNumDrives(); ++i) {
   1.131 +        printf("Drive %d:  \"%s\"\n", i, SDL_CDName(i));
   1.132      }
   1.133  
   1.134      /* Open the CD-ROM */
   1.135      drive = 0;
   1.136      i = 1;
   1.137 -    if (argv[i] && isdigit (argv[i][0])) {
   1.138 -        drive = atoi (argv[i++]);
   1.139 +    if (argv[i] && isdigit(argv[i][0])) {
   1.140 +        drive = atoi(argv[i++]);
   1.141      }
   1.142 -    cdrom = SDL_CDOpen (drive);
   1.143 +    cdrom = SDL_CDOpen(drive);
   1.144      if (cdrom == NULL) {
   1.145 -        fprintf (stderr, "Couldn't open drive %d: %s\n", drive,
   1.146 -                 SDL_GetError ());
   1.147 -        quit (2);
   1.148 +        fprintf(stderr, "Couldn't open drive %d: %s\n", drive,
   1.149 +                SDL_GetError());
   1.150 +        quit(2);
   1.151      }
   1.152  #ifdef TEST_NULLCD
   1.153      cdrom = NULL;
   1.154 @@ -135,69 +135,69 @@
   1.155  
   1.156      /* Find out which function to perform */
   1.157      for (; argv[i]; ++i) {
   1.158 -        if (strcmp (argv[i], "-status") == 0) {
   1.159 +        if (strcmp(argv[i], "-status") == 0) {
   1.160              /* PrintStatus(drive, cdrom); */
   1.161 -        } else if (strcmp (argv[i], "-list") == 0) {
   1.162 -            ListTracks (cdrom);
   1.163 -        } else if (strcmp (argv[i], "-play") == 0) {
   1.164 +        } else if (strcmp(argv[i], "-list") == 0) {
   1.165 +            ListTracks(cdrom);
   1.166 +        } else if (strcmp(argv[i], "-play") == 0) {
   1.167              int strack, sframe;
   1.168              int ntrack, nframe;
   1.169  
   1.170              strack = 0;
   1.171 -            if (argv[i + 1] && isdigit (argv[i + 1][0])) {
   1.172 -                strack = atoi (argv[++i]);
   1.173 +            if (argv[i + 1] && isdigit(argv[i + 1][0])) {
   1.174 +                strack = atoi(argv[++i]);
   1.175              }
   1.176              sframe = 0;
   1.177 -            if (argv[i + 1] && isdigit (argv[i + 1][0])) {
   1.178 -                sframe = atoi (argv[++i]);
   1.179 +            if (argv[i + 1] && isdigit(argv[i + 1][0])) {
   1.180 +                sframe = atoi(argv[++i]);
   1.181              }
   1.182              ntrack = 0;
   1.183 -            if (argv[i + 1] && isdigit (argv[i + 1][0])) {
   1.184 -                ntrack = atoi (argv[++i]);
   1.185 +            if (argv[i + 1] && isdigit(argv[i + 1][0])) {
   1.186 +                ntrack = atoi(argv[++i]);
   1.187              }
   1.188              nframe = 0;
   1.189 -            if (argv[i + 1] && isdigit (argv[i + 1][0])) {
   1.190 -                nframe = atoi (argv[++i]);
   1.191 +            if (argv[i + 1] && isdigit(argv[i + 1][0])) {
   1.192 +                nframe = atoi(argv[++i]);
   1.193              }
   1.194 -            if (CD_INDRIVE (SDL_CDStatus (cdrom))) {
   1.195 -                if (SDL_CDPlayTracks (cdrom, strack, sframe,
   1.196 -                                      ntrack, nframe) < 0) {
   1.197 -                    fprintf (stderr,
   1.198 -                             "Couldn't play tracks %d/%d for %d/%d: %s\n",
   1.199 -                             strack, sframe, ntrack, nframe, SDL_GetError ());
   1.200 +            if (CD_INDRIVE(SDL_CDStatus(cdrom))) {
   1.201 +                if (SDL_CDPlayTracks(cdrom, strack, sframe,
   1.202 +                                     ntrack, nframe) < 0) {
   1.203 +                    fprintf(stderr,
   1.204 +                            "Couldn't play tracks %d/%d for %d/%d: %s\n",
   1.205 +                            strack, sframe, ntrack, nframe, SDL_GetError());
   1.206                  }
   1.207              } else {
   1.208 -                fprintf (stderr, "No CD in drive!\n");
   1.209 +                fprintf(stderr, "No CD in drive!\n");
   1.210              }
   1.211 -        } else if (strcmp (argv[i], "-pause") == 0) {
   1.212 -            if (SDL_CDPause (cdrom) < 0) {
   1.213 -                fprintf (stderr, "Couldn't pause CD: %s\n", SDL_GetError ());
   1.214 +        } else if (strcmp(argv[i], "-pause") == 0) {
   1.215 +            if (SDL_CDPause(cdrom) < 0) {
   1.216 +                fprintf(stderr, "Couldn't pause CD: %s\n", SDL_GetError());
   1.217              }
   1.218 -        } else if (strcmp (argv[i], "-resume") == 0) {
   1.219 -            if (SDL_CDResume (cdrom) < 0) {
   1.220 -                fprintf (stderr, "Couldn't resume CD: %s\n", SDL_GetError ());
   1.221 +        } else if (strcmp(argv[i], "-resume") == 0) {
   1.222 +            if (SDL_CDResume(cdrom) < 0) {
   1.223 +                fprintf(stderr, "Couldn't resume CD: %s\n", SDL_GetError());
   1.224              }
   1.225 -        } else if (strcmp (argv[i], "-stop") == 0) {
   1.226 -            if (SDL_CDStop (cdrom) < 0) {
   1.227 -                fprintf (stderr, "Couldn't eject CD: %s\n", SDL_GetError ());
   1.228 +        } else if (strcmp(argv[i], "-stop") == 0) {
   1.229 +            if (SDL_CDStop(cdrom) < 0) {
   1.230 +                fprintf(stderr, "Couldn't eject CD: %s\n", SDL_GetError());
   1.231              }
   1.232 -        } else if (strcmp (argv[i], "-eject") == 0) {
   1.233 -            if (SDL_CDEject (cdrom) < 0) {
   1.234 -                fprintf (stderr, "Couldn't eject CD: %s\n", SDL_GetError ());
   1.235 +        } else if (strcmp(argv[i], "-eject") == 0) {
   1.236 +            if (SDL_CDEject(cdrom) < 0) {
   1.237 +                fprintf(stderr, "Couldn't eject CD: %s\n", SDL_GetError());
   1.238              }
   1.239 -        } else if ((strcmp (argv[i], "-sleep") == 0) &&
   1.240 -                   (argv[i + 1] && isdigit (argv[i + 1][0]))) {
   1.241 -            SDL_Delay (atoi (argv[++i]));
   1.242 -            printf ("Delayed %d milliseconds\n", atoi (argv[i]));
   1.243 +        } else if ((strcmp(argv[i], "-sleep") == 0) &&
   1.244 +                   (argv[i + 1] && isdigit(argv[i + 1][0]))) {
   1.245 +            SDL_Delay(atoi(argv[++i]));
   1.246 +            printf("Delayed %d milliseconds\n", atoi(argv[i]));
   1.247          } else {
   1.248 -            PrintUsage (argv[0]);
   1.249 -            SDL_CDClose (cdrom);
   1.250 -            quit (1);
   1.251 +            PrintUsage(argv[0]);
   1.252 +            SDL_CDClose(cdrom);
   1.253 +            quit(1);
   1.254          }
   1.255      }
   1.256 -    PrintStatus (drive, cdrom);
   1.257 -    SDL_CDClose (cdrom);
   1.258 -    SDL_Quit ();
   1.259 +    PrintStatus(drive, cdrom);
   1.260 +    SDL_CDClose(cdrom);
   1.261 +    SDL_Quit();
   1.262  
   1.263      return (0);
   1.264  }