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