chiark / gitweb /
document changes to make version 4.26
[bible-kjv.git] / buildcmp.c
1 /* -*-C-*-
2 ********************************************************************************
3 *
4 * File:         buildcmp.c
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
10 * Language:     C
11 * Package:      Bible Retrieval System
12 * Status:       Experimental (Do Not Distribute)
13 *
14 ********************************************************************************
15 *
16 * Revisions:
17 *
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
25 * include stdlib.h
26 *
27 * Revision 2.5  2005/01/22 17:57:33  matthew
28 * prototype functions properly
29 *
30 * Revision 2.4  2005/01/22 16:54:50  matthew
31 * we don't use command-line arguments so declare main (void)
32 *
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
35 *
36 * Revision 2.2  2003/02/22 16:00:03  matthew
37 * correct prototype of main(), and make it return correctly
38 *
39 * Revision 2.1  2003/01/09 12:59:10  matthew
40 * Add error checking to the fopen calls
41 *
42 * Revision 2.0  2003/01/08 15:29:52  matthew
43 * versions collected from the net
44 *
45  * Revision 1.5  93/04/26  11:18:16  11:18:16  chip (Chip Chapin)
46  * Release 4.00
47  * Public release of portable datafile version.
48  * 
49  * Revision 1.4  93/04/23  13:08:06  13:08:06  chip (Chip Chapin)
50  * PORTABILITY RELEASE
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.
56  * 
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.
59  * 
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.
63  * 
64  * Revision 1.1  89/09/05  17:49:23  17:49:23  chip (Chip Chapin)
65  * Initial revision
66  * 
67 *
68 */
69
70 #include <stdio.h>
71 #include <string.h>
72 #include <stdlib.h>
73 #include <errno.h>
74 #include "tsl.h"
75 #include "util.h"
76
77 static void put_header(void);
78 static void put_data(void);
79
80 struct tsl_fileheader fh;
81 FILE *sf, *df, *of;     /* stats file, data file, output file */
82
83 static void put_header(void)
84 {
85     int  i, j, count, d;
86     int headersize, tablesize;
87     int *w_table;
88     Univ_Int *winx;
89     
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 );
95     
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 );
102     count = d;
103     univ_assign(fh.wnum, d);
104
105     fwrite( &fh, sizeof(fh), 1, of );
106
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;
111
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 );
116     }
117     fwrite( w_table, tablesize, 1, of );
118 }
119
120 static void put_data(void)
121 {
122     int c;
123     
124     while ( (c = getc(df)) != EOF ) putc(c, of);
125 }
126
127 int main(void)
128 {
129     
130   if(NULL==(sf = fopen( "squish.stats",  "r" ))){
131     fprintf(stderr,"Failed to open squish.stats: %s\n",strerror(errno));
132     exit(1);
133   }
134   if(NULL==(df = fopen( "squish.data",   "r" ))){
135     fprintf(stderr,"Failed to open squish.data: %s\n",strerror(errno));
136     exit(1);
137   }
138   if(NULL==(of = fopen( "squish.output", "w" ))){
139     fprintf(stderr,"Failed to open squish.output: %s\n",strerror(errno));
140     exit(1);
141   }
142
143     put_header();
144     put_data();
145
146     fclose( sf );
147     fclose( df );
148     fclose( of );
149     exit(0);
150 }
151