Pull out mmssff_to_lba routine and fix bug when in error reporting

when frame >= 100.

Add msf3_to_lba and use that where possible (win32_ioctl.c for
example).
This commit is contained in:
rocky
2004-07-10 01:21:19 +00:00
parent 9eea6087d7
commit b525effb95
5 changed files with 223 additions and 252 deletions

View File

@@ -1,5 +1,5 @@
/* /*
$Id: sector.h,v 1.14 2004/06/27 15:29:21 rocky Exp $ $Id: sector.h,v 1.15 2004/07/10 01:21:19 rocky Exp $
Copyright (C) 2000 Herbert Valerio Riedel <hvr@gnu.org> Copyright (C) 2000 Herbert Valerio Riedel <hvr@gnu.org>
Copyright (C) 2003, 2004 Rocky Bernstein <rocky@panix.com> Copyright (C) 2003, 2004 Rocky Bernstein <rocky@panix.com>
@@ -181,6 +181,7 @@ void cdio_lba_to_msf(lba_t lba, msf_t *msf);
/*! /*!
Convert an LSN into the corresponding LBA. Convert an LSN into the corresponding LBA.
CDIO_INVALID_LBA is returned if there is an error.
*/ */
lba_t cdio_lsn_to_lba (lsn_t lsn); lba_t cdio_lsn_to_lba (lsn_t lsn);
@@ -191,15 +192,30 @@ void cdio_lsn_to_msf (lsn_t lsn, msf_t *msf);
/*! /*!
Convert a MSF into the corresponding LBA. Convert a MSF into the corresponding LBA.
CDIO_INVALID_LBA is returned if there is an error.
*/ */
lba_t lba_t cdio_msf_to_lba (const msf_t *msf);
cdio_msf_to_lba (const msf_t *msf);
/*! /*!
Convert a MSF into the corresponding LSN. Convert a MSF into the corresponding LSN.
CDIO_INVALID_LSN is returned if there is an error.
*/ */
lsn_t lsn_t cdio_msf_to_lsn (const msf_t *msf);
cdio_msf_to_lsn (const msf_t *msf);
/*!
Convert a MSF - broken out as 3 integer components into the
corresponding LBA.
CDIO_INVALID_LBA is returned if there is an error.
*/
lba_t cdio_msf3_to_lba (unsigned int minutes, unsigned int seconds,
unsigned int frames);
/*!
Convert a string of the form MM:SS:FF into the corresponding LBA.
CDIO_INVALID_LBA is returned if there is an error.
*/
lba_t cdio_mmssff_to_lba (const char *psz_mmssff);
#ifdef __cplusplus #ifdef __cplusplus
} }

View File

