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(1): rename ApplyModifiersState.nstr and ne...



details:   https://anonhg.NetBSD.org/src/rev/e03745f09098
branches:  trunk
changeset: 974327:e03745f09098
user:      rillig <rillig%NetBSD.org@localhost>
date:      Mon Jul 27 23:37:37 2020 +0000

description:
make(1): rename ApplyModifiersState.nstr and newStr

The old names were too easy to confuse.  In Var_Parse, nstr is indeed
used for the "new string", but that was misleading in ApplyModifiers,
especially since there was another variable called newStr.

The new variable names focus on the purpose of the variables, not on
their data types.

diffstat:

 usr.bin/make/var.c |  164 ++++++++++++++++++++++++++--------------------------
 1 files changed, 82 insertions(+), 82 deletions(-)

diffs (truncated from 527 to 300 lines):

diff -r c0d54a689978 -r e03745f09098 usr.bin/make/var.c
--- a/usr.bin/make/var.c        Mon Jul 27 23:24:55 2020 +0000
+++ b/usr.bin/make/var.c        Mon Jul 27 23:37:37 2020 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: var.c,v 1.348 2020/07/27 23:24:55 rillig Exp $ */
+/*     $NetBSD: var.c,v 1.349 2020/07/27 23:37:37 rillig Exp $ */
 
 /*
  * Copyright (c) 1988, 1989, 1990, 1993
@@ -69,14 +69,14 @@
  */
 
 #ifndef MAKE_NATIVE
-static char rcsid[] = "$NetBSD: var.c,v 1.348 2020/07/27 23:24:55 rillig Exp $";
+static char rcsid[] = "$NetBSD: var.c,v 1.349 2020/07/27 23:37:37 rillig Exp $";
 #else
 #include <sys/cdefs.h>
 #ifndef lint
 #if 0
 static char sccsid[] = "@(#)var.c      8.3 (Berkeley) 3/19/94";
 #else
-__RCSID("$NetBSD: var.c,v 1.348 2020/07/27 23:24:55 rillig Exp $");
+__RCSID("$NetBSD: var.c,v 1.349 2020/07/27 23:37:37 rillig Exp $");
 #endif
 #endif /* not lint */
 #endif
@@ -2045,7 +2045,7 @@
     VarEvalFlags eflags;
 
     /* read-write */
-    char *nstr;
+    char *val;
     const char *next;          /* The position where parsing continues
                                 * after the current modifier. */
     char termc;                        /* Character which terminated scan */
@@ -2059,7 +2059,7 @@
                                 * several space-separated words). */
 
     /* result */
-    char *newStr;              /* New value to return */
+    char *newVal;              /* New value to return */
 } ApplyModifiersState;
 
 /* we now have some modifiers with long names */
@@ -2106,7 +2106,7 @@
     args.eflags = st->eflags & (VARE_UNDEFERR | VARE_WANTRES);
     int prev_sep = st->sep;
     st->sep = ' ';             /* XXX: this is inconsistent */
-    st->newStr = ModifyWords(st->ctxt, st->sep, st->oneBigWord, st->nstr,
+    st->newVal = ModifyWords(st->ctxt, st->sep, st->oneBigWord, st->val,
                             ModifyWord_Loop, &args);
     st->sep = prev_sep;
     Var_Delete(args.tvar, st->ctxt);
@@ -2173,9 +2173,9 @@
     if (st->v->flags & VAR_JUNK)
        st->v->flags |= VAR_KEEP;
     if (neflags & VARE_WANTRES) {
-       st->newStr = Buf_Destroy(&buf, FALSE);
+       st->newVal = Buf_Destroy(&buf, FALSE);
     } else {
-       st->newStr = st->nstr;
+       st->newVal = st->val;
        Buf_Destroy(&buf, TRUE);
     }
 }
@@ -2198,7 +2198,7 @@
        utc = 0;
        st->next = mod + 6;
     }
-    st->newStr = VarStrftime(st->nstr, 1, utc);
+    st->newVal = VarStrftime(st->val, 1, utc);
     st->termc = *st->next;
     return TRUE;
 }
@@ -2221,7 +2221,7 @@
        utc = 0;
        st->next = mod + 9;
     }
