summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--apps/cuesheet.c67
1 files changed, 56 insertions, 11 deletions
diff --git a/apps/cuesheet.c b/apps/cuesheet.c
index be89ef96cf..ec917ce6a9 100644
--- a/apps/cuesheet.c
+++ b/apps/cuesheet.c
@@ -165,6 +165,38 @@ static unsigned long parse_cue_index(const char *line)
165 return offset; 165 return offset;
166} 166}
167 167
168enum eCS_SUPPORTED_TAGS {
169 eCS_TRACK = 0, eCS_INDEX_01, eCS_TITLE,
170 eCS_PERFORMER, eCS_SONGWRITER, eCS_FILE,
171 eCS_COUNT_TAGS_COUNT, eCS_NOTFOUND = -1
172};
173
174static enum eCS_SUPPORTED_TAGS cuesheet_tag_get_option(const char *option)
175{
176 #define CS_OPTN(str) {str, sizeof(str)-1}
177 static const struct cs_option_t {
178 const char *str;
179 const int len;
180 } cs_options[eCS_COUNT_TAGS_COUNT + 1] = {
181 [eCS_TRACK] = CS_OPTN("TRACK"),
182 [eCS_INDEX_01] = CS_OPTN("INDEX_01"),
183 [eCS_TITLE] =CS_OPTN("TITLE"),
184 [eCS_PERFORMER] =CS_OPTN("PERFORMER"),
185 [eCS_SONGWRITER] =CS_OPTN("SONGWRITER"),
186 [eCS_FILE] =CS_OPTN("FILE"),
187 [eCS_COUNT_TAGS_COUNT] = {NULL, 0} /*SENTINEL*/
188 };
189
190 const struct cs_option_t *op;
191 for (int i=0; ((op=&cs_options[i]))->str != NULL; i++)
192 {
193 if (strncmp(option, op->str, op->len) == 0)
194 return i;
195 }
196 return eCS_NOTFOUND;
197#undef CS_OPTN
198}
199
168/* parse cuesheet "cue_file" and store the information in "cue" */ 200/* parse cuesheet "cue_file" and store the information in "cue" */
169bool parse_cuesheet(struct cuesheet_file *cue_file, struct cuesheet *cue) 201bool parse_cuesheet(struct cuesheet_file *cue_file, struct cuesheet *cue)
170{ 202{
@@ -245,11 +277,16 @@ bool parse_cuesheet(struct cuesheet_file *cue_file, struct cuesheet *cue)
245 } 277 }
246 s = skip_whitespace(line); 278 s = skip_whitespace(line);
247 279
248 if (!strncmp(s, "TRACK", 5)) 280/* RECOGNIZED TAGS ***********************
281* eCS_TRACK = 0, eCS_INDEX_01, eCS_TITLE,
282* eCS_PERFORMER, eCS_SONGWRITER, eCS_FILE,
283*/
284 enum eCS_SUPPORTED_TAGS option = cuesheet_tag_get_option(s);
285 if (option == eCS_TRACK)
249 { 286 {
250 cue->track_count++; 287 cue->track_count++;
251 } 288 }
252 else if (!strncmp(s, "INDEX 01", 8)) 289 else if (option == eCS_INDEX_01)
253 { 290 {
254#if 0 291#if 0
255 s = strchr(s,' '); 292 s = strchr(s,' ');
@@ -265,10 +302,7 @@ bool parse_cuesheet(struct cuesheet_file *cue_file, struct cuesheet *cue)
265 cue->tracks[cue->track_count-1].offset = parse_cue_index(s); 302 cue->tracks[cue->track_count-1].offset = parse_cue_index(s);
266#endif 303#endif
267 } 304 }
268 else if (!strncmp(s, "TITLE", 5) 305 else if (option != eCS_NOTFOUND)
269 || !strncmp(s, "PERFORMER", 9)
270 || !strncmp(s, "SONGWRITER", 10)
271 || !strncmp(s, "FILE", 4))
272 { 306 {
273 char *dest = NULL; 307 char *dest = NULL;
274 char *string = get_string(s); 308 char *string = get_string(s);
@@ -278,24 +312,24 @@ bool parse_cuesheet(struct cuesheet_file *cue_file, struct cuesheet *cue)
278 size_t count = MAX_NAME*3 + 1; 312 size_t count = MAX_NAME*3 + 1;
279 size_t count8859 = MAX_NAME; 313 size_t count8859 = MAX_NAME;
280 314
281 switch (*s) 315 switch (option)
282 { 316 {
283 case 'T': /* TITLE */ 317 case eCS_TITLE: /* TITLE */
284 dest = (cue->track_count <= 0) ? cue->title : 318 dest = (cue->track_count <= 0) ? cue->title :
285 cue->tracks[cue->track_count-1].title; 319 cue->tracks[cue->track_count-1].title;
286 break; 320 break;
287 321
288 case 'P': /* PERFORMER */ 322 case eCS_PERFORMER: /* PERFORMER */
289 dest = (cue->track_count <= 0) ? cue->performer : 323 dest = (cue->track_count <= 0) ? cue->performer :
290 cue->tracks[cue->track_count-1].performer; 324 cue->tracks[cue->track_count-1].performer;
291 break; 325 break;
292 326
293 case 'S': /* SONGWRITER */ 327 case eCS_SONGWRITER: /* SONGWRITER */
294 dest = (cue->track_count <= 0) ? cue->songwriter : 328 dest = (cue->track_count <= 0) ? cue->songwriter :
295 cue->tracks[cue->track_count-1].songwriter; 329 cue->tracks[cue->track_count-1].songwriter;
296 break; 330 break;
297 331
298 case 'F': /* FILE */ 332 case eCS_FILE: /* FILE */
299 if (is_embedded || cue->track_count > 0) 333 if (is_embedded || cue->track_count > 0)
300 break; 334 break;
301 335
@@ -303,6 +337,16 @@ bool parse_cuesheet(struct cuesheet_file *cue_file, struct cuesheet *cue)
303 count = MAX_PATH; 337 count = MAX_PATH;
304 count8859 = MAX_PATH/3; 338 count8859 = MAX_PATH/3;
305 break; 339 break;
340 case eCS_TRACK:
341 /*Fall-Through*/
342 case eCS_INDEX_01:
343 /*Fall-Through*/
344 case eCS_COUNT_TAGS_COUNT:
345 /*Fall-Through*/
346 case eCS_NOTFOUND: /*Shouldn't happen*/
347 logf(HZ * 2, "Bad Tag %d @ %s", (int) option, __func__);
348 dest = NULL;
349 break;
306 } 350 }
307 351
308 if (dest) 352 if (dest)
@@ -319,6 +363,7 @@ bool parse_cuesheet(struct cuesheet_file *cue_file, struct cuesheet *cue)
319 } 363 }
320 } 364 }
321 } 365 }
366
322 if (is_embedded) 367 if (is_embedded)
323 { 368 {
324 bytes_left -= line_len; 369 bytes_left -= line_len;