2 ********************************************************************************
5 * RCS: $Header: /home/matthew/cvs/bible-kjv-4.10/buildcmp.c,v 2.6 2005/01/22 18:23:16 matthew Exp $
6 * Description: Build compressed data file
7 * Author: Chip Chapin, Hewlett Packard Company
8 * Created: Mon May 29 17:34:58 1989
9 * Modified: Mon Apr 26 11:15:20 1993 (Chip Chapin) chip@hpclbis
11 * Package: Bible Retrieval System
12 * Status: Experimental (Do Not Distribute)
14 ********************************************************************************
18 * Fri Apr 23 09:34:07 1993 (Chip Chapin) chip@hpclbis
19 * put_header modified to use Univ_Int portable data type.
20 * Wed Dec 23 13:57:38 1992 (Chip Chapin) chip@hpclbis
21 * Tweak to eliminate compile warning.
22 *******************************************************************************
23 * $Log: buildcmp.c,v $
24 * Revision 2.6 2005/01/22 18:23:16 matthew
27 * Revision 2.5 2005/01/22 17:57:33 matthew
28 * prototype functions properly
30 * Revision 2.4 2005/01/22 16:54:50 matthew
31 * we don't use command-line arguments so declare main (void)
33 * Revision 2.3 2005/01/22 00:34:42 matthew
34 * tidy up, and pass univ_assign *winx++, as that's the right type
36 * Revision 2.2 2003/02/22 16:00:03 matthew
37 * correct prototype of main(), and make it return correctly
39 * Revision 2.1 2003/01/09 12:59:10 matthew
40 * Add error checking to the fopen calls
42 * Revision 2.0 2003/01/08 15:29:52 matthew
43 * versions collected from the net
45 * Revision 1.5 93/04/26 11:18:16 11:18:16 chip (Chip Chapin)
47 * Public release of portable datafile version.
49 * Revision 1.4 93/04/23 13:08:06 13:08:06 chip (Chip Chapin)
51 * This version supports portable data files, usable on machines with
52 * differing native byte-orders.
53 * Also, this version compiles and runs on non-HPUX systems. It has been
54 * tested on SunOS 4.? and ULTRIX 4.?, using SPARC and DEC 3100 hardware
55 * respectively. Note that the data file format has rolled again.
57 * Revision 1.3 92/12/23 14:10:45 14:10:45 chip (Chip Chapin)
58 * Release 2.03: minor tweaks and bug fixes.
60 * Revision 1.2 89/09/14 20:33:56 20:33:56 chip (Chip Chapin)
61 * Release 1-2. Supports -f and -l options for formatting the output.
62 * Updates primarily brl.c, bible.c, and bible.1.
64 * Revision 1.1 89/09/05 17:49:23 17:49:23 chip (Chip Chapin)
77 static void put_header(void);
78 static void put_data(void);
80 struct tsl_fileheader fh;
81 FILE *sf, *df, *of; /* stats file, data file, output file */
83 static void put_header(void)
86 int headersize, tablesize;
90 fh.magic[0] = TSL_MAGIC1;
91 fh.magic[1] = TSL_MAGIC2;
92 fh.version[0] = TSL_FVERSION1;
93 fh.version[1] = TSL_FVERSION2;
94 strncpy( fh.description, "Compressed Data File", TSL_DESCRSZ );
96 /* Process the squish statistics */
97 fread( &d, sizeof(int), 1, sf );
98 printf( "Window size (bytes): %d\n", d );
99 univ_assign(fh.wsize, d);
100 fread( &d, sizeof(int), 1, sf );
101 printf( "Number of windows: %d\n", d );
103 univ_assign(fh.wnum, d);
105 fwrite( &fh, sizeof(fh), 1, of );
107 tablesize = sizeof(int)*(count+1); /* +1 for terminating entry */
108 headersize = sizeof(fh) + tablesize;
109 w_table = (int*) malloc( tablesize );
110 winx = (Univ_Int *) w_table;
112 for (i=0; i <= count; i++) {
113 fread( &d, sizeof(int), 1, sf );
114 univ_assign(*winx++, j=d+headersize);
115 printf( "Window[%d] starts at %d\n", i, j );
117 fwrite( w_table, tablesize, 1, of );
120 static void put_data(void)
124 while ( (c = getc(df)) != EOF ) putc(c, of);
130 if(NULL==(sf = fopen( "squish.stats", "r" ))){
131 fprintf(stderr,"Failed to open squish.stats: %s\n",strerror(errno));
134 if(NULL==(df = fopen( "squish.data", "r" ))){
135 fprintf(stderr,"Failed to open squish.data: %s\n",strerror(errno));
138 if(NULL==(of = fopen( "squish.output", "w" ))){
139 fprintf(stderr,"Failed to open squish.output: %s\n",strerror(errno));