From e90cd80fbef33e87337c61de8e09ca754bf42b9b Mon Sep 17 00:00:00 2001 From: SirTalksalot75 <132705706+SirTalksalot75@users.noreply.github.com> Date: Sun, 21 Apr 2024 22:48:29 +0200 Subject: [PATCH 01/13] added prototype for File-reading to main.c --- src/main.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/main.c b/src/main.c index 8bb8127..3c1edd2 100644 --- a/src/main.c +++ b/src/main.c @@ -35,6 +35,10 @@ void setup(void) int main(void) { setup(); + + FILE* input = fopen("program.gem", "r"); + + yyin = input; yyparse(); return 0; From 1cfe9485e9fb0a65fee9f39f1851ad18b9452094 Mon Sep 17 00:00:00 2001 From: SirTalksalot75 <132705706+SirTalksalot75@users.noreply.github.com> Date: Mon, 22 Apr 2024 11:51:27 +0200 Subject: [PATCH 02/13] added case for missing input of file to main.c --- src/main.c | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/main.c b/src/main.c index 3c1edd2..a152df0 100644 --- a/src/main.c +++ b/src/main.c @@ -38,8 +38,16 @@ int main(void) { FILE* input = fopen("program.gem", "r"); + if (input == NULL) + { + printf("Error opening file!\n"); + return 1; // Error when opening file + } + yyin = input; + fclose(input); + yyparse(); return 0; } From 6fca12df390908837f93b190764ed97be5ed4540 Mon Sep 17 00:00:00 2001 From: SirTalksalot75 <132705706+SirTalksalot75@users.noreply.github.com> Date: Mon, 22 Apr 2024 12:53:48 +0200 Subject: [PATCH 03/13] modified main.c -added Error-message from Logging API. -changed exit and moved after yyparse() -added extern for file name todo: make file name user input variable. --- src/main.c | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/src/main.c b/src/main.c index a152df0..89c214f 100644 --- a/src/main.c +++ b/src/main.c @@ -4,6 +4,8 @@ #define LOG_LEVEL LOG_LEVEL_DEBUG +extern FILE* yyin; + /** * @brief Log a debug message to inform about beginning exit procedures * @@ -38,10 +40,10 @@ int main(void) { FILE* input = fopen("program.gem", "r"); - if (input == NULL) + if (NULL == Input) { - printf("Error opening file!\n"); - return 1; // Error when opening file + ERROR("File couldn't be opened!"); + atexit(); } yyin = input; @@ -49,5 +51,7 @@ int main(void) { fclose(input); yyparse(); + + atexit(); return 0; } From 6d249dd9ea1ff742acd2a59153d18854f64eb3c5 Mon Sep 17 00:00:00 2001 From: SirTalksalot75 <132705706+SirTalksalot75@users.noreply.github.com> Date: Mon, 22 Apr 2024 12:54:20 +0200 Subject: [PATCH 04/13] Update main.c deleted fclose() --- src/main.c | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/main.c b/src/main.c index 89c214f..a24eb7a 100644 --- a/src/main.c +++ b/src/main.c @@ -48,8 +48,6 @@ int main(void) { yyin = input; - fclose(input); - yyparse(); atexit(); From 4976aeb22f19ed0effd87bcbe5f34dafe5107c43 Mon Sep 17 00:00:00 2001 From: SirTalksalot75 <132705706+SirTalksalot75@users.noreply.github.com> Date: Mon, 22 Apr 2024 12:57:49 +0200 Subject: [PATCH 05/13] Update main.c fixed typo --- src/main.c | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/src/main.c b/src/main.c index a24eb7a..f5d242a 100644 --- a/src/main.c +++ b/src/main.c @@ -40,16 +40,15 @@ int main(void) { FILE* input = fopen("program.gem", "r"); - if (NULL == Input) + if (NULL == input) { ERROR("File couldn't be opened!"); - atexit(); } yyin = input; yyparse(); - atexit(); + atexit(input); return 0; } From 05d603f7ac3b48fc267ab8f9d06931750f3be7e2 Mon Sep 17 00:00:00 2001 From: SirTalksalot75 <132705706+SirTalksalot75@users.noreply.github.com> Date: Mon, 22 Apr 2024 13:41:37 +0200 Subject: [PATCH 06/13] Update main.c added Function for file closing --- src/main.c | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/src/main.c b/src/main.c index f5d242a..6617ed8 100644 --- a/src/main.c +++ b/src/main.c @@ -31,12 +31,23 @@ void setup(void) #endif // actual setup - + DEBUG("finished starting up gemstone..."); } +/** + * @brief Closes File after compiling. + * + */ + +void close_file(void) +{ + fclose(input); +} + int main(void) { setup(); + atexit(close_file); FILE* input = fopen("program.gem", "r"); @@ -49,6 +60,5 @@ int main(void) { yyparse(); - atexit(input); return 0; } From a85558e118cda0bdec393a16a1898179c443cafe Mon Sep 17 00:00:00 2001 From: SirTalksalot75 <132705706+SirTalksalot75@users.noreply.github.com> Date: Mon, 22 Apr 2024 14:01:18 +0200 Subject: [PATCH 07/13] Update main.c changed close_file Function changed ERROR to PANIC --- src/main.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/main.c b/src/main.c index 6617ed8..f96edf3 100644 --- a/src/main.c +++ b/src/main.c @@ -42,7 +42,7 @@ void setup(void) void close_file(void) { - fclose(input); + fclose(yyin); } int main(void) { @@ -53,7 +53,7 @@ int main(void) { if (NULL == input) { - ERROR("File couldn't be opened!"); + PANIC("File couldn't be opened!"); } yyin = input; 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 08/13] 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!"); } From dad9cbb93a3966d2a91d4d4dae4efb0a81fea435 Mon Sep 17 00:00:00 2001 From: SirTalksalot75 <132705706+SirTalksalot75@users.noreply.github.com> Date: Tue, 23 Apr 2024 14:32:00 +0200 Subject: [PATCH 09/13] Update main.c fixed typo --- src/main.c | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/main.c b/src/main.c index d96e0fd..bbcf14b 100644 --- a/src/main.c +++ b/src/main.c @@ -64,8 +64,6 @@ int main(int argc, char *argv[]) { { PANIC("File couldn't be opened!"); } - - yyin = input; yyparse(); From fafcb942e02c8967c47cd7f88c9114463701e2d9 Mon Sep 17 00:00:00 2001 From: SirTalksalot75 <132705706+SirTalksalot75@users.noreply.github.com> Date: Tue, 23 Apr 2024 14:38:30 +0200 Subject: [PATCH 10/13] Update main.c fixed typo, and changed close_file function --- src/main.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/main.c b/src/main.c index bbcf14b..dd9dde2 100644 --- a/src/main.c +++ b/src/main.c @@ -38,15 +38,15 @@ void setup(void) * */ -void close_file(void) +void close_file(char file_to_close) { - fclose(argv[1]); + fclose(file_to_close); } int main(int argc, char *argv[]) { setup(); - atexit(close_file); + atexit(close_file(filename); // Check for file input as argument if (2 != argc) From 520520e576b052645226c1ed3f5c1ea836c68be5 Mon Sep 17 00:00:00 2001 From: SirTalksalot75 <132705706+SirTalksalot75@users.noreply.github.com> Date: Tue, 23 Apr 2024 15:27:11 +0200 Subject: [PATCH 11/13] Update main.c moved atexit() to setup --- src/main.c | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/src/main.c b/src/main.c index dd9dde2..db22990 100644 --- a/src/main.c +++ b/src/main.c @@ -13,6 +13,16 @@ void notify_exit(void) DEBUG("Exiting gemstone..."); } +/** + * @brief Closes File after compiling. + * + */ + +void close_file(char file_to_close) +{ + fclose(file_to_close); +} + /** * @brief Run compiler setup here * @@ -31,27 +41,17 @@ void setup(void) // actual setup DEBUG("finished starting up gemstone..."); -} - -/** - * @brief Closes File after compiling. - * - */ - -void close_file(char file_to_close) -{ - fclose(file_to_close); + atexit(close_file(filename)); } int main(int argc, char *argv[]) { setup(); - atexit(close_file(filename); // Check for file input as argument if (2 != argc) { - printf("Usage: %s \n", argv[0]); + INFO("Usage: %s \n", argv[0]); PANIC("No File could be found"); } From 5f53d1dce46555d9ffc403078d24a7197735deb9 Mon Sep 17 00:00:00 2001 From: SirTalksalot75 <132705706+SirTalksalot75@users.noreply.github.com> Date: Thu, 25 Apr 2024 14:02:12 +0200 Subject: [PATCH 12/13] Update main.c changed indendation and declared and initialized yyin after file opening --- src/main.c | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/src/main.c b/src/main.c index db22990..04ab464 100644 --- a/src/main.c +++ b/src/main.c @@ -41,13 +41,13 @@ void setup(void) // actual setup DEBUG("finished starting up gemstone..."); - atexit(close_file(filename)); } int main(int argc, char *argv[]) { setup(); - + atexit(close_file(filename)); + // Check for file input as argument if (2 != argc) { @@ -58,13 +58,14 @@ int main(int argc, char *argv[]) { // filename as first argument char *filename = argv[1]; - FILE *file = fopen(filename, "r"); - if (NULL == file) { PANIC("File couldn't be opened!"); } + FILE *file = fopen(filename, "r"); + *file = yyin; + yyparse(); return 0; From 72bba3278aaa4860bedc0369afc15182a72eaacd Mon Sep 17 00:00:00 2001 From: Ur Mom Date: Fri, 26 Apr 2024 16:21:54 +0200 Subject: [PATCH 13/13] updated main.c --- src/main.c | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/src/main.c b/src/main.c index 04ab464..38cf9c9 100644 --- a/src/main.c +++ b/src/main.c @@ -4,6 +4,8 @@ #define LOG_LEVEL LOG_LEVEL_DEBUG +extern FILE* yyin; + /** * @brief Log a debug message to inform about beginning exit procedures * @@ -18,9 +20,12 @@ void notify_exit(void) * */ -void close_file(char file_to_close) +void close_file(void) { - fclose(file_to_close); + if (NULL != yyin) + { + fclose(yyin); + } } /** @@ -46,7 +51,7 @@ void setup(void) int main(int argc, char *argv[]) { setup(); - atexit(close_file(filename)); + atexit(close_file); // Check for file input as argument if (2 != argc) @@ -58,13 +63,13 @@ int main(int argc, char *argv[]) { // filename as first argument char *filename = argv[1]; + FILE *file = fopen(filename, "r"); + if (NULL == file) { PANIC("File couldn't be opened!"); } - - FILE *file = fopen(filename, "r"); - *file = yyin; + yyin = file; yyparse();