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.
This commit is contained in:
Ori Bernstein 2021-06-22 23:40:11 +00:00
parent ce73821f35
commit 5770332282
8 changed files with 9 additions and 10 deletions

View file

@ -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);

View file

@ -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())

View file

@ -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? */

View file

@ -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;
}
/*

View file

@ -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));

View file

@ -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?

View file

@ -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 */

View file

@ -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;
}