diff --git a/autogen.sh b/autogen.sh index 5158e8e..275bcbe 100755 --- a/autogen.sh +++ b/autogen.sh @@ -2,6 +2,10 @@ # Run this to generate all the initial makefiles, etc. # Additional options go to configure. +# For OpenBSD +export AUTOCONF_VERSION=2.69 +export AUTOMAKE_VERSION=1.15 + echo "Rebuilding ./configure with autoreconf..." autoreconf -f -i if [ $? -ne 0 ]; then diff --git a/configure.ac b/configure.ac index 608277b..e3b8cba 100644 --- a/configure.ac +++ b/configure.ac @@ -86,6 +86,9 @@ AC_AIX AC_PROG_MKDIR_P +AC_PROG_AWK +AC_SUBST(AWK) + if test "x$GCC" != "xyes" then AC_MSG_WARN([ @@ -465,6 +468,7 @@ AC_CONFIG_FILES([ # AC_CONFIG_FILES([po/Makefile]) AC_CONFIG_FILES([test/check_paranoia.sh], [chmod +x test/check_paranoia.sh]) AC_CONFIG_FILES([test/endian.sh], [chmod +x test/endian.sh]) +AC_CONFIG_FILES([test/check_start_track_not_one.sh], [chmod +x test/check_start_track_not_one.sh]) AC_OUTPUT AC_MSG_NOTICE([ diff --git a/lib/cdda_interface/cddap_interface.c b/lib/cdda_interface/cddap_interface.c index 9e92545..53e23a6 100644 --- a/lib/cdda_interface/cddap_interface.c +++ b/lib/cdda_interface/cddap_interface.c @@ -55,7 +55,7 @@ cddap_readtoc (cdrom_drive_t *d) CDIO_CDROM_LEADOUT_TRACK); d->cd_extra=FixupTOC(d, d->tracks+1); /* fixup includes lead-out */ - return --i_track; /* number of tracks returned does not include lead-out */ + return d->tracks; /* number of tracks returned does not include lead-out */ } @@ -263,6 +263,7 @@ verify_read_command(cdrom_drive_t *d) int16_t *buff=malloc(CDIO_CD_FRAMESIZE_RAW); int audioflag=0; int i_test_flags = d->i_test_flags; + int first_track = cdio_get_first_track_num(d->p_cdio); d->i_test_flags = 0; @@ -270,7 +271,7 @@ verify_read_command(cdrom_drive_t *d) d->enable_cdda(d,1); - for(i=1;i<=d->tracks;i++){ + for(i=first_track; itracks; i++){ if(cdda_track_audiop(d,i)==1){ long firstsector=cdda_track_firstsector(d,i); long lastsector=cdda_track_lastsector(d,i); diff --git a/lib/cdda_interface/common_interface.c b/lib/cdda_interface/common_interface.c index 54bff7b..4840f1b 100644 --- a/lib/cdda_interface/common_interface.c +++ b/lib/cdda_interface/common_interface.c @@ -70,12 +70,13 @@ data_bigendianp(cdrom_drive_t *d) cdmessage(d,"\nAttempting to determine drive endianness from data..."); d->enable_cdda(d,1); - for(i=0,checked=0;itracks;i++){ + for(i=cdio_get_first_track_num(d->p_cdio), checked=0; + i<=cdio_get_last_track_num(d->p_cdio); i++){ float lsb_energy=0; float msb_energy=0; - if(cdda_track_audiop(d,i+1)==1){ - long firstsector=cdda_track_firstsector(d,i+1); - long lastsector=cdda_track_lastsector(d,i+1); + if(cdda_track_audiop(d,i)==1){ + long firstsector=cdda_track_firstsector(d,i); + long lastsector=cdda_track_lastsector(d,i); int zeroflag=-1; long beginsec=0; diff --git a/lib/cdda_interface/toc.c b/lib/cdda_interface/toc.c index 930cf9a..45195e9 100644 --- a/lib/cdda_interface/toc.c +++ b/lib/cdda_interface/toc.c @@ -65,15 +65,17 @@ lsn_t cdda_disc_firstsector(cdrom_drive_t *d) { int i; + int first_track = cdio_get_first_track_num(d->p_cdio); + if(!d->opened){ cderror(d,"400: Device not open\n"); return(-400); } /* look for an audio track */ - for ( i=0; itracks; i++ ) + for (i = first_track - 1; i < first_track - 1 + d->tracks; i++) if( cdda_track_audiop(d, i+1)==1 ) { - if (i == 0) /* disc starts at lba 0 if first track is an audio track */ + if (i == first_track - 1) /* disc starts at lba 0 if first track is an audio track */ return 0; else return cdda_track_firstsector(d, i+1); diff --git a/lib/paranoia/p_block.c b/lib/paranoia/p_block.c index 1f68d30..8cce81f 100644 --- a/lib/paranoia/p_block.c +++ b/lib/paranoia/p_block.c @@ -384,7 +384,8 @@ i_paranoia_firstlast(cdrom_paranoia_t *p) i = cdda_sector_gettrack(d, p->cursor); if ( CDIO_INVALID_TRACK != i ) { - if ( 0 == i ) i++; + if ( 0 == i ) + i = cdio_get_first_track_num(d->p_cdio); j = i; /* In the below loops, We assume the cursor already is on an audio sector. Not sure if this is correct if p->cursor is in the pregap diff --git a/src/cd-paranoia.c b/src/cd-paranoia.c index 9443b62..3f0da3c 100644 --- a/src/cd-paranoia.c +++ b/src/cd-paranoia.c @@ -148,7 +148,7 @@ parse_offset(cdrom_drive_t *d, char *offset, int begin) if(chars>0){ offset[chars]='\0'; i_track=atoi(offset); - if ( i_track > d->tracks ) { + if (i_track >= cdio_get_first_track_num(d->p_cdio) + d->tracks) { /*take track i_first_track-1 as pre-gap of 1st track*/ report("Track #%d does not exist.",i_track); exit(1); @@ -251,7 +251,8 @@ display_toc(cdrom_drive_t *d) "track length begin copy pre ch\n" "==========================================================="); - for( i=1; i<=d->tracks; i++) + for( i=cdio_get_first_track_num(d->p_cdio); + i<=cdio_get_last_track_num(d->p_cdio); i++) if ( cdda_track_audiop(d,i) > 0 ) { lsn_t sec=cdda_track_firstsector(d,i); @@ -1189,16 +1190,20 @@ main(int argc,char *argv[]) { int track1 = cdda_sector_gettrack(d, i_first_lsn); + int track2 = cdda_sector_gettrack(d, i_last_lsn); long off1 = i_first_lsn - cdda_track_firstsector(d, track1); long off2 = i_last_lsn - cdda_track_firstsector(d, track2); int i; - for( i=track1; i<=track2; i++ ) + for( i=track1; i<=track2; i++ ) { if(i != 0 && !cdda_track_audiop(d,i)){ report("Selected span contains non audio track at track %02d. Aborting.\n\n", i); exit(1); + if (i == 0) + i = cdio_get_first_track_num(d->p_cdio) - 1; } + } report("Ripping from sector %7ld (track %2d [%d:%02d.%02d])\n" "\t to sector %7ld (track %2d [%d:%02d.%02d])\n", diff --git a/test/.gitignore b/test/.gitignore index 5de0176..8abb1f6 100644 --- a/test/.gitignore +++ b/test/.gitignore @@ -50,3 +50,7 @@ /testtoc /testunconfig /testutils +/start_track_not_one.sh +/start_track_not_one.cue +/start_track_not_one.bin +/get_libcdio_version diff --git a/test/Makefile.am b/test/Makefile.am index 6fe380b..177f832 100644 --- a/test/Makefile.am +++ b/test/Makefile.am @@ -15,7 +15,7 @@ DATA_DIR = @abs_top_srcdir@/test/data AM_CPPFLAGS = -I$(top_srcdir) $(LIBCDIO_CFLAGS) $(LIBCDIO_PARANOIA_CFLAGS) -check_SCRIPTS = check_paranoia.sh endian.sh +check_SCRIPTS = check_paranoia.sh endian.sh check_start_track_not_one.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 @@ -28,6 +28,11 @@ EXTRA_DIST = $(check_SCRIPTS) $(check_DATA) TESTS = $(check_PROGRAMS) $(check_SCRIPTS) -MOSTLYCLEANFILES = core core.* *.dump cdda-orig.wav cdda-try.wav *.raw *.bin *.cue +MOSTLYCLEANFILES = core core.* *.dump cdda-orig.wav cdda-try.wav *.raw *.bin *.cue get_libcdio_version test: check-am + +# extra dependencies of tests +check-am: get_libcdio_version + +get_libcdio_version: CFLAGS += @LIBCDIO_CFLAGS@ diff --git a/test/check_start_track_not_one.sh b/test/check_start_track_not_one.sh new file mode 100755 index 0000000..cf9816b --- /dev/null +++ b/test/check_start_track_not_one.sh @@ -0,0 +1,62 @@ +#/bin/sh +# Check that a digital audio CD with a start track number of >1 works. + +if test ! -d "$abs_top_builddir" ; then + abs_top_builddir=/home/edd/source/libcdio-paranoia +fi + +if test ! -d "$abs_top_srcdir" ; then + abs_top_srcdir=/home/edd/source/libcdio-paranoia +fi + +test_dir=$abs_top_srcdir/test + +set -e + +cd_paranoia=$abs_top_builddir/src/cd-paranoia +base=start_track_not_one +orig_cdda=$test_dir/data/cdda.bin + +# First we make a longer CDDA image. +cdda=$test_dir/$base.bin +cat $orig_cdda $orig_cdda $orig_cdda > $cdda + +# And a CUE file with a non-one start track. +cue=$test_dir/$base.cue +cat << EOF > $cue +FILE "$cdda" BINARY + TRACK 07 AUDIO + FLAGS DCP + INDEX 01 00:00:00 + TRACK 08 AUDIO + FLAGS DCP + INDEX 01 00:04:02 + TRACK 09 AUDIO + FLAGS DCP + INDEX 01 00:08:04 +EOF + +# Use an awk program to parse/verify the TOC. +# We check that we see only tracks 7, 8 and 9. +awk_prog=' +BEGIN { expect_track = 7; in_toc = 0; err = 0; num_tracks = 0 } +/^TOTAL/ { in_toc = 0 } +in_toc == 1 { + if ($1 != expect_track ".") { + print "Expected track " expect_track ", got " $1; + err = 1 + } + expect_track ++; + num_tracks ++; + } +/^===/ { in_toc = 1 } +END { + if (num_tracks != 3) { + print "Number of tracks was not 3."; + err = 1 + } + exit err; + } +' + +$cd_paranoia -Q -d $cue 2>&1 | awk "$awk_prog" diff --git a/test/check_start_track_not_one.sh.in b/test/check_start_track_not_one.sh.in new file mode 100755 index 0000000..a0f7a31 --- /dev/null +++ b/test/check_start_track_not_one.sh.in @@ -0,0 +1,62 @@ +#/bin/sh +# Check that a digital audio CD with a start track number of >1 works. + +if test ! -d "$abs_top_builddir" ; then + abs_top_builddir=@abs_top_builddir@ +fi + +if test ! -d "$abs_top_srcdir" ; then + abs_top_srcdir=@abs_top_srcdir@ +fi + +test_dir=$abs_top_srcdir/test + +set -e + +cd_paranoia=$abs_top_builddir/src/cd-paranoia +base=start_track_not_one +orig_cdda=$test_dir/data/cdda.bin + +# First we make a longer CDDA image. +cdda=$test_dir/$base.bin +cat $orig_cdda $orig_cdda $orig_cdda > $cdda + +# And a CUE file with a non-one start track. +cue=$test_dir/$base.cue +cat << EOF > $cue +FILE "$cdda" BINARY + TRACK 07 AUDIO + FLAGS DCP + INDEX 01 00:00:00 + TRACK 08 AUDIO + FLAGS DCP + INDEX 01 00:04:02 + TRACK 09 AUDIO + FLAGS DCP + INDEX 01 00:08:04 +EOF + +# Use an awk program to parse/verify the TOC. +# We check that we see only tracks 7, 8 and 9. +awk_prog=' +BEGIN { expect_track = 7; in_toc = 0; err = 0; num_tracks = 0 } +/^TOTAL/ { in_toc = 0 } +in_toc == 1 { + if ($1 != expect_track ".") { + print "Expected track " expect_track ", got " $1; + err = 1 + } + expect_track ++; + num_tracks ++; + } +/^===/ { in_toc = 1 } +END { + if (num_tracks != 3) { + print "Number of tracks was not 3."; + err = 1 + } + exit err; + } +' + +$cd_paranoia -Q -d $cue 2>&1 | @AWK@ "$awk_prog" diff --git a/test/get_libcdio_version.c b/test/get_libcdio_version.c new file mode 100644 index 0000000..19c6c6b --- /dev/null +++ b/test/get_libcdio_version.c @@ -0,0 +1,16 @@ +/* + * Prints the version of libcdio. + * + * Test scripts can call this to skip tests under certain version conditions. + */ + +#include +#include +#include + +int +main(void) +{ + printf("%d\n", LIBCDIO_VERSION_NUM); + return EXIT_SUCCESS; +}