@@ -1,5 +1,5 @@
/* /*
$Id: win32_ioctl.c,v 1.6 2004/06/28 16:02:07 rocky Exp $ $Id: win32_ioctl.c,v 1.7 2004/07/10 01:21:20 rocky Exp $
Copyright (C) 2004 Rocky Bernstein <rocky@panix.com> Copyright (C) 2004 Rocky Bernstein <rocky@panix.com>
@@ -26,7 +26,7 @@
# include "config.h" # include "config.h"
#endif #endif
static const char _rcsid[] = "$Id: win32_ioctl.c,v 1.6 2004/06/28 16:02:07 rocky Exp $"; static const char _rcsid[] = "$Id: win32_ioctl.c,v 1.7 2004/07/10 01:21:20 rocky Exp $";
#include <cdio/cdio.h> #include <cdio/cdio.h>
#include <cdio/sector.h> #include <cdio/sector.h>
@@ -352,10 +352,6 @@ init_win32ioctl (_img_private_t *env)
return false; return false;
} }
#define MSF_TO_LBA2(min, sec, frame) \
((int) frame + CDIO_CD_FRAMES_PER_SEC * (CDIO_CD_SECS_PER_MIN*min + sec) \
- CDIO_PREGAP_SECTORS )
/*! /*!
Read and cache the CD's Track Table of Contents and track info. Read and cache the CD's Track Table of Contents and track info.
Return true if successful or false if an error. Return true if successful or false if an error.
@@ -381,7 +377,7 @@ read_toc_win32ioctl (_img_private_t *env)
for( i = 0 ; i <= env->total_tracks ; i++ ) { for( i = 0 ; i <= env->total_tracks ; i++ ) {
env->tocent[ i ].start_lsn = MSF_TO_LBA2( env->tocent[ i ].start_lsn = cdio_msf3_to_lba(
cdrom_toc.TrackData[i].Address[1], cdrom_toc.TrackData[i].Address[1],
cdrom_toc.TrackData[i].Address[2], cdrom_toc.TrackData[i].Address[2],
cdrom_toc.TrackData[i].Address[3] ); cdrom_toc.TrackData[i].Address[3] );

View File

@@ -1,5 +1,5 @@
/* /*
$Id: bincue.c,v 1.28 2004/07/09 20:48:05 rocky Exp $ $Id: bincue.c,v 1.29 2004/07/10 01:21:20 rocky Exp $
Copyright (C) 2002, 2003, 2004 Rocky Bernstein <rocky@panix.com> Copyright (C) 2002, 2003, 2004 Rocky Bernstein <rocky@panix.com>
Copyright (C) 2001 Herbert Valerio Riedel <hvr@gnu.org> Copyright (C) 2001 Herbert Valerio Riedel <hvr@gnu.org>
@@ -26,7 +26,7 @@
(*.cue). (*.cue).
*/ */
static const char _rcsid[] = "$Id: bincue.c,v 1.28 2004/07/09 20:48:05 rocky Exp $"; static const char _rcsid[] = "$Id: bincue.c,v 1.29 2004/07/10 01:21:20 rocky Exp $";
#include "cdio_assert.h" #include "cdio_assert.h"
#include "cdio_private.h" #include "cdio_private.h"
@@ -327,83 +327,6 @@ _stat_size_bincue (void *user_data)
return size; return size;
} }
static lba_t
msf_msf_to_lba (int minutes, int seconds, int frames)
{
return ( (minutes * CDIO_CD_SECS_PER_MIN + seconds)
* CDIO_CD_FRAMES_PER_SEC + frames );
}
static lba_t
mmssff_to_lba (char *s)
{
int field;
long ret;
char c;
if (0 == strcmp (s, "0"))
return 0;
c = *s++;
if(c >= '0' && c <= '9')
field = (c - '0');
else
return CDIO_INVALID_LBA;
while(':' != (c = *s++)) {
if(c >= '0' && c <= '9')
field = field * 10 + (c - '0');
else
return CDIO_INVALID_LBA;
}
ret = msf_msf_to_lba (field, 0, 0);
c = *s++;
if(c >= '0' && c <= '9')
field = (c - '0');
else
return CDIO_INVALID_LBA;
if(':' != (c = *s++)) {
if(c >= '0' && c <= '9') {
field = field * 10 + (c - '0');
c = *s++;
if(c != ':')
return CDIO_INVALID_LBA;
}
else
return CDIO_INVALID_LBA;
}
if(field >= CDIO_CD_SECS_PER_MIN)
return CDIO_INVALID_LBA;
ret += msf_msf_to_lba (0, field, 0);
c = *s++;
if(c >= '0' && c <= '9')
field = (c - '0');
else
return CDIO_INVALID_LBA;
if('\0' != (c = *s++)) {
if(c >= '0' && c <= '9') {
field = field * 10 + (c - '0');
c = *s++;
}
else
return CDIO_INVALID_LBA;
}
if('\0' != c)
return CDIO_INVALID_LBA;
if(field >= CDIO_CD_FRAMES_PER_SEC)
return CDIO_INVALID_LBA;
ret += field;
return ret;
}
#define MAXLINE 4096 /* maximum line length + 1 */ #define MAXLINE 4096 /* maximum line length + 1 */
static bool static bool
@@ -412,7 +335,6 @@ parse_cuefile (_img_private_t *cd, const char *psz_cue_name)
FILE *fp; FILE *fp;
char psz_line[MAXLINE]; char psz_line[MAXLINE];
unsigned int i_line=0; unsigned int i_line=0;
int min,sec,frame;
int start_index; int start_index;
char *psz_keyword, *psz_field; char *psz_keyword, *psz_field;
cdio_log_level_t log_level = (NULL == cd) ? CDIO_LOG_INFO : CDIO_LOG_WARN; cdio_log_level_t log_level = (NULL == cd) ? CDIO_LOG_INFO : CDIO_LOG_WARN;
@@ -505,9 +427,10 @@ parse_cuefile (_img_private_t *cd, const char *psz_cue_name)
if (NULL != (psz_field = strtok (NULL, " \t\n\r"))) { if (NULL != (psz_field = strtok (NULL, " \t\n\r"))) {
if (1!=sscanf(psz_field, "%d", &i_track)) { if (1!=sscanf(psz_field, "%d", &i_track)) {
cdio_log(log_level, cdio_log(log_level,
"%s line %d after keyword TRACK - " "%s line %d after word TRACK:",
"expecting a track number",
psz_cue_name, i_line); psz_cue_name, i_line);
cdio_log(log_level,
"Expecting a track number, got %s", psz_field);
goto err_exit; goto err_exit;
} }
} }
@@ -604,7 +527,12 @@ parse_cuefile (_img_private_t *cd, const char *psz_cue_name)
this_track->endsize = CDIO_CD_SYNC_SIZE + CDIO_CD_ECC_SIZE; this_track->endsize = CDIO_CD_SYNC_SIZE + CDIO_CD_ECC_SIZE;
} }
} else { } else {
goto format_error; cdio_log(log_level,
"%s line %d after word TRACK:",
psz_cue_name, i_line);
cdio_log(log_level,
"Unknown track mode %s", psz_field);
goto err_exit;
} }
} else { } else {
goto format_error; goto format_error;
@@ -646,7 +574,17 @@ parse_cuefile (_img_private_t *cd, const char *psz_cue_name)
} else if (0 == strcmp ("PREGAP", psz_keyword)) { } else if (0 == strcmp ("PREGAP", psz_keyword)) {
if (0 <= i) { if (0 <= i) {
if (NULL != (psz_field = strtok (NULL, " \t\n\r"))) { if (NULL != (psz_field = strtok (NULL, " \t\n\r"))) {
if (cd) cd->tocent[i].pregap = mmssff_to_lba (psz_field); lba_t lba = cdio_lsn_to_lba(cdio_mmssff_to_lba (psz_field));
if (CDIO_INVALID_LBA == lba) {
cdio_log(log_level, "%s line %d: after word PREGAP:",
psz_cue_name, i_line);
cdio_log(log_level, "Invalid MSF string %s",
psz_field);
goto err_exit;
}
if (cd) {
cd->tocent[i].pregap = lba;
}
} else { } else {
goto format_error; goto format_error;
} if (NULL != (psz_field = strtok (NULL, " \t\n\r"))) { } if (NULL != (psz_field = strtok (NULL, " \t\n\r"))) {
@@ -662,38 +600,35 @@ parse_cuefile (_img_private_t *cd, const char *psz_cue_name)
if (NULL != (psz_field = strtok (NULL, " \t\n\r"))) if (NULL != (psz_field = strtok (NULL, " \t\n\r")))
if (1!=sscanf(psz_field, "%d", &start_index)) { if (1!=sscanf(psz_field, "%d", &start_index)) {
cdio_log(log_level, cdio_log(log_level,
"%s line %d after keyword INDEX - " "%s line %d after word INDEX:",
"expecting an index number",
psz_cue_name, i_line); psz_cue_name, i_line);
cdio_log(log_level,
"expecting an index number, got %s",
psz_field);
goto err_exit; goto err_exit;
} }
if (NULL != (psz_field = strtok (NULL, " \t\n\r"))) { if (NULL != (psz_field = strtok (NULL, " \t\n\r"))) {
#if FIXED_ME lba_t lba = cdio_mmssff_to_lba (psz_field);
if (cd) cd->tocent[i].indexes[cd->tocent[i].nindex++] = if (CDIO_INVALID_LBA == lba) {
mmssff_to_lba (psz_field); cdio_log(log_level, "%s line %d: after word INDEX:",
#else psz_cue_name, i_line);
if (3==sscanf(psz_field, "%d:%d:%d", &min, &sec, &frame)) { cdio_log(log_level, "Invalid MSF string %s",
psz_field);
goto err_exit;
}
if (cd) { if (cd) {
#if FIXED_ME
cd->tocent[i].indexes[cd->tocent[i].nindex++] = lba;
#else
track_info_t *this_track= track_info_t *this_track=
&(cd->tocent[cd->i_tracks - cd->i_first_track]); &(cd->tocent[cd->i_tracks - cd->i_first_track]);
/* FIXME! all of this is a big hack. If start_index
== 0, then this is the "last_cue" information. The
+2 below seconds is to adjust for the 150 pregap.
*/
if (start_index != 0) { if (start_index != 0) {
if (!b_first_index_for_track) { if (!b_first_index_for_track) {
this_track->start_index = start_index; lba += CDIO_PREGAP_SECTORS;
sec += 2; cdio_lba_to_msf(lba, &(this_track->start_msf));
if (sec >= 60) {
min++;
sec -= 60;
}
b_first_index_for_track = true; b_first_index_for_track = true;
this_track->start_msf.m = to_bcd8 (min); this_track->start_lba = lba;
this_track->start_msf.s = to_bcd8 (sec);
this_track->start_msf.f = to_bcd8 (frame);
this_track->start_lba = cdio_msf_to_lba(&this_track->start_msf);
} }
if (cd->i_tracks > 1) { if (cd->i_tracks > 1) {
@@ -727,12 +662,6 @@ parse_cuefile (_img_private_t *cd, const char *psz_cue_name)
this_track->num_indices++; this_track->num_indices++;
} }
} }
} else {
cdio_log (log_level,
"%s line %d: after keyword: %s - expecting MM:SS::FF",
psz_cue_name, i_line, psz_keyword);
goto err_exit;
}
#endif #endif
} else { } else {
goto format_error; goto format_error;
@@ -771,17 +700,17 @@ parse_cuefile (_img_private_t *cd, const char *psz_cue_name)
return true; return true;
format_error: format_error:
cdio_log(log_level, "%s line %d after keyword %s", cdio_log(log_level, "%s line %d after word %s",
psz_cue_name, i_line, psz_keyword); psz_cue_name, i_line, psz_keyword);
goto err_exit; goto err_exit;
in_global_section: in_global_section:
cdio_log(log_level, "%s line %d: keyword %s not allowed in global section", cdio_log(log_level, "%s line %d: word %s not allowed in global section",
psz_cue_name, i_line, psz_keyword); psz_cue_name, i_line, psz_keyword);
goto err_exit; goto err_exit;
not_in_global_section: not_in_global_section:
cdio_log(log_level, "%s line %d: keyword %s only allowed in global section", cdio_log(log_level, "%s line %d: word %s only allowed in global section",
psz_cue_name, i_line, psz_keyword); psz_cue_name, i_line, psz_keyword);
err_exit: err_exit:

View File

@@ -1,5 +1,5 @@
/* /*
$Id: cdrdao.c,v 1.14 2004/07/09 20:48:05 rocky Exp $ $Id: cdrdao.c,v 1.15 2004/07/10 01:21:20 rocky Exp $
Copyright (C) 2004 Rocky Bernstein <rocky@panix.com> Copyright (C) 2004 Rocky Bernstein <rocky@panix.com>
toc reading routine adapted from cuetools toc reading routine adapted from cuetools
@@ -29,7 +29,7 @@
# include "config.h" # include "config.h"
#endif #endif
static const char _rcsid[] = "$Id: cdrdao.c,v 1.14 2004/07/09 20:48:05 rocky Exp $"; static const char _rcsid[] = "$Id: cdrdao.c,v 1.15 2004/07/10 01:21:20 rocky Exp $";
#include "cdio_assert.h" #include "cdio_assert.h"
#include "cdio_private.h" #include "cdio_private.h"
@@ -124,83 +124,6 @@ static bool parse_tocfile (_img_private_t *cd, const char *toc_name);
#include "image_common.h" #include "image_common.h"
static lba_t
msf_to_lba (int minutes, int seconds, int frames)
{
return ((minutes * CDIO_CD_SECS_PER_MIN + seconds) * CDIO_CD_FRAMES_PER_SEC
+ frames);
}
static lba_t
msf_lba_from_mmssff (char *s)
{
int field;
lba_t ret;
char c;
if (0 == strcmp (s, "0"))
return 0;
c = *s++;
if(c >= '0' && c <= '9')
field = (c - '0');
else
return CDIO_INVALID_LBA;
while(':' != (c = *s++)) {
if(c >= '0' && c <= '9')
field = field * 10 + (c - '0');
else
return CDIO_INVALID_LBA;
}
ret = msf_to_lba (field, 0, 0);
c = *s++;
if(c >= '0' && c <= '9')
field = (c - '0');
else
return CDIO_INVALID_LBA;
if(':' != (c = *s++)) {
if(c >= '0' && c <= '9') {
field = field * 10 + (c - '0');
c = *s++;
if(c != ':')
return CDIO_INVALID_LBA;
}
else
return CDIO_INVALID_LBA;
}
if(field >= CDIO_CD_SECS_PER_MIN)
return CDIO_INVALID_LBA;
ret += msf_to_lba (0, field, 0);
c = *s++;
if (isdigit(c))
field = (c - '0');
else
return -1;
if('\0' != (c = *s++)) {
if (isdigit(c)) {
field = field * 10 + (c - '0');
c = *s++;
}
else
return CDIO_INVALID_LBA;
}
if('\0' != c)
return -1;
if(field >= CDIO_CD_FRAMES_PER_SEC)
return CDIO_INVALID_LBA;
ret += field;
return ret;
}
/*! /*!
Initialize image structures. Initialize image structures.
*/ */
@@ -632,7 +555,7 @@ parse_tocfile (_img_private_t *cd, const char *psz_toc_name)
} }
if (NULL != (psz_field = strtok (NULL, " \t\n\r"))) { if (NULL != (psz_field = strtok (NULL, " \t\n\r"))) {
lba_t lba = cdio_lsn_to_lba(msf_lba_from_mmssff (psz_field)); lba_t lba = cdio_lsn_to_lba(cdio_mmssff_to_lba (psz_field));
if (CDIO_INVALID_LBA == lba) { if (CDIO_INVALID_LBA == lba) {
cdio_log(log_level, "%s line %d: invalid MSF string %s", cdio_log(log_level, "%s line %d: invalid MSF string %s",
psz_toc_name, i_line, psz_field); psz_toc_name, i_line, psz_field);
@@ -646,7 +569,7 @@ parse_tocfile (_img_private_t *cd, const char *psz_toc_name)
} }
if (NULL != (psz_field = strtok (NULL, " \t\n\r"))) if (NULL != (psz_field = strtok (NULL, " \t\n\r")))
if (NULL != cd) if (NULL != cd)
cd->tocent[i].length = msf_lba_from_mmssff (psz_field); cd->tocent[i].length = cdio_mmssff_to_lba (psz_field);
if (NULL != (psz_field = strtok (NULL, " \t\n\r"))) { if (NULL != (psz_field = strtok (NULL, " \t\n\r"))) {
goto format_error; goto format_error;
} }
@@ -668,7 +591,7 @@ parse_tocfile (_img_private_t *cd, const char *psz_toc_name)
if (NULL != (psz_field = strtok (NULL, " \t\n\r"))) { if (NULL != (psz_field = strtok (NULL, " \t\n\r"))) {
/* todo: line is too long! */ /* todo: line is too long! */
if (NULL != cd) { if (NULL != cd) {
cd->tocent[i].start_lba += msf_lba_from_mmssff (psz_field); cd->tocent[i].start_lba += cdio_mmssff_to_lba (psz_field);
cdio_lba_to_msf(cd->tocent[i].start_lba, cdio_lba_to_msf(cd->tocent[i].start_lba,
&(cd->tocent[i].start_msf)); &(cd->tocent[i].start_msf));
} }
@@ -686,7 +609,7 @@ parse_tocfile (_img_private_t *cd, const char *psz_toc_name)
if (0 <= i) { if (0 <= i) {
if (NULL != (psz_field = strtok (NULL, " \t\n\r"))) { if (NULL != (psz_field = strtok (NULL, " \t\n\r"))) {
if (NULL != cd) if (NULL != cd)
cd->tocent[i].pregap = msf_lba_from_mmssff (psz_field); cd->tocent[i].pregap = cdio_mmssff_to_lba (psz_field);
} else { } else {
goto format_error; goto format_error;
} }
@@ -708,7 +631,7 @@ parse_tocfile (_img_private_t *cd, const char *psz_toc_name)
cd->tocent[i].nindex++; cd->tocent[i].nindex++;
} }
cd->tocent[i].indexes[cd->tocent[i].nindex++] = cd->tocent[i].indexes[cd->tocent[i].nindex++] =
msf_lba_from_mmssff (psz_field) + cd->tocent[i].indexes[0]; cdio_mmssff_to_lba (psz_field) + cd->tocent[i].indexes[0];
#else #else
; ;

View File

@@ -1,5 +1,5 @@
/* /*
$Id: sector.c,v 1.11 2004/06/12 17:32:00 rocky Exp $ $Id: sector.c,v 1.12 2004/07/10 01:21:19 rocky Exp $
Copyright (C) 2004 Rocky Bernstein <rocky@panix.com> Copyright (C) 2004 Rocky Bernstein <rocky@panix.com>
Copyright (C) 2000 Herbert Valerio Riedel <hvr@gnu.org> Copyright (C) 2000 Herbert Valerio Riedel <hvr@gnu.org>
@@ -33,8 +33,9 @@
#include <string.h> #include <string.h>
#endif #endif
#include <ctype.h>
static const char _rcsid[] = "$Id: sector.c,v 1.11 2004/06/12 17:32:00 rocky Exp $"; static const char _rcsid[] = "$Id: sector.c,v 1.12 2004/07/10 01:21:19 rocky Exp $";
lba_t lba_t
cdio_lba_to_lsn (lba_t lba) cdio_lba_to_lsn (lba_t lba)
@@ -79,7 +80,9 @@ cdio_lsn_to_msf (lsn_t lsn, msf_t *msf)
msf->f = to_bcd8 (f); msf->f = to_bcd8 (f);
} }
/* warning, returns new allocated string */ /*!
Convert an LBA into a string representation of the MSF.
\warning cdio_lba_to_msf_str returns new allocated string */
char * char *
cdio_lba_to_msf_str (lba_t lba) cdio_lba_to_msf_str (lba_t lba)
{ {
@@ -93,6 +96,10 @@ cdio_lba_to_msf_str (lba_t lba)
} }
} }
/*!
Convert an LSN into the corresponding LBA.
CDIO_INVALID_LBA is returned if there is an error.
*/
lba_t lba_t
cdio_lsn_to_lba (lsn_t lsn) cdio_lsn_to_lba (lsn_t lsn)
{ {
@@ -100,6 +107,9 @@ cdio_lsn_to_lba (lsn_t lsn)
return lsn + CDIO_PREGAP_SECTORS; return lsn + CDIO_PREGAP_SECTORS;
} }
/*!
Convert an LBA into the corresponding MSF.
*/
void void
cdio_lba_to_msf (lba_t lba, msf_t *msf) cdio_lba_to_msf (lba_t lba, msf_t *msf)
{ {
@@ -107,6 +117,10 @@ cdio_lba_to_msf (lba_t lba, msf_t *msf)
cdio_lsn_to_msf(cdio_lba_to_lsn(lba), msf); cdio_lsn_to_msf(cdio_lba_to_lsn(lba), msf);
} }
/*!
Convert a MSF into the corresponding LBA.
CDIO_INVALID_LBA is returned if there is an error.
*/
lba_t lba_t
cdio_msf_to_lba (const msf_t *msf) cdio_msf_to_lba (const msf_t *msf)
{ {
@@ -125,13 +139,19 @@ cdio_msf_to_lba (const msf_t *msf)
return lba; return lba;
} }
/*!
Convert a MSF into the corresponding LSN.
CDIO_INVALID_LSN is returned if there is an error.
*/
lba_t lba_t
cdio_msf_to_lsn (const msf_t *msf) cdio_msf_to_lsn (const msf_t *msf)
{ {
return cdio_lba_to_lsn(cdio_msf_to_lba (msf)); return cdio_lba_to_lsn(cdio_msf_to_lba (msf));
} }
/* warning, returns new allocated string */ /*!
Convert an LBA into a string representation of the MSF.
\warning cdio_lba_to_msf_str returns new allocated string */
char * char *
cdio_msf_to_str (const msf_t *msf) cdio_msf_to_str (const msf_t *msf)
{ {
@@ -141,6 +161,93 @@ cdio_msf_to_str (const msf_t *msf)
return strdup (buf); return strdup (buf);
} }
/*!
Convert a MSF - broken out as 3 integer components into the
corresponding LBA.
CDIO_INVALID_LBA is returned if there is an error.
*/
lba_t
cdio_msf3_to_lba (unsigned int minutes, unsigned int seconds,
unsigned int frames)
{
return ((minutes * CDIO_CD_SECS_PER_MIN + seconds) * CDIO_CD_FRAMES_PER_SEC
+ frames);
}
/*!
Convert a string of the form MM:SS:FF into the corresponding LBA.
CDIO_INVALID_LBA is returned if there is an error.
*/
lba_t
cdio_mmssff_to_lba (const char *psz_mmssff)
{
int psz_field;
lba_t ret;
char c;
if (0 == strcmp (psz_mmssff, "0"))
return 0;
c = *psz_mmssff++;
if(c >= '0' && c <= '9')
psz_field = (c - '0');
else
return CDIO_INVALID_LBA;
while(':' != (c = *psz_mmssff++)) {
if(c >= '0' && c <= '9')
psz_field = psz_field * 10 + (c - '0');
else
return CDIO_INVALID_LBA;
}
ret = cdio_msf3_to_lba (psz_field, 0, 0);
c = *psz_mmssff++;
if(c >= '0' && c <= '9')
psz_field = (c - '0');
else
return CDIO_INVALID_LBA;
if(':' != (c = *psz_mmssff++)) {
if(c >= '0' && c <= '9') {
psz_field = psz_field * 10 + (c - '0');
c = *psz_mmssff++;
if(c != ':')
return CDIO_INVALID_LBA;
}
else
return CDIO_INVALID_LBA;
}
if(psz_field >= CDIO_CD_SECS_PER_MIN)
return CDIO_INVALID_LBA;
ret += cdio_msf3_to_lba (0, psz_field, 0);
c = *psz_mmssff++;
if (isdigit(c))
psz_field = (c - '0');
else
return -1;
if('\0' != (c = *psz_mmssff++)) {
if (isdigit(c)) {
psz_field = psz_field * 10 + (c - '0');
c = *psz_mmssff++;
}
else
return CDIO_INVALID_LBA;
}
if('\0' != c)
return CDIO_INVALID_LBA;
if(psz_field >= CDIO_CD_FRAMES_PER_SEC)
return CDIO_INVALID_LBA;
ret += psz_field;
return ret;
}
/* /*
* Local variables: * Local variables: