commit 3a71b23e11df84aa6a8a9121e111e1431f7af8bf
parent 3f4d63ea58373d2f6ffa194d5178ce52a7e5b994
Author: Christian Ermann <christianermann@gmail.com>
Date: Tue, 22 Oct 2024 23:32:14 -0700
Make input file a command line argument
Diffstat:
2 files changed, 8 insertions(+), 5 deletions(-)
diff --git a/Makefile b/Makefile
@@ -2,7 +2,7 @@ all:
gcc src/* -Iinclude -lm -o gcode-interpreter
run: all
- ./gcode-interpreter
+ ./gcode-interpreter CE3E3V2_3DBenchy.gcode
.PHONY: clean
clean:
diff --git a/src/main.c b/src/main.c
@@ -123,18 +123,21 @@ int main(int argc, char** argv) {
freopen("error.log", "w", stderr);
initialize_terminal();
- const char* filename = "CE3E3V2_3DBenchy.gcode";
+ if (argc < 2) {
+ fprintf(stderr, "! []: input filename must be provided.\n");
+ return -1;
+ }
- FILE* file = fopen(filename, "r");
+ FILE* file = fopen(argv[1], "r");
if (file == NULL) {
- fprintf(stderr, "! [%s]: %s\n", filename, strerror(errno));
+ fprintf(stderr, "! [%s]: %s\n", argv[1], strerror(errno));
return -1;
}
const char* output_filename = "out";
FILE* output_file = fopen(output_filename, "w");
if (output_file == NULL) {
- fprintf(stderr, "! [%s]: %s\n", filename, strerror(errno));
+ fprintf(stderr, "! [%s]: %s\n", output_filename, strerror(errno));
return -1;
}