diff options
| author | Zuhaitz Méndez Fernández de Aránguiz <zuhaitz@debian> | 2026-01-13 12:04:39 +0000 |
|---|---|---|
| committer | Zuhaitz Méndez Fernández de Aránguiz <zuhaitz@debian> | 2026-01-13 12:04:39 +0000 |
| commit | d561a63d8b5f6beadca30ab7b7846b387d67929a (patch) | |
| tree | 0ea1f420e84c310e17fda97fe6a82c99f7bc843f | |
| parent | ec9797df2a589d0a8cd36beb632956a1ec1f6bfc (diff) | |
Fix for #26
| -rw-r--r-- | README.md | 8 | ||||
| -rw-r--r-- | src/utils/utils.c | 47 |
2 files changed, 50 insertions, 5 deletions
@@ -46,6 +46,14 @@ zc build hello.zc -o hello zc repl ``` +### Environment Variables + +You can set `ZC_ROOT` to specify the location of the Standard Library (standard imports like `import "std/vector.zc"`). This allows you to run `zc` from any directory. + +```bash +export ZC_ROOT=/path/to/Zen-C +``` + --- ## Language Reference diff --git a/src/utils/utils.c b/src/utils/utils.c index 5f41f44..9e9c91c 100644 --- a/src/utils/utils.c +++ b/src/utils/utils.c @@ -490,6 +490,28 @@ char *load_file(const char *fn) FILE *f = fopen(fn, "rb"); if (!f) { + char *root = getenv("ZC_ROOT"); + if (root) + { + char path[1024]; + snprintf(path, sizeof(path), "%s/%s", root, fn); + f = fopen(path, "rb"); + } + } + if (!f) + { + char path[1024]; + snprintf(path, sizeof(path), "/usr/local/lib/zen/%s", fn); + f = fopen(path, "rb"); + } + if (!f) + { + char path[1024]; + snprintf(path, sizeof(path), "/usr/lib/zen/%s", fn); + f = fopen(path, "rb"); + } + if (!f) + { return 0; } fseek(f, 0, SEEK_END); @@ -538,7 +560,10 @@ void scan_build_directives(ParserContext *ctx, const char *src) if (0 == strncmp(line, "link:", 5)) { char *val = line + 5; - while (*val == ' ') val++; + while (*val == ' ') + { + val++; + } if (strlen(g_link_flags) > 0) { strcat(g_link_flags, " "); @@ -548,7 +573,10 @@ void scan_build_directives(ParserContext *ctx, const char *src) else if (0 == strncmp(line, "cflags:", 7)) { char *val = line + 7; - while (*val == ' ') val++; + while (*val == ' ') + { + val++; + } if (strlen(g_cflags) > 0) { strcat(g_cflags, " "); @@ -558,7 +586,10 @@ void scan_build_directives(ParserContext *ctx, const char *src) else if (0 == strncmp(line, "include:", 8)) { char *val = line + 8; - while (*val == ' ') val++; + while (*val == ' ') + { + val++; + } char flags[2048]; sprintf(flags, "-I%s", val); if (strlen(g_cflags) > 0) @@ -570,7 +601,10 @@ void scan_build_directives(ParserContext *ctx, const char *src) else if (strncmp(line, "lib:", 4) == 0) { char *val = line + 4; - while (*val == ' ') val++; + while (*val == ' ') + { + val++; + } char flags[2048]; sprintf(flags, "-L%s", val); if (strlen(g_link_flags) > 0) @@ -582,7 +616,10 @@ void scan_build_directives(ParserContext *ctx, const char *src) else if (strncmp(line, "define:", 7) == 0) { char *val = line + 7; - while (*val == ' ') val++; + while (*val == ' ') + { + val++; + } char flags[2048]; sprintf(flags, "-D%s", val); if (strlen(g_cflags) > 0) |
