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): fix indentation in var.c



details:   https://anonhg.NetBSD.org/src/rev/5dcf1767ca5c
branches:  trunk
changeset: 973540:5dcf1767ca5c
user:      rillig <rillig%NetBSD.org@localhost>
date:      Fri Jul 03 17:48:47 2020 +0000

description:
make(1): fix indentation in var.c

Fixing the indentation manually is a tedious task.  indent(1) was no help
since it has several bugs and is not flexible enough for the original
make code.

diffstat:

 usr.bin/make/var.c |  335 +++++++++++++++++++++++++---------------------------
 1 files changed, 160 insertions(+), 175 deletions(-)

diffs (truncated from 683 to 300 lines):

diff -r 7de5d5c2f85a -r 5dcf1767ca5c usr.bin/make/var.c
--- a/usr.bin/make/var.c        Fri Jul 03 17:22:14 2020 +0000
+++ b/usr.bin/make/var.c        Fri Jul 03 17:48:47 2020 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: var.c,v 1.241 2020/07/03 17:03:09 rillig Exp $ */
+/*     $NetBSD: var.c,v 1.242 2020/07/03 17:48:47 rillig Exp $ */
 
 /*
  * Copyright (c) 1988, 1989, 1990, 1993
@@ -69,14 +69,14 @@
  */
 
 #ifndef MAKE_NATIVE
-static char rcsid[] = "$NetBSD: var.c,v 1.241 2020/07/03 17:03:09 rillig Exp $";
+static char rcsid[] = "$NetBSD: var.c,v 1.242 2020/07/03 17:48:47 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.241 2020/07/03 17:03:09 rillig Exp $");
+__RCSID("$NetBSD: var.c,v 1.242 2020/07/03 17:48:47 rillig Exp $");
 #endif
 #endif /* not lint */
 #endif
@@ -372,45 +372,47 @@
     Hash_Entry                 *var;
     Var                        *v;
 
-       /*
-        * If the variable name begins with a '.', it could very well be one of
-        * the local ones.  We check the name against all the local variables
-        * and substitute the short version in for 'name' if it matches one of
-        * them.
-        */
-       if (*name == '.' && isupper((unsigned char) name[1]))
-               switch (name[1]) {
-               case 'A':
-                       if (!strcmp(name, ".ALLSRC"))
-                               name = ALLSRC;
-                       if (!strcmp(name, ".ARCHIVE"))
-                               name = ARCHIVE;
-                       break;
-               case 'I':
-                       if (!strcmp(name, ".IMPSRC"))
-                               name = IMPSRC;
-                       break;
-               case 'M':
-                       if (!strcmp(name, ".MEMBER"))
-                               name = MEMBER;
-                       break;
-               case 'O':
-                       if (!strcmp(name, ".OODATE"))
-                               name = OODATE;
-                       break;
-               case 'P':
-                       if (!strcmp(name, ".PREFIX"))
-                               name = PREFIX;
-                       break;
-               case 'T':
-                       if (!strcmp(name, ".TARGET"))
-                               name = TARGET;
-                       break;
-               }
+    /*
+     * If the variable name begins with a '.', it could very well be one of
+     * the local ones.  We check the name against all the local variables
+     * and substitute the short version in for 'name' if it matches one of
+     * them.
+     */
+    if (*name == '.' && isupper((unsigned char) name[1])) {
+       switch (name[1]) {
+       case 'A':
+           if (!strcmp(name, ".ALLSRC"))
+               name = ALLSRC;
+           if (!strcmp(name, ".ARCHIVE"))
+               name = ARCHIVE;
+           break;
+       case 'I':
+           if (!strcmp(name, ".IMPSRC"))
+               name = IMPSRC;
+           break;
+       case 'M':
+           if (!strcmp(name, ".MEMBER"))
+               name = MEMBER;
+           break;
+       case 'O':
+           if (!strcmp(name, ".OODATE"))
+               name = OODATE;
+           break;
+       case 'P':
+           if (!strcmp(name, ".PREFIX"))
+               name = PREFIX;
+           break;
+       case 'T':
+           if (!strcmp(name, ".TARGET"))
+               name = TARGET;
+           break;
+       }
+    }
+
 #ifdef notyet
     /* for compatibility with gmake */
     if (name[0] == '^' && name[1] == '\0')
-           name = ALLSRC;
+       name = ALLSRC;
 #endif
 
     /*
@@ -526,7 +528,7 @@
     v = bmake_malloc(sizeof(Var));
 
     len = val ? strlen(val) : 0;
-    Buf_Init(&v->val, len+1);
+    Buf_Init(&v->val, len + 1);
     Buf_AddBytes(&v->val, len, val);
 
     v->flags = 0;
@@ -582,7 +584,7 @@
            var_exportedVars = VAR_EXPORTED_NONE;
        }
        if (v->name != ln->name)
-               free(v->name);
+           free(v->name);
        Hash_DeleteEntry(&ctxt->context, ln);
        Buf_Destroy(&v->val, TRUE);
        free(v);
@@ -675,8 +677,8 @@
 static void
 Var_ExportVars_callback(void *entry, void *unused MAKE_ATTR_UNUSED)
 {
-       Var *var = entry;
-       Var_Export1(var->name, 0);
+    Var *var = entry;
+    Var_Export1(var->name, 0);
 }
 
 /*
@@ -809,7 +811,7 @@
     int n;
 
     if (!str || !str[0]) {
-       return;                 /* assert? */
+       return;                 /* assert? */
     }
 
     vlist = NULL;
@@ -896,7 +898,8 @@
 }
 
 static void
