# HG changeset patch # User David A. Holland # Date 1292806183 18000 # Node ID 120629a5d6bfa9f243d4af8877489d05b0608695 # Parent 6c15ca895585e5324d6c74cc21b2cf8377b541b1 seenfile -> placefile (clearer) diff -r 6c15ca895585 -r 120629a5d6bf files.c --- 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 #include #include +#include #include #include #include @@ -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; iname, "/", 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); } diff -r 6c15ca895585 -r 120629a5d6bf place.c --- a/place.c Sun Dec 19 19:39:26 2010 -0500 +++ b/place.c Sun Dec 19 19:49:43 2010 -0500 @@ -11,51 +11,52 @@ #define BUILTIN_LINE 1 #define COMMANDLINE_LINE 2 -struct seenfile { +struct placefile { struct place includedfrom; char *name; bool fromsystemdir; }; -DECLARRAY(seenfile); -DEFARRAY(seenfile, ); +DECLARRAY(placefile); +DEFARRAY(placefile, ); -static struct seenfilearray seenfiles; +static struct placefilearray placefiles; static bool overall_failure; //////////////////////////////////////////////////////////// // seenfiles static -struct seenfile * -seenfile_create(const struct place *from, char *name, bool fromsystemdir) +struct placefile * +placefile_create(const struct place *from, const char *name, + bool fromsystemdir) { - struct seenfile *sf; + struct placefile *pf; - sf = domalloc(sizeof(*sf)); - sf->includedfrom = *from; - sf->name = name; - sf->fromsystemdir = fromsystemdir; - return sf; + pf = domalloc(sizeof(*pf)); + pf->includedfrom = *from; + pf->name = dostrdup(name); + pf->fromsystemdir = fromsystemdir; + return pf; } static void -seenfile_destroy(struct seenfile *sf) +placefile_destroy(struct placefile *pf) { - free(sf->name); - free(sf); + free(pf->name); + free(pf); } -DESTROYALL_ARRAY(seenfile, ); +DESTROYALL_ARRAY(placefile, ); -struct seenfile * -place_seen_file(const struct place *place, char *file, bool issystem) +const struct placefile * +place_addfile(const struct place *place, const char *file, bool issystem) { - struct seenfile *sf; + struct placefile *pf; - sf = seenfile_create(place, file, issystem); - seenfilearray_add(&seenfiles, sf, NULL); - return sf; + pf = placefile_create(place, file, issystem); + placefilearray_add(&placefiles, pf, NULL); + return pf; } //////////////////////////////////////////////////////////// @@ -149,12 +150,12 @@ void place_init(void) { - seenfilearray_init(&seenfiles); + placefilearray_init(&placefiles); } void place_cleanup(void) { - seenfilearray_destroyall(&seenfiles); - seenfilearray_cleanup(&seenfiles); + placefilearray_destroyall(&placefiles); + placefilearray_cleanup(&placefiles); } diff -r 6c15ca895585 -r 120629a5d6bf place.h --- a/place.h Sun Dec 19 19:39:26 2010 -0500 +++ b/place.h Sun Dec 19 19:49:43 2010 -0500 @@ -7,7 +7,7 @@ }; struct place { enum places type; - struct seenfile *file; + const struct placefile *file; unsigned line; unsigned column; }; @@ -19,4 +19,5 @@ void place_setbuiltin(struct place *p, unsigned num); void place_setcommandline(struct place *p, unsigned word); -struct seenfile *place_seen_file(const struct place *p, char *name, bool fromsystemdir); +const struct placefile *place_addfile(const struct place *incplace, + const char *name, bool fromsystemdir);