src/cdrom/osf/SDL_syscdrom.c
branchSDL-1.3
changeset 1662 782fd950bd46
parent 1635 92947e3a18db
child 1668 4da1ee79c9af
     1.1 --- a/src/cdrom/osf/SDL_syscdrom.c	Sun May 21 17:27:13 2006 +0000
     1.2 +++ b/src/cdrom/osf/SDL_syscdrom.c	Sun May 28 13:04:16 2006 +0000
     1.3 @@ -45,96 +45,101 @@
     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 CheckDrive(char *drive, struct stat *stbuf)
    1.31 +/* Caution!! Not tested. */
    1.32 +static int
    1.33 +CheckDrive (char *drive, struct stat *stbuf)
    1.34  {
    1.35      int cdfd, is_cd = 0;
    1.36      struct mode_sel_sns_params msp;
    1.37      struct inquiry_info inq;
    1.38  
    1.39  #ifdef DEBUG_CDROM
    1.40 -    char *devtype[] = {"Disk", "Tape", "Printer", "Processor", "WORM",
    1.41 -	"CD-ROM", "Scanner", "Optical", "Changer", "Comm", "Unknown"};
    1.42 +    char *devtype[] = { "Disk", "Tape", "Printer", "Processor", "WORM",
    1.43 +        "CD-ROM", "Scanner", "Optical", "Changer", "Comm", "Unknown"
    1.44 +    };
    1.45  #endif
    1.46  
    1.47 -    bzero(&msp, sizeof(msp));
    1.48 -    bzero(&inq, sizeof(inq));
    1.49 +    bzero (&msp, sizeof (msp));
    1.50 +    bzero (&inq, sizeof (inq));
    1.51  
    1.52      /* If it doesn't exist, return -1 */
    1.53 -    if ( stat(drive, stbuf) < 0 ) {
    1.54 -	return(-1);
    1.55 +    if (stat (drive, stbuf) < 0) {
    1.56 +        return (-1);
    1.57      }
    1.58  
    1.59 -    if ( (cdfd = open(drive, (O_RDWR|O_NDELAY), 0)) >= 0 ) {
    1.60 -	msp.msp_addr   =   (caddr_t) &inq;
    1.61 -	msp.msp_pgcode =                0;
    1.62 -	msp.msp_pgctrl =                0;
    1.63 -	msp.msp_length =      sizeof(inq);
    1.64 -	msp.msp_setps  =                0;
    1.65 +    if ((cdfd = open (drive, (O_RDWR | O_NDELAY), 0)) >= 0) {
    1.66 +        msp.msp_addr = (caddr_t) & inq;
    1.67 +        msp.msp_pgcode = 0;
    1.68 +        msp.msp_pgctrl = 0;
    1.69 +        msp.msp_length = sizeof (inq);
    1.70 +        msp.msp_setps = 0;
    1.71  
    1.72 -	if ( ioctl(cdfd, SCSI_GET_INQUIRY_DATA, &msp) )
    1.73 -	    return (0);
    1.74 +        if (ioctl (cdfd, SCSI_GET_INQUIRY_DATA, &msp))
    1.75 +            return (0);
    1.76  
    1.77  #ifdef DEBUG_CDROM
    1.78 -	fprintf(stderr, "Device Type: %s\n", devtype[inq.perfdt]);
    1.79 -	fprintf(stderr, "Vendor: %.8s\n", inq.vndrid);
    1.80 -	fprintf(stderr, "Product: %.8s\n", inq.prodid);
    1.81 -	fprintf(stderr, "Revision: %.8s\n", inq.revlvl);
    1.82 +        fprintf (stderr, "Device Type: %s\n", devtype[inq.perfdt]);
    1.83 +        fprintf (stderr, "Vendor: %.8s\n", inq.vndrid);
    1.84 +        fprintf (stderr, "Product: %.8s\n", inq.prodid);
    1.85 +        fprintf (stderr, "Revision: %.8s\n", inq.revlvl);
    1.86  #endif
    1.87 -	if ( inq.perfdt == DTYPE_RODIRECT )
    1.88 -	    is_cd = 1;
    1.89 +        if (inq.perfdt == DTYPE_RODIRECT)
    1.90 +            is_cd = 1;
    1.91      }
    1.92  
    1.93 -    return(is_cd);
    1.94 +    return (is_cd);
    1.95  }
    1.96  
    1.97  /* Add a CD-ROM drive to our list of valid drives */
    1.98 -static void AddDrive(char *drive, struct stat *stbuf)
    1.99 +static void
   1.100 +AddDrive (char *drive, struct stat *stbuf)
   1.101  {
   1.102      int i;
   1.103  
   1.104 -    if ( SDL_numcds < MAX_DRIVES ) {
   1.105 -	/* Check to make sure it's not already in our list.
   1.106 -	 * This can happen when we see a drive via symbolic link.
   1.107 -	 *
   1.108 -	 */
   1.109 -	for ( i=0; i<SDL_numcds; ++i ) {
   1.110 -	    if ( stbuf->st_rdev == SDL_cdmode[i] ) {
   1.111 +    if (SDL_numcds < MAX_DRIVES) {
   1.112 +        /* Check to make sure it's not already in our list.
   1.113 +         * This can happen when we see a drive via symbolic link.
   1.114 +         *
   1.115 +         */
   1.116 +        for (i = 0; i < SDL_numcds; ++i) {
   1.117 +            if (stbuf->st_rdev == SDL_cdmode[i]) {
   1.118  #ifdef DEBUG_CDROM
   1.119 -  fprintf(stderr, "Duplicate drive detected: %s == %s\n", drive, SDL_cdlist[i]);
   1.120 +                fprintf (stderr, "Duplicate drive detected: %s == %s\n",
   1.121 +                         drive, SDL_cdlist[i]);
   1.122  #endif
   1.123 -	    return;
   1.124 -	    }
   1.125 -	}
   1.126 +                return;
   1.127 +            }
   1.128 +        }
   1.129  
   1.130 -	/* Add this drive to our list */
   1.131 -	i = SDL_numcds;
   1.132 -	SDL_cdlist[i] = SDL_strdup(drive);
   1.133 -	if ( SDL_cdlist[i] == NULL ) {
   1.134 -	    SDL_OutOfMemory();
   1.135 -	    return;
   1.136 -	}
   1.137 -	SDL_cdmode[i] = stbuf->st_rdev;
   1.138 -	++SDL_numcds;
   1.139 +        /* Add this drive to our list */
   1.140 +        i = SDL_numcds;
   1.141 +        SDL_cdlist[i] = SDL_strdup (drive);
   1.142 +        if (SDL_cdlist[i] == NULL) {
   1.143 +            SDL_OutOfMemory ();
   1.144 +            return;
   1.145 +        }
   1.146 +        SDL_cdmode[i] = stbuf->st_rdev;
   1.147 +        ++SDL_numcds;
   1.148  #ifdef DEBUG_CDROM
   1.149 -  fprintf(stderr, "Added CD-ROM drive: %s\n", drive);
   1.150 +        fprintf (stderr, "Added CD-ROM drive: %s\n", drive);
   1.151  #endif
   1.152      }
   1.153  }
   1.154  
   1.155 -int  SDL_SYS_CDInit(void)
   1.156 +int
   1.157 +SDL_SYS_CDInit (void)
   1.158  {
   1.159      /* checklist:
   1.160       *
   1.161 @@ -145,239 +150,250 @@
   1.162       * dir: /dev, name: rrz
   1.163       *
   1.164       */
   1.165 -    struct {
   1.166 -	char *dir;
   1.167 -	char *name;
   1.168 +    struct
   1.169 +    {
   1.170 +        char *dir;
   1.171 +        char *name;
   1.172      } checklist[] = {
   1.173 -	{"/dev/rdisk", "cdrom"},
   1.174 -	{"/dev", "rrz"},
   1.175 -	{NULL, NULL}};
   1.176 +        {
   1.177 +        "/dev/rdisk", "cdrom"}, {
   1.178 +        "/dev", "rrz"}, {
   1.179 +    NULL, NULL}};
   1.180      char drive[32];
   1.181      char *SDLcdrom;
   1.182      int i, j, exists;
   1.183      struct stat stbuf;
   1.184  
   1.185      /* Fill in our driver capabilities */
   1.186 -    SDL_CDcaps.Name   = SDL_SYS_CDName;
   1.187 -    SDL_CDcaps.Open   = SDL_SYS_CDOpen;
   1.188 +    SDL_CDcaps.Name = SDL_SYS_CDName;
   1.189 +    SDL_CDcaps.Open = SDL_SYS_CDOpen;
   1.190      SDL_CDcaps.GetTOC = SDL_SYS_CDGetTOC;
   1.191      SDL_CDcaps.Status = SDL_SYS_CDStatus;
   1.192 -    SDL_CDcaps.Play   = SDL_SYS_CDPlay;
   1.193 -    SDL_CDcaps.Pause  = SDL_SYS_CDPause;
   1.194 +    SDL_CDcaps.Play = SDL_SYS_CDPlay;
   1.195 +    SDL_CDcaps.Pause = SDL_SYS_CDPause;
   1.196      SDL_CDcaps.Resume = SDL_SYS_CDResume;
   1.197 -    SDL_CDcaps.Stop   = SDL_SYS_CDStop;
   1.198 -    SDL_CDcaps.Eject  = SDL_SYS_CDEject;
   1.199 -    SDL_CDcaps.Close  = SDL_SYS_CDClose;
   1.200 +    SDL_CDcaps.Stop = SDL_SYS_CDStop;
   1.201 +    SDL_CDcaps.Eject = SDL_SYS_CDEject;
   1.202 +    SDL_CDcaps.Close = SDL_SYS_CDClose;
   1.203  
   1.204  
   1.205      /* Look in the environment for our CD-ROM drive list */
   1.206 -    SDLcdrom = SDL_getenv("SDL_CDROM");	/* ':' separated list of devices */
   1.207 -    if ( SDLcdrom != NULL ) {
   1.208 -	char *cdpath, *delim;
   1.209 -	size_t len = SDL_strlen(SDLcdrom)+1;
   1.210 -	cdpath = SDL_stack_alloc(char, len);
   1.211 -	if ( cdpath != NULL ) {
   1.212 -	    SDL_strlcpy(cdpath, SDLcdrom, len);
   1.213 -	    SDLcdrom = cdpath;
   1.214 -	    do {
   1.215 -		delim = SDL_strchr(SDLcdrom, ':');
   1.216 -		if ( delim ) {
   1.217 -		    *delim++ = '\0';
   1.218 -		}
   1.219 -		if ( CheckDrive(SDLcdrom, &stbuf) > 0 ) {
   1.220 -		    AddDrive(SDLcdrom, &stbuf);
   1.221 -		}
   1.222 -		if ( delim ) {
   1.223 -		    SDLcdrom = delim;
   1.224 -		} else {
   1.225 -		    SDLcdrom = NULL;
   1.226 -		}
   1.227 -	    } while ( SDLcdrom );
   1.228 -	    SDL_stack_free(cdpath);
   1.229 -	}
   1.230 +    SDLcdrom = SDL_getenv ("SDL_CDROM");        /* ':' separated list of devices */
   1.231 +    if (SDLcdrom != NULL) {
   1.232 +        char *cdpath, *delim;
   1.233 +        size_t len = SDL_strlen (SDLcdrom) + 1;
   1.234 +        cdpath = SDL_stack_alloc (char, len);
   1.235 +        if (cdpath != NULL) {
   1.236 +            SDL_strlcpy (cdpath, SDLcdrom, len);
   1.237 +            SDLcdrom = cdpath;
   1.238 +            do {
   1.239 +                delim = SDL_strchr (SDLcdrom, ':');
   1.240 +                if (delim) {
   1.241 +                    *delim++ = '\0';
   1.242 +                }
   1.243 +                if (CheckDrive (SDLcdrom, &stbuf) > 0) {
   1.244 +                    AddDrive (SDLcdrom, &stbuf);
   1.245 +                }
   1.246 +                if (delim) {
   1.247 +                    SDLcdrom = delim;
   1.248 +                } else {
   1.249 +                    SDLcdrom = NULL;
   1.250 +                }
   1.251 +            }
   1.252 +            while (SDLcdrom);
   1.253 +            SDL_stack_free (cdpath);
   1.254 +        }
   1.255  
   1.256 -	/* If we found our drives, there's nothing left to do */
   1.257 -	if ( SDL_numcds > 0 ) {
   1.258 -	    return(0);
   1.259 -	}
   1.260 +        /* If we found our drives, there's nothing left to do */
   1.261 +        if (SDL_numcds > 0) {
   1.262 +            return (0);
   1.263 +        }
   1.264      }
   1.265      /* Scan the system for CD-ROM drives */
   1.266 -    for ( i = 0; checklist[i].dir; ++i) {
   1.267 -	DIR *devdir;
   1.268 -	struct dirent *devent;
   1.269 -	int name_len;
   1.270 +    for (i = 0; checklist[i].dir; ++i) {
   1.271 +        DIR *devdir;
   1.272 +        struct dirent *devent;
   1.273 +        int name_len;
   1.274  
   1.275 -	devdir = opendir(checklist[i].dir);
   1.276 -	if (devdir) {
   1.277 -	    name_len = SDL_strlen(checklist[i].name);
   1.278 -	    while (devent = readdir(devdir))
   1.279 -		if (SDL_memcmp(checklist[i].name, devent->d_name, name_len) == 0)
   1.280 -		    if (devent->d_name[devent->d_namlen-1] == 'c') {
   1.281 -			SDL_snprintf(drive, SDL_arraysize(drive), "%s/%s", checklist[i].dir, devent->d_name);
   1.282 +        devdir = opendir (checklist[i].dir);
   1.283 +        if (devdir) {
   1.284 +            name_len = SDL_strlen (checklist[i].name);
   1.285 +            while (devent = readdir (devdir))
   1.286 +                if (SDL_memcmp
   1.287 +                    (checklist[i].name, devent->d_name, name_len) == 0)
   1.288 +                    if (devent->d_name[devent->d_namlen - 1] == 'c') {
   1.289 +                        SDL_snprintf (drive, SDL_arraysize (drive),
   1.290 +                                      "%s/%s", checklist[i].dir,
   1.291 +                                      devent->d_name);
   1.292  #ifdef DEBUG_CDROM
   1.293 -			fprintf(stderr, "Try to add drive: %s\n", drive);
   1.294 +                        fprintf (stderr, "Try to add drive: %s\n", drive);
   1.295  #endif
   1.296 -			if ( CheckDrive(drive, &stbuf) > 0 )
   1.297 -			    AddDrive(drive, &stbuf);
   1.298 -		    }
   1.299 -	    closedir(devdir);
   1.300 -	} else {
   1.301 +                        if (CheckDrive (drive, &stbuf) > 0)
   1.302 +                            AddDrive (drive, &stbuf);
   1.303 +                    }
   1.304 +            closedir (devdir);
   1.305 +        } else {
   1.306  #ifdef DEBUG_CDROM
   1.307 -	    fprintf(stderr, "cannot open dir: %s\n", checklist[i].dir);
   1.308 +            fprintf (stderr, "cannot open dir: %s\n", checklist[i].dir);
   1.309  #endif
   1.310 -	}
   1.311 +        }
   1.312      }
   1.313      return (0);
   1.314  }
   1.315  
   1.316 -static const char *SDL_SYS_CDName(int drive)
   1.317 +static const char *
   1.318 +SDL_SYS_CDName (int drive)
   1.319  {
   1.320 -    return(SDL_cdlist[drive]);
   1.321 +    return (SDL_cdlist[drive]);
   1.322  }
   1.323  
   1.324 -static int SDL_SYS_CDOpen(int drive)
   1.325 +static int
   1.326 +SDL_SYS_CDOpen (int drive)
   1.327  {
   1.328      /* O_RDWR: To use ioctl(fd, SCSI_STOP_UNIT) */
   1.329 -    return(open(SDL_cdlist[drive], (O_RDWR|O_NDELAY), 0));
   1.330 +    return (open (SDL_cdlist[drive], (O_RDWR | O_NDELAY), 0));
   1.331  }
   1.332  
   1.333 -static int SDL_SYS_CDGetTOC(SDL_CD *cdrom)
   1.334 +static int
   1.335 +SDL_SYS_CDGetTOC (SDL_CD * cdrom)
   1.336  {
   1.337 -    struct cd_toc                  toc;
   1.338 -    struct cd_toc_header           hdr;
   1.339 -    struct cd_toc_entry          *cdte;
   1.340 +    struct cd_toc toc;
   1.341 +    struct cd_toc_header hdr;
   1.342 +    struct cd_toc_entry *cdte;
   1.343      int i;
   1.344      int okay = 0;
   1.345 -    if ( ioctl(cdrom->id, CDROM_TOC_HEADER, &hdr) ) {
   1.346 -	fprintf(stderr,"ioctl error CDROM_TOC_HEADER\n");
   1.347 -	return -1;
   1.348 +    if (ioctl (cdrom->id, CDROM_TOC_HEADER, &hdr)) {
   1.349 +        fprintf (stderr, "ioctl error CDROM_TOC_HEADER\n");
   1.350 +        return -1;
   1.351      }
   1.352      cdrom->numtracks = hdr.th_ending_track - hdr.th_starting_track + 1;
   1.353 -    if ( cdrom->numtracks > SDL_MAX_TRACKS ) {
   1.354 -	cdrom->numtracks = SDL_MAX_TRACKS;
   1.355 +    if (cdrom->numtracks > SDL_MAX_TRACKS) {
   1.356 +        cdrom->numtracks = SDL_MAX_TRACKS;
   1.357      }
   1.358  #ifdef DEBUG_CDROM
   1.359 -  fprintf(stderr,"hdr.th_data_len1 = %d\n", hdr.th_data_len1);
   1.360 -  fprintf(stderr,"hdr.th_data_len0 = %d\n", hdr.th_data_len0);
   1.361 -  fprintf(stderr,"hdr.th_starting_track = %d\n", hdr.th_starting_track);
   1.362 -  fprintf(stderr,"hdr.th_ending_track = %d\n", hdr.th_ending_track);
   1.363 -  fprintf(stderr,"cdrom->numtracks = %d\n", cdrom->numtracks);
   1.364 +    fprintf (stderr, "hdr.th_data_len1 = %d\n", hdr.th_data_len1);
   1.365 +    fprintf (stderr, "hdr.th_data_len0 = %d\n", hdr.th_data_len0);
   1.366 +    fprintf (stderr, "hdr.th_starting_track = %d\n", hdr.th_starting_track);
   1.367 +    fprintf (stderr, "hdr.th_ending_track = %d\n", hdr.th_ending_track);
   1.368 +    fprintf (stderr, "cdrom->numtracks = %d\n", cdrom->numtracks);
   1.369  #endif
   1.370      toc.toc_address_format = CDROM_LBA_FORMAT;
   1.371      toc.toc_starting_track = 0;
   1.372      toc.toc_alloc_length = (hdr.th_data_len1 << 8) +
   1.373 -			    hdr.th_data_len0 + sizeof(hdr);
   1.374 -    if ( (toc.toc_buffer = alloca(toc.toc_alloc_length)) == NULL) {
   1.375 -	fprintf(stderr,"cannot allocate toc.toc_buffer\n");
   1.376 -	return -1;
   1.377 +        hdr.th_data_len0 + sizeof (hdr);
   1.378 +    if ((toc.toc_buffer = alloca (toc.toc_alloc_length)) == NULL) {
   1.379 +        fprintf (stderr, "cannot allocate toc.toc_buffer\n");
   1.380 +        return -1;
   1.381      }
   1.382  
   1.383      bzero (toc.toc_buffer, toc.toc_alloc_length);
   1.384 -    if (ioctl(cdrom->id, CDROM_TOC_ENTRYS, &toc)) {
   1.385 -	fprintf(stderr,"ioctl error CDROM_TOC_ENTRYS\n");
   1.386 -	return -1;
   1.387 +    if (ioctl (cdrom->id, CDROM_TOC_ENTRYS, &toc)) {
   1.388 +        fprintf (stderr, "ioctl error CDROM_TOC_ENTRYS\n");
   1.389 +        return -1;
   1.390      }
   1.391  
   1.392 -    cdte =(struct cd_toc_entry *) ((char *) toc.toc_buffer + sizeof(hdr));
   1.393 -    for (i=0; i <= cdrom->numtracks; ++i) {
   1.394 -	if (i == cdrom->numtracks ) {
   1.395 -	    cdrom->track[i].id = 0xAA;;
   1.396 -	} else {
   1.397 -	    cdrom->track[i].id = hdr.th_starting_track + i;
   1.398 -	}
   1.399 +    cdte = (struct cd_toc_entry *) ((char *) toc.toc_buffer + sizeof (hdr));
   1.400 +    for (i = 0; i <= cdrom->numtracks; ++i) {
   1.401 +        if (i == cdrom->numtracks) {
   1.402 +            cdrom->track[i].id = 0xAA;;
   1.403 +        } else {
   1.404 +            cdrom->track[i].id = hdr.th_starting_track + i;
   1.405 +        }
   1.406  
   1.407 -	cdrom->track[i].type =
   1.408 -	    cdte[i].te_control & CDROM_DATA_TRACK;
   1.409 -	cdrom->track[i].offset =
   1.410 -	    cdte[i].te_absaddr.lba.addr3 << 24 |
   1.411 -	    cdte[i].te_absaddr.lba.addr2 << 16 |
   1.412 -	    cdte[i].te_absaddr.lba.addr1 << 8  |
   1.413 -	    cdte[i].te_absaddr.lba.addr0;
   1.414 -	cdrom->track[i].length = 0;
   1.415 -	if ( i > 0 ) {
   1.416 -	    cdrom->track[i - 1].length =
   1.417 -		cdrom->track[i].offset -
   1.418 -		cdrom->track[i - 1].offset;
   1.419 -	}
   1.420 +        cdrom->track[i].type = cdte[i].te_control & CDROM_DATA_TRACK;
   1.421 +        cdrom->track[i].offset =
   1.422 +            cdte[i].te_absaddr.lba.addr3 << 24 |
   1.423 +            cdte[i].te_absaddr.lba.addr2 << 16 |
   1.424 +            cdte[i].te_absaddr.lba.addr1 << 8 | cdte[i].te_absaddr.lba.addr0;
   1.425 +        cdrom->track[i].length = 0;
   1.426 +        if (i > 0) {
   1.427 +            cdrom->track[i - 1].length =
   1.428 +                cdrom->track[i].offset - cdrom->track[i - 1].offset;
   1.429 +        }
   1.430      }
   1.431  #ifdef DEBUG_CDROM
   1.432 -  for (i = 0; i <= cdrom->numtracks; i++) {
   1.433 -    fprintf(stderr,"toc_entry[%d].te_track_number = %d\n",
   1.434 -	    i,cdte[i].te_track_number);
   1.435 -    fprintf(stderr,"cdrom->track[%d].id = %d\n", i,cdrom->track[i].id);
   1.436 -    fprintf(stderr,"cdrom->track[%d].type = %x\n", i,cdrom->track[i].type);
   1.437 -    fprintf(stderr,"cdrom->track[%d].offset = %d\n", i,cdrom->track[i].offset);
   1.438 -    fprintf(stderr,"cdrom->track[%d].length = %d\n", i,cdrom->track[i].length);
   1.439 -  }
   1.440 +    for (i = 0; i <= cdrom->numtracks; i++) {
   1.441 +        fprintf (stderr, "toc_entry[%d].te_track_number = %d\n",
   1.442 +                 i, cdte[i].te_track_number);
   1.443 +        fprintf (stderr, "cdrom->track[%d].id = %d\n", i, cdrom->track[i].id);
   1.444 +        fprintf (stderr, "cdrom->track[%d].type = %x\n", i,
   1.445 +                 cdrom->track[i].type);
   1.446 +        fprintf (stderr, "cdrom->track[%d].offset = %d\n", i,
   1.447 +                 cdrom->track[i].offset);
   1.448 +        fprintf (stderr, "cdrom->track[%d].length = %d\n", i,
   1.449 +                 cdrom->track[i].length);
   1.450 +    }
   1.451  #endif
   1.452 -    if ( i == (cdrom->numtracks+1) ) {
   1.453 -	okay = 1;
   1.454 +    if (i == (cdrom->numtracks + 1)) {
   1.455 +        okay = 1;
   1.456      }
   1.457  
   1.458 -    return(okay ? 0 : -1);
   1.459 +    return (okay ? 0 : -1);
   1.460  }
   1.461  
   1.462  /* Get CD-ROM status */
   1.463 -static CDstatus SDL_SYS_CDStatus(SDL_CD *cdrom, int *position)
   1.464 +static CDstatus
   1.465 +SDL_SYS_CDStatus (SDL_CD * cdrom, int *position)
   1.466  {
   1.467 -    CDstatus                     status;
   1.468 -    struct cd_sub_channel            sc;
   1.469 -    struct cd_subc_channel_data     scd;
   1.470 +    CDstatus status;
   1.471 +    struct cd_sub_channel sc;
   1.472 +    struct cd_subc_channel_data scd;
   1.473  
   1.474      sc.sch_address_format = CDROM_LBA_FORMAT;
   1.475 -    sc.sch_data_format    = CDROM_CURRENT_POSITION;
   1.476 -    sc.sch_track_number   = 0;
   1.477 -    sc.sch_alloc_length   = sizeof(scd);
   1.478 -    sc.sch_buffer         = (caddr_t)&scd;
   1.479 -    if ( ioctl(cdrom->id, CDROM_READ_SUBCHANNEL, &sc) ) {
   1.480 -	status = CD_ERROR;
   1.481 -	fprintf(stderr,"ioctl error CDROM_READ_SUBCHANNEL \n");
   1.482 +    sc.sch_data_format = CDROM_CURRENT_POSITION;
   1.483 +    sc.sch_track_number = 0;
   1.484 +    sc.sch_alloc_length = sizeof (scd);
   1.485 +    sc.sch_buffer = (caddr_t) & scd;
   1.486 +    if (ioctl (cdrom->id, CDROM_READ_SUBCHANNEL, &sc)) {
   1.487 +        status = CD_ERROR;
   1.488 +        fprintf (stderr, "ioctl error CDROM_READ_SUBCHANNEL \n");
   1.489      } else {
   1.490 -	switch (scd.scd_header.sh_audio_status) {
   1.491 -	    case AS_AUDIO_INVALID:
   1.492 -		status = CD_STOPPED;
   1.493 -		break;
   1.494 -	    case AS_PLAY_IN_PROGRESS:
   1.495 -		status = CD_PLAYING;
   1.496 -		break;
   1.497 -	    case AS_PLAY_PAUSED:
   1.498 -		status = CD_PAUSED;
   1.499 -		break;
   1.500 -	    case AS_PLAY_COMPLETED:
   1.501 -		status = CD_STOPPED;
   1.502 -		break;
   1.503 -	    case AS_PLAY_ERROR:
   1.504 -		status = CD_ERROR;
   1.505 -		break;
   1.506 -	    case AS_NO_STATUS:
   1.507 -		status = CD_STOPPED;
   1.508 -		break;
   1.509 -	    default:
   1.510 -		status = CD_ERROR;
   1.511 -		break;
   1.512 -	}
   1.513 +        switch (scd.scd_header.sh_audio_status) {
   1.514 +        case AS_AUDIO_INVALID:
   1.515 +            status = CD_STOPPED;
   1.516 +            break;
   1.517 +        case AS_PLAY_IN_PROGRESS:
   1.518 +            status = CD_PLAYING;
   1.519 +            break;
   1.520 +        case AS_PLAY_PAUSED:
   1.521 +            status = CD_PAUSED;
   1.522 +            break;
   1.523 +        case AS_PLAY_COMPLETED:
   1.524 +            status = CD_STOPPED;
   1.525 +            break;
   1.526 +        case AS_PLAY_ERROR:
   1.527 +            status = CD_ERROR;
   1.528 +            break;
   1.529 +        case AS_NO_STATUS:
   1.530 +            status = CD_STOPPED;
   1.531 +            break;
   1.532 +        default:
   1.533 +            status = CD_ERROR;
   1.534 +            break;
   1.535 +        }
   1.536  #ifdef DEBUG_CDROM
   1.537 -  fprintf(stderr,"scd.scd_header.sh_audio_status = %x\n",
   1.538 -	scd.scd_header.sh_audio_status);
   1.539 +        fprintf (stderr, "scd.scd_header.sh_audio_status = %x\n",
   1.540 +                 scd.scd_header.sh_audio_status);
   1.541  #endif
   1.542      }
   1.543      if (position) {
   1.544 -	if (status == CD_PLAYING || (status == CD_PAUSED) ) {
   1.545 -	    *position =
   1.546 -		scd.scd_position_data.scp_absaddr.lba.addr3 << 24 |
   1.547 -		scd.scd_position_data.scp_absaddr.lba.addr2 << 16 |
   1.548 -		scd.scd_position_data.scp_absaddr.lba.addr1 << 8  |
   1.549 -		scd.scd_position_data.scp_absaddr.lba.addr0;
   1.550 -	} else {
   1.551 -	    *position = 0;
   1.552 -	}
   1.553 +        if (status == CD_PLAYING || (status == CD_PAUSED)) {
   1.554 +            *position =
   1.555 +                scd.scd_position_data.scp_absaddr.lba.addr3 << 24 |
   1.556 +                scd.scd_position_data.scp_absaddr.lba.addr2 << 16 |
   1.557 +                scd.scd_position_data.scp_absaddr.lba.addr1 << 8 |
   1.558 +                scd.scd_position_data.scp_absaddr.lba.addr0;
   1.559 +        } else {
   1.560 +            *position = 0;
   1.561 +        }
   1.562      }
   1.563  
   1.564      return status;
   1.565  }
   1.566  
   1.567  /* Start play */
   1.568 -static int SDL_SYS_CDPlay(SDL_CD *cdrom, int start, int length)
   1.569 +static int
   1.570 +SDL_SYS_CDPlay (SDL_CD * cdrom, int start, int length)
   1.571  {
   1.572  /*
   1.573   * Play MSF
   1.574 @@ -385,60 +401,65 @@
   1.575      struct cd_play_audio_msf msf;
   1.576      int end;
   1.577  
   1.578 -    bzero(&msf, sizeof(msf));
   1.579 -    end = start +length;
   1.580 -    FRAMES_TO_MSF(start + 150, /* LBA = 4500*M + 75*S + F - 150 */
   1.581 -		  &msf.msf_starting_M_unit,
   1.582 -		  &msf.msf_starting_S_unit,
   1.583 -		  &msf.msf_starting_F_unit);
   1.584 -    FRAMES_TO_MSF(end + 150, /* LBA = 4500*M + 75*S + F - 150 */
   1.585 -		  &msf.msf_ending_M_unit,
   1.586 -		  &msf.msf_ending_S_unit,
   1.587 -		  &msf.msf_ending_F_unit);
   1.588 +    bzero (&msf, sizeof (msf));
   1.589 +    end = start + length;
   1.590 +    FRAMES_TO_MSF (start + 150, /* LBA = 4500*M + 75*S + F - 150 */
   1.591 +                   &msf.msf_starting_M_unit,
   1.592 +                   &msf.msf_starting_S_unit, &msf.msf_starting_F_unit);
   1.593 +    FRAMES_TO_MSF (end + 150,   /* LBA = 4500*M + 75*S + F - 150 */
   1.594 +                   &msf.msf_ending_M_unit,
   1.595 +                   &msf.msf_ending_S_unit, &msf.msf_ending_F_unit);
   1.596  
   1.597 -    return(ioctl(cdrom->id, CDROM_PLAY_AUDIO_MSF, &msf));
   1.598 +    return (ioctl (cdrom->id, CDROM_PLAY_AUDIO_MSF, &msf));
   1.599  }
   1.600  
   1.601  /* Pause play */
   1.602 -static int SDL_SYS_CDPause(SDL_CD *cdrom)
   1.603 +static int
   1.604 +SDL_SYS_CDPause (SDL_CD * cdrom)
   1.605  {
   1.606 -    return(ioctl(cdrom->id, CDROM_PAUSE_PLAY));
   1.607 +    return (ioctl (cdrom->id, CDROM_PAUSE_PLAY));
   1.608  }
   1.609  
   1.610  /* Resume play */
   1.611 -static int SDL_SYS_CDResume(SDL_CD *cdrom)
   1.612 +static int
   1.613 +SDL_SYS_CDResume (SDL_CD * cdrom)
   1.614  {
   1.615 -    return(ioctl(cdrom->id, CDROM_RESUME_PLAY));
   1.616 +    return (ioctl (cdrom->id, CDROM_RESUME_PLAY));
   1.617  }
   1.618  
   1.619  /* Stop play */
   1.620 -static int SDL_SYS_CDStop(SDL_CD *cdrom)
   1.621 +static int
   1.622 +SDL_SYS_CDStop (SDL_CD * cdrom)
   1.623  {
   1.624 -    return(ioctl(cdrom->id, SCSI_STOP_UNIT));
   1.625 +    return (ioctl (cdrom->id, SCSI_STOP_UNIT));
   1.626  }
   1.627  
   1.628  /* Eject the CD-ROM */
   1.629 -static int SDL_SYS_CDEject(SDL_CD *cdrom)
   1.630 +static int
   1.631 +SDL_SYS_CDEject (SDL_CD * cdrom)
   1.632  {
   1.633 -    return(ioctl(cdrom->id, CDROM_EJECT_CADDY));
   1.634 +    return (ioctl (cdrom->id, CDROM_EJECT_CADDY));
   1.635  }
   1.636  
   1.637  /* Close the CD-ROM handle */
   1.638 -static void SDL_SYS_CDClose(SDL_CD *cdrom)
   1.639 +static void
   1.640 +SDL_SYS_CDClose (SDL_CD * cdrom)
   1.641  {
   1.642 -    close(cdrom->id);
   1.643 +    close (cdrom->id);
   1.644  }
   1.645  
   1.646 -void SDL_SYS_CDQuit(void)
   1.647 +void
   1.648 +SDL_SYS_CDQuit (void)
   1.649  {
   1.650      int i;
   1.651  
   1.652 -    if ( SDL_numcds > 0 ) {
   1.653 -	for ( i=0; i<SDL_numcds; ++i ) {
   1.654 -	    SDL_free(SDL_cdlist[i]);
   1.655 -	}
   1.656 -	SDL_numcds = 0;
   1.657 +    if (SDL_numcds > 0) {
   1.658 +        for (i = 0; i < SDL_numcds; ++i) {
   1.659 +            SDL_free (SDL_cdlist[i]);
   1.660 +        }
   1.661 +        SDL_numcds = 0;
   1.662      }
   1.663  }
   1.664  
   1.665  #endif /* SDL_CDROM_OSF */
   1.666 +/* vi: set ts=4 sw=4 expandtab: */