X-Git-Url: https://notaz.gp2x.de/cgi-bin/gitweb.cgi?a=blobdiff_plain;f=Pico%2Fcd%2Fcue.c;h=9d0b498016cbde4903a3cf9d9f424db25e3f6d04;hb=6a13ef3f56a80ac698d463f5d00235ea2a090f52;hp=3380b0e98d7276b2ac47000b21b4d79297b0684a;hpb=9037e45d9f2752fdd6ebbc01328148839403a84f;p=picodrive.git diff --git a/Pico/cd/cue.c b/Pico/cd/cue.c index 3380b0e..9d0b498 100644 --- a/Pico/cd/cue.c +++ b/Pico/cd/cue.c @@ -6,6 +6,13 @@ #include "../PicoInt.h" // #define elprintf(w,f,...) printf(f "\n",##__VA_ARGS__); +#ifdef _MSC_VER +#define snprintf _snprintf +#endif +#ifdef __EPOC32__ +#define snprintf(b,s,...) sprintf(b,##__VA_ARGS__) +#endif + static char *mystrip(char *str) { int i, len; @@ -60,17 +67,24 @@ static char *get_ext(char *fname) /* note: tracks[0] is not used */ cue_data_t *cue_parse(const char *fname) { - char buff[256], current_file[256], buff2[32]; + char buff[256], current_file[256], buff2[32], *current_filep; FILE *f, *tmpf; - int ret, count = 0, count_alloc = 2; + int ret, count = 0, count_alloc = 2, pending_pregap = 0; cue_data_t *data; void *tmp; f = fopen(fname, "r"); if (f == NULL) return NULL; - current_file[0] = 0; + snprintf(current_file, sizeof(current_file), "%s", fname); + for (current_filep = current_file + strlen(current_file); current_filep > current_file; current_filep--) + if (current_filep[-1] == '/' || current_filep[-1] == '\\') break; + data = calloc(1, sizeof(*data) + count_alloc * sizeof(cue_track)); + if (data == NULL) { + fclose(f); + return NULL; + } while (!feof(f)) { @@ -79,11 +93,11 @@ cue_data_t *cue_parse(const char *fname) mystrip(buff); if (buff[0] == 0) continue; - if (BEGINS(buff, "TITLE ") || BEGINS(buff, "PERFORMER ")) + if (BEGINS(buff, "TITLE ") || BEGINS(buff, "PERFORMER ") || BEGINS(buff, "SONGWRITER ")) continue; /* who would put those here? Ignore! */ else if (BEGINS(buff, "FILE ")) { - get_token(buff+5, current_file, sizeof(current_file)); + get_token(buff+5, current_filep, sizeof(current_file) - (current_filep - current_file)); } else if (BEGINS(buff, "TRACK ")) { @@ -107,6 +121,8 @@ cue_data_t *cue_parse(const char *fname) } fclose(tmpf); } + data->tracks[count].pregap = pending_pregap; + pending_pregap = 0; // track number ret = get_token(buff+6, buff2, sizeof(buff2)); if (count != atoi(buff2)) @@ -172,7 +188,7 @@ cue_data_t *cue_parse(const char *fname) data->tracks[count].fname = strdup(current_file); } } - else if (BEGINS(buff, "PREGAP ")) + else if (BEGINS(buff, "PREGAP ") || BEGINS(buff, "POSTGAP ")) { int m, s, f; get_token(buff+7, buff2, sizeof(buff2)); @@ -181,8 +197,23 @@ cue_data_t *cue_parse(const char *fname) elprintf(EL_STATUS, "cue: failed to parse: \"%s\"", buff); continue; } - data->tracks[count].pregap = m*60*75 + s*75 + f; + // pregap overrides previous postgap? + // by looking at some .cues produced by some programs I've decided that.. + if (BEGINS(buff, "PREGAP ")) + data->tracks[count].pregap = m*60*75 + s*75 + f; + else + pending_pregap = m*60*75 + s*75 + f; + } + else if (BEGINS(buff, "REM LENGTH ")) // custom "extension" + { + int m, s, f; + get_token(buff+11, buff2, sizeof(buff2)); + ret = sscanf(buff2, "%d:%d:%d", &m, &s, &f); + if (ret != 3) continue; + data->tracks[count].sector_xlength = m*60*75 + s*75 + f; } + else if (BEGINS(buff, "REM")) + continue; else { elprintf(EL_STATUS, "cue: unhandled line: \"%s\"", buff);