aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRocky Bernstein <rocky.bernstein@gmail.com>2009-08-11 15:59:33 +1000
committermaximilian attems <max@stro.at>2010-03-22 00:29:17 +0100
commit96ecdb25ae8951c5a0720f38cc5b8322681b2eaf (patch)
tree6b19de5ec5f5686d39bc8f18e73d8681ac397703
parent3c3f2c117ed578505e6d264b23f1eb50d8ff4be4 (diff)
downloadklibc-96ecdb25ae8951c5a0720f38cc5b8322681b2eaf.tar.gz
[klibc] [SHELL] Add preliminary LINENO support
Looks like in contrast to what the dash.1 manual page says, expansion of PS{1,2,4} does work. Here is a little patch to set LINENO. The ways in that it is less than ideal mirror the ways that the line number error reporting is also less than ideal. For example if you run this: ( x=$((1/0)) # Just to add another line # And another ) # error reports this line The error reported will be the closing parenthesis even though I think most people would prefer the error to be the one where x was set. Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au> Signed-off-by: maximilian attems <max@stro.at>
-rw-r--r--usr/dash/input.c10
-rw-r--r--usr/dash/input.h1
-rw-r--r--usr/dash/parser.c12
-rw-r--r--usr/dash/var.c1
4 files changed, 18 insertions, 6 deletions
diff --git a/usr/dash/input.c b/usr/dash/input.c
index 1e198e9ebd259..e57ad761485c4 100644
--- a/usr/dash/input.c
+++ b/usr/dash/input.c
@@ -53,6 +53,7 @@
#include "alias.h"
#include "parser.h"
#include "main.h"
+#include "var.h"
#ifndef SMALL
#include "myhistedit.h"
#endif
@@ -528,3 +529,12 @@ closescript(void)
parsefile->fd = 0;
}
}
+
+
+int lineno_inc(void)
+{
+ int lineno = plinno++;
+
+ setvarint("LINENO", lineno, 0);
+ return lineno;
+}
diff --git a/usr/dash/input.h b/usr/dash/input.h
index 50a77971ebfdf..bdf8857b4b17c 100644
--- a/usr/dash/input.h
+++ b/usr/dash/input.h
@@ -61,6 +61,7 @@ void setinputstring(char *);
void popfile(void);
void popallfiles(void);
void closescript(void);
+int lineno_inc(void);
#define pgetc_macro() \
(--parsenleft >= 0 ? (signed char)*parsenextc++ : preadbuffer())
diff --git a/usr/dash/parser.c b/usr/dash/parser.c
index 28a46c01e1bb4..be20ff735498b 100644
--- a/usr/dash/parser.c
+++ b/usr/dash/parser.c
@@ -776,7 +776,7 @@ xxreadtoken(void)
continue;
case '\\':
if (pgetc() == '\n') {
- startlinno = ++plinno;
+ startlinno = lineno_inc();
if (doprompt)
setprompt(2);
continue;
@@ -784,7 +784,7 @@ xxreadtoken(void)
pungetc();
goto breakloop;
case '\n':
- plinno++;
+ lineno_inc();
needprompt = doprompt;
RETURN(TNL);
case PEOF:
@@ -886,7 +886,7 @@ readtoken1(int firstc, char const *syntax, char *eofmark, int striptabs)
if (syntax == BASESYNTAX)
goto endword; /* exit outer loop */
USTPUTC(c, out);
- plinno++;
+ lineno_inc();
if (doprompt)
setprompt(2);
c = pgetc();
@@ -1065,7 +1065,7 @@ checkend: {
if (c == '\n' || c == PEOF) {
c = PEOF;
- plinno++;
+ lineno_inc();
needprompt = doprompt;
} else {
int len;
@@ -1315,7 +1315,7 @@ parsebackq: {
case '\\':
if ((pc = pgetc()) == '\n') {
- plinno++;
+ lineno_inc();
if (doprompt)
setprompt(2);
/*
@@ -1340,7 +1340,7 @@ parsebackq: {
synerror("EOF in backquote substitution");
case '\n':
- plinno++;
+ lineno_inc();
needprompt = doprompt;
break;
diff --git a/usr/dash/var.c b/usr/dash/var.c
index 7f9af9c613e24..2737fb116bb47 100644
--- a/usr/dash/var.c
+++ b/usr/dash/var.c
@@ -90,6 +90,7 @@ struct var varinit[] = {
{ 0, VSTRFIXED|VTEXTFIXED, "PS2=> ", 0 },
{ 0, VSTRFIXED|VTEXTFIXED, "PS4=+ ", 0 },
{ 0, VSTRFIXED|VTEXTFIXED, "OPTIND=1", getoptsreset },
+ { 0, VSTRFIXED|VTEXTFIXED, "LINENO=1", 0 },
#ifndef SMALL
{ 0, VSTRFIXED|VTEXTFIXED|VUNSET, "TERM\0", 0 },
{ 0, VSTRFIXED|VTEXTFIXED|VUNSET, "HISTSIZE\0", sethistsize },