summaryrefslogtreecommitdiff
path: root/usr.bin/m4
diff options
context:
space:
mode:
authorMarc Espie <espie@cvs.openbsd.org>2006-03-20 10:55:20 +0000
committerMarc Espie <espie@cvs.openbsd.org>2006-03-20 10:55:20 +0000
commit97a6df38bb41a7240f610c0ba5424d79ff95ad4d (patch)
tree9313fa03d112c71c2d7b03daf9ea86bd24015579 /usr.bin/m4
parentd44c43192e771ba81e9bb56363da34c349de4d36 (diff)
report function m4errx, that shows app-specific data (filename/linenumber)
before the error message. Use it to simplify code. okay miod@
Diffstat (limited to 'usr.bin/m4')
-rw-r--r--usr.bin/m4/eval.c22
-rw-r--r--usr.bin/m4/extern.h3
-rw-r--r--usr.bin/m4/gnum4.c10
-rw-r--r--usr.bin/m4/main.c3
-rw-r--r--usr.bin/m4/misc.c25
-rw-r--r--usr.bin/m4/trace.c3
6 files changed, 37 insertions, 29 deletions
diff --git a/usr.bin/m4/eval.c b/usr.bin/m4/eval.c
index 34255aa9a3f..8a841a2b2f6 100644
--- a/usr.bin/m4/eval.c
+++ b/usr.bin/m4/eval.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: eval.c,v 1.59 2006/01/20 23:10:19 espie Exp $ */
+/* $OpenBSD: eval.c,v 1.60 2006/03/20 10:55:19 espie Exp $ */
/* $NetBSD: eval.c,v 1.7 1996/11/10 21:21:29 pk Exp $ */
/*
@@ -48,7 +48,6 @@
#include <stddef.h>
#include <string.h>
#include <fcntl.h>
-#include <err.h>
#include "mdef.h"
#include "stdd.h"
#include "extern.h"
@@ -101,8 +100,7 @@ eval(const char *argv[], int argc, int td, int is_traced)
expansion_id++;
if (td & RECDEF)
- errx(1, "%s at line %lu: expanding recursive definition for %s",
- CURRENT_NAME, CURRENT_LINE, argv[1]);
+ m4errx(1, "expanding recursive definition for %s.", argv[1]);
if (is_traced)
mark = trace(argv, argc, infile+ilevel);
if (td == MACRTYPE)
@@ -180,13 +178,13 @@ expand_builtin(const char *argv[], int argc, int td)
if (argc > 3) {
base = strtonum(argv[3], 2, 36, &errstr);
if (errstr) {
- errx(1, "base %s invalid", argv[3]);
+ m4errx(1, "expr: base %s invalid.", argv[3]);
}
}
if (argc > 4) {
maxdigits = strtonum(argv[4], 0, INT_MAX, &errstr);
if (errstr) {
- errx(1, "maxdigits %s invalid", argv[4]);
+ m4errx(1, "expr: maxdigits %s invalid.", argv[4]);
}
}
if (argc > 2)
@@ -489,8 +487,7 @@ expand_builtin(const char *argv[], int argc, int td)
pbstr(lquote);
break;
default:
- errx(1, "%s at line %lu: eval: major botch.",
- CURRENT_NAME, CURRENT_LINE);
+ m4errx(1, "eval: major botch.");
break;
}
}
@@ -576,8 +573,7 @@ void
dodefine(const char *name, const char *defn)
{
if (!*name)
- errx(1, "%s at line %lu: null definition.", CURRENT_NAME,
- CURRENT_LINE);
+ m4errx(1, "null definition.");
macro_define(name, defn);
}
@@ -613,8 +609,7 @@ static void
dopushdef(const char *name, const char *defn)
{
if (!*name)
- errx(1, "%s at line %lu: null definition", CURRENT_NAME,
- CURRENT_LINE);
+ m4errx(1, "null definition.");
macro_pushdef(name, defn);
}
@@ -697,8 +692,7 @@ static int
doincl(const char *ifile)
{
if (ilevel + 1 == MAXINP)
- errx(1, "%s at line %lu: too many include files.",
- CURRENT_NAME, CURRENT_LINE);
+ m4errx(1, "too many include files.");
if (fopen_trypath(infile+ilevel+1, ifile) != NULL) {
ilevel++;
bbase[ilevel] = bufbase = bp;
diff --git a/usr.bin/m4/extern.h b/usr.bin/m4/extern.h
index 32e553d10ff..93f873882ca 100644
--- a/usr.bin/m4/extern.h
+++ b/usr.bin/m4/extern.h
@@ -1,4 +1,4 @@
-/* $OpenBSD: extern.h,v 1.43 2006/01/20 23:10:19 espie Exp $ */
+/* $OpenBSD: extern.h,v 1.44 2006/03/20 10:55:19 espie Exp $ */
/* $NetBSD: extern.h,v 1.3 1996/01/13 23:25:24 pk Exp $ */
/*-
@@ -108,6 +108,7 @@ extern void usage(void);
extern void resizedivs(int);
extern size_t buffer_mark(void);
extern void dump_buffer(FILE *, size_t);
+extern void m4errx(int, const char *, ...);
extern int obtain_char(struct input_file *);
extern void set_input(struct input_file *, FILE *, const char *);
diff --git a/usr.bin/m4/gnum4.c b/usr.bin/m4/gnum4.c
index 6e6e51b3c8f..0b71338263f 100644
--- a/usr.bin/m4/gnum4.c
+++ b/usr.bin/m4/gnum4.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: gnum4.c,v 1.31 2005/05/29 18:44:36 espie Exp $ */
+/* $OpenBSD: gnum4.c,v 1.32 2006/03/20 10:55:19 espie Exp $ */
/*
* Copyright (c) 1999 Marc Espie
@@ -39,7 +39,6 @@
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
-#include <err.h>
#include <errno.h>
#include <unistd.h>
#include "mdef.h"
@@ -164,7 +163,7 @@ doindir(const char *argv[], int argc)
n = lookup(argv[2]);
if (n == NULL || (p = macro_getdef(n)) == NULL)
- errx(1, "undefined macro %s", argv[2]);
+ m4errx(1, "indir: undefined macro %s.", argv[2]);
argv[1] = p->defn;
eval(argv+1, argc-1, p->type, is_traced(n));
@@ -180,7 +179,7 @@ dobuiltin(const char *argv[], int argc)
if (p != NULL)
eval(argv+1, argc-1, macro_builtin_type(p), is_traced(p));
else
- errx(1, "unknown builtin %s", argv[2]);
+ m4errx(1, "unknown builtin %s.", argv[2]);
}
@@ -250,8 +249,7 @@ exit_regerror(int er, regex_t *re)
errbuf = xalloc(errlen,
"malloc in regerror: %lu", (unsigned long)errlen);
regerror(er, re, errbuf, errlen);
- errx(1, "%s at line %lu: regular expression error: %s",
- CURRENT_NAME, CURRENT_LINE, errbuf);
+ m4errx(1, "regular expression error: %s.", errbuf);
}
static void
diff --git a/usr.bin/m4/main.c b/usr.bin/m4/main.c
index a5ed6cd98ef..f489cd38b6d 100644
--- a/usr.bin/m4/main.c
+++ b/usr.bin/m4/main.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: main.c,v 1.69 2006/01/20 23:10:19 espie Exp $ */
+/* $OpenBSD: main.c,v 1.70 2006/03/20 10:55:19 espie Exp $ */
/* $NetBSD: main.c,v 1.12 1997/02/08 23:54:49 cgd Exp $ */
/*-
@@ -50,7 +50,6 @@
#include <stdint.h>
#include <stdlib.h>
#include <ohash.h>
-#include <err.h>
#include "mdef.h"
#include "stdd.h"
#include "extern.h"
diff --git a/usr.bin/m4/misc.c b/usr.bin/m4/misc.c
index eca33141abf..7a3ebbe2e96 100644
--- a/usr.bin/m4/misc.c
+++ b/usr.bin/m4/misc.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: misc.c,v 1.34 2005/09/07 13:22:24 jmc Exp $ */
+/* $OpenBSD: misc.c,v 1.35 2006/03/20 10:55:19 espie Exp $ */
/* $NetBSD: misc.c,v 1.6 1995/09/28 05:37:41 tls Exp $ */
/*
@@ -122,10 +122,10 @@ pbnumbase(int n, int base, int d)
int printed = 0;
if (base > 36)
- errx(1, "base %d > 36: not supported", base);
+ m4errx(1, "base %d > 36: not supported.", base);
if (base < 2)
- errx(1, "bad base %d for conversion", base);
+ m4errx(1, "bad base %d for conversion.", base);
num = (n < 0) ? -n : n;
do {
@@ -228,7 +228,7 @@ getdiv(int n)
int c;
if (active == outfile[n])
- errx(1, "undivert: diversion still active");
+ m4errx(1, "undivert: diversion still active.");
rewind(outfile[n]);
while ((c = getc(outfile[n])) != EOF)
putc(c, active);
@@ -258,6 +258,23 @@ killdiv()
}
}
+extern char *__progname;
+
+void
+m4errx(int eval, const char *fmt, ...)
+{
+ va_list ap;
+
+ va_start(ap, fmt);
+ fprintf(stderr, "%s: ", __progname);
+ fprintf(stderr, "%s at line %lu: ", CURRENT_NAME, CURRENT_LINE);
+ if (fmt != NULL)
+ vfprintf(stderr, fmt, ap);
+ fprintf(stderr, "\n");
+ exit(eval);
+ va_end(ap);
+}
+
/*
* resizedivs: allocate more diversion files */
void
diff --git a/usr.bin/m4/trace.c b/usr.bin/m4/trace.c
index e2416cb2b1e..897bc141f44 100644
--- a/usr.bin/m4/trace.c
+++ b/usr.bin/m4/trace.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: trace.c,v 1.13 2006/01/20 23:10:19 espie Exp $ */
+/* $OpenBSD: trace.c,v 1.14 2006/03/20 10:55:19 espie Exp $ */
/*
* Copyright (c) 2001 Marc Espie.
*
@@ -28,7 +28,6 @@
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
-#include <err.h>
#include "mdef.h"
#include "stdd.h"
#include "extern.h"