-Var_Set_Flags(const char *name, const char *val, GNode *ctxt, VarSet_Flags flags)
+Var_Set_with_flags(const char *name, const char *val, GNode *ctxt,
+                  VarSet_Flags flags)
 {
     Var   *v;
     char *expanded_name = NULL;
@@ -981,7 +984,7 @@
            save_dollars = s2Boolean(val, save_dollars);
     }
 
- out:
+out:
     free(expanded_name);
     if (v != NULL)
        VarFreeEnv(v, TRUE);
@@ -1018,7 +1021,7 @@
 void
 Var_Set(const char *name, const char *val, GNode *ctxt)
 {
-       Var_Set_Flags(name, val, ctxt, 0);
+    Var_Set_with_flags(name, val, ctxt, 0);
 }
 
 /*-
@@ -1079,7 +1082,7 @@
 
        if (DEBUG(VAR)) {
            fprintf(debug_file, "%s:%s = %s\n", ctxt->name, name,
-                  Buf_GetAll(&v->val, NULL));
+                   Buf_GetAll(&v->val, NULL));
        }
 
        if (v->flags & VAR_FROM_ENV) {
@@ -1310,7 +1313,7 @@
     addSpace = TRUE;
 
     if ((ptr = Str_SYSVMatch(word, pat->lhs, &len, &hasPercent)) != NULL) {
-        varexp = Var_Subst(NULL, pat->rhs, ctx, VARF_WANTRES);
+       varexp = Var_Subst(NULL, pat->rhs, ctx, VARF_WANTRES);
        Str_SYSVSubst(buf, varexp, ptr, len, hasPercent);
        free(varexp);
     } else {
@@ -1399,44 +1402,44 @@
         */
        if ((pattern->flags & VAR_MATCH_START) &&
            (strncmp(word, pattern->lhs, pattern->leftLen) == 0)) {
+           /*
+            * Anchored at start and beginning of word matches pattern
+            */
+           if ((pattern->flags & VAR_MATCH_END) &&
+               (wordLen == pattern->leftLen)) {
                /*
-                * Anchored at start and beginning of word matches pattern
+                * Also anchored at end and matches to the end (word
+                * is same length as pattern) add space and rhs only
+                * if rhs is non-null.
                 */
-               if ((pattern->flags & VAR_MATCH_END) &&
-                   (wordLen == pattern->leftLen)) {
-                       /*
-                        * Also anchored at end and matches to the end (word
-                        * is same length as pattern) add space and rhs only
-                        * if rhs is non-null.
-                        */
-                       if (pattern->rightLen != 0) {
-                           if (addSpace && vpstate->varSpace) {
-                               Buf_AddByte(buf, vpstate->varSpace);
-                           }
-                           addSpace = TRUE;
-                           Buf_AddBytes(buf, pattern->rightLen, pattern->rhs);
-                       }
-                       pattern->flags |= VAR_SUB_MATCHED;
-               } else if (pattern->flags & VAR_MATCH_END) {
-                   /*
-                    * Doesn't match to end -- copy word wholesale
-                    */
-                   goto nosub;
-               } else {
-                   /*
-                    * Matches at start but need to copy in trailing characters
-                    */
-                   if ((pattern->rightLen + wordLen - pattern->leftLen) != 0){
-                       if (addSpace && vpstate->varSpace) {
-                           Buf_AddByte(buf, vpstate->varSpace);
-                       }
-                       addSpace = TRUE;
+               if (pattern->rightLen != 0) {
+                   if (addSpace && vpstate->varSpace) {
+                       Buf_AddByte(buf, vpstate->varSpace);
                    }
+                   addSpace = TRUE;
                    Buf_AddBytes(buf, pattern->rightLen, pattern->rhs);
-                   Buf_AddBytes(buf, wordLen - pattern->leftLen,
-                                (word + pattern->leftLen));
-                   pattern->flags |= VAR_SUB_MATCHED;
                }
+               pattern->flags |= VAR_SUB_MATCHED;
+           } else if (pattern->flags & VAR_MATCH_END) {
+               /*
+                * Doesn't match to end -- copy word wholesale
+                */
+               goto nosub;
+           } else {
+               /*
+                * Matches at start but need to copy in trailing characters
+                */
+               if ((pattern->rightLen + wordLen - pattern->leftLen) != 0){
+                   if (addSpace && vpstate->varSpace) {
+                       Buf_AddByte(buf, vpstate->varSpace);
+                   }
+                   addSpace = TRUE;
+               }
+               Buf_AddBytes(buf, pattern->rightLen, pattern->rhs);
+               Buf_AddBytes(buf, wordLen - pattern->leftLen,
+                            (word + pattern->leftLen));
+               pattern->flags |= VAR_SUB_MATCHED;
+           }
        } else if (pattern->flags & VAR_MATCH_START) {
            /*
             * Had to match at start of word and didn't -- copy whole word.
@@ -1527,7 +1530,7 @@
        }
        return addSpace;
     }
- nosub:
+nosub:
     if (addSpace && vpstate->varSpace) {
        Buf_AddByte(buf, vpstate->varSpace);
     }
@@ -1620,8 +1623,7 @@
                MAYBE_ADD_SPACE();
                Buf_AddByte(buf, rp[1]);
                rp++;
-           }
-           else if ((*rp == '&') ||
+           } else if ((*rp == '&') ||
                ((*rp == '\\') && isdigit((unsigned char)rp[1]))) {
                int n;
                const char *subbuf;
@@ -1649,7 +1651,7 @@
                    Error("No match for subexpression %s", &errstr[0]);
                    subbuf = "";
                    sublen = 0;
-               } else {
+               } else {
                    subbuf = wp + pat->matches[n].rm_so;
                    sublen = pat->matches[n].rm_eo - pat->matches[n].rm_so;
                }



Home | Main Index | Thread Index | Old Index