From owner-svn-src-all@freebsd.org Fri Sep 13 07:10:53 2019 Return-Path: Delivered-To: svn-src-all@mailman.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mailman.nyi.freebsd.org (Postfix) with ESMTP id 2BC51E8714; Fri, 13 Sep 2019 07:10:53 +0000 (UTC) (envelope-from bapt@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) server-signature RSA-PSS (4096 bits) client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "mxrelay.nyi.freebsd.org", Issuer "Let's Encrypt Authority X3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 46V6HJ6YDjz4GN5; Fri, 13 Sep 2019 07:10:52 +0000 (UTC) (envelope-from bapt@FreeBSD.org) Received: from repo.freebsd.org (repo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:0]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id A996337D5; Fri, 13 Sep 2019 07:10:52 +0000 (UTC) (envelope-from bapt@FreeBSD.org) Received: from repo.freebsd.org ([127.0.1.37]) by repo.freebsd.org (8.15.2/8.15.2) with ESMTP id x8D7AqbE048829; Fri, 13 Sep 2019 07:10:52 GMT (envelope-from bapt@FreeBSD.org) Received: (from bapt@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id x8D7Ap15048821; Fri, 13 Sep 2019 07:10:51 GMT (envelope-from bapt@FreeBSD.org) Message-Id: <201909130710.x8D7Ap15048821@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: bapt set sender to bapt@FreeBSD.org using -f From: Baptiste Daroussin Date: Fri, 13 Sep 2019 07:10:51 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-stable@freebsd.org, svn-src-stable-12@freebsd.org Subject: svn commit: r352277 - stable/12/usr.bin/m4 X-SVN-Group: stable-12 X-SVN-Commit-Author: bapt X-SVN-Commit-Paths: stable/12/usr.bin/m4 X-SVN-Commit-Revision: 352277 X-SVN-Commit-Repository: base MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-all@freebsd.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: "SVN commit messages for the entire src tree \(except for " user" and " projects" \)" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 13 Sep 2019 07:10:53 -0000 Author: bapt Date: Fri Sep 13 07:10:50 2019 New Revision: 352277 URL: https://svnweb.freebsd.org/changeset/base/352277 Log: MFC r352065-r352070 Sync with OpenBSD, in particular this adds support for -E flags (GNU compatibility) Modified: stable/12/usr.bin/m4/Makefile stable/12/usr.bin/m4/eval.c stable/12/usr.bin/m4/extern.h stable/12/usr.bin/m4/gnum4.c stable/12/usr.bin/m4/m4.1 stable/12/usr.bin/m4/main.c stable/12/usr.bin/m4/misc.c stable/12/usr.bin/m4/tokenizer.l Directory Properties: stable/12/ (props changed) Modified: stable/12/usr.bin/m4/Makefile ============================================================================== --- stable/12/usr.bin/m4/Makefile Fri Sep 13 07:08:43 2019 (r352276) +++ stable/12/usr.bin/m4/Makefile Fri Sep 13 07:10:50 2019 (r352277) @@ -8,7 +8,7 @@ PROG= m4 CFLAGS+=-DEXTENDED -I${.CURDIR} -I${SRCTOP}/lib/libopenbsd -LIBADD= y l m openbsd +LIBADD= m openbsd NO_WMISSING_VARIABLE_DECLARATIONS= Modified: stable/12/usr.bin/m4/eval.c ============================================================================== --- stable/12/usr.bin/m4/eval.c Fri Sep 13 07:08:43 2019 (r352276) +++ stable/12/usr.bin/m4/eval.c Fri Sep 13 07:10:50 2019 (r352277) @@ -1,4 +1,4 @@ -/* $OpenBSD: eval.c,v 1.74 2015/02/05 12:59:57 millert Exp $ */ +/* $OpenBSD: eval.c,v 1.78 2019/06/28 05:35:34 deraadt Exp $ */ /* $NetBSD: eval.c,v 1.7 1996/11/10 21:21:29 pk Exp $ */ /*- @@ -126,6 +126,7 @@ void expand_builtin(const char *argv[], int argc, int td) { int c, n; + const char *errstr; int ac; static int sysval = 0; @@ -186,13 +187,15 @@ 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 %s invalid.", argv[3]); + m4errx(1, "expr: base is %s: %s.", + errstr, argv[3]); } } if (argc > 4) { maxdigits = strtonum(argv[4], 0, INT_MAX, &errstr); if (errstr) { - m4errx(1, "expr: maxdigits %s invalid.", argv[4]); + m4errx(1, "expr: maxdigits is %s: %s.", + errstr, argv[4]); } } if (argc > 2) @@ -201,8 +204,7 @@ expand_builtin(const char *argv[], int argc, int td) } case IFELTYPE: - if (argc > 4) - doifelse(argv, argc); + doifelse(argv, argc); break; case IFDFTYPE: @@ -232,8 +234,13 @@ expand_builtin(const char *argv[], int argc, int td) * doincr - increment the value of the * argument */ - if (argc > 2) - pbnum(atoi(argv[2]) + 1); + if (argc > 2) { + n = strtonum(argv[2], INT_MIN, INT_MAX-1, &errstr); + if (errstr != NULL) + m4errx(1, "incr: argument is %s: %s.", + errstr, argv[2]); + pbnum(n + 1); + } break; case DECRTYPE: @@ -241,8 +248,13 @@ expand_builtin(const char *argv[], int argc, int td) * dodecr - decrement the value of the * argument */ - if (argc > 2) - pbnum(atoi(argv[2]) - 1); + if (argc > 2) { + n = strtonum(argv[2], INT_MIN+1, INT_MAX, &errstr); + if (errstr) + m4errx(1, "decr: argument is %s: %s.", + errstr, argv[2]); + pbnum(n - 1); + } break; case SYSCTYPE: @@ -275,6 +287,10 @@ expand_builtin(const char *argv[], int argc, int td) warn("%s at line %lu: include(%s)", CURRENT_NAME, CURRENT_LINE, argv[2]); exit_code = 1; + if (fatal_warns) { + killdiv(); + exit(exit_code); + } } else err(1, "%s at line %lu: include(%s)", CURRENT_NAME, CURRENT_LINE, argv[2]); @@ -339,12 +355,18 @@ expand_builtin(const char *argv[], int argc, int td) break; case DIVRTYPE: - if (argc > 2 && (n = atoi(argv[2])) != 0) - dodiv(n); - else { - active = stdout; - oindex = 0; + 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); + break; + } } + active = stdout; + oindex = 0; break; case UNDVTYPE: @@ -691,17 +713,17 @@ dotrace(const char *argv[], int argc, int on) static void doifelse(const char *argv[], int argc) { - cycle { - if (STREQ(argv[2], argv[3])) + while (argc > 4) { + if (STREQ(argv[2], argv[3])) { pbstr(argv[4]); - else if (argc == 6) + break; + } else if (argc == 6) { pbstr(argv[5]); - else if (argc > 6) { + break; + } else { argv += 3; argc -= 3; - continue; } - break; } } @@ -824,7 +846,7 @@ dodiv(int n) if (outfile[n] == NULL) { char fname[] = _PATH_DIVNAME; - if ((fd = mkstemp(fname)) < 0 || + if ((fd = mkstemp(fname)) == -1 || unlink(fname) == -1 || (outfile[n] = fdopen(fd, "w+")) == NULL) err(1, "%s: cannot divert", fname); Modified: stable/12/usr.bin/m4/extern.h ============================================================================== --- stable/12/usr.bin/m4/extern.h Fri Sep 13 07:08:43 2019 (r352276) +++ stable/12/usr.bin/m4/extern.h Fri Sep 13 07:10:50 2019 (r352277) @@ -1,4 +1,4 @@ -/* $OpenBSD: extern.h,v 1.54 2014/05/12 19:11:19 espie Exp $ */ +/* $OpenBSD: extern.h,v 1.55 2017/06/15 13:48:42 bcallah Exp $ */ /* $NetBSD: extern.h,v 1.3 1996/01/13 23:25:24 pk Exp $ */ /*- @@ -61,6 +61,8 @@ extern void doesyscmd(const char *); extern void getdivfile(const char *); extern void doformat(const char *[], int); +extern void m4_warnx(const char *, ...); + /* look.c */ #define FLAG_UNTRACED 0 @@ -178,4 +180,5 @@ extern int synch_lines; /* line synchronisation direc extern int mimic_gnu; /* behaves like gnu-m4 */ extern int prefix_builtins; /* prefix builtin macros with m4_ */ - +extern int error_warns; /* make warnings cause exit_code = 1 */ +extern int fatal_warns; /* make warnings fatal */ Modified: stable/12/usr.bin/m4/gnum4.c ============================================================================== --- stable/12/usr.bin/m4/gnum4.c Fri Sep 13 07:08:43 2019 (r352276) +++ stable/12/usr.bin/m4/gnum4.c Fri Sep 13 07:10:50 2019 (r352277) @@ -1,4 +1,4 @@ -/* $OpenBSD: gnum4.c,v 1.50 2015/04/29 00:13:26 millert Exp $ */ +/* $OpenBSD: gnum4.c,v 1.52 2017/08/21 21:41:13 deraadt Exp $ */ /*- * SPDX-License-Identifier: BSD-2-Clause @@ -39,6 +39,7 @@ __FBSDID("$FreeBSD$"); #include #include #include +#include #include #include #include @@ -259,11 +260,29 @@ exit_regerror(int er, regex_t *re, const char *source) m4errx(1, "regular expression error in %s: %s.", source, errbuf); } +/* warnx() plus check to see if we need to change exit code or exit . + * -E flag functionality. + */ +void +m4_warnx(const char *fmt, ...) +{ + va_list ap; + + va_start(ap, fmt); + warnx(fmt, ap); + va_end(ap); + + if (fatal_warns) + exit(1); + if (error_warns) + exit_code = 1; +} + static void add_sub(int n, const char *string, regex_t *re, regmatch_t *pm) { if (n > (int)re->re_nsub) - warnx("No subexpression %d", n); + m4_warnx("No subexpression %d", n); /* Subexpressions that did not match are * not an error. */ else if (pm[n].rm_so != -1 && @@ -446,7 +465,7 @@ void dopatsubst(const char *argv[], int argc) { if (argc <= 3) { - warnx("Too few arguments to patsubst"); + m4_warnx("Too few arguments to patsubst"); return; } /* special case: empty regexp */ @@ -498,7 +517,7 @@ doregexp(const char *argv[], int argc) const char *source; if (argc <= 3) { - warnx("Too few arguments to regexp"); + m4_warnx("Too few arguments to regexp"); return; } /* special gnu case */ @@ -615,7 +634,7 @@ void doesyscmd(const char *cmd) { int p[2]; - pid_t pid, cpid; + pid_t cpid; char *argv[4]; int cc; int status; @@ -653,8 +672,10 @@ doesyscmd(const char *cmd) } while (cc > 0 || (cc == -1 && errno == EINTR)); (void) close(p[0]); - while ((pid = wait(&status)) != cpid && pid >= 0) - continue; + while (waitpid(cpid, &status, 0) == -1) { + if (errno != EINTR) + break; + } pbstr(getstring()); } } Modified: stable/12/usr.bin/m4/m4.1 ============================================================================== --- stable/12/usr.bin/m4/m4.1 Fri Sep 13 07:08:43 2019 (r352276) +++ stable/12/usr.bin/m4/m4.1 Fri Sep 13 07:10:50 2019 (r352277) @@ -1,5 +1,5 @@ .\" $NetBSD: m4.1,v 1.23 2012/04/08 22:00:39 wiz Exp $ -.\" @(#) $OpenBSD: m4.1,v 1.63 2015/09/14 20:06:58 schwarze Exp $ +.\" @(#) $OpenBSD: m4.1,v 1.64 2017/06/15 13:48:42 bcallah Exp $ .\" .\" Copyright (c) 1989, 1993 .\" The Regents of the University of California. All rights reserved. @@ -33,7 +33,7 @@ .\" .\" $FreeBSD$ .\" -.Dd $Mdocdate: September 14 2015 $ +.Dd $Mdocdate: June 15 2017 $ .Dt M4 1 .Os .Sh NAME @@ -41,7 +41,7 @@ .Nd macro language processor .Sh SYNOPSIS .Nm -.Op Fl gPs +.Op Fl EgPs .Oo .Sm off .Fl D Ar name Op No = Ar value @@ -130,6 +130,21 @@ turn on all options. .Pp By default, trace is set to .Qq eq . +.It Fl E +Set warnings to be fatal. +When a single +.Fl E +flag is specified, if warnings are issued, execution +continues but +.Nm +will exit with a non-zero exit status. +When multiple +.Fl E +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 @@ -437,7 +452,9 @@ Returns the current file's name. .Pp But note that the .Ic m4exit -macro can modify the exit status. +macro can modify the exit status, as can the +.Fl E +flag. .Sh STANDARDS The .Nm @@ -446,7 +463,7 @@ utility is compliant with the specification. .Pp The flags -.Op Fl dgIPot +.Op Fl dEgIPot and the macros .Ic builtin , .Ic esyscmd , Modified: stable/12/usr.bin/m4/main.c ============================================================================== --- stable/12/usr.bin/m4/main.c Fri Sep 13 07:08:43 2019 (r352276) +++ stable/12/usr.bin/m4/main.c Fri Sep 13 07:10:50 2019 (r352277) @@ -1,4 +1,4 @@ -/* $OpenBSD: main.c,v 1.86 2015/11/03 16:21:47 deraadt Exp $ */ +/* $OpenBSD: main.c,v 1.87 2017/06/15 13:48:42 bcallah Exp $ */ /* $NetBSD: main.c,v 1.12 1997/02/08 23:54:49 cgd Exp $ */ /*- @@ -81,6 +81,8 @@ char scommt[MAXCCHARS+1] = {SCOMMT}; /* start characte char ecommt[MAXCCHARS+1] = {ECOMMT}; /* end character for comment */ int synch_lines = 0; /* line synchronisation for C preprocessor */ int prefix_builtins = 0; /* -P option to prefix builtin keywords */ +int error_warns = 0; /* -E option to make warnings exit_code = 1 */ +int fatal_warns = 0; /* -E -E option to make warnings fatal */ struct keyblk { const char *knam; /* keyword name */ @@ -186,7 +188,7 @@ main(int argc, char *argv[]) outfile = NULL; resizedivs(MAXOUT); - while ((c = getopt(argc, argv, "gst:d:D:U:o:I:P")) != -1) + while ((c = getopt(argc, argv, "gst:d:D:EU:o:I:P")) != -1) switch(c) { case 'D': /* define something..*/ @@ -196,6 +198,12 @@ main(int argc, char *argv[]) if (*p) *p++ = EOS; dodefine(optarg, p); + break; + case 'E': /* like GNU m4 1.4.9+ */ + if (error_warns == 0) + error_warns = 1; + else + fatal_warns = 1; break; case 'I': addtoincludepath(optarg); Modified: stable/12/usr.bin/m4/misc.c ============================================================================== --- stable/12/usr.bin/m4/misc.c Fri Sep 13 07:08:43 2019 (r352276) +++ stable/12/usr.bin/m4/misc.c Fri Sep 13 07:10:50 2019 (r352277) @@ -1,4 +1,4 @@ -/* $OpenBSD: misc.c,v 1.46 2015/12/07 14:12:46 espie Exp $ */ +/* $OpenBSD: misc.c,v 1.47 2017/06/15 13:48:42 bcallah Exp $ */ /* $NetBSD: misc.c,v 1.6 1995/09/28 05:37:41 tls Exp $ */ /*- @@ -386,7 +386,7 @@ xstrdup(const char *s) void usage(void) { - fprintf(stderr, "usage: m4 [-gPs] [-Dname[=value]] [-d flags] " + fprintf(stderr, "usage: m4 [-EgPs] [-Dname[=value]] [-d flags] " "[-I dirname] [-o filename]\n" "\t[-t macro] [-Uname] [file ...]\n"); exit(1); Modified: stable/12/usr.bin/m4/tokenizer.l ============================================================================== --- stable/12/usr.bin/m4/tokenizer.l Fri Sep 13 07:08:43 2019 (r352276) +++ stable/12/usr.bin/m4/tokenizer.l Fri Sep 13 07:10:50 2019 (r352277) @@ -1,6 +1,6 @@ %option nounput noinput %{ -/* $OpenBSD: tokenizer.l,v 1.8 2012/04/12 17:00:11 espie Exp $ */ +/* $OpenBSD: tokenizer.l,v 1.9 2017/06/15 13:48:42 bcallah Exp $ */ /* * Copyright (c) 2004 Marc Espie * @@ -25,6 +25,7 @@ #include #include +extern void m4_warnx(const char *, ...); extern int mimic_gnu; extern int32_t yylval; @@ -42,6 +43,8 @@ oct 0[0-7]* dec [1-9][0-9]* radix 0[rR][0-9]+:[0-9a-zA-Z]+ +%option noyywrap + %% {ws} {/* just skip it */} {hex}|{oct}|{dec} { yylval = number(); return(NUMBER); } @@ -72,7 +75,7 @@ number(void) l = strtol(yytext, NULL, 0); if (((l == LONG_MAX || l == LONG_MIN) && errno == ERANGE) || l > INT32_MAX || l < INT32_MIN) { - fprintf(stderr, "m4: numeric overflow in expr: %s\n", yytext); + m4_warnx("numeric overflow in expr: %s", yytext); } return l; } @@ -88,7 +91,7 @@ parse_radix(void) l = 0; base = strtol(yytext+2, &next, 0); if (base > 36 || next == NULL) { - fprintf(stderr, "m4: error in number %s\n", yytext); + m4_warnx("error in number %s", yytext); } else { next++; while (*next != 0) { @@ -101,8 +104,7 @@ parse_radix(void) d = *next - 'A' + 10; } if (d >= base) { - fprintf(stderr, - "m4: error in number %s\n", yytext); + m4_warnx("error in number %s", yytext); return 0; } l = base * l + d;