Mercurial > ~dholland > hg > tradcpp > index.cgi
changeset 10:800f3a560a3b
move seenfiles to place.c too
author | David A. Holland |
---|---|
date | Sun, 19 Dec 2010 19:27:14 -0500 |
parents | 1fbcbd58742e |
children | b9d50e786322 |
files | files.c main.c place.c place.h |
diffstat | 4 files changed, 81 insertions(+), 61 deletions(-) [+] |
line wrap: on
line diff
--- a/files.c Sun Dec 19 19:19:02 2010 -0500 +++ b/files.c Sun Dec 19 19:27:14 2010 -0500 @@ -14,19 +14,10 @@ bool issystem; }; -struct seenfile { - struct place includedfrom; - char *name; - bool fromsystemdir; -}; - DECLARRAY(incdir); -DECLARRAY(seenfile); DEFARRAY(incdir, ); -DEFARRAY(seenfile, ); static struct incdirarray quotepath, bracketpath; -static struct seenfilearray seenfiles; //////////////////////////////////////////////////////////// // management @@ -50,27 +41,6 @@ free(id); } -static -struct seenfile * -seenfile_create(const struct place *from, char *name, bool fromsystemdir) -{ - struct seenfile *sf; - - sf = domalloc(sizeof(*sf)); - sf->includedfrom = *from; - sf->name = name; - sf->fromsystemdir = fromsystemdir; - return sf; -} - -static -void -seenfile_destroy(struct seenfile *sf) -{ - free(sf->name); - free(sf); -} - void files_init(void) { @@ -79,14 +49,10 @@ } DESTROYALL_ARRAY(incdir, ); -DESTROYALL_ARRAY(seenfile, ); void files_cleanup(void) { - seenfilearray_destroyall(&seenfiles); - seenfilearray_cleanup(&seenfiles); - incdirarray_destroyall("epath); incdirarray_cleanup("epath); incdirarray_destroyall(&bracketpath); @@ -115,21 +81,6 @@ } //////////////////////////////////////////////////////////// -// seenfile functions exposed for places.c - -const char * -seenfile_getname(const struct seenfile *file) -{ - return file->name; -} - -const struct place * -seenfile_getincludeplace(const struct seenfile *file) -{ - return &file->includedfrom; -} - -//////////////////////////////////////////////////////////// // parsing void @@ -170,8 +121,7 @@ file = dostrdup3(id->name, "/", name); fd = file_tryopen(file); if (fd >= 0) { - sf = seenfile_create(place, file, id->issystem); - seenfilearray_add(&seenfiles, sf, NULL); + sf = place_seen_file(place, file, id->issystem); file_read(sf, fd); close(fd); return; @@ -207,8 +157,7 @@ warn("%s", name); die(); } - sf = seenfile_create(place, dostrdup(name), false); - seenfilearray_add(&seenfiles, sf, NULL); + sf = place_seen_file(place, dostrdup(name), false); file_read(sf, fd); close(fd); }
--- a/main.c Sun Dec 19 19:19:02 2010 -0500 +++ b/main.c Sun Dec 19 19:27:14 2010 -0500 @@ -861,6 +861,7 @@ commandline_macros_init(); commandline_files_init(); + place_init(); files_init(); } @@ -871,6 +872,7 @@ unsigned i, num; files_cleanup(); + place_cleanup(); commandline_files_cleanup(); commandline_macros_cleanup();
--- a/place.c Sun Dec 19 19:19:02 2010 -0500 +++ b/place.c Sun Dec 19 19:27:14 2010 -0500 @@ -4,17 +4,67 @@ #include <stdlib.h> #include "utils.h" +#include "array.h" #include "place.h" -static bool overall_failure; - #define NOWHERE_LINE 0 #define BUILTIN_LINE 1 #define COMMANDLINE_LINE 2 +struct seenfile { + struct place includedfrom; + char *name; + bool fromsystemdir; +}; +DECLARRAY(seenfile); +DEFARRAY(seenfile, ); + +static bool overall_failure; + static struct place scratchplace; static bool scratchplace_inuse; +static struct seenfilearray seenfiles; + +//////////////////////////////////////////////////////////// +// seenfiles + +static +struct seenfile * +seenfile_create(const struct place *from, char *name, bool fromsystemdir) +{ + struct seenfile *sf; + + sf = domalloc(sizeof(*sf)); + sf->includedfrom = *from; + sf->name = name; + sf->fromsystemdir = fromsystemdir; + return sf; +} + +static +void +seenfile_destroy(struct seenfile *sf) +{ + free(sf->name); + free(sf); +} + +DESTROYALL_ARRAY(seenfile, ); + +struct seenfile * +place_seen_file(const struct place *place, char *file, bool issystem) +{ + struct seenfile *sf; + + sf = seenfile_create(place, file, issystem); + seenfilearray_add(&seenfiles, sf, NULL); + return sf; +} + +//////////////////////////////////////////////////////////// +// places + static bool place_isnowhere(const struct place *p) @@ -111,7 +161,7 @@ } else if (place_isbuiltin(p)) { fprintf(stderr, "<built-in>:%u:1", p->column); } else { - fprintf(stderr, "%s:%u:%u", seenfile_getname(p->file), + fprintf(stderr, "%s:%u:%u", p->file->name, p->line, p->column); } } @@ -122,7 +172,7 @@ { const struct place *from; - from = seenfile_getincludeplace(p->file); + from = &p->file->includedfrom; if (!place_isnowhere(from)) { place_printfrom(from); } @@ -131,13 +181,16 @@ fprintf(stderr, ":\n"); } +//////////////////////////////////////////////////////////// +// complaints + void complain(const struct place *p, const char *fmt, ...) { va_list ap; const struct place *from; - from = seenfile_getincludeplace(p->file); + from = &p->file->includedfrom; if (!place_isnowhere(from)) { place_printfrom(from); } @@ -161,3 +214,18 @@ return overall_failure; } +//////////////////////////////////////////////////////////// +// module init and cleanup + +void +place_init(void) +{ + seenfilearray_init(&seenfiles); +} + +void +place_cleanup(void) +{ + seenfilearray_destroyall(&seenfiles); + seenfilearray_cleanup(&seenfiles); +}
--- a/place.h Sun Dec 19 19:19:02 2010 -0500 +++ b/place.h Sun Dec 19 19:27:14 2010 -0500 @@ -4,6 +4,9 @@ unsigned column; }; +void place_init(void); +void place_cleanup(void); + struct place *place_gettemporary(void); void place_puttemporary(struct place *p); struct place *place_create(void); @@ -13,6 +16,4 @@ void place_setbuiltin(struct place *p, unsigned num); void place_setcommandline(struct place *p, unsigned column); -/* in files.c */ -const char *seenfile_getname(const struct seenfile *file); -const struct place *seenfile_getincludeplace(const struct seenfile *file); +struct seenfile *place_seen_file(const struct place *p, char *name, bool fromsystemdir);