diff options
Diffstat (limited to 'src/main.c')
-rw-r--r-- | src/main.c | 17 |
1 files changed, 14 insertions, 3 deletions
@@ -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); |