Source-Changes-HG archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
[src/trunk]: src/usr.bin/make Centralize the "is a meta char" test, instead o...
details: https://anonhg.NetBSD.org/src/rev/cde5cf017e28
branches: trunk
changeset: 338937:cde5cf017e28
user: christos <christos%NetBSD.org@localhost>
date: Wed Jun 17 17:43:23 2015 +0000
description:
Centralize the "is a meta char" test, instead of using two different arrays.
diffstat:
usr.bin/make/Makefile | 4 ++--
usr.bin/make/compat.c | 48 ++++++++++++------------------------------------
usr.bin/make/var.c | 29 +++++++++++++----------------
3 files changed, 27 insertions(+), 54 deletions(-)
diffs (198 lines):
diff -r 62fd376195fe -r cde5cf017e28 usr.bin/make/Makefile
--- a/usr.bin/make/Makefile Wed Jun 17 15:52:37 2015 +0000
+++ b/usr.bin/make/Makefile Wed Jun 17 17:43:23 2015 +0000
@@ -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 \
diff -r 62fd376195fe -r cde5cf017e28 usr.bin/make/compat.c
--- a/usr.bin/make/compat.c Wed Jun 17 15:52:37 2015 +0000
+++ b/usr.bin/make/compat.c Wed Jun 17 17:43:23 2015 +0000
@@ -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 @@
#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 @@
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 @@
* 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 @@
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 @@
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);
diff -r 62fd376195fe -r cde5cf017e28 usr.bin/make/var.c
--- a/usr.bin/make/var.c Wed Jun 17 15:52:37 2015 +0000
+++ b/usr.bin/make/var.c Wed Jun 17 17:43:23 2015 +0000
@@ -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 @@
#include "buf.h"
#include "dir.h"
#include "job.h"
+#include "metachar.h"
extern int makelevel;
/*
@@ -2260,29 +2261,25 @@
{
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 {
+ continue;
+ }
+ if (ismeta((unsigned char)*str))
Buf_AddByte(&buf, '\\');
- Buf_AddByte(&buf, *str);
- ++str;
- }
+ Buf_AddByte(&buf, *str);
}
+
str = Buf_Destroy(&buf, FALSE);
if (DEBUG(VAR))
fprintf(debug_file, "QuoteMeta: [%s]\n", str);
Home |
Main Index |
Thread Index |
Old Index