forked from layeh/kjv
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Tim Cooper
committed
Aug 6, 2018
0 parents
commit 26c2bbf
Showing
7 changed files
with
31,400 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
/kjv |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
This is free and unencumbered software released into the public domain. | ||
|
||
Anyone is free to copy, modify, publish, use, compile, sell, or | ||
distribute this software, either in source code form or as a compiled | ||
binary, for any purpose, commercial or non-commercial, and by any | ||
means. | ||
|
||
In jurisdictions that recognize copyright laws, the author or authors | ||
of this software dedicate any and all copyright interest in the | ||
software to the public domain. We make this dedication for the benefit | ||
of the public at large and to the detriment of our heirs and | ||
successors. We intend this dedication to be an overt act of | ||
relinquishment in perpetuity of all present and future rights to this | ||
software under copyright law. | ||
|
||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, | ||
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF | ||
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. | ||
IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR | ||
OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, | ||
ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR | ||
OTHER DEALINGS IN THE SOFTWARE. | ||
|
||
For more information, please refer to <http://unlicense.org/> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
kjv: kjv_logic.sh kjv.awk kjv.tsv | ||
cat kjv_logic.sh > $@ | ||
|
||
echo 'exit 0' >> $@ | ||
|
||
echo '##SCRIPT##' >> $@ | ||
gzip kjv.awk -c | base64 >> $@ | ||
echo '##/SCRIPT##' >> $@ | ||
|
||
echo '##BIBLE##' >> $@ | ||
tail -n +2 kjv.tsv | gzip -c | base64 >> $@ | ||
echo '##/BIBLE##' >> $@ | ||
|
||
chmod +x $@ | ||
|
||
test: kjv kjv_logic.sh | ||
shellcheck -s sh kjv_logic.sh | ||
|
||
.PHONY: test |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
# kjv | ||
|
||
Read the Word of God from your terminal | ||
|
||
usage: ./kjv [flags] <references...> | ||
|
||
-l list books | ||
-h show help | ||
|
||
References types: | ||
{Book} | ||
Individual book | ||
{Book}:{Chapter} | ||
Individual chapter of a book | ||
{Book}:{Chapter}:{Verse} | ||
Individual verse of a specific chapter of a book | ||
{Book}:{Chapter}-{Chapter} | ||
Range of chapters in a book | ||
{Book}:{Chapter}:{Verse}-{Verse} | ||
Range of verses in a book chapter | ||
{Book}:{Chapter}:{Verse}-{Chapter}:{Verse} | ||
Range of chapters and verses in a book | ||
|
||
/{Search} | ||
All verses that match a pattern | ||
{Book}/{Search} | ||
All verses in a book that match a pattern | ||
{Book}:{Chapter}/{Search} | ||
All verses in a chapter of a book that match a pattern | ||
|
||
## License | ||
|
||
Public domain |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,147 @@ | ||
BEGIN { | ||
# $1 Book name | ||
# $2 Book abbreviation | ||
# $3 Book number | ||
# $4 Chapter number | ||
# $5 Verse number | ||
# $6 Verse | ||
FS = "\t" | ||
|
||
if (cmd == "ref") { | ||
if (match(ref, "^[a-zA-Z0-9 ]+$")) { | ||
mode = "exact" | ||
r_book = tolower(ref) | ||
|
||
} else if (match(ref, "^[a-zA-Z0-9 ]+:[0-9]+$")) { | ||
mode = "exact" | ||
|
||
split(ref, arr, ":") | ||
r_book = tolower(arr[1]) | ||
r_chapter = arr[2] | ||
|
||
} else if (match(ref, "^[a-zA-Z0-9 ]+:[0-9]+:[0-9]+$")) { | ||
mode = "exact" | ||
|
||
split(ref, arr, ":") | ||
r_book = tolower(arr[1]) | ||
r_chapter = arr[2] | ||
r_verse = arr[3] | ||
|
||
} else if (match(ref, "^[a-zA-Z0-9 ]+:[0-9]+-[0-9]+$")) { | ||
mode = "range" | ||
|
||
split(ref, arr, ":") | ||
r_book = tolower(arr[1]) | ||
|
||
split(arr[2], arr, "-") | ||
r_chapter_lower = arr[1] | ||
r_chapter_upper = arr[2] | ||
|
||
} else if (match(ref, "^[a-zA-Z0-9 ]+:[0-9]+:[0-9]+-[0-9]+$")) { | ||
mode = "range" | ||
|
||
split(ref, arr, ":") | ||
r_book = tolower(arr[1]) | ||
r_chapter_lower = r_chapter_upper = arr[2] | ||
|
||
split(arr[3], arr, "-") | ||
r_verse_lower = arr[1] | ||
r_verse_upper = arr[2] | ||
|
||
} else if (match(ref, "^[a-zA-Z0-9 ]+:[0-9]+:[0-9]+-[0-9]+:[0-9]+$")) { | ||
mode = "range_ext" | ||
|
||
split(ref, arr, ":") | ||
r_book = tolower(arr[1]) | ||
r_start_chapter = arr[2] | ||
r_end_verse = arr[4] | ||
|
||
split(arr[3], arr, "-") | ||
r_start_verse = arr[1] | ||
r_end_chapter = arr[2] | ||
|
||
} else if (match(ref, "^/")) { | ||
mode = "search" | ||
|
||
r_search = substr(ref, 2) | ||
|
||
} else if (match(ref, "^[a-zA-Z0-9 ]+/")) { | ||
mode = "search" | ||
|
||
i = index(ref, "/") | ||
r_book = tolower(substr(ref, 1, i - 1)) | ||
r_search = substr(ref, i + 1) | ||
|
||
} else if (match(ref, "^[a-zA-Z0-9 ]+:[0-9]+/")) { | ||
mode = "search" | ||
|
||
i = index(ref, ":") | ||
r_book = tolower(substr(ref, 1, i - 1)) | ||
|
||
ref2 = substr(ref, i + 1) | ||
i = index(ref2, "/") | ||
r_chapter = substr(ref2, 0, i - 1) | ||
r_search = substr(ref2, i + 1) | ||
} | ||
} | ||
} | ||
|
||
cmd == "list" { | ||
if (!($2 in seen_books)) { | ||
printf("%s (%s)\n", $1, $2) | ||
seen_books[$2] = 1 | ||
} | ||
} | ||
|
||
function beforeprintverse(book, bookabbr) { | ||
if (last_book_printed != bookabbr) { | ||
print $1 | ||
last_book_printed = bookabbr | ||
} | ||
} | ||
|
||
function printverse(verse, word_count, characters_printed) { | ||
word_count = split(verse, words, " ") | ||
for (i = 1; i <= word_count; i++) { | ||
if (characters_printed + length(words[i]) > 72) { | ||
printf("\n\t") | ||
characters_printed = 0 | ||
} | ||
if (characters_printed > 0) { | ||
printf(" ") | ||
characters_printed++ | ||
} | ||
printf("%s", words[i]) | ||
characters_printed += length(words[i]) | ||
} | ||
printf("\n") | ||
} | ||
|
||
function processline() { | ||
beforeprintverse($1, $2) | ||
printf("%d:%d\t", $4, $5) | ||
printverse($6) | ||
outputted_records++ | ||
} | ||
|
||
cmd == "ref" && mode == "exact" && (tolower($1) == r_book || tolower($2) == r_book) && (r_chapter == "" || $4 == r_chapter) && (r_verse == "" || $5 == r_verse) { | ||
processline() | ||
} | ||
|
||
cmd == "ref" && mode == "range" && (tolower($1) == r_book || tolower($2) == r_book) && $4 >= r_chapter_lower && $4 <= r_chapter_upper && (r_verse_lower == "" || $5 >= r_verse_lower) && (r_verse_upper == "" || $5 <= r_verse_upper) { | ||
processline() | ||
} | ||
|
||
cmd == "ref" && mode == "range_ext" && (tolower($1) == r_book || tolower($2) == r_book) && (($4 == r_start_chapter && $5 >= r_start_verse) || ($4 > r_start_chapter && $4 < r_end_chapter) || ($4 == r_end_chapter && $5 <= r_end_verse)) { | ||
processline() | ||
} | ||
|
||
cmd == "ref" && mode == "search" && (r_book == "" || tolower($1) == r_book || tolower($2) == r_book) && (r_chapter == "" || $4 == r_chapter) && match(tolower($6), tolower(r_search)) { | ||
processline() | ||
} | ||
|
||
END { | ||
if (cmd == "ref" && outputted_records == 0) { | ||
print "Unknown reference: " ref | ||
} | ||
} |
Oops, something went wrong.