Module Name:    src
Committed By:   christos
Date:           Wed Jun 17 17:43:23 UTC 2015

Modified Files:
        src/usr.bin/make: Makefile compat.c var.c

Log Message:
Centralize the "is a meta char" test, instead of using two different arrays.


To generate a diff of this commit:
cvs rdiff -u -r1.57 -r1.58 src/usr.bin/make/Makefile
cvs rdiff -u -r1.96 -r1.97 src/usr.bin/make/compat.c
cvs rdiff -u -r1.192 -r1.193 src/usr.bin/make/var.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/usr.bin/make/Makefile
diff -u src/usr.bin/make/Makefile:1.57 src/usr.bin/make/Makefile:1.58
--- src/usr.bin/make/Makefile:1.57	Sat Jul  5 15:22:05 2014
+++ src/usr.bin/make/Makefile	Wed Jun 17 13:43:23 2015
@@ -1,9 +1,9 @@
-#	$NetBSD: Makefile,v 1.57 2014/07/05 19:22:05 dholland Exp $
+#	$NetBSD: Makefile,v 1.58 2015/06/17 17:43:23 christos Exp $
 #	@(#)Makefile	5.2 (Berkeley) 12/28/90
 
 PROG=	make
 SRCS=	arch.c buf.c compat.c cond.c dir.c for.c hash.c job.c main.c \
-	make.c parse.c str.c suff.c targ.c trace.c var.c util.c 
+	make.c metachar.c parse.c str.c suff.c targ.c trace.c var.c util.c 
 SRCS+=  strlist.c
 SRCS+=  make_malloc.c
 SRCS+=	lstAppend.c lstAtEnd.c lstAtFront.c lstClose.c lstConcat.c \

Index: src/usr.bin/make/compat.c
diff -u src/usr.bin/make/compat.c:1.96 src/usr.bin/make/compat.c:1.97
--- src/usr.bin/make/compat.c:1.96	Sun Sep  7 16:55:34 2014
+++ src/usr.bin/make/compat.c	Wed Jun 17 13:43:23 2015
@@ -1,4 +1,4 @@
-/*	$NetBSD: compat.c,v 1.96 2014/09/07 20:55:34 joerg Exp $	*/
+/*	$NetBSD: compat.c,v 1.97 2015/06/17 17:43:23 christos Exp $	*/
 
 /*
  * Copyright (c) 1988, 1989, 1990 The Regents of the University of California.
@@ -70,14 +70,14 @@
  */
 
 #ifndef MAKE_NATIVE
-static char rcsid[] = "$NetBSD: compat.c,v 1.96 2014/09/07 20:55:34 joerg Exp $";
+static char rcsid[] = "$NetBSD: compat.c,v 1.97 2015/06/17 17:43:23 christos Exp $";
 #else
 #include <sys/cdefs.h>
 #ifndef lint
 #if 0
 static char sccsid[] = "@(#)compat.c	8.2 (Berkeley) 3/19/94";
 #else
-__RCSID("$NetBSD: compat.c,v 1.96 2014/09/07 20:55:34 joerg Exp $");
+__RCSID("$NetBSD: compat.c,v 1.97 2015/06/17 17:43:23 christos Exp $");
 #endif
 #endif /* not lint */
 #endif
@@ -108,37 +108,14 @@ __RCSID("$NetBSD: compat.c,v 1.96 2014/0
 #include    "hash.h"
 #include    "dir.h"
 #include    "job.h"
+#include    "metachar.h"
 #include    "pathnames.h"
 
-/*
- * The following array is used to make a fast determination of which
- * characters are interpreted specially by the shell.  If a command
- * contains any of these characters, it is executed by the shell, not
- * directly by us.
- */
-
-static char 	    meta[256];
 
 static GNode	    *curTarg = NULL;
 static GNode	    *ENDNode;
 static void CompatInterrupt(int);
 
-static void
-Compat_Init(void)
-{
-    const char *cp;
-
-    Shell_Init();		/* setup default shell */
-    
-    for (cp = "~#=|^(){};&<>*?[]:$`\\\n"; *cp != '\0'; cp++) {
-	meta[(unsigned char) *cp] = 1;
-    }
-    /*
-     * The null character serves as a sentinel in the string.
-     */
-    meta[0] = 1;
-}
-
 /*-
  *-----------------------------------------------------------------------
  * CompatInterrupt --
@@ -268,8 +245,8 @@ CompatRunCommand(void *cmdp, void *gnp)
 	    break;
 	case '+':
 	    doIt = TRUE;
-	    if (!meta[0])		/* we came here from jobs */
-		Compat_Init();
+	    if (!shellName)		/* we came here from jobs */
+		Shell_Init();
 	    break;
 	}
 	cmd++;
