Mercurial > ~dholland > hg > tradcpp > index.cgi
diff files.c @ 13:120629a5d6bf
seenfile -> placefile (clearer)
author | David A. Holland |
---|---|
date | Sun, 19 Dec 2010 19:49:43 -0500 (2010-12-20) |
parents | 800f3a560a3b |
children | f6177d3ed5c2 |
line wrap: on
line diff
--- a/files.c Sun Dec 19 19:39:26 2010 -0500 +++ b/files.c Sun Dec 19 19:49:43 2010 -0500 @@ -1,6 +1,7 @@ #include <stdbool.h> #include <stdio.h> #include <stdlib.h> +#include <string.h> #include <unistd.h> #include <fcntl.h> #include <err.h> @@ -84,12 +85,36 @@ // parsing void -file_read(struct seenfile *sf, int fd); +file_read(const struct placefile *pf, int fd); //////////////////////////////////////////////////////////// // path search static +char * +mkfilename(const char *dir, const char *file) +{ + size_t dlen, flen, rlen; + char *ret; + bool needslash = false; + + dlen = strlen(dir); + flen = strlen(file); + if (dlen > 0 && dir[dlen-1] != '/') { + needslash = true; + } + + rlen = dlen + (needslash ? 1 : 0) + flen; + ret = domalloc(rlen + 1); + strcpy(ret, dir); + if (needslash) { + strcat(ret, "/"); + } + strcat(ret, file); + return ret; +} + +static int file_tryopen(const char *file) { @@ -109,7 +134,7 @@ { unsigned i, num; struct incdir *id; - struct seenfile *sf; + const struct placefile *pf; char *file; int fd; @@ -118,11 +143,12 @@ num = incdirarray_num(path); for (i=0; i<num; i++) { id = incdirarray_get(path, i); - file = dostrdup3(id->name, "/", name); + file = mkfilename(id->name, name); fd = file_tryopen(file); if (fd >= 0) { - sf = place_seen_file(place, file, id->issystem); - file_read(sf, fd); + pf = place_addfile(place, file, id->issystem); + free(file); + file_read(pf, fd); close(fd); return; } @@ -147,7 +173,7 @@ void file_readabsolute(struct place *place, const char *name) { - struct seenfile *sf; + const struct placefile *pf; int fd; assert(place != NULL); @@ -157,7 +183,7 @@ warn("%s", name); die(); } - sf = place_seen_file(place, dostrdup(name), false); - file_read(sf, fd); + pf = place_addfile(place, name, false); + file_read(pf, fd); close(fd); }