Mercurial > ~dholland > hg > tradcpp > index.cgi
changeset 176:a2f047301c15
Replace Joerg's place_setfile with something that at least sort of works.
author | David A. Holland |
---|---|
date | Fri, 12 Jun 2015 02:55:02 -0400 |
parents | ffdb0b73856f |
children | 6119608a9817 |
files | CHANGES directive.c place.c place.h |
diffstat | 4 files changed, 61 insertions(+), 15 deletions(-) [+] |
line wrap: on
line diff
--- a/CHANGES Fri Jun 12 02:38:04 2015 -0400 +++ b/CHANGES Fri Jun 12 02:55:02 2015 -0400 @@ -1,4 +1,8 @@ pending + - Fix output spacing behavior to match gcc when newlines appear in or + while looking for macro arguments. Partly from Joerg Sonnenberger. + - Implement __FILE__ and __LINE__ macros. Mostly from Joerg Sonnenberger. + - Implement #line. Partly from Joerg Sonnenberger. - Declare usage() with PF(). From wiz. release 0.4 (20130713)
--- a/directive.c Fri Jun 12 02:38:04 2015 -0400 +++ b/directive.c Fri Jun 12 02:55:02 2015 -0400 @@ -456,7 +456,7 @@ if (moretextlen > 2 && moretext[0] == '"' && moretext[moretextlen-1] == '"') { filename = dostrndup(moretext+1, moretextlen-2); - place_setfile(&lp->nextline, filename); + place_changefile(&lp->nextline, filename); dostrfree(filename); } else if (moretextlen > 0) {
--- a/place.c Fri Jun 12 02:38:04 2015 -0400 +++ b/place.c Fri Jun 12 02:55:02 2015 -0400 @@ -53,7 +53,7 @@ static const char *myprogname; //////////////////////////////////////////////////////////// -// seenfiles +// placefiles static struct placefile * @@ -101,6 +101,58 @@ return place->file->dir; } +static +bool +place_eq(const struct place *a, const struct place *b) +{ + if (a->type != b->type) { + return false; + } + if (a->file != b->file) { + return false; + } + if (a->line != b->line || a->column != b->column) { + return false; + } + return true; +} + +static +struct placefile * +placefile_find(const struct place *incfrom, const char *name) +{ + unsigned i, num; + struct placefile *pf; + + num = placefilearray_num(&placefiles); + for (i=0; i<num; i++) { + pf = placefilearray_get(&placefiles, i); + if (place_eq(incfrom, &pf->includedfrom) && + !strcmp(name, pf->name)) { + return pf; + } + } + return NULL; +} + +void +place_changefile(struct place *p, const char *name) +{ + struct placefile *pf; + + assert(p->type == P_FILE); + if (!strcmp(name, p->file->name)) { + return; + } + pf = placefile_find(&p->file->includedfrom, name); + if (pf == NULL) { + pf = placefile_create(&p->file->includedfrom, name, + p->file->fromsystemdir); + placefilearray_add(&placefiles, pf, NULL); + } + p->file = pf; +} + const struct placefile * place_addfile(const struct place *place, const char *file, bool issystem) { @@ -154,17 +206,6 @@ p->column = 1; } -void -place_setfile(struct place *p, const char *name) -{ - assert(p->type == P_FILE); - if (strcmp(name, p->file->name) == 0) { - return; - } - p->file = placefile_create(&p->file->includedfrom, name, - p->file->fromsystemdir); -} - const char * place_getname(const struct place *p) {
--- a/place.h Fri Jun 12 02:38:04 2015 -0400 +++ b/place.h Fri Jun 12 02:55:02 2015 -0400 @@ -47,16 +47,17 @@ void place_init(void); void place_cleanup(void); -const char *place_getname(const struct place *); void place_setnowhere(struct place *p); void place_setbuiltin(struct place *p, unsigned num); void place_setcommandline(struct place *p, unsigned word, unsigned column); void place_setfilestart(struct place *p, const struct placefile *pf); -void place_setfile(struct place *p, const char *name); +const char *place_getname(const struct place *); const char *place_getparsedir(const struct place *incplace); +void place_changefile(struct place *p, const char *name); + const struct placefile *place_addfile(const struct place *incplace, const char *name, bool fromsystemdir);