static char sccsid
[] = "@(#)uncompact.c 4.8 (Berkeley) 12/21/87";
* Uncompact adaptive Huffman code input to output
* Input file does not contain decoding tree
* Written by Colin L. Mc Master (UCB) February 14, 1979
char *infname
; /* input file's name */
char fname
[MAXPATHLEN
+1]; /* output file's name */
struct stat status
; /* compacted file status */
if (argc
> 0 && strcmp(*argv
, "-v") == 0) {
for (head
= dir
+ (j
= 513); j
--; ) {
bottom
= dirp
->pt
= dict
;
dict
[0].sons
[LEFT
].top
= dict
[0].sons
[RIGHT
].top
= dirp
;
in
[EF
].flags
= FBIT
| SEEN
;
for (j
= 0; j
< argc
; j
++) {
printf("%s uncompacted to %s\n", argv
[j
], fname
);
bottom
->sons
[RIGHT
].top
->next
= flist
;
bottom
->sons
[RIGHT
].top
= dirp
;
if (strcmp(file
, "-") != 0) {
if (cp
== 0 || strcmp(cp
, ".C") != 0) {
"uncompact: %s: File must have .C suffix.\n", file
);
fprintf(stderr
, "uncompact: "), perror(file
);
(void) fstat(fileno(cfp
), &status
);
uncfp
= setup(cfp
, &ignore
);
if (ferror(uncfp
) || ferror(cfp
)) {
fprintf(stderr
, "uncompact: ");
"Unsuccessful uncompact of standard input to standard output.\n");
if (uncfp
!= stdout
&& unlink(infname
) < 0)
fprintf(stderr
, "uncompact: "), perror(infname
);
if (uncfp
!= NULL
&& uncfp
!= stdout
)
register FILE *cfp
, *uncfp
;
register union cio
*dp
= &d
;
while ((c
.integ
= getc (cfp
)) != EOF
) {
b
= (m
& c
.integ
? 1 : 0);
if (p
->fath
.flags
& (b
? RLEAF
: LLEAF
)) {
dp
->integ
= p
->sons
[b
].sp
.ch
;
for (j
= 8; j
--; m
>>= 1) {
putc(dp
->chars
.lob
, uncfp
);
register union cio
*dp
= &d
;
register union cio
*cp
= &c
;
dp
->chars
.hib
= cp
->integ
& 0377;
if ((dp
->integ
&= 0177777) != COMPACTED
) {
fprintf(stderr
, "uncompact: ");
fprintf(stderr
, "%s: File is packed, use unpack.\n",
fprintf(stderr
, "%s: Not a compacted file.\n", infname
);
if (strcmp(infname
, "-") != 0) {
uncfp
= fopen(fname
, "w");
(void) fchmod(fileno(uncfp
), status
.st_mode
);
putc(cp
->chars
.lob
, uncfp
);
in
[NC
].fp
= in
[EF
].fp
= dict
[0].sons
[LEFT
].sp
.p
= bottom
= dict
+ 1;
bottom
->sons
[LEFT
].count
= bottom
->sons
[RIGHT
].count
=
dict
[0].sons
[RIGHT
].count
= 1;
dirp
->next
= dict
[0].sons
[RIGHT
].top
= bottom
->sons
[LEFT
].top
=
bottom
->sons
[RIGHT
].top
= dirq
= NEW
;
dirq
->pt
= bottom
->fath
.fp
= in
[cp
->integ
].fp
= dict
;
in
[cp
->integ
].flags
= (FBIT
| SEEN
);
dict
[0].fath
.flags
= RLEAF
;
bottom
->fath
.flags
= (LLEAF
| RLEAF
);
dict
[0].sons
[LEFT
].count
= 2;
dict
[0].sons
[RIGHT
].sp
.ch
= cp
->integ
;
bottom
->sons
[LEFT
].sp
.ch
= NC
;
bottom
->sons
[RIGHT
].sp
.ch
= EF
;
fprintf(stderr
, "uncompact: ");
if (uncfp
&& uncfp
!= stdout
) {