ref: 60befe7df166ae7464c665394ba3793d9d26e184
parent: d1c0f53fcdff6d31a36f9d802133b721fc84be1a
author: glenda <glenda@cirno.localdomain>
date: Mon Feb 26 17:39:49 EST 2018
games/mix: fix incorrect line numbers
--- a/rc/bin/g
+++ b/rc/bin/g
@@ -14,7 +14,7 @@
exit usage
case 1
pattern=$1
- files=(`{ls *.[bcChlmsy] *.asm *.awk *.cc *.cgi *.cpp *.cs *.go *.goc *.java *.lx *.ms *.pl *.py *.rc *.tex *.xy >[2]/dev/null})
+ files=(`{ls *.[bcChlmsy] *.ml[iyl] *.ml *.asm *.awk *.cc *.cgi *.cpp *.cs *.go *.goc *.java *.lx *.ms *.pl *.py *.rc *.tex *.xy >[2]/dev/null})
case *
pattern=$1
shift
--- a/sys/src/games/mix/mix.c
+++ b/sys/src/games/mix/mix.c
@@ -320,6 +320,14 @@
return r;
}
+void
+ungetr(Rune r)
+{
+ if(r == '\n')
+ line--;
+ Bungetrune(&bin);
+}
+
long
yylex(void)
{
@@ -339,22 +347,16 @@
case '\t':
case ' ':
goto Loop;
- case '\n':
- case '*':
- case '+':
- case '-':
- case ':':
- case ',':
- case '(':
- case ')':
- case '=':
+ case '\n': case '*': case '+':
+ case '-': case ':': case ',':
+ case '(': case ')': case '=':
return r;
case '/':
r = getr();
- if(r == '/') {
+ if(r == '/')
return LSS;
- } else
- Bungetrune(&bin);
+ else
+ ungetr(r);
return '/';
case '"':
for(bp = buf; bp < buf+5; bp++) {
@@ -369,7 +371,7 @@
ep = buf+nelem(buf)-1;
isnum = 1;
for(;;) {
- if(runetomix(r) == -1)
+ if(runetomix(r) == -1)
yyerror("Invalid character %C", r);
if(bp == ep)
yyerror("Symbol or number too long");
@@ -376,23 +378,13 @@
*bp++ = r;
if(isnum && (r >= Runeself || !isdigit(r)))
isnum = 0;
- r = getr();
- switch(r) {
- case Beof:
- case '\t':
- case '\n':
- case '+':
- case '-':
- case '*':
- case ':':
- case ',':
- case '(':
- case ')':
- case '=':
- case ' ':
- case '/':
- case '#':
- Bungetrune(&bin);
+ switch(r = getr()) {
+ case Beof: case '\t': case '\n':
+ case '+': case '-': case '*':
+ case ':': case ',': case '(':
+ case ')': case '=': case ' ':
+ case '/': case '#':
+ ungetr(r);
*bp = '\0';
goto End;
}
@@ -408,6 +400,18 @@
}
Sym*
+getsym(char *name)
+{
+ Sym *s;
+
+ s = emallocz(sizeof(*s) + strlen(name));
+ strcpy(s->nbuf, name);
+ s->name = s->nbuf;
+ s->lex = LSYMREF;
+ return s;
+}
+
+Sym*
sym(char *name)
{
Sym *s, l;
@@ -416,11 +420,7 @@
s = (Sym*)avllookup(syms, &l, 0);
if(s != nil)
return s;
-
- s = emallocz(sizeof(*s) + strlen(name));
- strcpy(s->nbuf, name);
- s->name = s->nbuf;
- s->lex = LSYMREF;
+ s = getsym(name);
avlinsert(syms, s);
return s;
}
--- a/sys/src/games/mix/mix.h
+++ b/sys/src/games/mix/mix.h
@@ -39,6 +39,7 @@
void vmerror(char*, ...);
void skipto(char);
Sym *sym(char*);
+Sym *getsym(char*);
void sinit(void);
int asmfile(char*);
int V(u32int, int);