11 mode = parseref
(ref
, p
)
12 p
["book"] =
tolower(p
["book"])
17 if (!
($
2 in seen_books
)) {
18 printf("%s (%s)\n", $
1, $
2)
23 function parseref
(ref
, arr
) {
25 # 2. <book>:?<chapter>
26 # 3. <book>:?<chapter>:<verse>
27 # 4. <book>:?<chapter>-<chapter>
28 # 5. <book>:?<chapter>:<verse>-<verse>
29 # 6. <book>:?<chapter>:<verse>-<chapter>:<verse>
32 # 9. <book>:?<chapter>/search
34 if (match(ref
, "^[1-9]?[a-zA-Z ]+")) {
35 # 1, 2, 3, 4, 5, 6, 8, 9
36 arr
["book"] =
substr(ref
, 1, RLENGTH)
37 ref =
substr(ref
, RLENGTH + 1)
38 } else if (match(ref
, "^/")) {
40 arr
["search"] =
substr(ref
, 2)
46 if (match(ref
, "^:?[1-9]+[0-9]*")) {
48 if (sub("^:", "", ref
)) {
49 arr
["chapter"] = int
(substr(ref
, 1, RLENGTH - 1))
50 ref =
substr(ref
, RLENGTH)
52 arr
["chapter"] = int
(substr(ref
, 1, RLENGTH))
53 ref =
substr(ref
, RLENGTH + 1)
55 } else if (match(ref
, "^/")) {
57 arr
["search"] =
substr(ref
, 2)
59 } else if (ref ==
"") {
66 if (match(ref
, "^:[1-9]+[0-9]*")) {
68 arr
["verse"] = int
(substr(ref
, 2, RLENGTH - 1))
69 ref =
substr(ref
, RLENGTH + 1)
70 } else if (match(ref
, "^-[1-9]+[0-9]*$")) {
72 arr
["chapter_end"] = int
(substr(ref
, 2))
74 } else if (match(ref
, "^/")) {
76 arr
["search"] =
substr(ref
, 2)
78 } else if (ref ==
"") {
85 if (match(ref
, "^-[1-9]+[0-9]*$")) {
87 arr
["verse_end"] = int
(substr(ref
, 2))
89 } else if (match(ref
, "-[1-9]+[0-9]*")) {
91 arr
["chapter_end"] = int
(substr(ref
, 2, RLENGTH - 1))
92 ref =
substr(ref
, RLENGTH + 1)
93 } else if (ref ==
"") {
100 if (match(ref
, "^:[1-9]+[0-9]*$")) {
102 arr
["verse_end"] = int
(substr(ref
, 2))
109 function printverse
(verse
, word_count
, characters_printed
) {
110 word_count =
split(verse
, words
, " ")
111 for (i =
1; i
<= word_count
; i
++) {
112 if (characters_printed
+ length(words
[i
]) + (characters_printed
> 0 ?
1 : 0) > 72) {
114 characters_printed =
0
116 if (characters_printed
> 0) {
120 printf("%s", words
[i
])
121 characters_printed
+=
length(words
[i
])
126 function processline
() {
127 if (last_book_printed
!= $
2) {
129 last_book_printed = $
2
132 printf("%d:%d\t", $
4, $
5)
137 cmd ==
"ref" && mode ==
"exact" && (tolower($
1) == p
["book"] || tolower($
2) == p
["book"]) && (p
["chapter"] ==
"" || $
4 == p
["chapter"]) && (p
["verse"] ==
"" || $
5 == p
["verse"]) {
141 cmd ==
"ref" && mode ==
"range" && (tolower($
1) == p
["book"] || tolower($
2) == p
["book"]) && ((p
["chapter_end"] ==
"" && $
4 == p
["chapter"]) || ($
4 >= p
["chapter"] && $
4 <= p
["chapter_end"])) && (p
["verse"] ==
"" || $
5 >= p
["verse"]) && (p
["verse_end"] ==
"" || $
5 <= p
["verse_end"]) {
145 cmd ==
"ref" && mode ==
"range_ext" && (tolower($
1) == p
["book"] || tolower($
2) == p
["book"]) && (($
4 == p
["chapter"] && $
5 >= p
["verse"] && p
["chapter"] != p
["chapter_end"]) || ($
4 > p
["chapter"] && $
4 < p
["chapter_end"]) || ($
4 == p
["chapter_end"] && $
5 <= p
["verse_end"] && p
["chapter"] != p
["chapter_end"]) || (p
["chapter"] == p
["chapter_end"] && $
4 == p
["chapter"] && $
5 >= p
["verse"] && $
5 <= p
["verse_end"])) {
149 cmd ==
"ref" && mode ==
"search" && (p
["book"] ==
"" || tolower($
1) == p
["book"] || tolower($
2) == p
["book"]) && (p
["chapter"] ==
"" || $
4 == p
["chapter"]) && match(tolower($
6), tolower(p
["search"])) {
154 if (cmd ==
"ref" && outputted_records ==
0) {
155 print "Unknown reference: " ref