From nobody Mon Jul 3 15:14:57 2023 X-Original-To: dev-commits-src-all@mlmmj.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mlmmj.nyi.freebsd.org (Postfix) with ESMTP id 4QvqGn2bqgz4lDW9; Mon, 3 Jul 2023 15:14:57 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256 client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "mxrelay.nyi.freebsd.org", Issuer "R3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4QvqGn21lgz44vw; Mon, 3 Jul 2023 15:14:57 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1688397297; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=V3LNAFJLsgWsNLKsqN8QT9rAhvU9awWePHAzd2CS3pg=; b=b0YNvPTjl8AIKbOTckVD4w2X7n8Zj+O2tS1DpEGXKU+L14UxiztvdqjzVgKSRjygSLfnqA WDEo7ar9ORIRU6EK8bFSCnT5RF0aSTlTGZS8o7FprlIpwCCeqU5mq9poQoG2CwGOnt5Aqv 8khWfPsPJI0J1htFL1GwDF1CnP5lBROFof/ShU4B0+OgL9tKddL+qvN5w3N+daQc5qTzJW dG292+quJdcixdSd+g4g5PeYc629Nq3zeP9eSI+FBZ2L2UnrYpre6haB/ZlVVZCcwa50FI T3t7JSooINUgGXJqk+/2mZnVCV8ZXtO7pT4B9Be5QIvWXG7BNS4N2bERFiWZOQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1688397297; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=V3LNAFJLsgWsNLKsqN8QT9rAhvU9awWePHAzd2CS3pg=; b=vGdAarJEUEhWu2EJe2etcJDLXktTjd6ghrY/oOipa/pWD8TvsjG+T+vSq6qgJGiCGhAAGr v8LVT8EQFeK+381EdvbIzAhpL7bKRxn19yLharcAbIyu5KK7QSuApgxVMp701sW1Sp1nO/ LveLgd75hZUVpZ7YFUb3O7R4d3W6bqyrPFegOSLpH/mZ3jR6j70iEP9Qg0bXbXsm96K1Bn komrME2O/CAP7N0p7EbjTVAFvscpXKakScafuEV5+4gOodNSHvFunn1JX8DXKAuva8MSJ7 /PqqlaFPQ1JoRSCVqgXYutyi6ve/JIaj0a3Pl0Oq31+McHl7XE+pzWjALgpbtg== ARC-Authentication-Results: i=1; mx1.freebsd.org; none ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1688397297; a=rsa-sha256; cv=none; b=r9Yn853aKY9eRflMxAk56xwr9bBZN8DoMe34h/21nN5UF5IZIvZx1Oxz+P0NK8nJz5wVvi sr13pDeL5hvSqeJ4C16bQbGrv2GkLY4qvLCt6dxHFUuZcskS1Sz8PNq5N00AaW+RA18w3T /QBFPWWR7aPTqOvMGuaG7MMoc77a5CIs3rxxUieWZ2qS8Dk3HqkjtzHtWKOouuN94d1L/y QlmpISrwBbyB7xl+WVAQOQ2t+YgorQhI+STZaZkvYK9EdLIHPKWeYwXDyycTEc5+GvKjkO 16rcVUMZ7OP8diJ7Q0O/pOKATya9s7zbU/2r+VlzvjgbwCJQGI+cjMbgj/AulQ== Received: from gitrepo.freebsd.org (gitrepo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:5]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (Client did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id 4QvqGn14wFzvM0; Mon, 3 Jul 2023 15:14:57 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org ([127.0.1.44]) by gitrepo.freebsd.org (8.17.1/8.17.1) with ESMTP id 363FEvEf017892; Mon, 3 Jul 2023 15:14:57 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.17.1/8.17.1/Submit) id 363FEv6P017891; Mon, 3 Jul 2023 15:14:57 GMT (envelope-from git) Date: Mon, 3 Jul 2023 15:14:57 GMT Message-Id: <202307031514.363FEv6P017891@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-branches@FreeBSD.org From: =?utf-8?Q?Dag-Erling=20Sm=C3=B8rgrav?= Subject: git: 2c1f52c11f17 - stable/13 - m4: Support long options. List-Id: Commit messages for all branches of the src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-all List-Help: List-Post: List-Subscribe: List-Unsubscribe: Sender: owner-dev-commits-src-all@freebsd.org X-BeenThere: dev-commits-src-all@freebsd.org MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: des X-Git-Repository: src X-Git-Refname: refs/heads/stable/13 X-Git-Reftype: branch X-Git-Commit: 2c1f52c11f175c8da3e6c59e967d9807dfbc28b7 Auto-Submitted: auto-generated X-ThisMailContainsUnwantedMimeParts: N The branch stable/13 has been updated by des: URL: https://cgit.FreeBSD.org/src/commit/?id=2c1f52c11f175c8da3e6c59e967d9807dfbc28b7 commit 2c1f52c11f175c8da3e6c59e967d9807dfbc28b7 Author: Dag-Erling Smørgrav AuthorDate: 2023-06-21 20:58:40 +0000 Commit: Dag-Erling Smørgrav CommitDate: 2023-07-03 15:13:11 +0000 m4: Support long options. The option names are identical to those of the equivalent options in GNU m4, except of course for --gnu which does not exist in GNU m4. While here, make the argument to -d / --debug optional, with the same default behavior as in GNU m4, and document it properly. Sponsored by: Klara, Inc. Reviewed by: kevans, imp Differential Revision: https://reviews.freebsd.org/D40694 (cherry picked from commit 47b32f8f93b46ce2c7fe3973c331a40096b529da) 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 (cherry picked from commit 6c9ed64c94f192eda8c8b5e9e2b92ff93da36de2) m4: Miscellaneous man page fixes. Sponsored by: Klara, Inc. Reviewed by: imp Differential Revision: https://reviews.freebsd.org/D40701 (cherry picked from commit db4c5b8a05bbd54a00dad145a91902d71c1f92a1) Fix spelling of "behavior" to be consistent with the rest of the file (cherry picked from commit 764464af49688e74fd6d803df0404ca4726dd460) --- usr.bin/m4/m4.1 | 70 +++++++++++++++++++++++++++++++++++++------------------ usr.bin/m4/main.c | 24 +++++++++++++++++-- 2 files changed, 69 insertions(+), 25 deletions(-) diff --git a/usr.bin/m4/m4.1 b/usr.bin/m4/m4.1 index 83f124dd3dfc..ffc60af22d30 100644 --- a/usr.bin/m4/m4.1 +++ b/usr.bin/m4/m4.1 @@ -33,7 +33,7 @@ .\" .\" $FreeBSD$ .\" -.Dd April 8, 2021 +.Dd June 21, 2023 .Dt M4 1 .Os .Sh NAME @@ -41,13 +41,13 @@ .Nd macro language processor .Sh SYNOPSIS .Nm -.Op Fl EgPs +.Op Fl EGgPs .Oo .Sm off .Fl D Ar name Op No = Ar value .Sm on .Oc -.Op Fl d Ar flags +.Op Fl d Oo Oo +- Oc Ns Ar flags Oc .Op Fl I Ar dirname .Op Fl o Ar filename .Op Fl t Ar macro @@ -98,15 +98,14 @@ recognized as special when not followed by an open parenthesis. .Pp The options are as follows: .Bl -tag -width Ds -.It Fl D Ns Ar name Ns Op = Ns Ar value +.It Fl D Ns Ar name Ns Oo = Ns Ar value Oc , Fl -define Ns = Ns Ar name Ns Oo = Ns Ar value Oc Define the symbol .Ar name to have some value (or .Dv NULL ) . -.It Fl d Ar "flags" -Set trace flags. -.Ar flags -may hold the following: +.It Fl d Oo Oo +|- Oc Ns Ar flags Oc , Fl -debug Ns = Ns Oo Oo +|- Oc Ns Ar flags Oc +Set or unset trace flags. +The trace flags are as follows: .Bl -tag -width Ds .It Ar a print macro arguments. @@ -128,9 +127,21 @@ number macro expansions. turn on all options. .El .Pp +If +.Qq + +or +.Qq - +is used, the specified flags are added to or removed from the set of +active trace flags, respectively; otherwise, the specified flags +replace the set of active trace flags. +.Pp +Specifying this option without an argument is equivalent to specifying +it with the argument +.Qq aeq . +.Pp By default, trace is set to .Qq eq . -.It Fl E +.It Fl E , Fl -fatal-warnings Set warnings to be fatal. When a single .Fl E @@ -144,38 +155,51 @@ flags are specified, execution will halt upon issuing the 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 -Activate GNU-m4 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, +This behavior 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 +Enable GNU compatibility mode. +In this mode, +.Ic translit +handles simple character ranges (e.g., +.Sq a-z ) , +regular expressions mimic Emacs behavior, +multiple +.Ic m4wrap +calls are handled as a stack, the number of diversions is unlimited, empty names for macro definitions are allowed, -and eval understands +.Ic undivert +can be used to include files, +and +.Ic eval +understands .Sq 0rbase:value numbers. -.It Fl I Ar "dirname" +.It Fl I Ar dirname , Fl -include Ns = Ns Ar dirname Add directory .Ar dirname to the include path. -.It Fl o Ar filename +.It Fl o Ar filename , Fl -error-output Ns = Ns Ar filename Send trace output to .Ar filename . -.It Fl P +.It Fl P , Fl -prefix-builtins Prefix all built-in macros with .Sq m4_ . For example, instead of writing .Ic define , use .Ic m4_define . -.It Fl s +.It Fl s , Fl -synclines Output line synchronization directives, suitable for .Xr cpp 1 . -.It Fl t Ar macro +.It Fl t Ar macro , Fl -trace Ns = Ns Ar macro Turn tracing on for .Ar macro . -.It Fl "U" Ns Ar "name" +.It Fl U Ns Ar name , Fl -undefine Ns = Ns Ar name Undefine the symbol .Ar name . .El @@ -474,7 +498,7 @@ utility is compliant with the specification. .Pp The flags -.Op Fl dEgIPot +.Op Fl dEGgIPot and the macros .Ic builtin , .Ic esyscmd , diff --git a/usr.bin/m4/main.c b/usr.bin/m4/main.c index 292dc5eb3f76..f776ca8594e4 100644 --- a/usr.bin/m4/main.c +++ b/usr.bin/m4/main.c @@ -47,6 +47,7 @@ __FBSDID("$FreeBSD$"); #include #include #include +#include #include #include #include @@ -60,6 +61,22 @@ __FBSDID("$FreeBSD$"); #include "extern.h" #include "pathnames.h" +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' }, + { "prefix-builtins", no_argument, NULL, 'P' }, + { "synclines", no_argument, NULL, 's' }, + { "trace", required_argument, NULL, 't' }, + { "undefine", required_argument, NULL, 'U' }, + { NULL, 0, NULL, 0 }, +}; + stae *mstack; /* stack of m4 machine */ char *sstack; /* shadow stack, for string space extension */ static size_t STACKMAX; /* current maximum size of stack */ @@ -188,7 +205,7 @@ main(int argc, char *argv[]) outfile = NULL; resizedivs(MAXOUT); - while ((c = getopt(argc, argv, "gst:d:D:EU:o:I:P")) != -1) + while ((c = getopt_long(argc, argv, shortopts, longopts, NULL)) != -1) switch(c) { case 'D': /* define something..*/ @@ -214,11 +231,14 @@ main(int argc, char *argv[]) case 'U': /* undefine... */ macro_popdef(optarg); break; + case 'G': + mimic_gnu = 0; + break; case 'g': mimic_gnu = 1; break; case 'd': - set_trace_flags(optarg); + set_trace_flags(optarg ? optarg : "aeq"); break; case 's': synch_lines = 1;