m4: Add -G option which reverses -g.

This matches GNU m4's -G / --traditional option, and although BSD m4 in non-GNU mode is not exactly identical to GNU mode in traditional mode, it's close enough.

Sponsored by:	Klara, Inc.
Reviewed by:	kevans, imp
Differential Revision:	https://reviews.freebsd.org/D40697
This commit is contained in:
Dag-Erling Smørgrav 2023-06-21 20:58:45 +00:00
parent 47b32f8f93
commit 6c9ed64c94
2 changed files with 12 additions and 4 deletions

View file

@ -41,7 +41,7 @@
.Nd macro language processor
.Sh SYNOPSIS
.Nm
.Op Fl EgPs
.Op Fl EGgPs
.Oo
.Sm off
.Fl D Ar name Op No = Ar value
@ -156,8 +156,12 @@ first warning and
.Nm
will exit with a non-zero exit status.
This behaviour matches GNU-m4 1.4.9 and later.
.It Fl G , Fl -traditional
Disable GNU compatibility mode (see
.Fl g
below).
.It Fl g , Fl -gnu
Activate GNU-m4 compatibility mode.
Enable GNU compatibility mode.
In this mode, translit handles simple character
ranges (e.g., a-z), regular expressions mimic emacs behavior,
multiple m4wrap calls are handled as a stack,
@ -485,7 +489,7 @@ utility is compliant with the
specification.
.Pp
The flags
.Op Fl dEgIPot
.Op Fl dEGgIPot
and the macros
.Ic builtin ,
.Ic esyscmd ,

View file

@ -61,11 +61,12 @@ __FBSDID("$FreeBSD$");
#include "extern.h"
#include "pathnames.h"
static const char *shortopts = "+D:d::EgI:o:Pst:U:";
static const char *shortopts = "+D:d::EGgI:o:Pst:U:";
static const struct option longopts[] = {
{ "define", required_argument, NULL, 'D' },
{ "debug", optional_argument, NULL, 'd' },
{ "fatal-warnings", no_argument, NULL, 'E' },
{ "traditional", no_argument, NULL, 'G' },
{ "gnu", no_argument, NULL, 'g' },
{ "include", required_argument, NULL, 'I' },
{ "error-output", required_argument, NULL, 'o' },
@ -230,6 +231,9 @@ main(int argc, char *argv[])
case 'U': /* undefine... */
macro_popdef(optarg);
break;
case 'G':
mimic_gnu = 0;
break;
case 'g':
mimic_gnu = 1;
break;