backpedal with $'…' and $"…" interpolation

it turns out this breaks more legacy scripts than anticipated
This commit is contained in:
tg 2013-02-17 05:40:17 +00:00
parent 47f8a21e3c
commit b684a7c6bd
6 changed files with 50 additions and 36 deletions

View File

@ -1,5 +1,5 @@
#!/bin/sh
srcversion='$MirOS: src/bin/mksh/Build.sh,v 1.618 2013/02/16 17:55:51 tg Exp $'
srcversion='$MirOS: src/bin/mksh/Build.sh,v 1.619 2013/02/17 05:40:11 tg Exp $'
#-
# Copyright (c) 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010,
# 2011, 2012, 2013
@ -1529,7 +1529,7 @@ else
#define EXTERN
#define MKSH_INCLUDES_ONLY
#include "sh.h"
__RCSID("$MirOS: src/bin/mksh/Build.sh,v 1.618 2013/02/16 17:55:51 tg Exp $");
__RCSID("$MirOS: src/bin/mksh/Build.sh,v 1.619 2013/02/17 05:40:11 tg Exp $");
int main(void) { printf("Hello, World!\n"); return (0); }
EOF
case $cm in
@ -2126,7 +2126,7 @@ addsrcs USE_PRINTF_BUILTIN printf.c
test 1 = "$USE_PRINTF_BUILTIN" && add_cppflags -DMKSH_PRINTF_BUILTIN
test 1 = "$HAVE_CAN_VERB" && CFLAGS="$CFLAGS -verbose"
test -n "$LDSTATIC" && add_cppflags -DMKSH_OPTSTATIC
add_cppflags -DMKSH_BUILD_R=429
add_cppflags -DMKSH_BUILD_R=430
$e $bi$me: Finished configuration testing, now producing output.$ao

View File

@ -1,7 +1,7 @@
# $MirOS: src/bin/mksh/Makefile,v 1.110 2013/02/16 00:21:56 tg Exp $
# $MirOS: src/bin/mksh/Makefile,v 1.111 2013/02/17 05:40:12 tg Exp $
#-
# Copyright (c) 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010,
# 2011, 2012
# 2011, 2012, 2013
# Thorsten Glaser <tg@mirbsd.org>
#
# Provided that these terms and disclaimer and all copyright notices
@ -55,7 +55,7 @@ CPPFLAGS+= -DMKSH_ASSUME_UTF8 -DMKSH_DISABLE_DEPRECATED \
-DHAVE_STRLCPY=1 -DHAVE_FLOCK_DECL=1 -DHAVE_REVOKE_DECL=1 \
-DHAVE_SYS_ERRLIST_DECL=1 -DHAVE_SYS_SIGLIST_DECL=1 \
-DHAVE_PERSISTENT_HISTORY=1 -DHAVE_SILENT_IDIVWRAPV=0 \
-DMKSH_BUILD_R=429
-DMKSH_BUILD_R=430
CPPFLAGS+= -D${${PROG:L}_tf:C/(Mir${MAN:E}{0,1}){2}/4/:S/x/mksh_BUILD/:U}
COPTS+= -std=c99 -Wall
.endif

37
check.t
View File

