diff options
author | Marc Espie <espie@cvs.openbsd.org> | 2001-09-18 14:43:24 +0000 |
---|---|---|
committer | Marc Espie <espie@cvs.openbsd.org> | 2001-09-18 14:43:24 +0000 |
commit | e225fe17b4e2ab01139f7a64db84f79b4127bb61 (patch) | |
tree | 5e215a15bef464d68a17a2b5330b16e0d07b3fd1 /usr.bin/m4 | |
parent | d53177c07d32617ce96d72021b5dd67f12f0a8b6 (diff) |
instrumentation for tracing mode: macro expansion
Diffstat (limited to 'usr.bin/m4')
-rw-r--r-- | usr.bin/m4/eval.c | 6 | ||||
-rw-r--r-- | usr.bin/m4/extern.h | 5 | ||||
-rw-r--r-- | usr.bin/m4/misc.c | 26 |
3 files changed, 32 insertions, 5 deletions
diff --git a/usr.bin/m4/eval.c b/usr.bin/m4/eval.c index 4e367003c0b..db78e62fd96 100644 --- a/usr.bin/m4/eval.c +++ b/usr.bin/m4/eval.c @@ -1,4 +1,4 @@ -/* $OpenBSD: eval.c,v 1.33 2001/09/18 14:17:38 espie Exp $ */ +/* $OpenBSD: eval.c,v 1.34 2001/09/18 14:43:22 espie Exp $ */ /* $NetBSD: eval.c,v 1.7 1996/11/10 21:21:29 pk Exp $ */ /* @@ -41,7 +41,7 @@ #if 0 static char sccsid[] = "@(#)eval.c 8.2 (Berkeley) 4/27/95"; #else -static char rcsid[] = "$OpenBSD: eval.c,v 1.33 2001/09/18 14:17:38 espie Exp $"; +static char rcsid[] = "$OpenBSD: eval.c,v 1.34 2001/09/18 14:43:22 espie Exp $"; #endif #endif /* not lint */ @@ -84,6 +84,7 @@ static void expand_builtin __P((const char *[], int, int)); static void expand_macro __P((const char *[], int)); static void dump_one_def __P((ndptr)); +unsigned long expansion_id; /* * eval - eval all macros and builtins calls @@ -94,6 +95,7 @@ eval(argv, argc, td) int argc; int td; { + expansion_id++; if (td & RECDEF) errx(1, "%s at line %lu: expanding recursive definition for %s", CURRENT_NAME, CURRENT_LINE, argv[1]); diff --git a/usr.bin/m4/extern.h b/usr.bin/m4/extern.h index 3264d2285c2..e3dd6c733c3 100644 --- a/usr.bin/m4/extern.h +++ b/usr.bin/m4/extern.h @@ -1,4 +1,4 @@ -/* $OpenBSD: extern.h,v 1.23 2001/09/18 14:05:14 espie Exp $ */ +/* $OpenBSD: extern.h,v 1.24 2001/09/18 14:43:22 espie Exp $ */ /* $NetBSD: extern.h,v 1.3 1996/01/13 23:25:24 pk Exp $ */ /*- @@ -42,6 +42,7 @@ /* eval.c */ extern void eval __P((const char *[], int, int)); extern void dodefine __P((const char *, const char *)); +extern unsigned long expansion_id; /* expr.c */ extern int expr __P((const char *)); @@ -87,6 +88,8 @@ extern void *xalloc __P((size_t)); extern char *xstrdup __P((const char *)); extern void usage __P((void)); extern void resizedivs __P((int n)); +extern size_t buffer_mark __P((void)); +extern void dump_buffer __P((FILE *, size_t)); extern int obtain_char __P((struct input_file *)); extern void set_input __P((struct input_file *, FILE *, const char *)); diff --git a/usr.bin/m4/misc.c b/usr.bin/m4/misc.c index 318b79987e4..4581327bf11 100644 --- a/usr.bin/m4/misc.c +++ b/usr.bin/m4/misc.c @@ -1,4 +1,4 @@ -/* $OpenBSD: misc.c,v 1.21 2001/07/18 16:18:17 espie Exp $ */ +/* $OpenBSD: misc.c,v 1.22 2001/09/18 14:43:23 espie Exp $ */ /* $NetBSD: misc.c,v 1.6 1995/09/28 05:37:41 tls Exp $ */ /* @@ -41,7 +41,7 @@ #if 0 static char sccsid[] = "@(#)misc.c 8.1 (Berkeley) 6/6/93"; #else -static char rcsid[] = "$OpenBSD: misc.c,v 1.21 2001/07/18 16:18:17 espie Exp $"; +static char rcsid[] = "$OpenBSD: misc.c,v 1.22 2001/09/18 14:43:23 espie Exp $"; #endif #endif /* not lint */ @@ -357,3 +357,25 @@ doprintfilename(f) { pbstr(f->name); } + +/* + * buffer_mark/dump_buffer: allows one to save a mark in a buffer, + * and later dump everything that was added since then to a file. + */ +size_t +buffer_mark() +{ + return bp - buf; +} + + +void +dump_buffer(f, m) + FILE *f; + size_t m; +{ + char *s; + + for (s = bp; s != buf + m;) + fputc(*--s, f); +} |