summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorOri Bernstein <ori@eigenstate.org>2021-06-22 23:40:11 +0000
committerOri Bernstein <ori@eigenstate.org>2021-06-22 23:40:11 +0000
commit577033228209f28350dc3f75ef9d4ce88dfdf190 (patch)
tree7540037c6ffd83810da4209abbdd6879a484e075
parentce73821f3575921e24f839b21c7be60520a9dc42 (diff)
downloadplan9front-577033228209f28350dc3f75ef9d4ce88dfdf190.tar.xz
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.
-rw-r--r--sys/src/cmd/rc/code.c2
-rw-r--r--sys/src/cmd/rc/exec.c5
-rw-r--r--sys/src/cmd/rc/exec.h1
-rw-r--r--sys/src/cmd/rc/lex.c3
-rw-r--r--sys/src/cmd/rc/plan9.c2
-rw-r--r--sys/src/cmd/rc/rc.h1
-rw-r--r--sys/src/cmd/rc/simple.c3
-rw-r--r--sys/src/cmd/rc/tree.c2
8 files changed, 9 insertions, 10 deletions
diff --git a/sys/src/cmd/rc/code.c b/sys/src/cmd/rc/code.c
index d85a12260..89cc43183 100644
--- a/sys/src/cmd/rc/code.c
+++ b/sys/src/cmd/rc/code.c
@@ -184,7 +184,7 @@ outcode(tree *t, int eflag)
emits(strdup(f));
}
emitf(Xsrcline);
- emiti(lexline);
+ emiti(runq->lexline);
outcode(c1, eflag);
emitf(Xunlocal); /* get rid of $* */
emitf(Xreturn);
diff --git a/sys/src/cmd/rc/exec.c b/sys/src/cmd/rc/exec.c
index 04b3a4120..bbb13a17c 100644
--- a/sys/src/cmd/rc/exec.c
+++ b/sys/src/cmd/rc/exec.c
@@ -23,7 +23,7 @@ start(code *c, int pc, var *local)
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 @@ main(int argc, char *argv[])
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 @@ Xrdcmds(void)
{
struct thread *p = runq;
word *prompt;
+
flush(err);
nerror = 0;
if(flag['s'] && !truestatus())
diff --git a/sys/src/cmd/rc/exec.h b/sys/src/cmd/rc/exec.h
index 7975596bd..1d07b58d5 100644
--- a/sys/src/cmd/rc/exec.h
+++ b/sys/src/cmd/rc/exec.h
@@ -49,6 +49,7 @@ struct thread{
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? */
diff --git a/sys/src/cmd/rc/lex.c b/sys/src/cmd/rc/lex.c
index 52ded7769..3462bed69 100644
--- a/sys/src/cmd/rc/lex.c
+++ b/sys/src/cmd/rc/lex.c
@@ -28,7 +28,6 @@ int incomm;
int lastc;
int ndot;
int nerror;
-int lexline;
int nlexpath;
int lexpathsz;
@@ -53,7 +52,7 @@ advance(void)
lastc = future;
future = EOF;
if(c == '\n')
- lexline++;
+ runq->lexline++;
return c;
}
/*
diff --git a/sys/src/cmd/rc/plan9.c b/sys/src/cmd/rc/plan9.c
index 634570c26..fb375b270 100644
--- a/sys/src/cmd/rc/plan9.c
+++ b/sys/src/cmd/rc/plan9.c
@@ -166,8 +166,8 @@ Xrdfn(void)
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));
diff --git a/sys/src/cmd/rc/rc.h b/sys/src/cmd/rc/rc.h
index 165f044e3..87bc5c8a9 100644
--- a/sys/src/cmd/rc/rc.h
+++ b/sys/src/cmd/rc/rc.h
@@ -132,7 +132,6 @@ extern char **argp;
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?
diff --git a/sys/src/cmd/rc/simple.c b/sys/src/cmd/rc/simple.c
index 3987dbe5a..661533b97 100644
--- a/sys/src/cmd/rc/simple.c
+++ b/sys/src/cmd/rc/simple.c
@@ -364,13 +364,12 @@ execdot(void)
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 */
diff --git a/sys/src/cmd/rc/tree.c b/sys/src/cmd/rc/tree.c
index 557d14d6c..ce9fd152a 100644
--- a/sys/src/cmd/rc/tree.c
+++ b/sys/src/cmd/rc/tree.c
@@ -16,7 +16,7 @@ newtree(void)
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;
}