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:
parent
ce73821f35
commit
5770332282
8 changed files with 9 additions and 10 deletions
|
@ -184,7 +184,7 @@ outcode(tree *t, int eflag)
|
||||||
emits(strdup(f));
|
emits(strdup(f));
|
||||||
}
|
}
|
||||||
emitf(Xsrcline);
|
emitf(Xsrcline);
|
||||||
emiti(lexline);
|
emiti(runq->lexline);
|
||||||
outcode(c1, eflag);
|
outcode(c1, eflag);
|
||||||
emitf(Xunlocal); /* get rid of $* */
|
emitf(Xunlocal); /* get rid of $* */
|
||||||
emitf(Xreturn);
|
emitf(Xreturn);
|
||||||
|
|
|
@ -23,7 +23,7 @@ start(code *c, int pc, var *local)
|
||||||
p->cmdfd = 0;
|
p->cmdfd = 0;
|
||||||
p->eof = 0;
|
p->eof = 0;
|
||||||
p->iflag = 0;
|
p->iflag = 0;
|
||||||
p->lineno = 1;
|
p->lineno = runq ? runq->lineno : 1;
|
||||||
p->ret = runq;
|
p->ret = runq;
|
||||||
runq = p;
|
runq = p;
|
||||||
}
|
}
|
||||||
|
@ -203,12 +203,12 @@ main(int argc, char *argv[])
|
||||||
bootstrap[i].i = 0;
|
bootstrap[i].i = 0;
|
||||||
start(bootstrap, 1, (var *)0);
|
start(bootstrap, 1, (var *)0);
|
||||||
runq->cmdfile = strdup("rc");
|
runq->cmdfile = strdup("rc");
|
||||||
|
runq->lexline = 0;
|
||||||
/* prime bootstrap argv */
|
/* prime bootstrap argv */
|
||||||
pushlist();
|
pushlist();
|
||||||
argv0 = estrdup(argv[0]);
|
argv0 = estrdup(argv[0]);
|
||||||
for(i = argc-1;i!=0;--i) pushword(argv[i]);
|
for(i = argc-1;i!=0;--i) pushword(argv[i]);
|
||||||
|
|
||||||
lexline = 0;
|
|
||||||
|
|
||||||
for(;;){
|
for(;;){
|
||||||
if(flag['r'])
|
if(flag['r'])
|
||||||
|
@ -922,6 +922,7 @@ Xrdcmds(void)
|
||||||
{
|
{
|
||||||
struct thread *p = runq;
|
struct thread *p = runq;
|
||||||
word *prompt;
|
word *prompt;
|
||||||
|
|
||||||
flush(err);
|
flush(err);
|
||||||
nerror = 0;
|
nerror = 0;
|
||||||
if(flag['s'] && !truestatus())
|
if(flag['s'] && !truestatus())
|
||||||
|
|
|
@ -49,6 +49,7 @@ struct thread{
|
||||||
var *local; /* list of local variables */
|
var *local; /* list of local variables */
|
||||||
char *cmdfile; /* file name in Xrdcmd */
|
char *cmdfile; /* file name in Xrdcmd */
|
||||||
io *cmdfd; /* file descriptor for Xrdcmd */
|
io *cmdfd; /* file descriptor for Xrdcmd */
|
||||||
|
int lexline; /* file descriptor line */
|
||||||
int iflast; /* static `if not' checking */
|
int iflast; /* static `if not' checking */
|
||||||
int eof; /* is cmdfd at eof? */
|
int eof; /* is cmdfd at eof? */
|
||||||
int iflag; /* interactive? */
|
int iflag; /* interactive? */
|
||||||
|
|
|
@ -28,7 +28,6 @@ int incomm;
|
||||||
int lastc;
|
int lastc;
|
||||||
int ndot;
|
int ndot;
|
||||||
int nerror;
|
int nerror;
|
||||||
int lexline;
|
|
||||||
int nlexpath;
|
int nlexpath;
|
||||||
int lexpathsz;
|
int lexpathsz;
|
||||||
|
|
||||||
|
@ -53,7 +52,7 @@ advance(void)
|
||||||
lastc = future;
|
lastc = future;
|
||||||
future = EOF;
|
future = EOF;
|
||||||
if(c == '\n')
|
if(c == '\n')
|
||||||
lexline++;
|
runq->lexline++;
|
||||||
return c;
|
return c;
|
||||||
}
|
}
|
||||||
/*
|
/*
|
||||||
|
|
|
@ -166,8 +166,8 @@ Xrdfn(void)
|
||||||
else {
|
else {
|
||||||
free(runq->cmdfile);
|
free(runq->cmdfile);
|
||||||
int f = open(runq->argv->words->word, 0);
|
int f = open(runq->argv->words->word, 0);
|
||||||
lexline = 0;
|
|
||||||
runq->cmdfile = strdup(runq->argv->words->word);
|
runq->cmdfile = strdup(runq->argv->words->word);
|
||||||
|
runq->lexline = 1;
|
||||||
runq->pc--;
|
runq->pc--;
|
||||||
popword();
|
popword();
|
||||||
if(f>=0) execcmds(openfd(f));
|
if(f>=0) execcmds(openfd(f));
|
||||||
|
|
|
@ -132,7 +132,6 @@ extern char **argp;
|
||||||
extern char **args;
|
extern char **args;
|
||||||
extern int nerror; /* number of errors encountered during compilation */
|
extern int nerror; /* number of errors encountered during compilation */
|
||||||
extern int doprompt; /* is it time for a prompt? */
|
extern int doprompt; /* is it time for a prompt? */
|
||||||
extern int lexline;
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Which fds are the reading/writing end of a pipe?
|
* Which fds are the reading/writing end of a pipe?
|
||||||
|
|
|
@ -364,13 +364,12 @@ execdot(void)
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
lexline = 1;
|
|
||||||
|
|
||||||
/* set up for a new command loop */
|
/* set up for a new command loop */
|
||||||
start(dotcmds, 1, (struct var *)0);
|
start(dotcmds, 1, (struct var *)0);
|
||||||
pushredir(RCLOSE, fd, 0);
|
pushredir(RCLOSE, fd, 0);
|
||||||
runq->cmdfile = zero;
|
runq->cmdfile = zero;
|
||||||
runq->cmdfd = openfd(fd);
|
runq->cmdfd = openfd(fd);
|
||||||
|
runq->lexline = 1;
|
||||||
runq->iflag = iflag;
|
runq->iflag = iflag;
|
||||||
runq->iflast = 0;
|
runq->iflast = 0;
|
||||||
/* push $* value */
|
/* push $* value */
|
||||||
|
|
|
@ -16,7 +16,7 @@ newtree(void)
|
||||||
t->str = 0;
|
t->str = 0;
|
||||||
t->child[0] = t->child[1] = t->child[2] = 0;
|
t->child[0] = t->child[1] = t->child[2] = 0;
|
||||||
t->next = treenodes;
|
t->next = treenodes;
|
||||||
t->line = lexline;
|
t->line = runq->lexline;
|
||||||
treenodes = t;
|
treenodes = t;
|
||||||
return t;
|
return t;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue