mirror of
https://github.com/openbsd/src.git
synced 2025-01-10 06:47:55 -08:00
One single point for all macros/builtin expansion.
This commit is contained in:
parent
422db66274
commit
08f7f207a7
@ -1,4 +1,4 @@
|
||||
/* $OpenBSD: eval.c,v 1.29 2001/06/13 12:20:43 espie Exp $ */
|
||||
/* $OpenBSD: eval.c,v 1.30 2001/09/18 13:52:58 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.29 2001/06/13 12:20:43 espie Exp $";
|
||||
static char rcsid[] = "$OpenBSD: eval.c,v 1.30 2001/09/18 13:52:58 espie Exp $";
|
||||
#endif
|
||||
#endif /* not lint */
|
||||
|
||||
@ -78,8 +78,30 @@ static void doundiv __P((const char *[], int));
|
||||
static void dosub __P((const char *[], int));
|
||||
static void map __P((char *, const char *, const char *, const char *));
|
||||
static const char *handledash __P((char *, char *, const char *));
|
||||
static void expand_builtin __P((const char *[], int, int));
|
||||
static void expand_macro __P((const char *[], int));
|
||||
|
||||
|
||||
/*
|
||||
* eval - evaluate built-in macros.
|
||||
* eval - eval all macros and builtins calls
|
||||
*/
|
||||
void
|
||||
eval(argv, argc, td)
|
||||
const char *argv[];
|
||||
int argc;
|
||||
int td;
|
||||
{
|
||||
if (td & RECDEF)
|
||||
errx(1, "%s at line %lu: expanding recursive definition for %s",
|
||||
CURRENT_NAME, CURRENT_LINE, argv[1]);
|
||||
if (td == MACRTYPE)
|
||||
expand_macro(argv, argc);
|
||||
else
|
||||
expand_builtin(argv, argc, td);
|
||||
}
|
||||
|
||||
/*
|
||||
* expand_builtin - evaluate built-in macros.
|
||||
* argc - number of elements in argv.
|
||||
* argv - element vector :
|
||||
* argv[0] = definition of a user
|
||||
@ -98,7 +120,7 @@ static const char *handledash __P((char *, char *, const char *));
|
||||
*/
|
||||
|
||||
void
|
||||
eval(argv, argc, td)
|
||||
expand_builtin(argv, argc, td)
|
||||
const char *argv[];
|
||||
int argc;
|
||||
int td;
|
||||
@ -112,9 +134,6 @@ eval(argv, argc, td)
|
||||
printf("argv[%d] = %s\n", n, argv[n]);
|
||||
#endif
|
||||
|
||||
if (td & RECDEF)
|
||||
errx(1, "%s at line %lu: expanding recursive definition for %s",
|
||||
CURRENT_NAME, CURRENT_LINE, argv[1]);
|
||||
/*
|
||||
* if argc == 3 and argv[2] is null, then we
|
||||
* have macro-or-builtin() type call. We adjust
|
||||
@ -446,10 +465,10 @@ eval(argv, argc, td)
|
||||
char *dumpfmt = "`%s'\t`%s'\n"; /* format string for dumpdef */
|
||||
|
||||
/*
|
||||
* expand - user-defined macro expansion
|
||||
* expand_macro - user-defined macro expansion
|
||||
*/
|
||||
void
|
||||
expand(argv, argc)
|
||||
expand_macro(argv, argc)
|
||||
const char *argv[];
|
||||
int argc;
|
||||
{
|
||||
|
@ -1,4 +1,4 @@
|
||||
/* $OpenBSD: extern.h,v 1.21 2000/07/27 17:44:33 espie Exp $ */
|
||||
/* $OpenBSD: extern.h,v 1.22 2001/09/18 13:52:58 espie Exp $ */
|
||||
/* $NetBSD: extern.h,v 1.3 1996/01/13 23:25:24 pk Exp $ */
|
||||
|
||||
/*-
|
||||
@ -41,7 +41,6 @@
|
||||
|
||||
/* eval.c */
|
||||
extern void eval __P((const char *[], int, int));
|
||||
extern void expand __P((const char *[], int));
|
||||
extern void dodefine __P((const char *, const char *));
|
||||
|
||||
/* expr.c */
|
||||
|
@ -1,4 +1,4 @@
|
||||
/* $OpenBSD: gnum4.c,v 1.11 2001/09/18 13:42:37 espie Exp $ */
|
||||
/* $OpenBSD: gnum4.c,v 1.12 2001/09/18 13:52:58 espie Exp $ */
|
||||
|
||||
/*
|
||||
* Copyright (c) 1999 Marc Espie
|
||||
@ -173,10 +173,7 @@ doindir(argv, argc)
|
||||
if (p == NULL)
|
||||
errx(1, "undefined macro %s", argv[2]);
|
||||
argv[1] = p->defn;
|
||||
if (p->type == MACRTYPE)
|
||||
expand(argv+1, argc-1);
|
||||
else
|
||||
eval(argv+1, argc-1, p->type);
|
||||
eval(argv+1, argc-1, p->type);
|
||||
}
|
||||
|
||||
void
|
||||
|
@ -1,4 +1,4 @@
|
||||
/* $OpenBSD: main.c,v 1.43 2001/09/18 13:44:51 espie Exp $ */
|
||||
/* $OpenBSD: main.c,v 1.44 2001/09/18 13:52:58 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.43 2001/09/18 13:44:51 espie Exp $";
|
||||
static char rcsid[] = "$OpenBSD: main.c,v 1.44 2001/09/18 13:52:58 espie Exp $";
|
||||
#endif
|
||||
#endif /* not lint */
|
||||
|
||||
@ -336,10 +336,8 @@ macro()
|
||||
|
||||
if (sp == STACKMAX)
|
||||
errx(1, "internal stack overflow");
|
||||
if (CALTYP == MACRTYPE)
|
||||
expand((const char **) mstack+fp+1, 2);
|
||||
else
|
||||
eval((const char **) mstack+fp+1, 2, CALTYP);
|
||||
eval((const char **) mstack+fp+1, 2,
|
||||
CALTYP);
|
||||
|
||||
ep = PREVEP; /* flush strspace */
|
||||
sp = PREVSP; /* previous sp.. */
|
||||
@ -436,10 +434,8 @@ macro()
|
||||
if (sp == STACKMAX)
|
||||
errx(1, "internal stack overflow");
|
||||
|
||||
if (CALTYP == MACRTYPE)
|
||||
expand((const char **) mstack+fp+1, sp-fp);
|
||||
else
|
||||
eval((const char **) mstack+fp+1, sp-fp, CALTYP);
|
||||
eval((const char **) mstack+fp+1, sp-fp,
|
||||
CALTYP);
|
||||
|
||||
ep = PREVEP; /* flush strspace */
|
||||
sp = PREVSP; /* previous sp.. */
|
||||
|
Loading…
Reference in New Issue
Block a user