@ -1,4 +1,4 @@
# $MirOS: src/bin/mksh/check.t,v 1.594 2013/02/15 18:50:11 tg Exp $
# $MirOS: src/bin/mksh/check.t,v 1.595 2013/02/17 05:40:13 tg Exp $
# $OpenBSD: bksl-nl.t,v 1.2 2001/01/28 23:04:56 niklas Exp $
# $OpenBSD: history.t,v 1.5 2001/01/28 23:04:56 niklas Exp $
# $OpenBSD: read.t,v 1.3 2003/03/10 03:48:16 david Exp $
@ -29,7 +29,7 @@
# http://www.freebsd.org/cgi/cvsweb.cgi/src/tools/regression/bin/test/regress.sh?rev=HEAD
expected-stdout:
@(#)MIRBSD KSH R42 2013/02/15
@(#)MIRBSD KSH R43 2013/02/16
description:
Check version of shell.
stdin:
@ -38,7 +38,7 @@ name: KSH_VERSION
category: shell:legacy-no
---
expected-stdout:
@(#)LEGACY KSH R42 2013/02/15
@(#)LEGACY KSH R43 2013/02/16
description:
Check version of legacy shell.
stdin:
@ -7688,25 +7688,19 @@ expected-stdout:
00000070 EF BF BD 0A C4 A3 0A 66 - 6E 0A 13 34 0A 9C 0A 9C |.......fn..4....|
00000080 35 0A 01 0A 01 0A 7F 0A - 02 82 AC 0A 61 0A 62 0A |5...........a.b.|
---
name: dollar-quotes-in-heredocs
name: dollar-quotes-in-heredocs-strings
description:
They are, however, not parsed in here documents
They are, however, not parsed in here documents, here strings
(outside of string delimiters) or regular strings, but in
parameter substitutions.
stdin:
cat <<EOF
dollar = strchr(s, '$'); /* ' */
foo " bar \" baz
EOF
cat <<$'a\tb'
a\tb
a b
expected-stdout:
dollar = strchr(s, '$'); /* ' */
a\tb
---
name: dollar-quotes-in-herestrings
description:
On the other hand, they are parsed in here strings and
parameter substitutions
stdin:
cat <<<"dollar = strchr(s, '$'); /* ' */"
cat <<<'dollar = strchr(s, '\''$'\''); /* '\'' */'
x="dollar = strchr(s, '$'); /* ' */"
@ -7714,16 +7708,25 @@ stdin:
cat <<<$'a\E[0m\tb'
unset nl; print -r -- "x${nl:=$'\n'}y"
echo "1 foo\"bar"
# cf & HEREDOC
cat <<EOF
2 foo\"bar
EOF
# probably never reached for here strings?
cat <<<"3 foo\"bar"
cat <<<"4 foo\\\"bar"
cat <<<'5 foo\"bar'
# old scripts use this (e.g. ncurses)
echo "^$"
# make sure this works, outside of quotes
cat <<<'7'$'\t''.'
expected-stdout:
dollar = strchr(s, '); /* */
dollar = strchr(s, '$'); /* ' */
foo " bar \" baz
a\tb
dollar = strchr(s, '$'); /* ' */
dollar = strchr(s, '$'); /* ' */
dollar = strchr(s, '$'); /* ' */
dollar = strchr(s, '); /* */
a b
x
y
@ -7732,6 +7735,8 @@ expected-stdout:
3 foo"bar
4 foo\"bar
5 foo\"bar
^$
7 .
---
name: dot-needs-argument
description:

6
exec.c
View File

@ -23,7 +23,7 @@
#include "sh.h"
__RCSID("$MirOS: src/bin/mksh/exec.c,v 1.115 2013/02/15 18:50:13 tg Exp $");
__RCSID("$MirOS: src/bin/mksh/exec.c,v 1.116 2013/02/17 05:40:15 tg Exp $");
#ifndef MKSH_DEFAULT_EXECSHELL
#define MKSH_DEFAULT_EXECSHELL "/bin/sh"
@ -1481,9 +1481,7 @@ herein(struct ioword *iop, char **resbuf)
}
/* lexer substitution flags */
i = (iop->flag & IOEVAL) ?
(ONEWORD | ((iop->flag & IOHERESTR) ? HERESTRBODY : HEREDOCBODY)) :
0;
i = (iop->flag & IOEVAL) ? (ONEWORD | HEREDOC) : 0;
/* skip all the fd setup if we just want the value */
if (resbuf != NULL)

22
lex.c
View File

@ -23,7 +23,7 @@
#include "sh.h"
__RCSID("$MirOS: src/bin/mksh/lex.c,v 1.179 2013/02/10 17:18:48 tg Exp $");
__RCSID("$MirOS: src/bin/mksh/lex.c,v 1.180 2013/02/17 05:40:16 tg Exp $");
/*
* states while lexing word
@ -359,7 +359,7 @@ yylex(int cf)
c = getsc();
switch (c) {
case '"':
if ((cf & (HEREDOCBODY | HERESTRBODY)))
if ((cf & HEREDOC))
goto heredocquote;
/* FALLTHROUGH */
case '\\':
@ -504,15 +504,27 @@ yylex(int cf)
*wp++ = '\0';
*wp++ = CSUBST;
*wp++ = 'X';
} else if (c == '\'' && !(cf & HEREDOCBODY)) {
} else if (c == '\'' || c == '"') {
switch (state) {
/*
* states in which $''/$"" are
* invalid; still not too sure about
* which must be included/excluded
*/
case SWORD:
case SDQUOTE:
goto DNQUOTE;
}
if (c == '"')
goto DEQUOTE;
/* c == '\'' */
*wp++ = OQUOTE;
ignore_backslash_newline++;
PUSH_STATE(SEQUOTE);
statep->ls_bool = false;
break;
} else if (c == '"' && !(cf & HEREDOCBODY)) {
goto DEQUOTE;
} else {
DNQUOTE:
*wp++ = CHAR;
*wp++ = '$';
DEQUOTE:

9
sh.h
View File

@ -164,9 +164,9 @@
#endif
#ifdef EXTERN
__RCSID("$MirOS: src/bin/mksh/sh.h,v 1.636 2013/02/16 00:21:57 tg Exp $");
__RCSID("$MirOS: src/bin/mksh/sh.h,v 1.637 2013/02/17 05:40:17 tg Exp $");
#endif
#define MKSH_VERSION "R42 2013/02/15"
#define MKSH_VERSION "R43 2013/02/16"
/* arithmetic types: C implementation */
#if !HAVE_CAN_INTTYPES
@ -511,7 +511,7 @@ char *ucstrstr(char *, const char *);
#define mkssert(e) do { } while (/* CONSTCOND */ 0)
#endif
#if (!defined(MKSH_BUILDMAKEFILE4BSD) && !defined(MKSH_BUILDSH)) || (MKSH_BUILD_R != 429)
#if (!defined(MKSH_BUILDMAKEFILE4BSD) && !defined(MKSH_BUILDSH)) || (MKSH_BUILD_R != 430)
#error Must run Build.sh to compile this.
int
im_sorry_dave(void)
@ -1584,8 +1584,7 @@ typedef union {
#define CMDWORD BIT(8) /* parsing simple command (alias related) */
#define HEREDELIM BIT(9) /* parsing <<,<<- delimiter */
#define LQCHAR BIT(10) /* source string contains QCHAR */
#define HEREDOCBODY BIT(11) /* parsing a here document body */
#define HERESTRBODY BIT(12) /* parsing a here string body */
#define HEREDOC BIT(11) /* parsing a here document body */
#define HERES 10 /* max number of << in line */