From 8f984bb2f075e56fd4729cc3ead24dbeb1afbf7d Mon Sep 17 00:00:00 2001 From: Lukas Krickl Date: Sat, 9 Dec 2023 22:40:55 +0100 Subject: [PATCH] Added -i option for include path management --- include/ulas.h | 8 ++++---- src/main.c | 18 +++++++++++++++++- src/ulas.c | 4 ++-- 3 files changed, 23 insertions(+), 7 deletions(-) diff --git a/include/ulas.h b/include/ulas.h index c57f73a..575d284 100644 --- a/include/ulas.h +++ b/include/ulas.h @@ -102,6 +102,10 @@ struct ulas_config { int verbose; int preproc_only; + + // all include search paths + char **incpaths; + int incpathslen; }; /** @@ -231,10 +235,6 @@ struct ulas { // internal counter // used whenever a new unique number might be needed int icntr; - - // all include search paths - char **include_paths; - int include_paths_len; }; extern struct ulas ulas; diff --git a/src/main.c b/src/main.c index d801c9b..e7484df 100644 --- a/src/main.c +++ b/src/main.c @@ -1,5 +1,6 @@ #include #include +#include #include #include "ulas.h" #include @@ -12,10 +13,15 @@ #define ULAS_OPTS "hvVp" // args with value -#define ULAS_OPTS_ARG "o:l:s:" +#define ULAS_OPTS_ARG "o:l:s:i:" #define ULAS_HELP(a, desc) printf("\t-%s\t%s\n", (a), desc); +#define ULAS_INCPATHSMAX 256 + +const char *incpaths[ULAS_INCPATHSMAX]; +long incpathslen = 0; + void ulas_help(void) { printf("%s\n", ULAS_NAME); printf("Usage %s [-%s] [-o=path] [input]\n\n", ULAS_NAME, ULAS_OPTS); @@ -26,6 +32,7 @@ void ulas_help(void) { ULAS_HELP("o=path", "Output file"); ULAS_HELP("l=path", "Listing file"); ULAS_HELP("s=path", "Symbols file"); + ULAS_HELP("i=path", "Add include search path"); } void ulas_version(void) { printf("%s version %s\n", ULAS_NAME, ULAS_VER); } @@ -57,6 +64,9 @@ void ulas_getopt(int argc, char **argv, struct ulas_config *cfg) { case 'l': cfg->lst_path = strndup(optarg, ULAS_PATHMAX); break; + case 'i': + assert(incpathslen < ULAS_INCPATHSMAX); + incpaths[incpathslen++] = strndup(optarg, ULAS_PATHMAX); case '?': break; default: @@ -76,6 +86,8 @@ int main(int argc, char **argv) { struct ulas_config cfg = ulas_cfg_from_env(); ulas_getopt(argc, argv, &cfg); + cfg.incpaths = incpaths; + cfg.incpathslen = incpathslen; int res = ulas_main(cfg); @@ -91,5 +103,9 @@ int main(int argc, char **argv) { free(cfg.lst_path); } + for (int i = 0; i < incpathslen; i++) { + free(incpaths[i]); + } + return res; } diff --git a/src/ulas.c b/src/ulas.c index 43c253c..3989b5a 100644 --- a/src/ulas.c +++ b/src/ulas.c @@ -68,9 +68,9 @@ FILE *ulas_incpathfopen(const char *path, const char *mode) { int baselen = strlen(path); // check all include paths - for (int i = 0; i < ulas.include_paths_len; i++) { + for (int i = 0; i < ulascfg.incpathslen; i++) { pathbuf[0] = '\0'; - char *ip = ulas.include_paths[i]; + char *ip = ulascfg.incpaths[i]; int len = strlen(ip); if (len + baselen + 1 >= ULAS_PATHMAX) { continue; -- 2.30.2