# HG changeset patch # User David A. Holland # Date 1292805566 18000 # Node ID 6c15ca895585e5324d6c74cc21b2cf8377b541b1 # Parent b9d50e7863222811877786eafde780cc9953bf99 improve places more diff -r b9d50e786322 -r 6c15ca895585 place.c --- a/place.c Sun Dec 19 19:30:24 2010 -0500 +++ b/place.c Sun Dec 19 19:39:26 2010 -0500 @@ -61,41 +61,22 @@ //////////////////////////////////////////////////////////// // places -static -bool -place_isnowhere(const struct place *p) -{ - return p->file == NULL && p->line == NOWHERE_LINE; -} - -static -bool -place_isbuiltin(const struct place *p) -{ - return p->file == NULL && p->line == BUILTIN_LINE; -} - -static -bool -place_iscommandline(const struct place *p) -{ - return p->file == NULL && p->line == COMMANDLINE_LINE; -} - void place_setnowhere(struct place *p) { + p->type = P_NOWHERE; p->file = NULL; - p->line = NOWHERE_LINE; + p->line = 0; p->column = 0; } void place_setbuiltin(struct place *p, unsigned num) { + p->type = P_BUILTIN; p->file = NULL; - p->line = BUILTIN_LINE; - p->column = num; + p->line = num; + p->column = 1; } void @@ -107,17 +88,17 @@ } static -void -place_print(const struct place *p) +const char * +place_getname(const struct place *p) { - if (place_iscommandline(p)) { - fprintf(stderr, ":1:%u", p->column); - } else if (place_isbuiltin(p)) { - fprintf(stderr, ":%u:1", p->column); - } else { - fprintf(stderr, "%s:%u:%u", p->file->name, - p->line, p->column); + switch (p->type) { + case P_NOWHERE: return ""; + case P_BUILTIN: return ""; + case P_COMMANDLINE: return ""; + case P_FILE: return p->file->name; } + assert(0); + return NULL; } static @@ -127,12 +108,11 @@ const struct place *from; from = &p->file->includedfrom; - if (!place_isnowhere(from)) { + if (from->type != P_NOWHERE) { place_printfrom(from); + fprintf(stderr, "In file included from %s:%u:%u:\n", + place_getname(from), from->line, from->column); } - fprintf(stderr, "In file included from "); - place_print(p); - fprintf(stderr, ":\n"); } //////////////////////////////////////////////////////////// @@ -142,14 +122,9 @@ complain(const struct place *p, const char *fmt, ...) { va_list ap; - const struct place *from; - from = &p->file->includedfrom; - if (!place_isnowhere(from)) { - place_printfrom(from); - } - place_print(p); - fprintf(stderr, ": "); + place_printfrom(p); + fprintf(stderr, "%s:%u:%u: ", place_getname(p), p->line, p->column); va_start(ap, fmt); vfprintf(stderr, fmt, ap); va_end(ap); diff -r b9d50e786322 -r 6c15ca895585 place.h --- a/place.h Sun Dec 19 19:30:24 2010 -0500 +++ b/place.h Sun Dec 19 19:39:26 2010 -0500 @@ -1,4 +1,12 @@ + +enum places { + P_NOWHERE, + P_BUILTIN, + P_COMMANDLINE, + P_FILE, +}; struct place { + enum places type; struct seenfile *file; unsigned line; unsigned column;