Add original unix v6

This commit is contained in:
memnoth
2018-01-27 22:35:41 +09:00
commit 2c7099ee50
664 changed files with 106254 additions and 0 deletions
+83
View File
@@ -0,0 +1,83 @@
struct tempent {
char *beg;
int ct;
char term;
} temp[30];
char lbuf[5];
int cflag;
int t1;
int level;
int hlevel;
int dlevel;
int xtrn;
int tp[5];
struct {
int cl[NUMC];
} tab[NUMS];
int coll();
int save();
int out();
int asym();
int asw();
int csym();
int csw();
int incl();
int decl();
int sk2();
int sk();
int tabs();
int semi();
char line[132];
int l;
int lno;
char c;
int cursl;
char curs[9];
int curfl;
char curf[10];
int usw;
int xsw;
int only;
int cross;
int file;
int cs;
int (*flag[8])();
int fl;
char gch[8];
struct htab {
int hsiz;
int ssiz;
int nsym;
int curb;
int *hptr;
char *symt;
};
struct htab itab;
struct htab xtab;
int ipsp[PTRI];
char issp[CHARI];
int xpsp[PTRX];
char xssp[CHARX];
int ib1[259];
int ib2[259];
char *ibuf;
char *ibuf1;
char *ibuf2;
char mone;
int order;
int ssw;
int type;
char *utmp;
+76
View File
@@ -0,0 +1,76 @@
int count;
int page;
struct {
char *beg;
int ct;
char term;
} temp[30];
int pn;
int word;
int hsw;
int t1;
int level;
int hlevel;
int dlevel;
int xtrn;
int tp[2];
struct {
int cl[NUMC];
} tab[NUMS];
int coll();
int save();
int out();
int hyphen();
int hyp1();
int hyp2();
int pno();
int error();
char line[300];
int l;
int lno;
char c;
int cursl;
char curs[9];
int curfl;
char curf[10];
int usw;
int xsw;
int only;
int cross;
int file;
int cs;
int (*flag[8])();
int fl;
char gch[8];
struct htab {
int hsiz;
int ssiz;
int nsym;
int curb;
int *hptr;
char *symt;
};
struct htab itab;
int ipsp[PTRI];
char issp[CHARI];
int ib1[259];
char *ibuf;
char *ibuf1;
char mone;
int order;
int ssw;
int type;
char *utmp;
+22
View File
@@ -0,0 +1,22 @@
# define NUMA 14
# define NUMC 128
# define NUMS 3
# define SIZA 8
# define SIZC 2
# define SIZS 8
# define PTRI 509
# define CHARI 4000
# define PTRX 5147
# define CHARX 40000
# define CONT 0
# define COLL 1
# define SAVE 2
# define OUT 3
# define EGOBL 4
# define SHARP 5
# define PNO 6
# define SKIP 0
# define COLLECT 1
# define SKIP2 2
#define CREATC 0644
+363
View File
@@ -0,0 +1,363 @@
#
# include "econs.h"
# include "ecmn.h"
/*int mbuf[1024]; /*INSTR*/
/*int tbuf[12]; /*INSTR*/
int (*acts[])() {0,
&coll,
&save,
&out,
&error,
&hyphen,
&pno
};
char *tmp[2] {"/tmp/crt0a",
"/tmp/crt1a"
};
char *ignonl "/usr/lib/eign";
char *gtab "/usr/lib/etab";
main(argc,argv)
char *argv[];
{
auto i,j,tm1,tm2,tm3;
char *fn,*av[8];
/* extern etext; /*INSTR*/
/* monitor(&main,&etext,&mbuf,1024); /*INSTR*/
if(*argv[1] == '-') {
j = flags(argv);
argv =+ j;
argc =- j;
}
init();
i = 0;
if(argc == 1) {
*ibuf1 = 0;
curfl = 2;
curf[0] = '_';
curf[1] = '\t';
goto pipe;
}
while(++i < argc) {
curs[4] = '\t';
if(fopen(argv[i],ibuf1) < 0) {
printf("Can't open %s\n",argv[i]);
dexit();
}
curfl = 0;
while((curf[curfl] = *argv[i]++) != 0 && curfl <=8)
if(curf[curfl++] == '/') curfl = 0;
curf[curfl++] = '\t';
if(curfl == 8) curf[8] = -1;
pipe:
ibuf = ibuf1;
lno = 1;
driver();
close(file);
}
flsh(0);
close(tp[0]);
/* monitor(0); /*INSTR*/
/* dexit(); /*INSTR*/
/* times(tbuf); /*INSTR*/
/* tm1 = tbuf[0]/6; /*INSTR*/
/* tm2 = tbuf[1]/6; /*INSTR*/
/* printf("Prep: %d %d\n", tm1, tm2); /*INSTR*/
/* exit(); /*DEBUG*/
fn = "/bin/sort";
av[0] = "sort";
av[1] = tmp[0];
av[2] = "-o";
av[3] = tmp[0];
av[4] = 0;
callsys(fn, av);
/* times(tbuf); /*INSTR*/
/* tm1 = tbuf[3]/6; /*INSTR*/
/* tm2 = tbuf[5]/6; /*INSTR*/
/* printf("Sort: %d %d\n", tm1, tm2); /*INSTR*/
if(usw) {
fn = "/usr/bin/upost";
av[0] = "upost";
i = 0;
} else if(count) {
fn = "count";
av[0] = "count";
i = 0;
} else {
fn = "/usr/bin/crpost";
av[0] = "crpost";
av[1] = "-E";
i = 1;
}
av[++i] = tmp[0];
av[++i] = 0;
callsys(fn,av);
/* times(tbuf); /*INSTR*/
/* tm1 = tbuf[3]/6 - tm1; /*INSTR*/
/* tm2 = tbuf[5]/6 - tm2; /*INSTR*/
/* printf("Post: %d %d\n", tm1, tm2); /*INSTR*/
dexit();
}
driver()
{
auto p;
top:
l = -1;
while((c = line[++l] = getc(ibuf)) != -1) {
/* printf("driver: c = %o l = %d\n",c,l); /*DEBUG*/
if(l >= 299) {
printf("Line too long: %d.\n",lno);
dexit();
}
if(c & 0200) {
printf("Illegal character: %o line %d\n",c,lno);
dexit();
}
if(fl) {
if((*flag[fl])())
continue;
}
/*printf("cs = %d cc = %c ca = %d\n",cs,c,tab[cs].cl[c]); /*DEBUG*/
if(p = tab[cs].cl[c])
(*acts[p])();
continue;
}
if(ibuf == ibuf1) return;
ibuf = ibuf1;
goto top;
}
init()
{
int b[3];
auto fi,i;
extern coll(),save(),out(),asym(),asw(),csym(),csw();
extern incl(),decl(),sk(),sk2();
extern dexit();
ibuf1 = &ib1;
if((fi = open(gtab,0)) < 0) {
printf("Cannot open grammar table; see lem\n");
dexit();
}
i = -1;
while(++i < NUMS)
if(read(fi,tab[i].cl,256) < 256) {
printf("Bad grammar table; see lem\n");
dexit();
}
close(fi);
if(signal(1,1) != 1) signal(1,&dexit);
if(signal(2,1) != 1) signal(2,&dexit);
if(signal(3,1) != 1) signal(3,&dexit);
while((tp[1] = creat(tmp[1],0)) < 0)
tmp[1][9]++;
close(tp[1]);
tmp[0][9] = tmp[1][9];
tp[0] = creat(tmp[0],CREATC);
if(count) return;
itab.hptr = &ipsp;
itab.symt = &issp;
itab.hsiz = PTRI;
itab.ssiz = CHARI;
itab.nsym = 0;
itab.curb = 1;
if((fi = open(ignonl,0)) < 0) {
printf("Cannot open ignore/only file.\n");
dexit();
}
if((read(fi,b,6) == 6) && (b[0] == 0100200)) {
if(read(fi,itab.hptr,b[1]) < b[1]) {
printf("Cannot read ignore/only file.\n");
dexit();
}
if(read(fi,itab.symt,b[2]) < b[2]) {
printf("Cannot read ignor/only file.\n");
dexit();
}
close(fi);
} else {
close(fi);
compile();
}
return;
}
error(a)
{
printf("Error %d\n",a);
dexit();
}
dexit()
{
extern nflush;
/* printf("nflush = %d\n",nflush); /*DEBUG*/
if(tp[0] > 0 && utmp == 0) {
unlink(tmp[0]);
unlink(tmp[1]);
}
exit();
}
callsys(f,v)
char f[],*v[];
{
int t,status,i;
if((t = fork()) == 0) {
for(i = 1; i <= 12; i++) signal(i,0);
execv(f,v);
printf("Can't find %s\n",f);
exit(1);
} else {
if(t == -1) {
printf("Try again\n");
return(1);
}
}
while(t != wait(&status));
/* printf("Status = %o, %s\n",status,f); /*DEBUG*/
if((t = (status & 0377)) != 0) {
if(t != 2) {
printf("Fatal error in %s\n",f);
printf("t = %d\n",t);
}
dexit();
}
return((status>>8) & 0377);
}
flags(argv)
char *argv[];
{
int j,xx;
char *ap;
j = 1;
ap = argv[1];
while(*++ap != '\0') {
switch(*ap) {
default:
printf("Unrecognized flag: %c\n",*ap);
dexit();
case 'c':
count = 1;
continue;
case 'i': /* Ignore file */
if(!xx) {
xx = 1;
only = 0;
ignonl = argv[++j];
}
continue;
case 'o': /*only file*/
if(!xx) {
xx = 1;
only = 1;
ignonl = argv[++j];
}
continue;
case 'p':
page = 1;
continue;
case 't':
utmp = argv[++j];
tmp[0] = argv[j];
continue;
case 'u': /* Unique symbols only */
usw = 1;
continue;
case 'w': /* Word list only */
word = 1;
continue;
}
}
return(j);
}
compile()
{
char buf[40],*b;
int i,v;
fopen(ignonl,ibuf1);
b = buf - 1;
while((*++b = getc(ibuf1)) != -1) {
if(*b == '\n') {
*b = '\0';
search(buf,b - buf,&itab,1);
b = buf - 1;
} else {
if(*b == '\t') {
v = 0;
while((i = getc(ibuf1)) != -1) {
if(i == '\n') break;
v = v*10 + (i - '0');
}
search(buf,b - buf,&itab,v);
b = buf - 1;
} else {
if((b - buf) > 39) {
printf("Ignore/only symbol too long.\n");
dexit();
}
}
}
}
close(ibuf1);
return;
}
+259
View File
@@ -0,0 +1,259 @@
#
# include "econs.h"
# include "ecmn.h"
# define SKIP 0
# define COLLECT 1
# define SKIP2 2
char mone -1;
int tlno 1;
coll()
{
cs = COLLECT;
temp[t1].beg = &line[l];
return;
}
save()
{
extern only;
char *pt1,*pt2,cbuf[30];
int a,tt,val;
cs = SKIP;
line[l] = '\0';
temp[t1].ct = &line[l] - temp[t1].beg;
if(!count)
if(temp[t1].ct == 1) goto no;
pt1 = temp[t1].beg-1;
pt2 = cbuf-1;
while(*++pt2 = *++pt1)
if(*pt2 >= 'A' && *pt2 <= 'Z')
*pt2 =| 040;
if(count)
goto yes;
val = search(cbuf,temp[t1].ct,&itab,0);
if(!val == !only) goto yes;
no:
line[l] = c;
return(0);
yes:
if(count == 0) {
tt = t1;
while(tt)
if(comp(temp[t1].beg,temp[--tt].beg)) goto no;
}
temp[t1++].term = c;
return(1);
}
out()
{
auto i,ct,t2;
char *b,*e;
if(cs == COLLECT) save();
ct = t1;
while(ct--)
temp[ct].beg[temp[ct].ct] = temp[ct].term;
t2 = t1 - 1;
while(t1--) {
/*printf("t1 = %d beg = %o ct = %d\n",t1,temp[t1].beg,temp[t1].ct); /* DEBUG */
if((ct = temp[t1].ct) >= 15) {
ct = 15;
}
put(temp[t1].beg,ct);
if(count) {
put("\n", 1);
continue;
}
put("\t",1);
if(!page) {
put(curf,curfl);
conf(lno,4,curs);
put(curs,4);
} else {
conf(pn,4,curs);
put(curs,4);
}
if(word == 0) {
put("\t",1);
if(t1 >= 1)
b = temp[t1-1].beg;
else
b = line;
if(t2 > t1)
e = temp[t1+1].beg + temp[t1+1].ct;
else
e = &line[l];
/*printf("e = %o b = %o\n",e,b); /*DEBUG*/
put(b,e-b);
}
put("\n",1);
}
t1 = 0;
l = -1;
lno =+ tlno;
tlno = 1;
cs = SKIP;
return;
}
search(symbol,length,params,install)
char *symbol;
int length;
struct htab *params;
int install;
{
char *sp,*p;
static int *hptr,hsiz,nsym;
static char *ssiz;
static int curb;
static char *symt;
auto h,i,j,k;
if(hptr != params->hptr) {
hptr = params->hptr;
hsiz = params->hsiz;
symt = params->symt;
ssiz = params->ssiz;
curb = params->curb;
nsym = params->nsym;
}
symbol[length] = '\0';
/*printf("ssiz = %d; nsym = %d; %s\n", ssiz, nsym, symbol);/*DEBUG*/
sp = symbol;
i = length;
h = 1;
while(i--)
h =* *sp++;
if(h == 0100000) {
h = 1;
} else {
h = h<0?(-h)%hsiz:h%hsiz;
}
if(h == 0) h++;
/* printf("%s %d\n",symbol,h); /*DEBUG*/
while((p = &symt[hptr[h]]) > symt) {
j = length + 2;
sp = symbol;
while(--j) {
if(*p++ != *sp++) goto no;
}
return(*p);
no:
h = (h + h)%hsiz;
}
if(install) {
if(++nsym >= hsiz) {
printf("Too many symbols in ignore/only file.\n");
dexit();
}
hptr[h] = curb;
length++;
if((curb + length) >= ssiz) {
printf("i/o file too big; ssiz = %d\n", ssiz);
dexit();
}
while(length--)
symt[curb++] = *symbol++;
symt[curb++] = install;
params->curb = curb;
params->nsym = nsym;
}
return(0);
}
conf(n,width,buf)
char *buf;
{
auto i,a;
i = width;
while(i--) buf[i] = ' ';
buf[(a = n/10)?conf(a,--width,buf):--width] = n%10 + '0';
return(++width);
}
comp(a,b)
char *a;
char *b;
{
a--;
b--;
while(*++a == *++b)
if(*a == '\0') return(1);
return(0);
}
hyphen()
{
/* printf("hyphen\n"); /*DEBUG*/
if(gch[fl] == 0)
flag[++fl] = &hyp1;
return(1);
}
hyp1()
{
/* printf("hyp1 c = %o\n",c); /*DEBUG*/
if(c != '\n') {
fl--;
return(0);
} else {
l =- 2;
flag[fl] = &hyp2;
hsw = 1;
return(1);
}
}
hyp2()
{
/* printf("hyp2 c = %o l = %d\n",c,l); /*DEBUG*/
if(hsw && (tab[2].cl[c] == 0)) {
l--;
if(c == 3) pno();
if(c == '\n') tlno++;
return(1);
}
hsw = 0;
if(tab[cs].cl[c]) {
line[l] = '\n';
out();
fl--;
return(0);
}
return(1);
}
pno()
{
if(flag[fl] != &pno) {
flag[++fl] = &pno;
pn = 0;
return(1);
}
if(c == '\n') {
fl--;
out();
return(1);
}
pn = pn*10 + c - '0';
return(1);
}
+49
View File
@@ -0,0 +1,49 @@
int optr;
char obuf[512];
int nflush;
put(string,n)
char *string;
{
extern utmp;
int i;
char *o;
/*printf("%d %c %d\n",fil,*string,n);/*DEBUG*/
string--;
if((i = optr + n - 512) >= 0) {
n =- i;
o = &obuf[optr] -1;
while(--n >= 0)
*++o = *++string;
optr = 512;
flsh(1);
n = i;
}
o = &obuf[optr] - 1;
optr =+ n;
while(--n >= 0) {
*++o = *++string;
}
return(0);
}
flsh(fil)
{
extern tp[],utmp;
if(optr <= 0) return(optr);
nflush++;
if(write(tp[0],obuf,optr) != optr)
return(-1);
optr = 0;
return(0);
}
+30
View File
@@ -0,0 +1,30 @@
# define NUMA 14
# define NUMC 128
# define NUMS 3
# define SIZA 8
# define SIZC 2
# define SIZS 8
# define PTRI 509
# define CHARI 4000
# define PTRX 509
# define CHARX 4000
# define CONT 1
# define COLL 2
# define SAVE 3
# define OUT 4
# define ASYM 5
# define ASW 6
# define CSYM 7
# define CSW 8
# define INCL 9
# define DECL 10
# define SK2 11
# define SK 12
# define TABS 13
# define SEMI 14
# define SHARP 15
# define SKIP 0
# define COLLECT 1
# define SKIP2 2
#define CREATC 0644
+30
View File
@@ -0,0 +1,30 @@
chdir tab
cc mtab.c
a.out atable atab
a.out ctable ctab
a.out etable etab
cmp atab /usr/lib/atab
cp atab /usr/lib/atab
cmp ctab /usr/lib/ctab
cp ctab /usr/lib/ctab
cmp etab /usr/lib/etab
cp etab /usr/lib/etab
rm a.out atab ctab etab
chdir ../src
cc -s -O upost.c
cmp a.out /usr/bin/upost
cp a.out /usr/bin/upost
cc -s -O crpost.c
cmp a.out /usr/bin/crpost
cp a.out /usr/bin/crpost
cc -s -O dr.c acts.c put.c
cmp a.out /usr/bin/cref
cp a.out /usr/bin/cref
rm a.out *.o
chdir ../index
cc -s -O ind?.c
cmp a.out /usr/bin/index
cp a.out /usr/bin/index
rm a.out *.o
+484
View File
@@ -0,0 +1,484 @@
#
# include "../mcons.h"
# include "../ccmn.h"
# define SKIP 0
# define COLLECT 1
# define SKIP2 2
int cross 1;
int order 1;
char mone -1;
coll()
{
cs = COLLECT;
temp[t1].beg = &line[l];
return;
}
save()
{
extern wspace();
line[l] = '\0';
temp[t1].ct = &line[l] - temp[t1].beg;
temp[t1].term = c;
if((c == ' ' || c == '\t') && cflag) {
gch[++fl] = mone;
flag[fl] = &wspace;
} else {
sav1();
}
return;
}
sav1()
{
extern only;
struct tempent *ptr;
int a,tt,val;
if(cflag && c == '(' && level == 0) csym();
cs = SKIP;
ptr = &temp[t1];
val = search(ptr->beg,ptr->ct,&itab,0);
if(xsw) {
switch(val) {
case 0:
if((!level&&!hlevel)||(c == '(')||xtrn
|| ssw) {
search(ptr->beg,ptr->ct,&xtab,1);
goto yes;
} else {
if(search(ptr->beg,ptr->ct,&xtab,0))
goto yes;
}
goto no;
case 1:
goto no;
case 2:
xtrn = 1;
goto no;
case 3:
if(hlevel) type = 1;
if(!level&&!hlevel) ssw = 1;
goto no;
case 4:
if(hlevel) type = 1;
goto no;
}
}
if(hlevel && (val == 4 || val == 3)) type = 1;
if(!val == !only) goto yes;
no:
*(ptr->beg + ptr->ct) = ptr->term;
return(0);
yes:
tt = t1;
while(tt)
if(comp(ptr->beg,temp[--tt].beg)) goto no;
t1++;
return(1);
}
out()
{
auto i,ct;
if(cs == COLLECT) save();
ct = t1;
while(ct--)
temp[ct].beg[temp[ct].ct] = temp[ct].term;
while(t1--) {
/*printf("t1 = %d beg = %d ct = %d\n",t1,temp[t1].beg,temp[t1].ct); /* DEBUG */
switch(order) {
case 1:
if(utmp)
i = 0;
else
i = dfile(temp[t1].beg);
if((ct = temp[t1].ct) >= 8) {
ct = 8;
*curf = -1;
} else {
*curf = '\t';
}
put(i,temp[t1].beg,ct);
put(i,curf,curfl);
if(cross) put(i,curs,cursl);
conf(lno,4,lbuf);
put(i,lbuf,5);
break;
case 2:
i = dfile(curf+1);
put(i,curf+1,curfl-1);
if(cross) put(i,curs,cursl);
else {
conf(lno,4,lbuf);
put(i,lbuf,5);
}
if((ct = temp[t1].ct) >= 8) {
put(i,temp[t1].beg,8);
put(i,&mone,1);
} else {
put(i,temp[t1].beg,ct);
put(i,"\t",1);
}
if(cross) {
conf(lno,4,lbuf);
put(i,lbuf,5);
}
break;
case 3:
i = dfile(curs);
put(i,curs,cursl);
if((ct = temp[t1].ct) >= 8) {
put(i,temp[t1].beg,8);
*curf = -1;
} else {
put(i,temp[t1].beg,ct);
*curf = '\t';
}
put(i,curf,curfl);
conf(lno,4,lbuf);
put(i,lbuf,5);
}
put(i,line,l + 1);
}
t1 = 0;
l = -1;
lno++;
cs = SKIP;
return;
}
asym()
{
int i;
char *p;
if(cs == COLLECT) {
if(cross) {
p = temp[t1].beg;
cursl = &line[l] - p;
cursl = cursl>8?8:cursl;
i = -1;
while(++i < cursl)
curs[i] = *p++;
if(cursl < 8)
curs[cursl++] = '\t';
else
curs[cursl++] = -1;
}
save();
}
cs = SKIP;
}
asw()
{
switch(gch[fl]) {
case 0:
if(cs == COLLECT) save();
cs = SKIP;
flag[++fl] = &asw;
gch[fl] = c;
return(1);
case '\'':
if(c == '\\') {
gch[fl] = c;
return(1);
}
break;
case '"':
gch[fl] = '\'';
if(c == '\\') {
flag[++fl] = &asw;
gch[fl] = c;
return(1);
}
return(1);
case '<':
if(c == '\n') out();
if(c == '\\') {
flag[++fl] = &asw;
gch[fl] = c;
return(1);
}
if(c != '>') return(1);
break;
case '/':
if(c != '\n') return(1);
case '\\':
if(c == '\n') out();
}
fl--;
return(1);
}
csw()
{
if(cs == COLLECT) save();
switch(gch[fl]) {
case 0:
if(c == '*')
if(line[l - 1] != '/')
return(1);
gch[++fl] = c;
flag[fl] = &csw;
return(1);
case '*':
if(c == '\n') out();
if(c == '/' && line[l - 1] == '*')
break;
return(1);
case '\'':
case '"':
if(c == gch[fl])
break;
if(c == '\\') {
gch[++fl] = c;
flag[fl] = &csw;
}
return(1);
case '\\':
break;
}
fl--;
return(1);
}
incl()
{
/* printf("incl: l = %d hl = %d dl = %d\n",level,hlevel,dlevel);/*DEBUG*/
if(cs == COLLECT) save();
if(hlevel) {
hlevel = 0;
level++;
} else {
dlevel++;
}
cs = SKIP;
}
decl()
{
/* printf("decl: l = %d hl = %d dl = %d\n",level,hlevel,dlevel);/*DEBUG*/
if(cs == COLLECT) save();
cs = SKIP;
if(dlevel) {
dlevel--;
return;
}
if(--level > 0) return;
curs[0] = '_';
curs[1] = '\t';
cursl = 2;
level = 0;
return;
}
csym()
{
int i;
char *p;
/* printf("csym: l = %d hl = %d dl = %d\n",level,hlevel,dlevel);/*DEBUG*/
p = temp[t1].beg;
if(cs == COLLECT && level == 0) {
if(cross) {
cursl = temp[t1].ct;
cursl = cursl>8?8:cursl;
i = -1;
while(++i < cursl)
curs[i] = *p++;
if(cursl < 8)
curs[cursl++] = '\t';
else
curs[cursl++] = -1;
}
hlevel = 1;
}
cs = SKIP;
}
dfile(a)
char *a;
{
if(*a < 'c') return(0);
if(*a < 'h') return(1);
if(*a < 'r') return(2);
return(3);
}
sk2()
{
cs = SKIP2;
}
sk()
{
cs = SKIP;
}
tabs()
{
if(l == 0) l = -1;
}
search(symbol,length,params,install)
char *symbol;
int length;
struct htab *params;
int install;
{
char *sp,*p;
static int curb,*hptr,hsiz,nsym,ssiz;
static char *symt;
auto h,i,j,k;
if(hptr != params->hptr) {
hptr = params->hptr;
hsiz = params->hsiz;
symt = params->symt;
ssiz = params->ssiz;
curb = params->curb;
nsym = params->nsym;
}
symbol[length] = '\0';
sp = symbol;
i = length;
h = 1;
while(i--)
h =* *sp++;
if(h == 0100000) {
h = 1;
} else {
h = h<0?(-h)%hsiz:h%hsiz;
}
if(h == 0) h++;
/* printf("%s %d\n",symbol,h); /*DEBUG*/
while((p = &symt[hptr[h]]) > symt) {
j = length + 2;
sp = symbol;
while(--j) {
if(*p++ != *sp++) goto no;
}
return(*p);
no:
h = (h + h)%hsiz;
}
if(install) {
if(++nsym >= hsiz) {
printf("Too many symbols.\n");
dexit();
}
hptr[h] = curb;
length++;
if((curb + length) >= ssiz) {
printf("Too many characters in symbols.\n");
dexit();
}
while(length--)
symt[curb++] = *symbol++;
symt[curb++] = install;
params->curb = curb;
params->nsym = nsym;
}
return(0);
}
conf(n,width,buf)
char *buf;
{
auto i,a;
i = width;
while(i--) buf[i] = ' ';
buf[(a = n/10)?conf(a,--width,buf):--width] = n%10 + '0';
return(++width);
}
comp(a,b)
char *a;
char *b;
{
a--;
b--;
while(*++a == *++b)
if(*a == '\0') return(1);
return(0);
}
semi()
{
if(cs == COLLECT) save();
if(only) return;
xtrn = 0;
if(!level) {
ssw = 0;
if(!type) {
hlevel = 0;
curs[0] = '_';
curs[1] = '\t';
cursl = 2;
}
type = 0;
}
cs = SKIP;
}
wspace()
{
if(c == ' ' || c == '\t')
return(1);
sav1();
fl--;
return(0);
}
+265
View File
@@ -0,0 +1,265 @@
/*int mbuf[1024]; /*INSTR*/
int ig 100;
int esw;
int initf 1;
char ssp[270];
char *sym[9] {ssp,
ssp + 30,
ssp + 60,
ssp + 90,
ssp + 120,
ssp + 150,
ssp + 180,
ssp + 210,
ssp + 240,
ssp + 270
};
main(argc, argv)
char *argv[];
{
auto f,fct,file,i;
if(argc < 2) {
printf("Usage: crpost [-d] file1 file2 ...\n");
exit();
}
if(*argv[1] == '-') {
if(argv[1][1] == 'E') {
fct = 3;
esw = 1;
goto on;
}
fct = argv[1][1] - '0';
if((fct < 1) || (fct > 9)) {
printf("-d: 0 < d < 10\n");
exit();
}
if(argv[1][2] == 'x') {
ig = fct-1;
}
on:
argv++;
argc--;
} else {
fct = 3;
}
f = 0;
while(++f < argc) {
file = open(argv[f], 0);
edf(file, fct);
close(file);
}
flsh(0);
exit();
}
int lno 1;
edf(file, fct)
{
auto i,j,l;
extern lno,etext;
char brk,*buf,bufsp[150],line[150];
char extern *sym[];
/* monitor(&main,&etext,&mbuf,1024); /*INSTR*/
for(i = 0; i < fct; i++)
*sym[i] = 0200;
fields:
l = -1;
buf = &bufsp;
for(i = 0; i < fct; ++i) {
buf--;
swt:
switch(*++buf = get(file)) {
default:
if(esw && *buf >= 'A' && *buf <= 'Z'
&& i == 0)
*buf =| 040;
goto swt;
case -1:
*buf = ' ';
case '\t':
if(i == ig) continue;
brk = *buf;
*buf = '\0';
buf = &bufsp;
if(comp(buf, sym[i])) {
if(esw && i == 0) {
line[0] = line[1] = '\t';
l = 1;
goto rest;
}
line[++l] = '\t';
continue;
} else {
copy(buf, sym[i]);
l =+ copy(buf, &line[++l]);
line[--l] = brk;
if(l < 8 && esw && i == 0)
line[++l] = '\t';
j = i;
while(++j < fct)
*sym[j] = 0200;
continue;
}
case '\n':
lno++;
brk = *buf;
*buf = '\0';
buf = &bufsp;
if(comp(buf, sym[i])) {
goto fields;
} else {
copy(buf, sym[i]);
l =+ copy(buf, &line[++l]);
line[--l] = '\n';
j = i;
while(++j < fct)
*sym[j] = 0;
goto out;
}
case '\0':
goto fexit;
}
}
rest:
while((line[++l] = get(file)) != '\n')
if(line[l] == '\0') goto fexit;
lno++;
out:
if(*line != '\t') {
put(0,"\n",1);
lno++;
}
put(0,line,++l);
goto fields;
fexit:
/* monitor(0); /*INSTR*/
return(0);
}
copy(a, b)
char *a,*b;
{
char *c;
b--;
c = --a;
while(*++b = *++a);
return(a - c);
}
comp(a, b)
char *a, *b;
{
/* printf("comp: %s %s\n",a,b); /*DEBUG*/
a--;
b--;
while(*++a == *++b) {
if(*a == '\0') return(1);
}
return(0);
}
char buf[512];
int nread 1;
get(ifile) int ifile;
{
char static *ibuf;
if(--nread){
return(*ibuf++);
}
if(nread = read(ifile,buf,512)){
if(nread < 0)goto err;
ibuf = buf;
return(*ibuf++);
}
nread = 1;
return(0);
err:
nread = 1;
printf("read error\n");
return(0);
}
int tp[1] 1;
int optr[4];
char bsp[512];
char *obuf[1] bsp;
int nflush;
put(fil,string,n)
char *string;
{
int i;
char *o;
/*printf("%d %c %d\n",fil,*string,n);/*DEBUG*/
string--;
if((i = optr[fil] + n - 512) >= 0) {
n =- i;
o = &obuf[fil][optr[fil]] -1;
while(--n >= 0)
*++o = *++string;
optr[fil] = 512;
flsh(fil);
n = i;
}
o = &obuf[fil][optr[fil]] - 1;
optr[fil] =+ n;
while(--n >= 0) {
*++o = *++string;
}
return(0);
}
flsh(fil)
{
extern tp[];
if(optr[fil] <= 0) return(optr[fil]);
nflush++;
if(write(tp[fil],obuf[fil],optr[fil]) != optr[fil])
return(-1);
optr[fil] = 0;
return(0);
}
+441
View File
@@ -0,0 +1,441 @@
#
# include "../mcons.h"
# include "../ccmn.h"
/*int mbuf[1024]; /*INSTR*/
/*int tbuf[36]; /*INSTR*/
int (*acts[])() {0,
&coll,
&save,
&out,
&asym,
&asw,
&csym,
&csw,
&incl,
&decl,
&sk2,
&sk,
&tabs,
&semi
};
char *tmp[5] {"/tmp/crt0a",
"/tmp/crt1a",
"/tmp/crt2a",
"/tmp/crt3a",
"/tmp/crt4a"
};
char *ignonl "/usr/lib/aign";
char *gtab "/usr/lib/atab";
main(argc,argv)
char *argv[];
{
auto i,j,tm1,tm2,tm3;
char *fn,*av[8];
/* extern etext; /*INSTR*/
/* monitor(&main,&etext,&mbuf,1024); /*INSTR*/
if(argc < 2) {
printf("Usage: cref [-aceilosux] file1 ...\n");
exit();
}
lbuf[4] = '\t';
if(*argv[1] == '-') {
j = flags(argv);
argv =+ j;
argc =- j;
}
init();
i = 0;
while(++i < argc) {
curs[0] = '_';
curs[1] = '\t';
curs[4] = '\t';
cursl = 2;
if(fopen(argv[i],ibuf1) < 0) {
printf("Can't open %s\n",argv[i]);
dexit();
}
ibuf = ibuf1;
curf[0] = '\t';
curfl = 1;
while((curf[curfl] = *argv[i]++) != 0 && curfl <= 8)
if(curf[curfl++] == '/') curfl = 1;
curf[curfl++] = '\t';
if(curfl == 10) curf[9] = -1;
/* printf("%s %d\n",curf,curfl);/*DEBUG*/
lno = 1;
driver();
close(file);
}
for(j = 0; j < 4;) {
flsh(j,0);
close(tp[j++]);
}
/* monitor(0); /*INSTR*/
/* dexit(); /*INSTR*/
/* times(tbuf); /*INSTR*/
/* tm1 = tbuf[15]/6; /*INSTR*/
/* tm2 = tbuf[19]/6; /*INSTR*/
/* tm3 = tbuf[23]/6; /*INSTR*/
/* printf("Prep: %d %d %d\n",tm1,tm2,tm3); /*INSTR*/
if(utmp) exit();
fn = "/bin/sort";
av[0] = "sort";
av[1] = "-a";
av[3] = "-o";
av[5] = 0;
for(i = 0; i < 4; i++) {
av[4] = av[2] = tmp[i];
callsys(fn,av);
if(utmp) break;
}
/* times(tbuf); /*INSTR*/
/* tm1 = tbuf[27]/6; /*INSTR*/
/* tm2 = tbuf[31]/6; /*INSTR*/
/* tm3 = tbuf[35]/6; /*INSTR*/
/* printf("Sort: %d %d %d\n",tm1,tm2,tm3); /*INSTR*/
if(usw) {
fn = "/usr/bin/upost";
av[0] = "upost";
i = 0;
} else {
fn = "/usr/bin/crpost";
av[0] = "crpost";
av[1] = cross? "-4x": "-3";
i = 1;
}
j = -1;
while(++j < 4) {
av[++i] = tmp[j];
if(utmp) break;
}
av[++i] = 0;
callsys(fn,av);
/* times(tbuf); /*INSTR*/
/* tm1 = tbuf[27]/6 - tm1; /*INSTR*/
/* tm2 = tbuf[31]/6 - tm2; /*INSTR*/
/* tm3 = tbuf[35]/6 - tm3; /*INSTR*/
/* printf("Post: %d %d %d\n",tm1,tm2,tm3); /*INSTR*/
dexit();
}
driver()
{
auto p;
top:
l = -1;
while((c = line[++l] = getc(ibuf)) != -1) {
if(l >= 131) {
printf("Line too long: %d %s\n",lno,curf);
dexit();
}
if(c & 0200) {
printf("Illegal character: %o line %d\n",c,lno);
dexit();
}
if(fl) {
if((*flag[fl])())
continue;
}
/*printf("cs = %d cc = %c ca = %d\n",cs,c,tab[cs].cl[c]); /*DEBUG*/
if(p = tab[cs].cl[c])
(*acts[p])();
continue;
}
if(ibuf == ibuf1) return;
ibuf = ibuf1;
goto top;
}
init()
{
int b[3];
auto fi,i;
extern coll(),save(),out(),asym(),asw(),csym(),csw();
extern incl(),decl(),sk(),sk2();
extern dexit();
ibuf1 = &ib1;
ibuf2 = &ib2;
xtab.hptr = &xpsp;
xtab.symt = &xssp;
xtab.hsiz = PTRX;
xtab.ssiz = CHARX;
xtab.nsym = 0;
xtab.curb = 1;
itab.hptr = &ipsp;
itab.symt = &issp;
itab.hsiz = PTRI;
itab.ssiz = CHARI;
itab.nsym = 0;
itab.curb = 1;
if((fi = open(gtab,0)) < 0) {
printf("Cannot open grammar table; see lem\n");
dexit();
}
i = -1;
while(++i < NUMS)
if(read(fi,tab[i].cl,256) < 256) {
printf("Bad grammar table.\n");
dexit();
}
close(fi);
if((fi = open(ignonl,0)) < 0) {
printf("Cannot open ignore/only file: %s\n",ignonl);
dexit();
}
if((read(fi,b,6) == 6) && (b[0] == 0100200)) {
if(read(fi,itab.hptr,b[1]) < b[1]) {
printf("Cannot read ignore/only file: %s\n",ignonl);
dexit();
}
if(read(fi,itab.symt,b[2]) < b[2]) {
printf("Cannot read ignore/only file: %s\n",ignonl);
dexit();
}
close(fi);
} else {
close(fi);
compile();
}
if((signal(1,1) & 1) == 0) signal(1,&dexit);
if((signal(2,1) & 1) == 0) signal(2,&dexit);
if((signal(3,1) & 1) == 0) signal(3,&dexit);
/* signal(4,&dexit);
signal(5,&dexit);
signal(6,&dexit);
signal(7,&dexit);
signal(8,&dexit);
signal(10,&dexit);
signal(11,&dexit);
signal(12,&dexit);
*/
if(utmp == 0) {
while((tp[4] = creat(tmp[4],0)) < 0)
tmp[4][9]++;
close(tp[4]);
tmp[0][9] = tmp[4][9];
tmp[1][9] = tmp[4][9];
tmp[2][9] = tmp[4][9];
tmp[3][9] = tmp[4][9];
tp[0] = creat(tmp[0],CREATC);
tp[1] = creat(tmp[1],CREATC);
tp[2] = creat(tmp[2],CREATC);
tp[3] = creat(tmp[3],CREATC);
} else {
if((tp[0] = creat(utmp,CREATC)) < 0) {
printf("Can't create user's temp file.\n");
exit();
}
}
return;
}
error(a)
{
printf("Error %d\n",a);
dexit();
}
dexit()
{
extern nflush;
/* printf("nflush = %d\n",nflush); /*DEBUG*/
if(tp[0] > 0 && utmp == 0) {
unlink(tmp[0]);
unlink(tmp[1]);
unlink(tmp[2]);
unlink(tmp[3]);
unlink(tmp[4]);
}
exit();
}
callsys(f,v)
char f[],*v[];
{
int t,status,i;
if((t = fork()) == 0) {
execv(f,v);
printf("Can't find %s\n",f);
exit(1);
} else {
if(t == -1) {
printf("Try again\n");
return(1);
}
}
while(t != wait(&status));
/* printf("Status = %o, %s\n",status,f); /*DEBUG*/
if((t = (status & 0377)) != 0) {
if(t != 2) {
printf("Fatal error in %s\n",f);
printf("t = %d\n",t);
}
dexit();
}
return((status>>8) & 0377);
}
flags(argv)
char *argv[];
{
int j,xx;
char *ap;
j = 1;
ap = argv[1];
while(*++ap != '\0') {
switch(*ap) {
default:
printf("Unrecognized flag: %c\n",*ap);
dexit();
case '1': /* Symbol first */
order = 1;
continue;
case '2': /* Current file first */
order = 2;
continue;
case '3': /* Current symbol first */
order = 3;
continue;
case 'a': /* Assembler */
cflag = 0;
continue;
case 'c': /* C */
gtab = "/usr/lib/ctab";
if(!xx)
ignonl = "/usr/lib/cign";
cflag = 1;
continue;
case 'e': /* English */
gtab = "/usr/lib/etab";
if(!xx)
ignonl = "/usr/lib/eign";
continue;
case 'i': /* Ignore file */
if(!xx) {
xx = 1;
only = 0;
ignonl = argv[++j];
}
continue;
case 'l': /* Line numbers in col. 3 */
cross = 0;
continue;
case 'o': /* Only file */
if(!xx) {
xx = 1;
only = 1;
ignonl = argv[++j];
}
continue;
case 's': /* Symbols in col. 3 */
cross = 1;
continue;
case 't':
utmp = argv[++j];
tmp[0] = argv[j];
continue;
case 'u': /* Unique symbols only */
usw = 1;
continue;
case 'x': /* C externals */
xsw = 1;
gtab = "/usr/lib/ctab";
if(!xx)
ignonl = "/usr/lib/cign";
cflag = 1;
continue;
}
}
return(j);
}
compile()
{
char buf[40],*b;
int i,v;
fopen(ignonl,ibuf1);
b = buf - 1;
while((*++b = getc(ibuf1)) != -1) {
if(*b == '\n') {
*b = '\0';
search(buf,b - buf,&itab,1);
b = buf - 1;
} else {
if(*b == '\t') {
v = 0;
while((i = getc(ibuf1)) != -1) {
if(i == '\n') break;
v = v*10 + (i - '0');
}
search(buf,b - buf,&itab,v);
b = buf - 1;
} else {
if((b - buf) > 39) {
printf("Ignore/only symbol too long");
dexit();
}
}
}
}
close(ibuf1);
return;
}
+59
View File
@@ -0,0 +1,59 @@
int bct[4];
int optr[4];
char bsp[2048];
char *obuf[4] {bsp,
bsp + 512,
bsp + 1024,
bsp + 1536
};
int nflush;
put(fil,string,n)
char *string;
{
extern utmp;
int i;
char *o;
/*printf("%d %c %d\n",fil,*string,n);/*DEBUG*/
string--;
if((i = optr[fil] + n - 512) >= 0) {
n =- i;
o = &obuf[fil][optr[fil]] -1;
while(--n >= 0)
*++o = *++string;
optr[fil] = 512;
flsh(fil);
n = i;
}
o = &obuf[fil][optr[fil]] - 1;
optr[fil] =+ n;
while(--n >= 0) {
*++o = *++string;
}
return(0);
}
flsh(fil)
{
extern tp[],utmp;
if(optr[fil] <= 0) return(optr[fil]);
if(bct[fil]++ >= 128 && utmp == 0) {
printf("Wraparound temp file %d\n",fil);
dexit();
}
nflush++;
if(write(tp[fil],obuf[fil],optr[fil]) != optr[fil])
return(-1);
optr[fil] = 0;
return(0);
}
+214
View File
@@ -0,0 +1,214 @@
/*int mbuf[1024]; /*INSTR*/
int psw 1;
int initf 1;
main(argc, argv)
char *argv[];
{
auto f,fct,file;
if(argc < 2) {
printf("Usage: cpost [-d] file1 file2 ...\n");
exit();
}
if(*argv[1] == '-') {
fct = argv[1][1] - '0';
if((fct < 1) || (fct > 9)) {
printf("-d: 0 < d < 10\n");
exit();
}
argv++;
argc--;
} else {
fct = 1;
}
f = 0;
while(++f < argc) {
file = open(argv[f], 0);
edl(file, fct);
close(file);
psw = 0;
}
flsh(0);
exit();
}
int lno 1;
edl(file)
{
auto t,l;
char static buf[20],fld[20],line[200];
char c;
field:
t = -1;
while(((buf[++t] = get(file)) != '\t') && (buf[t] != -1))
if(buf[t] == '\0') goto done;
if((c = buf[t]) == -1) c = ' ';
buf[t] = '\0';
if(comp(buf,fld)) {
lno++;
goto junk;
} else {
if(lno == 0) {
put(0,line,++l);
}
l = copy(buf,line);
copy(buf,fld);
line[--l] = c;
lno = 0;
goto fill;
}
fill:
while((line[++l] = get(file)) != '\n') {
if(line[l] == -1) line[l] = ' ';
if(line[l] == '\0') goto done;
}
goto field;
junk:
while((*line = get(file)) != '\n')
if(*line == '\0') goto done;
goto field;
done:
if(lno == 0)
put(0,line,++l);
lno = 1;
return(0);
}
gfld(file, buf)
char *buf;
{
char c;
buf--;
while(*++buf = get(file)) {
if((*buf == '\t') || (*buf == '\n')) {
c = *buf;
*buf = '\0';
return(c);
} else {
continue;
}
}
return('\0');
}
copy(a, b)
char *a,*b;
{
char *c;
b--;
c = --a;
while(*++b = *++a);
return(a - c);
}
comp(a, b)
char *a, *b;
{
/* printf("comp: %s %s\n",a,b); /*DEBUG*/
a--;
b--;
while(*++a == *++b) {
if(*a == '\0') return(1);
}
return(0);
}
char buf[512];
int nread 1;
get(ifile) int ifile;
{
char static *ibuf;
if(--nread){
return(*ibuf++);
}
if(nread = read(ifile,buf,512)){
if(nread < 0)goto err;
ibuf = buf;
return(*ibuf++);
}
nread = 1;
return(0);
err:
nread = 1;
printf("read error\n");
return(0);
}
int tp[1] 1;
int optr[4];
char bsp[512];
char *obuf[1] bsp;
int nflush;
put(fil,string,n)
char *string;
{
int i;
char *o;
/*printf("%d %c %d\n",fil,*string,n);/*DEBUG*/
string--;
if((i = optr[fil] + n - 512) >= 0) {
n =- i;
o = &obuf[fil][optr[fil]] -1;
while(--n >= 0)
*++o = *++string;
optr[fil] = 512;
flsh(fil);
n = i;
}
o = &obuf[fil][optr[fil]] - 1;
optr[fil] =+ n;
while(--n >= 0) {
*++o = *++string;
}
return(0);
}
flsh(fil)
{
extern tp[];
if(optr[fil] <= 0) return(optr[fil]);
nflush++;
if(write(tp[fil],obuf[fil],optr[fil]) != optr[fil])
return(-1);
optr[fil] = 0;
return(0);
}
+214
View File
@@ -0,0 +1,214 @@
skip
collect save
skip2 sk
cont coll save out asym agobl csym cgobl incl decl sk2 sk
collect/'/agobl;
collect/"/agobl;
collect/</agobl;
collect/\//agobl;
collect/\\/agobl;
collect/:/asym;
collect/a/cont;
collect/b/cont;
collect/c/cont;
collect/d/cont;
collect/e/cont;
collect/f/cont;
collect/g/cont;
collect/h/cont;
collect/i/cont;
collect/j/cont;
collect/k/cont;
collect/l/cont;
collect/m/cont;
collect/n/cont;
collect/o/cont;
collect/p/cont;
collect/q/cont;
collect/r/cont;
collect/s/cont;
collect/t/cont;
collect/u/cont;
collect/v/cont;
collect/w/cont;
collect/x/cont;
collect/y/cont;
collect/z/cont;
collect/A/cont;
collect/B/cont;
collect/C/cont;
collect/D/cont;
collect/E/cont;
collect/F/cont;
collect/G/cont;
collect/H/cont;
collect/I/cont;
collect/J/cont;
collect/K/cont;
collect/L/cont;
collect/M/cont;
collect/N/cont;
collect/O/cont;
collect/P/cont;
collect/Q/cont;
collect/R/cont;
collect/S/cont;
collect/T/cont;
collect/U/cont;
collect/V/cont;
collect/W/cont;
collect/X/cont;
collect/Y/cont;
collect/Z/cont;
collect/1/cont;
collect/2/cont;
collect/3/cont;
collect/4/cont;
collect/5/cont;
collect/6/cont;
collect/7/cont;
collect/8/cont;
collect/9/cont;
collect/0/cont;
collect/./cont;
collect/_/cont;
collect/
/out;
skip/'/agobl;
skip/"/agobl;
skip/</agobl;
skip/\//agobl;
skip/\\/agobl;
skip/
/out;
skip/./coll;
skip/_/coll;
skip/a/coll;
skip/b/coll;
skip/c/coll;
skip/d/coll;
skip/e/coll;
skip/f/coll;
skip/g/coll;
skip/h/coll;
skip/i/coll;
skip/j/coll;
skip/k/coll;
skip/l/coll;
skip/m/coll;
skip/n/coll;
skip/o/coll;
skip/p/coll;
skip/q/coll;
skip/r/coll;
skip/s/coll;
skip/t/coll;
skip/u/coll;
skip/v/coll;
skip/w/coll;
skip/x/coll;
skip/y/coll;
skip/z/coll;
skip/A/coll;
skip/B/coll;
skip/C/coll;
skip/D/coll;
skip/E/coll;
skip/F/coll;
skip/G/coll;
skip/H/coll;
skip/I/coll;
skip/J/coll;
skip/K/coll;
skip/L/coll;
skip/M/coll;
skip/N/coll;
skip/O/coll;
skip/P/coll;
skip/Q/coll;
skip/R/coll;
skip/S/coll;
skip/T/coll;
skip/U/coll;
skip/V/coll;
skip/W/coll;
skip/X/coll;
skip/Y/coll;
skip/Z/coll;
skip/0/sk2;
skip/1/sk2;
skip/2/sk2;
skip/3/sk2;
skip/4/sk2;
skip/5/sk2;
skip/6/sk2;
skip/7/sk2;
skip/8/sk2;
skip/9/sk2;
skip2/a/cont;
skip2/b/cont;
skip2/c/cont;
skip2/d/cont;
skip2/e/cont;
skip2/f/cont;
skip2/g/cont;
skip2/h/cont;
skip2/i/cont;
skip2/j/cont;
skip2/k/cont;
skip2/l/cont;
skip2/m/cont;
skip2/n/cont;
skip2/o/cont;
skip2/p/cont;
skip2/q/cont;
skip2/r/cont;
skip2/s/cont;
skip2/t/cont;
skip2/u/cont;
skip2/v/cont;
skip2/w/cont;
skip2/x/cont;
skip2/y/cont;
skip2/z/cont;
skip2/A/cont;
skip2/B/cont;
skip2/C/cont;
skip2/D/cont;
skip2/E/cont;
skip2/F/cont;
skip2/G/cont;
skip2/H/cont;
skip2/I/cont;
skip2/J/cont;
skip2/K/cont;
skip2/L/cont;
skip2/M/cont;
skip2/N/cont;
skip2/O/cont;
skip2/P/cont;
skip2/Q/cont;
skip2/R/cont;
skip2/S/cont;
skip2/T/cont;
skip2/U/cont;
skip2/V/cont;
skip2/W/cont;
skip2/X/cont;
skip2/Y/cont;
skip2/Z/cont;
skip2/0/cont;
skip2/1/cont;
skip2/2/cont;
skip2/3/cont;
skip2/4/cont;
skip2/5/cont;
skip2/6/cont;
skip2/7/cont;
skip2/8/cont;
skip2/9/cont;
skip2/
/out;
skip2/\//agobl;
+217
View File
@@ -0,0 +1,217 @@
skip
collect save
skip2 sk
cont coll save out asym agobl csym cgobl incl decl sk2 sk tab semi
collect/\;/semi;
collect/_/cont;
collect/{/incl;
collect/}/decl;
collect/'/cgobl;
collect/\\/cgobl;
collect/"/cgobl;
collect/a/cont;
collect/b/cont;
collect/c/cont;
collect/d/cont;
collect/e/cont;
collect/f/cont;
collect/g/cont;
collect/h/cont;
collect/i/cont;
collect/j/cont;
collect/k/cont;
collect/l/cont;
collect/m/cont;
collect/n/cont;
collect/o/cont;
collect/p/cont;
collect/q/cont;
collect/r/cont;
collect/s/cont;
collect/t/cont;
collect/u/cont;
collect/v/cont;
collect/w/cont;
collect/x/cont;
collect/y/cont;
collect/z/cont;
collect/A/cont;
collect/B/cont;
collect/C/cont;
collect/D/cont;
collect/E/cont;
collect/F/cont;
collect/G/cont;
collect/H/cont;
collect/I/cont;
collect/J/cont;
collect/K/cont;
collect/L/cont;
collect/M/cont;
collect/N/cont;
collect/O/cont;
collect/P/cont;
collect/Q/cont;
collect/R/cont;
collect/S/cont;
collect/T/cont;
collect/U/cont;
collect/V/cont;
collect/W/cont;
collect/X/cont;
collect/Y/cont;
collect/Z/cont;
collect/1/cont;
collect/2/cont;
collect/3/cont;
collect/4/cont;
collect/5/cont;
collect/6/cont;
collect/7/cont;
collect/8/cont;
collect/9/cont;
collect/0/cont;
collect/
/out;
skip/\;/semi;
skip/_/coll;
skip/ /tab;
skip/{/incl;
skip/}/decl;
skip/*/cgobl;
skip/'/cgobl;
skip/"/cgobl;
skip/\\/cgobl;
skip/
/out;
skip/1/sk2;
skip/2/sk2;
skip/3/sk2;
skip/4/sk2;
skip/5/sk2;
skip/6/sk2;
skip/7/sk2;
skip/8/sk2;
skip/9/sk2;
skip/0/sk2;
skip/a/coll;
skip/b/coll;
skip/c/coll;
skip/d/coll;
skip/e/coll;
skip/f/coll;
skip/g/coll;
skip/h/coll;
skip/i/coll;
skip/j/coll;
skip/k/coll;
skip/l/coll;
skip/m/coll;
skip/n/coll;
skip/o/coll;
skip/p/coll;
skip/q/coll;
skip/r/coll;
skip/s/coll;
skip/t/coll;
skip/u/coll;
skip/v/coll;
skip/w/coll;
skip/x/coll;
skip/y/coll;
skip/z/coll;
skip/A/coll;
skip/B/coll;
skip/C/coll;
skip/D/coll;
skip/E/coll;
skip/F/coll;
skip/G/coll;
skip/H/coll;
skip/I/coll;
skip/J/coll;
skip/K/coll;
skip/L/coll;
skip/M/coll;
skip/N/coll;
skip/O/coll;
skip/P/coll;
skip/Q/coll;
skip/R/coll;
skip/S/coll;
skip/T/coll;
skip/U/coll;
skip/V/coll;
skip/W/coll;
skip/X/coll;
skip/Y/coll;
skip/Z/coll;
skip2/{/incl;
skip2/}/decl;
skip2/a/cont;
skip2/b/cont;
skip2/c/cont;
skip2/d/cont;
skip2/e/cont;
skip2/f/cont;
skip2/g/cont;
skip2/h/cont;
skip2/i/cont;
skip2/j/cont;
skip2/k/cont;
skip2/l/cont;
skip2/m/cont;
skip2/n/cont;
skip2/o/cont;
skip2/p/cont;
skip2/q/cont;
skip2/r/cont;
skip2/s/cont;
skip2/t/cont;
skip2/u/cont;
skip2/v/cont;
skip2/w/cont;
skip2/x/cont;
skip2/y/cont;
skip2/z/cont;
skip2/A/cont;
skip2/B/cont;
skip2/C/cont;
skip2/D/cont;
skip2/E/cont;
skip2/F/cont;
skip2/G/cont;
skip2/H/cont;
skip2/I/cont;
skip2/J/cont;
skip2/K/cont;
skip2/L/cont;
skip2/M/cont;
skip2/N/cont;
skip2/O/cont;
skip2/P/cont;
skip2/Q/cont;
skip2/R/cont;
skip2/S/cont;
skip2/T/cont;
skip2/U/cont;
skip2/V/cont;
skip2/W/cont;
skip2/X/cont;
skip2/Y/cont;
skip2/Z/cont;
skip2/1/cont;
skip2/2/cont;
skip2/3/cont;
skip2/4/cont;
skip2/5/cont;
skip2/6/cont;
skip2/7/cont;
skip2/8/cont;
skip2/9/cont;
skip2/0/cont;
skip2/./cont;
skip2/
/out;
+169
View File
@@ -0,0 +1,169 @@
skip
collect save
skip2
cont coll save out egobl hyphen pno
skip//pno;
skip/
/out;
skip/a/coll;
skip/b/coll;
skip/c/coll;
skip/d/coll;
skip/e/coll;
skip/f/coll;
skip/g/coll;
skip/h/coll;
skip/i/coll;
skip/j/coll;
skip/k/coll;
skip/l/coll;
skip/m/coll;
skip/n/coll;
skip/o/coll;
skip/p/coll;
skip/q/coll;
skip/r/coll;
skip/s/coll;
skip/t/coll;
skip/u/coll;
skip/v/coll;
skip/w/coll;
skip/x/coll;
skip/y/coll;
skip/z/coll;
skip/A/coll;
skip/B/coll;
skip/C/coll;
skip/D/coll;
skip/E/coll;
skip/F/coll;
skip/G/coll;
skip/H/coll;
skip/I/coll;
skip/J/coll;
skip/K/coll;
skip/L/coll;
skip/M/coll;
skip/N/coll;
skip/O/coll;
skip/P/coll;
skip/Q/coll;
skip/R/coll;
skip/S/coll;
skip/T/coll;
skip/U/coll;
skip/V/coll;
skip/W/coll;
skip/X/coll;
skip/Y/coll;
skip/Z/coll;
collect/'/cont;
collect/-/hyphen;
collect/
/out;
collect/a/cont;
collect/b/cont;
collect/c/cont;
collect/d/cont;
collect/e/cont;
collect/f/cont;
collect/g/cont;
collect/h/cont;
collect/i/cont;
collect/j/cont;
collect/k/cont;
collect/l/cont;
collect/m/cont;
collect/n/cont;
collect/o/cont;
collect/p/cont;
collect/q/cont;
collect/r/cont;
collect/s/cont;
collect/t/cont;
collect/u/cont;
collect/v/cont;
collect/w/cont;
collect/x/cont;
collect/y/cont;
collect/z/cont;
collect/A/cont;
collect/B/cont;
collect/C/cont;
collect/D/cont;
collect/E/cont;
collect/F/cont;
collect/G/cont;
collect/H/cont;
collect/I/cont;
collect/J/cont;
collect/K/cont;
collect/L/cont;
collect/M/cont;
collect/N/cont;
collect/O/cont;
collect/P/cont;
collect/Q/cont;
collect/R/cont;
collect/S/cont;
collect/T/cont;
collect/U/cont;
collect/V/cont;
collect/W/cont;
collect/X/cont;
collect/Y/cont;
collect/Z/cont;
skip2/a/coll;
skip2/b/coll;
skip2/c/coll;
skip2/d/coll;
skip2/e/coll;
skip2/f/coll;
skip2/g/coll;
skip2/h/coll;
skip2/i/coll;
skip2/j/coll;
skip2/k/coll;
skip2/l/coll;
skip2/m/coll;
skip2/n/coll;
skip2/o/coll;
skip2/p/coll;
skip2/q/coll;
skip2/r/coll;
skip2/s/coll;
skip2/t/coll;
skip2/u/coll;
skip2/v/coll;
skip2/w/coll;
skip2/x/coll;
skip2/y/coll;
skip2/z/coll;
skip2/A/coll;
skip2/B/coll;
skip2/C/coll;
skip2/D/coll;
skip2/E/coll;
skip2/F/coll;
skip2/G/coll;
skip2/H/coll;
skip2/I/coll;
skip2/J/coll;
skip2/K/coll;
skip2/L/coll;
skip2/M/coll;
skip2/N/coll;
skip2/O/coll;
skip2/P/coll;
skip2/Q/coll;
skip2/R/coll;
skip2/S/coll;
skip2/T/coll;
skip2/U/coll;
skip2/V/coll;
skip2/W/coll;
skip2/X/coll;
skip2/Y/coll;
skip2/Z/coll;
+237
View File
@@ -0,0 +1,237 @@
# include "../mcons.h"
struct {
int cl[NUMC];
}tab[NUMS];
char state[NUMS][SIZS];
char class[NUMC][SIZC];
char act[NUMA][SIZA];
char def[NUMS][SIZA];
char temp[SIZA];
char *st[NUMS];
char *df[NUMS];
char *cl[NUMC];
char *ac[NUMA];
int t1;
int t2;
main(argc,argv) char **argv;
{
extern fin;
char fl,nlfl,c,bfl,fo,brk;
int cs,ca,cc,i,j,cd;
if(argc != 3) {
printf("Usage: mtab input output\n");
exit();
}
if((fo = creat(argv[2],0644)) < 0) {
printf("Output file.\n");
exit();
}
if((fin = open(argv[1],0)) < 0) {
printf("Input file.\n");
exit();
}
nlfl = 1;
i = -1;
while(brk = rword()) {
switch (brk) {
case '\n':
if(nlfl) {
move(temp,state[++i]);
st[i] = &state[i];
} else {
move(temp,def[i]);
df[i] = &def[i];
nlfl = 1;
}
continue;
case ' ':
if(nlfl) {
move(temp,state[++i]);
st[i] = &state[i];
nlfl = 0;
} else {
error(7);
}
continue;
}
}
i = 128;
while(--i) {
class[i][0] = i;
class[i][1] = '\0';
cl[i] = &class[i];
}
cl[0] = &class[0];
bfl = nlfl = 0;
t1 = 0;
t2 = -1;
while(c = getchar()) {
switch(c) {
default:
if(t1 >= NUMA) error(4);
bfl = nlfl = 0;
act[t1][++t2<8?t2:7] = c;
continue;
case '\n':
if(nlfl) break;
nlfl = 1;
case ' ':
if(bfl) continue;
bfl = 1;
act[t1][++t2<8?t2:7] = '\0';
ac[t1] = &act[t1];
t1++;
t2 = -1;
continue;
}
break;
}
if(c == '\0') exit();
i = -1;
while(++i < NUMS) {
if(df[i]) {
cd = find(ac,df[i],NUMA);
j = -1;
while(++j < NUMC)
tab[i].cl[j] = cd;
}
}
fl = 0;
i = -1;
while(c = getchar()) {
switch(c) {
case '\\':
temp[++i] = getchar();
continue;
case '\n':
if(fl != 1) continue;
default:
temp[++i] = c;
continue;
case '/':
temp[++i] = '\0';
i = -1;
switch(fl) {
case 0:
cs = find(st,temp,NUMS);
fl = 1;
continue;
case 1:
cc = find(cl,temp,NUMC);
fl = 2;
continue;
default:
error(1);
}
case ';':
if(fl != 2) error(2);
temp[++i] = '\0';
i = -1;
ca = find(ac,temp,NUMA);
/*printf("%o %o %o\n",cs,cc,ca); /*DEBUG*/
tab[cs].cl[cc] = ca;
fl = 0;
continue;
}
}
i = -1;
while(++i < NUMS)
write(fo,tab[i].cl,256);
}
error(a)
{
printf("Error %d\n",a);
exit();
}
find(a,b,c) char (*a[])[];
char b[];
int c;
{
int i,j;
/* printf("%s\n",b); /*DEBUG*/
i = -1;
while(++i < c) {
/* printf(" %s\n",a[i]); /*DEBUG*/
j = 0;
/* printf("b = %c\ta = %c\n",b[0],(*a[i])[0]); /*DEBUG*/
while(b[j] == (*a[i])[j]) {
if(b[j] == '\0') goto found;
j++;
}
}
found:
return(i);
}
rword() {
char c;
int ct;
ct = -1;
while(c = getchar()) {
switch(c) {
default:
temp[++ct] = c;
continue;
case '\n':
if(ct == -1) return('\0');
case ' ':
temp[++ct] = '\0';
return(c);
}
}
}
move(a,b) char *a;
char *b;
{
while((*b++ = *a++) != '\0');
return;
}