diff options
Diffstat (limited to 'apps/cuesheet.c')
-rw-r--r-- | apps/cuesheet.c | 51 |
1 files changed, 51 insertions, 0 deletions
diff --git a/apps/cuesheet.c b/apps/cuesheet.c index a9180a70d4..57c588ee9a 100644 --- a/apps/cuesheet.c +++ b/apps/cuesheet.c | |||
@@ -118,6 +118,53 @@ static char *get_string(const char *line) | |||
118 | return start; | 118 | return start; |
119 | } | 119 | } |
120 | 120 | ||
121 | static unsigned long parse_cue_index(const char *line) | ||
122 | { | ||
123 | /* assumes strncmp(line, "INDEX 01", 8) & NULL terminated string */ | ||
124 | /* INDEX 01 MM:SS:FF\0 (00:00:00\0 - 99:99:99\0)*/ | ||
125 | const unsigned field_m[3] = {60 * 1000, 1000, 13}; /* MM:SS:~FF*/ | ||
126 | const char f_sep = ':'; | ||
127 | int field = -1; | ||
128 | unsigned long offset = 0; /* ms from start of track */ | ||
129 | unsigned long value = 0; | ||
130 | while (*line) | ||
131 | { | ||
132 | if (!isdigit(*line)) /* search for numbers */ | ||
133 | { | ||
134 | line++; | ||
135 | continue; | ||
136 | } | ||
137 | |||
138 | while (isdigit(*line)) | ||
139 | { | ||
140 | value = 10 * value + (*line - '0'); | ||
141 | if (value > 99) /* Sanity check bail early */ | ||
142 | return 0; | ||
143 | line++; | ||
144 | } | ||
145 | |||
146 | if (field < 0) /*Filter INDEX 01*/ | ||
147 | { | ||
148 | /* safe to assume value == 1 */ | ||
149 | } | ||
150 | else if (field <= 2) | ||
151 | { | ||
152 | while(*line && *line != f_sep) | ||
153 | line++; | ||
154 | |||
155 | if (*line || field == 2) /* if *line valid we found f_sep */ | ||
156 | offset += (unsigned long) field_m[field] * value; | ||
157 | } | ||
158 | else | ||
159 | break; | ||
160 | |||
161 | value = 0; | ||
162 | field++; | ||
163 | } | ||
164 | |||
165 | return offset; | ||
166 | } | ||
167 | |||
121 | /* parse cuesheet "cue_file" and store the information in "cue" */ | 168 | /* parse cuesheet "cue_file" and store the information in "cue" */ |
122 | bool parse_cuesheet(struct cuesheet_file *cue_file, struct cuesheet *cue) | 169 | bool parse_cuesheet(struct cuesheet_file *cue_file, struct cuesheet *cue) |
123 | { | 170 | { |
@@ -204,6 +251,7 @@ bool parse_cuesheet(struct cuesheet_file *cue_file, struct cuesheet *cue) | |||
204 | } | 251 | } |
205 | else if (!strncmp(s, "INDEX 01", 8)) | 252 | else if (!strncmp(s, "INDEX 01", 8)) |
206 | { | 253 | { |
254 | #if 0 | ||
207 | s = strchr(s,' '); | 255 | s = strchr(s,' '); |
208 | s = skip_whitespace(s); | 256 | s = skip_whitespace(s); |
209 | s = strchr(s,' '); | 257 | s = strchr(s,' '); |
@@ -213,6 +261,9 @@ bool parse_cuesheet(struct cuesheet_file *cue_file, struct cuesheet *cue) | |||
213 | cue->tracks[cue->track_count-1].offset += 1000 * atoi(s); | 261 | cue->tracks[cue->track_count-1].offset += 1000 * atoi(s); |
214 | s = strchr(s,':') + 1; | 262 | s = strchr(s,':') + 1; |
215 | cue->tracks[cue->track_count-1].offset += 13 * atoi(s); | 263 | cue->tracks[cue->track_count-1].offset += 13 * atoi(s); |
264 | #else | ||
265 | cue->tracks[cue->track_count-1].offset = parse_cue_index(s); | ||
266 | #endif | ||
216 | } | 267 | } |
217 | else if (!strncmp(s, "TITLE", 5) | 268 | else if (!strncmp(s, "TITLE", 5) |
218 | || !strncmp(s, "PERFORMER", 9) | 269 | || !strncmp(s, "PERFORMER", 9) |