HUFFMAN 3
NAME
huffman - huffman coding/decoding
SYNOPSIS


#include <huffman.h>

Huff_t *huffinit(Sfio_t *file, long size)
Huff_t *huffgethdr(Sfio_t *file)
int huffputhdr(Huff_t *ptr, Sfio_t *file)
int huffencode(Huff_t *ptr, Sfio_t *infile, Sfio_t *outfile, int size)
int huffdecode(Huff_t *ptr, Sfio_t *infile, Sfio_t *outfile, int size)
int huffend(Huff_t *ptr)
long huffisize(Huff_t *ptr)
long huffosize(Huff_t *ptr)
int huffhsize(Huff_t *ptr)

DESCRIPTION

The huffman routines can be used to pack and unpack files or strings using static huffman encoding. The huffint routine counts the frequency of the first size characters in file and returns an encoded table based on these frequencies. The file argument can refer to a file or string that has been opened with dfopen (3). If size is less than zero, the complete file or string will be used. When successful, huffinit returns a pointer to an encoded huffman table which can be used as the first argument to other huffman routines. Otherwise, huffinit returns a null pointer and the errno variable contains the cause of the error.

huffputhdr writes the encoding information to file in the format used by the pack (1) utility. When successful, huffputhdr returns the number of bytes written. Otherwise, huffputhdr returns -1 and the errno variable contains the cause of the error.

huffgethdr reads from file and builds the encoding table. The information in file must be in the format produced by huffputhdr . When successful, huffgethdr returns a pointer to an encoded huffman table which can be used as the first argument to other huffman routines. Otherwise, huffgethdr returns a null pointer and the errno variable contains the cause of the error.

huffencode encodes infile using the huffman codes contained in ptr and writes the encoded result onto outfile . The size arguments specifies the number of bytes from infile that will be encoded. The whole file will be encoded if size is less than zero. When successful, huffencode returns the number of bytes written. Otherwise, huffencode returns -1 and the errno variable contains the cause of the error. When successful,

huffdecode decodes infile using the huffman codes contained in ptr and writes the decoded results onto outfile . The size arguments specifies the number maximum number of bytes that will be decoded and written to outfile . The whole file will be decoded if size is less than zero. huffdecode returns the number of bytes decoded. Otherwise, huffdecode returns -1 and the errno variable contains the cause of the error.

huffisize , huffosize , and huffhsize provide the size of the input file, the output file, and the header respectively.

HISTORY
huffman is a library interface that can be used to implement the pack and unpack utilities provided in System V. The code was derived from the pack and unpack utilities but was substantially rewritten to provide better performance and to utilize the sfio library. It can also be use to encode and decode strings.
AUTHOR
David Korn
SEE ALSO
pack(1), unpack(1), sfio(3).