summaryrefslogtreecommitdiff
path: root/src/main.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/main.c')
-rw-r--r--src/main.c17
1 files changed, 14 insertions, 3 deletions
diff --git a/src/main.c b/src/main.c
index ac5e0f7..20134cd 100644
--- a/src/main.c
+++ b/src/main.c
@@ -25,13 +25,24 @@
/// % Clear screen
int main(int argc, char** argv) {
- if (argc != 2) {
+
+ FILE* file;
+
+ if (argc == 1) {
+ file = stdin;
+ } else if (argc == 2) {
+ file = fopen (argv[1], "r");
+ if (file == NULL) {
+ printf("error: failed to open %s (%s)\n", argv[1], strerror(errno));
+ exit(EXIT_FAILURE);
+ }
+ } else {
printf("usage: brainfucked infile\n");
return EXIT_FAILURE;
}
-
+
Program program;
- program_init(argv[1], &program);
+ program_init(file, &program);
run_program(&program);
program_free(&program);