summaryrefslogtreecommitdiff
path: root/usr.bin/m4/trace.c
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/trace.c
parent37bf947e8d7999f07e2efca7fba6082b5a75f630 (diff)
traceon/traceoff built-ins.
Diffstat (limited to 'usr.bin/m4/trace.c')
-rw-r--r--usr.bin/m4/trace.c57
1 files changed, 45 insertions, 12 deletions
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