src/cdrom/macosx/SDL_syscdrom.c
branchSDL-1.3
changeset 1668 4da1ee79c9af
parent 1662 782fd950bd46
     1.1 --- a/src/cdrom/macosx/SDL_syscdrom.c	Mon May 29 03:53:21 2006 +0000
     1.2 +++ b/src/cdrom/macosx/SDL_syscdrom.c	Mon May 29 04:04:35 2006 +0000
     1.3 @@ -40,22 +40,22 @@
     1.4  
     1.5  #pragma mark -- Prototypes --
     1.6  
     1.7 -static const char *SDL_SYS_CDName (int drive);
     1.8 -static int SDL_SYS_CDOpen (int drive);
     1.9 -static int SDL_SYS_CDGetTOC (SDL_CD * cdrom);
    1.10 -static CDstatus SDL_SYS_CDStatus (SDL_CD * cdrom, int *position);
    1.11 -static int SDL_SYS_CDPlay (SDL_CD * cdrom, int start, int length);
    1.12 -static int SDL_SYS_CDPause (SDL_CD * cdrom);
    1.13 -static int SDL_SYS_CDResume (SDL_CD * cdrom);
    1.14 -static int SDL_SYS_CDStop (SDL_CD * cdrom);
    1.15 -static int SDL_SYS_CDEject (SDL_CD * cdrom);
    1.16 -static void SDL_SYS_CDClose (SDL_CD * cdrom);
    1.17 +static const char *SDL_SYS_CDName(int drive);
    1.18 +static int SDL_SYS_CDOpen(int drive);
    1.19 +static int SDL_SYS_CDGetTOC(SDL_CD * cdrom);
    1.20 +static CDstatus SDL_SYS_CDStatus(SDL_CD * cdrom, int *position);
    1.21 +static int SDL_SYS_CDPlay(SDL_CD * cdrom, int start, int length);
    1.22 +static int SDL_SYS_CDPause(SDL_CD * cdrom);
    1.23 +static int SDL_SYS_CDResume(SDL_CD * cdrom);
    1.24 +static int SDL_SYS_CDStop(SDL_CD * cdrom);
    1.25 +static int SDL_SYS_CDEject(SDL_CD * cdrom);
    1.26 +static void SDL_SYS_CDClose(SDL_CD * cdrom);
    1.27  
    1.28  #pragma mark -- Helper Functions --
    1.29  
    1.30  /* Read a list of tracks from the volume */
    1.31  static int
    1.32 -LoadTracks (SDL_CD * cdrom)
    1.33 +LoadTracks(SDL_CD * cdrom)
    1.34  {
    1.35      /* Check if tracks are already loaded */
    1.36      if (tracks[cdrom->id] != NULL)
    1.37 @@ -63,9 +63,9 @@
    1.38  
    1.39      /* Allocate memory for tracks */
    1.40      tracks[cdrom->id] =
    1.41 -        (FSRef *) SDL_calloc (1, sizeof (**tracks) * cdrom->numtracks);
    1.42 +        (FSRef *) SDL_calloc(1, sizeof(**tracks) * cdrom->numtracks);
    1.43      if (tracks[cdrom->id] == NULL) {
    1.44 -        SDL_OutOfMemory ();
    1.45 +        SDL_OutOfMemory();
    1.46          return -1;
    1.47      }
    1.48  
    1.49 @@ -79,8 +79,8 @@
    1.50  
    1.51  /* Find a file for a given start frame and length */
    1.52  static FSRef *
    1.53 -GetFileForOffset (SDL_CD * cdrom, int start, int length, int *outStartFrame,
    1.54 -                  int *outStopFrame)
    1.55 +GetFileForOffset(SDL_CD * cdrom, int start, int length, int *outStartFrame,
    1.56 +                 int *outStopFrame)
    1.57  {
    1.58      int i;
    1.59  
    1.60 @@ -115,10 +115,10 @@
    1.61  
    1.62  /* Setup another file for playback, or stop playback (called from another thread) */
    1.63  static void
    1.64 -CompletionProc (SDL_CD * cdrom)
    1.65 +CompletionProc(SDL_CD * cdrom)
    1.66  {
    1.67  
    1.68 -    Lock ();
    1.69 +    Lock();
    1.70  
    1.71      if (nextTrackFrame > 0 && nextTrackFramesRemaining > 0) {
    1.72  
    1.73 @@ -126,33 +126,33 @@
    1.74          int startFrame, stopFrame;
    1.75          FSRef *file;
    1.76  
    1.77 -        PauseFile ();
    1.78 -        ReleaseFile ();
    1.79 +        PauseFile();
    1.80 +        ReleaseFile();
    1.81  
    1.82 -        file = GetFileForOffset (cdrom, nextTrackFrame,
    1.83 -                                 nextTrackFramesRemaining, &startFrame,
    1.84 -                                 &stopFrame);
    1.85 +        file = GetFileForOffset(cdrom, nextTrackFrame,
    1.86 +                                nextTrackFramesRemaining, &startFrame,
    1.87 +                                &stopFrame);
    1.88  
    1.89          if (file == NULL) {
    1.90              status = CD_STOPPED;
    1.91 -            Unlock ();
    1.92 +            Unlock();
    1.93              return;
    1.94          }
    1.95  
    1.96 -        LoadFile (file, startFrame, stopFrame);
    1.97 +        LoadFile(file, startFrame, stopFrame);
    1.98  
    1.99 -        SetCompletionProc (CompletionProc, cdrom);
   1.100 +        SetCompletionProc(CompletionProc, cdrom);
   1.101  
   1.102 -        PlayFile ();
   1.103 +        PlayFile();
   1.104      } else {
   1.105  
   1.106          /* Release the current file */
   1.107 -        PauseFile ();
   1.108 -        ReleaseFile ();
   1.109 +        PauseFile();
   1.110 +        ReleaseFile();
   1.111          status = CD_STOPPED;
   1.112      }
   1.113  
   1.114 -    Unlock ();
   1.115 +    Unlock();
   1.116  }
   1.117  
   1.118  
   1.119 @@ -160,7 +160,7 @@
   1.120  
   1.121  /* Initialize */
   1.122  int
   1.123 -SDL_SYS_CDInit (void)
   1.124 +SDL_SYS_CDInit(void)
   1.125  {
   1.126      /* Initialize globals */
   1.127      volumes = NULL;
   1.128 @@ -196,7 +196,7 @@
   1.129       */
   1.130  
   1.131      /* Find out how many cd volumes are mounted */
   1.132 -    SDL_numcds = DetectAudioCDVolumes (NULL, 0);
   1.133 +    SDL_numcds = DetectAudioCDVolumes(NULL, 0);
   1.134  
   1.135      /*
   1.136         If there are no volumes, fake a cd device
   1.137 @@ -212,17 +212,16 @@
   1.138      }
   1.139  
   1.140      /* Allocate space for volumes */
   1.141 -    volumes =
   1.142 -        (FSVolumeRefNum *) SDL_calloc (1, sizeof (*volumes) * SDL_numcds);
   1.143 +    volumes = (FSVolumeRefNum *) SDL_calloc(1, sizeof(*volumes) * SDL_numcds);
   1.144      if (volumes == NULL) {
   1.145 -        SDL_OutOfMemory ();
   1.146 +        SDL_OutOfMemory();
   1.147          return -1;
   1.148      }
   1.149  
   1.150      /* Allocate space for tracks */
   1.151 -    tracks = (FSRef **) SDL_calloc (1, sizeof (*tracks) * (SDL_numcds + 1));
   1.152 +    tracks = (FSRef **) SDL_calloc(1, sizeof(*tracks) * (SDL_numcds + 1));
   1.153      if (tracks == NULL) {
   1.154 -        SDL_OutOfMemory ();
   1.155 +        SDL_OutOfMemory();
   1.156          return -1;
   1.157      }
   1.158  
   1.159 @@ -236,11 +235,11 @@
   1.160      {
   1.161          int numVolumes = SDL_numcds;
   1.162  
   1.163 -        SDL_numcds = DetectAudioCDVolumes (volumes, numVolumes);
   1.164 +        SDL_numcds = DetectAudioCDVolumes(volumes, numVolumes);
   1.165  
   1.166          /* If more cds suddenly show up, ignore them */
   1.167          if (SDL_numcds > numVolumes) {
   1.168 -            SDL_SetError ("Some CD's were added but they will be ignored");
   1.169 +            SDL_SetError("Some CD's were added but they will be ignored");
   1.170              SDL_numcds = numVolumes;
   1.171          }
   1.172      }
   1.173 @@ -250,27 +249,27 @@
   1.174  
   1.175  /* Shutdown and cleanup */
   1.176  void
   1.177 -SDL_SYS_CDQuit (void)
   1.178 +SDL_SYS_CDQuit(void)
   1.179  {
   1.180 -    ReleaseFile ();
   1.181 +    ReleaseFile();
   1.182  
   1.183      if (volumes != NULL)
   1.184 -        free (volumes);
   1.185 +        free(volumes);
   1.186  
   1.187      if (tracks != NULL) {
   1.188  
   1.189          FSRef **ptr;
   1.190          for (ptr = tracks; *ptr != (FSRef *) - 1; ptr++)
   1.191              if (*ptr != NULL)
   1.192 -                free (*ptr);
   1.193 +                free(*ptr);
   1.194  
   1.195 -        free (tracks);
   1.196 +        free(tracks);
   1.197      }
   1.198  }
   1.199  
   1.200  /* Get the Unix disk name of the volume */
   1.201  static const char *
   1.202 -SDL_SYS_CDName (int drive)
   1.203 +SDL_SYS_CDName(int drive)
   1.204  {
   1.205      OSStatus err = noErr;
   1.206      HParamBlockRec pb;
   1.207 @@ -282,11 +281,11 @@
   1.208      pb.ioParam.ioNamePtr = NULL;
   1.209      pb.ioParam.ioVRefNum = volumes[drive];
   1.210      pb.ioParam.ioBuffer = (Ptr) & volParmsInfo;
   1.211 -    pb.ioParam.ioReqCount = (SInt32) sizeof (volParmsInfo);
   1.212 -    err = PBHGetVolParmsSync (&pb);
   1.213 +    pb.ioParam.ioReqCount = (SInt32) sizeof(volParmsInfo);
   1.214 +    err = PBHGetVolParmsSync(&pb);
   1.215  
   1.216      if (err != noErr) {
   1.217 -        SDL_SetError ("PBHGetVolParmsSync returned %d", err);
   1.218 +        SDL_SetError("PBHGetVolParmsSync returned %d", err);
   1.219          return NULL;
   1.220      }
   1.221  
   1.222 @@ -295,11 +294,11 @@
   1.223  
   1.224  /* Open the "device" */
   1.225  static int
   1.226 -SDL_SYS_CDOpen (int drive)
   1.227 +SDL_SYS_CDOpen(int drive)
   1.228  {
   1.229      /* Only allow 1 device to be open */
   1.230      if (currentDrive >= 0) {
   1.231 -        SDL_SetError ("Only one cdrom is supported");
   1.232 +        SDL_SetError("Only one cdrom is supported");
   1.233          return -1;
   1.234      } else
   1.235          currentDrive = drive;
   1.236 @@ -309,10 +308,10 @@
   1.237  
   1.238  /* Get the table of contents */
   1.239  static int
   1.240 -SDL_SYS_CDGetTOC (SDL_CD * cdrom)
   1.241 +SDL_SYS_CDGetTOC(SDL_CD * cdrom)
   1.242  {
   1.243      if (fakeCD) {
   1.244 -        SDL_SetError (kErrorFakeDevice);
   1.245 +        SDL_SetError(kErrorFakeDevice);
   1.246          return -1;
   1.247      }
   1.248  
   1.249 @@ -322,7 +321,7 @@
   1.250      }
   1.251  
   1.252  
   1.253 -    ReadTOCData (volumes[cdrom->id], cdrom);
   1.254 +    ReadTOCData(volumes[cdrom->id], cdrom);
   1.255      didReadTOC = SDL_TRUE;
   1.256      cacheTOCNumTracks = cdrom->numtracks;
   1.257  
   1.258 @@ -331,14 +330,14 @@
   1.259  
   1.260  /* Get CD-ROM status */
   1.261  static CDstatus
   1.262 -SDL_SYS_CDStatus (SDL_CD * cdrom, int *position)
   1.263 +SDL_SYS_CDStatus(SDL_CD * cdrom, int *position)
   1.264  {
   1.265      if (position) {
   1.266          int trackFrame;
   1.267  
   1.268 -        Lock ();
   1.269 -        trackFrame = GetCurrentFrame ();
   1.270 -        Unlock ();
   1.271 +        Lock();
   1.272 +        trackFrame = GetCurrentFrame();
   1.273 +        Unlock();
   1.274  
   1.275          *position = cdrom->track[currentTrack].offset + trackFrame;
   1.276      }
   1.277 @@ -348,155 +347,155 @@
   1.278  
   1.279  /* Start playback */
   1.280  static int
   1.281 -SDL_SYS_CDPlay (SDL_CD * cdrom, int start, int length)
   1.282 +SDL_SYS_CDPlay(SDL_CD * cdrom, int start, int length)
   1.283  {
   1.284      int startFrame, stopFrame;
   1.285      FSRef *ref;
   1.286  
   1.287      if (fakeCD) {
   1.288 -        SDL_SetError (kErrorFakeDevice);
   1.289 +        SDL_SetError(kErrorFakeDevice);
   1.290          return -1;
   1.291      }
   1.292  
   1.293 -    Lock ();
   1.294 +    Lock();
   1.295  
   1.296 -    if (LoadTracks (cdrom) < 0)
   1.297 +    if (LoadTracks(cdrom) < 0)
   1.298          return -2;
   1.299  
   1.300 -    if (PauseFile () < 0)
   1.301 +    if (PauseFile() < 0)
   1.302          return -3;
   1.303  
   1.304 -    if (ReleaseFile () < 0)
   1.305 +    if (ReleaseFile() < 0)
   1.306          return -4;
   1.307  
   1.308 -    ref = GetFileForOffset (cdrom, start, length, &startFrame, &stopFrame);
   1.309 +    ref = GetFileForOffset(cdrom, start, length, &startFrame, &stopFrame);
   1.310      if (ref == NULL) {
   1.311 -        SDL_SetError ("SDL_SYS_CDPlay: No file for start=%d, length=%d",
   1.312 -                      start, length);
   1.313 +        SDL_SetError("SDL_SYS_CDPlay: No file for start=%d, length=%d",
   1.314 +                     start, length);
   1.315          return -5;
   1.316      }
   1.317  
   1.318 -    if (LoadFile (ref, startFrame, stopFrame) < 0)
   1.319 +    if (LoadFile(ref, startFrame, stopFrame) < 0)
   1.320          return -6;
   1.321  
   1.322 -    SetCompletionProc (CompletionProc, cdrom);
   1.323 +    SetCompletionProc(CompletionProc, cdrom);
   1.324  
   1.325 -    if (PlayFile () < 0)
   1.326 +    if (PlayFile() < 0)
   1.327          return -7;
   1.328  
   1.329      status = CD_PLAYING;
   1.330  
   1.331 -    Unlock ();
   1.332 +    Unlock();
   1.333  
   1.334      return 0;
   1.335  }
   1.336  
   1.337  /* Pause playback */
   1.338  static int
   1.339 -SDL_SYS_CDPause (SDL_CD * cdrom)
   1.340 +SDL_SYS_CDPause(SDL_CD * cdrom)
   1.341  {
   1.342      if (fakeCD) {
   1.343 -        SDL_SetError (kErrorFakeDevice);
   1.344 +        SDL_SetError(kErrorFakeDevice);
   1.345          return -1;
   1.346      }
   1.347  
   1.348 -    Lock ();
   1.349 +    Lock();
   1.350  
   1.351 -    if (PauseFile () < 0) {
   1.352 -        Unlock ();
   1.353 +    if (PauseFile() < 0) {
   1.354 +        Unlock();
   1.355          return -2;
   1.356      }
   1.357  
   1.358      status = CD_PAUSED;
   1.359  
   1.360 -    Unlock ();
   1.361 +    Unlock();
   1.362  
   1.363      return 0;
   1.364  }
   1.365  
   1.366  /* Resume playback */
   1.367  static int
   1.368 -SDL_SYS_CDResume (SDL_CD * cdrom)
   1.369 +SDL_SYS_CDResume(SDL_CD * cdrom)
   1.370  {
   1.371      if (fakeCD) {
   1.372 -        SDL_SetError (kErrorFakeDevice);
   1.373 +        SDL_SetError(kErrorFakeDevice);
   1.374          return -1;
   1.375      }
   1.376  
   1.377 -    Lock ();
   1.378 +    Lock();
   1.379  
   1.380 -    if (PlayFile () < 0) {
   1.381 -        Unlock ();
   1.382 +    if (PlayFile() < 0) {
   1.383 +        Unlock();
   1.384          return -2;
   1.385      }
   1.386  
   1.387      status = CD_PLAYING;
   1.388  
   1.389 -    Unlock ();
   1.390 +    Unlock();
   1.391  
   1.392      return 0;
   1.393  }
   1.394  
   1.395  /* Stop playback */
   1.396  static int
   1.397 -SDL_SYS_CDStop (SDL_CD * cdrom)
   1.398 +SDL_SYS_CDStop(SDL_CD * cdrom)
   1.399  {
   1.400      if (fakeCD) {
   1.401 -        SDL_SetError (kErrorFakeDevice);
   1.402 +        SDL_SetError(kErrorFakeDevice);
   1.403          return -1;
   1.404      }
   1.405  
   1.406 -    Lock ();
   1.407 +    Lock();
   1.408  
   1.409 -    if (PauseFile () < 0) {
   1.410 -        Unlock ();
   1.411 +    if (PauseFile() < 0) {
   1.412 +        Unlock();
   1.413          return -2;
   1.414      }
   1.415  
   1.416 -    if (ReleaseFile () < 0) {
   1.417 -        Unlock ();
   1.418 +    if (ReleaseFile() < 0) {
   1.419 +        Unlock();
   1.420          return -3;
   1.421      }
   1.422  
   1.423      status = CD_STOPPED;
   1.424  
   1.425 -    Unlock ();
   1.426 +    Unlock();
   1.427  
   1.428      return 0;
   1.429  }
   1.430  
   1.431  /* Eject the CD-ROM (Unmount the volume) */
   1.432  static int
   1.433 -SDL_SYS_CDEject (SDL_CD * cdrom)
   1.434 +SDL_SYS_CDEject(SDL_CD * cdrom)
   1.435  {
   1.436      OSStatus err;
   1.437      pid_t dissenter;
   1.438  
   1.439      if (fakeCD) {
   1.440 -        SDL_SetError (kErrorFakeDevice);
   1.441 +        SDL_SetError(kErrorFakeDevice);
   1.442          return -1;
   1.443      }
   1.444  
   1.445 -    Lock ();
   1.446 +    Lock();
   1.447  
   1.448 -    if (PauseFile () < 0) {
   1.449 -        Unlock ();
   1.450 +    if (PauseFile() < 0) {
   1.451 +        Unlock();
   1.452          return -2;
   1.453      }
   1.454  
   1.455 -    if (ReleaseFile () < 0) {
   1.456 -        Unlock ();
   1.457 +    if (ReleaseFile() < 0) {
   1.458 +        Unlock();
   1.459          return -3;
   1.460      }
   1.461  
   1.462      status = CD_STOPPED;
   1.463  
   1.464      /* Eject the volume */
   1.465 -    err = FSEjectVolumeSync (volumes[cdrom->id], kNilOptions, &dissenter);
   1.466 +    err = FSEjectVolumeSync(volumes[cdrom->id], kNilOptions, &dissenter);
   1.467  
   1.468      if (err != noErr) {
   1.469 -        Unlock ();
   1.470 -        SDL_SetError ("PBUnmountVol returned %d", err);
   1.471 +        Unlock();
   1.472 +        SDL_SetError("PBUnmountVol returned %d", err);
   1.473          return -4;
   1.474      }
   1.475  
   1.476 @@ -504,17 +503,17 @@
   1.477  
   1.478      /* Invalidate volume and track info */
   1.479      volumes[cdrom->id] = 0;
   1.480 -    free (tracks[cdrom->id]);
   1.481 +    free(tracks[cdrom->id]);
   1.482      tracks[cdrom->id] = NULL;
   1.483  
   1.484 -    Unlock ();
   1.485 +    Unlock();
   1.486  
   1.487      return 0;
   1.488  }
   1.489  
   1.490  /* Close the CD-ROM */
   1.491  static void
   1.492 -SDL_SYS_CDClose (SDL_CD * cdrom)
   1.493 +SDL_SYS_CDClose(SDL_CD * cdrom)
   1.494  {
   1.495      currentDrive = -1;
   1.496      return;