initial commit

This commit is contained in:
Tim Cooper 2018-08-06 20:49:49 -03:00
commit 26c2bbf8e7
7 changed files with 31400 additions and 0 deletions

1
.gitignore vendored Normal file
View File

@ -0,0 +1 @@
/kjv

24
LICENSE Normal file
View File

@ -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/>

19
Makefile Normal file
View File

@ -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

33
README.md Normal file
View File

@ -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

147
kjv.awk Normal file
View File

@ -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
}
}

31103
kjv.tsv Normal file

File diff suppressed because it is too large Load Diff

73
kjv_logic.sh Executable file
View File

@ -0,0 +1,73 @@
#!/bin/sh
# kjv: Read the Word of God from your terminal
# License: Public domain
SELF="$0"
get_data() {
sed -n "/^##$1##$/,/^##\\/$1##$/p" < "$SELF" | tail -n +2 | head -n -1 | base64 -d | gunzip -c
}
if [ -z "$PAGER" ]; then
if command -v less >/dev/null; then
PAGER="less"
else
PAGER="cat"
fi
fi
while [ $# -gt 0 ]; do
isFlag=0
firstChar="${1%"${1#?}"}"
if [ "$firstChar" = "-" ]; then
isFlag=1
fi
if [ "$1" = "--" ]; then
shift
break
elif [ "$1" = "-l" ]; then
# List all book names with their abbreviations
get_data BIBLE | awk -v cmd=list -e "$(get_data SCRIPT)"
exit
elif [ "$1" = "-h" ] || [ "$isFlag" -eq 1 ]; then
exec >&2
echo "usage: $0 [flags] <references...>"
echo
echo " -l list books"
echo " -h show help"
echo
echo " References types:"
echo " {Book}"
echo " Individual book"
echo " {Book}:{Chapter}"
echo " Individual chapter of a book"
echo " {Book}:{Chapter}:{Verse}"
echo " Individual verse of a specific chapter of a book"
echo " {Book}:{Chapter}-{Chapter}"
echo " Range of chapters in a book"
echo " {Book}:{Chapter}:{Verse}-{Verse}"
echo " Range of verses in a book chapter"
echo " {Book}:{Chapter}:{Verse}-{Chapter}:{Verse}"
echo " Range of chapters and verses in a book"
echo
echo " /{Search}"
echo " All verses that match a pattern"
echo " {Book}/{Search}"
echo " All verses in a book that match a pattern"
echo " {Book}:{Chapter}/{Search}"
echo " All verses in a chapter of a book that match a pattern"
exit 2
fi
break
done
startIdx=$#
(while [ $# -gt 0 ]; do
if [ "${startIdx}" -ne $# ]; then
echo
fi
ref="$1"
shift
get_data BIBLE | awk -v cmd=ref -v ref="$ref" -e "$(get_data SCRIPT)"
done ) | ${PAGER}