summaryrefslogtreecommitdiff
path: root/src/main.c
diff options
context:
space:
mode:
authorTyler Murphy <tylerm@tylerm.dev>2023-04-14 15:15:10 -0400
committerTyler Murphy <tylerm@tylerm.dev>2023-04-14 15:15:10 -0400
commitd7ecc6b9efc8e8ebb032678cacb8d532b2331902 (patch)
treedc2292a212e8fefcded4652808c88025ccc4bb2f /src/main.c
parentuse correct dumb variable name (diff)
downloadbrainfucked-d7ecc6b9efc8e8ebb032678cacb8d532b2331902.tar.gz
brainfucked-d7ecc6b9efc8e8ebb032678cacb8d532b2331902.tar.bz2
brainfucked-d7ecc6b9efc8e8ebb032678cacb8d532b2331902.zip
allow stdin
Diffstat (limited to '')
-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);