diff options
author | Marc Espie <espie@cvs.openbsd.org> | 2012-03-22 13:47:13 +0000 |
---|---|---|
committer | Marc Espie <espie@cvs.openbsd.org> | 2012-03-22 13:47:13 +0000 |
commit | 3977dfb25ab339398ce4e463f1516523799ad64a (patch) | |
tree | 7e7c2f3abd07f0d76e0bcd79112d840c62d76ffd /usr.bin | |
parent | aadb8c731774443f3c939e50c31e9dcfabaa7844 (diff) |
minor cleanup: error messages include lineno and fileno together, so
recognize that and create a struct Location_ for it.
mostly from Jonathan Calmels, a few nits from me.
okay otto@
Diffstat (limited to 'usr.bin')
-rw-r--r-- | usr.bin/make/compat.c | 8 | ||||
-rw-r--r-- | usr.bin/make/cond.c | 10 | ||||
-rw-r--r-- | usr.bin/make/defines.h | 5 | ||||
-rw-r--r-- | usr.bin/make/engine.c | 8 | ||||
-rw-r--r-- | usr.bin/make/error.c | 18 | ||||
-rw-r--r-- | usr.bin/make/gnode.h | 8 | ||||
-rw-r--r-- | usr.bin/make/job.c | 6 | ||||
-rw-r--r-- | usr.bin/make/location.h | 33 | ||||
-rw-r--r-- | usr.bin/make/lowparse.c | 61 | ||||
-rw-r--r-- | usr.bin/make/lowparse.h | 6 | ||||
-rw-r--r-- | usr.bin/make/parse.c | 8 | ||||
-rw-r--r-- | usr.bin/make/targ.c | 6 | ||||
-rw-r--r-- | usr.bin/make/var.c | 7 |
13 files changed, 117 insertions, 67 deletions
diff --git a/usr.bin/make/compat.c b/usr.bin/make/compat.c index 30c5f4e9a60..80f3f5641c4 100644 --- a/usr.bin/make/compat.c +++ b/usr.bin/make/compat.c @@ -1,4 +1,4 @@ -/* $OpenBSD: compat.c,v 1.75 2010/11/02 19:47:22 deraadt Exp $ */ +/* $OpenBSD: compat.c,v 1.76 2012/03/22 13:47:12 espie Exp $ */ /* $NetBSD: compat.c,v 1.14 1996/11/06 17:59:01 christos Exp $ */ /* @@ -229,11 +229,11 @@ CompatMake(void *gnp, /* The node to make */ pgn->must_make = false; else { - if (gn->lineno) + if (gn->origin.lineno) printf("\n\nStop in %s (line %lu of %s).\n", Var_Value(".CURDIR"), - (unsigned long)gn->lineno, - gn->fname); + (unsigned long)gn->origin.lineno, + gn->origin.fname); else printf("\n\nStop in %s.\n", Var_Value(".CURDIR")); diff --git a/usr.bin/make/cond.c b/usr.bin/make/cond.c index b1420d3eb10..941ca20e73f 100644 --- a/usr.bin/make/cond.c +++ b/usr.bin/make/cond.c @@ -1,4 +1,4 @@ -/* $OpenBSD: cond.c,v 1.43 2010/07/19 19:46:43 espie Exp $ */ +/* $OpenBSD: cond.c,v 1.44 2012/03/22 13:47:12 espie Exp $ */ /* $NetBSD: cond.c,v 1.7 1996/11/06 17:59:02 christos Exp $ */ /* @@ -156,8 +156,7 @@ static Token condPushBack=None; /* Single push-back token used in parsing */ static struct { bool value; - unsigned long lineno; - const char *filename; + Location origin; } condStack[MAXIF]; /* Stack of conditionals */ static int condTop = MAXIF; /* Top-most conditional */ @@ -1107,8 +1106,7 @@ err: } condStack[condTop].value = value; - condStack[condTop].lineno = Parse_Getlineno(); - condStack[condTop].filename = Parse_Getfilename(); + Parse_FillLocation(&condStack[condTop].origin); skipLine = !value; return value ? COND_PARSE : COND_SKIP; } @@ -1124,7 +1122,7 @@ Cond_End(void) MAXIF-condTop == 1 ? "" : "s"); for (i = MAXIF-1; i >= condTop; i--) { fprintf(stderr, "\t at line %lu of %s\n", - condStack[i].lineno, condStack[i].filename); + condStack[i].origin.lineno, condStack[i].origin.fname); } } condTop = MAXIF; diff --git a/usr.bin/make/defines.h b/usr.bin/make/defines.h index 9a18a3ced37..267860fc1aa 100644 --- a/usr.bin/make/defines.h +++ b/usr.bin/make/defines.h @@ -1,7 +1,7 @@ #ifndef DEFINES_H #define DEFINES_H -/* $OpenBSD: defines.h,v 1.9 2010/07/19 19:46:44 espie Exp $ */ +/* $OpenBSD: defines.h,v 1.10 2012/03/22 13:47:12 espie Exp $ */ /* * Copyright (c) 2001 Marc Espie. @@ -40,6 +40,9 @@ typedef int bool; struct GNode_; typedef struct GNode_ GNode; +struct Location_; +typedef struct Location_ Location; + struct List_; typedef struct List_ *Lst; diff --git a/usr.bin/make/engine.c b/usr.bin/make/engine.c index 3a4b5d071db..c6071755664 100644 --- a/usr.bin/make/engine.c +++ b/usr.bin/make/engine.c @@ -1,4 +1,4 @@ -/* $OpenBSD: engine.c,v 1.28 2010/04/25 13:59:53 espie Exp $ */ +/* $OpenBSD: engine.c,v 1.29 2012/03/22 13:47:12 espie Exp $ */ /* * Copyright (c) 1988, 1989, 1990 The Regents of the University of California. * Copyright (c) 1988, 1989 by Adam de Boor @@ -253,10 +253,8 @@ Make_HandleUse(GNode *cgn, /* The .USE node */ /* if the parent node doesn't have any location, then inherit the * use stuff, since that gives us better error messages. */ - if (!pgn->lineno) { - pgn->lineno = cgn->lineno; - pgn->fname = cgn->fname; - } + if (!pgn->origin.lineno) + pgn->origin = cgn->origin; } void diff --git a/usr.bin/make/error.c b/usr.bin/make/error.c index c79961bf837..61060648cc2 100644 --- a/usr.bin/make/error.c +++ b/usr.bin/make/error.c @@ -1,4 +1,4 @@ -/* $OpenBSD: error.c,v 1.19 2010/07/19 19:46:44 espie Exp $ */ +/* $OpenBSD: error.c,v 1.20 2012/03/22 13:47:12 espie Exp $ */ /* * Copyright (c) 2001 Marc Espie. @@ -37,13 +37,14 @@ #include "job.h" #include "targ.h" #include "var.h" +#include "location.h" #include "lowparse.h" int fatal_errors = 0; bool supervise_jobs = false; -static void ParseVErrorInternal(const char *, unsigned long, int, const char *, va_list); +static void ParseVErrorInternal(const Location *, int, const char *, va_list); /*- * Error -- * Print an error message given its format. @@ -146,11 +147,11 @@ Finish(int errors) /* number of errors encountered in Make_Make */ */ /* VARARGS */ static void -ParseVErrorInternal(const char *cfname, unsigned long clineno, int type, - const char *fmt, va_list ap) +ParseVErrorInternal(const Location *origin, int type, const char *fmt, + va_list ap) { - if (cfname) - (void)fprintf(stderr, "\"%s\", line %lu: ", cfname, clineno); + if (origin->fname) + (void)fprintf(stderr, "\"%s\", line %lu: ", origin->fname, origin->lineno); if (type == PARSE_WARNING) (void)fprintf(stderr, "warning: "); (void)vfprintf(stderr, fmt, ap); @@ -170,10 +171,11 @@ void Parse_Error(int type, const char *fmt, ...) { va_list ap; + Location l; va_start(ap, fmt); - ParseVErrorInternal(Parse_Getfilename(), Parse_Getlineno(), type, - fmt, ap); + Parse_FillLocation(&l); + ParseVErrorInternal(&l, type, fmt, ap); va_end(ap); } diff --git a/usr.bin/make/gnode.h b/usr.bin/make/gnode.h index 8c179854b04..6dc9d18e1e7 100644 --- a/usr.bin/make/gnode.h +++ b/usr.bin/make/gnode.h @@ -1,6 +1,6 @@ #ifndef GNODE_H #define GNODE_H -/* $OpenBSD: gnode.h,v 1.17 2010/07/19 19:46:44 espie Exp $ */ +/* $OpenBSD: gnode.h,v 1.18 2012/03/22 13:47:12 espie Exp $ */ /* * Copyright (c) 2001 Marc Espie. @@ -33,6 +33,9 @@ #ifndef LIST_TYPE #include "lst_t.h" #endif +#ifndef LOCATION_TYPE +#include "location.h" +#endif #ifndef SYMTABLE_H #include "symtable.h" #endif @@ -127,8 +130,7 @@ struct GNode_ { LIST preds; /* Nodes that must be made before this one */ SymTable context; /* The local variables */ - unsigned long lineno;/* First line number of commands. */ - const char *fname; /* File name of commands. */ + Location origin; /* First line number and file name of commands. */ LIST commands; /* Creation commands */ LIST expanded; /* Expanded commands */ struct Suff_ *suffix;/* Suffix for the node (determined by diff --git a/usr.bin/make/job.c b/usr.bin/make/job.c index 54cb8d1d893..374bdb7bd88 100644 --- a/usr.bin/make/job.c +++ b/usr.bin/make/job.c @@ -1,4 +1,4 @@ -/* $OpenBSD: job.c,v 1.120 2010/07/19 19:46:44 espie Exp $ */ +/* $OpenBSD: job.c,v 1.121 2012/03/22 13:47:12 espie Exp $ */ /* $NetBSD: job.c,v 1.16 1996/11/06 17:59:08 christos Exp $ */ /* @@ -265,9 +265,9 @@ print_errors() type = "Should not happen"; break; } - if (p->n->lineno) + if (p->n->origin.lineno) Error(" %s %d (%s, line %lu of %s)", - type, p->code, p->n->name, p->n->lineno, p->n->fname); + type, p->code, p->n->name, p->n->origin.lineno, p->n->origin.fname); else Error(" %s %d (%s)", type, p->code, p->n->name); } diff --git a/usr.bin/make/location.h b/usr.bin/make/location.h new file mode 100644 index 00000000000..6e0f4a375de --- /dev/null +++ b/usr.bin/make/location.h @@ -0,0 +1,33 @@ +/* $OpenBSD: location.h,v 1.1 2012/03/22 13:47:12 espie Exp $ */ + +/* + * Copyright (c) 2012 Marc Espie. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE OPENBSD PROJECT AND CONTRIBUTORS + * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OPENBSD + * PROJECT OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +struct Location_ { + const char *fname; /* Name of file */ + unsigned long lineno; /* Line number */ +}; + +#define LOCATION_TYPE diff --git a/usr.bin/make/lowparse.c b/usr.bin/make/lowparse.c index 533faa32274..af87b399416 100644 --- a/usr.bin/make/lowparse.c +++ b/usr.bin/make/lowparse.c @@ -1,4 +1,4 @@ -/* $OpenBSD: lowparse.c,v 1.25 2010/12/26 13:09:22 espie Exp $ */ +/* $OpenBSD: lowparse.c,v 1.26 2012/03/22 13:47:12 espie Exp $ */ /* low-level parsing functions. */ @@ -42,6 +42,8 @@ #include "error.h" #include "lst.h" #include "memory.h" +#include "location.h" + /* XXX check whether we can free filenames at the end, for a proper * definition of `end'. */ @@ -55,8 +57,7 @@ static LIST fileNames; /* file names to free at end */ * Strings have F == NULL, str != NULL. */ struct input_stream { - const char *fname; /* Name of file */ - unsigned long lineno; /* Line number */ + Location origin; /* Name of file and line number */ FILE *F; /* Open stream, or NULL if pure string. */ char *str; /* Input string, if F == NULL. */ @@ -75,9 +76,9 @@ static LIST input_stack; /* Stack of input_stream waiting to be parsed * obj = new_input_file(filename, filehandle); * Create input stream from filename, filehandle. */ static struct input_stream *new_input_file(const char *, FILE *); -/* obj = new_input_string(str, filename, lineno); - * Create input stream from str, filename, lineno. */ -static struct input_stream *new_input_string(char *, const char *, unsigned long); +/* obj = new_input_string(str, origin); + * Create input stream from str, origin. */ +static struct input_stream *new_input_string(char *, const Location *); /* free_input_stream(obj); * Discard consumed input stream, closing files, freeing memory. */ static void free_input_stream(struct input_stream *); @@ -119,10 +120,10 @@ new_input_file(const char *name, FILE *stream) #endif istream = emalloc(sizeof(*istream)); - istream->fname = name; + istream->origin.fname = name; istream->str = NULL; /* Naturally enough, we start reading at line 0. */ - istream->lineno = 0; + istream->origin.lineno = 0; istream->F = stream; istream->ptr = istream->end = NULL; return istream; @@ -140,17 +141,16 @@ free_input_stream(struct input_stream *istream) } static struct input_stream * -new_input_string(char *str, const char *name, unsigned long lineno) +new_input_string(char *str, const Location *origin) { struct input_stream *istream; istream = emalloc(sizeof(*istream)); - /* No malloc, name is always taken from an already existing istream */ - istream->fname = name; + /* No malloc, name is always taken from an already existing istream + * and strings are used in for loops, so we need to reset the line counter + * to an appropriate value. */ + istream->origin = *origin; istream->F = NULL; - /* Strings are used in for loops, so we need to reset the line counter - * to an appropriate value. */ - istream->lineno = lineno; istream->ptr = istream->str = str; istream->end = str + strlen(str); return istream; @@ -160,12 +160,16 @@ new_input_string(char *str, const char *name, unsigned long lineno) void Parse_FromString(char *str, unsigned long lineno) { + Location origin; + + origin.fname = current->origin.fname; + origin.lineno = lineno; if (DEBUG(FOR)) (void)fprintf(stderr, "%s\n----\n", str); Lst_Push(&input_stack, current); assert(current != NULL); - current = new_input_string(str, current->fname, lineno); + current = new_input_string(str, &origin); } @@ -234,7 +238,7 @@ Parse_ReadNextConditionalLine(Buffer linebuf) if (c == '\\') { c = read_char(); if (c == '\n') - current->lineno++; + current->origin.lineno++; } if (c == EOF) { Parse_Error(PARSE_FATAL, @@ -242,7 +246,7 @@ Parse_ReadNextConditionalLine(Buffer linebuf) return NULL; } } - current->lineno++; + current->origin.lineno++; } /* This is the line we need to copy */ @@ -254,7 +258,7 @@ read_logical_line(Buffer linebuf, int c) { for (;;) { if (c == '\n') { - current->lineno++; + current->origin.lineno++; break; } if (c == EOF) @@ -265,7 +269,7 @@ read_logical_line(Buffer linebuf, int c) c = read_char(); if (c == '\n') { Buf_AddSpace(linebuf); - current->lineno++; + current->origin.lineno++; do { c = read_char(); } while (c == ' ' || c == '\t'); @@ -297,7 +301,7 @@ Parse_ReadUnparsedLine(Buffer linebuf, const char *type) while (c == '\\') { c = read_char(); if (c == '\n') { - current->lineno++; + current->origin.lineno++; do { c = read_char(); } while (c == ' ' || c == '\t'); @@ -333,7 +337,7 @@ skip_empty_lines_and_read_char(Buffer linebuf) while (c == '\\') { c = read_char(); if (c == '\n') { - current->lineno++; + current->origin.lineno++; do { c = read_char(); } while (c == ' ' || c == '\t'); @@ -364,7 +368,7 @@ skip_empty_lines_and_read_char(Buffer linebuf) while (c == '\\') { c = read_char(); if (c == '\n') { - current->lineno++; + current->origin.lineno++; do { c = read_char(); } while (c == ' ' || c == '\t'); @@ -382,7 +386,7 @@ skip_empty_lines_and_read_char(Buffer linebuf) } } if (c == '\n') - current->lineno++; + current->origin.lineno++; else return c; } @@ -417,13 +421,20 @@ Parse_ReadNormalLine(Buffer linebuf) unsigned long Parse_Getlineno(void) { - return current ? current->lineno : 0; + return current ? current->origin.lineno : 0; } const char * Parse_Getfilename(void) { - return current ? current->fname : NULL; + return current ? current->origin.fname : NULL; +} + +void +Parse_FillLocation(Location *origin) +{ + origin->lineno = Parse_Getlineno(); + origin->fname = Parse_Getfilename(); } #ifdef CLEANUP diff --git a/usr.bin/make/lowparse.h b/usr.bin/make/lowparse.h index c1b0aef9ff0..70f22483b8e 100644 --- a/usr.bin/make/lowparse.h +++ b/usr.bin/make/lowparse.h @@ -1,7 +1,7 @@ #ifndef LOWPARSE_H #define LOWPARSE_H -/* $OpenBSD: lowparse.h,v 1.7 2010/07/19 19:46:44 espie Exp $ */ +/* $OpenBSD: lowparse.h,v 1.8 2012/03/22 13:47:12 espie Exp $ */ /* * Copyright (c) 1999 Marc Espie. @@ -77,6 +77,10 @@ extern unsigned long Parse_Getlineno(void); * Returns the current filename. Safe to keep without copying. */ extern const char *Parse_Getfilename(void); +/* Parse_FillLocation(origin) + * Fill the location pointed by origin with the current location. */ +extern void Parse_FillLocation(Location *); + /* continue = Parse_NextFile(); * Advance parsing to the next file in the input stack. Returns true * if there is parsing left to do. diff --git a/usr.bin/make/parse.c b/usr.bin/make/parse.c index efc1dab235b..928a81c6f11 100644 --- a/usr.bin/make/parse.c +++ b/usr.bin/make/parse.c @@ -1,4 +1,4 @@ -/* $OpenBSD: parse.c,v 1.100 2010/12/26 13:09:22 espie Exp $ */ +/* $OpenBSD: parse.c,v 1.101 2012/03/22 13:47:12 espie Exp $ */ /* $NetBSD: parse.c,v 1.29 1997/03/10 21:20:04 christos Exp $ */ /* @@ -1013,10 +1013,8 @@ ParseAddCmd(void *gnp, void *cmd) /* if target already supplied, ignore commands */ if (!(gn->type & OP_HAS_COMMANDS)) { Lst_AtEnd(&gn->commands, cmd); - if (!gn->lineno) { - gn->lineno = Parse_Getlineno(); - gn->fname = Parse_Getfilename(); - } + if (!gn->origin.lineno) + Parse_FillLocation(&gn->origin); } } diff --git a/usr.bin/make/targ.c b/usr.bin/make/targ.c index 5c3e8407c67..b69a7baa112 100644 --- a/usr.bin/make/targ.c +++ b/usr.bin/make/targ.c @@ -1,4 +1,4 @@ -/* $OpenBSD: targ.c,v 1.62 2010/07/19 19:46:44 espie Exp $ */ +/* $OpenBSD: targ.c,v 1.63 2012/03/22 13:47:12 espie Exp $ */ /* $NetBSD: targ.c,v 1.11 1997/02/20 16:51:50 christos Exp $ */ /* @@ -191,8 +191,8 @@ Targ_NewGNi(const char *name, const char *ename) Lst_Init(&gn->successors); Lst_Init(&gn->preds); SymTable_Init(&gn->context); - gn->lineno = 0; - gn->fname = NULL; + gn->origin.lineno = 0; + gn->origin.fname = NULL; gn->impliedsrc = NULL; Lst_Init(&gn->commands); Lst_Init(&gn->expanded); diff --git a/usr.bin/make/var.c b/usr.bin/make/var.c index 1999478a431..584b538cae0 100644 --- a/usr.bin/make/var.c +++ b/usr.bin/make/var.c @@ -1,4 +1,4 @@ -/* $OpenBSD: var.c,v 1.88 2011/06/20 19:05:33 espie Exp $ */ +/* $OpenBSD: var.c,v 1.89 2012/03/22 13:47:12 espie Exp $ */ /* $NetBSD: var.c,v 1.18 1997/03/18 19:24:46 christos Exp $ */ /* @@ -959,12 +959,13 @@ Var_Parse(const char *str, /* The string to parse */ case IMPSRC_INDEX: Fatal( "Using $< in a non-suffix rule context is a GNUmake idiom (line %lu of %s)", - n->lineno, n->fname); + n->origin.lineno, n->origin.fname); break; default: Error( "Using undefined dynamic variable $%s (line %lu of %s)", - varnames[idx], n->lineno, n->fname); + varnames[idx], n->origin.lineno, + n->origin.fname); break; } } |