summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDavid Phillips <david@sighup.nz>2017-12-28 19:27:15 +1300
committerDavid Phillips <david@sighup.nz>2017-12-28 19:27:15 +1300
commit4064bc9ea637563f4b579ed61baa882a4c0ed39d (patch)
tree6dab5c9a60cd73b6ef8bff0d3b168c1ea5c1e56a
parent22d2cb0a71b22c3142cc073b7ceca976d7a513c1 (diff)
downloadhence-4064bc9ea637563f4b579ed61baa882a4c0ed39d.tar.xz
Refactor main from parser to simulator
-rw-r--r--Makefile6
-rw-r--r--parser.c18
-rw-r--r--simulator.c21
3 files changed, 23 insertions, 22 deletions
diff --git a/Makefile b/Makefile
index cc75e79..a41403f 100644
--- a/Makefile
+++ b/Makefile
@@ -1,10 +1,8 @@
CFLAGS += -std=c99 -D_XOPEN_SOURCE=500 -Wall -Wextra
-all: simulator parser
+all: simulator
-simulator: simulator.o gate.o logic.o
-
-parser: parser.o gate.o logic.o
+simulator: simulator.o gate.o logic.o parser.o
.PHONY: test
test:
diff --git a/parser.c b/parser.c
index dc1e9a9..0e9a90b 100644
--- a/parser.c
+++ b/parser.c
@@ -179,21 +179,3 @@ parse_line(char *line) {
return 0;
}
-int main(void) {
- char buf[4096];
- FILE *fd = stdin;
-
- while (NULL != fgets(buf, sizeof(buf), fd)) {
- buf[strcspn(buf, "\r\n")] = '\0';
- if (parse_line(buf)) {
- return 1;
- }
- }
-
- gate_set_input("a", LOGIC_LOW);
- gate_set_input("b", LOGIC_LOW);
- gate_update();
- gate_dump();
-
- return 0;
-}
diff --git a/simulator.c b/simulator.c
index d89ceb0..657355f 100644
--- a/simulator.c
+++ b/simulator.c
@@ -1,10 +1,31 @@
+#include <stdio.h>
+#include <string.h>
+
#include "gate.h"
#include "logic.h"
+#include "parser.h"
int main(int argc, char **argv) {
+ char buf[4096];
+ FILE *fd = stdin;
+
(void)argc;
(void)argv;
+
logic_test();
gate_init();
+
+ while (NULL != fgets(buf, sizeof(buf), fd)) {
+ buf[strcspn(buf, "\r\n")] = '\0';
+ if (parse_line(buf)) {
+ return 1;
+ }
+ }
+
+ gate_set_input("a", LOGIC_LOW);
+ gate_set_input("b", LOGIC_LOW);
+ gate_update();
+ gate_dump();
+
return 0;
}