From 5b79bb49efbac5d75e4e3bd47e4fe743829bbf30 Mon Sep 17 00:00:00 2001 From: rocky Date: Sun, 28 Sep 2003 01:04:57 +0000 Subject: [PATCH] Impliment MCN for bincue. --- include/cdio/cdio.h | 6 +++--- lib/_cdio_bincue.c | 40 ++++++++++++++++++++++++++++++++++++---- test/cdda.cue | 1 + test/cdda.right | 2 +- 4 files changed, 41 insertions(+), 8 deletions(-) diff --git a/include/cdio/cdio.h b/include/cdio/cdio.h index 327c20dd..a9d03e07 100644 --- a/include/cdio/cdio.h +++ b/include/cdio/cdio.h @@ -1,5 +1,5 @@ /* -*- c -*- - $Id: cdio.h,v 1.22 2003/09/27 23:29:29 rocky Exp $ + $Id: cdio.h,v 1.23 2003/09/28 01:04:57 rocky Exp $ Copyright (C) 2001 Herbert Valerio Riedel Copyright (C) 2003 Rocky Bernstein @@ -131,8 +131,8 @@ extern "C" { char * cdio_get_default_device (const CdIo *obj); /*! - Return the media catalog number MCN from the CD or NULL if there is none or - we don't have the ability to get it. + Return the media catalog number (MCN) from the CD or NULL if there + is none or we don't have the ability to get it. Note: string is malloc'd so caller has to free() the returned string when done with it. diff --git a/lib/_cdio_bincue.c b/lib/_cdio_bincue.c index 5b30635f..5d81d452 100644 --- a/lib/_cdio_bincue.c +++ b/lib/_cdio_bincue.c @@ -1,5 +1,5 @@ /* - $Id: _cdio_bincue.c,v 1.31 2003/09/27 23:29:29 rocky Exp $ + $Id: _cdio_bincue.c,v 1.32 2003/09/28 01:04:58 rocky Exp $ Copyright (C) 2001 Herbert Valerio Riedel Copyright (C) 2002,2003 Rocky Bernstein @@ -24,7 +24,7 @@ (*.cue). */ -static const char _rcsid[] = "$Id: _cdio_bincue.c,v 1.31 2003/09/27 23:29:29 rocky Exp $"; +static const char _rcsid[] = "$Id: _cdio_bincue.c,v 1.32 2003/09/28 01:04:58 rocky Exp $"; #include "cdio_assert.h" #include "cdio_private.h" @@ -88,6 +88,7 @@ typedef struct { bool sector_2336; /* Playstation (PSX) uses 2336-byte sectors */ char *cue_name; + char *mcn; /* Media catalog number. */ track_info_t tocent[100]; /* entry info for each track */ track_t total_tracks; /* number of tracks in image */ track_t first_track_num; /* track number of first track */ @@ -314,6 +315,8 @@ _cdio_image_read_cue (_img_private_t *_obj) _obj->total_tracks=0; _obj->first_track_num=1; + _obj->mcn=NULL; + while ((fgets(line, MAXLINE, fp)) != NULL) { char *s=NULL; char *p; @@ -326,6 +329,8 @@ _cdio_image_read_cue (_img_private_t *_obj) _obj->bin_file = s; */ /* printf("Found file name %s\n", s); */ + } else if (1==sscanf(p, "CATALOG %as", &s)) { + _obj->mcn = s; } else if (2==sscanf(p, "TRACK %d MODE2/%d", &track_num, &blocksize)) { track_info_t *this_track=&(_obj->tocent[_obj->total_tracks]); this_track->track_num = track_num; @@ -563,6 +568,15 @@ _cdio_read_mode2_sectors (void *env, void *data, uint32_t lsn, #define free_if_notnull(obj) \ if (NULL != obj) free(obj); +static void +_cdio_bincue_free (void *env) { + _img_private_t *_obj = env; + + if (NULL == _obj) return; + free_if_notnull(_obj->mcn); + cdio_generic_stream_free(_obj); +} + /*! Set the arg "key" with "value" in the source device. Currently "source" to set the source device in I/O operations @@ -650,6 +664,24 @@ _cdio_get_first_track_num(void *env) return _obj->first_track_num; } +/*! + Return the media catalog number (MCN) from the CD or NULL if there + is none or we don't have the ability to get it. + + Note: string is malloc'd so caller has to free() the returned + string when done with it. + */ +static char * +_cdio_get_mcn(void *env) +{ + _img_private_t *_obj = env; + + _cdio_init (_obj); + + if (NULL == _obj->mcn) return NULL; + return strdup(_obj->mcn); +} + /*! Return the number of tracks in the current medium. If no cuesheet is available, We fake it an just say there's @@ -819,11 +851,11 @@ cdio_open_common (_img_private_t **_data) { cdio_funcs _funcs = { .eject_media = cdio_generic_bogus_eject_media, - .free = cdio_generic_stream_free, + .free = _cdio_bincue_free, .get_arg = _cdio_get_arg, .get_default_device = cdio_get_default_device_bincue, .get_first_track_num= _cdio_get_first_track_num, - .get_mcn = NULL, + .get_mcn = _cdio_get_mcn, .get_num_tracks = _cdio_get_num_tracks, .get_track_format = _cdio_get_track_format, .get_track_green = _cdio_get_track_green, diff --git a/test/cdda.cue b/test/cdda.cue index c7396d94..982b1054 100644 --- a/test/cdda.cue +++ b/test/cdda.cue @@ -1,3 +1,4 @@ +CATALOG 0000010271955 FILE "BOING.BIN" BINARY TRACK 01 AUDIO INDEX 01 00:00:00 diff --git a/test/cdda.right b/test/cdda.right index 48d63b0a..8cec6de9 100644 --- a/test/cdda.right +++ b/test/cdda.right @@ -6,7 +6,7 @@ CD-ROM Track List (1 - 1) #: MSF LSN Type 1: 00:02:00 000000 audio 170: 00:06:02 000302 leadout -Media Catalog Number (MCN): not available +Media Catalog Number (MCN): 0000010271955 __________________________________ CD Analysis Report Audio CD, CDDB disc ID is 02000401