Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
att
GitHub Repository: att/ast
Path: blob/master/src/cmd/pack/huffputhdr.c
1808 views
1
/***********************************************************************
2
* *
3
* This software is part of the ast package *
4
* Copyright (c) 1993-2011 AT&T Intellectual Property *
5
* and is licensed under the *
6
* Eclipse Public License, Version 1.0 *
7
* by AT&T Intellectual Property *
8
* *
9
* A copy of the License is available at *
10
* http://www.eclipse.org/org/documents/epl-v10.html *
11
* (with md5 checksum b35adb5213ca9657e911e9befb180842) *
12
* *
13
* Information and Software Systems Research *
14
* AT&T Research *
15
* Florham Park NJ *
16
* *
17
* David Korn <[email protected]> *
18
* *
19
***********************************************************************/
20
#pragma prototyped
21
/*
22
* huffman coding routine to write pack format file header
23
*
24
* David Korn
25
* AT&T Laboratories
26
*/
27
28
#include "huffman.h"
29
30
/*
31
* This routine outputs a pack format header to <outfile> and returns
32
* the number of bytes in the header
33
*/
34
35
int huffputhdr(register Huff_t *hp,Sfio_t *outfile)
36
{
37
register int i, c;
38
register Sfio_t *fp = outfile;
39
/* output magic number */
40
sfputc(fp,HUFFMAG1);
41
sfputc(fp,HUFFMAG2);
42
if(sizeof(Sfoff_t)>4 && hp->insize >= ((Sfoff_t)1)<<(4*CHAR_BIT))
43
{
44
sfputc(fp,hp->insize>>(7*CHAR_BIT));
45
sfputc(fp,hp->insize>>(6*CHAR_BIT));
46
sfputc(fp,hp->insize>>(5*CHAR_BIT));
47
sfputc(fp,hp->insize>>(4*CHAR_BIT));
48
sfputc(fp,0);
49
}
50
/* output the length and the dictionary */
51
sfputc(fp,hp->insize>>(3*CHAR_BIT));
52
sfputc(fp,hp->insize>>(2*CHAR_BIT));
53
sfputc(fp,hp->insize>>(CHAR_BIT));
54
sfputc(fp,hp->insize);
55
/* output number of levels and count for each level */
56
sfputc(fp,hp->maxlev);
57
for (i=1; i<hp->maxlev; i++)
58
sfputc(fp,hp->levcount[i]);
59
sfputc(fp,hp->levcount[hp->maxlev]-2);
60
/* output the characters */
61
for (i=1; i<=hp->maxlev; i++)
62
for (c=0; c < (1<<CHAR_BIT); c++)
63
if (hp->length[c] == i)
64
sfputc(fp,c);
65
return(huffhsize(hp));
66
}
67
68