1
0
mirror of https://github.com/openbsd/src.git synced 2026-04-24 06:04:47 +00:00

rename a few functions and defines

also reformat some comments with ludicrously short lines.  No functional
changes, except the usage of `eval' instead of `expr' in two error message,
since that's the actual macro name (expr is merely an alias for eval)

diff from espie, typo from sthen

ok sthen
This commit is contained in:
op
2026-02-25 05:37:25 +00:00
parent 2d65136ff0
commit 31a6dbcb58
6 changed files with 173 additions and 185 deletions

View File

@@ -1,4 +1,4 @@
/* $OpenBSD: eval.c,v 1.80 2026/02/10 08:42:35 tb Exp $ */
/* $OpenBSD: eval.c,v 1.81 2026/02/25 05:37:25 op Exp $ */
/* $NetBSD: eval.c,v 1.7 1996/11/10 21:21:29 pk Exp $ */
/*
@@ -57,17 +57,17 @@
static void dodefn(const char *);
static void dopushdef(const char *, const char *);
static void dodump(const char *[], int);
static void dodumpdef(const char *[], int);
static void dotrace(const char *[], int, int);
static void doifelse(const char *[], int);
static int doincl(const char *);
static int doinclude(const char *);
static int dopaste(const char *);
static void dochq(const char *[], int);
static void dochc(const char *[], int);
static void dochangequote(const char *[], int);
static void dochangecom(const char *[], int);
static void dom4wrap(const char *);
static void dodiv(int);
static void doundiv(const char *[], int);
static void dosub(const char *[], int);
static void dodivert(int);
static void doundivert(const char *[], int);
static void dosubstr(const char *[], int);
static void map(char *, const char *, const char *, const char *);
static const char *handledash(char *, char *, const char *);
static void expand_builtin(const char *[], int, int);
@@ -105,7 +105,7 @@ eval(const char *argv[], int argc, int td, int is_traced)
m4errx(1, "expanding recursive definition for %s.", argv[1]);
if (is_traced)
mark = trace(argv, argc, infile+ilevel);
if (td == MACRTYPE)
if (td == MACROTYPE)
expand_macro(argv, argc);
else
expand_builtin(argv, argc, td);
@@ -146,18 +146,18 @@ expand_builtin(const char *argv[], int argc, int td)
switch (td & TYPEMASK) {
case DEFITYPE:
case DEFINETYPE:
if (argc > 2)
dodefine(argv[2], (argc > 3) ? argv[3] : null);
break;
case PUSDTYPE:
case PUSHDEFTYPE:
if (argc > 2)
dopushdef(argv[2], (argc > 3) ? argv[3] : null);
break;
case DUMPTYPE:
dodump(argv, argc);
case DUMPDEFTYPE:
dodumpdef(argv, argc);
break;
case TRACEONTYPE:
@@ -168,10 +168,9 @@ expand_builtin(const char *argv[], int argc, int td)
dotrace(argv, argc, 0);
break;
case EXPRTYPE:
case EVALTYPE:
/*
* doexpr - evaluate arithmetic
* expression
* doeval - evaluate arithmetic expression
*/
{
int base = 10;
@@ -180,14 +179,14 @@ expand_builtin(const char *argv[], int argc, int td)
if (argc > 3) {
base = strtonum(argv[3], 2, 36, &errstr);
if (errstr) {
m4errx(1, "expr: base is %s: %s.",
m4errx(1, "eval: base is %s: %s.",
errstr, argv[3]);
}
}
if (argc > 4) {
maxdigits = strtonum(argv[4], 0, INT_MAX, &errstr);
if (errstr) {
m4errx(1, "expr: maxdigits is %s: %s.",
m4errx(1, "eval: maxdigits is %s: %s.",
errstr, argv[4]);
}
}
@@ -196,15 +195,14 @@ expand_builtin(const char *argv[], int argc, int td)
break;
}
case IFELTYPE:
case IFELSETYPE:
doifelse(argv, argc);
break;
case IFDFTYPE:
case IFDEFTYPE:
/*
* doifdef - select one of two
* alternatives based on the existence of
* another definition
* doifdef - select one of two alternatives based
* on the existence of another definition
*/
if (argc > 3) {
if (lookup_macro_definition(argv[2]) != NULL)
@@ -214,18 +212,16 @@ expand_builtin(const char *argv[], int argc, int td)
}
break;
case LENGTYPE:
case LENTYPE:
/*
* dolen - find the length of the
* argument
* dolen - find the length of the argument
*/
pbnum((argc > 2) ? strlen(argv[2]) : 0);
break;
case INCRTYPE:
/*
* doincr - increment the value of the
* argument
* doincr - increment the value of the argument
*/
if (argc > 2) {
n = strtonum(argv[2], INT_MIN, INT_MAX-1, &errstr);
@@ -238,8 +234,7 @@ expand_builtin(const char *argv[], int argc, int td)
case DECRTYPE:
/*
* dodecr - decrement the value of the
* argument
* dodecr - decrement the value of the argument
*/
if (argc > 2) {
n = strtonum(argv[2], INT_MIN+1, INT_MAX, &errstr);
@@ -250,9 +245,9 @@ expand_builtin(const char *argv[], int argc, int td)
}
break;
case SYSCTYPE:
case SYSCMDTYPE:
/*
* dosys - execute system command
* dosyscmd - execute system command
*/
if (argc > 2) {
fflush(stdout);
@@ -260,10 +255,9 @@ expand_builtin(const char *argv[], int argc, int td)
}
break;
case SYSVTYPE:
case SYSVALTYPE:
/*
* dosysval - return value of the last
* system call.
* dosysval - return value of the last system call.
*
*/
pbnum(sysval);
@@ -273,9 +267,9 @@ expand_builtin(const char *argv[], int argc, int td)
if (argc > 2)
doesyscmd(argv[2]);
break;
case INCLTYPE:
case INCLUDETYPE:
if (argc > 2) {
if (!doincl(argv[2])) {
if (!doinclude(argv[2])) {
if (mimic_gnu) {
warn("%s at line %lu: include(%s)",
CURRENT_NAME, CURRENT_LINE, argv[2]);
@@ -291,19 +285,20 @@ expand_builtin(const char *argv[], int argc, int td)
}
break;
case SINCTYPE:
case SINCLUDETYPE:
/* like include, but don't error out if file not found */
if (argc > 2)
(void) doincl(argv[2]);
(void) doinclude(argv[2]);
break;
#ifdef EXTENDED
case PASTTYPE:
case PASTETYPE:
if (argc > 2)
if (!dopaste(argv[2]))
err(1, "%s at line %lu: paste(%s)",
CURRENT_NAME, CURRENT_LINE, argv[2]);
break;
case SPASTYPE:
case SPASTETYPE:
if (argc > 2)
(void) dopaste(argv[2]);
break;
@@ -311,28 +306,27 @@ expand_builtin(const char *argv[], int argc, int td)
doformat(argv, argc);
break;
#endif
case CHNQTYPE:
dochq(argv, ac);
case CHANGEQUOTETYPE:
dochangequote(argv, ac);
break;
case CHNCTYPE:
dochc(argv, argc);
case CHANGECOMTYPE:
dochangecom(argv, argc);
break;
case SUBSTYPE:
case SUBSTRTYPE:
/*
* dosub - select substring
* dosubstr - select substring
*
*/
if (argc > 3)
dosub(argv, argc);
dosubstr(argv, argc);
break;
case SHIFTYPE:
case SHIFTTYPE:
/*
* doshift - push back all arguments
* except the first one (i.e. skip
* argv[2])
* doshift - push back all arguments except the first one
* (i.e. skip argv[2])
*/
if (argc > 3) {
for (n = argc - 1; n > 3; n--) {
@@ -347,14 +341,14 @@ expand_builtin(const char *argv[], int argc, int td)
}
break;
case DIVRTYPE:
case DIVERTTYPE:
if (argc > 2) {
n = strtonum(argv[2], INT_MIN, INT_MAX, &errstr);
if (errstr)
m4errx(1, "divert: argument is %s: %s.",
errstr, argv[2]);
if (n != 0) {
dodiv(n);
dodivert(n);
break;
}
}
@@ -362,42 +356,39 @@ expand_builtin(const char *argv[], int argc, int td)
oindex = 0;
break;
case UNDVTYPE:
doundiv(argv, argc);
case UNDIVERTTYPE:
doundivert(argv, argc);
break;
case DIVNTYPE:
case DIVNUMTYPE:
/*
* dodivnum - return the number of
* current output diversion
* dodivnum - return the number of current output diversion
*/
pbnum(oindex);
break;
case UNDFTYPE:
case UNDEFINETYPE:
/*
* doundefine - undefine a previously
* defined macro(s) or m4 keyword(s).
* doundefine - undefine a previously defined macro(s) or m4 keyword(s).
*/
if (argc > 2)
for (n = 2; n < argc; n++)
macro_undefine(argv[n]);
break;
case POPDTYPE:
case POPDEFTYPE:
/*
* dopopdef - remove the topmost
* definitions of macro(s) or m4
* keyword(s).
* dopopdef - remove the topmost definitions of macro(s)
* or m4 keyword(s).
*/
if (argc > 2)
for (n = 2; n < argc; n++)
macro_popdef(argv[n]);
break;
case MKTMTYPE:
case MKSTEMPTYPE:
/*
* dotemp - create a temporary file
* domkstemp - safely create a temporary file
*/
if (argc > 2) {
int fd;
@@ -416,11 +407,10 @@ expand_builtin(const char *argv[], int argc, int td)
}
break;
case TRNLTYPE:
case TRANSLITTYPE:
/*
* dotranslit - replace all characters in
* the source string that appears in the
* "from" string with the corresponding
* dotranslit - replace all characters in the source string
* that appear in the "from" string with the corresponding
* characters in the "to" string.
*/
if (argc > 3) {
@@ -437,19 +427,17 @@ expand_builtin(const char *argv[], int argc, int td)
pbstr(argv[2]);
break;
case INDXTYPE:
case INDEXTYPE:
/*
* doindex - find the index of the second
* argument string in the first argument
* string. -1 if not present.
* doindex - find the index of the second argument string
* in the first argument string. -1 if not present.
*/
pbnum((argc > 3) ? indx(argv[2], argv[3]) : -1);
pbnum((argc > 3) ? doindex(argv[2], argv[3]) : -1);
break;
case ERRPTYPE:
case ERRPRINTTYPE:
/*
* doerrp - print the arguments to stderr
* file
* doerrprint - print the arguments to stderr
*/
if (argc > 2) {
for (n = 2; n < argc; n++)
@@ -458,16 +446,15 @@ expand_builtin(const char *argv[], int argc, int td)
}
break;
case DNLNTYPE:
case DNLTYPE:
/*
* dodnl - eat-up-to and including
* newline
* dodnl - eat-up-to and including newline
*/
while ((c = gpbc()) != '\n' && c != EOF)
;
break;
case M4WRTYPE:
case M4WRAPTYPE:
/*
* dom4wrap - set up for
* wrap-up/wind-down activity
@@ -476,9 +463,9 @@ expand_builtin(const char *argv[], int argc, int td)
dom4wrap(argv[2]);
break;
case EXITTYPE:
case M4EXITTYPE:
/*
* doexit - immediate exit from m4.
* dom4exit - immediate exit from m4.
*/
killdiv();
exit((argc > 2) ? atoi(argv[2]) : 0);
@@ -500,7 +487,7 @@ expand_builtin(const char *argv[], int argc, int td)
dobuiltin(argv, argc);
break;
case PATSTYPE:
case PATSUBSTTYPE:
if (argc > 2)
dopatsubst(argv, argc);
break;
@@ -621,7 +608,7 @@ dodefn(const char *name)
struct macro_definition *p;
if ((p = lookup_macro_definition(name)) != NULL) {
if ((p->type & TYPEMASK) == MACRTYPE) {
if ((p->type & TYPEMASK) == MACROTYPE) {
pbstr(rquote);
pbstr(p->defn);
pbstr(lquote);
@@ -657,7 +644,7 @@ dump_one_def(const char *name, struct macro_definition *p)
if (!traceout)
traceout = stderr;
if (mimic_gnu) {
if ((p->type & TYPEMASK) == MACRTYPE)
if ((p->type & TYPEMASK) == MACROTYPE)
fprintf(traceout, "%s:\t%s\n", name, p->defn);
else {
fprintf(traceout, "%s:\t<%s>\n", name, p->defn);
@@ -672,7 +659,7 @@ dump_one_def(const char *name, struct macro_definition *p)
* hash table is dumped.
*/
static void
dodump(const char *argv[], int argc)
dodumpdef(const char *argv[], int argc)
{
int n;
struct macro_definition *p;
@@ -724,7 +711,7 @@ doifelse(const char *argv[], int argc)
* doinclude - include a given file.
*/
static int
doincl(const char *ifile)
doinclude(const char *ifile)
{
if (ilevel + 1 == MAXINP)
m4errx(1, "too many include files.");
@@ -761,10 +748,10 @@ dopaste(const char *pfile)
#endif
/*
* dochq - change quote characters
* dochangequote - change quote characters
*/
static void
dochq(const char *argv[], int ac)
dochangequote(const char *argv[], int ac)
{
if (ac == 2) {
lquote[0] = LQUOTE; lquote[1] = EOS;
@@ -780,10 +767,10 @@ dochq(const char *argv[], int ac)
}
/*
* dochc - change comment characters
* dochangecom - change comment characters
*/
static void
dochc(const char *argv[], int argc)
dochangecom(const char *argv[], int argc)
{
/* XXX Note that there is no difference between no argument and a single
* empty argument.
@@ -822,7 +809,7 @@ dom4wrap(const char *text)
* dodivert - divert the output to a temporary file
*/
static void
dodiv(int n)
dodivert(int n)
{
int fd;
@@ -852,7 +839,7 @@ dodiv(int n)
* other outputs, in numerical order.
*/
static void
doundiv(const char *argv[], int argc)
doundivert(const char *argv[], int argc)
{
int ind;
int n;
@@ -877,10 +864,10 @@ doundiv(const char *argv[], int argc)
}
/*
* dosub - select substring
* dosubstr - select substring
*/
static void
dosub(const char *argv[], int argc)
dosubstr(const char *argv[], int argc)
{
const char *ap, *fc, *k;
int nc;

View File

@@ -1,4 +1,4 @@
/* $OpenBSD: extern.h,v 1.56 2024/05/21 05:00:48 jsg Exp $ */
/* $OpenBSD: extern.h,v 1.57 2026/02/25 05:37:25 op Exp $ */
/* $NetBSD: extern.h,v 1.3 1996/01/13 23:25:24 pk Exp $ */
/*-
@@ -94,7 +94,7 @@ extern int exit_code;
/* misc.c */
extern void chrsave(int);
extern void getdiv(int);
extern ptrdiff_t indx(const char *, const char *);
extern ptrdiff_t doindex(const char *, const char *);
extern void initspaces(void);
extern void killdiv(void);
extern void onintr(int);

View File

@@ -1,4 +1,4 @@
/* $OpenBSD: look.c,v 1.25 2025/11/05 17:10:45 tb Exp $ */
/* $OpenBSD: look.c,v 1.26 2026/02/25 05:37:25 op Exp $ */
/*
* Copyright (c) 1989, 1993
@@ -124,7 +124,7 @@ setup_definition(struct macro_definition *d, const char *defn, const char *name)
d->defn = null;
else
d->defn = xstrdup(defn);
d->type = MACRTYPE;
d->type = MACROTYPE;
}
if (STREQ(name, defn))
d->type |= RECDEF;
@@ -143,7 +143,7 @@ create_entry(const char *name)
n = ohash_create_entry(&macro_info, name, &end);
ohash_insert(&macros, i, n);
n->trace_flags = FLAG_NO_TRACE;
n->builtin_type = MACRTYPE;
n->builtin_type = MACROTYPE;
n->d = NULL;
}
return n;
@@ -268,7 +268,7 @@ macro_getbuiltin(const char *name)
ndptr p;
p = lookup(name);
if (p == NULL || p->builtin_type == MACRTYPE)
if (p == NULL || p->builtin_type == MACROTYPE)
return NULL;
else
return p;

View File

@@ -1,4 +1,4 @@
/* $OpenBSD: main.c,v 1.89 2026/02/18 08:54:46 deraadt Exp $ */
/* $OpenBSD: main.c,v 1.90 2026/02/25 05:37:25 op Exp $ */
/* $NetBSD: main.c,v 1.12 1997/02/08 23:54:49 cgd Exp $ */
/*-
@@ -86,53 +86,54 @@ struct keyblk {
};
struct keyblk keywrds[] = { /* m4 keywords to be installed */
{ "include", INCLTYPE },
{ "sinclude", SINCTYPE },
{ "define", DEFITYPE },
{ "include", INCLUDETYPE },
{ "sinclude", SINCLUDETYPE },
{ "define", DEFINETYPE },
{ "defn", DEFNTYPE },
{ "divert", DIVRTYPE | NOARGS },
{ "expr", EXPRTYPE },
{ "eval", EXPRTYPE },
{ "substr", SUBSTYPE },
{ "ifelse", IFELTYPE },
{ "ifdef", IFDFTYPE },
{ "len", LENGTYPE },
{ "divert", DIVERTTYPE | NOARGS },
{ "eval", EVALTYPE },
{ "expr", EVALTYPE },
{ "substr", SUBSTRTYPE },
{ "ifelse", IFELSETYPE },
{ "ifdef", IFDEFTYPE },
{ "len", LENTYPE },
{ "incr", INCRTYPE },
{ "decr", DECRTYPE },
{ "dnl", DNLNTYPE | NOARGS },
{ "changequote", CHNQTYPE | NOARGS },
{ "changecom", CHNCTYPE | NOARGS },
{ "index", INDXTYPE },
{ "dnl", DNLTYPE | NOARGS },
{ "changequote", CHANGEQUOTETYPE | NOARGS },
{ "changecom", CHANGECOMTYPE | NOARGS },
{ "index", INDEXTYPE },
#ifdef EXTENDED
{ "paste", PASTTYPE },
{ "spaste", SPASTYPE },
{ "paste", PASTETYPE },
{ "spaste", SPASTETYPE },
/* Newer extensions, needed to handle gnu-m4 scripts */
{ "indir", INDIRTYPE},
{ "builtin", BUILTINTYPE},
{ "patsubst", PATSTYPE},
{ "patsubst", PATSUBSTTYPE},
{ "regexp", REGEXPTYPE},
{ "esyscmd", ESYSCMDTYPE},
{ "__file__", FILENAMETYPE | NOARGS},
{ "__line__", LINETYPE | NOARGS},
#endif
{ "popdef", POPDTYPE },
{ "pushdef", PUSDTYPE },
{ "dumpdef", DUMPTYPE | NOARGS },
{ "shift", SHIFTYPE | NOARGS },
{ "translit", TRNLTYPE },
{ "undefine", UNDFTYPE },
{ "undivert", UNDVTYPE | NOARGS },
{ "divnum", DIVNTYPE | NOARGS },
{ "maketemp", MKTMTYPE },
{ "mkstemp", MKTMTYPE },
{ "errprint", ERRPTYPE | NOARGS },
{ "m4wrap", M4WRTYPE | NOARGS },
{ "m4exit", EXITTYPE | NOARGS },
{ "syscmd", SYSCTYPE },
{ "sysval", SYSVTYPE | NOARGS },
{ "popdef", POPDEFTYPE },
{ "pushdef", PUSHDEFTYPE },
{ "dumpdef", DUMPDEFTYPE | NOARGS },
{ "shift", SHIFTTYPE | NOARGS },
{ "translit", TRANSLITTYPE },
{ "undefine", UNDEFINETYPE },
{ "undivert", UNDIVERTTYPE | NOARGS },
{ "divnum", DIVNUMTYPE | NOARGS },
{ "maketemp", MKSTEMPTYPE },
{ "mkstemp", MKSTEMPTYPE },
{ "errprint", ERRPRINTTYPE | NOARGS },
{ "m4wrap", M4WRAPTYPE | NOARGS },
{ "m4exit", M4EXITTYPE | NOARGS },
{ "syscmd", SYSCMDTYPE },
{ "sysval", SYSVALTYPE | NOARGS },
{ "traceon", TRACEONTYPE | NOARGS },
{ "traceoff", TRACEOFFTYPE | NOARGS },
/* Macro that expands to itself, signature of the current OS */
{ "unix", SELFTYPE | NOARGS },
};

View File

@@ -1,4 +1,4 @@
/* $OpenBSD: mdef.h,v 1.34 2022/12/26 19:16:01 jmc Exp $ */
/* $OpenBSD: mdef.h,v 1.35 2026/02/25 05:37:25 op Exp $ */
/* $NetBSD: mdef.h,v 1.7 1996/01/13 23:25:27 pk Exp $ */
/*
@@ -41,50 +41,50 @@
# define UNUSED
#endif
#define MACRTYPE 1
#define DEFITYPE 2
#define EXPRTYPE 3
#define SUBSTYPE 4
#define IFELTYPE 5
#define LENGTYPE 6
#define CHNQTYPE 7
#define SYSCTYPE 8
#define UNDFTYPE 9
#define INCLTYPE 10
#define SINCTYPE 11
#define PASTTYPE 12
#define SPASTYPE 13
#define INCRTYPE 14
#define IFDFTYPE 15
#define PUSDTYPE 16
#define POPDTYPE 17
#define SHIFTYPE 18
#define DECRTYPE 19
#define DIVRTYPE 20
#define UNDVTYPE 21
#define DIVNTYPE 22
#define MKTMTYPE 23
#define ERRPTYPE 24
#define M4WRTYPE 25
#define TRNLTYPE 26
#define DNLNTYPE 27
#define DUMPTYPE 28
#define CHNCTYPE 29
#define INDXTYPE 30
#define SYSVTYPE 31
#define EXITTYPE 32
#define DEFNTYPE 33
#define SELFTYPE 34
#define INDIRTYPE 35
#define BUILTINTYPE 36
#define PATSTYPE 37
#define FILENAMETYPE 38
#define LINETYPE 39
#define REGEXPTYPE 40
#define ESYSCMDTYPE 41
#define TRACEONTYPE 42
#define TRACEOFFTYPE 43
#define FORMATTYPE 44
#define MACROTYPE 1
#define DEFINETYPE 2
#define EVALTYPE 3
#define SUBSTRTYPE 4
#define IFELSETYPE 5
#define LENTYPE 6
#define CHANGEQUOTETYPE 7
#define SYSCMDTYPE 8
#define UNDEFINETYPE 9
#define INCLUDETYPE 10
#define SINCLUDETYPE 11
#define PASTETYPE 12
#define SPASTETYPE 13
#define INCRTYPE 14
#define IFDEFTYPE 15
#define PUSHDEFTYPE 16
#define POPDEFTYPE 17
#define SHIFTTYPE 18
#define DECRTYPE 19
#define DIVERTTYPE 20
#define UNDIVERTTYPE 21
#define DIVNUMTYPE 22
#define MKSTEMPTYPE 23
#define ERRPRINTTYPE 24
#define M4WRAPTYPE 25
#define TRANSLITTYPE 26
#define DNLTYPE 27
#define DUMPDEFTYPE 28
#define CHANGECOMTYPE 29
#define INDEXTYPE 30
#define SYSVALTYPE 31
#define M4EXITTYPE 32
#define DEFNTYPE 33
#define SELFTYPE 34
#define INDIRTYPE 35
#define BUILTINTYPE 36
#define PATSUBSTTYPE 37
#define FILENAMETYPE 38
#define LINETYPE 39
#define REGEXPTYPE 40
#define ESYSCMDTYPE 41
#define TRACEONTYPE 42
#define TRACEOFFTYPE 43
#define FORMATTYPE 44
#define BUILTIN_MARKER "__builtin_"

View File

@@ -1,4 +1,4 @@
/* $OpenBSD: misc.c,v 1.49 2025/11/05 17:10:45 tb Exp $ */
/* $OpenBSD: misc.c,v 1.50 2026/02/25 05:37:25 op Exp $ */
/* $NetBSD: misc.c,v 1.6 1995/09/28 05:37:41 tls Exp $ */
/*
@@ -66,7 +66,7 @@ unsigned char *endpbb; /* end of push-back buffer */
* find the index of second str in the first str.
*/
ptrdiff_t
indx(const char *s1, const char *s2)
doindex(const char *s1, const char *s2)
{
char *t;