-    st->newStr = VarStrftime(st->nstr, 0, utc);
+    st->newVal = VarStrftime(st->val, 0, utc);
     st->termc = *st->next;
     return TRUE;
 }
@@ -2235,7 +2235,7 @@
        return FALSE;
     }
 
-    st->newStr = VarHash(st->nstr);
+    st->newVal = VarHash(st->val);
     st->next = mod + 4;
     st->termc = *st->next;
     return TRUE;
@@ -2249,14 +2249,14 @@
        st->v->flags |= VAR_KEEP;
     GNode *gn = Targ_FindNode(st->v->name, TARG_NOCREATE);
     if (gn == NULL || gn->type & OP_NOPATH) {
-       st->newStr = NULL;
+       st->newVal = NULL;
     } else if (gn->path) {
-       st->newStr = bmake_strdup(gn->path);
+       st->newVal = bmake_strdup(gn->path);
     } else {
-       st->newStr = Dir_FindFile(st->v->name, Suff_FindPath(gn));
+       st->newVal = Dir_FindFile(st->v->name, Suff_FindPath(gn));
     }
-    if (!st->newStr)
-       st->newStr = bmake_strdup(st->v->name);
+    if (!st->newVal)
+       st->newVal = bmake_strdup(st->v->name);
     st->next = mod + 1;
     st->termc = *st->next;
 }
@@ -2276,13 +2276,13 @@
 
     const char *emsg = NULL;
     if (st->eflags & VARE_WANTRES)
-       st->newStr = Cmd_Exec(cmd, &emsg);
+       st->newVal = Cmd_Exec(cmd, &emsg);
     else
-       st->newStr = varNoError;
+       st->newVal = varNoError;
     free(cmd);
 
     if (emsg)
-       Error(emsg, st->nstr);
+       Error(emsg, st->val);
 
     st->termc = *st->next;
     if (st->v->flags & VAR_JUNK)
@@ -2308,7 +2308,7 @@
        n = 0;
        st->next = mod + 5;
     }
-    st->newStr = VarRange(st->nstr, n);
+    st->newVal = VarRange(st->val, n);
     st->termc = *st->next;
     return TRUE;
 }
@@ -2380,11 +2380,11 @@
 
     if (DEBUG(VAR))
        fprintf(debug_file, "Pattern[%s] for [%s] is [%s]\n",
-           st->v->name, st->nstr, pattern);
+           st->v->name, st->val, pattern);
 
     ModifyWordsCallback callback = mod[0] == 'M'
        ? ModifyWord_Match : ModifyWord_NoMatch;
-    st->newStr = ModifyWords(st->ctxt, st->sep, st->oneBigWord, st->nstr,
+    st->newVal = ModifyWords(st->ctxt, st->sep, st->oneBigWord, st->val,
                             callback, pattern);
     free(pattern);
 }
@@ -2446,7 +2446,7 @@
     }
 
     st->termc = *st->next;
