From 7797595fef71fa52efbbad7566f9a9666926da4e Mon Sep 17 00:00:00 2001 From: SirTalksalot75 <132705706+SirTalksalot75@users.noreply.github.com> Date: Tue, 23 Apr 2024 14:25:49 +0200 Subject: [PATCH] Update main.c added File Insertion through arguments --- src/main.c | 23 ++++++++++++++++------- 1 file changed, 16 insertions(+), 7 deletions(-) diff --git a/src/main.c b/src/main.c index f96edf3..d96e0fd 100644 --- a/src/main.c +++ b/src/main.c @@ -4,8 +4,6 @@ #define LOG_LEVEL LOG_LEVEL_DEBUG -extern FILE* yyin; - /** * @brief Log a debug message to inform about beginning exit procedures * @@ -42,16 +40,27 @@ void setup(void) void close_file(void) { - fclose(yyin); + fclose(argv[1]); } -int main(void) { +int main(int argc, char *argv[]) { + setup(); atexit(close_file); - - FILE* input = fopen("program.gem", "r"); - if (NULL == input) + // Check for file input as argument + if (2 != argc) + { + printf("Usage: %s \n", argv[0]); + PANIC("No File could be found"); + } + + // filename as first argument + char *filename = argv[1]; + + FILE *file = fopen(filename, "r"); + + if (NULL == file) { PANIC("File couldn't be opened!"); }