First commit after CVS conversion. Should be just administrative changes.
This commit is contained in:
64
parse/Makefile
Normal file
64
parse/Makefile
Normal file
@@ -0,0 +1,64 @@
|
||||
# $Id: Makefile,v 1.5 2008/03/23 17:21:34 karl Exp $
|
||||
#
|
||||
# Copyright (C) 2008 Rocky Bernstein <rocky@gnu.org>
|
||||
#
|
||||
# This program is free software: you can redistribute it and/or modify
|
||||
# it under the terms of the GNU General Public License as published by
|
||||
# the Free Software Foundation, either version 3 of the License, or
|
||||
# (at your option) any later version.
|
||||
#
|
||||
# This program is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
# GNU General Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU General Public License
|
||||
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
INCLUDES = -I .
|
||||
all: cueparser cuelexer tocparser
|
||||
|
||||
lex.cue.c: cue.L cue.tab.h
|
||||
flex -Pcue cue.L
|
||||
|
||||
lex.cuelex.c: cue.L cue.tab.h
|
||||
flex -Pcuelex cue.L
|
||||
|
||||
lex.cue.o: lex.cue.c
|
||||
gcc -g -Wall -c lex.cue.c $(INCLUDES)
|
||||
|
||||
lex.cuelex.o: lex.cuelex.c
|
||||
gcc -g -DSTANDALONE -Wall -c lex.cuelex.c
|
||||
|
||||
cue.tab.c, cue.tab.h: cue.y
|
||||
bison -p cue -d cue.y
|
||||
|
||||
cue.tab.o: cue.tab.c cue.tab.h
|
||||
gcc -g -Wall -DSTANDALONE -c cue.tab.c $(INCLUDES)
|
||||
|
||||
cueparser: lex.cue.o cue.tab.o
|
||||
gcc -g lex.cue.o cue.tab.o -lfl -o cueparser
|
||||
|
||||
cuelexer: lex.cuelex.o
|
||||
gcc -g lex.cuelex.o -lfl -o cuelexer
|
||||
|
||||
toc.tab.h: toc.tab.c
|
||||
|
||||
toc.tab.c: toc.y
|
||||
bison -p toc -d toc.y
|
||||
|
||||
toclexer.o: toclexer.c
|
||||
gcc -g -Wall -c toclexer.c $(INCLUDES)
|
||||
|
||||
toc.tab.o: toc.tab.c toc.tab.h
|
||||
gcc -g -Wall -DSTANDALONE -c toc.tab.c $(INCLUDES)
|
||||
|
||||
tocparser: toc.tab.o toclexer.o
|
||||
gcc -g toclexer.o toc.tab.o -o tocparser
|
||||
|
||||
clean:
|
||||
rm -f lex.cue.c lex.cuelex.c lex.cue.o lex.cuelex.o cue.tab.c \
|
||||
cue.tab.o cueparser cuelexer
|
||||
|
||||
check:
|
||||
(cd test && ./runall)
|
||||
239
parse/cue.L
Normal file
239
parse/cue.L
Normal file
@@ -0,0 +1,239 @@
|
||||
/* $Id: cue.L,v 1.2 2008/03/23 17:21:34 karl Exp $ -*- C -*- */
|
||||
/* CUE-sheet scanner
|
||||
Copyright (C) 2005, 2008 Rocky Bernstein <rocky@gnu.org>
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
%{
|
||||
#undef yywrap
|
||||
#ifdef STANDALONE
|
||||
#include <stdio.h>
|
||||
#endif
|
||||
|
||||
#include "cue.tab.h"
|
||||
|
||||
static int debug_lex=0;
|
||||
%}
|
||||
%x filename
|
||||
|
||||
TrackDef "TRACK"
|
||||
Audio "AUDIO"
|
||||
Mode1_2048 "MODE1/2048"
|
||||
Mode1_2352 "MODE1/2352"
|
||||
Mode2_2336 "MODE2/2336"
|
||||
Mode2_2352 "MODE2/2352"
|
||||
Index "INDEX"
|
||||
File "FILE"
|
||||
Pregap "PREGAP"
|
||||
Postgap "POSTGAP"
|
||||
Binary "BINARY"
|
||||
Motorola "MOTOROLA"
|
||||
Flags "FLAGS"
|
||||
Catalog "CATALOG"
|
||||
Isrc "ISRC"
|
||||
Four_Channel "4CH"
|
||||
Dont_Copy "DCP"
|
||||
Pre_Emphasis "PRE"
|
||||
Colon ":"
|
||||
Integer [[:digit:]]+
|
||||
Spaces [[:blank:]\n\r]+
|
||||
String \".+\"
|
||||
Filename [^[:blank:]\n\r]+
|
||||
%%
|
||||
{TrackDef} {
|
||||
/*"*/
|
||||
return TRACK_TOKEN;
|
||||
}
|
||||
{Audio} {
|
||||
return AUDIO_TOKEN;
|
||||
}
|
||||
|
||||
{Mode1_2048} {
|
||||
return MODE1_2048_TOKEN;
|
||||
}
|
||||
|
||||
{Mode1_2352} {
|
||||
return MODE1_2352_TOKEN;
|
||||
}
|
||||
|
||||
{Mode2_2336} {
|
||||
return MODE2_2336_TOKEN;
|
||||
}
|
||||
|
||||
{Mode2_2352} {
|
||||
return MODE2_2352_TOKEN;
|
||||
}
|
||||
|
||||
{Index} {
|
||||
return INDEX_TOKEN;
|
||||
}
|
||||
|
||||
{File} {
|
||||
BEGIN(filename);
|
||||
return FILE_TOKEN;
|
||||
}
|
||||
|
||||
{Pregap} {
|
||||
return PREGAP_TOKEN;
|
||||
}
|
||||
|
||||
{Postgap} {
|
||||
return POSTGAP_TOKEN;
|
||||
}
|
||||
|
||||
{Binary} {
|
||||
return BINARY_TOKEN;
|
||||
}
|
||||
|
||||
{Motorola} {
|
||||
return MOTOROLA_TOKEN;
|
||||
}
|
||||
|
||||
{Flags} {
|
||||
return FLAGS_TOKEN;
|
||||
}
|
||||
|
||||
{Catalog} {
|
||||
return CATALOG_TOKEN;
|
||||
}
|
||||
|
||||
{Isrc} {
|
||||
if (debug_lex) printf("Isrc token\n");
|
||||
}
|
||||
|
||||
{Four_Channel} {
|
||||
return FOURCH_TOKEN;
|
||||
}
|
||||
|
||||
{Dont_Copy} {
|
||||
return DCP_TOKEN;
|
||||
}
|
||||
|
||||
{Pre_Emphasis} {
|
||||
if (debug_lex) printf("Pre_Emphasis token\n");
|
||||
}
|
||||
|
||||
{Colon} {
|
||||
return COLON_TOKEN;
|
||||
}
|
||||
|
||||
{Integer} {
|
||||
return INTEGER_TOKEN;
|
||||
}
|
||||
|
||||
<filename>{Filename} {
|
||||
BEGIN(INITIAL);
|
||||
return FILENAME_TOKEN;
|
||||
}
|
||||
|
||||
<INITIAL,filename>{String} {
|
||||
return STRING_TOKEN;
|
||||
}
|
||||
|
||||
<INITIAL,filename>{Spaces} {
|
||||
return SPACES_TOKEN;
|
||||
}
|
||||
|
||||
<INITIAL,filename><<EOF>> {
|
||||
return EOF;
|
||||
}
|
||||
|
||||
|
||||
%%
|
||||
|
||||
#if STANDALONE
|
||||
int
|
||||
main( int argc, const char **argv )
|
||||
{
|
||||
int token;
|
||||
|
||||
++argv, --argc; /* skip over program name */
|
||||
debug_lex = 1;
|
||||
if ( argc > 0 )
|
||||
yyin = fopen( argv[0], "r" );
|
||||
else
|
||||
yyin = stdin;
|
||||
|
||||
while ((token=yylex()) != EOF) {
|
||||
switch (token) {
|
||||
case TRACK_TOKEN:
|
||||
printf("TRACK\n");
|
||||
break;
|
||||
case AUDIO_TOKEN:
|
||||
printf("AUDIO token\n");
|
||||
break;
|
||||
case MODE1_2048_TOKEN:
|
||||
printf("MODE1/2048\n");
|
||||
break;
|
||||
case MODE1_2352_TOKEN:
|
||||
printf("MODE1/2352\n");
|
||||
break;
|
||||
case MODE2_2336_TOKEN:
|
||||
printf("MODE1/2336\n");
|
||||
break;
|
||||
case MODE2_2352_TOKEN:
|
||||
printf("MODE2/2352\n");
|
||||
break;
|
||||
case INDEX_TOKEN:
|
||||
printf("INDEX\n");
|
||||
break;
|
||||
case FILE_TOKEN:
|
||||
printf("FILE\n");
|
||||
break;
|
||||
case PREGAP_TOKEN:
|
||||
printf("PREGAP\n");
|
||||
break;
|
||||
case POSTGAP_TOKEN:
|
||||
printf("POSTGAP\n");
|
||||
break;
|
||||
case BINARY_TOKEN:
|
||||
printf("BINARY\n");
|
||||
break;
|
||||
case SPACES_TOKEN:
|
||||
printf("spaces\n");
|
||||
break;
|
||||
case STRING_TOKEN:
|
||||
printf("string: %s\n", yytext);
|
||||
break;
|
||||
case INTEGER_TOKEN:
|
||||
printf("integer: %d (%s)\n", atoi(yytext), yytext);
|
||||
break;
|
||||
case COLON_TOKEN:
|
||||
printf(":\n");
|
||||
break;
|
||||
case FLAGS_TOKEN:
|
||||
printf("FLAGS\n");
|
||||
break;
|
||||
case CATALOG_TOKEN:
|
||||
printf("CATALOG\n");
|
||||
break;
|
||||
case DCP_TOKEN:
|
||||
printf("DCP\n");
|
||||
break;
|
||||
case MOTOROLA_TOKEN:
|
||||
printf("MOTOROLA\n");
|
||||
break;
|
||||
case FOURCH_TOKEN:
|
||||
printf("4CH\n");
|
||||
break;
|
||||
case FILENAME_TOKEN:
|
||||
printf("filename %s\n", yytext);
|
||||
break;
|
||||
default: ;
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
#endif
|
||||
183
parse/cue.y
Normal file
183
parse/cue.y
Normal file
@@ -0,0 +1,183 @@
|
||||
%{
|
||||
/* $Id: cue.y,v 1.2 2008/03/23 17:21:34 karl Exp $
|
||||
|
||||
Copyright (C) 2005, 2008 Rocky Bernstein <rocky@gnu.org>
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
extern FILE *cuein;
|
||||
int cuelex(void);
|
||||
int cueerror(char *s);
|
||||
|
||||
#ifdef STANDALONE
|
||||
#include <getopt.h>
|
||||
#define YYDEBUG 1
|
||||
#endif
|
||||
|
||||
%}
|
||||
|
||||
/* BISON Declarations */
|
||||
%token TRACK_TOKEN
|
||||
%token AUDIO_TOKEN
|
||||
%token MODE1_2048_TOKEN
|
||||
%token MODE1_2352_TOKEN
|
||||
%token MODE2_2336_TOKEN
|
||||
%token MODE2_2352_TOKEN
|
||||
%token INDEX_TOKEN
|
||||
%token FILE_TOKEN
|
||||
%token PREGAP_TOKEN
|
||||
%token POSTGAP_TOKEN
|
||||
%token BINARY_TOKEN
|
||||
%token MOTOROLA_TOKEN
|
||||
%token FLAGS_TOKEN
|
||||
%token CATALOG_TOKEN
|
||||
%token ISRC_TOKEN
|
||||
%token FOURCH_TOKEN
|
||||
%token DCP_TOKEN
|
||||
%token PRE_TOKEN
|
||||
%token COLON_TOKEN
|
||||
%token INTEGER_TOKEN
|
||||
%token SPACES_TOKEN
|
||||
%token STRING_TOKEN
|
||||
%token FILENAME_TOKEN
|
||||
|
||||
/* Grammar follows */
|
||||
%%
|
||||
|
||||
/* We optionally allow spaces at the end of the file.
|
||||
*/
|
||||
cue: cue_stmts opt_spaces ;
|
||||
|
||||
/* one or more cuesheet statements. We allow spaces before the beginning
|
||||
of the cuesheet statement */
|
||||
cue_stmts: cue_stmts SPACES_TOKEN cue_stmt | opt_spaces cue_stmt ;
|
||||
|
||||
cue_stmt: catalog_stmt
|
||||
| file_stmt
|
||||
| track_stmt
|
||||
| flags_stmt
|
||||
| pregap_stmt
|
||||
| postgap_stmt
|
||||
| index_stmt
|
||||
;
|
||||
|
||||
|
||||
/* FILE *filename* {BINARY|MOTOROLA|AUDIO} */
|
||||
file_stmt: FILE_TOKEN SPACES_TOKEN file_id SPACES_TOKEN file_flags
|
||||
;
|
||||
|
||||
file_id: FILENAME_TOKEN | STRING_TOKEN
|
||||
;
|
||||
|
||||
|
||||
file_flags: BINARY_TOKEN | MOTOROLA_TOKEN | AUDIO_TOKEN
|
||||
;
|
||||
|
||||
/* CATALOG *n* */
|
||||
catalog_stmt: CATALOG_TOKEN INTEGER_TOKEN
|
||||
;
|
||||
|
||||
/* TRACK *n* {MODE1/2048 | MODE1/2352 | MODE2/2336 | MODE2/2352} */
|
||||
track_stmt: TRACK_TOKEN SPACES_TOKEN INTEGER_TOKEN SPACES_TOKEN track_mode_exp
|
||||
;
|
||||
|
||||
track_mode_exp: MODE1_2048_TOKEN
|
||||
| MODE1_2352_TOKEN
|
||||
| MODE2_2336_TOKEN
|
||||
| MODE2_2352_TOKEN
|
||||
;
|
||||
|
||||
/* FLAGS {DCP | 4CH | PRE} */
|
||||
flags_stmt: FLAGS_TOKEN SPACES_TOKEN flags_exp
|
||||
;
|
||||
|
||||
flags_exp: DCP_TOKEN | FOURCH_TOKEN | PRE_TOKEN
|
||||
;
|
||||
|
||||
/* PREGAP dd:dd:ddx */
|
||||
pregap_stmt: PREGAP_TOKEN SPACES_TOKEN msf_exp
|
||||
;
|
||||
|
||||
/* PROSTGAP dd:dd:dd */
|
||||
postgap_stmt: POSTGAP_TOKEN SPACES_TOKEN msf_exp
|
||||
;
|
||||
|
||||
/* INDEX *n* dd:dd:dd */
|
||||
index_stmt: INDEX_TOKEN SPACES_TOKEN INTEGER_TOKEN SPACES_TOKEN msf_exp
|
||||
;
|
||||
|
||||
/* a MSF e.g. 00:00:00 or 02:00 */
|
||||
msf_exp: INTEGER_TOKEN COLON_TOKEN INTEGER_TOKEN COLON_TOKEN INTEGER_TOKEN
|
||||
| INTEGER_TOKEN COLON_TOKEN INTEGER_TOKEN
|
||||
;
|
||||
|
||||
|
||||
opt_spaces: SPACES_TOKEN | ;
|
||||
|
||||
%%
|
||||
|
||||
#ifdef STANDALONE
|
||||
/* The controlling function */
|
||||
|
||||
int
|
||||
cueerror(char *s) /* called by cueparse on error */
|
||||
{
|
||||
printf("%s\n",s);
|
||||
return(0);
|
||||
}
|
||||
|
||||
int
|
||||
main( int argc, char **argv )
|
||||
{
|
||||
int c;
|
||||
|
||||
cuedebug = 0;
|
||||
|
||||
while (1) {
|
||||
int option_index = 0;
|
||||
static struct option long_options[] = {
|
||||
{"debug", 0, 0, 'd'},
|
||||
{0, 0, 0, 0}
|
||||
};
|
||||
|
||||
c = getopt_long (argc, argv, "d", long_options, &option_index);
|
||||
if (c == -1)
|
||||
break;
|
||||
|
||||
switch (c) {
|
||||
case 'd':
|
||||
cuedebug = 1;
|
||||
break;
|
||||
default:
|
||||
printf ("?? getopt returned character code 0%o ??\n", c);
|
||||
exit(1);
|
||||
}
|
||||
}
|
||||
|
||||
if ( optind < argc )
|
||||
cuein = fopen( argv[optind], "r" );
|
||||
else
|
||||
cuein = stdin;
|
||||
|
||||
if (cueparse()==0) {
|
||||
printf("Is a CUE file\n");
|
||||
} else {
|
||||
printf("Isn't a CUE file\n");
|
||||
}
|
||||
exit(0);
|
||||
}
|
||||
#endif /* STANDALONE*/
|
||||
13
parse/test/runall
Executable file
13
parse/test/runall
Executable file
@@ -0,0 +1,13 @@
|
||||
#!/usr/bin/perl -w
|
||||
use strict;
|
||||
my @tests;
|
||||
|
||||
if (@ARGV) {
|
||||
@tests = @ARGV;
|
||||
} else {
|
||||
@tests=qw(t1.cue t2.cue t3.cue);
|
||||
}
|
||||
|
||||
foreach my $cue_file (@tests) {
|
||||
system("../cueparser $cue_file");
|
||||
}
|
||||
9
parse/test/t1.cue
Normal file
9
parse/test/t1.cue
Normal file
@@ -0,0 +1,9 @@
|
||||
FILE "t1.bin" BINARY
|
||||
TRACK 01 MODE2/2352
|
||||
FLAGS DCP
|
||||
INDEX 01 00:00:00
|
||||
TRACK 02 MODE2/2352
|
||||
FLAGS DCP
|
||||
INDEX 00 00:04:00
|
||||
INDEX 01 00:06:00
|
||||
INDEX 02 00:06:32
|
||||
10
parse/test/t2.cue
Normal file
10
parse/test/t2.cue
Normal file
@@ -0,0 +1,10 @@
|
||||
|
||||
|
||||
FILE t2.bin AUDIO
|
||||
TRACK 01 MODE1/2352
|
||||
FLAGS DCP INDEX 01 00:00:00
|
||||
TRACK 02 MODE1/2048
|
||||
FLAGS DCP
|
||||
INDEX 00 00:04:00
|
||||
INDEX 01 00:06:00
|
||||
INDEX 02 00:06:32
|
||||
7
parse/test/t3.cue
Normal file
7
parse/test/t3.cue
Normal file
@@ -0,0 +1,7 @@
|
||||
FILE BINARY BINARY
|
||||
TRACK 01 MODE2/2352
|
||||
FLAGS DCP
|
||||
INDEX 01 00:00:00
|
||||
TRACK 02 MODE2/2352
|
||||
FLAGS DCP
|
||||
INDEX 00 00:04:00 INDEX 01 00:06:93 INDEX 02 00:61:32
|
||||
91
parse/toc.L
Normal file
91
parse/toc.L
Normal file
@@ -0,0 +1,91 @@
|
||||
/* $Id: toc.L,v 1.2 2008/03/23 17:21:34 karl Exp $ -*- C -*- */
|
||||
/* cdrdao TOC scanner
|
||||
Copyright (C) 2005, 2008 Rocky Bernstein <rocky@gnu.org>
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
%{
|
||||
#undef yywrap
|
||||
#ifdef STANDALONE
|
||||
#include <stdio.h>
|
||||
#endif
|
||||
|
||||
#include "toc.tab.h"
|
||||
|
||||
static int debug_lex=0;
|
||||
%}
|
||||
%union {
|
||||
unsigned long int val; /* For returning numbers. */
|
||||
char const * str; /* For returning stringss. */
|
||||
}
|
||||
|
||||
|
||||
integer [[:digit:]]+
|
||||
|
||||
/* The below isn't octal. I'm just going by the name and pattern
|
||||
in the cdrdao pacct grammar. */
|
||||
stringoctal [[:digit:]]{3}
|
||||
|
||||
spaces [[:blank:]\n\r]+
|
||||
|
||||
# Need to expand this to include "octal" \000 and embedded quotes.
|
||||
string \".+\"
|
||||
%%
|
||||
{integer} {
|
||||
/*"*/
|
||||
return Integer;
|
||||
}
|
||||
|
||||
{stringoctal} {
|
||||
/*"*/
|
||||
return StringOctal;
|
||||
}
|
||||
|
||||
{spaces} {
|
||||
return Spaces;
|
||||
}
|
||||
|
||||
%%
|
||||
|
||||
#if STANDALONE
|
||||
int
|
||||
main( int argc, const char **argv )
|
||||
{
|
||||
int token;
|
||||
|
||||
++argv, --argc; /* skip over program name */
|
||||
debug_lex = 1;
|
||||
if ( argc > 0 )
|
||||
yyin = fopen( argv[0], "r" );
|
||||
else
|
||||
yyin = stdin;
|
||||
|
||||
while ((token=yylex()) != EOF) {
|
||||
switch (token) {
|
||||
case StringOctal:
|
||||
printf("StringOctal\n");
|
||||
break;
|
||||
case Spaces:
|
||||
printf("Spaces\n");
|
||||
break;
|
||||
case Integer:
|
||||
printf("Integer\n");
|
||||
break;
|
||||
default: ;
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
#endif
|
||||
296
parse/toc.y
Normal file
296
parse/toc.y
Normal file
@@ -0,0 +1,296 @@
|
||||
/*
|
||||
$Id: toc.y,v 1.3 2008/03/23 17:21:34 karl Exp $
|
||||
|
||||
Copyright (C) 2005, 2008 Rocky Bernstein <rocky@panix.com>
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
/* Yacc grammer for cdrdao TOC file */
|
||||
%{
|
||||
#include "toclexer.h"
|
||||
#include "errno.h"
|
||||
FILE *toc_in;
|
||||
int tocerror (char const *s);
|
||||
|
||||
#ifdef STANDALONE
|
||||
#include <getopt.h>
|
||||
#define YYDEBUG 1
|
||||
#endif
|
||||
|
||||
%}
|
||||
|
||||
/* BISON Declarations */
|
||||
|
||||
%token ARRANGER
|
||||
%token AUDIO
|
||||
%token AUDIOFILE
|
||||
%token CATALOG
|
||||
%token CD_DA
|
||||
%token CD_I
|
||||
%token CD_ROM
|
||||
%token CD_ROM_XA
|
||||
%token CD_TEXT
|
||||
%token COMPOSER
|
||||
%token COPY
|
||||
%token DATAFILE
|
||||
%token DISC_ID
|
||||
%token EN
|
||||
%token END
|
||||
%token FIFO
|
||||
%token FILE_TOKEN
|
||||
%token FOUR_CHANNEL_AUDIO
|
||||
%token GENRE
|
||||
%token INDEX
|
||||
%token ISRC
|
||||
%token LANGUAGE
|
||||
%token LANGUAGE_MAP
|
||||
%token MESSAGE
|
||||
%token MODE0
|
||||
%token MODE1
|
||||
%token MODE1_RAW
|
||||
%token MODE2
|
||||
%token MODE2_FORM1
|
||||
%token MODE2_FORM2
|
||||
%token MODE2_FORM_MIX
|
||||
%token MODE2_RAW
|
||||
%token NO
|
||||
%token PERFORMER
|
||||
%token PREGAP
|
||||
%token PRE_EMPHASIS
|
||||
%token RESERVED1
|
||||
%token RESERVED2
|
||||
%token RESERVED3
|
||||
%token RESERVED4
|
||||
%token RW
|
||||
%token RW_RAW
|
||||
%token SILENCE
|
||||
%token SIZE_INFO
|
||||
%token SONGWRITER
|
||||
%token START
|
||||
%token SWAP
|
||||
%token TITLE
|
||||
%token TOC_INFO1
|
||||
%token TOC_INFO2
|
||||
%token TRACK
|
||||
%token TWO_CHANNEL_AUDIO
|
||||
%token UPC_EAN
|
||||
%token ZERO
|
||||
|
||||
%token LeftBrace /* "{" */
|
||||
%token RightBrace /* "}" */
|
||||
%token Colon /* ":" */
|
||||
%token Error /* Error token return */
|
||||
%token Id /* Id but not one of the above keywords */
|
||||
%token Integer
|
||||
%token String
|
||||
|
||||
%union {
|
||||
long unsigned int val; /* For returning numbers. */
|
||||
symrec *tptr; /* For returning symbol-table pointers. */
|
||||
}
|
||||
|
||||
/* Grammar follows */
|
||||
%%
|
||||
|
||||
/* We optionally allow spaces at the end of the TOC file.
|
||||
*/
|
||||
toc: catalog_or_tocType cdTextGlobal tracks ;
|
||||
|
||||
catalog_or_tocType: catalog_or_tocType CATALOG String
|
||||
| catalog_or_tocType tocType
|
||||
| /* empty */ ;
|
||||
|
||||
tracks: tracks track | track ;
|
||||
|
||||
track: TRACK trackMode opt_subChannelMode opt_track_flags
|
||||
cdTextTrack opt_pregap_msf subTracks_or_starts_or_ends opt_index_msfs
|
||||
;
|
||||
|
||||
opt_track_flags: opt_track_flags track_flag
|
||||
| /* empty */;
|
||||
|
||||
track_flag: ISRC String
|
||||
| opt_no COPY
|
||||
| opt_no PRE_EMPHASIS
|
||||
| TWO_CHANNEL_AUDIO
|
||||
| FOUR_CHANNEL_AUDIO ;
|
||||
|
||||
opt_no: NO
|
||||
| /* empty */;
|
||||
|
||||
opt_pregap_msf: PREGAP msf
|
||||
| /* empty */;
|
||||
|
||||
opt_index_msfs: opt_index_msfs INDEX msf
|
||||
| /* empty */ ;
|
||||
|
||||
subTrack_or_start_or_end: subTrack
|
||||
| START opt_msf
|
||||
| END opt_msf ;
|
||||
|
||||
subTracks_or_starts_or_ends: subTracks_or_starts_or_ends
|
||||
subTrack_or_start_or_end
|
||||
| subTrack_or_start_or_end ;
|
||||
|
||||
subTrack:
|
||||
AudioFile String opt_swap opt_start_offset samples
|
||||
| DATAFILE String opt_start_length
|
||||
| FIFO String dataLength
|
||||
| SILENCE samples
|
||||
| ZERO opt_dataMode opt_subChannelMode dataLength
|
||||
;
|
||||
|
||||
AudioFile: AUDIOFILE | FILE_TOKEN ;
|
||||
|
||||
opt_swap: SWAP
|
||||
| /* empty */;
|
||||
|
||||
opt_start_offset: "#" sLong
|
||||
| /* empty */;
|
||||
|
||||
opt_start_length: "#" sLong
|
||||
| '#' sLong dataLength
|
||||
| /* empty */;
|
||||
|
||||
opt_dataMode: dataMode
|
||||
| /* empty */ ;
|
||||
|
||||
opt_string: String
|
||||
| /* empty */ ;
|
||||
|
||||
uLong: Integer ;
|
||||
|
||||
sLong: Integer ;
|
||||
|
||||
msf: Integer Colon Integer Colon Integer ;
|
||||
|
||||
opt_msf: msf | /* empty */ ;
|
||||
|
||||
samples: msf | uLong ;
|
||||
|
||||
dataLength: msf | uLong ;
|
||||
|
||||
dataMode: AUDIO | MODE0 | MODE1 | MODE1_RAW | MODE2
|
||||
| MODE2_RAW | MODE2_FORM1 | MODE2_FORM2 | MODE2_FORM_MIX
|
||||
;
|
||||
|
||||
|
||||
trackMode: AUDIO | MODE1 | MODE1_RAW | MODE2
|
||||
| MODE2_RAW | MODE2_FORM1 | MODE2_FORM2 | MODE2_FORM_MIX
|
||||
;
|
||||
|
||||
|
||||
opt_subChannelMode: RW | RW_RAW
|
||||
| /* empty */;
|
||||
|
||||
tocType: CD_DA | CD_ROM | CD_ROM_XA | CD_I ;
|
||||
|
||||
packType: TITLE | PERFORMER | SONGWRITER | COMPOSER | ARRANGER
|
||||
| MESSAGE | DISC_ID | GENRE | TOC_INFO1 | TOC_INFO2
|
||||
| RESERVED1 | RESERVED2 | RESERVED3 | RESERVED4 | UPC_EAN
|
||||
| ISRC | SIZE_INFO ;
|
||||
|
||||
|
||||
binaryData: LeftBrace Integers RightBrace ;
|
||||
|
||||
Integers: Integers "," Integer | Integer ;
|
||||
|
||||
|
||||
cdTextItem: packType opt_string_or_binaryData | ;
|
||||
|
||||
opt_string_or_binaryData: opt_string | binaryData ;
|
||||
|
||||
cdTextBlock: LANGUAGE Integer LeftBrace cdTextItem RightBrace ;
|
||||
|
||||
opt_cdTextBlock: cdTextBlock
|
||||
| /* empty */;
|
||||
|
||||
opt_cdTextBlocks: opt_cdTextBlocks cdTextBlock
|
||||
| /* empty */ ;
|
||||
|
||||
opt_cdTextLanguageMap : LANGUAGE_MAP LeftBrace Language_mappings RightBrace
|
||||
| /* empty */;
|
||||
|
||||
Language_mappings: Language_mappings Language_mapping | Language_mapping ;
|
||||
|
||||
Language_mapping: Integer ":" Language_id ;
|
||||
|
||||
Language_id: Integer | EN;
|
||||
|
||||
cdTextTrack: CD_TEXT LeftBrace opt_cdTextBlocks RightBrace | ;
|
||||
|
||||
cdTextGlobal: CD_TEXT LeftBrace opt_cdTextLanguageMap opt_cdTextBlock
|
||||
RightBrace
|
||||
| /* empty */;
|
||||
|
||||
|
||||
%%
|
||||
|
||||
#ifdef STANDALONE
|
||||
/* The controlling function */
|
||||
|
||||
int
|
||||
tocerror(char const *s) /* called by tocparse on error */
|
||||
{
|
||||
printf("%s\n",s);
|
||||
return(0);
|
||||
}
|
||||
|
||||
int
|
||||
main( int argc, char **argv )
|
||||
{
|
||||
int c;
|
||||
|
||||
tocdebug = 0;
|
||||
|
||||
while (1) {
|
||||
int option_index = 0;
|
||||
static struct option long_options[] = {
|
||||
{"debug", 0, 0, 'd'},
|
||||
{0, 0, 0, 0}
|
||||
};
|
||||
|
||||
c = getopt_long (argc, argv, "d", long_options, &option_index);
|
||||
if (c == -1)
|
||||
break;
|
||||
|
||||
switch (c) {
|
||||
case 'd':
|
||||
tocdebug = 1;
|
||||
break;
|
||||
default:
|
||||
printf ("?? getopt returned character code 0%o ??\n", c);
|
||||
exit(1);
|
||||
}
|
||||
}
|
||||
|
||||
if ( optind < argc ) {
|
||||
toc_in = fopen( argv[optind], "r" );
|
||||
if (!toc_in) {
|
||||
printf("unable to open %s for reading: %s\n", argv[optind],
|
||||
strerror(errno));
|
||||
exit(1);
|
||||
}
|
||||
} else
|
||||
toc_in = stdin;
|
||||
|
||||
|
||||
if (tocparse()==0) {
|
||||
printf("Is a TOC file\n");
|
||||
} else {
|
||||
printf("Isn't a TOC file\n");
|
||||
}
|
||||
exit(0);
|
||||
}
|
||||
#endif /* STANDALONE*/
|
||||
197
parse/toclexer.c
Normal file
197
parse/toclexer.c
Normal file
@@ -0,0 +1,197 @@
|
||||
/*
|
||||
$Id: toclexer.c,v 1.2 2008/03/23 17:21:34 karl Exp $
|
||||
|
||||
Copyright (C) 2005, 2008 Rocky Bernstein <rocky@gnu.org>
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
/* Lexical scanner for cdrdao's TOC. */
|
||||
#include "toclexer.h"
|
||||
#include "toc.tab.h"
|
||||
#include <ctype.h>
|
||||
|
||||
#define YYEOF 0
|
||||
|
||||
/* A structure for associating a word with a token. */
|
||||
typedef struct keyword_s
|
||||
{
|
||||
char const *psz_keyword;
|
||||
token_t i_token;
|
||||
} keyword_t;
|
||||
|
||||
/* These are all of the words that might appear in a TOC file and
|
||||
the token association that the parser will use.
|
||||
*/
|
||||
const keyword_t keywords[] =
|
||||
{
|
||||
{"ARRANGER", ARRANGER},
|
||||
{"AUDIO", AUDIO},
|
||||
{"AUDIOFILE", AUDIOFILE},
|
||||
{"CATALOG", CATALOG},
|
||||
{"CD_DA", CD_DA},
|
||||
{"CD_I", CD_I},
|
||||
{"CD_ROM", CD_ROM},
|
||||
{"CD_ROM_XA", CD_ROM_XA},
|
||||
{"CD_TEXT", CD_TEXT},
|
||||
{"COMPOSER", COMPOSER},
|
||||
{"COPY", COPY},
|
||||
{"DATAFILE", DATAFILE},
|
||||
{"DISC_ID", DISC_ID},
|
||||
{"EN", EN},
|
||||
{"END", END},
|
||||
{"FIFO", FIFO},
|
||||
{"FILE", FILE_TOKEN},
|
||||
{"FOUR_CHANNEL_AUDIO", FOUR_CHANNEL_AUDIO},
|
||||
{"GENRE", GENRE},
|
||||
{"INDEX", INDEX},
|
||||
{"ISRC", ISRC},
|
||||
{"LANGUAGE", LANGUAGE},
|
||||
{"LANGUAGE_MAP", LANGUAGE_MAP},
|
||||
{"MESSAGE", MESSAGE},
|
||||
{"MODE0", MODE0},
|
||||
{"MODE1", MODE1},
|
||||
{"MODE1_RAW", MODE1_RAW},
|
||||
{"MODE2", MODE2},
|
||||
{"MODE2_FORM1", MODE2_FORM1},
|
||||
{"MODE2_FORM2", MODE2_FORM2},
|
||||
{"MODE2_FORM_MIX", MODE2_FORM_MIX},
|
||||
{"MODE2_RAW", MODE2_RAW},
|
||||
{"NO", NO},
|
||||
{"PERFORMER", PERFORMER},
|
||||
{"PREGAP", PREGAP},
|
||||
{"PRE_EMPHASIS", PRE_EMPHASIS},
|
||||
{"RESERVED1", RESERVED1},
|
||||
{"RESERVED2", RESERVED2},
|
||||
{"RESERVED3", RESERVED3},
|
||||
{"RESERVED4", RESERVED4},
|
||||
{"RW", RW},
|
||||
{"RW_RAW", RW_RAW},
|
||||
{"SILENCE", SILENCE},
|
||||
{"SIZE_INFO", SIZE_INFO},
|
||||
{"SONGWRITER", SONGWRITER},
|
||||
{"START", START},
|
||||
{"SWAP", SWAP},
|
||||
{"TITLE", TITLE},
|
||||
{"TOC_INFO1", TOC_INFO1},
|
||||
{"TOC_INFO2", TOC_INFO2},
|
||||
{"TRACK", TRACK},
|
||||
{"TWO_CHANNEL_AUDIO", TWO_CHANNEL_AUDIO},
|
||||
{"UPC_EAN", UPC_EAN},
|
||||
{"ZERO", ZERO},
|
||||
{0, 0}
|
||||
};
|
||||
|
||||
static int
|
||||
compare_keyword(const void *p_id, const void *p_keyword) {
|
||||
char *psz_id = (char *) p_id;
|
||||
char const *psz_keyword = ((keyword_t *) p_keyword)->psz_keyword;
|
||||
return strcmp(psz_id, psz_keyword);
|
||||
}
|
||||
|
||||
token_t
|
||||
toclex (void)
|
||||
{
|
||||
int c;
|
||||
|
||||
start:
|
||||
/* Skip white space. */
|
||||
while ( isspace(c = fgetc (toc_in)) )
|
||||
;
|
||||
|
||||
/* Process a number. */
|
||||
if (isdigit (c))
|
||||
{
|
||||
ungetc (c, toc_in);
|
||||
fscanf (toc_in, "%lu", &(toclval.val));
|
||||
return Integer;
|
||||
}
|
||||
|
||||
/* Process a comment. */
|
||||
if ( '/' == c ) {
|
||||
if ('/' == (c = fgetc (toc_in)) ) {
|
||||
while ((c = fgetc (toc_in)) != EOF && c != '\n')
|
||||
;
|
||||
|
||||
/* Return end-of-input. */
|
||||
if (EOF == c) return YYEOF;
|
||||
goto start;
|
||||
}
|
||||
/* Not a comment. So put back the character after the '/' and
|
||||
return '/' */
|
||||
ungetc (c, toc_in);
|
||||
return '/';
|
||||
}
|
||||
|
||||
/* Char starts an identifier => read the name. */
|
||||
if (isalpha (c))
|
||||
{
|
||||
static char symbol[50] = "";
|
||||
unsigned int i;
|
||||
|
||||
i = 0;
|
||||
do
|
||||
{
|
||||
/* Add this character to the buffer. */
|
||||
symbol[i++] = c;
|
||||
/* Get another character. */
|
||||
c = fgetc (toc_in);
|
||||
}
|
||||
while (isgraph (c));
|
||||
|
||||
ungetc (c, toc_in);
|
||||
symbol[i] = '\0';
|
||||
|
||||
toclval.psz_str = symbol;
|
||||
|
||||
{
|
||||
keyword_t *p_keyword;
|
||||
p_keyword = bsearch(symbol, keywords,
|
||||
(sizeof(keywords) / sizeof(keyword_t)) - 1,
|
||||
sizeof(keyword_t), compare_keyword);
|
||||
if (!p_keyword) return Id;
|
||||
return p_keyword->i_token;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/* Process a string.
|
||||
To do: save the value of the string and process octal numbers.
|
||||
*/
|
||||
if ( '"' == c ) {
|
||||
int b_backslash = 0;
|
||||
while ( EOF != (c = fgetc (toc_in))
|
||||
&& (b_backslash || '"' != c ) ) {
|
||||
b_backslash = ('\\' == c );
|
||||
}
|
||||
|
||||
/* Return end-of-input. */
|
||||
if (EOF == c) return YYEOF;
|
||||
|
||||
return String;
|
||||
}
|
||||
|
||||
/* Return end-of-input. */
|
||||
if (EOF == c) return YYEOF;
|
||||
|
||||
switch (c) {
|
||||
case ':': return Colon;
|
||||
case '{': return LeftBrace;
|
||||
case '}': return RightBrace;
|
||||
default:
|
||||
/* Return a single char. */
|
||||
return c;
|
||||
}
|
||||
|
||||
}
|
||||
43
parse/toclexer.h
Normal file
43
parse/toclexer.h
Normal file
@@ -0,0 +1,43 @@
|
||||
/*
|
||||
$Id: toclexer.h,v 1.2 2008/03/23 17:21:34 karl Exp $
|
||||
|
||||
Copyright (C) 2005, 2008 Rocky Bernstein <rocky@gnu.org>
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
/* Common header between TOC lexer and parser. */
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include "string.h"
|
||||
|
||||
typedef int token_t;
|
||||
|
||||
extern FILE *toc_in;
|
||||
|
||||
typedef union {
|
||||
long unsigned int val; /* For returning numbers. */
|
||||
char const *psz_str; /* For strings. */
|
||||
} tocval_t;
|
||||
|
||||
#define YYSTYPE tocval_t
|
||||
|
||||
YYSTYPE toclval;
|
||||
|
||||
/* Call to the TOC scanner */
|
||||
token_t toclex (void);
|
||||
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user