Download raw body.
patch: clean-up m4 function and macro names
Maybe it made sense to abbreviate things randomly 20 years ago,
but today, it only makes it more difficult to find things.
This patch renames a bunch of defines and function names to make
things simpler to follow.
Also reformat some comments with ludicrously short lines.
Some editorial choices: eval is the actual sanctionned macro name,
mkstemp reflects the actual semantics we chose.
And we keep unix as "selftype" since it could be used for other OS markers.
Also, rename indx to doindex to remove any ambiguity towards idx and
strstr, since the return values are notably different, and it matches
what actually happens.
There should be zero functional changes, just something that's clearer.
Index: eval.c
===================================================================
RCS file: /build/data/openbsd/cvs/src/usr.bin/m4/eval.c,v
diff -u -p -r1.80 eval.c
--- eval.c 10 Feb 2026 08:42:35 -0000 1.80
+++ eval.c 24 Feb 2026 09:52:15 -0000
@@ -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 t
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 a
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 a
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 a
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 a
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 a
}
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 a
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 a
}
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 a
}
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 a
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 a
}
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 a
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 a
}
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 a
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 a
}
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 appears 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 a
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 a
}
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 a
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 a
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 ma
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 ma
* 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;
Index: extern.h
===================================================================
RCS file: /build/data/openbsd/cvs/src/usr.bin/m4/extern.h,v
diff -u -p -r1.56 extern.h
--- extern.h 21 May 2024 05:00:48 -0000 1.56
+++ extern.h 24 Feb 2026 09:34:15 -0000
@@ -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);
Index: look.c
===================================================================
RCS file: /build/data/openbsd/cvs/src/usr.bin/m4/look.c,v
diff -u -p -r1.25 look.c
--- look.c 5 Nov 2025 17:10:45 -0000 1.25
+++ look.c 24 Feb 2026 09:37:00 -0000
@@ -124,7 +124,7 @@ setup_definition(struct macro_definition
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(¯o_info, name, &end);
ohash_insert(¯os, 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;
Index: main.c
===================================================================
RCS file: /build/data/openbsd/cvs/src/usr.bin/m4/main.c,v
diff -u -p -r1.88 main.c
--- main.c 4 Dec 2022 23:50:48 -0000 1.88
+++ main.c 24 Feb 2026 09:54:40 -0000
@@ -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 },
};
Index: mdef.h
===================================================================
RCS file: /build/data/openbsd/cvs/src/usr.bin/m4/mdef.h,v
diff -u -p -r1.34 mdef.h
--- mdef.h 26 Dec 2022 19:16:01 -0000 1.34
+++ mdef.h 24 Feb 2026 09:52:05 -0000
@@ -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_"
Index: misc.c
===================================================================
RCS file: /build/data/openbsd/cvs/src/usr.bin/m4/misc.c,v
diff -u -p -r1.49 misc.c
--- misc.c 5 Nov 2025 17:10:45 -0000 1.49
+++ misc.c 24 Feb 2026 09:34:23 -0000
@@ -66,7 +66,7 @@ unsigned char *endpbb; /* end of push-
* 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;
patch: clean-up m4 function and macro names