2 *******************************************************************************
5 * RCS: $Header: /home/matthew/cvs/bible-kjv-4.10/makeindex.c,v 2.6 2005/01/23 11:23:15 matthew Exp $
6 * Description: Create Line Index to Text File
7 * Author: Chip Chapin, Hewlett Packard Company
9 * Modified: Thu Sep 14 12:37:15 1989 (Chip Chapin) chip@hpcllcc
11 * Package: Bible Retrieval System
12 * Status: Experimental (Do Not Distribute)
14 * $Log: makeindex.c,v $
15 * Revision 2.6 2005/01/23 11:23:15 matthew
16 * include standard header files
18 * Revision 2.5 2005/01/22 17:48:08 matthew
19 * prototype main correctly
21 * Revision 2.4 2005/01/21 19:39:36 matthew
22 * remove unused variables
24 * Revision 2.3 2003/07/26 09:22:12 matthew
25 * Correct arguments to printf
27 * Revision 2.2 2003/02/01 02:40:43 matthew
28 * Make main() return an int, and prototype accordingly.
30 * Revision 2.1 2003/01/08 15:52:50 matthew
31 * line_locator[] is int not long (from debian patch)
33 * Revision 2.0 2003/01/08 15:29:52 matthew
34 * versions collected from the net
36 * Revision 1.2 89/09/14 20:34:03 20:34:03 chip (Chip Chapin)
37 * Release 1-2. Supports -f and -l options for formatting the output.
38 * Updates primarily brl.c, bible.c, and bible.1.
40 * Revision 1.1 89/09/05 17:49:34 17:49:34 chip (Chip Chapin)
44 *******************************************************************************
47 /*----------------------------------------------------------------------
52 | Create an index to each line of a text file.
54 | The table thus produced may be indexed by line number to
55 | produce the absolute byte number of the file at which that
58 | An extra entry is guaranteed at the end, so that
59 | table[n+1], where n is the total number of lines in the
60 | file, yields the byte number just *after* the last byte of
61 | the last line (i.e. the total number of bytes in the
64 | By convention, I assume that "line 0" of the text file is
65 | an informational string describing the data. So the first
66 | line of data is actually "line 1". But there's really
67 | nothing in the construction of the index that mandates
70 | For the Bible Retrieval System, each verse starts on a new
71 | line. So the index produced by this program is an index
72 | to each Bible verse.
79 | 890904 cc Tidy it up, and read filenames from command line.
81 \*----------------------------------------------------------------------*/
89 /* Size of text buffer. Better be enough for one line */
94 int main(int argc,char **argv)
100 char textbuff[TBSIZE];
103 fprintf( stderr, "%s: Missing input file name\n", *argv );
104 fprintf( stderr, "Usage: %s textfile\n", *argv );
108 fp = fopen( argv[1], "r" );
110 fprintf( stderr, "%s: Cannot open file %s\n", *argv, argv[1] );
115 printf( "/* Text index to file: %s\n", argv[1] );
116 printf( " Created %s\n", ctime(&t) );
118 printf( "int line_locator[] = {" );
120 offset = cur_line = 0L;
122 if (cur_line % 8 == 0) printf( "\n\t" ); /* pretty */
123 /* print offset of current line */
124 printf( "%ld, ", offset );
126 /* Determine offset of next line */
127 fgets( textbuff, TBSIZE, fp);
128 offset += strlen(textbuff);
131 /* print offset of last line */
132 printf( "%ld\n\t};\n", offset ); /* end of array initialization */
133 printf( "\t/* textfile: %s, %ld lines. */\n", argv[1], cur_line );
134 printf( "int max_line = %ld;\n", cur_line-1 );