/* Copyright (C) 1991, Marcus J. Ranum. All rights reserved. */ #ifndef lint static char RCSid[] = "$Header: /usr/users/mjr/hacks/umud/DB/RCS/comp.c,v 1.1 91/07/04 17:33:08 mjr Rel $"; #endif #include "config.h" #include <stdio.h> #include "comp.h" static char ctab[128][128]; void comp_init() { int i; int j; for(i = 0; i < 128; i++) for(j = 0; j < 128; j++) ctab[i][j] = 0; for(i = 0; i < 128; i++) ctab[ctok[i][0]][ctok[i][1]] = i | 0x80; } compress(fin,fout) FILE *fin; FILE *fout; { char c; char nxt = -1; while(1) { if(nxt == -1) c = getc(fin); else c = nxt; nxt = getc(fin); if(ferror(fin) || feof(fin)) { if(c != -1) putc(c,fout); return(ferror(fin) == 0); } if(ctab[c][nxt]) { if(fputc(ctab[c][nxt],fout) == EOF) return(1); nxt = -1; } else { if(fputc(c,fout) == EOF) return(1); } } } decompress(fin,fout) FILE *fin; FILE *fout; { char c; while(1) { c = getc(fin); if(feof(fin) || ferror(fin)) return(ferror(fin) == 0); if(c & 0x80) { putc(ctok[c & 0x7f][0],fout); putc(ctok[c & 0x7f][1],fout); } else putc(c,fout); } } main(ac,av) int ac; char *av[]; { char *p; extern char *rindex(); comp_init(); if(ac < 2) exit(compress(stdin,stdout)); else exit(decompress(stdin,stdout)); }