1 /* ------------------- decomp.c -------------------- */
4 * Decompress the application.HLP file
5 * or load the application.TXT file if the .HLP file
15 static DF_BYTECOUNTER bytectr
;
16 static int LoadingASCII
;
17 struct DfHTr
*DfHelpTree
;
20 /* ------- open the help database file -------- */
21 FILE *DfOpenHelpFile(void)
27 /* -------- get the name of the help file ---------- */
28 DfBuildFileName(helpname
, ".hlp");
30 if ((fi
= fopen(helpname
, "rb")) == NULL
) {
31 /* ---- no .hlp file, look for .txt file ---- */
32 if ((cp
= strrchr(helpname
, '.')) != NULL
) {
34 fi
= fopen(helpname
, "rt");
41 if (!LoadingASCII
&& DfHelpTree
== NULL
) {
42 /* ----- read the byte count ------ */
43 fread(&bytectr
, sizeof bytectr
, 1, fi
);
44 /* ----- read the frequency count ------ */
45 fread(&treect
, sizeof treect
, 1, fi
);
46 /* ----- read the root offset ------ */
47 fread(&root
, sizeof root
, 1, fi
);
48 DfHelpTree
= DfCalloc(treect
-256, sizeof(struct DfHTr
));
49 /* ---- read in the tree --- */
50 for (i
= 0; i
< treect
-256; i
++) {
51 fread(&DfHelpTree
[i
].left
, sizeof(int), 1, fi
);
52 fread(&DfHelpTree
[i
].right
, sizeof(int), 1, fi
);
58 /* ----- read a line of text from the help database ----- */
59 void *DfGetHelpLine(char *line
)
65 hp
= fgets(line
, 160, fi
);
71 /* ----- decompress a line from the file ------ */
73 /* ----- walk the Huffman tree ----- */
75 /* --- h is a node pointer --- */
77 /* --- read 8 bits of compressed data --- */
78 if ((in8
= fgetc(fi
)) == EOF
) {
84 /* -- point to left or right node based on msb -- */
86 h
= DfHelpTree
[h
-256].left
;
88 h
= DfHelpTree
[h
-256].right
;
89 /* --- shift the next bit in --- */
93 /* --- h < 255 = decompressed character --- */
95 continue; /* skip the '\r' character */
96 /* --- put the character in the buffer --- */
98 /* --- if '\n', end of line --- */
102 *line
= '\0'; /* null-terminate the line */
106 /* --- compute the database file byte and bit position --- */
107 void DfHelpFilePosition(long *offset
, int *bit
)
119 /* -- position the database to the specified byte and bit -- */
120 void DfSeekHelpLine(long offset
, int bit
)
123 fseek(fi
, offset
, 0);
128 for (i
= 0; i
< bit
; i
++)