cdriso: improve .toc handling yet more

git-svn-id: https://pcsxr.svn.codeplex.com/svn/pcsxr@82225 e17a0e51-4ae3-4d35-97c3-1a29b211df97
This commit is contained in:
SND\notaz_cp 2013-01-12 21:07:44 +00:00
parent c288a602fc
commit 085ec60fd4

View File

@ -141,10 +141,11 @@ static void tok2msf(char *time, char *msf) {
static int parsetoc(const char *isofile) {
char tocname[MAXPATHLEN];
FILE *fi;
char linebuf[256], dummy[256], name[256];
char linebuf[256], tmp[256], name[256];
char *token;
char time[20], time2[20];
unsigned int t, sector_offs, sector_size;
unsigned int current_zero_gap = 0;
numtracks = 0;
@ -186,12 +187,15 @@ static int parsetoc(const char *isofile) {
// parse the .toc file
while (fgets(linebuf, sizeof(linebuf), fi) != NULL) {
// search for tracks
strncpy(dummy, linebuf, sizeof(linebuf));
token = strtok(dummy, " ");
strncpy(tmp, linebuf, sizeof(linebuf));
token = strtok(tmp, " ");
if (token == NULL) continue;
if (!strcmp(token, "TRACK")) {
sector_offs += current_zero_gap;
current_zero_gap = 0;
// get type of track
token = strtok(NULL, " ");
numtracks++;
@ -202,10 +206,11 @@ static int parsetoc(const char *isofile) {
// check if this image contains mixed subchannel data
token = strtok(NULL, " ");
if (token != NULL && !strncmp(token, "RW_RAW", 6)) {
subChanMixed = TRUE;
subChanRaw = TRUE;
if (token != NULL && !strncmp(token, "RW", 2)) {
sector_size = CD_FRAMESIZE_RAW + SUB_FRAMESIZE;
subChanMixed = TRUE;
if (!strncmp(token, "RW_RAW", 6))
subChanRaw = TRUE;
}
}
else if (!strncmp(token, "AUDIO", 5)) {
@ -234,16 +239,33 @@ static int parsetoc(const char *isofile) {
sec2msf(t, (char *)&ti[numtracks].start);
tok2msf((char *)&time2, (char *)&ti[numtracks].length);
}
else if (!strcmp(token, "ZERO")) {
sscanf(linebuf, "ZERO AUDIO RW_RAW %8s", time);
tok2msf((char *)&time, dummy);
sector_offs += msf2sec(dummy);
else if (!strcmp(token, "ZERO") || !strcmp(token, "SILENCE")) {
// skip unneeded optional fields
while (token != NULL) {
token = strtok(NULL, " ");
if (strchr(token, ':') != NULL)
break;
}
if (token != NULL) {
tok2msf(token, tmp);
current_zero_gap = msf2sec(tmp);
}
if (numtracks > 1) {
t = ti[numtracks - 1].start_offset;
t /= sector_size;
pregapOffset = t + msf2sec(ti[numtracks - 1].length);
}
}
else if (!strcmp(token, "START")) {
token = strtok(NULL, " ");
if (token != NULL && strchr(token, ':')) {
tok2msf(token, tmp);
t = msf2sec(tmp);
ti[numtracks].start_offset += (t - current_zero_gap) * sector_size;
t = msf2sec(ti[numtracks].start) + t;
sec2msf(t, (char *)&ti[numtracks].start);
}
}
}
fclose(fi);