home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
ftp.barnyard.co.uk
/
2015.02.ftp.barnyard.co.uk.tar
/
ftp.barnyard.co.uk
/
cpm
/
walnut-creek-CDROM
/
CPM
/
CUG
/
SOFTT-5.LBR
/
CPRESS.RQT
/
CPRESS.RAT
Wrap
Text File
|
2000-06-30
|
3KB
|
95 lines
#-h- cpress.r 3024 local 12/15/80 13:17:58
#-h- cpress 1161 local 12/15/80 11:50:40
## cpress - compress input files
# These definitions are used by both the cpress and expand tools
#must have RCODE > MAXCHUNK or RCODE = 0
define(MAXCHUNK,124)
define(RCODE,125)
define(THRESH,4)
# include ratdef
DRIVER(cpress)
character buf(MAXLINE)
integer getarg, open
integer i
#must have RCODE > MAXCHUNK or RCODE = 0
call query ('usage: cpress [files].')
for (i=1; ; i=i+1)
{
if (getarg(i,buf,MAXLINE) == EOF)
{
if (i != 1)
break
int = STDIN
}
else if (buf(1) == MINUS & buf(2) == EOS)
int = STDIN
else
{
int = open(buf,READ)
if (int == ERR)
call cant(buf)
}
call press (int)
if (int != STDIN)
call close(int)
}
DRETURN
end
#-t- cpress 1161 local 12/15/80 11:50:40
#-h- press 1101 local 12/15/80 11:50:41
## press - compress file -int-
subroutine press (int)
character getch
character buf(MAXCHUNK), c, lastc
integer int, nrep, nsave
#must have RCODE > MAXCHUNK or RCODE = 0
nsave = 0
for (lastc=getch(lastc,int); lastc != EOF; lastc = c)
{
for (nrep=1; getch(c,int) == lastc; nrep = nrep + 1)
if (nrep >= MAXCHUNK) #count repetitions
break
if (nrep < THRESH) #append short string
for (; nrep > 0; nrep = nrep - 1)
{
nsave = nsave + 1
buf(nsave) = lastc
if (nsave >= MAXCHUNK)
call putbuf(buf, nsave)
}
else
{
call putbuf(buf, nsave)
call putc (RCODE)
call putc(lastc)
call putc(nrep)
}
}
call putbuf(buf, nsave) #put last chunk
return
end
#-t- press 1101 local 12/15/80 11:50:41
#-h- putbuf 366 local 12/15/80 11:50:41
## putbuf - output buf(1) ... buf(nsave), clear nsave
subroutine putbuf(buf, nsave)
character buf(MAXCHUNK)
integer i, nsave
if (nsave > 0)
{
call putc (nsave)
for (i=1; i<=nsave; i=i+1)
call putc(buf(i))
}
nsave = 0
return
end
#-t- putbuf 366 local 12/15/80 11:50:41
#-t- cpress.r 3024 local 12/15/80 13:17:58
#-t- cpress 4063 local 01/09/81 00:44:51
if (nsave >= MAXCHUNK)