endline char in(0), out(0) int lf [ char unit(300), tounit(300), c int signal if(fopen(1,in,0,unit))return if(fopen(2,out,0,tounit))return char newend(1), endnew(0), eof(0) newend(0)=13; newend(1)=10 /*new end-of-line token endnew = newend + (lf!=0) /*end of end-of-line token eof(0)=26 /*end-of-file token gbend=pbend=0 /*required initial values /* this loop processes each token of the file while(signal==0)[ c=gettok(unit) if(c==13)signal=puttok(tounit,newend,endnew) else if(c==26)[ signal=puttok(tounit,eof,eof) prefcb tounit if(signal==0)fclose(tounit) prefcb tounit break ] else signal=puttok(tounit,gtokbeg,gtokend) ] ] /* puts a token, using a double buffering technique. /* unit is big enough for an efcb plus two buffers. char gbend(0), pbend(0) /*get and put buffers end of /* valid contents char gtokbeg(0), gtokend(0) /*get token beginning and end puttok char unit(291),f(0),l(0) [ if(pbend==0)pbend=unit+36 int signal movebl(f,l,pbend-f) /* move token into buffer pbend=pbend+l-f+1 /* advance put-buff-end by token length if(pbend-unit>163)[ /* test if first buffer is full signal=fwrite(unit+36,unit+163,unit) /* full, so write it pft unit+36, unit+163 movebl(unit+164,unit+291,-128) /*move 2nd buff -> 1st pbend=pbend-128 ] if(f(0)==26)[ /* end-of-file processing if(signal)return signal /*just in case if(pbend-unit == 36)return /*no partial record signal=fwrite(unit+36,unit+163,unit) pft unit+36, pbend-1 ] return signal ] /* gets a token, using double buffering technique. Returns /* new values for global variables gtokbeg and gtokend /* pointing to begining and end of new token. /* Returns first char of token as value of gettok. gettok char unit(291) [ int length if(gbend==0)[ /*signals initial call gbend=gtokend=unit+163 length=fread(unit+164,unit) if(length<0)return 26 /*empty file case gbend=gbend+length /*points to last good byte ] gtokbeg=gtokend+1 /* l pointed to last byte of previous token. /* So make gtokbeg point to first byte after gtokend if(gtokbeg-unit>163[ /* if gtokbeg -> 2nd block, then can movebl(unit+164,unit+291,-128) /*move it down and read gtokbeg=gtokbeg-128 /*another record length=fread(unit+164,unit) if(length<0)gbend=gbend-128 /*nothing read, so move /* gbend down too else gbend=unit+163+length ] return scantok(gtokbeg,gbend) ] /* scans for the end of a token, and returns the tokens type. /* from points to the tokens beginning, to to the end of usable /* text. tokend is to be returned as the tokens end. scantok char from(0), to(0) [ int n(0) /* used by scann n(0)=1 if(from>to)return 26 /*empty string returns end-of-file if(from(0)==13)[ /*end-of-line token gtokend=from while(gtokend(1)==10)gtokend=gtokend+1 ] else gtokend=scann(from,to,13,n) + from - 1 return from(0) ] main[ endline "x, "y, 1 ]