ref: 577033228209f28350dc3f75ef9d4ce88dfdf190
parent: ce73821f3575921e24f839b21c7be60520a9dc42
author: Ori Bernstein <[email protected]>
date: Tue Jun 22 19:40:11 EDT 2021
rc: correct line numbers When loading a file using ".", we could end up with our line numbers thrown off due to the mutation of lexline. Putting lexline into the runq beside the file that we're reading from causes it to get pushed and popped correctly, so that we no longer lose track of our location.
--- a/sys/src/cmd/rc/code.c
+++ b/sys/src/cmd/rc/code.c
@@ -184,7 +184,7 @@
emits(strdup(f));
}
emitf(Xsrcline);
- emiti(lexline);
+ emiti(runq->lexline);
outcode(c1, eflag);
emitf(Xunlocal); /* get rid of $* */
emitf(Xreturn);
--- a/sys/src/cmd/rc/exec.c
+++ b/sys/src/cmd/rc/exec.c
@@ -23,7 +23,7 @@
p->cmdfd = 0;
p->eof = 0;
p->iflag = 0;
- p->lineno = 1;
+ p->lineno = runq ? runq->lineno : 1;
p->ret = runq;
runq = p;
}
@@ -203,12 +203,12 @@
bootstrap[i].i = 0;
start(bootstrap, 1, (var *)0);
runq->cmdfile = strdup("rc");
+ runq->lexline = 0;
/* prime bootstrap argv */
pushlist();
argv0 = estrdup(argv[0]);
for(i = argc-1;i!=0;--i) pushword(argv[i]);
- lexline = 0;
for(;;){
if(flag['r'])
@@ -922,6 +922,7 @@
{
struct thread *p = runq;
word *prompt;
+
flush(err);
nerror = 0;
if(flag['s'] && !truestatus())
--- a/sys/src/cmd/rc/exec.h
+++ b/sys/src/cmd/rc/exec.h
@@ -49,6 +49,7 @@
var *local; /* list of local variables */
char *cmdfile; /* file name in Xrdcmd */
io *cmdfd; /* file descriptor for Xrdcmd */
+ int lexline; /* file descriptor line */
int iflast; /* static `if not' checking */
int eof; /* is cmdfd at eof? */
int iflag; /* interactive? */
--- a/sys/src/cmd/rc/lex.c
+++ b/sys/src/cmd/rc/lex.c
@@ -28,7 +28,6 @@
int lastc;
int ndot;
int nerror;
-int lexline;
int nlexpath;
int lexpathsz;
@@ -53,7 +52,7 @@
lastc = future;
future = EOF;
if(c == '\n')
- lexline++;
+ runq->lexline++;
return c;
}
/*
--- a/sys/src/cmd/rc/plan9.c
+++ b/sys/src/cmd/rc/plan9.c
@@ -166,8 +166,8 @@
else {
free(runq->cmdfile);
int f = open(runq->argv->words->word, 0);
- lexline = 0;
runq->cmdfile = strdup(runq->argv->words->word);
+ runq->lexline = 1;
runq->pc--;
popword();
if(f>=0) execcmds(openfd(f));
--- a/sys/src/cmd/rc/rc.h
+++ b/sys/src/cmd/rc/rc.h
@@ -132,7 +132,6 @@
extern char **args;
extern int nerror; /* number of errors encountered during compilation */
extern int doprompt; /* is it time for a prompt? */
-extern int lexline;
/*
* Which fds are the reading/writing end of a pipe?
--- a/sys/src/cmd/rc/simple.c
+++ b/sys/src/cmd/rc/simple.c
@@ -364,13 +364,12 @@
return;
}
- lexline = 1;
-
/* set up for a new command loop */
start(dotcmds, 1, (struct var *)0);
pushredir(RCLOSE, fd, 0);
runq->cmdfile = zero;
runq->cmdfd = openfd(fd);
+ runq->lexline = 1;
runq->iflag = iflag;
runq->iflast = 0;
/* push $* value */
--- a/sys/src/cmd/rc/tree.c
+++ b/sys/src/cmd/rc/tree.c
@@ -16,7 +16,7 @@
t->str = 0;
t->child[0] = t->child[1] = t->child[2] = 0;
t->next = treenodes;
- t->line = lexline;
+ t->line = runq->lexline;
treenodes = t;
return t;
}