* Uncompact adaptive Huffman code input to output
* Input file does not contain decoding tree
* Written by Colin L. Mc Master (UCB) February 14, 1979
for (head
= dir
+ (j
= 513); j
--; ) {
bottom
= dirp
-> pt
= dict
;
dict
[0] . top
[0] = dict
[0] . top
[1] = dirp
;
in
[EF
] . flags
= FBIT
| SEEN
;
(bottom
-> top
[1]) -> next
= flist
;
bottom
-> top
[1] = dirp
;
for (j
= 0; j
< (LNAME
- 3) && (*cp
= argv
[i
][j
]); j
++)
if (cp
[-1] == 'C' && cp
[-2] == '.') cp
[-2] = 0;
fprintf (stderr
, "%s: File name must end with \".C\"\n", argv
[i
]);
if (i
== argc
- 1) break;
if (j
>= (LNAME
- 3) || (j
- m
) > 15) {
fprintf (stderr
, "File name too long -- %s\n", argv
[i
]);
if (i
== argc
- 1) break;
if ((cfp
= fopen (argv
[i
], "r")) == NULL
) {
if (i
== argc
- 1) break;
if ((uncfp
= fopen (fname
, "w")) == NULL
) {
if (i
== argc
- 1) break;
fstat (fileno (cfp
), &status
);
chmod (fname
, status
.st_mode
& 07777);
if ((c
. integ
= getc (cfp
)) != EOF
) {
if ((d
. integ
= getc (cfp
)) != EOF
) {
c
. chars
. hib
= d
. integ
& 0377;
if (c
. integ
!= COMPACTED
) goto notcompact
;
if ((c
. integ
= getc (cfp
)) != EOF
) {
putc (c
. chars
. lob
, uncfp
);
in
[NC
] . fp
= in
[EF
] . fp
= dict
[0] . sp
[0] . p
= bottom
= dict
+ 1;
bottom
-> count
[0] = bottom
-> count
[1] = dict
[0] . count
[1] = 1;
dirp
-> next
= dict
[0] . top
[1] = bottom
-> top
[0] = bottom
-> top
[1] = dirq
= NEW
;
dict
[0] . fath
. fp
= NULL
;
dirq
-> pt
= bottom
-> fath
. fp
= in
[c
. integ
] . fp
= dict
;
in
[c
. integ
] . flags
= (FBIT
| SEEN
);
dict
[0] . fath
. flags
= RLEAF
;
bottom
-> fath
. flags
= (LLEAF
| RLEAF
);
dict
[0] . count
[0] = 2;
dict
[0] . sp
[1] . ch
= c
. integ
;
bottom
-> sp
[0] . ch
= NC
;
bottom
-> sp
[1] . ch
= EF
;
while ((c
. integ
= getc (cfp
)) != EOF
) {
b
= (m
& c
. integ
? 1 : 0);
if (p
-> fath
. flags
& (b
? RLEAF
: LLEAF
)) {
d
. integ
= p
-> sp
[b
] . ch
;
if (d
. integ
== EF
) break;
for (j
= 8; j
--; m
>>= 1) {
if (m
& c
. integ
) d
. integ
++;
putc (d
. chars
. lob
, uncfp
);
else p
= p
-> sp
[b
] . p
;
notcompact
: if (i
< argc
) {
fprintf (stderr
, "%s: ", argv
[i
]);
if (c
. integ
== PACKED
) fprintf (stderr
, "File is packed. Use unpack.\n");
else fprintf (stderr
, "Not a compacted file.\n");
if (ferror (uncfp
) || ferror (cfp
))
fprintf (stderr
, "Unable to uncompact %s\n", argv
[i
]);
fprintf (stderr
, "%s uncompacted to %s\n", argv
[i
], fname
);
closeboth
: fclose (cfp
);
closein
: fclose (uncfp
);
if (i
== argc
- 1) break;
for (j
= 256; j
--; ) in
[j
] . flags
= 0;
fail
: fprintf (stderr
, "Unsuccessful uncompact of standard input to standard output.\n");