File: makeindex2

package info (click to toggle)
bible-kjv 4.41
  • links: PTS
  • area: main
  • in suites: forky, sid
  • size: 4,760 kB
  • sloc: ansic: 3,589; makefile: 336; sh: 238; perl: 37
file content (195 lines) | stat: -rwxr-xr-x 6,187 bytes parent folder | download | duplicates (11)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
#!/bin/bash
###############################################################################
#
# File:         makeindex2
# RCS:          $Header: /home/matthew/cvs/bible-kjv-4.10/makeindex2,v 2.2 2003/01/13 17:40:29 matthew Exp $
# Description:  Create start_verse and start_chapter tables
# Author:       Chip Chapin
# Created:      Tue Jan  5 14:20:08 1993
# Modified:     Tue Apr 27 12:30:49 1993 (Chip Chapin) chip@hpclbis
# Language:     Sh
# Package:      Text Storage Library (Bible Retrieval System)
# Status:       Experimental (Do Not Distribute)
#
###############################################################################
#
# Revisions:
# $Log: makeindex2,v $
# Revision 2.2  2003/01/13 17:40:29  matthew
# changed to #!/bin/bash, since that's in Debian's build-essential
# whereas ksh isn't :)
#
# Revision 2.1  2003/01/08 16:06:25  matthew
# create the vrs2num.index file earlier on so that the later routines do not barf
#
# Tue Apr 27 12:30:21 1993 (Chip Chapin) chip@hpclbis
#  Use temp files and only create output files if successful.
# Tue Jan  5 14:23:06 1993 (Chip Chapin) chip@hpclbis
#  Initial creation, incorporating the scripts "vrs2num", "mkvstruct", 
#  and "mkcstruct" from January 1989.  This is the first time I've had to
#  rebuild these tables since then...
#  Many changes to vrs2num, required by changes to rawtext format.
#  Additional changes were required throughout to reflect small data structure 
#  changes that had been made by hand.
###############################################################################


if [ $# -lt 1 ]; then
    print "Usage: $0 datafile"
    exit 1
fi
RAWDATA="$1"

T1=brsA$$
T2=brsB$$
T3=brsC$$

###############################################################################
# vrs2num, January 21, 1989
#
# script to read bible text  and produce a list will specify
# the absolute "verse number" from the start of the KJ text
# for each Book:Chapter (zero-based).  Also records how many verses
# are in each chapter.
# Output is the following table:
#
# Book	Chapter	VrsNum	NumVerses
# Gen   1       0	31
# Gen   2       31	25
# ....

awk '
    BEGIN { 
	last_bc = "Ge1"; 
	book = "Ge"; chap = 1;
	start_absverse = 0; 
    }
    
    {
	# File starts with an info line. 
	if ( split($1,p,":") < 2 ) next;

	book_chap = p[1];
	if (book_chap != last_bc) {
	    # starting new chapter
	    # Print info for last chapter.
	    # Book -- Chapter -- Starting absverse -- Number of verses
	    printf "%s\t%d\t%d\t%d\n", book, chap, start_absverse, nverses;

            # Get ref without first character.  This avoids problems with
	    # refs that start with a number, e.g. "1Ki1:1".
	    # Then find out where the chapter number starts.
	    # Finally, extract the book and chapter info.
            tempbc = substr(book_chap, 2);
	    n=match(tempbc, /[0-9]/);
	    book = substr(book_chap, 1, n);
	    chap = substr(book_chap, n+1);

	    start_absverse = NR-2;  # Remember where we are now.
				    # Lose one due to leading \n in file,
				    # and one because we are zero-based.
	    nverses = 0;
	    last_bc = book_chap;
	}
	nverses++;		# Keep count of verses in chapter
    }

    END { # print the last chapter.  Might as well do this right.
	printf "%s\t%d\t%d\t%d\n", book, chap, start_absverse, nverses;
    }
' "$RAWDATA" > $T1

#Do this now, so we have a vrs2num.index to work from later.
if [ -s "$T1" ]; then mv $T1 vrs2num.index     ; fi



###############################################################################
# mkvstruct, January 21, 1989
#
# Make verse structure -- creates the array that contains the 
# "absolute verse number" (zero-based) for every CHAPTER in the Bible.
# Uses the table "vrs2num" which we created earlier.
#
# This table gives the number of verses occuring in the Bible BEFORE
# any particular chapter.  Gen 1 is "chapter 1", Gen 2 is "chapter 2"
# etc.  Since there are no verses prior to Gen 1, start_verse[1] == 0.
# start_verse[2] == 31 because there are 31 verses prior to Gen 2:1.
#
# Chip Chapin, 890114.
#
awk '
    BEGIN {
	FS="\t";
	printf "short start_verse[]={ 0,";
    }
    {
	if (chaps_printed % 10 == 0) printf "\n\t";
	chaps_printed++;
	printf "%s, ", $3;
	nextone = $3 + $4
    }
    END {
	printf "%d\n\t};\n", nextone ;
    }
' vrs2num.index > $T2 


###############################################################################
# mkcstruct, January 21, 1989
# Adapted from mkvstruct
#
# Make chapter structure -- creates the array that contains the 
# "absolute chapter number" (zero-based) for every BOOK in the Bible.
# Uses the table "vrs2num" which we created earlier, and contains one
# entry for each chapter in the Bible.  We wish to create a table that
# can be indexed by BOOK (Genesis == 0, Revelation == 65) to determine
# the number of chapters that precede that book in the Bible.
# Our only purpose here is to create the appropriate C structure.
#
#    The start_chapter table is indexed by Bible BOOK (0..65) and
#    gives the number of CHAPTERS in the whole Bible that precede that
#    particular book.  Thus given the BOOK, CHAPTER, and VERSE for a
#    reference, we can easily compute an absolute verse number for that
#    reference as follows:
#
#	abs_verse = start_verse[ start_chapter[BOOK] + CHAPTER ] + VERSE
#
# Chip Chapin, 890114.

awk '
    BEGIN {
	FS="\t";
	printf "short start_chapter[]={";
	books = 0;
	last_book = "";
    }
    $1 != last_book {
	if (books_printed % 10 == 0) printf "\n\t";
	books_printed++;
	printf "%d, ", NR-1;
	last_book = $1;
    }
    END {
	printf "%d\n\t};\n", NR ;
    }
' vrs2num.index > $T3

# Have to do this earlier or the second two routines barf
#if [ -s "$T1" ]; then mv $T1 vrs2num.index     ; fi
if [ -s "$T2" ]; then mv $T2 brl-startverse.h  ; fi
if [ -s "$T3" ]; then mv $T3 brl-startchapter.h; fi

# end

###############################################################################
# Gnu Emacs variables...
#
#   Local Variables:
#   mode:   	    	    	        sh
#   eval:   	    	    	        (auto-fill-mode 0)
#   default-header-comment-character:	?#
#   header-prefix:			"#!/bin/ksh"
#   header-suffix:			"#"
#   header-comment-character:		?#
#   end: