Add original unix v6
This commit is contained in:
@@ -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;
|
||||
@@ -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
|
||||
@@ -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;
|
||||
}
|
||||
@@ -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);
|
||||
}
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user