-    st->newStr = ModifyWords(st->ctxt, st->sep, oneBigWord, st->nstr,
+    st->newVal = ModifyWords(st->ctxt, st->sep, oneBigWord, st->val,
                             ModifyWord_Subst, &args);
 
     free(lhs);
@@ -2513,7 +2513,7 @@
        args.nsub = 1;
     if (args.nsub > 10)
        args.nsub = 10;
-    st->newStr = ModifyWords(st->ctxt, st->sep, oneBigWord, st->nstr,
+    st->newVal = ModifyWords(st->ctxt, st->sep, oneBigWord, st->val,
                             ModifyWord_SubstRegex, &args);
     regfree(&args.re);
     free(args.replace);
@@ -2576,7 +2576,7 @@
     }
 
     st->termc = *st->next;
-    st->newStr = ModifyWords(st->ctxt, st->sep, st->oneBigWord, st->nstr,
+    st->newVal = ModifyWords(st->ctxt, st->sep, st->oneBigWord, st->val,
                             ModifyWord_Copy, NULL);
     return TRUE;
 }
@@ -2597,25 +2597,25 @@
 
     /* Check for two-character options: ":tu", ":tl" */
     if (mod[1] == 'A') {       /* absolute path */
-       st->newStr = ModifyWords(st->ctxt, st->sep, st->oneBigWord, st->nstr,
+       st->newVal = ModifyWords(st->ctxt, st->sep, st->oneBigWord, st->val,
                                 ModifyWord_Realpath, NULL);
        st->next = mod + 2;
        st->termc = *st->next;
     } else if (mod[1] == 'u') {
-       char *dp = bmake_strdup(st->nstr);
-       for (st->newStr = dp; *dp; dp++)
+       char *dp = bmake_strdup(st->val);
+       for (st->newVal = dp; *dp; dp++)
            *dp = toupper((unsigned char)*dp);
        st->next = mod + 2;
        st->termc = *st->next;
     } else if (mod[1] == 'l') {
-       char *dp = bmake_strdup(st->nstr);
-       for (st->newStr = dp; *dp; dp++)
+       char *dp = bmake_strdup(st->val);
+       for (st->newVal = dp; *dp; dp++)
            *dp = tolower((unsigned char)*dp);
        st->next = mod + 2;
        st->termc = *st->next;
     } else if (mod[1] == 'W' || mod[1] == 'w') {
        st->oneBigWord = mod[1] == 'W';
-       st->newStr = st->nstr;
+       st->newVal = st->val;
        st->next = mod + 2;
        st->termc = *st->next;
     } else {
@@ -2647,20 +2647,20 @@
 
     if (estr[0] == '#' && estr[1] == '\0') { /* Found ":[#]" */
        if (st->oneBigWord) {
-           st->newStr = bmake_strdup("1");
+           st->newVal = bmake_strdup("1");
        } else {
            /* XXX: brk_string() is a rather expensive
             * way of counting words. */
            char *as;
            int ac;
-           char **av = brk_string(st->nstr, &ac, FALSE, &as);
+           char **av = brk_string(st->val, &ac, FALSE, &as);
            free(as);
            free(av);
 
            Buffer buf;
            Buf_Init(&buf, 4);  /* 3 digits + '\0' */
            Buf_AddInt(&buf, ac);
-           st->newStr = Buf_Destroy(&buf, FALSE);
+           st->newVal = Buf_Destroy(&buf, FALSE);
        }
        goto ok;
     }
@@ -2668,14 +2668,14 @@
     if (estr[0] == '*' && estr[1] == '\0') {
        /* Found ":[*]" */
        st->oneBigWord = TRUE;
-       st->newStr = st->nstr;
+       st->newVal = st->val;
        goto ok;
     }
 
     if (estr[0] == '@' && estr[1] == '\0') {
        /* Found ":[@]" */
        st->oneBigWord = FALSE;
-       st->newStr = st->nstr;
+       st->newVal = st->val;
        goto ok;
     }
 
@@ -2707,7 +2707,7 @@
     if (first == 0 && last == 0) {
        /* ":[0]" or perhaps ":[0..0]" */
        st->oneBigWord = TRUE;
-       st->newStr = st->nstr;
+       st->newVal = st->val;
        goto ok;
     }
 
@@ -2716,7 +2716,7 @@
        goto bad_modifier;
 
     /* Normal case: select the words described by seldata. */
-    st->newStr = VarSelectWords(st->sep, st->oneBigWord, st->nstr, first, last);
+    st->newVal = VarSelectWords(st->sep, st->oneBigWord, st->val, first, last);
 
 ok:
     st->termc = *st->next;
@@ -2746,7 +2746,7 @@
     } else {
        return FALSE;
     }
-    st->newStr = VarOrder(st->nstr, otype);
+    st->newVal = VarOrder(st->val, otype);
     return TRUE;
 }
 
@@ -2792,10 +2792,10 @@
     }
 
     if (value) {
-       st->newStr = then_expr;
+       st->newVal = then_expr;
        free(else_expr);
     } else {
-       st->newStr = else_expr;
+       st->newVal = else_expr;
        free(then_expr);
     }
     if (st->v->flags & VAR_JUNK)
@@ -2887,12 +2887,12 @@
            break;
        case '!': {
            const char *emsg;
-           st->newStr = Cmd_Exec(val, &emsg);
+           st->newVal = Cmd_Exec(val, &emsg);
            if (emsg)
-               Error(emsg, st->nstr);



Home | Main Index | Thread Index | Old Index