Add the ability to read from a file, move to own directory
This commit is contained in:
parent
28ac6d8331
commit
dc7c3666aa
7
Makefile
7
Makefile
@ -1,9 +1,10 @@
|
||||
CC = g++
|
||||
CFLAGS = -g
|
||||
|
||||
all: cyoa
|
||||
cyoa: cyoa.c
|
||||
all: storybook
|
||||
storybook: main.c cyoa.c
|
||||
$(CC) $(CFLAGS) main.c -o storybook
|
||||
cyoa.c: cyoa.leg
|
||||
leg -o $@ $^
|
||||
clean:
|
||||
rm -f cyoa.c cyoa
|
||||
rm -f cyoa.c cyoa storybook
|
||||
|
34
cyoa.leg
34
cyoa.leg
@ -85,29 +85,27 @@ union value {
|
||||
%}
|
||||
|
||||
|
||||
Story = BlankLine* (p:Page { pages.push_back(p.page); })+ EndOfFile;
|
||||
Story = BlankLine* (p:Page { pages.push_back(p.page); })+ EndOfFile
|
||||
|
||||
Page = h:Header b:Body { $$.page = b.page; $$.page->id = h.string}
|
||||
BlankLine*;
|
||||
BlankLine*
|
||||
|
||||
Header = < i:Identifier > Newline BlankLine* { $$ = i; }
|
||||
|
||||
Identifier = < [A-Z][A-Z0-9_]+ > - { $$.string = strndup(yytext, yyleng); };
|
||||
Identifier = < [A-Z][A-Z0-9_]+ > - { $$.string = strndup(yytext, yyleng); }
|
||||
|
||||
Body = Footer | t:TextLine b:Body { $$ = b; append_body(b.page, t.string);};
|
||||
Body = Footer | t:TextLine b:Body { $$ = b; append_body(b.page, t.string);}
|
||||
|
||||
TextLine = < (!Newline .)* Newline > { $$.string = strndup(yytext, yyleng); };
|
||||
TextLine = < (!Newline .)* Newline > { $$.string = strndup(yytext, yyleng); }
|
||||
|
||||
Footer = Ending { $$.page = emit_ending(); }
|
||||
| g:Goto { $$.page = emit_goto(g.string); }
|
||||
| c:ChoiceList { $$.page = emit_choices(c.choices); }
|
||||
;
|
||||
|
||||
Goto = 'GOTO' - < i:Identifier > Newline
|
||||
{ $$.string = strndup(yytext, yyleng); }
|
||||
;
|
||||
|
||||
Ending = 'THE END' Newline;
|
||||
Ending = 'THE END' Newline
|
||||
|
||||
ChoiceList = c:Choice l:ChoiceList { $$ = l; $$.choices->push_back(c.choice); }
|
||||
| c:Choice { $$.choices = new std::vector<Choice*>(); $$.choices->push_back(c.choice); }
|
||||
@ -117,11 +115,11 @@ Choice = b:Bullet f:Freetext r:Redirect
|
||||
$$ = r;
|
||||
$$.choice->option = b.num;
|
||||
$$.choice->flavor = f.string;
|
||||
};
|
||||
}
|
||||
|
||||
Bullet = < [0-9]+ > ')' - { $$.num = atoi(yytext); };
|
||||
Bullet = < [0-9]+ > ')' - { $$.num = atoi(yytext); }
|
||||
|
||||
Freetext = < ([^[<])+ > { $$.string = strndup(yytext, yyleng); };
|
||||
Freetext = < ([^[<])+ > { $$.string = strndup(yytext, yyleng); }
|
||||
|
||||
Redirect = ck:StatCheck? '[' i:Identifier ']' - cg:StatChange? Newline
|
||||
{ $$.choice = new Choice(i.string, ck.statcheck, cg.statchange); }
|
||||
@ -132,7 +130,7 @@ StatCheck = '<' n:StatName v:StatVal r:StatRel '>' -
|
||||
StatChange = '(' ('+' | '-') v:StatVal n:StatName ')'
|
||||
{ $$.statchange = new statchange_t{n.string, v.num}; }
|
||||
|
||||
StatName = < [A-Za-z]+ > - { $$.string = strdup(yytext); };
|
||||
StatName = < [A-Za-z]+ > - { $$.string = strdup(yytext); }
|
||||
|
||||
StatVal = < [0-9]+ > - { $$.num = atoi(yytext); }
|
||||
|
||||
@ -231,18 +229,6 @@ std::vector<Page*> CyoaParse(FILE *file) {
|
||||
return pages;
|
||||
}
|
||||
|
||||
int main(int argc, char **argv) {
|
||||
if (argc < 2) {
|
||||
return 1;
|
||||
}
|
||||
FILE* fin = fopen(argv[1], "r");
|
||||
auto mypages = CyoaParse(fin);
|
||||
for (Page* page : pages) {
|
||||
print_page(page);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* Local Variables: */
|
||||
/* mode: text */
|
||||
/* End: */
|
||||
|
13
main.c
Normal file
13
main.c
Normal file
@ -0,0 +1,13 @@
|
||||
#include "cyoa.c"
|
||||
|
||||
int main(int argc, char **argv) {
|
||||
if (argc < 2) {
|
||||
return 1;
|
||||
}
|
||||
FILE* fin = fopen(argv[1], "r");
|
||||
auto mypages = CyoaParse(fin);
|
||||
for (Page* page : pages) {
|
||||
print_page(page);
|
||||
}
|
||||
return 0;
|
||||
}
|
Loading…
Reference in New Issue
Block a user