From d82f3052c813f671561362126d0fbe08568542d3 Mon Sep 17 00:00:00 2001 From: lemon Date: Sat, 6 Dec 2025 11:41:44 +0100 Subject: add command-line predefined macros (-D, -U) --- io.c | 39 +++++++++++++++++++++++++++++++++++---- 1 file changed, 35 insertions(+), 4 deletions(-) (limited to 'io.c') diff --git a/io.c b/io.c index 6e1d425..f9e34b7 100644 --- a/io.c +++ b/io.c @@ -827,6 +827,37 @@ static struct file { } *fileht[1<uid.dev == uid.dev && f->uid.ino == uid.ino) { + break; + } else if (!f) { + f = allocz(&globarena, sizeof *f, 0); + f->uid = uid; + f->path = name; + f->f = (struct memfile) { .statik = 1 }; + fileht[id] = f; + vinit(&f->lineoffs, NULL, 10); + vpush(&f->lineoffs, 0); + ++nfiles; + break; + } + assert(--n > 0 && "fileht full"); + } + *pf = &f->f; + return id; +} + int openfile(const char **err, struct memfile **pf, const char *path) { @@ -873,14 +904,14 @@ openfile(const char **err, struct memfile **pf, const char *path) const char * getfilename(int id) { - assert(id < arraylength(fileht) && fileht[id]); + assert((uint)id < arraylength(fileht) && fileht[id]); return fileht[id]->path; } struct memfile * getfile(int id) { - assert(id < arraylength(fileht) && fileht[id]); + assert((uint)id < arraylength(fileht) && fileht[id]); return &fileht[id]->f; } @@ -889,7 +920,7 @@ addfileline(int id, uint off) { vec_of(uint) *lineoffs; - assert(id < arraylength(fileht) && fileht[id]); + assert((uint)id < arraylength(fileht) && fileht[id]); lineoffs = (void *)&fileht[id]->lineoffs; if (lineoffs->n && off > lineoffs->p[lineoffs->n-1]) vpush(lineoffs, off); @@ -901,7 +932,7 @@ getfilepos(int *line, int *col, int id, uint off) uint *offs, n; int l = 0, h, i = 0; - assert(id < arraylength(fileht) && fileht[id]); + assert((uint)id < arraylength(fileht) && fileht[id]); offs = fileht[id]->lineoffs.p; n = fileht[id]->lineoffs.n; h = n - 1; -- cgit v1.2.3