Source-Changes-HG archive

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

[src/trunk]: src/usr.bin/make move some code out of the gigantic main functio...



details:   https://anonhg.NetBSD.org/src/rev/946ebab8fe68
branches:  trunk
changeset: 824765:946ebab8fe68
user:      christos <christos%NetBSD.org@localhost>
date:      Sat Jun 17 15:26:50 2017 +0000

description:
move some code out of the gigantic main function; no functional change.

diffstat:

 usr.bin/make/main.c |  155 +++++++++++++++++++++++++++++----------------------
 1 files changed, 87 insertions(+), 68 deletions(-)

diffs (201 lines):

diff -r fa618cafc2db -r 946ebab8fe68 usr.bin/make/main.c
--- a/usr.bin/make/main.c       Sat Jun 17 15:26:44 2017 +0000
+++ b/usr.bin/make/main.c       Sat Jun 17 15:26:50 2017 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: main.c,v 1.265 2017/05/10 22:26:14 sjg Exp $   */
+/*     $NetBSD: main.c,v 1.266 2017/06/17 15:26:50 christos Exp $      */
 
 /*
  * Copyright (c) 1988, 1989, 1990, 1993
@@ -69,7 +69,7 @@
  */
 
 #ifndef MAKE_NATIVE
-static char rcsid[] = "$NetBSD: main.c,v 1.265 2017/05/10 22:26:14 sjg Exp $";
+static char rcsid[] = "$NetBSD: main.c,v 1.266 2017/06/17 15:26:50 christos Exp $";
 #else
 #include <sys/cdefs.h>
 #ifndef lint
@@ -81,7 +81,7 @@
 #if 0
 static char sccsid[] = "@(#)main.c     8.3 (Berkeley) 3/19/94";
 #else
-__RCSID("$NetBSD: main.c,v 1.265 2017/05/10 22:26:14 sjg Exp $");
+__RCSID("$NetBSD: main.c,v 1.266 2017/06/17 15:26:50 christos Exp $");
 #endif
 #endif /* not lint */
 #endif
@@ -846,6 +846,86 @@
     free(mp);
 }
 
+static void
+doPrintVars(void)
+{
+       LstNode ln;
+       Boolean expandVars;
+
+       if (debugVflag)
+               expandVars = FALSE;
+       else
+               expandVars = getBoolean(".MAKE.EXPAND_VARIABLES", FALSE);
+
+       for (ln = Lst_First(variables); ln != NULL;
+           ln = Lst_Succ(ln)) {
+               char *var = (char *)Lst_Datum(ln);
+               char *value;
+               char *p1;
+               
+               if (strchr(var, '$')) {
+                   value = p1 = Var_Subst(NULL, var, VAR_GLOBAL, VARF_WANTRES);
+               } else if (expandVars) {
+                       char tmp[128];
+                       int len = snprintf(tmp, sizeof(tmp), "${%s}", var);
+                                                       
+                       if (len >= (int)sizeof(tmp))
+                               Fatal("%s: variable name too big: %s",
+                                     progname, var);
+                       value = p1 = Var_Subst(NULL, tmp, VAR_GLOBAL,
+                           VARF_WANTRES);
+               } else {
+                       value = Var_Value(var, VAR_GLOBAL, &p1);
+               }
+               printf("%s\n", value ? value : "");
+               free(p1);
+       }
+}
+
+static Boolean
+runTargets(void)
+{
+       Lst targs;      /* target nodes to create -- passed to Make_Init */
+       Boolean outOfDate;      /* FALSE if all targets up to date */
+
+       /*
+        * Have now read the entire graph and need to make a list of
+        * targets to create. If none was given on the command line,
+        * we consult the parsing module to find the main target(s)
+        * to create.
+        */
+       if (Lst_IsEmpty(create))
+               targs = Parse_MainName();
+       else
+               targs = Targ_FindList(create, TARG_CREATE);
+
+       if (!compatMake) {
+               /*
+                * Initialize job module before traversing the graph
+                * now that any .BEGIN and .END targets have been read.
+                * This is done only if the -q flag wasn't given
+                * (to prevent the .BEGIN from being executed should
+                * it exist).
+                */
+               if (!queryFlag) {
+                       Job_Init();
+                       jobsRunning = TRUE;
+               }
+
+               /* Traverse the graph, checking on all the targets */
+               outOfDate = Make_Run(targs);
+       } else {
+               /*
+                * Compat_Init will take care of creating all the
+                * targets as well as initializing the module.
+                */
+               Compat_Run(targs);
+               outOfDate = FALSE;
+       }
+       Lst_Destroy(targs, NULL);
+       return outOfDate;
+}
+
 /*-
  * main --
  *     The main function, for obvious reasons. Initializes variables
@@ -866,8 +946,7 @@
 int
 main(int argc, char **argv)
 {
-       Lst targs;      /* target nodes to create -- passed to Make_Init */
-       Boolean outOfDate = FALSE;      /* FALSE if all targets up to date */
+       Boolean outOfDate;      /* FALSE if all targets up to date */
        struct stat sb, sa;
        char *p1, *path;
        char mdpath[MAXPATHLEN];
