Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/usr.bin/make make: condense RegexReplace for the modifier ':C'



details:   https://anonhg.NetBSD.org/src/rev/eeca3585d8c9
branches:  trunk
changeset: 1027615:eeca3585d8c9
user:      rillig <rillig%NetBSD.org@localhost>
date:      Mon Dec 13 03:19:32 2021 +0000

description:
make: condense RegexReplace for the modifier ':C'

No functional change.

diffstat:

 usr.bin/make/var.c |  30 ++++++++++--------------------
 1 files changed, 10 insertions(+), 20 deletions(-)

diffs (62 lines):

diff -r a39846eb4325 -r eeca3585d8c9 usr.bin/make/var.c
--- a/usr.bin/make/var.c        Mon Dec 13 03:17:50 2021 +0000
+++ b/usr.bin/make/var.c        Mon Dec 13 03:19:32 2021 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: var.c,v 1.982 2021/12/13 03:03:42 rillig Exp $ */
+/*     $NetBSD: var.c,v 1.983 2021/12/13 03:19:32 rillig Exp $ */
 
 /*
  * Copyright (c) 1988, 1989, 1990, 1993
@@ -140,7 +140,7 @@
 #include "metachar.h"
 
 /*     "@(#)var.c      8.3 (Berkeley) 3/19/94" */
-MAKE_RCSID("$NetBSD: var.c,v 1.982 2021/12/13 03:03:42 rillig Exp $");
+MAKE_RCSID("$NetBSD: var.c,v 1.983 2021/12/13 03:19:32 rillig Exp $");
 
 /*
  * Variables are defined using one of the VAR=value assignments.  Their
@@ -1626,8 +1626,8 @@
 }
 
 /*
- * Replacement of regular expressions is not specified by POSIX, therefore
- * re-implement it here.
+ * The regular expression matches the word; now add the replacement to the
+ * buffer, taking back-references from 'wp'.
  */
 static void
 RegexReplace(const char *replace, SepBuf *buf, const char *wp,
@@ -1636,26 +1636,16 @@
        const char *rp;
 
        for (rp = replace; *rp != '\0'; rp++) {
-               if (*rp == '\\' && (rp[1] == '&' || rp[1] == '\\')) {
-                       SepBuf_AddBytes(buf, rp + 1, 1);
-                       rp++;
-                       continue;
-               }
-
-               if (*rp == '&') {
+               if (*rp == '\\' && (rp[1] == '&' || rp[1] == '\\'))
+                       SepBuf_AddBytes(buf, ++rp, 1);
+               else if (*rp == '\\' && ch_isdigit(rp[1]))
+                       RegexReplaceBackref(*++rp, buf, wp, m, nsub);
+               else if (*rp == '&') {
                        SepBuf_AddBytesBetween(buf,
                            wp + (size_t)m[0].rm_so,
                            wp + (size_t)m[0].rm_eo);
-                       continue;
-               }
-
-               if (*rp != '\\' || !ch_isdigit(rp[1])) {
+               } else
                        SepBuf_AddBytes(buf, rp, 1);
-                       continue;
-               }
-
-               rp++;
-               RegexReplaceBackref(*rp, buf, wp, m, nsub);
        }
 }
 



Home | Main Index | Thread Index | Old Index