PackIt htest.c

/*		htest

	Main program to test the Huffman encoding module.

	© Copyright 1986 by Harry R. Chesley.
	All rights reserved.
*/

#include <memory.h>

#define MEMSZ 10000L

char bitTab[320];
long bitTabSz;
char *dataPtr;
long dataSz;

main()

{
	char *ptr, *ptrout;
	long pre, tab, data;
	register char *p, *p2;
	register char b;
	long HuffBTable(), BitSize();

	printf("Starting.\n");
	HuffInit();
	ptr = NewPtr(MEMSZ);
	ptrout = NewPtr(MEMSZ);
	dataPtr = NewPtr(MEMSZ);
	for (p = ptr+MEMSZ-1, p2 = ptrout+MEMSZ-1, b=0; p >= ptr; *p-- = b++, *p2-- = 0xEE);
	printf("Before:\n  in: "); pBlock(ptr);
	printf("\n out: "); pBlock(ptrout); printf("\n");
	HuffCount(ptr,MEMSZ);
	HuffCode();
	HuffStat(&pre,&tab,&data);
	printf("Pre size %ld; table size %ld; encoded size %ld.\n",pre,tab,data);
	bitTabSz = HuffBTable(bitTab,320L,0L);
	BitInit(dataPtr,MEMSZ,0L);
	HuffBData(ptr,MEMSZ);
	dataSz = (BitSize()+7)/8L;
	printf("Encoded table size %ld; encoded data size %ld.\n",bitTabSz,dataSz);
	BitInit(bitTab,320L,0L);
	HuffDTable();
	printf("Table decoded.\n");
	BitInit(dataPtr,MEMSZ,0L);
	HuffDData(ptrout,MEMSZ);
	printf("After:\n  in: "); pBlock(ptr);
	printf("\n out: "); pBlock(ptrout); printf("\n");
	for (p = ptr+MEMSZ-1, p2 = ptrout+MEMSZ-1; p >= ptr; p--, p2--)
		if (*p != *p2) printf("Didn't match: %u != %u [%u]!!!\n",*p & 0xFF,*p2 & 0xFF,
							(unsigned) p-ptr);
	printf("All done.\n");
}

pBlock(ptr)

char *ptr;

{
	register char *p;

	for (p = ptr; p < ptr+16; p++) printf("%2x ",*p & 0xFF);
}