diff --git a/allioli.awk b/allioli.awk index 93ca8b8..0c3f536 100644 --- a/allioli.awk +++ b/allioli.awk @@ -151,6 +151,11 @@ function bookmatches(book, bookabbr, query) { } function printverse(verse, word_count, characters_printed) { + # Remove superscript footnote numbers if footnotes are disabled + if (ENVIRON["ALLIOLI_NOFOOTNOTES"] != "" && ENVIRON["ALLIOLI_NOFOOTNOTES"] != "0") { + gsub(/[⁰¹²³⁴⁵⁶⁷⁸⁹]+/, "", verse) + } + if (ENVIRON["ALLIOLI_NOLINEWRAP"] != "" && ENVIRON["ALLIOLI_NOLINEWRAP"] != "0") { printf("%s\n", verse) return @@ -172,14 +177,91 @@ function printverse(verse, word_count, characters_printed) { printf("\n") } +function printintroductionpar(verse, word_count, characters_printed) { + if (ENVIRON["ALLIOLI_NOLINEWRAP"] != "" && ENVIRON["ALLIOLI_NOLINEWRAP"] != "0") { + printf("%s\n", verse) + return + } + + word_count = split(verse, words, " ") + characters_printed=8 #account for indents at beginning of each verse + for (i = 1; i <= word_count; i++) { + if (characters_printed + length(words[i]) + (characters_printed > 0 ? 1 : 0) > MAX_WIDTH) { + printf("\n") + characters_printed = 0 + } + if (i != 1 && characters_printed > 0) { #need first check because we set characters_printed > 0 for first line only + printf(" ") + characters_printed++ + } + printf("%s", words[i]) + characters_printed += length(words[i]) + } + printf("\n") + printed_intrudction=1 +} + +function printfootnote(footnote_num, footnote, word_count, characters_printed) { + if ( ENVIRON["ALLIOLI_NOFOOTNOTES"] != "" && ENVIRON["ALLIOLI_NOFOOTNOTES"] != "0"){ + return + } + else{ + if (ENVIRON["ALLIOLI_NOLINEWRAP"] != "" && ENVIRON["ALLIOLI_NOLINEWRAP"] != "0") { + printf("\t\t%s%s\n", footnote_num, footnote) + return + } + + if( length(footnote) < MAX_WIDTH - 17){ + for ( i=1; i <= MAX_WIDTH - length(footnote) - 1; i++){ + printf(" ") + } + printf("%s%s", footnote_num, footnote) + } + else{ + word_count = split(footnote, words, " ") + printf("\n\t\t%s", footnote_num) + characters_printed=17 #account for indents at beginning of each multiline footnote (2 tabs + footnote_num) + for (i = 1; i <= word_count; i++) { + if (characters_printed + length(words[i]) + (characters_printed > 0 ? 1 : 0) > MAX_WIDTH - 8 ) { + printf("\n\t") + characters_printed = 0 + } + if (i != 1 && characters_printed > 0) { #Do not print empty space in front of first word for the first line (since characters_printed gets initialized > 0 we need this + printf(" ") + characters_printed++ + } + printf("%s", words[i]) + characters_printed += length(words[i]) + } + printf("\n") + } + printf("\n") + } +} + function processline() { + if (printed_intrudction && $4 != 0){ + printf("\n\n") + printed_intrudction=0 + } if (last_book_printed != $2) { print $1 last_book_printed = $2 } - - printf("%d:%d\t", $4, $5) - printverse($6) + # Check if this is a footnote (column 6 is a number) + if ($6 ~ /^[0-9]+$/) { + printfootnote($6, $7) + } + # Check if this is an introduction (chapter 0) + else if ($4 == 0){ + printf("\t") + printintroductionpar($6) + } + # Regular verse + else { + printf("%d:%d\t", $4, $5) + printverse($6) + } outputted_records++ } diff --git a/allioli.sh b/allioli.sh index 8b75eff..9a67527 100755 --- a/allioli.sh +++ b/allioli.sh @@ -22,6 +22,7 @@ show_help() { echo echo " -l list books" echo " -W no line wrap" + echo " -F no footnotes" echo " -h show help" echo echo " Reference types:" @@ -64,6 +65,9 @@ while [ $# -gt 0 ]; do elif [ "$1" = "-W" ]; then export ALLIOLI_NOLINEWRAP=1 shift + elif [ "$1" = "-F" ]; then + export ALLIOLI_NOFOOTNOTES=1 + shift elif [ "$1" = "-h" ] || [ "$isFlag" -eq 1 ]; then show_help else