diff options
| author | 2025-11-22 10:24:12 +0100 | |
|---|---|---|
| committer | 2025-11-22 10:24:12 +0100 | |
| commit | c2f9d128ecd15c9f285426b4e7b9bc2cd3d53732 (patch) | |
| tree | 743cde39225e04adfeae733dca9fa1bab0fe79e2 /c/lex.c | |
| parent | 654dde3b3f2fafddb9139cc53af0633689b1d2b7 (diff) | |
lex: #include ".." should also look in working directory
Diffstat (limited to 'c/lex.c')
| -rw-r--r-- | c/lex.c | 36 |
1 files changed, 17 insertions, 19 deletions
@@ -1597,25 +1597,23 @@ ppinclude(struct lexer *lx, const struct span *span0) const char *base, *end; joinspan(&span.ex, tk.span.ex); if (tk.t == TKPPHDRQ) { - if (tk.s[0] == '/') { - /* absolute path */ - xbgrow(&path, tk.len + 1); - memcpy(path, tk.s, tk.len); - path[tk.len] = 0; - if (tryinclude(lx, &span, path)) return; - goto NotFound; - } else { - /* build relative path */ - base = getfilename(lx->fileid); - for (end = base; *end != 0; ++end) {} - for (--end; *end != '/' && end != base; --end) {} - if (*end == '/') ++end; - xbgrow(&path, end - base + tk.len + 1); - memcpy(path, base, end - base); - memcpy(path + (end - base), tk.s, tk.len); - path[end - base + tk.len] = 0; - if (tryinclude(lx, &span, path)) return; - } + /* try raw path: absolute or relative to working dir */ + xbgrow(&path, tk.len + 1); + memcpy(path, tk.s, tk.len); + path[tk.len] = 0; + if (tryinclude(lx, &span, path)) return; + if (tk.s[0] == '/') goto NotFound; + + /* try relative to current file's directory */ + base = getfilename(lx->fileid); + for (end = base; *end != 0; ++end) {} + for (--end; *end != '/' && end != base; --end) {} + if (*end == '/') ++end; + xbgrow(&path, end - base + tk.len + 1); + memcpy(path, base, end - base); + memcpy(path + (end - base), tk.s, tk.len); + path[end - base + tk.len] = 0; + if (tryinclude(lx, &span, path)) return; } /* try system paths */ for (struct inclpaths *p = cinclpaths; p; p = p->next) { |