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): indent for.c using tabs instead of spaces



details:   https://anonhg.NetBSD.org/src/rev/fd44de85f661
branches:  trunk
changeset: 979140:fd44de85f661
user:      rillig <rillig%NetBSD.org@localhost>
date:      Tue Dec 15 16:24:17 2020 +0000

description:
make(1): indent for.c using tabs instead of spaces

diffstat:

 usr.bin/make/for.c |  512 ++++++++++++++++++++++++++--------------------------
 1 files changed, 260 insertions(+), 252 deletions(-)

diffs (truncated from 667 to 300 lines):

diff -r b9d41581af03 -r fd44de85f661 usr.bin/make/for.c
--- a/usr.bin/make/for.c        Tue Dec 15 15:20:05 2020 +0000
+++ b/usr.bin/make/for.c        Tue Dec 15 16:24:17 2020 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: for.c,v 1.117 2020/12/13 21:27:45 rillig Exp $ */
+/*     $NetBSD: for.c,v 1.118 2020/12/15 16:24:17 rillig Exp $ */
 
 /*
  * Copyright (c) 1992, The Regents of the University of California.
@@ -60,29 +60,29 @@
 #include "make.h"
 
 /*     "@(#)for.c      8.1 (Berkeley) 6/6/93"  */
-MAKE_RCSID("$NetBSD: for.c,v 1.117 2020/12/13 21:27:45 rillig Exp $");
+MAKE_RCSID("$NetBSD: for.c,v 1.118 2020/12/15 16:24:17 rillig Exp $");
 
 static int forLevel = 0;       /* Nesting level */
 
 /* One of the variables to the left of the "in" in a .for loop. */
 typedef struct ForVar {
-    char *name;
-    size_t len;
+       char *name;
+       size_t len;
 } ForVar;
 
 /*
  * State of a for loop.
  */
 typedef struct For {
-    Buffer body;               /* Unexpanded body of the loop */
-    Vector /* of ForVar */ vars; /* Iteration variables */
-    Words items;               /* Substitution items */
-    Buffer curBody;            /* Expanded body of the current iteration */
-    /* Is any of the names 1 character long? If so, when the variable values
-     * are substituted, the parser must handle $V expressions as well, not
-     * only ${V} and $(V). */
-    Boolean short_var;
-    unsigned int sub_next;     /* Where to continue iterating */
+       Buffer body;            /* Unexpanded body of the loop */
+       Vector /* of ForVar */ vars; /* Iteration variables */
+       Words items;            /* Substitution items */
+       Buffer curBody;         /* Expanded body of the current iteration */
+       /* Is any of the names 1 character long? If so, when the variable values
+        * are substituted, the parser must handle $V expressions as well, not
+        * only ${V} and $(V). */
+       Boolean short_var;
+       unsigned int sub_next;  /* Where to continue iterating */
 } For;
 
 static For *accumFor;          /* Loop being accumulated */
@@ -90,39 +90,39 @@
 static void
 ForAddVar(For *f, const char *name, size_t len)
 {
-    ForVar *var = Vector_Push(&f->vars);
-    var->name = bmake_strldup(name, len);
-    var->len = len;
+       ForVar *var = Vector_Push(&f->vars);
+       var->name = bmake_strldup(name, len);
+       var->len = len;
 }
 
 static void
 For_Free(For *f)
 {
-    Buf_Destroy(&f->body, TRUE);
+       Buf_Destroy(&f->body, TRUE);
 
-    while (f->vars.len > 0) {
-       ForVar *var = Vector_Pop(&f->vars);
-       free(var->name);
-    }
-    Vector_Done(&f->vars);
+       while (f->vars.len > 0) {
+               ForVar *var = Vector_Pop(&f->vars);
+               free(var->name);
+       }
+       Vector_Done(&f->vars);
 
-    Words_Free(f->items);
-    Buf_Destroy(&f->curBody, TRUE);
+       Words_Free(f->items);
+       Buf_Destroy(&f->curBody, TRUE);
 
-    free(f);
+       free(f);
 }
 
 static Boolean
 IsFor(const char *p)
 {
-    return p[0] == 'f' && p[1] == 'o' && p[2] == 'r' && ch_isspace(p[3]);
+       return p[0] == 'f' && p[1] == 'o' && p[2] == 'r' && ch_isspace(p[3]);
 }
 
 static Boolean
 IsEndfor(const char *p)
 {
-    return p[0] == 'e' && strncmp(p, "endfor", 6) == 0 &&
-          (p[6] == '\0' || ch_isspace(p[6]));
+       return p[0] == 'e' && strncmp(p, "endfor", 6) == 0 &&
+              (p[6] == '\0' || ch_isspace(p[6]));
 }
 
 /* Evaluate the for loop in the passed line. The line looks like this:
@@ -139,99 +139,103 @@
 int
 For_Eval(const char *line)
 {
-    For *f;
-    const char *p;
+       For *f;
+       const char *p;
 
-    p = line + 1;              /* skip the '.' */
-    cpp_skip_whitespace(&p);
+       p = line + 1;           /* skip the '.' */
+       cpp_skip_whitespace(&p);
 
