src/cdrom/osf/SDL_syscdrom.c
branchSDL-1.3
changeset 1668 4da1ee79c9af
parent 1662 782fd950bd46
     1.1 --- a/src/cdrom/osf/SDL_syscdrom.c	Mon May 29 03:53:21 2006 +0000
     1.2 +++ b/src/cdrom/osf/SDL_syscdrom.c	Mon May 29 04:04:35 2006 +0000
     1.3 @@ -45,21 +45,21 @@
     1.4  static dev_t SDL_cdmode[MAX_DRIVES];
     1.5  
     1.6  /* The system-dependent CD control functions */
     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  /* Check a drive to see if it is a CD-ROM */
    1.29  /* Caution!! Not tested. */
    1.30  static int
    1.31 -CheckDrive (char *drive, struct stat *stbuf)
    1.32 +CheckDrive(char *drive, struct stat *stbuf)
    1.33  {
    1.34      int cdfd, is_cd = 0;
    1.35      struct mode_sel_sns_params msp;
    1.36 @@ -71,29 +71,29 @@
    1.37      };
    1.38  #endif
    1.39  
    1.40 -    bzero (&msp, sizeof (msp));
    1.41 -    bzero (&inq, sizeof (inq));
    1.42 +    bzero(&msp, sizeof(msp));
    1.43 +    bzero(&inq, sizeof(inq));
    1.44  
    1.45      /* If it doesn't exist, return -1 */
    1.46 -    if (stat (drive, stbuf) < 0) {
    1.47 +    if (stat(drive, stbuf) < 0) {
    1.48          return (-1);
    1.49      }
    1.50  
    1.51 -    if ((cdfd = open (drive, (O_RDWR | O_NDELAY), 0)) >= 0) {
    1.52 +    if ((cdfd = open(drive, (O_RDWR | O_NDELAY), 0)) >= 0) {
    1.53          msp.msp_addr = (caddr_t) & inq;
    1.54          msp.msp_pgcode = 0;
    1.55          msp.msp_pgctrl = 0;
    1.56 -        msp.msp_length = sizeof (inq);
    1.57 +        msp.msp_length = sizeof(inq);
    1.58          msp.msp_setps = 0;
    1.59  
    1.60 -        if (ioctl (cdfd, SCSI_GET_INQUIRY_DATA, &msp))
    1.61 +        if (ioctl(cdfd, SCSI_GET_INQUIRY_DATA, &msp))
    1.62              return (0);
    1.63  
    1.64  #ifdef DEBUG_CDROM
    1.65 -        fprintf (stderr, "Device Type: %s\n", devtype[inq.perfdt]);
    1.66 -        fprintf (stderr, "Vendor: %.8s\n", inq.vndrid);
    1.67 -        fprintf (stderr, "Product: %.8s\n", inq.prodid);
    1.68 -        fprintf (stderr, "Revision: %.8s\n", inq.revlvl);
    1.69 +        fprintf(stderr, "Device Type: %s\n", devtype[inq.perfdt]);
    1.70 +        fprintf(stderr, "Vendor: %.8s\n", inq.vndrid);
    1.71 +        fprintf(stderr, "Product: %.8s\n", inq.prodid);
    1.72 +        fprintf(stderr, "Revision: %.8s\n", inq.revlvl);
    1.73  #endif
    1.74          if (inq.perfdt == DTYPE_RODIRECT)
    1.75              is_cd = 1;
    1.76 @@ -104,7 +104,7 @@
    1.77  
    1.78  /* Add a CD-ROM drive to our list of valid drives */
    1.79  static void
    1.80 -AddDrive (char *drive, struct stat *stbuf)
    1.81 +AddDrive(char *drive, struct stat *stbuf)
    1.82  {
    1.83      int i;
    1.84  
    1.85 @@ -116,8 +116,8 @@
    1.86          for (i = 0; i < SDL_numcds; ++i) {
    1.87              if (stbuf->st_rdev == SDL_cdmode[i]) {
    1.88  #ifdef DEBUG_CDROM
    1.89 -                fprintf (stderr, "Duplicate drive detected: %s == %s\n",
    1.90 -                         drive, SDL_cdlist[i]);
    1.91 +                fprintf(stderr, "Duplicate drive detected: %s == %s\n",
    1.92 +                        drive, SDL_cdlist[i]);
    1.93  #endif
    1.94                  return;
    1.95              }
    1.96 @@ -125,21 +125,21 @@
    1.97  
    1.98          /* Add this drive to our list */
    1.99          i = SDL_numcds;
   1.100 -        SDL_cdlist[i] = SDL_strdup (drive);
   1.101 +        SDL_cdlist[i] = SDL_strdup(drive);
   1.102          if (SDL_cdlist[i] == NULL) {
   1.103 -            SDL_OutOfMemory ();
   1.104 +            SDL_OutOfMemory();
   1.105              return;
   1.106          }
   1.107          SDL_cdmode[i] = stbuf->st_rdev;
   1.108          ++SDL_numcds;
   1.109  #ifdef DEBUG_CDROM
   1.110 -        fprintf (stderr, "Added CD-ROM drive: %s\n", drive);
   1.111 +        fprintf(stderr, "Added CD-ROM drive: %s\n", drive);
   1.112  #endif
   1.113      }
   1.114  }
   1.115  
   1.116  int
   1.117 -SDL_SYS_CDInit (void)
   1.118 +SDL_SYS_CDInit(void)
   1.119  {
   1.120      /* checklist:
   1.121       *
   1.122 @@ -178,21 +178,21 @@
   1.123  
   1.124  
   1.125      /* Look in the environment for our CD-ROM drive list */
   1.126 -    SDLcdrom = SDL_getenv ("SDL_CDROM");        /* ':' separated list of devices */
   1.127 +    SDLcdrom = SDL_getenv("SDL_CDROM"); /* ':' separated list of devices */
   1.128      if (SDLcdrom != NULL) {
   1.129          char *cdpath, *delim;
   1.130 -        size_t len = SDL_strlen (SDLcdrom) + 1;
   1.131 -        cdpath = SDL_stack_alloc (char, len);
   1.132 +        size_t len = SDL_strlen(SDLcdrom) + 1;
   1.133 +        cdpath = SDL_stack_alloc(char, len);
   1.134          if (cdpath != NULL) {
   1.135 -            SDL_strlcpy (cdpath, SDLcdrom, len);
   1.136 +            SDL_strlcpy(cdpath, SDLcdrom, len);
   1.137              SDLcdrom = cdpath;
   1.138              do {
   1.139 -                delim = SDL_strchr (SDLcdrom, ':');
   1.140 +                delim = SDL_strchr(SDLcdrom, ':');
   1.141                  if (delim) {
   1.142                      *delim++ = '\0';
   1.143                  }
   1.144 -                if (CheckDrive (SDLcdrom, &stbuf) > 0) {
   1.145 -                    AddDrive (SDLcdrom, &stbuf);
   1.146 +                if (CheckDrive(SDLcdrom, &stbuf) > 0) {
   1.147 +                    AddDrive(SDLcdrom, &stbuf);
   1.148                  }
   1.149                  if (delim) {
   1.150                      SDLcdrom = delim;
   1.151 @@ -201,7 +201,7 @@
   1.152                  }
   1.153              }
   1.154              while (SDLcdrom);
   1.155 -            SDL_stack_free (cdpath);
   1.156 +            SDL_stack_free(cdpath);
   1.157          }
   1.158  
   1.159          /* If we found our drives, there's nothing left to do */
   1.160 @@ -215,26 +215,26 @@
   1.161          struct dirent *devent;
   1.162          int name_len;
   1.163  
   1.164 -        devdir = opendir (checklist[i].dir);
   1.165 +        devdir = opendir(checklist[i].dir);
   1.166          if (devdir) {
   1.167 -            name_len = SDL_strlen (checklist[i].name);
   1.168 -            while (devent = readdir (devdir))
   1.169 +            name_len = SDL_strlen(checklist[i].name);
   1.170 +            while (devent = readdir(devdir))
   1.171                  if (SDL_memcmp
   1.172                      (checklist[i].name, devent->d_name, name_len) == 0)
   1.173                      if (devent->d_name[devent->d_namlen - 1] == 'c') {
   1.174 -                        SDL_snprintf (drive, SDL_arraysize (drive),
   1.175 -                                      "%s/%s", checklist[i].dir,
   1.176 -                                      devent->d_name);
   1.177 +                        SDL_snprintf(drive, SDL_arraysize(drive),
   1.178 +                                     "%s/%s", checklist[i].dir,
   1.179 +                                     devent->d_name);
   1.180  #ifdef DEBUG_CDROM
   1.181 -                        fprintf (stderr, "Try to add drive: %s\n", drive);
   1.182 +                        fprintf(stderr, "Try to add drive: %s\n", drive);
   1.183  #endif
   1.184 -                        if (CheckDrive (drive, &stbuf) > 0)
   1.185 -                            AddDrive (drive, &stbuf);
   1.186 +                        if (CheckDrive(drive, &stbuf) > 0)
   1.187 +                            AddDrive(drive, &stbuf);
   1.188                      }
   1.189 -            closedir (devdir);
   1.190 +            closedir(devdir);
   1.191          } else {
   1.192  #ifdef DEBUG_CDROM
   1.193 -            fprintf (stderr, "cannot open dir: %s\n", checklist[i].dir);
   1.194 +            fprintf(stderr, "cannot open dir: %s\n", checklist[i].dir);
   1.195  #endif
   1.196          }
   1.197      }
   1.198 @@ -242,28 +242,28 @@
   1.199  }
   1.200  
   1.201  static const char *
   1.202 -SDL_SYS_CDName (int drive)
   1.203 +SDL_SYS_CDName(int drive)
   1.204  {
   1.205      return (SDL_cdlist[drive]);
   1.206  }
   1.207  
   1.208  static int
   1.209 -SDL_SYS_CDOpen (int drive)
   1.210 +SDL_SYS_CDOpen(int drive)
   1.211  {
   1.212      /* O_RDWR: To use ioctl(fd, SCSI_STOP_UNIT) */
   1.213 -    return (open (SDL_cdlist[drive], (O_RDWR | O_NDELAY), 0));
   1.214 +    return (open(SDL_cdlist[drive], (O_RDWR | O_NDELAY), 0));
   1.215  }
   1.216  
   1.217  static int
   1.218 -SDL_SYS_CDGetTOC (SDL_CD * cdrom)
   1.219 +SDL_SYS_CDGetTOC(SDL_CD * cdrom)
   1.220  {
   1.221      struct cd_toc toc;
   1.222      struct cd_toc_header hdr;
   1.223      struct cd_toc_entry *cdte;
   1.224      int i;
   1.225      int okay = 0;
   1.226 -    if (ioctl (cdrom->id, CDROM_TOC_HEADER, &hdr)) {
   1.227 -        fprintf (stderr, "ioctl error CDROM_TOC_HEADER\n");
   1.228 +    if (ioctl(cdrom->id, CDROM_TOC_HEADER, &hdr)) {
   1.229 +        fprintf(stderr, "ioctl error CDROM_TOC_HEADER\n");
   1.230          return -1;
   1.231      }
   1.232      cdrom->numtracks = hdr.th_ending_track - hdr.th_starting_track + 1;
   1.233 @@ -271,28 +271,28 @@
   1.234          cdrom->numtracks = SDL_MAX_TRACKS;
   1.235      }
   1.236  #ifdef DEBUG_CDROM
   1.237 -    fprintf (stderr, "hdr.th_data_len1 = %d\n", hdr.th_data_len1);
   1.238 -    fprintf (stderr, "hdr.th_data_len0 = %d\n", hdr.th_data_len0);
   1.239 -    fprintf (stderr, "hdr.th_starting_track = %d\n", hdr.th_starting_track);
   1.240 -    fprintf (stderr, "hdr.th_ending_track = %d\n", hdr.th_ending_track);
   1.241 -    fprintf (stderr, "cdrom->numtracks = %d\n", cdrom->numtracks);
   1.242 +    fprintf(stderr, "hdr.th_data_len1 = %d\n", hdr.th_data_len1);
   1.243 +    fprintf(stderr, "hdr.th_data_len0 = %d\n", hdr.th_data_len0);
   1.244 +    fprintf(stderr, "hdr.th_starting_track = %d\n", hdr.th_starting_track);
   1.245 +    fprintf(stderr, "hdr.th_ending_track = %d\n", hdr.th_ending_track);
   1.246 +    fprintf(stderr, "cdrom->numtracks = %d\n", cdrom->numtracks);
   1.247  #endif
   1.248      toc.toc_address_format = CDROM_LBA_FORMAT;
   1.249      toc.toc_starting_track = 0;
   1.250      toc.toc_alloc_length = (hdr.th_data_len1 << 8) +
   1.251 -        hdr.th_data_len0 + sizeof (hdr);
   1.252 -    if ((toc.toc_buffer = alloca (toc.toc_alloc_length)) == NULL) {
   1.253 -        fprintf (stderr, "cannot allocate toc.toc_buffer\n");
   1.254 +        hdr.th_data_len0 + sizeof(hdr);
   1.255 +    if ((toc.toc_buffer = alloca(toc.toc_alloc_length)) == NULL) {
   1.256 +        fprintf(stderr, "cannot allocate toc.toc_buffer\n");
   1.257          return -1;
   1.258      }
   1.259  
   1.260 -    bzero (toc.toc_buffer, toc.toc_alloc_length);
   1.261 -    if (ioctl (cdrom->id, CDROM_TOC_ENTRYS, &toc)) {
   1.262 -        fprintf (stderr, "ioctl error CDROM_TOC_ENTRYS\n");
   1.263 +    bzero(toc.toc_buffer, toc.toc_alloc_length);
   1.264 +    if (ioctl(cdrom->id, CDROM_TOC_ENTRYS, &toc)) {
   1.265 +        fprintf(stderr, "ioctl error CDROM_TOC_ENTRYS\n");
   1.266          return -1;
   1.267      }
   1.268  
   1.269 -    cdte = (struct cd_toc_entry *) ((char *) toc.toc_buffer + sizeof (hdr));
   1.270 +    cdte = (struct cd_toc_entry *) ((char *) toc.toc_buffer + sizeof(hdr));
   1.271      for (i = 0; i <= cdrom->numtracks; ++i) {
   1.272          if (i == cdrom->numtracks) {
   1.273              cdrom->track[i].id = 0xAA;;
   1.274 @@ -313,15 +313,15 @@
   1.275      }
   1.276  #ifdef DEBUG_CDROM
   1.277      for (i = 0; i <= cdrom->numtracks; i++) {
   1.278 -        fprintf (stderr, "toc_entry[%d].te_track_number = %d\n",
   1.279 -                 i, cdte[i].te_track_number);
   1.280 -        fprintf (stderr, "cdrom->track[%d].id = %d\n", i, cdrom->track[i].id);
   1.281 -        fprintf (stderr, "cdrom->track[%d].type = %x\n", i,
   1.282 -                 cdrom->track[i].type);
   1.283 -        fprintf (stderr, "cdrom->track[%d].offset = %d\n", i,
   1.284 -                 cdrom->track[i].offset);
   1.285 -        fprintf (stderr, "cdrom->track[%d].length = %d\n", i,
   1.286 -                 cdrom->track[i].length);
   1.287 +        fprintf(stderr, "toc_entry[%d].te_track_number = %d\n",
   1.288 +                i, cdte[i].te_track_number);
   1.289 +        fprintf(stderr, "cdrom->track[%d].id = %d\n", i, cdrom->track[i].id);
   1.290 +        fprintf(stderr, "cdrom->track[%d].type = %x\n", i,
   1.291 +                cdrom->track[i].type);
   1.292 +        fprintf(stderr, "cdrom->track[%d].offset = %d\n", i,
   1.293 +                cdrom->track[i].offset);
   1.294 +        fprintf(stderr, "cdrom->track[%d].length = %d\n", i,
   1.295 +                cdrom->track[i].length);
   1.296      }
   1.297  #endif
   1.298      if (i == (cdrom->numtracks + 1)) {
   1.299 @@ -333,7 +333,7 @@
   1.300  
   1.301  /* Get CD-ROM status */
   1.302  static CDstatus
   1.303 -SDL_SYS_CDStatus (SDL_CD * cdrom, int *position)
   1.304 +SDL_SYS_CDStatus(SDL_CD * cdrom, int *position)
   1.305  {
   1.306      CDstatus status;
   1.307      struct cd_sub_channel sc;
   1.308 @@ -342,11 +342,11 @@
   1.309      sc.sch_address_format = CDROM_LBA_FORMAT;
   1.310      sc.sch_data_format = CDROM_CURRENT_POSITION;
   1.311      sc.sch_track_number = 0;
   1.312 -    sc.sch_alloc_length = sizeof (scd);
   1.313 +    sc.sch_alloc_length = sizeof(scd);
   1.314      sc.sch_buffer = (caddr_t) & scd;
   1.315 -    if (ioctl (cdrom->id, CDROM_READ_SUBCHANNEL, &sc)) {
   1.316 +    if (ioctl(cdrom->id, CDROM_READ_SUBCHANNEL, &sc)) {
   1.317          status = CD_ERROR;
   1.318 -        fprintf (stderr, "ioctl error CDROM_READ_SUBCHANNEL \n");
   1.319 +        fprintf(stderr, "ioctl error CDROM_READ_SUBCHANNEL \n");
   1.320      } else {
   1.321          switch (scd.scd_header.sh_audio_status) {
   1.322          case AS_AUDIO_INVALID:
   1.323 @@ -372,8 +372,8 @@
   1.324              break;
   1.325          }
   1.326  #ifdef DEBUG_CDROM
   1.327 -        fprintf (stderr, "scd.scd_header.sh_audio_status = %x\n",
   1.328 -                 scd.scd_header.sh_audio_status);
   1.329 +        fprintf(stderr, "scd.scd_header.sh_audio_status = %x\n",
   1.330 +                scd.scd_header.sh_audio_status);
   1.331  #endif
   1.332      }
   1.333      if (position) {
   1.334 @@ -393,7 +393,7 @@
   1.335  
   1.336  /* Start play */
   1.337  static int
   1.338 -SDL_SYS_CDPlay (SDL_CD * cdrom, int start, int length)
   1.339 +SDL_SYS_CDPlay(SDL_CD * cdrom, int start, int length)
   1.340  {
   1.341  /*
   1.342   * Play MSF
   1.343 @@ -401,61 +401,61 @@
   1.344      struct cd_play_audio_msf msf;
   1.345      int end;
   1.346  
   1.347 -    bzero (&msf, sizeof (msf));
   1.348 +    bzero(&msf, sizeof(msf));
   1.349      end = start + length;
   1.350 -    FRAMES_TO_MSF (start + 150, /* LBA = 4500*M + 75*S + F - 150 */
   1.351 -                   &msf.msf_starting_M_unit,
   1.352 -                   &msf.msf_starting_S_unit, &msf.msf_starting_F_unit);
   1.353 -    FRAMES_TO_MSF (end + 150,   /* LBA = 4500*M + 75*S + F - 150 */
   1.354 -                   &msf.msf_ending_M_unit,
   1.355 -                   &msf.msf_ending_S_unit, &msf.msf_ending_F_unit);
   1.356 +    FRAMES_TO_MSF(start + 150,  /* LBA = 4500*M + 75*S + F - 150 */
   1.357 +                  &msf.msf_starting_M_unit,
   1.358 +                  &msf.msf_starting_S_unit, &msf.msf_starting_F_unit);
   1.359 +    FRAMES_TO_MSF(end + 150,    /* LBA = 4500*M + 75*S + F - 150 */
   1.360 +                  &msf.msf_ending_M_unit,
   1.361 +                  &msf.msf_ending_S_unit, &msf.msf_ending_F_unit);
   1.362  
   1.363 -    return (ioctl (cdrom->id, CDROM_PLAY_AUDIO_MSF, &msf));
   1.364 +    return (ioctl(cdrom->id, CDROM_PLAY_AUDIO_MSF, &msf));
   1.365  }
   1.366  
   1.367  /* Pause play */
   1.368  static int
   1.369 -SDL_SYS_CDPause (SDL_CD * cdrom)
   1.370 +SDL_SYS_CDPause(SDL_CD * cdrom)
   1.371  {
   1.372 -    return (ioctl (cdrom->id, CDROM_PAUSE_PLAY));
   1.373 +    return (ioctl(cdrom->id, CDROM_PAUSE_PLAY));
   1.374  }
   1.375  
   1.376  /* Resume play */
   1.377  static int
   1.378 -SDL_SYS_CDResume (SDL_CD * cdrom)
   1.379 +SDL_SYS_CDResume(SDL_CD * cdrom)
   1.380  {
   1.381 -    return (ioctl (cdrom->id, CDROM_RESUME_PLAY));
   1.382 +    return (ioctl(cdrom->id, CDROM_RESUME_PLAY));
   1.383  }
   1.384  
   1.385  /* Stop play */
   1.386  static int
   1.387 -SDL_SYS_CDStop (SDL_CD * cdrom)
   1.388 +SDL_SYS_CDStop(SDL_CD * cdrom)
   1.389  {
   1.390 -    return (ioctl (cdrom->id, SCSI_STOP_UNIT));
   1.391 +    return (ioctl(cdrom->id, SCSI_STOP_UNIT));
   1.392  }
   1.393  
   1.394  /* Eject the CD-ROM */
   1.395  static int
   1.396 -SDL_SYS_CDEject (SDL_CD * cdrom)
   1.397 +SDL_SYS_CDEject(SDL_CD * cdrom)
   1.398  {
   1.399 -    return (ioctl (cdrom->id, CDROM_EJECT_CADDY));
   1.400 +    return (ioctl(cdrom->id, CDROM_EJECT_CADDY));
   1.401  }
   1.402  
   1.403  /* Close the CD-ROM handle */
   1.404  static void
   1.405 -SDL_SYS_CDClose (SDL_CD * cdrom)
   1.406 +SDL_SYS_CDClose(SDL_CD * cdrom)
   1.407  {
   1.408 -    close (cdrom->id);
   1.409 +    close(cdrom->id);
   1.410  }
   1.411  
   1.412  void
   1.413 -SDL_SYS_CDQuit (void)
   1.414 +SDL_SYS_CDQuit(void)
   1.415  {
   1.416      int i;
   1.417  
   1.418      if (SDL_numcds > 0) {
   1.419          for (i = 0; i < SDL_numcds; ++i) {
   1.420 -            SDL_free (SDL_cdlist[i]);
   1.421 +            SDL_free(SDL_cdlist[i]);
   1.422          }
   1.423          SDL_numcds = 0;
   1.424      }