The commit where I moved everything

This commit is contained in:
Dane Johnson 2021-12-31 13:07:59 -06:00
parent 58187bbff0
commit 6aba0d0227
11 changed files with 62 additions and 60 deletions

6
.gitignore vendored
View File

@ -1,4 +1,4 @@
*.o *.o
storybook storybook-cli
src/storybook src/cli/storybook-cli
src/cyoa.cpp src/base/cyoa.cpp

View File

@ -1,8 +1,8 @@
.PHONY: all clean storybook .PHONY: all clean storybook-cli
all: storybook all: storybook-cli
storybook: storybook-cli:
$(MAKE) -C src storybook $(MAKE) -C src all
cp src/storybook storybook cp src/cli/storybook-cli storybook-cli
clean: clean:
rm -f storybook rm -f storybook-cli
$(MAKE) -C src clean $(MAKE) -C src clean

View File

@ -1,9 +1,9 @@
CXXFLAGS = -g .PHONY: all base cli clean
OBJS = cyoa.o all: base cli
base:
all: storybook $(MAKE) -C base
storybook: storybook.cpp cyoa.o cli:
cyoa.cpp: cyoa.leg $(MAKE) -C cli
leg -o $@ $^
clean: clean:
rm -f cyoa.c $(OBJS) storybook $(MAKE) -C base clean
$(MAKE) -C cli clean

8
src/base/Makefile Normal file
View File

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

View File

@ -4,40 +4,10 @@
#include "storybook.h" #include "storybook.h"
void usage(const char* bin) {
fprintf(stderr, "Usage: %s <storyfile>", 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) { Storybook::Storybook(FILE* fin) {
pages = CyoaParse(fin); pages = CyoaParse(fin);
} }
void Storybook::Find(const char* id) { void Storybook::Find(const char* id) {
for (Page* page : pages) { for (Page* page : pages) {
if (strcmp(page->id, id) == 0) { if (strcmp(page->id, id) == 0) {

5
src/cli/Makefile Normal file
View File

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

32
src/cli/storybook_cli.cpp Normal file
View File

@ -0,0 +1,32 @@
#include <cstdio>
#include <cstdlib>
#include "../base/storybook.h"
void usage(const char* bin) {
fprintf(stderr, "Usage: %s <storyfile>", 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;
}

View File

@ -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;
}