-    if (!IsFor(p)) {
-       if (IsEndfor(p)) {
-           Parse_Error(PARSE_FATAL, "for-less endfor");
-           return -1;
+       if (!IsFor(p)) {
+               if (IsEndfor(p)) {
+                       Parse_Error(PARSE_FATAL, "for-less endfor");
+                       return -1;
+               }
+               return 0;
        }
-       return 0;
-    }
-    p += 3;
+       p += 3;
+
+       /*
+        * we found a for loop, and now we are going to parse it.
+        */
 
-    /*
-     * we found a for loop, and now we are going to parse it.
-     */
+       f = bmake_malloc(sizeof *f);
+       Buf_Init(&f->body);
+       Vector_Init(&f->vars, sizeof(ForVar));
+       f->items.words = NULL;
+       f->items.freeIt = NULL;
+       Buf_Init(&f->curBody);
+       f->short_var = FALSE;
+       f->sub_next = 0;
 
-    f = bmake_malloc(sizeof *f);
-    Buf_Init(&f->body);
-    Vector_Init(&f->vars, sizeof(ForVar));
-    f->items.words = NULL;
-    f->items.freeIt = NULL;
-    Buf_Init(&f->curBody);
-    f->short_var = FALSE;
-    f->sub_next = 0;
+       /* Grab the variables. Terminate on "in". */
+       for (;;) {
+               size_t len;
+
+               cpp_skip_whitespace(&p);
+               if (*p == '\0') {
+                       Parse_Error(PARSE_FATAL, "missing `in' in for");
+                       For_Free(f);
+                       return -1;
+               }
 
-    /* Grab the variables. Terminate on "in". */
-    for (;;) {
-       size_t len;
+               /*
+                * XXX: This allows arbitrary variable names;
+                * see directive-for.mk.
+                */
+               for (len = 1; p[len] != '\0' && !ch_isspace(p[len]); len++)
+                       continue;
 
-       cpp_skip_whitespace(&p);
-       if (*p == '\0') {
-           Parse_Error(PARSE_FATAL, "missing `in' in for");
-           For_Free(f);
-           return -1;
+               if (len == 2 && p[0] == 'i' && p[1] == 'n') {
+                       p += 2;
+                       break;
+               }
+               if (len == 1)
+                       f->short_var = TRUE;
+
+               ForAddVar(f, p, len);
+               p += len;
        }
 
-       /* XXX: This allows arbitrary variable names; see directive-for.mk. */
-       for (len = 1; p[len] != '\0' && !ch_isspace(p[len]); len++)
-           continue;
+       if (f->vars.len == 0) {
+               Parse_Error(PARSE_FATAL, "no iteration variables in for");
+               For_Free(f);
+               return -1;
+       }
 
-       if (len == 2 && p[0] == 'i' && p[1] == 'n') {
-           p += 2;
-           break;
-       }
-       if (len == 1)
-           f->short_var = TRUE;
+       cpp_skip_whitespace(&p);
 
-       ForAddVar(f, p, len);
-       p += len;
-    }
+       {
+               char *items;
+               (void)Var_Subst(p, VAR_GLOBAL, VARE_WANTRES, &items);
+               /* TODO: handle errors */
+               f->items = Str_Words(items, FALSE);
+               free(items);
 
-    if (f->vars.len == 0) {
-       Parse_Error(PARSE_FATAL, "no iteration variables in for");
-       For_Free(f);
-       return -1;
-    }
-
-    cpp_skip_whitespace(&p);
+               if (f->items.len == 1 && f->items.words[0][0] == '\0')
+                       f->items.len = 0; /* .for var in ${:U} */
+       }
 
-    {
-       char *items;
-       (void)Var_Subst(p, VAR_GLOBAL, VARE_WANTRES, &items);
-       /* TODO: handle errors */
-       f->items = Str_Words(items, FALSE);
-       free(items);
-
-       if (f->items.len == 1 && f->items.words[0][0] == '\0')
-           f->items.len = 0;   /* .for var in ${:U} */
-    }
-
-    {
-       size_t nitems, nvars;
+       {
+               size_t nitems, nvars;
 
-       if ((nitems = f->items.len) > 0 && nitems % (nvars = f->vars.len)) {
-           Parse_Error(PARSE_FATAL,
-                       "Wrong number of words (%u) in .for substitution list"
-                       " with %u variables",
-                       (unsigned)nitems, (unsigned)nvars);
-           /*
-            * Return 'success' so that the body of the .for loop is
-            * accumulated.
-            * Remove all items so that the loop doesn't iterate.
-            */
-           f->items.len = 0;
+               if ((nitems = f->items.len) > 0 &&
+                   nitems % (nvars = f->vars.len)) {
+                       Parse_Error(PARSE_FATAL,
+                           "Wrong number of words (%u) in .for "
+                           "substitution list with %u variables",
+                           (unsigned)nitems, (unsigned)nvars);
+                       /*
+                        * Return 'success' so that the body of the .for loop
+                        * is accumulated.
+                        * Remove all items so that the loop doesn't iterate.
+                        */
+                       f->items.len = 0;
+               }
        }
-    }
 
-    accumFor = f;
-    forLevel = 1;
-    return 1;
+       accumFor = f;
+       forLevel = 1;
+       return 1;
 }
 
 /*
@@ -241,58 +245,57 @@
 Boolean
 For_Accum(const char *line)
 {
-    const char *ptr = line;
+       const char *ptr = line;
 
-    if (*ptr == '.') {
-       ptr++;
-       cpp_skip_whitespace(&ptr);
+       if (*ptr == '.') {
+               ptr++;
+               cpp_skip_whitespace(&ptr);



Home | Main Index | Thread Index | Old Index