From 027b54d0872eeb69a039fecef4e75a9f0123923a Mon Sep 17 00:00:00 2001 From: Ur Mom Date: Tue, 14 May 2024 22:32:44 +0200 Subject: [PATCH] Second commit --- src/main.c | 50 +++++++++++++++++++++++++++++++++++++++++++------- 1 file changed, 43 insertions(+), 7 deletions(-) diff --git a/src/main.c b/src/main.c index 70fc423..c9eda55 100644 --- a/src/main.c +++ b/src/main.c @@ -7,19 +7,44 @@ extern FILE *yyin; +// Global array to store options +char options[5][10]; +int num_options = 0; + /** * @brief Log a debug message to inform about beginning exit procedures * */ void notify_exit(void) { DEBUG("Exiting gemstone..."); } + +/** + * @brief add option to global option array + * + */ + +void add_option(const char* option) { + if (num_options < 5 ) { + strcpy(options[num_options], option); + num_options++; + } else { + PANIC("Too Many Options given"); + } +} + +/** + * @brief Check if Option is set + * + */ + size_t check_option(const char* name) { -if (0 != name){ - return 1; -} else { - return 0; -}; -}; + for (int i = 0; i < num_options; i++) { + if (strcmp(options[i], name) == 0) { + return 1; + } + } + return 0; +} /** * @brief Closes File after compiling. @@ -38,7 +63,6 @@ void close_file(void) { */ void setup(void) { // setup preample - log_init(); DEBUG("starting gemstone..."); @@ -54,6 +78,18 @@ void setup(void) { int main(int argc, char *argv[]) { + // Iteration through arguments + for (int i = 1; i < argc; i++) { + // Check if the argument starts with "--" + if (argv[i][0] == '-' && argv[i][1] == '-') { + // Extract option name + char option[10]; + strcpy(option, argv[i] + 2); + + // Add option to the global array + add_option(option); + } + } setup(); atexit(close_file);