COMMON: Parsing FILE token in CueSheets

This commit is contained in:
Eugene Sandulenko 2023-09-17 01:39:21 +02:00
parent 5284c8d7a0
commit 9f3b4b6128
2 changed files with 62 additions and 3 deletions

View File

@ -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) {

View File

@ -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<CueFile> _files;
};
} // End of namespace Common