Update main.c

added File Insertion through arguments
This commit is contained in:
SirTalksalot75 2024-04-23 14:25:49 +02:00 committed by GitHub
parent 67efb13fe4
commit 7797595fef
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
1 changed files with 16 additions and 7 deletions

View File

@ -4,8 +4,6 @@
#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
* *
@ -42,16 +40,27 @@ void setup(void)
void close_file(void) void close_file(void)
{ {
fclose(yyin); fclose(argv[1]);
} }
int main(void) { int main(int argc, char *argv[]) {
setup(); setup();
atexit(close_file); atexit(close_file);
FILE* input = fopen("program.gem", "r");
if (NULL == input) // Check for file input as argument
if (2 != argc)
{
printf("Usage: %s <filename>\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!"); PANIC("File couldn't be opened!");
} }