More integration/cleanup. Now uses cdio bytesex.h's BE/LE routines.

copystring -> strdup.

Some int's changed to track_t. But I need to be careful *not* to change
cdda_interface.h.
This commit is contained in:
rocky
2004-12-19 01:43:38 +00:00
parent 81d0304b7e
commit 0c35a965fc
13 changed files with 243 additions and 314 deletions

View File

@@ -1,5 +1,5 @@
/* /*
$Id: cdda_interface.h,v 1.1 2004/12/18 17:29:32 rocky Exp $ $Id: cdda_interface.h,v 1.2 2004/12/19 01:43:38 rocky Exp $
Copyright (C) 2004 Rocky Bernstein <rocky@panix.com> Copyright (C) 2004 Rocky Bernstein <rocky@panix.com>
Copyright (C) 2001 Xiph.org Copyright (C) 2001 Xiph.org
@@ -28,6 +28,7 @@
#define _CDDA_INTERFACE_H_ #define _CDDA_INTERFACE_H_
#include <cdio/paranoia.h> #include <cdio/paranoia.h>
#include <cdio/types.h>
#define CD_FRAMESAMPLES (CDIO_CD_FRAMESIZE_RAW / 4) #define CD_FRAMESAMPLES (CDIO_CD_FRAMESIZE_RAW / 4)

View File

@@ -1,5 +1,5 @@
/* /*
$Id: common_interface.c,v 1.1 2004/12/18 17:29:32 rocky Exp $ $Id: common_interface.c,v 1.2 2004/12/19 01:43:38 rocky Exp $
Copyright (C) 2004 Rocky Bernstein <rocky@panix.com> Copyright (C) 2004 Rocky Bernstein <rocky@panix.com>
Copyright (C) 1998, 2002 Monty monty@xiph.org Copyright (C) 1998, 2002 Monty monty@xiph.org
@@ -28,6 +28,7 @@
#include <math.h> #include <math.h>
#include "common_interface.h" #include "common_interface.h"
#include <cdio/bytesex.h>
#include "utils.h" #include "utils.h"
#include "smallft.h" #include "smallft.h"
@@ -57,11 +58,11 @@ char *atapi_drive_info(int fd){
if (!(ioctl(fd, HDIO_GET_IDENTITY, id))) { if (!(ioctl(fd, HDIO_GET_IDENTITY, id))) {
if(id->model==0 || id->model[0]==0) if(id->model==0 || id->model[0]==0)
ret=copystring("Generic Unidentifiable ATAPI CDROM"); ret=strdup("Generic Unidentifiable ATAPI CDROM");
else else
ret=copystring(id->model); ret=strdup(id->model);
}else }else
ret=copystring("Generic Unidentifiable CDROM"); ret=strdup("Generic Unidentifiable CDROM");
free(id); free(id);
return(ret); return(ret);
@@ -131,14 +132,23 @@ data_bigendianp(cdrom_drive_t *d)
if(!zeroflag){ if(!zeroflag){
int j; int j;
for(j=0;j<128;j++)a[j]=le16_to_cpu(buff[j*2+beginsec+460]); for(j=0;j<128;j++)
for(j=0;j<128;j++)b[j]=le16_to_cpu(buff[j*2+beginsec+461]); a[j]=UINT16_FROM_LE(buff[j*2+beginsec+460]);
for(j=0;j<128;j++)
b[j]=UINT16_FROM_LE(buff[j*2+beginsec+461]);
fft_forward(128,a,NULL,NULL); fft_forward(128,a,NULL,NULL);
fft_forward(128,b,NULL,NULL); fft_forward(128,b,NULL,NULL);
for(j=0;j<128;j++)lsb_energy+=fabs(a[j])+fabs(b[j]);
for(j=0;j<128;j++)a[j]=be16_to_cpu(buff[j*2+beginsec+460]); for(j=0;j<128;j++)
for(j=0;j<128;j++)b[j]=be16_to_cpu(buff[j*2+beginsec+461]); lsb_energy+=fabs(a[j])+fabs(b[j]);
for(j=0;j<128;j++)
a[j]=UINT16_FROM_BE(buff[j*2+beginsec+460]);
for(j=0;j<128;j++)
b[j]=UINT16_FROM_BE(buff[j*2+beginsec+461]);
fft_forward(128,a,NULL,NULL); fft_forward(128,a,NULL,NULL);
fft_forward(128,b,NULL,NULL); fft_forward(128,b,NULL,NULL);
for(j=0;j<128;j++)msb_energy+=fabs(a[j])+fabs(b[j]); for(j=0;j<128;j++)msb_energy+=fabs(a[j])+fabs(b[j]);
@@ -193,20 +203,20 @@ data_bigendianp(cdrom_drive_t *d)
knows the leadoud/leadin size. */ knows the leadoud/leadin size. */
int int
FixupTOC(cdrom_drive_t *d,int tracks) FixupTOC(cdrom_drive_t *d, track_t i_tracks)
{ {
struct cdrom_multisession ms_str; struct cdrom_multisession ms_str;
int j; int j;
/* First off, make sure the 'starting sector' is >=0 */ /* First off, make sure the 'starting sector' is >=0 */
for(j=0;j<tracks;j++){ for(j=0;j<i_tracks;j++){
if(d->disc_toc[j].dwStartSector<0){ if(d->disc_toc[j].dwStartSector<0){
cdmessage(d,"\n\tTOC entry claims a negative start offset: massaging" cdmessage(d,"\n\tTOC entry claims a negative start offset: massaging"
".\n"); ".\n");
d->disc_toc[j].dwStartSector=0; d->disc_toc[j].dwStartSector=0;
} }
if(j<tracks-1 && d->disc_toc[j].dwStartSector> if(j<i_tracks-1 && d->disc_toc[j].dwStartSector>
d->disc_toc[j+1].dwStartSector){ d->disc_toc[j+1].dwStartSector){
cdmessage(d,"\n\tTOC entry claims an overly large start offset: massaging" cdmessage(d,"\n\tTOC entry claims an overly large start offset: massaging"
".\n"); ".\n");
@@ -218,7 +228,7 @@ FixupTOC(cdrom_drive_t *d,int tracks)
Flag things that are blatant/stupid/wrong */ Flag things that are blatant/stupid/wrong */
{ {
long last=d->disc_toc[0].dwStartSector; long last=d->disc_toc[0].dwStartSector;
for(j=1;j<tracks;j++){ for(j=1;j<i_tracks;j++){
if(d->disc_toc[j].dwStartSector<last){ if(d->disc_toc[j].dwStartSector<last){
cdmessage(d,"\n\tTOC entries claim non-increasing offsets: massaging" cdmessage(d,"\n\tTOC entries claim non-increasing offsets: massaging"
".\n"); ".\n");
@@ -245,7 +255,7 @@ FixupTOC(cdrom_drive_t *d,int tracks)
/* believe the multisession offset :-) */ /* believe the multisession offset :-) */
/* adjust end of last audio track to be in the first session */ /* adjust end of last audio track to be in the first session */
for (j = tracks-1; j >= 0; j--) { for (j = i_tracks-1; j >= 0; j--) {
if (j > 0 && !IS_AUDIO(d,j) && IS_AUDIO(d,j-1)) { if (j > 0 && !IS_AUDIO(d,j) && IS_AUDIO(d,j-1)) {
if ((d->disc_toc[j].dwStartSector > ms_str.addr.lba - 11400) && if ((d->disc_toc[j].dwStartSector > ms_str.addr.lba - 11400) &&
(ms_str.addr.lba - 11400 > d->disc_toc[j-1].dwStartSector)) (ms_str.addr.lba - 11400 > d->disc_toc[j-1].dwStartSector))

View File

@@ -1,5 +1,5 @@
/* /*
$Id: common_interface.h,v 1.1 2004/12/18 17:29:32 rocky Exp $ $Id: common_interface.h,v 1.2 2004/12/19 01:43:38 rocky Exp $
Copyright (C) 2004 Rocky Bernstein <rocky@panix.com> Copyright (C) 2004 Rocky Bernstein <rocky@panix.com>
Copyright (C) 1998 Monty xiphmont@mit.edu Copyright (C) 1998 Monty xiphmont@mit.edu
@@ -23,12 +23,13 @@
#define _CDDA_COMMON_INTERFACE_H_ #define _CDDA_COMMON_INTERFACE_H_
#include "low_interface.h" #include "low_interface.h"
#include <cdio/types.h>
/* Test for presence of a cdrom by pinging with the 'CDROMVOLREAD' ioctl() */ /** Test for presence of a cdrom by pinging with the 'CDROMVOLREAD' ioctl() */
extern int ioctl_ping_cdrom(int fd); extern int ioctl_ping_cdrom(int fd);
extern char *atapi_drive_info(int fd); extern char *atapi_drive_info(int fd);
extern int data_bigendianp(cdrom_drive_t *d); extern int data_bigendianp(cdrom_drive_t *d);
extern int FixupTOC(cdrom_drive_t *d,int tracks); extern int FixupTOC(cdrom_drive_t *d, track_t tracks);
#endif /*_CDDA_COMMON_INTERFACE_H_*/ #endif /*_CDDA_COMMON_INTERFACE_H_*/

View File

@@ -1,5 +1,5 @@
/* /*
$Id: cooked_interface.c,v 1.1 2004/12/18 17:29:32 rocky Exp $ $Id: cooked_interface.c,v 1.2 2004/12/19 01:43:38 rocky Exp $
Copyright (C) 2004 Rocky Bernstein <rocky@panix.com> Copyright (C) 2004 Rocky Bernstein <rocky@panix.com>
Original interface.c Copyright (C) 1994-1997 Original interface.c Copyright (C) 1994-1997
@@ -35,7 +35,7 @@ static int
cooked_readtoc (cdrom_drive_t *d) cooked_readtoc (cdrom_drive_t *d)
{ {
int i; int i;
int tracks; track_t i_tracks;
struct cdrom_tochdr hdr; struct cdrom_tochdr hdr;
struct cdrom_tocentry entry; struct cdrom_tocentry entry;
@@ -74,9 +74,9 @@ cooked_readtoc (cdrom_drive_t *d)
d->disc_toc[i].bTrack = entry.cdte_track; d->disc_toc[i].bTrack = entry.cdte_track;
d->disc_toc[i].dwStartSector = entry.cdte_addr.lba; d->disc_toc[i].dwStartSector = entry.cdte_addr.lba;
tracks=hdr.cdth_trk1+1; i_tracks=hdr.cdth_trk1+1;
d->cd_extra=FixupTOC(d,tracks); d->cd_extra=FixupTOC(d,i_tracks);
return(--tracks); /* without lead-out */ return(--i_tracks); /* without lead-out */
} }

View File

@@ -12,6 +12,7 @@
#include "low_interface.h" #include "low_interface.h"
#include "common_interface.h" #include "common_interface.h"
#include "utils.h" #include "utils.h"
#include <cdio/bytesex.h>
static void _clean_messages(cdrom_drive_t *d) static void _clean_messages(cdrom_drive_t *d)
{ {
@@ -76,7 +77,7 @@ cdda_open(cdrom_drive_t *d)
/* Some drives happily return a TOC even if there is no disc... */ /* Some drives happily return a TOC even if there is no disc... */
{ {
int i; int i;
for(i=0;i<d->tracks;i++) for(i=0; i<d->tracks; i++)
if(d->disc_toc[i].dwStartSector<0 || if(d->disc_toc[i].dwStartSector<0 ||
d->disc_toc[i+1].dwStartSector==0){ d->disc_toc[i+1].dwStartSector==0){
d->opened=0; d->opened=0;
@@ -115,7 +116,8 @@ long cdda_read(cdrom_drive_t *d, void *buffer, long beginsector, long sectors)
u_int16_t *p=(u_int16_t *)buffer; u_int16_t *p=(u_int16_t *)buffer;
long els=sectors*CD_FRAMESIZE_RAW/2; long els=sectors*CD_FRAMESIZE_RAW/2;
for(i=0;i<els;i++)p[i]=UINT16_SWAP_LE_BE_C(p[i]); for(i=0;i<els;i++)
p[i]=UINT16_SWAP_LE_BE_C(p[i]);
} }
} }
} }

View File

@@ -1,5 +1,5 @@
/* /*
$Id: scan_devices.c,v 1.1 2004/12/18 17:29:32 rocky Exp $ $Id: scan_devices.c,v 1.2 2004/12/19 01:43:38 rocky Exp $
Copyright (C) 2004 Rocky Bernstein <rocky@panix.com> Copyright (C) 2004 Rocky Bernstein <rocky@panix.com>
Copyright (C) 1998 Monty xiphmont@mit.edu Copyright (C) 1998 Monty xiphmont@mit.edu
@@ -86,7 +86,7 @@ cdda_find_a_cdrom(int messagedest, char **messages){
int j; int j;
/* try first eight of each device */ /* try first eight of each device */
for(j=0;j<4;j++){ for(j=0;j<4;j++){
char *buffer=copystring(cdrom_devices[i]); char *buffer=strdup(cdrom_devices[i]);
/* number, then letter */ /* number, then letter */
@@ -227,11 +227,11 @@ cdda_identify_cooked(const char *dev, int messagedest,
break; break;
case CDU31A_CDROM_MAJOR: case CDU31A_CDROM_MAJOR:
/* major indicates this is a cdrom; no ping necessary. */ /* major indicates this is a cdrom; no ping necessary. */
description=copystring("Sony CDU31A or compatible"); description=strdup("Sony CDU31A or compatible");
break; break;
case CDU535_CDROM_MAJOR: case CDU535_CDROM_MAJOR:
/* major indicates this is a cdrom; no ping necessary. */ /* major indicates this is a cdrom; no ping necessary. */
description=copystring("Sony CDU535 or compatible"); description=strdup("Sony CDU535 or compatible");
break; break;
case MATSUSHITA_CDROM_MAJOR: case MATSUSHITA_CDROM_MAJOR:
@@ -239,26 +239,26 @@ cdda_identify_cooked(const char *dev, int messagedest,
case MATSUSHITA_CDROM3_MAJOR: case MATSUSHITA_CDROM3_MAJOR:
case MATSUSHITA_CDROM4_MAJOR: case MATSUSHITA_CDROM4_MAJOR:
/* major indicates this is a cdrom; no ping necessary. */ /* major indicates this is a cdrom; no ping necessary. */
description=copystring("non-ATAPI IDE-style Matsushita/Panasonic CR-5xx or compatible"); description=strdup("non-ATAPI IDE-style Matsushita/Panasonic CR-5xx or compatible");
break; break;
case SANYO_CDROM_MAJOR: case SANYO_CDROM_MAJOR:
description=copystring("Sanyo proprietary or compatible: NOT CDDA CAPABLE"); description=strdup("Sanyo proprietary or compatible: NOT CDDA CAPABLE");
break; break;
case MITSUMI_CDROM_MAJOR: case MITSUMI_CDROM_MAJOR:
case MITSUMI_X_CDROM_MAJOR: case MITSUMI_X_CDROM_MAJOR:
description=copystring("Mitsumi proprietary or compatible: NOT CDDA CAPABLE"); description=strdup("Mitsumi proprietary or compatible: NOT CDDA CAPABLE");
break; break;
case OPTICS_CDROM_MAJOR: case OPTICS_CDROM_MAJOR:
description=copystring("Optics Dolphin or compatible: NOT CDDA CAPABLE"); description=strdup("Optics Dolphin or compatible: NOT CDDA CAPABLE");
break; break;
case AZTECH_CDROM_MAJOR: case AZTECH_CDROM_MAJOR:
description=copystring("Aztech proprietary or compatible: NOT CDDA CAPABLE"); description=strdup("Aztech proprietary or compatible: NOT CDDA CAPABLE");
break; break;
case GOLDSTAR_CDROM_MAJOR: case GOLDSTAR_CDROM_MAJOR:
description=copystring("Goldstar proprietary: NOT CDDA CAPABLE"); description=strdup("Goldstar proprietary: NOT CDDA CAPABLE");
break; break;
case CM206_CDROM_MAJOR: case CM206_CDROM_MAJOR:
description=copystring("Philips/LMS CM206 proprietary: NOT CDDA CAPABLE"); description=strdup("Philips/LMS CM206 proprietary: NOT CDDA CAPABLE");
break; break;
case SCSI_CDROM_MAJOR: case SCSI_CDROM_MAJOR:
@@ -286,7 +286,7 @@ cdda_identify_cooked(const char *dev, int messagedest,
d=calloc(1,sizeof(cdrom_drive_t)); d=calloc(1,sizeof(cdrom_drive_t));
d->cdda_device_name=device; d->cdda_device_name=device;
d->ioctl_device_name=copystring(device); d->ioctl_device_name=strdup(device);
d->drive_model=description; d->drive_model=description;
d->drive_type=type; d->drive_type=type;
d->cdda_fd=fd; d->cdda_fd=fd;
@@ -663,8 +663,8 @@ cdda_identify_scsi(const char *generic_device,
d->drive_model=calloc(36,1); d->drive_model=calloc(36,1);
memcpy(d->inqbytes,p,4); memcpy(d->inqbytes,p,4);
d->cdda_device_name=copystring(generic_device); d->cdda_device_name=strdup(generic_device);
d->ioctl_device_name=copystring(ioctl_device); d->ioctl_device_name=strdup(ioctl_device);
d->drive_model=calloc(36,1); d->drive_model=calloc(36,1);
strscat(d->drive_model,p+8,8); strscat(d->drive_model,p+8,8);
@@ -716,15 +716,15 @@ cdrom_drive_t *cdda_identify_test(const char *filename, int messagedest,
d=calloc(1,sizeof(cdrom_drive_t)); d=calloc(1,sizeof(cdrom_drive_t));
d->cdda_device_name=copystring(filename); d->cdda_device_name=strdup(filename);
d->ioctl_device_name=copystring(filename); d->ioctl_device_name=strdup(filename);
d->drive_type=-1; d->drive_type=-1;
d->cdda_fd=fd; d->cdda_fd=fd;
d->ioctl_fd=fd; d->ioctl_fd=fd;
d->interface=TEST_INTERFACE; d->interface=TEST_INTERFACE;
d->bigendianp=-1; /* We don't know yet... */ d->bigendianp=-1; /* We don't know yet... */
d->nsectors=-1; d->nsectors=-1;
d->drive_model=copystring("File based test interface"); d->drive_model=strdup("File based test interface");
idmessage(messagedest,messages,"\t\tCDROM sensed: %s\n",d->drive_model); idmessage(messagedest,messages,"\t\tCDROM sensed: %s\n",d->drive_model);
return(d); return(d);

View File

@@ -1,5 +1,5 @@
/* /*
$Id: scsi_interface.c,v 1.1 2004/12/18 17:29:32 rocky Exp $ $Id: scsi_interface.c,v 1.2 2004/12/19 01:43:38 rocky Exp $
Copyright (C) 2004 Rocky Bernstein <rocky@panix.com> Copyright (C) 2004 Rocky Bernstein <rocky@panix.com>
Original interface.c Copyright (C) 1994-1997 Original interface.c Copyright (C) 1994-1997
@@ -35,6 +35,7 @@
#include "common_interface.h" #include "common_interface.h"
#include "utils.h" #include "utils.h"
#include <cdio/scsi_mmc.h> #include <cdio/scsi_mmc.h>
#include <cdio/bytesex.h>
/* hook */ /* hook */
static int static int
@@ -504,7 +505,7 @@ static int
scsi_read_toc (cdrom_drive_t *d) scsi_read_toc (cdrom_drive_t *d)
{ {
int i,first,last; int i,first,last;
unsigned tracks; track_t i_tracks;
/* READTOC, MSF format flag, res, res, res, res, Start track, len msb, /* READTOC, MSF format flag, res, res, res, res, Start track, len msb,
len lsb, flags */ len lsb, flags */
@@ -521,7 +522,7 @@ scsi_read_toc (cdrom_drive_t *d)
first=d->sg_buffer[2]; first=d->sg_buffer[2];
last=d->sg_buffer[3]; last=d->sg_buffer[3];
tracks=last-first+1; i_tracks=last-first+1;
if (last > MAXTRK || first > MAXTRK || last<0 || first<0) { if (last > MAXTRK || first > MAXTRK || last<0 || first<0) {
cderror(d,"003: CDROM reporting illegal number of tracks\n"); cderror(d,"003: CDROM reporting illegal number of tracks\n");
@@ -572,8 +573,8 @@ scsi_read_toc (cdrom_drive_t *d)
(toc->start_LSB)); (toc->start_LSB));
} }
d->cd_extra = FixupTOC(d,tracks+1); /* include lead-out */ d->cd_extra = FixupTOC(d,i_tracks+1); /* include lead-out */
return(tracks); return(i_tracks);
} }
/* a contribution from Boris for IMS cdd 522 */ /* a contribution from Boris for IMS cdd 522 */
@@ -584,7 +585,7 @@ scsi_read_toc2 (cdrom_drive_t *d)
u_int32_t foo,bar; u_int32_t foo,bar;
int i; int i;
unsigned tracks; track_t i_tracks;
memcpy(d->sg_buffer, (char[]){ 0xe5, 0, 0, 0, 0, 0, 0, 0, 0, 0}, 10); memcpy(d->sg_buffer, (char[]){ 0xe5, 0, 0, 0, 0, 0, 0, 0, 0, 0}, 10);
d->sg_buffer[5]=1; d->sg_buffer[5]=1;
@@ -596,13 +597,13 @@ scsi_read_toc2 (cdrom_drive_t *d)
} }
/* copy to our structure and convert start sector */ /* copy to our structure and convert start sector */
tracks = d->sg_buffer[1]; i_tracks = d->sg_buffer[1];
if (tracks > MAXTRK) { if (i_tracks > MAXTRK) {
cderror(d,"003: CDROM reporting illegal number of tracks\n"); cderror(d,"003: CDROM reporting illegal number of tracks\n");
return(-3); return(-3);
} }
for (i = 0; i < tracks; i++){ for (i = 0; i < i_tracks; i++){
memcpy(d->sg_buffer, (char[]){ 0xe5, 0, 0, 0, 0, 0, 0, 0, 0, 0}, 10); memcpy(d->sg_buffer, (char[]){ 0xe5, 0, 0, 0, 0, 0, 0, 0, 0, 0}, 10);
d->sg_buffer[5]=i+1; d->sg_buffer[5]=i+1;
d->sg_buffer[8]=255; d->sg_buffer[8]=255;
@@ -626,8 +627,8 @@ scsi_read_toc2 (cdrom_drive_t *d)
d->disc_toc[i].bTrack = i + 1; d->disc_toc[i].bTrack = i + 1;
memcpy (&foo, d->sg_buffer+2, 4); memcpy (&foo, d->sg_buffer+2, 4);
memcpy (&bar, d->sg_buffer+6, 4); memcpy (&bar, d->sg_buffer+6, 4);
d->disc_toc[i].dwStartSector = d->adjust_ssize * (be32_to_cpu(foo) + d->disc_toc[i].dwStartSector =
be32_to_cpu(bar)); d->adjust_ssize * (UINT32_FROM_BE(foo) + UINT32_FROM_BE(bar));
d->disc_toc[i].dwStartSector= d->adjust_ssize * d->disc_toc[i].dwStartSector= d->adjust_ssize *
((((signed char)(d->sg_buffer[2])<<24) | ((((signed char)(d->sg_buffer[2])<<24) |
@@ -641,8 +642,8 @@ scsi_read_toc2 (cdrom_drive_t *d)
(d->sg_buffer[9])))); (d->sg_buffer[9]))));
d->cd_extra = FixupTOC(d,tracks+1); d->cd_extra = FixupTOC(d,i_tracks+1);
return(tracks); return(i_tracks);
} }
/* These do one 'extra' copy in the name of clean code */ /* These do one 'extra' copy in the name of clean code */
@@ -835,7 +836,7 @@ i_read_mmc3 (cdrom_drive_t *d, void *p, long int begin, long int sectors)
/* straight from the MMC3 spec */ /* straight from the MMC3 spec */
static inline void static inline void
LBA_to_MSF(long int lba, unsigned char *M, unsigned char *S, unsigned char *F) LBA_to_MSF(lba_t lba, unsigned char *M, unsigned char *S, unsigned char *F)
{ {
if (lba>=-CDIO_PREGAP_SECTORS){ if (lba>=-CDIO_PREGAP_SECTORS){
*M = ( lba+CDIO_PREGAP_SECTORS)/(CDIO_CD_FRAMES_PER_MIN); *M = ( lba+CDIO_PREGAP_SECTORS)/(CDIO_CD_FRAMES_PER_MIN);

View File

@@ -1,5 +1,5 @@
/* /*
$Id: utils.h,v 1.2 2004/12/19 00:02:09 rocky Exp $ $Id: utils.h,v 1.3 2004/12/19 01:43:38 rocky Exp $
Copyright (C) 2004 Rocky Bernstein <rocky@panix.com> Copyright (C) 2004 Rocky Bernstein <rocky@panix.com>
Copyright (C) 1998 Monty xiphmont@mit.edu Copyright (C) 1998 Monty xiphmont@mit.edu
@@ -19,89 +19,22 @@
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/ */
#include <endian.h>
#include <stdio.h> #include <stdio.h>
#include <errno.h>
#include <string.h>
#include <cdio/types.h>
#include <cdio/bytesex.h>
/* I wonder how many alignment issues this is gonna trip in the /* I wonder how many alignment issues this is gonna trip in the
future... it shouldn't trip any... I guess we'll find out :) */ future... it shouldn't trip any... I guess we'll find out :) */
static inline int bigendianp(void){ static inline int
bigendianp(void)
{
int test=1; int test=1;
char *hack=(char *)(&test); char *hack=(char *)(&test);
if(hack[0])return(0); if(hack[0])return(0);
return(1); return(1);
} }
#if BYTE_ORDER == LITTLE_ENDIAN static inline char *
catstring(char *buff,const char *s){
static inline int32_t be32_to_cpu(int32_t x){
return(UINT32_SWAP_LE_BE_C(x));
}
static inline int16_t be16_to_cpu(int16_t x){
return(UINT16_SWAP_LE_BE_C(x));
}
static inline int32_t le32_to_cpu(int32_t x){
return(x);
}
static inline int16_t le16_to_cpu(int16_t x){
return(x);
}
#else
static inline int32_t be32_to_cpu(int32_t x){
return(x);
}
static inline int16_t be16_to_cpu(int16_t x){
return(x);
}
static inline int32_t le32_to_cpu(int32_t x){
return(UINT32_SWAP_LE_BE_C(x));
}
static inline int16_t le16_to_cpu(int16_t x){
return(UINT16_SWAP_LE_BE_C(x));
}
#endif
static inline int32_t cpu_to_be32(int32_t x){
return(be32_to_cpu(x));
}
static inline int32_t cpu_to_le32(int32_t x){
return(le32_to_cpu(x));
}
static inline int16_t cpu_to_be16(int16_t x){
return(be16_to_cpu(x));
}
static inline int16_t cpu_to_le16(int16_t x){
return(le16_to_cpu(x));
}
static inline char *copystring(const char *s){
if(s){
char *ret=malloc((strlen(s)+9)*sizeof(char)); /* +9 to get around a linux
libc 5 bug. below too */
strcpy(ret,s);
return(ret);
}
return(NULL);
}
static inline char *catstring(char *buff,const char *s){
if(s){ if(s){
if(buff) if(buff)
buff=realloc(buff,strlen(buff)+strlen(s)+9); buff=realloc(buff,strlen(buff)+strlen(s)+9);

View File

@@ -1,3 +1,24 @@
/*
$Id: buffering_write.c,v 1.2 2004/12/19 01:43:38 rocky Exp $
Copyright (C) 2004 Rocky Bernstein <rocky@panix.com>
Copyright (C) 1998, 1999 Monty <xiphmont@mit.edu>
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License as
published by the Free Software Foundation; either version 2, or (at
your option) any later version.
This program is distributed in the hope that it will be useful, but
WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
/* Eliminate teeny little writes. patch submitted by /* Eliminate teeny little writes. patch submitted by
Rob Ross <rbross@parl.ces.clemson.edu> --Monty 19991008 */ Rob Ross <rbross@parl.ces.clemson.edu> --Monty 19991008 */
@@ -18,13 +39,31 @@ static long bw_pos = 0;
static char bw_outbuf[OUTBUFSZ]; static char bw_outbuf[OUTBUFSZ];
/* buffering_write() - buffers data to a specified size before writing.
long int
blocking_write(int outf, char *buffer, long num){
long int words=0,temp;
while(words<num){
temp=write(outf,buffer+words,num-words);
if(temp==-1){
if(errno!=EINTR && errno!=EAGAIN)
return(-1);
temp=0;
}
words+=temp;
}
return(0);
}
/** buffering_write() - buffers data to a specified size before writing.
* *
* Restrictions: * Restrictions:
* - MUST CALL BUFFERING_CLOSE() WHEN FINISHED!!! * - MUST CALL BUFFERING_CLOSE() WHEN FINISHED!!!
* *
*/ */
long buffering_write(int fd, char *buffer, long num) long int
buffering_write(int fd, char *buffer, long num)
{ {
if (fd != bw_fd) { if (fd != bw_fd) {
/* clean up after buffering for some other file */ /* clean up after buffering for some other file */
@@ -55,11 +94,12 @@ long buffering_write(int fd, char *buffer, long num)
return(0); return(0);
} }
/* buffering_close() - writes out remaining buffered data before closing /** buffering_close() - writes out remaining buffered data before
* file. * closing file.
* *
*/ */
int buffering_close(int fd) int
buffering_close(int fd)
{ {
if (fd == bw_fd && bw_pos > 0) { if (fd == bw_fd && bw_pos > 0) {
/* write out remaining data and clean up */ /* write out remaining data and clean up */

View File

@@ -1,23 +1,39 @@
/* /*
* Copyright: GNU Public License 2 applies $Id: buffering_write.h,v 1.2 2004/12/19 01:43:38 rocky Exp $
*
* This program is free software; you can redistribute it and/or modify Copyright (C) 2004 Rocky Bernstein <rocky@panix.com>
* it under the terms of the GNU General Public License as published by Copyright (C) 1998 Monty <xiphmont@mit.edu>
* the Free Software Foundation; either version 2, or (at your option)
* any later version. This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License as
* This program is distributed in the hope that it will be useful, published by the Free Software Foundation; either version 2, or (at
* but WITHOUT ANY WARRANTY; without even the implied warranty of your option) any later version.
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details. This program is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* You should have received a copy of the GNU General Public License MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* along with this program; if not, write to the Free Software General Public License for more details.
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
* You should have received a copy of the GNU General Public License
* Copyright (C) 2004 Rocky Bernstein <rocky@panix.com> along with this program; if not, write to the Free Software
* (C) 1998 Monty <xiphmont@mit.edu> Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*
*/ */
extern long blocking_write(int outf, char *buffer, long i_num); extern long blocking_write(int outf, char *buffer, long i_num);
/** buffering_write() - buffers data to a specified size before writing.
*
* Restrictions:
* - MUST CALL BUFFERING_CLOSE() WHEN FINISHED!!!
*
*/
extern long buffering_write(int outf, char *buffer, long num);
/** buffering_close() - writes out remaining buffered data before
* closing file.
*
*/
extern int buffering_close(int fd);

View File

@@ -1,5 +1,6 @@
/* /*
* Copyright: GNU Public License 2 applies * Copyright (C) 2004 Rocky Bernstein <rocky@panix.com>
* (C) 1998 Monty <xiphmont@mit.edu>
* *
* This program is free software; you can redistribute it and/or modify * This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by * it under the terms of the GNU General Public License as published by
@@ -15,8 +16,6 @@
* along with this program; if not, write to the Free Software * along with this program; if not, write to the Free Software
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
* *
* Copyright (C) 2004 Rocky Bernstein <rocky@panix.com>
* (C) 1998 Monty <xiphmont@mit.edu>
* *
* See ChangeLog for recent changes. * See ChangeLog for recent changes.
* *
@@ -71,6 +70,17 @@
extern int verbose; extern int verbose;
extern int quiet; extern int quiet;
/* I wonder how many alignment issues this is gonna trip in the
future... it shouldn't trip any... I guess we'll find out :) */
static int bigendianp(void)
{
int test=1;
char *hack=(char *)(&test);
if(hack[0])return(0);
return(1);
}
static long parse_offset(cdrom_drive_t *d, char *offset, int begin){ static long parse_offset(cdrom_drive_t *d, char *offset, int begin){
long track=-1; long track=-1;
long hours=-1; long hours=-1;
@@ -196,7 +206,7 @@ static long parse_offset(cdrom_drive_t *d, char *offset, int begin){
static void display_toc(cdrom_drive_t *d){ static void display_toc(cdrom_drive_t *d){
long audiolen=0; long audiolen=0;
int i; track_t i;
report("\nTable of contents (audio tracks only):\n" report("\nTable of contents (audio tracks only):\n"
"track length begin copy pre ch\n" "track length begin copy pre ch\n"
"==========================================================="); "===========================================================");
@@ -642,21 +652,6 @@ struct option options [] = {
{NULL,0,NULL,0} {NULL,0,NULL,0}
}; };
long blocking_write(int outf, char *buffer, long num){
long words=0,temp;
while(words<num){
temp=write(outf,buffer+words,num-words);
if(temp==-1){
if(errno!=EINTR && errno!=EAGAIN)
return(-1);
temp=0;
}
words+=temp;
}
return(0);
}
static cdrom_drive_t *d=NULL; static cdrom_drive_t *d=NULL;
static cdrom_paranoia_t *p=NULL; static cdrom_paranoia_t *p=NULL;
@@ -665,22 +660,25 @@ static void cleanup(void){
if(d)cdda_close(d); if(d)cdda_close(d);
} }
int main(int argc,char *argv[]){ int
int toc_bias=0; main(int argc,char *argv[])
int toc_offset=0; {
int sample_offset=0; int toc_bias = 0;
int force_cdrom_endian=-1; int toc_offset = 0;
int force_cdrom_sectors=-1; int sample_offset = 0;
int force_cdrom_overlap=-1; int force_cdrom_endian = -1;
char *force_cdrom_device=NULL; int force_cdrom_sectors = -1;
char *force_generic_device=NULL; int force_cdrom_overlap = -1;
int force_cdrom_speed=-1; char *force_cdrom_device = NULL;
int max_retries=20; char *force_generic_device = NULL;
char *span=NULL; int force_cdrom_speed = -1;
int output_type=1; /* 0=raw, 1=wav, 2=aifc */ int max_retries = 20;
int output_endian=0; /* -1=host, 0=little, 1=big */ char *span = NULL;
int query_only=0; int output_type = 1; /* 0=raw, 1=wav, 2=aifc */
int batch=0,i; int output_endian = 0; /* -1=host, 0=little, 1=big */
int query_only = 0;
int batch = 0;
int i;
/* full paranoia, but allow skipping */ /* full paranoia, but allow skipping */
int paranoia_mode=PARANOIA_MODE_FULL^PARANOIA_MODE_NEVERSKIP; int paranoia_mode=PARANOIA_MODE_FULL^PARANOIA_MODE_NEVERSKIP;
@@ -712,11 +710,11 @@ int main(int argc,char *argv[]){
break; break;
case 'd': case 'd':
if(force_cdrom_device)free(force_cdrom_device); if(force_cdrom_device)free(force_cdrom_device);
force_cdrom_device=copystring(optarg); force_cdrom_device=strdup(optarg);
break; break;
case 'g': case 'g':
if(force_generic_device)free(force_generic_device); if(force_generic_device)free(force_generic_device);
force_generic_device=copystring(optarg); force_generic_device=strdup(optarg);
break; break;
case 'S': case 'S':
force_cdrom_speed=atoi(optarg); force_cdrom_speed=atoi(optarg);
@@ -799,7 +797,7 @@ int main(int argc,char *argv[]){
break; break;
case 'i': case 'i':
if(info_file)free(info_file); if(info_file)free(info_file);
info_file=copystring(info_file); info_file=strdup(info_file);
break; break;
case 'T': case 'T':
toc_bias=-1; toc_bias=-1;
@@ -825,7 +823,7 @@ int main(int argc,char *argv[]){
exit(1); exit(1);
} }
}else }else
span=copystring(argv[optind]); span=strdup(argv[optind]);
report(VERSION); report(VERSION);
@@ -979,6 +977,7 @@ int main(int argc,char *argv[]){
char *span2=strchr(span,'-'); char *span2=strchr(span,'-');
if(strrchr(span,'-')!=span2){ if(strrchr(span,'-')!=span2){
report("Error parsing span argument"); report("Error parsing span argument");
free(span);
cdda_close(d); cdda_close(d);
d=NULL; d=NULL;
exit(1); exit(1);
@@ -1322,6 +1321,9 @@ int main(int argc,char *argv[]){
report("Done.\n\n"); report("Done.\n\n");
cdda_close(d); cdda_close(d);
if (span) free(span);
if (force_cdrom_device) free(force_cdrom_device);
if (force_generic_device) free(force_generic_device);
d=NULL; d=NULL;
return 0; return 0;
} }

View File

@@ -1,5 +1,5 @@
/* /*
$Id: utils.h,v 1.2 2004/12/19 00:02:09 rocky Exp $ $Id: utils.h,v 1.3 2004/12/19 01:43:38 rocky Exp $
Copyright (C) 2004 Rocky Bernstein <rocky@panix.com> Copyright (C) 2004 Rocky Bernstein <rocky@panix.com>
Copyright (C) 1998 Monty xiphmont@mit.edu Copyright (C) 1998 Monty xiphmont@mit.edu
@@ -20,92 +20,12 @@
*/ */
#include <stdlib.h> #include <stdlib.h>
#include <endian.h>
#include <stdio.h> #include <stdio.h>
#include <errno.h>
#include <string.h> #include <string.h>
#include <cdio/types.h>
#include <cdio/bytesex.h>
extern long buffering_write(int outf, char *buffer, long num); static inline char *
extern int buffering_close(int fd); catstring(char *buff, const char *s)
{
/* I wonder how many alignment issues this is gonna trip in the
future... it shouldn't trip any... I guess we'll find out :) */
static inline int bigendianp(void){
int test=1;
char *hack=(char *)(&test);
if(hack[0])return(0);
return(1);
}
#if BYTE_ORDER == LITTLE_ENDIAN
static inline int32_t be32_to_cpu(int32_t x){
return(UINT32_SWAP_LE_BE_C(x));
}
static inline int16_t be16_to_cpu(int16_t x){
return(UINT16_SWAP_LE_BE_C(x));
}
static inline int32_t le32_to_cpu(int32_t x){
return(x);
}
static inline int16_t le16_to_cpu(int16_t x){
return(x);
}
#else
static inline int32_t be32_to_cpu(int32_t x){
return(x);
}
static inline int16_t be16_to_cpu(int16_t x){
return(x);
}
static inline int32_t le32_to_cpu(int32_t x){
return(UINT32_SWAP_LE_BE_C(x));
}
static inline int16_t le16_to_cpu(int16_t x){
return(UINT16_SWAP_LE_BE_C(x));
}
#endif
static inline int32_t cpu_to_be32(int32_t x){
return(be32_to_cpu(x));
}
static inline int32_t cpu_to_le32(int32_t x){
return(le32_to_cpu(x));
}
static inline int16_t cpu_to_be16(int16_t x){
return(be16_to_cpu(x));
}
static inline int16_t cpu_to_le16(int16_t x){
return(le16_to_cpu(x));
}
static inline char *copystring(const char *s){
if(s){
char *ret=malloc((strlen(s)+1)*sizeof(char));
strcpy(ret,s);
return(ret);
}
return(NULL);
}
static inline char *catstring(char *buff,const char *s){
if(s){ if(s){
if(buff) if(buff)
buff=realloc(buff,strlen(buff)+strlen(s)+1); buff=realloc(buff,strlen(buff)+strlen(s)+1);

View File

@@ -1,4 +1,4 @@
# $Id: Makefile.am,v 1.36 2004/12/19 00:02:09 rocky Exp $ # $Id: Makefile.am,v 1.37 2004/12/19 01:43:38 rocky Exp $
# #
# Copyright (C) 2003, 2004 Rocky Bernstein <rocky@panix.com> # Copyright (C) 2003, 2004 Rocky Bernstein <rocky@panix.com>
# #
@@ -41,7 +41,10 @@ testbincue_LDADD = $(LIBCDIO_LIBS)
testbincue_CFLAGS = -DTEST_DIR=\"$(srcdir)\" testbincue_CFLAGS = -DTEST_DIR=\"$(srcdir)\"
check_SCRIPTS = check_nrg.sh check_cue.sh check_cd_read.sh \ check_SCRIPTS = check_nrg.sh check_cue.sh check_cd_read.sh \
check_iso.sh check_opts.sh check_paranoia.sh check_iso.sh check_opts.sh
# If we beefed this up so it checked to see if a CD-DA was loaded
# it could be an automatic test. But for now, not so.
# check_paranoia.sh
check_PROGRAMS = $(hack) check_PROGRAMS = $(hack)