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: reduce indentation in ModifyWord_SubstReg...
details: https://anonhg.NetBSD.org/src/rev/10894918c5dc
branches: trunk
changeset: 984106:10894918c5dc
user: rillig <rillig%NetBSD.org@localhost>
date: Mon Jun 21 17:21:37 2021 +0000
description:
make: reduce indentation in ModifyWord_SubstRegex for ':C'
No functional change.
diffstat:
usr.bin/make/var.c | 138 +++++++++++++++++++++++++---------------------------
1 files changed, 67 insertions(+), 71 deletions(-)
diffs (168 lines):
diff -r f5aa2d922fdb -r 10894918c5dc usr.bin/make/var.c
--- a/usr.bin/make/var.c Mon Jun 21 16:59:18 2021 +0000
+++ b/usr.bin/make/var.c Mon Jun 21 17:21:37 2021 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: var.c,v 1.934 2021/06/21 08:40:44 rillig Exp $ */
+/* $NetBSD: var.c,v 1.935 2021/06/21 17:21:37 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.934 2021/06/21 08:40:44 rillig Exp $");
+MAKE_RCSID("$NetBSD: var.c,v 1.935 2021/06/21 17:21:37 rillig Exp $");
/*
* Variables are defined using one of the VAR=value assignments. Their
@@ -1606,84 +1606,80 @@
const char *rp;
int flags = 0;
regmatch_t m[10];
+ size_t n;
assert(word.end[0] == '\0'); /* assume null-terminated word */
wp = word.start;
- if (args->pflags.subOnce && args->matched)
- goto nosub;
-
-tryagain:
+ if (args->pflags.subOnce && args->matched) {
+ nosub:
+ SepBuf_AddStr(buf, wp);
+ return;
+ }
+
+again:
xrv = regexec(&args->re, wp, args->nsub, m, flags);
-
- switch (xrv) {
- case 0:
- args->matched = true;
- SepBuf_AddBytes(buf, wp, (size_t)m[0].rm_so);
-
- /*
- * Replacement of regular expressions is not specified by
- * POSIX, therefore implement it here.
- */
-
- for (rp = args->replace; *rp != '\0'; rp++) {
- if (*rp == '\\' && (rp[1] == '&' || rp[1] == '\\')) {
- SepBuf_AddBytes(buf, rp + 1, 1);
- rp++;
- continue;
- }
-
- if (*rp == '&') {
- SepBuf_AddBytesBetween(buf,
- wp + m[0].rm_so, wp + m[0].rm_eo);
- continue;
+ if (xrv == 0)
+ goto ok;
+ if (xrv != REG_NOMATCH)
+ VarREError(xrv, &args->re, "Unexpected regex error");
+ goto nosub;
+
+ok:
+ args->matched = true;
+ SepBuf_AddBytes(buf, wp, (size_t)m[0].rm_so);
+
+ /*
+ * Replacement of regular expressions is not specified by
+ * POSIX, therefore re-implement it here.
+ */
+
+ for (rp = args->replace; *rp != '\0'; rp++) {
+ if (*rp == '\\' && (rp[1] == '&' || rp[1] == '\\')) {
+ SepBuf_AddBytes(buf, rp + 1, 1);
+ rp++;
+ continue;
+ }
+
+ if (*rp == '&') {
+ SepBuf_AddBytesBetween(buf,
+ wp + m[0].rm_so, wp + m[0].rm_eo);
+ continue;
+ }
+
+ if (*rp != '\\' || !ch_isdigit(rp[1])) {
+ SepBuf_AddBytes(buf, rp, 1);
+ continue;
+ }
+
+ /* \0 to \9 backreference */
+ n = (size_t)(rp[1] - '0');
+ rp++;
+
+ if (n >= args->nsub) {
+ Error("No subexpression \\%u", (unsigned)n);
+ } else if (m[n].rm_so == -1) {
+ if (opts.strict) {
+ Error("No match for subexpression \\%u",
+ (unsigned)n);
}
-
- if (*rp != '\\' || !ch_isdigit(rp[1])) {
- SepBuf_AddBytes(buf, rp, 1);
- continue;
- }
-
- { /* \0 to \9 backreference */
- size_t n = (size_t)(rp[1] - '0');
- rp++;
-
- if (n >= args->nsub) {
- Error("No subexpression \\%u",
- (unsigned)n);
- } else if (m[n].rm_so == -1) {
- if (opts.strict) {
- Error(
- "No match for subexpression \\%u",
- (unsigned)n);
- }
- } else {
- SepBuf_AddBytesBetween(buf,
- wp + m[n].rm_so, wp + m[n].rm_eo);
- }
- }
+ } else {
+ SepBuf_AddBytesBetween(buf,
+ wp + m[n].rm_so, wp + m[n].rm_eo);
}
-
- wp += m[0].rm_eo;
- if (args->pflags.subGlobal) {
- flags |= REG_NOTBOL;
- if (m[0].rm_so == 0 && m[0].rm_eo == 0) {
- SepBuf_AddBytes(buf, wp, 1);
- wp++;
- }
- if (*wp != '\0')
- goto tryagain;
+ }
+
+ wp += m[0].rm_eo;
+ if (args->pflags.subGlobal) {
+ flags |= REG_NOTBOL;
+ if (m[0].rm_so == 0 && m[0].rm_eo == 0) {
+ SepBuf_AddBytes(buf, wp, 1);
+ wp++;
}
if (*wp != '\0')
- SepBuf_AddStr(buf, wp);
- break;
- default:
- VarREError(xrv, &args->re, "Unexpected regex error");
- /* FALLTHROUGH */
- case REG_NOMATCH:
- nosub:
+ goto again;
+ }
+ if (*wp != '\0')
SepBuf_AddStr(buf, wp);
- break;
- }
}
#endif
Home |
Main Index |
Thread Index |
Old Index