diff --git a/.gitignore b/.gitignore index 4370f81..8c854d1 100644 --- a/.gitignore +++ b/.gitignore @@ -1,4 +1,4 @@ *.o -storybook -src/storybook -src/cyoa.cpp \ No newline at end of file +storybook-cli +src/cli/storybook-cli +src/base/cyoa.cpp \ No newline at end of file diff --git a/Makefile b/Makefile index 8b0bdb4..cd38382 100644 --- a/Makefile +++ b/Makefile @@ -1,8 +1,8 @@ -.PHONY: all clean storybook -all: storybook -storybook: - $(MAKE) -C src storybook - cp src/storybook storybook +.PHONY: all clean storybook-cli +all: storybook-cli +storybook-cli: + $(MAKE) -C src all + cp src/cli/storybook-cli storybook-cli clean: - rm -f storybook + rm -f storybook-cli $(MAKE) -C src clean diff --git a/src/Makefile b/src/Makefile index 73dda3c..11bdfe0 100644 --- a/src/Makefile +++ b/src/Makefile @@ -1,9 +1,9 @@ -CXXFLAGS = -g -OBJS = cyoa.o - -all: storybook -storybook: storybook.cpp cyoa.o -cyoa.cpp: cyoa.leg - leg -o $@ $^ +.PHONY: all base cli clean +all: base cli +base: + $(MAKE) -C base +cli: + $(MAKE) -C cli clean: - rm -f cyoa.c $(OBJS) storybook + $(MAKE) -C base clean + $(MAKE) -C cli clean diff --git a/src/base/Makefile b/src/base/Makefile new file mode 100644 index 0000000..3ba0032 --- /dev/null +++ b/src/base/Makefile @@ -0,0 +1,8 @@ +CXXFLAGS = -g +OBJS = cyoa.o storybook.o + +all: $(OBJS) +cyoa.cpp: cyoa.leg + leg -o $@ $^ +clean: + rm -f cyoa.c $(OBJS) diff --git a/src/cyoa.h b/src/base/cyoa.h similarity index 100% rename from src/cyoa.h rename to src/base/cyoa.h diff --git a/src/cyoa.leg b/src/base/cyoa.leg similarity index 100% rename from src/cyoa.leg rename to src/base/cyoa.leg diff --git a/src/storybook.cpp b/src/base/storybook.cpp similarity index 72% rename from src/storybook.cpp rename to src/base/storybook.cpp index 0eefcf8..48e34cc 100644 --- a/src/storybook.cpp +++ b/src/base/storybook.cpp @@ -4,40 +4,10 @@ #include "storybook.h" -void usage(const char* bin) { - fprintf(stderr, "Usage: %s ", bin); - exit(1); -} - -int main(int argc, const char *argv[]) { - if (argc != 2) { - usage(argv[0]); - } - - FILE *fin = fopen(argv[1], "r"); - if (!fin) { - fprintf(stderr, "Error: could not read %s", argv[1]); - return 2; - } - Storybook sb(fin); - fclose(fin); - - sb.Find("START"); - sb.Play(); - - while (!sb.IsEnded) { - sb.Play(); - } - - return 0; -} - - Storybook::Storybook(FILE* fin) { pages = CyoaParse(fin); } - void Storybook::Find(const char* id) { for (Page* page : pages) { if (strcmp(page->id, id) == 0) { diff --git a/src/storybook.h b/src/base/storybook.h similarity index 100% rename from src/storybook.h rename to src/base/storybook.h diff --git a/src/cli/Makefile b/src/cli/Makefile new file mode 100644 index 0000000..2b64afc --- /dev/null +++ b/src/cli/Makefile @@ -0,0 +1,5 @@ +CXXFLAGS = -g -L../base/ +.PHONY: all clean +all: storybook-cli +storybook-cli: storybook_cli.cpp + $(CXX) $(CXXFLAGS) -o $@ $^ ../base/storybook.o ../base/cyoa.o diff --git a/src/cli/storybook_cli.cpp b/src/cli/storybook_cli.cpp new file mode 100644 index 0000000..2651fad --- /dev/null +++ b/src/cli/storybook_cli.cpp @@ -0,0 +1,32 @@ +#include +#include + +#include "../base/storybook.h" + +void usage(const char* bin) { + fprintf(stderr, "Usage: %s ", bin); + exit(1); +} + +int main(int argc, const char *argv[]) { + if (argc != 2) { + usage(argv[0]); + } + + FILE *fin = fopen(argv[1], "r"); + if (!fin) { + fprintf(stderr, "Error: could not read %s", argv[1]); + return 2; + } + Storybook sb(fin); + fclose(fin); + + sb.Find("START"); + sb.Play(); + + while (!sb.IsEnded) { + sb.Play(); + } + + return 0; +} diff --git a/src/main.c b/src/main.c deleted file mode 100644 index a95fda4..0000000 --- a/src/main.c +++ /dev/null @@ -1,13 +0,0 @@ -#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; -}