@@ -298,10 +275,8 @@ CompatRunCommand(void *cmdp, void *gnp)
      * characters, there's no need to execute a shell to execute the
      * command.
      */
-    for (cp = cmd; !meta[(unsigned char)*cp]; cp++) {
-	continue;
-    }
-    useShell = (*cp != '\0');
+    
+    useShell = hasmeta(cmd);
 #endif
 
     /*
@@ -509,8 +484,8 @@ Compat_Make(void *gnp, void *pgnp)
     GNode *gn = (GNode *)gnp;
     GNode *pgn = (GNode *)pgnp;
 
-    if (!meta[0])		/* we came here from jobs */
-	Compat_Init();
+    if (!shellName)		/* we came here from jobs */
+	Shell_Init();
     if (gn->made == UNMADE && (gn == pgn || (pgn->type & OP_MADE) == 0)) {
 	/*
 	 * First mark ourselves to be made, then apply whatever transformations
@@ -690,7 +665,8 @@ Compat_Run(Lst targs)
     GNode   	  *gn = NULL;/* Current root target */
     int	    	  errors;   /* Number of targets not remade due to errors */
 
-    Compat_Init();
+    if (!shellName)
+	Shell_Init();
 
     if (bmake_signal(SIGINT, SIG_IGN) != SIG_IGN) {
 	bmake_signal(SIGINT, CompatInterrupt);

Index: src/usr.bin/make/var.c
diff -u src/usr.bin/make/var.c:1.192 src/usr.bin/make/var.c:1.193
--- src/usr.bin/make/var.c:1.192	Tue May  5 17:51:09 2015
+++ src/usr.bin/make/var.c	Wed Jun 17 13:43:23 2015
@@ -1,4 +1,4 @@
-/*	$NetBSD: var.c,v 1.192 2015/05/05 21:51:09 sjg Exp $	*/
+/*	$NetBSD: var.c,v 1.193 2015/06/17 17:43:23 christos Exp $	*/
 
 /*
  * Copyright (c) 1988, 1989, 1990, 1993
@@ -69,14 +69,14 @@
  */
 
 #ifndef MAKE_NATIVE
-static char rcsid[] = "$NetBSD: var.c,v 1.192 2015/05/05 21:51:09 sjg Exp $";
+static char rcsid[] = "$NetBSD: var.c,v 1.193 2015/06/17 17:43:23 christos 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.192 2015/05/05 21:51:09 sjg Exp $");
+__RCSID("$NetBSD: var.c,v 1.193 2015/06/17 17:43:23 christos Exp $");
 #endif
 #endif /* not lint */
 #endif
@@ -138,6 +138,7 @@ __RCSID("$NetBSD: var.c,v 1.192 2015/05/
 #include    "buf.h"
 #include    "dir.h"
 #include    "job.h"
+#include    "metachar.h"
 
 extern int makelevel;
 /*
@@ -2260,29 +2261,25 @@ VarQuote(char *str)
 {
 
     Buffer  	  buf;
-    /* This should cover most shells :-( */
-    static const char meta[] = "\n \t'`\";&<>()|*?{}[]\\$!#^~";
     const char	*newline;
-    size_t len, nlen;
+    size_t nlen;
 
     if ((newline = Shell_GetNewline()) == NULL)
 	    newline = "\\\n";
     nlen = strlen(newline);
 
     Buf_Init(&buf, 0);
-    while (*str != '\0') {
-	if ((len = strcspn(str, meta)) != 0) {
-	    Buf_AddBytes(&buf, len, str);
-	    str += len;
-	} else if (*str == '\n') {
+
+    for (; *str != '\0'; str++) {
+	if (*str == '\n') {
 	    Buf_AddBytes(&buf, nlen, newline);
-	    ++str;
-	} else {
-	    Buf_AddByte(&buf, '\\');
-	    Buf_AddByte(&buf, *str);
-	    ++str;
+	    continue;
 	}
+	if (ismeta((unsigned char)*str))
+	    Buf_AddByte(&buf, '\\');
+	Buf_AddByte(&buf, *str);
     }
+
     str = Buf_Destroy(&buf, FALSE);
     if (DEBUG(VAR))
 	fprintf(debug_file, "QuoteMeta: [%s]\n", str);

Reply via email to