%%s 0/0/0 %%d D 1.1 25-Mar-82 12:02:57 v1.1 1 0 %%c Version 1.1 is the Spring 1982 Distribution of the LBL/Hughes release %%c of the Software Tools Virtual Operating System software and documentation. %%T %%I 1 #-h- cprsym 244 asc 25-mar-82 07:28:52 v1.1 (sw-tools v1.1) # symbols for compress and expand tools # put on a file called 'cprsym' # Used only by compress and expand #must have RCODE > (MAXCHUNK + BLANK) or RCODE = 0 define(RCODE,125) define(MAXCHUNK,arith(RCODE,-,incr(' '))) define(THRESH,4) #-h- cpress.r 1915 asc 25-mar-82 07:28:55 v1.1 (sw-tools v1.1) #-h- main 524 asc 25-mar-82 07:28:25 v1.1 (sw-tools v1.1) ## cpress - compress input files include cprsym DRIVER(cpress) character buf(MAXLINE) integer getarg, open integer i #must have RCODE > (MAXCHUNK + ' ') or RCODE = 0 call query("usage: cpress [file] ...") for (i=1; ; i=i+1) { if (getarg(i,buf,MAXLINE) == EOF) { if (i != 1) break int = STDIN } else if (buf(1) == '-' & 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 #-h- press 702 asc 25-mar-82 07:28:27 v1.1 (sw-tools v1.1) ## 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 putcnt(nrep) } } call putbuf(buf, nsave) #put last chunk return end #-h- putbuf 246 asc 25-mar-82 07:28:28 v1.1 (sw-tools v1.1) ## putbuf - output buf(1) ... buf(nsave), clear nsave subroutine putbuf(buf, nsave) character buf(MAXCHUNK) integer i, nsave if (nsave > 0) { call putcnt(nsave) for (i=1; i<=nsave; i=i+1) call putc(buf(i)) } nsave = 0 return end #-h- putcnt 151 asc 25-mar-82 07:28:30 v1.1 (sw-tools v1.1) ## putcnt - output integer offset by ' ' as a character subroutine putcnt(int) integer int character c c = int + ' ' call putc(c) return end #-h- cpress.fmt 526 asc 25-mar-82 07:28:58 v1.1 (sw-tools v1.1) .so ~bin/manhdr .hd Cpress (1) 15-Jan-79 compress input files .sy cpress [file] ... .ds cpress compresses runs of repeated characters in the input files. The output file can eventually be expanded with the tool 'expand'. If no input files are given, or the filename '-' appears, input will be from the standard input. .fl none .sa expand .di A message is printed if an input file cannot be opened; further processing is terminated. .au From Kernighan & Plauger's 'Software Tools', with modifications by Debbie Scherrer. .bu %%E 1