@@ -1372,73 +1451,13 @@
 
        /* print the values of any variables requested by the user */
        if (printVars) {
-               LstNode ln;
-               Boolean expandVars;
-
-               if (debugVflag)
-                       expandVars = FALSE;
-               else
-                       expandVars = getBoolean(".MAKE.EXPAND_VARIABLES", FALSE);
-               for (ln = Lst_First(variables); ln != NULL;
-                   ln = Lst_Succ(ln)) {
-                       char *var = (char *)Lst_Datum(ln);
-                       char *value;
-                       
-                       if (strchr(var, '$')) {
-                           value = p1 = Var_Subst(NULL, var, VAR_GLOBAL,
-                                                  VARF_WANTRES);
-                       } else if (expandVars) {
-                               char tmp[128];
-                                                               
-                               if (snprintf(tmp, sizeof(tmp), "${%s}", var) >= (int)(sizeof(tmp)))
-                                       Fatal("%s: variable name too big: %s",
-                                             progname, var);
-                               value = p1 = Var_Subst(NULL, tmp, VAR_GLOBAL,
-                                                      VARF_WANTRES);
-                       } else {
-                               value = Var_Value(var, VAR_GLOBAL, &p1);
-                       }
-                       printf("%s\n", value ? value : "");
-                       free(p1);
-               }
+               doPrintVars();
+               outOfDate = FALSE;
        } else {
-               /*
-                * Have now read the entire graph and need to make a list of
-                * targets to create. If none was given on the command line,
-                * we consult the parsing module to find the main target(s)
-                * to create.
-                */
-               if (Lst_IsEmpty(create))
-                       targs = Parse_MainName();
-               else
-                       targs = Targ_FindList(create, TARG_CREATE);
-
-               if (!compatMake) {
-                       /*
-                        * Initialize job module before traversing the graph
-                        * now that any .BEGIN and .END targets have been read.
-                        * This is done only if the -q flag wasn't given
-                        * (to prevent the .BEGIN from being executed should
-                        * it exist).
-                        */
-                       if (!queryFlag) {
-                               Job_Init();
-                               jobsRunning = TRUE;
-                       }
-
-                       /* Traverse the graph, checking on all the targets */
-                       outOfDate = Make_Run(targs);
-               } else {
-                       /*
-                        * Compat_Init will take care of creating all the
-                        * targets as well as initializing the module.
-                        */
-                       Compat_Run(targs);
-               }
+               outOfDate = runTargets();
        }
 
 #ifdef CLEANUP
-       Lst_Destroy(targs, NULL);
        Lst_Destroy(variables, NULL);
        Lst_Destroy(makefiles, NULL);
        Lst_Destroy(create, (FreeProc *)free);



Home | Main Index | Thread Index | Old Index