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

add a flag for each macro name that records built-in status.

Fold built-in lookup into normal lookup.
okay millert@
This commit is contained in:
espie 2003-06-30 22:11:38 +00:00
parent ec8803d52b
commit 7888c33aa2
4 changed files with 36 additions and 27 deletions

View File

@ -1,4 +1,4 @@
/* $OpenBSD: extern.h,v 1.36 2003/06/30 22:10:21 espie Exp $ */
/* $OpenBSD: extern.h,v 1.37 2003/06/30 22:11:38 espie Exp $ */
/* $NetBSD: extern.h,v 1.3 1996/01/13 23:25:24 pk Exp $ */
/*-
@ -70,10 +70,11 @@ extern void setup_builtin(const char *, unsigned int);
extern void macro_for_all(void (*)(const char *, struct macro_definition *));
extern const char *macro_name(ndptr);
extern struct macro_definition *macro_getdef(ndptr);
extern ndptr macro_getbuiltin(const char *);
extern int macro_builtin_type(ndptr);
/* main.c */
extern void outputstr(const char *);
extern int builtin_type(const char *);
extern void do_emit_synchline(void);
#define emit_synchline() do { if (synch_lines) do_emit_synchline(); } while(0)

View File

@ -1,4 +1,4 @@
/* $OpenBSD: gnum4.c,v 1.23 2003/06/30 21:47:21 espie Exp $ */
/* $OpenBSD: gnum4.c,v 1.24 2003/06/30 22:11:38 espie Exp $ */
/*
* Copyright (c) 1999 Marc Espie
@ -172,11 +172,11 @@ doindir(const char *argv[], int argc)
void
dobuiltin(const char *argv[], int argc)
{
int n;
ndptr p;
argv[1] = NULL;
n = builtin_type(argv[2]);
if (n != -1)
eval(argv+1, argc-1, n, traced_macros && is_traced(argv[2]));
p = macro_getbuiltin(argv[2]);
if (p != NULL)
eval(argv+1, argc-1, macro_builtin_type(p), traced_macros && is_traced(argv[2]));
else
errx(1, "unknown builtin %s", argv[2]);
}

View File

@ -1,4 +1,4 @@
/* $OpenBSD: look.c,v 1.13 2003/06/30 22:10:21 espie Exp $ */
/* $OpenBSD: look.c,v 1.14 2003/06/30 22:11:38 espie Exp $ */
/*
* Copyright (c) 1989, 1993
@ -53,6 +53,7 @@ static char sccsid[] = "@(#)look.c 8.1 (Berkeley) 6/6/93";
#include "extern.h"
struct ndblock { /* hashtable structure */
unsigned int builtin_type;
struct macro_definition *d;
char name[1]; /* entry name.. */
};
@ -99,13 +100,11 @@ lookup_macro_definition(const char *name)
static void
setup_definition(struct macro_definition *d, const char *defn, const char *name)
{
int n;
ndptr p;
if (strncmp(defn, BUILTIN_MARKER, sizeof(BUILTIN_MARKER)-1) == 0 &&
(n = builtin_type(defn+sizeof(BUILTIN_MARKER)-1)) != -1) {
d->type = n & TYPEMASK;
if ((n & NOARGS) == 0)
d->type |= NEEDARGS;
(p = macro_getbuiltin(defn+sizeof(BUILTIN_MARKER)-1)) != NULL) {
d->type = macro_builtin_type(p);
d->defn = xstrdup(defn+sizeof(BUILTIN_MARKER)-1);
} else {
if (!*defn)
@ -130,6 +129,7 @@ create_entry(const char *name)
if (n == NULL) {
n = ohash_create_entry(&macro_info, name, &end);
ohash_insert(&macros, i, n);
n->builtin_type = MACRTYPE;
n->d = NULL;
}
return n;
@ -212,6 +212,7 @@ setup_builtin(const char *name, unsigned int type)
ndptr n;
n = create_entry(name);
n->builtin_type = type;
n->d = xalloc(sizeof(struct macro_definition));
n->d->defn = xstrdup(name);
n->d->type = type;
@ -229,3 +230,22 @@ macro_getdef(ndptr p)
{
return p->d;
}
ndptr
macro_getbuiltin(const char *name)
{
ndptr p;
p = lookup(name);
if (p == NULL || p->builtin_type == MACRTYPE)
return NULL;
else
return p;
}
int
macro_builtin_type(ndptr p)
{
return p->builtin_type;
}

View File

@ -1,4 +1,4 @@
/* $OpenBSD: main.c,v 1.61 2003/06/30 22:10:21 espie Exp $ */
/* $OpenBSD: main.c,v 1.62 2003/06/30 22:11:38 espie Exp $ */
/* $NetBSD: main.c,v 1.12 1997/02/08 23:54:49 cgd Exp $ */
/*-
@ -43,7 +43,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.61 2003/06/30 22:10:21 espie Exp $";
static char rcsid[] = "$OpenBSD: main.c,v 1.62 2003/06/30 22:11:38 espie Exp $";
#endif
#endif /* not lint */
@ -593,18 +593,6 @@ initkwds(void)
}
}
/* Look up a builtin type, even if overridden by the user */
int
builtin_type(const char *key)
{
int i;
for (i = 0; i != MAXKEYS; i++)
if (STREQ(keywrds[i].knam, key))
return keywrds[i].ktyp;
return -1;
}
static void
record(struct position *t, int lev)
{