From d46e7b662d62cfe5e71945f4ebffa000524d029c Mon Sep 17 00:00:00 2001 From: "ALI Mohammadiyeh (Max Base)" Date: Sat, 28 Dec 2024 12:16:41 +0100 Subject: [PATCH] Add header for funcs in main --- src/main.c | 159 +++++++++++++++++++++++++++++++++-------------------- 1 file changed, 100 insertions(+), 59 deletions(-) diff --git a/src/main.c b/src/main.c index b073d95c..e36b6028 100644 --- a/src/main.c +++ b/src/main.c @@ -25,7 +25,7 @@ /** * - * @function lint + * @function lint_do * @brief Linting the given content and parameters * @params {bool} isCode - Whether the content is code or file * @params {const char*} path - Path of the file @@ -34,7 +34,7 @@ * @returns {void} * */ -void lint(bool isCode, const char *path, char *content, char *build_file) { +void lint_do(bool isCode, const char *path, char *content, char *build_file) { DEBUG_ME; lexer_t *lexer = lexer_create(path, content); @@ -165,12 +165,12 @@ void help(char *app) { } /** - * + * * @function update * @brief Update and download new version * @params {void} * @returns {void} - * + * */ void update() { @@ -205,86 +205,127 @@ void update() /** * - * @function doargs - * @brief Handle command line arguments + * @function lint + * @brief Lint a file or code based on arguments * @params {int} argc - Number of arguments * @params {char**} argv - Array of arguments * @returns {void} * */ -void doargs(int argc, char **argv) { - DEBUG_ME; - if (argc < 2) { - help(argv[0]); +void lint(int argc, char **argv) { + const char *path = argv[1]; + if (argc <= 2) { + error(1, "Usage: %s lint \n", argv[0]); } - const char *path = argv[1]; - // printf("path: %s\n", path); - // printf("Argc: %d\n", argc); + if (strcmp(argv[2], "code") == 0) { + if (argc <= 3) { + error(1, "Usage: %s lint code \n", argv[0]); + } - if (strcmp(path, "version") == 0) { - printf("Salam %s\n", SALAM_VERSION); - exit(1); - } else if (strcmp(path, "help") == 0) { - help(argv[0]); - } else if (strcmp(path, "update") == 0) { - update(); - } else if (strcmp(path, "lint") == 0) { - if (argc <= 2) { - error(1, "Usage: %s lint \n", argv[0]); + char *content = argv[3]; + + lint_do(true, "stdin", content, NULL); + } else { + if (!file_exists(argv[2])) { + error(1, "File does not exist: %s\n", argv[2]); } - if (strcmp(argv[2], "code") == 0) { - if (argc <= 3) { - error(1, "Usage: %s lint code \n", argv[0]); - } + if (argc <= 3) { + error(1, "Usage: %s lint \n", argv[0]); + } - char *content = argv[3]; + char *content = file_reads_binary(path, NULL); - lint(true, "stdin", content, NULL); - } else { - if (!file_exists(argv[2])) { - error(1, "File does not exist: %s\n", argv[2]); - } + char *output_file = argv[3]; - if (argc <= 3) { - error(1, "Usage: %s lint \n", argv[0]); - } + lint_do(false, path, content, output_file); - char *content = file_reads_binary(path, NULL); + memory_destroy(content); + } +} - char *output_file = argv[3]; +/** + * + * @function code + * @brief Execute code content + * @params {int} argc - Number of arguments + * @params {char**} argv - Array of arguments + * @returns {void} + * + */ +void code(int argc, char **argv) +{ + if (argc <= 2) { + error(1, "Usage: %s code \n", argv[0]); + } - lint(false, path, content, output_file); + char *content = argv[2]; - memory_destroy(content); - } - } else if (strcmp(path, "code") == 0) { - if (argc <= 2) { - error(1, "Usage: %s code \n", argv[0]); - } + char *output_dir = argv[3]; + + run(true, "stdin", content, output_dir); +} - char *content = argv[2]; +/** + * + * @function execute + * @brief Execute a file + * @params {int} argc - Number of arguments + * @params {char**} argv - Array of arguments + * @returns {void} + * + */ +void execute(int argc, char** argv) +{ + const char *path = argv[1]; + if (!file_exists(path)) { + error(1, "File does not exist: %s\n", path); + } - char *output_dir = argv[3]; + char *content = file_reads_binary(path, NULL); - run(true, "stdin", content, output_dir); - } else { - if (!file_exists(path)) { - error(1, "File does not exist: %s\n", path); - } + char *output_dir = NULL; - char *content = file_reads_binary(path, NULL); + if (argc >= 3) { + output_dir = argv[2]; + } - char *output_dir = NULL; + run(false, path, content, output_dir); - if (argc >= 3) { - output_dir = argv[2]; - } + memory_destroy(content); +} + +/** + * + * @function doargs + * @brief Handle command line arguments + * @params {int} argc - Number of arguments + * @params {char**} argv - Array of arguments + * @returns {void} + * + */ +void doargs(int argc, char **argv) { + DEBUG_ME; + if (argc < 2) { + help(argv[0]); + } - run(false, path, content, output_dir); + const char *path = argv[1]; - memory_destroy(content); + if (strcmp(path, "version") == 0) { + printf("Salam %s\n", SALAM_VERSION); + exit(1); + } else if (strcmp(path, "help") == 0) { + help(argv[0]); + } else if (strcmp(path, "update") == 0) { + update(argc, argv); + } else if (strcmp(path, "lint") == 0) { + lint(argc, argv); + } else if (strcmp(path, "code") == 0) { + code(argc, argv); + } else { + execute(argc, argv); } }