diff options
| author | rillig <rillig@NetBSD.org> | 2006-06-29 22:01:17 +0000 |
|---|---|---|
| committer | rillig <rillig@NetBSD.org> | 2006-06-29 22:01:17 +0000 |
| commit | a3ea8b9d595cf152aaa082cd30461b2917f43b75 (patch) | |
| tree | fb9b6e5ef1a944a8c525442b345d5cdcc973b95e /usr.bin/make | |
| parent | fbdae7393a2efb6791315666dafc3ac3f712cdd5 (diff) | |
Fixed the bug reported in PR 33866, which is that the :Q operator does not
handle newlines correctly. Ok'ed by christos.
Diffstat (limited to 'usr.bin/make')
| -rw-r--r-- | usr.bin/make/job.c | 28 | ||||
| -rw-r--r-- | usr.bin/make/job.h | 6 | ||||
| -rw-r--r-- | usr.bin/make/make.1 | 9 | ||||
| -rw-r--r-- | usr.bin/make/var.c | 22 |
4 files changed, 47 insertions, 18 deletions
diff --git a/usr.bin/make/job.c b/usr.bin/make/job.c index 3a137a93ff9..930121cd9f5 100644 --- a/usr.bin/make/job.c +++ b/usr.bin/make/job.c @@ -1,4 +1,4 @@ -/* $NetBSD: job.c,v 1.111 2006/03/31 21:05:34 dsl Exp $ */ +/* $NetBSD: job.c,v 1.112 2006/06/29 22:01:17 rillig Exp $ */ /* * Copyright (c) 1988, 1989, 1990 The Regents of the University of California. @@ -70,14 +70,14 @@ */ #ifndef MAKE_NATIVE -static char rcsid[] = "$NetBSD: job.c,v 1.111 2006/03/31 21:05:34 dsl Exp $"; +static char rcsid[] = "$NetBSD: job.c,v 1.112 2006/06/29 22:01:17 rillig Exp $"; #else #include <sys/cdefs.h> #ifndef lint #if 0 static char sccsid[] = "@(#)job.c 8.2 (Berkeley) 3/19/94"; #else -__RCSID("$NetBSD: job.c,v 1.111 2006/03/31 21:05:34 dsl Exp $"); +__RCSID("$NetBSD: job.c,v 1.112 2006/06/29 22:01:17 rillig Exp $"); #endif #endif /* not lint */ #endif @@ -215,7 +215,7 @@ static Shell shells[] = { { "csh", TRUE, "unset verbose", "set verbose", "unset verbose", 10, - FALSE, "echo \"%s\"\n", "csh -c \"%s || exit 0\"\n", "", '#', + FALSE, "echo \"%s\"\n", "csh -c \"%s || exit 0\"\n", "", "'\\\n'", '#', "v", "e", }, /* @@ -225,7 +225,7 @@ static Shell shells[] = { { "sh", FALSE, "", "", "", 0, - FALSE, "echo \"%s\"\n", "%s\n", "{ %s \n} || exit $?\n", '#', + FALSE, "echo \"%s\"\n", "%s\n", "{ %s \n} || exit $?\n", "'\n'", '#', #ifdef __NetBSD__ "q", #else @@ -239,7 +239,7 @@ static Shell shells[] = { { "ksh", TRUE, "set +v", "set -v", "set +v", 6, - FALSE, "echo \"%s\"\n", "%s\n", "{ %s \n} || exit $?\n", '#', + FALSE, "echo \"%s\"\n", "%s\n", "{ %s \n} || exit $?\n", "'\n'", '#', "v", "", }, @@ -249,7 +249,7 @@ static Shell shells[] = { { NULL, FALSE, NULL, NULL, NULL, 0, - FALSE, NULL, NULL, NULL, 0, + FALSE, NULL, NULL, NULL, NULL, 0, NULL, NULL, } }; @@ -2187,6 +2187,17 @@ Shell_Init() } /*- + * Returns the string literal that is used in the current command shell + * to produce a newline character. + */ +const char * +Shell_GetNewline(void) +{ + + return commandShell->newline; +} + +/*- *----------------------------------------------------------------------- * Job_Init -- * Initialize the process module @@ -2364,6 +2375,7 @@ JobMatchShell(const char *name) * echoFlag Flag to turn echoing on at the start * errFlag Flag to turn error checking on at the start * hasErrCtl True if shell has error checking control + * newline String literal to represent a newline char * check Command to turn on error checking if hasErrCtl * is TRUE or template of command to echo a command * for which error checking is off if hasErrCtl is @@ -2422,6 +2434,8 @@ Job_ParseShell(char *line) char c = argv[0][10]; newShell.hasErrCtl = !((c != 'Y') && (c != 'y') && (c != 'T') && (c != 't')); + } else if (strncmp(*argv, "newline=", 8) == 0) { + newShell.newline = &argv[0][8]; } else if (strncmp(*argv, "check=", 6) == 0) { newShell.errCheck = &argv[0][6]; } else if (strncmp(*argv, "ignore=", 7) == 0) { diff --git a/usr.bin/make/job.h b/usr.bin/make/job.h index 19d3ed4d398..a1be71b49f2 100644 --- a/usr.bin/make/job.h +++ b/usr.bin/make/job.h @@ -1,4 +1,4 @@ -/* $NetBSD: job.h,v 1.27 2006/03/31 21:05:34 dsl Exp $ */ +/* $NetBSD: job.h,v 1.28 2006/06/29 22:01:17 rillig Exp $ */ /* * Copyright (c) 1988, 1989, 1990 The Regents of the University of California. @@ -250,6 +250,9 @@ typedef struct Shell { const char *errCheck; /* string to turn error checking on */ const char *ignErr; /* string to turn off error checking */ const char *errOut; /* string to use for testing exit code */ + const char *newline; /* string literal that results in a newline + * character when it appears outside of any + * 'quote' or "quote" characters */ char commentChar; /* character used by shell for comment lines */ /* @@ -268,6 +271,7 @@ extern int maxJobs; /* Max jobs we can run */ extern int maxJobTokens; /* Number of token for the job pipe */ void Shell_Init(void); +const char *Shell_GetNewline(void); void Job_Touch(GNode *, Boolean); Boolean Job_CheckCommands(GNode *, void (*abortProc )(const char *, ...)); void Job_CatchChildren(Boolean); diff --git a/usr.bin/make/make.1 b/usr.bin/make/make.1 index 9057d7af446..27a7dfda50a 100644 --- a/usr.bin/make/make.1 +++ b/usr.bin/make/make.1 @@ -1,4 +1,4 @@ -.\" $NetBSD: make.1,v 1.126 2006/06/17 02:15:22 reed Exp $ +.\" $NetBSD: make.1,v 1.127 2006/06/29 22:01:17 rillig Exp $ .\" .\" Copyright (c) 1990, 1993 .\" The Regents of the University of California. All rights reserved. @@ -29,7 +29,7 @@ .\" .\" from: @(#)make.1 8.4 (Berkeley) 3/19/94 .\" -.Dd March 18, 2006 +.Dd June 29, 2006 .Dt MAKE 1 .Os .Sh NAME @@ -1574,13 +1574,16 @@ It is typically identical to The flag to pass the shell to enable error checking. .It Ar echoFlag The flag to pass the shell to enable command echoing. +.It Ar newline +The string literal to pass the shell that results in a single newline +character when used outside of any quoting characters. .El Example: .Bd -literal \&.SHELL: name=ksh path=/bin/ksh hasErrCtl=true \\ check="set -e" ignore="set +e" \\ echo="set -v" quiet="set +v" filter="set +v" \\ - echoFlag=v errFlag=e + echoFlag=v errFlag=e newline="'\\n'" .Ed .It Ic .SILENT Apply the diff --git a/usr.bin/make/var.c b/usr.bin/make/var.c index 5c909c154b8..d6f8b4e1f91 100644 --- a/usr.bin/make/var.c +++ b/usr.bin/make/var.c @@ -1,4 +1,4 @@ -/* $NetBSD: var.c,v 1.110 2006/05/19 17:29:01 christos Exp $ */ +/* $NetBSD: var.c,v 1.111 2006/06/29 22:01:17 rillig Exp $ */ /* * Copyright (c) 1988, 1989, 1990, 1993 @@ -69,14 +69,14 @@ */ #ifndef MAKE_NATIVE -static char rcsid[] = "$NetBSD: var.c,v 1.110 2006/05/19 17:29:01 christos Exp $"; +static char rcsid[] = "$NetBSD: var.c,v 1.111 2006/06/29 22:01:17 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.110 2006/05/19 17:29:01 christos Exp $"); +__RCSID("$NetBSD: var.c,v 1.111 2006/06/29 22:01:17 rillig Exp $"); #endif #endif /* not lint */ #endif @@ -134,6 +134,7 @@ __RCSID("$NetBSD: var.c,v 1.110 2006/05/19 17:29:01 christos Exp $"); #include "make.h" #include "buf.h" #include "dir.h" +#include "job.h" /* * This is a harmless return value for Var_Parse that can be used by Var_Subst @@ -1835,12 +1836,19 @@ VarQuote(char *str) Buffer buf; /* This should cover most shells :-( */ static char meta[] = "\n \t'`\";&<>()|*?{}[]\\$!#^~"; + const char *newline; + + newline = Shell_GetNewline(); buf = Buf_Init(MAKE_BSIZE); for (; *str; str++) { - if (strchr(meta, *str) != NULL) - Buf_AddByte(buf, (Byte)'\\'); - Buf_AddByte(buf, (Byte)*str); + if (*str == '\n' && newline != NULL) { + Buf_AddBytes(buf, strlen(newline), newline); + } else { + if (strchr(meta, *str) != NULL) + Buf_AddByte(buf, (Byte)'\\'); + Buf_AddByte(buf, (Byte)*str); + } } Buf_AddByte(buf, (Byte)'\0'); str = (char *)Buf_GetAll(buf, NULL); @@ -2016,7 +2024,7 @@ ApplyModifiers(char *nstr, const char *tstr, v, ctxt, err, &used, freePtr); if (nstr == var_Error || (nstr == varNoError && err == 0) - || strlen(rval) != used) { + || strlen(rval) != (size_t) used) { if (freeIt) free(freeIt); goto out; /* error already reported */ |
