1
0
mirror of https://github.com/openbsd/src.git synced 2025-01-10 06:47:55 -08:00

traceon/traceoff built-ins.

This commit is contained in:
espie 2001-09-27 11:40:33 +00:00
parent 4994900200
commit 34970243d3
6 changed files with 94 additions and 23 deletions

View File

@ -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
@ -675,6 +684,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.
*/

View File

@ -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 *));

View File

@ -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.

View File

@ -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);

View File

@ -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 */

View File

@ -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 unsigned int letter_to_flag __P((int));
static void print_header __P((struct input_file *));
static unsigned int flags = TRACE_QUOTE | TRACE_EXPANSION;
static struct t {
struct t *next;
char *name;
int on;
} *l;
void
mark_traced(name)
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 *
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, on)
const char *name;
int on;
{
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