shithub: cuefs

Download patch

ref: a7ed62f0c1bdc685b8d23da6722ba0a9d3716b78
parent: 8c159e9284fd9079b4ef08e3911baf3901f43a5a
author: Tevo <estevan.cps@gmail.com>
date: Sat Feb 13 20:16:37 EST 2021

Handle CATALOG properly

--- a/BUGS
+++ b/BUGS
@@ -3,6 +3,7 @@
 • everything will get resampled to 44100Hz/16bit/2channel
 • the codebase is a mess
 • reading concurrently from the same fid might break decoding logic, or be unecessarily slow (does that ever happen?)
+• the parser might be leaking memory (it strdup()s the strings before passing to yacc, but we strdup() some of them again when setting the sheet fields)
 • zuke with wav keeps requesting the file header at offsets 0, 4 and 8; never starts playing
 • some parser/cuefs behavior might be non-standard or undesirable
 	- for example, there's currently no way to split tracks without including the pregap either at the end of the last track or beggining of current one
--- a/cue.c
+++ b/cue.c
@@ -80,6 +80,7 @@
 
 	free(s->title);
 	free(s->performer);
+	free(s->mcn);
 
 	free(s);
 }
@@ -145,6 +146,12 @@
 		free(c->curentry->title);
 		c->curentry->title = title;
 	}
+}
+
+void
+setmcn(Cuesheet *c, char *mcn)
+{
+	c->mcn = mcn;
 }
 
 void
--- a/cue.l
+++ b/cue.l
@@ -4,6 +4,7 @@
 
 %}
 
+%s MCNNO
 %%
 \".*\"			{
 					yylval.str = strdup(yytext+1);
@@ -16,12 +17,21 @@
 					return STRING;
 				}
 
+<MCNNO>[0-9]+ 	{ 
+					int len = strlen(yytext);
+					if(len > 13)
+						parserfatal("UPC/EAN code cannot be larger than 13 characters");
+					yylval.str = strdup(yytext); 
+					BEGIN(INITIAL);
+					return MCN; 
+				}
+
 [0-9]+			{
 					yylval.i = atoi(yytext);
 					return INTEGER;
 				}
 
-"CATALOG"		return CATALOG;
+"CATALOG"		{ BEGIN(MCNNO); return CATALOG; }
 "CDTEXTFILE"	return CDTEXTFILE;
 "FILE"			return FILE;
 "FLAGS"			return FLAGS;
--- a/cue.y
+++ b/cue.y
@@ -18,7 +18,7 @@
 }
 
 %token <i>   INTEGER
-%token <str> STRING
+%token <str> STRING MCN
 
 %type <i>    filetype
 %type <time> timestamp
@@ -25,7 +25,7 @@
 
 %token CATALOG CDTEXTFILE FLAGS DCP CHAN4 PREEMPH SCMS INDEX
 %token ISRC PERFORMER POSTGAP PREGAP SONGWRITER TITLE TRACK
-%token FILE FWAVE FMP3 FAIFF FBINARY FMOTOROLA AUDIO
+%token FILE FWAVE FMP3 FAIFF FBINARY FMOTOROLA AUDIO MCN
 
 %%
 cuesheet:
@@ -38,6 +38,7 @@
 	| FILE STRING filetype		{ addfile(cursheet, $2, $3); }
 	| TRACK INTEGER AUDIO		{ addnewtrack(cursheet, $2); }
 	| INDEX INTEGER timestamp	{ settimestamp(cursheet, $2, $3); }
+	| CATALOG MCN				{ setmcn(cursheet, $2); }
 	;
 
 filetype:
--- a/cuefs.h
+++ b/cuefs.h
@@ -73,7 +73,7 @@
 
 struct Cuesheet
 {
-	char *title, *performer;
+	char *title, *performer, *mcn;
 	AFile *files, *curfile;
 	Entry *entries, *curentry;
 };
@@ -87,6 +87,7 @@
 Cuesheet* newsheet(void);
 void freesheet(Cuesheet*);
 
+void setmcn(Cuesheet*, char*);
 void setperformer(Cuesheet*, char*);
 void settitle(Cuesheet*, char*);
 void addfile(Cuesheet*, char*, int);
--- a/fs.c
+++ b/fs.c
@@ -416,7 +416,6 @@
 		close(infd);
 		close(outfd);
 		{
-			/* TODO better metadata handling */
 			char **argv = metaflags(enc, e);
 			exec(enc, argv);
 			enc = smprint("/bin/%s", enc);