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
+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);
}