# HG changeset patch # User David A. Holland # Date 1434092102 14400 # Node ID a2f047301c15a6b1754168a55288ef7c566af2b7 # Parent ffdb0b73856fbbc85dc64bcd082eea2704e232c0 Replace Joerg's place_setfile with something that at least sort of works. diff -r ffdb0b73856f -r a2f047301c15 CHANGES --- 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) diff -r ffdb0b73856f -r a2f047301c15 directive.c --- 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) { diff -r ffdb0b73856f -r a2f047301c15 place.c --- 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; iincludedfrom) && + !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) { diff -r ffdb0b73856f -r a2f047301c15 place.h --- 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);