summaryrefslogtreecommitdiff
path: root/usr.bin/m4
diff options
context:
space:
mode:
authorMarc Espie <espie@cvs.openbsd.org>2001-09-27 11:40:34 +0000
committerMarc Espie <espie@cvs.openbsd.org>2001-09-27 11:40:34 +0000
commit075e3957eaedc259ec5ceda71fbc399ebb27f739 (patch)
treefbdfcadefcc6bcccd57925fcf5860c288ddb76ce /usr.bin/m4
parent37bf947e8d7999f07e2efca7fba6082b5a75f630 (diff)
traceon/traceoff built-ins.
Diffstat (limited to 'usr.bin/m4')
-rw-r--r--usr.bin/m4/eval.c31
-rw-r--r--usr.bin/m4/extern.h4
-rw-r--r--usr.bin/m4/m4.18
-rw-r--r--usr.bin/m4/main.c8
-rw-r--r--usr.bin/m4/mdef.h5
-rw-r--r--usr.bin/m4/trace.c57
6 files changed, 92 insertions, 21 deletions
diff --git a/usr.bin/m4/eval.c b/usr.bin/m4/eval.c
index 868621d2d57..36f70ee4d6a 100644
--- a/usr.bin/m4/eval.c
+++ b/usr.bin/m4/eval.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: eval.c,v 1.36 2001/09/19 13:14:18 espie Exp $ */
+/* $OpenBSD: eval.c,v 1.37 2001/09/27 11:40:33 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.36 2001/09/19 13:14:18 espie Exp $";
+static char rcsid[] = "$OpenBSD: eval.c,v 1.37 2001/09/27 11:40:33 espie Exp $";
#endif
#endif /* not lint */
@@ -70,6 +70,7 @@ static char rcsid[] = "$OpenBSD: eval.c,v 1.36 2001/09/19 13:14:18 espie Exp $";
static void dodefn __P((const char *));
static void dopushdef __P((const char *, const char *));
static void dodump __P((const char *[], int));
+static void dotrace __P((const char *[], int, int));
static void doifelse __P((const char *[], int));
static int doincl __P((const char *));
static int dopaste __P((const char *));
@@ -169,6 +170,14 @@ expand_builtin(argv, argc, td)
dodump(argv, argc);
break;
+ case TRACEONTYPE:
+ dotrace(argv, argc, 1);
+ break;
+
+ case TRACEOFFTYPE:
+ dotrace(argv, argc, 0);
+ break;
+
case EXPRTYPE:
/*
* doexpr - evaluate arithmetic
@@ -676,6 +685,24 @@ dodump(argv, argc)
}
/*
+ * dotrace - mark some macros as traced/untraced depending upon on.
+ */
+static void
+dotrace(argv, argc, on)
+ const char *argv[];
+ int argc;
+ int on;
+{
+ int n;
+
+ if (argc > 2) {
+ for (n = 2; n < argc; n++)
+ mark_traced(argv[n], on);
+ } else
+ mark_traced(NULL, on);
+}
+
+/*
* doifelse - select one of two alternatives - loop.
*/
static void
diff --git a/usr.bin/m4/extern.h b/usr.bin/m4/extern.h
index 60f5afe1267..eb4c38a9378 100644
--- a/usr.bin/m4/extern.h
+++ b/usr.bin/m4/extern.h
@@ -1,4 +1,4 @@
-/* $OpenBSD: extern.h,v 1.26 2001/09/19 13:14:18 espie Exp $ */
+/* $OpenBSD: extern.h,v 1.27 2001/09/27 11:40:33 espie Exp $ */
/* $NetBSD: extern.h,v 1.3 1996/01/13 23:25:24 pk Exp $ */
/*-
@@ -117,7 +117,7 @@ extern char *endpbb;
extern char *endest;
/* trace.c */
-extern void mark_traced __P((const char *));
+extern void mark_traced __P((const char *, int));
extern int is_traced __P((const char *));
extern void trace_file __P((const char *));
extern ssize_t trace __P((const char **, int, struct input_file *));
diff --git a/usr.bin/m4/m4.1 b/usr.bin/m4/m4.1
index 2dd619ee9f2..560099d9ec4 100644
--- a/usr.bin/m4/m4.1
+++ b/usr.bin/m4/m4.1
@@ -1,4 +1,4 @@
-.\" @(#) $OpenBSD: m4.1,v 1.21 2000/11/10 05:10:33 aaron Exp $
+.\" @(#) $OpenBSD: m4.1,v 1.22 2001/09/27 11:40:33 espie Exp $
.\"
.\"
.Dd January 26, 1993
@@ -272,6 +272,12 @@ Nothing is returned.
.It Ic sysval
Returns the return value from the last
.Ic syscmd .
+.It Ic traceon
+Enables tracing of macro expansions for the given arguments, or for all
+macros if no argument is given.
+.It Ic traceoff
+Disables tracing of macro expansions for the given arguments, or for all
+macros if no argument is given.
.It Ic translit
Transliterate the characters in the first argument from the set
given by the second argument to the set given by the third.
diff --git a/usr.bin/m4/main.c b/usr.bin/m4/main.c
index e6987b8bd50..475cf8fcdff 100644
--- a/usr.bin/m4/main.c
+++ b/usr.bin/m4/main.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: main.c,v 1.48 2001/09/19 13:14:18 espie Exp $ */
+/* $OpenBSD: main.c,v 1.49 2001/09/27 11:40:33 espie Exp $ */
/* $NetBSD: main.c,v 1.12 1997/02/08 23:54:49 cgd Exp $ */
/*-
@@ -47,7 +47,7 @@ static char copyright[] =
#if 0
static char sccsid[] = "@(#)main.c 8.1 (Berkeley) 6/6/93";
#else
-static char rcsid[] = "$OpenBSD: main.c,v 1.48 2001/09/19 13:14:18 espie Exp $";
+static char rcsid[] = "$OpenBSD: main.c,v 1.49 2001/09/27 11:40:33 espie Exp $";
#endif
#endif /* not lint */
@@ -136,6 +136,8 @@ struct keyblk keywrds[] = { /* m4 keywords to be installed */
{ "m4exit", EXITTYPE | NOARGS },
{ "syscmd", SYSCTYPE },
{ "sysval", SYSVTYPE | NOARGS },
+ { "traceon", TRACEONTYPE | NOARGS },
+ { "traceoff", TRACEOFFTYPE | NOARGS },
#if defined(unix) || defined(__unix__)
{ "unix", SELFTYPE | NOARGS },
@@ -216,7 +218,7 @@ main(argc,argv)
set_trace_flags(optarg);
break;
case 't':
- mark_traced(optarg);
+ mark_traced(optarg, 1);
break;
case 'o':
trace_file(optarg);
diff --git a/usr.bin/m4/mdef.h b/usr.bin/m4/mdef.h
index 5a51945e42d..4a10500be28 100644
--- a/usr.bin/m4/mdef.h
+++ b/usr.bin/m4/mdef.h
@@ -1,4 +1,4 @@
-/* $OpenBSD: mdef.h,v 1.20 2001/09/18 13:39:52 espie Exp $ */
+/* $OpenBSD: mdef.h,v 1.21 2001/09/27 11:40:33 espie Exp $ */
/* $NetBSD: mdef.h,v 1.7 1996/01/13 23:25:27 pk Exp $ */
/*
@@ -80,6 +80,9 @@
#define LINETYPE 39
#define REGEXPTYPE 40
#define ESYSCMDTYPE 41
+#define TRACEONTYPE 42
+#define TRACEOFFTYPE 43
+
#define TYPEMASK 63 /* Keep bits really corresponding to a type. */
#define RECDEF 256 /* Pure recursive def, don't expand it */
diff --git a/usr.bin/m4/trace.c b/usr.bin/m4/trace.c
index f183c997f56..9ccf8c707a8 100644
--- a/usr.bin/m4/trace.c
+++ b/usr.bin/m4/trace.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: trace.c,v 1.1 2001/09/18 14:55:52 espie Exp $ */
+/* $OpenBSD: trace.c,v 1.2 2001/09/27 11:40:33 espie Exp $ */
/*
* Copyright (c) 2001 Marc Espie.
*
@@ -28,6 +28,7 @@
#include <stddef.h>
#include <stdio.h>
#include <err.h>
+#include <stdlib.h>
#include "mdef.h"
#include "stdd.h"
#include "extern.h"
@@ -47,43 +48,75 @@ int traced_macros = 0;
#define TRACE_INPUT 256 /* not implemented yet */
#define TRACE_ALL 512
+static struct t {
+ struct t *next;
+ char *name;
+ int on;
+} *l;
static unsigned int letter_to_flag __P((int));
static void print_header __P((struct input_file *));
+static struct t *find_trace_entry __P((const char *));
static unsigned int flags = TRACE_QUOTE | TRACE_EXPANSION;
-static struct t {
- struct t *next;
- char *name;
-} *l;
+static struct t *
+find_trace_entry(name)
+ const char *name;
+{
+ struct t *n;
+
+ for (n = l; n != NULL; n = n->next)
+ if (STREQ(n->name, name))
+ return n;
+ return NULL;
+}
+
void
-mark_traced(name)
+mark_traced(name, on)
const char *name;
+ int on;
{
- struct t *n;
+ struct t *n, *n2;
traced_macros = 1;
+
+ if (name == NULL) {
+ if (on)
+ flags |= TRACE_ALL;
+ else {
+ flags &= ~TRACE_ALL;
+ traced_macros = 0;
+ }
+ for (n = l; n != NULL; n = n2) {
+ n2 = n->next;
+ free(n->name);
+ free(n);
+ }
+ l = NULL;
+ } else {
+ n = find_trace_entry(name);
+ if (n == NULL) {
n = xalloc(sizeof(struct t));
n->name = xstrdup(name);
n->next = l;
l = n;
+ }
+ n->on = on;
+ }
}
-
int
is_traced(name)
const char *name;
{
struct t *n;
- if (flags & TRACE_ALL)
- return 1;
for (n = l; n != NULL; n = n->next)
if (STREQ(n->name, name))
- return 1;
- return 0;
+ return n->on;
+ return (flags & TRACE_ALL) ? 1 : 0;
}
void