summary refs log tree commit diff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/input.c10
-rw-r--r--src/input.h1
-rw-r--r--src/parser.c12
-rw-r--r--src/var.c1
4 files changed, 18 insertions, 6 deletions
diff --git a/src/input.c b/src/input.c
index 1e198e9..e57ad76 100644
--- a/src/input.c
+++ b/src/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/src/input.h b/src/input.h
index 50a7797..bdf8857 100644
--- a/src/input.h
+++ b/src/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/src/parser.c b/src/parser.c
index 28a46c0..be20ff7 100644
--- a/src/parser.c
+++ b/src/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/src/var.c b/src/var.c
index 7f9af9c..2737fb1 100644
--- a/src/var.c
+++ b/src/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 },