Zsh Mailing List Archive
Messages sorted by: Reverse Date, Date, Thread, Author

PATCH: LINENO (was: Re: PATCH: 3.0.6-pre-4: COLUMNS/LINES environment handling)



Peter Stephenson wrote:

> This is a non-sequitur, but while I was looking at the UNIX spec I noticed
> that LINENO, unlike LINES, is specified, and it says that functions as well
> as scripts should have it set.  You'll find out that with autoloaded
> functions you always get 0 from `print $LINENO' (the question of why is not
> entirely trivial).  I've known about this for ages, but the ways I thought
> about fixing it at the time were rather gross.  But maybe someone's little
> grey cells...

Hm. This looks almost too simple, but it seems to work.

The patch adds a INP_* flag which says that linno should be updated
even when parsing a string. Then it changes parse_string() to accept
an argument to switch on line numbering and the places where this is
called.

Have I missed something?

Bye
 Sven

diff -u -r os/Modules/parameter.c Src/Modules/parameter.c
--- os/Modules/parameter.c	Thu Jun 17 13:05:42 1999
+++ Src/Modules/parameter.c	Thu Jun 17 13:05:53 1999
@@ -326,7 +326,7 @@
     val = metafy(val, strlen(val), META_REALLOC);
 
     HEAPALLOC {
-	list = parse_string(val);
+	list = parse_string(val, 1);
     } LASTALLOC;
 
     if (!list || list == &dummy_list) {
diff -u -r os/builtin.c Src/builtin.c
--- os/builtin.c	Thu Jun 17 09:10:04 1999
+++ Src/builtin.c	Thu Jun 17 13:04:33 1999
@@ -3618,7 +3618,7 @@
     arg = *argv++;
     if (!*arg)
 	l = NULL;
-    else if (!(l = parse_string(arg))) {
+    else if (!(l = parse_string(arg, 1))) {
 	zwarnnam(name, "couldn't parse trap command", NULL, 0);
 	return 1;
     }
diff -u -r os/exec.c Src/exec.c
--- os/exec.c	Wed Jun 16 10:31:32 1999
+++ Src/exec.c	Thu Jun 17 13:05:06 1999
@@ -133,14 +133,20 @@
 
 /**/
 List
-parse_string(char *s)
+parse_string(char *s, int ln)
 {
     List l;
+    int oldlineno = lineno;
 
     lexsave();
-    inpush(s, 0, NULL);
+    lineno = 1;
+    inpush(s, (ln ? INP_LINENO : 0), NULL);
     strinbeg(0);
+    if (ln)
+	lineno = 1;
     l = parse_list();
+    if (ln)
+	lineno = oldlineno;
     strinend();
     inpop();
     lexrestore();
@@ -678,7 +684,7 @@
     List list;
 
     pushheap();
-    if ((list = parse_string(s)))
+    if ((list = parse_string(s, 0)))
 	execlist(list, dont_change_job, exiting);
     popheap();
 }
@@ -2324,7 +2330,7 @@
     Cmd c;
     Redir r;
 
-    if (!(list = parse_string(cmd)))
+    if (!(list = parse_string(cmd, 0)))
 	return NULL;
     if (list != &dummy_list && !list->right && !list->left->flags &&
 	list->left->type == END && list->left->left->type == END &&
@@ -2453,7 +2459,7 @@
 	return NULL;
     }
     *str = '\0';
-    if (str[1] || !(list = parse_string(cmd + 2))) {
+    if (str[1] || !(list = parse_string(cmd + 2, 0))) {
 	zerr("parse error in process substitution", NULL, 0);
 	return NULL;
     }
@@ -3010,7 +3016,7 @@
 		    d[len] = '\0';
 		    d = metafy(d, len, META_REALLOC);
 		    HEAPALLOC {
-			r = parse_string(d);
+			r = parse_string(d, 1);
 		    } LASTALLOC;
 		    return r;
 		} else
diff -u -r os/input.c Src/input.c
--- os/input.c	Wed Jun 16 10:31:33 1999
+++ Src/input.c	Thu Jun 17 13:13:52 1999
@@ -186,6 +186,8 @@
 	    inbufct--;
 	    if (itok(lastc = STOUC(*inbufptr++)))
 		continue;
+	    if ((inbufflags & INP_LINENO) && lastc == '\n')
+		lineno++;
 	    return lastc;
 	}
 
@@ -359,6 +361,8 @@
 	    inbufptr--;
 	    inbufct++;
 	    inbufleft++;
+	    if ((inbufflags & INP_LINENO) && c == '\n')
+		lineno--;
 	}
 #ifdef DEBUG
         else if (!(inbufflags & INP_CONT)) {
diff -u -r os/zsh.h Src/zsh.h
--- os/zsh.h	Wed Jun 16 10:31:35 1999
+++ Src/zsh.h	Thu Jun 17 13:02:07 1999
@@ -226,6 +226,7 @@
 #define INP_HIST      (1<<2)	/* expanding history                       */
 #define INP_CONT      (1<<3)	/* continue onto previously stacked input  */
 #define INP_ALCONT    (1<<4)	/* stack is continued from alias expn.     */
+#define INP_LINENO    (1<<5)    /* update line number                      */
 
 /* Flags for metafy */
 #define META_REALLOC	0

--
Sven Wischnowsky                         wischnow@xxxxxxxxxxxxxxxxxxxxxxx



Messages sorted by: Reverse Date, Date, Thread, Author