Module Name: src
Committed By: christos
Date: Wed Oct 2 19:52:58 UTC 2013
Modified Files:
src/bin/sh: expand.c parser.c parser.h
Log Message:
add crude $LINENO support for FreeBSD
To generate a diff of this commit:
cvs rdiff -u -r1.88 -r1.89 src/bin/sh/expand.c
cvs rdiff -u -r1.83 -r1.84 src/bin/sh/parser.c
cvs rdiff -u -r1.17 -r1.18 src/bin/sh/parser.h
Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.
Modified files:
Index: src/bin/sh/expand.c
diff -u src/bin/sh/expand.c:1.88 src/bin/sh/expand.c:1.89
--- src/bin/sh/expand.c:1.88 Sat Dec 22 15:15:22 2012
+++ src/bin/sh/expand.c Wed Oct 2 15:52:58 2013
@@ -1,4 +1,4 @@
-/* $NetBSD: expand.c,v 1.88 2012/12/22 20:15:22 dsl Exp $ */
+/* $NetBSD: expand.c,v 1.89 2013/10/02 19:52:58 christos Exp $ */
/*-
* Copyright (c) 1991, 1993
@@ -37,7 +37,7 @@
#if 0
static char sccsid[] = "@(#)expand.c 8.5 (Berkeley) 5/15/95";
#else
-__RCSID("$NetBSD: expand.c,v 1.88 2012/12/22 20:15:22 dsl Exp $");
+__RCSID("$NetBSD: expand.c,v 1.89 2013/10/02 19:52:58 christos Exp $");
#endif
#endif /* not lint */
@@ -647,7 +647,12 @@ evalvar(char *p, int flag)
p = strchr(p, '=') + 1;
again: /* jump here after setting a variable with ${var=text} */
- if (special) {
+ if (varflags & VSLINENO) {
+ set = 1;
+ special = 0;
+ val = var;
+ p[-1] = '\0';
+ } else if (special) {
set = varisset(var, varflags & VSNUL);
val = NULL;
} else {
@@ -784,6 +789,7 @@ again: /* jump here after setting a vari
default:
abort();
}
+ p[-1] = '='; /* recover overwritten '=' */
if (apply_ifs)
recordregion(startloc, expdest - stackblock(),
Index: src/bin/sh/parser.c
diff -u src/bin/sh/parser.c:1.83 src/bin/sh/parser.c:1.84
--- src/bin/sh/parser.c:1.83 Sun Jun 17 16:48:27 2012
+++ src/bin/sh/parser.c Wed Oct 2 15:52:58 2013
@@ -1,4 +1,4 @@
-/* $NetBSD: parser.c,v 1.83 2012/06/17 20:48:27 wiz Exp $ */
+/* $NetBSD: parser.c,v 1.84 2013/10/02 19:52:58 christos Exp $ */
/*-
* Copyright (c) 1991, 1993
@@ -37,7 +37,7 @@
#if 0
static char sccsid[] = "@(#)parser.c 8.7 (Berkeley) 5/16/95";
#else
-__RCSID("$NetBSD: parser.c,v 1.83 2012/06/17 20:48:27 wiz Exp $");
+__RCSID("$NetBSD: parser.c,v 1.84 2013/10/02 19:52:58 christos Exp $");
#endif
#endif /* not lint */
@@ -100,6 +100,7 @@ union node *redirnode;
struct heredoc *heredoc;
int quoteflag; /* set if (part of) last token was quoted */
int startlinno; /* line # where last token started */
+int funclinno; /* line # where the current function started */
STATIC union node *list(int, int);
@@ -583,11 +584,13 @@ simplecmd(union node **rpp, union node *
/* We have a function */
if (readtoken() != TRP)
synexpect(TRP);
+ funclinno = plinno;
rmescapes(n->narg.text);
if (!goodname(n->narg.text))
synerror("Bad function name");
n->type = NDEFUN;
n->narg.next = command();
+ funclinno = 0;
goto checkneg;
} else {
tokpushback++;
@@ -1253,11 +1256,14 @@ parseredir: {
*/
parsesub: {
+ char buf[10];
int subtype;
int typeloc;
int flags;
char *p;
static const char types[] = "}-+?=";
+ int i;
+ int linno;
c = pgetc();
if (c != '(' && c != OPENBRACE && !is_name(c) && !is_special(c)) {
@@ -1275,6 +1281,7 @@ parsesub: {
typeloc = out - stackblock();
USTPUTC(VSNORMAL, out);
subtype = VSNORMAL;
+ flags = 0;
if (c == OPENBRACE) {
c = pgetc();
if (c == '#') {
@@ -1287,10 +1294,23 @@ parsesub: {
subtype = 0;
}
if (is_name(c)) {
+ p = out;
do {
STPUTC(c, out);
c = pgetc();
} while (is_in_name(c));
+ if (out - p == 6 && strncmp(p, "LINENO", 6) == 0) {
+ /* Replace the variable name with the
+ * current line number. */
+ linno = plinno;
+ if (funclinno != 0)
+ linno -= funclinno - 1;
+ snprintf(buf, sizeof(buf), "%d", linno);
+ STADJUST(-6, out);
+ for (i = 0; buf[i] != '\0'; i++)
+ STPUTC(buf[i], out);
+ flags |= VSLINENO;
+ }
} else if (is_digit(c)) {
do {
USTPUTC(c, out);
@@ -1305,11 +1325,10 @@ parsesub: {
badsub: synerror("Bad substitution");
STPUTC('=', out);
- flags = 0;
if (subtype == 0) {
switch (c) {
case ':':
- flags = VSNUL;
+ flags |= VSNUL;
c = pgetc();
/*FALLTHROUGH*/
default:
Index: src/bin/sh/parser.h
diff -u src/bin/sh/parser.h:1.17 src/bin/sh/parser.h:1.18
--- src/bin/sh/parser.h:1.17 Sat Jun 26 18:09:49 2004
+++ src/bin/sh/parser.h Wed Oct 2 15:52:58 2013
@@ -1,4 +1,4 @@
-/* $NetBSD: parser.h,v 1.17 2004/06/26 22:09:49 dsl Exp $ */
+/* $NetBSD: parser.h,v 1.18 2013/10/02 19:52:58 christos Exp $ */
/*-
* Copyright (c) 1991, 1993
@@ -49,9 +49,11 @@
#define CTL_LAST '\211' /* last 'special' character */
/* variable substitution byte (follows CTLVAR) */
-#define VSTYPE 0x0f /* type of variable substitution */
-#define VSNUL 0x10 /* colon--treat the empty string as unset */
-#define VSQUOTE 0x80 /* inside double quotes--suppress splitting */
+#define VSTYPE 0x0f /* type of variable substitution */
+#define VSNUL 0x10 /* colon--treat the empty string as unset */
+#define VSLINENO 0x20 /* expansion of $LINENO, the line number
+ follows immediately */
+#define VSQUOTE 0x80 /* inside double quotes--suppress splitting */
/* values of VSTYPE field */
#define VSNORMAL 0x1 /* normal variable: $var or ${var} */