From 9f3b4b6128bd32720188b81c1afdb7d116bc54ef Mon Sep 17 00:00:00 2001 From: Eugene Sandulenko Date: Sun, 17 Sep 2023 01:39:21 +0200 Subject: [PATCH] COMMON: Parsing FILE token in CueSheets --- common/formats/cue.cpp | 44 ++++++++++++++++++++++++++++++++++++++++++ common/formats/cue.h | 21 +++++++++++++++++--- 2 files changed, 62 insertions(+), 3 deletions(-) diff --git a/common/formats/cue.cpp b/common/formats/cue.cpp index 58a5ee4c26e..6302f61ff09 100644 --- a/common/formats/cue.cpp +++ b/common/formats/cue.cpp @@ -19,6 +19,7 @@ * */ +#include "common/str.h" #include "common/formats/cue.h" namespace Common { @@ -106,7 +107,50 @@ CueSheet::CueSheet(const char *sheet) { } } +struct LookupTable { + const char *key; + int value; +}; + +static int lookupInTable(LookupTable *table, const char *key) { + while (table->key) { + if (!strcmp(key, table->key)) + return table->value; + + table++; + } + + error("CueSheet::lookupInTable(): Unknown token %s", key); +} + +LookupTable fileTypes[] = { + { "BINARY", CueSheet::kCueFileTypeBinary }, + { "AIFF", CueSheet::kCueFileTypeAIFF }, + { "WAVE", CueSheet::kCueFileTypeWave }, + { "MP3", CueSheet::kCueFileTypeMP3 }, + { "MOTOROLA", CueSheet::kCueFileTypeMotorola }, + { 0, 0 } +}; + void CueSheet::parseHeaderContext(const char *line) { + const char *s = line; + + String command = nexttok(s, &s); + + if (command == "FILE") { + _files.push_back(CueFile()); + + _currentFile++; + + _files[_currentFile].name = nexttok(s, &s); + + String type = nexttok(s, &s); + + _files[_currentFile].type = kCueFileTypeBinary; + _files[_currentFile].type = (CueFileType)lookupInTable(fileTypes, type.c_str()); + + _context = kCueContextFiles; + } } void CueSheet::parseFilesContext(const char *line) { diff --git a/common/formats/cue.h b/common/formats/cue.h index 5aae53d995d..85af559162a 100644 --- a/common/formats/cue.h +++ b/common/formats/cue.h @@ -22,9 +22,7 @@ #ifndef COMMON_FORMATS_CUE_H #define COMMON_FORMATS_CUE_H -#include "common/hash-str.h" -#include "common/str.h" -#include "common/types.h" +#include "common/array.h" namespace Common { @@ -37,6 +35,20 @@ class CueSheet { public: CueSheet(const char *sheet); +public: + enum CueFileType { + kCueFileTypeBinary, + kCueFileTypeAIFF, + kCueFileTypeWave, + kCueFileTypeMP3, + kCueFileTypeMotorola, + }; + + struct CueFile { + String name; + CueFileType type = kCueFileTypeBinary; + }; + private: void parseHeaderContext(const char *line); void parseFilesContext(const char *line); @@ -44,6 +56,9 @@ private: private: int _context; + int _currentFile = -1; + + Common::Array _files; }; } // End of namespace Common