updated main.c

This commit is contained in:
Ur Mom 2024-04-26 16:21:54 +02:00
parent cebe5c5bf4
commit 72bba3278a
1 changed files with 11 additions and 6 deletions

View File

@ -4,6 +4,8 @@
#define LOG_LEVEL LOG_LEVEL_DEBUG #define LOG_LEVEL LOG_LEVEL_DEBUG
extern FILE* yyin;
/** /**
* @brief Log a debug message to inform about beginning exit procedures * @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[]) { int main(int argc, char *argv[]) {
setup(); setup();
atexit(close_file(filename)); atexit(close_file);
// Check for file input as argument // Check for file input as argument
if (2 != argc) if (2 != argc)
@ -58,13 +63,13 @@ int main(int argc, char *argv[]) {
// filename as first argument // filename as first argument
char *filename = argv[1]; char *filename = argv[1];
FILE *file = fopen(filename, "r");
if (NULL == file) if (NULL == file)
{ {
PANIC("File couldn't be opened!"); PANIC("File couldn't be opened!");
} }
yyin = file;
FILE *file = fopen(filename, "r");
*file = yyin;
yyparse(); yyparse();