Fix footnote alignment and verse sorting
- Fix footnote spacing to account for multi-character superscript numbers - Transform introductions from chapter 0 to verse 0 of their respective chapters - Sort TSV by book, chapter, verse with verses before footnotes - Update AWK to handle verse 0 introductions instead of chapter 0 - Print newline before introductions and start them from left margin
This commit is contained in:
227
allioli.awk
227
allioli.awk
@@ -49,8 +49,8 @@ function parseref(ref, arr) {
|
||||
return "unknown"
|
||||
}
|
||||
|
||||
if (match(ref, "^:?[1-9]+[0-9]*")) {
|
||||
# 2, 3, 3a, 4, 5, 6, 9
|
||||
if (match(ref, "^:?[0-9]+")) {
|
||||
# 2, 3, 3a, 4, 5, 6, 9 (including chapter 0)
|
||||
if (sub("^:", "", ref)) {
|
||||
arr["chapter"] = int(substr(ref, 1, RLENGTH - 1))
|
||||
ref = substr(ref, RLENGTH)
|
||||
@@ -69,11 +69,11 @@ function parseref(ref, arr) {
|
||||
return "unknown"
|
||||
}
|
||||
|
||||
if (match(ref, "^:[1-9]+[0-9]*")) {
|
||||
if (match(ref, "^:[0-9]+")) {
|
||||
# 3, 3a, 5, 6
|
||||
arr["verse"] = int(substr(ref, 2, RLENGTH - 1))
|
||||
ref = substr(ref, RLENGTH + 1)
|
||||
} else if (match(ref, "^-[1-9]+[0-9]*$")) {
|
||||
} else if (match(ref, "^-[0-9]+$")) {
|
||||
# 4
|
||||
arr["chapter_end"] = int(substr(ref, 2))
|
||||
return "range"
|
||||
@@ -88,25 +88,25 @@ function parseref(ref, arr) {
|
||||
return "unknown"
|
||||
}
|
||||
|
||||
if (match(ref, "^-[1-9]+[0-9]*$")) {
|
||||
if (match(ref, "^-[0-9]+$")) {
|
||||
# 5
|
||||
arr["verse_end"] = int(substr(ref, 2))
|
||||
return "range"
|
||||
} else if (match(ref, "-[1-9]+[0-9]*")) {
|
||||
} else if (match(ref, "-[0-9]+")) {
|
||||
# 6
|
||||
arr["chapter_end"] = int(substr(ref, 2, RLENGTH - 1))
|
||||
ref = substr(ref, RLENGTH + 1)
|
||||
} else if (ref == "") {
|
||||
# 3
|
||||
return "exact"
|
||||
} else if (match(ref, "^,[1-9]+[0-9]*")) {
|
||||
} else if (match(ref, "^,[0-9]+")) {
|
||||
# 3a
|
||||
arr["verse", arr["verse"]] = 1
|
||||
delete arr["verse"]
|
||||
do {
|
||||
arr["verse", substr(ref, 2, RLENGTH - 1)] = 1
|
||||
ref = substr(ref, RLENGTH + 1)
|
||||
} while (match(ref, "^,[1-9]+[0-9]*"))
|
||||
} while (match(ref, "^,[0-9]+"))
|
||||
|
||||
if (ref != "") {
|
||||
return "unknown"
|
||||
@@ -117,7 +117,7 @@ function parseref(ref, arr) {
|
||||
return "unknown"
|
||||
}
|
||||
|
||||
if (match(ref, "^:[1-9]+[0-9]*$")) {
|
||||
if (match(ref, "^:[0-9]+$")) {
|
||||
# 6
|
||||
arr["verse_end"] = int(substr(ref, 2))
|
||||
return "range_ext"
|
||||
@@ -302,7 +302,7 @@ function printfootnote(footnote_num, footnote, word_count, characters_printed
|
||||
}
|
||||
|
||||
if( length(footnote) < MAX_WIDTH - 17){
|
||||
for ( i=1; i <= MAX_WIDTH - length(footnote) - 1; i++){
|
||||
for ( i=1; i <= MAX_WIDTH - length(footnote) - length(sup_num); i++){
|
||||
printf(" ")
|
||||
}
|
||||
printf("%s%s\n", sup_num, footnote)
|
||||
@@ -331,42 +331,38 @@ function printfootnote(footnote_num, footnote, word_count, characters_printed
|
||||
function processline() {
|
||||
# JSON mode: collect data instead of printing
|
||||
if (ENVIRON["ALLIOLI_JSON_OUTPUT"] != "" && ENVIRON["ALLIOLI_JSON_OUTPUT"] != "0") {
|
||||
# Store book info (will be used in END block)
|
||||
if (json_book_name == "") {
|
||||
json_book_name = $1
|
||||
json_book_abbr = $2
|
||||
json_book_num = $3
|
||||
book_key = $3 # Use book number as key
|
||||
|
||||
# Store book info (track multiple books for dump mode)
|
||||
if (!json_book_seen[book_key]) {
|
||||
json_book_seen[book_key] = 1
|
||||
json_books[++json_book_total] = book_key
|
||||
json_book_name[book_key] = $1
|
||||
json_book_abbr[book_key] = $2
|
||||
json_book_num[book_key] = $3
|
||||
}
|
||||
|
||||
# Check if this is a footnote
|
||||
if ($6 == "" && $7 ~ /^[0-9]+$/ && NF >= 8) {
|
||||
json_footnotes[$4, $5, $7] = $8
|
||||
json_footnote_nums[$4, $5, ++json_footnote_count[$4, $5]] = $7
|
||||
json_footnotes[book_key, $4, $5, $7] = $8
|
||||
json_footnote_nums[book_key, $4, $5, ++json_footnote_count[book_key, $4, $5]] = $7
|
||||
}
|
||||
# Check if this is an introduction (chapter 0)
|
||||
else if ($4 == 0 && $6 == "") {
|
||||
if (json_intro == "") {
|
||||
json_intro = $7
|
||||
} else {
|
||||
json_intro = json_intro " " $7
|
||||
}
|
||||
}
|
||||
# Verse with content
|
||||
# Verse with content (including chapter 0 introductions)
|
||||
else if ($6 != "" || ($7 != "" && $7 !~ /^[0-9]+$/)) {
|
||||
# Store verse data
|
||||
json_latin[$4, $5] = $6
|
||||
json_german[$4, $5] = $7
|
||||
json_latin[book_key, $4, $5] = $6
|
||||
json_german[book_key, $4, $5] = $7
|
||||
|
||||
# Track unique verses per chapter
|
||||
if (!json_verse_seen[$4, $5]) {
|
||||
json_verse_seen[$4, $5] = 1
|
||||
json_verses[$4, ++json_verse_count[$4]] = $5
|
||||
if (!json_verse_seen[book_key, $4, $5]) {
|
||||
json_verse_seen[book_key, $4, $5] = 1
|
||||
json_verses[book_key, $4, ++json_verse_count[book_key, $4]] = $5
|
||||
}
|
||||
|
||||
# Track chapters
|
||||
if (!json_chapter_seen[$4]) {
|
||||
json_chapter_seen[$4] = 1
|
||||
json_chapters[++json_chapter_total] = $4
|
||||
# Track chapters per book
|
||||
if (!json_chapter_seen[book_key, $4]) {
|
||||
json_chapter_seen[book_key, $4] = 1
|
||||
json_chapters[book_key, ++json_chapter_total[book_key]] = $4
|
||||
}
|
||||
}
|
||||
|
||||
@@ -375,7 +371,7 @@ function processline() {
|
||||
}
|
||||
|
||||
# Normal text output mode
|
||||
if (printed_intrudction && $4 != 0){
|
||||
if (printed_intrudction && $5 != 0){
|
||||
printf("\n\n")
|
||||
printed_intrudction=0
|
||||
}
|
||||
@@ -391,9 +387,9 @@ function processline() {
|
||||
if ($6 == "" && $7 ~ /^[0-9]+$/ && NF >= 8) {
|
||||
printfootnote($7, $8)
|
||||
}
|
||||
# Check if this is an introduction (chapter 0, column 6 empty, column 7 is text)
|
||||
else if ($4 == 0 && $6 == ""){
|
||||
printf("\t")
|
||||
# Check if this is an introduction (verse 0, column 6 empty, column 7 is text)
|
||||
else if ($5 == 0 && $6 == ""){
|
||||
printf("\n")
|
||||
printintroductionpar($7)
|
||||
}
|
||||
# Bilingual verse (both column 6 and 7 have text)
|
||||
@@ -426,6 +422,10 @@ function processline() {
|
||||
outputted_records++
|
||||
}
|
||||
|
||||
cmd == "dump" {
|
||||
processline()
|
||||
}
|
||||
|
||||
cmd == "ref" && mode == "exact" && bookmatches($1, $2, p["book"]) && (p["chapter"] == "" || $4 == p["chapter"]) && (p["verse"] == "" || $5 == p["verse"]) {
|
||||
processline()
|
||||
}
|
||||
@@ -448,52 +448,67 @@ cmd == "ref" && mode == "search" && (p["book"] == "" || bookmatches($1, $2, p["b
|
||||
|
||||
END {
|
||||
# JSON output mode
|
||||
if (cmd == "ref" && ENVIRON["ALLIOLI_JSON_OUTPUT"] != "" && ENVIRON["ALLIOLI_JSON_OUTPUT"] != "0") {
|
||||
if ((cmd == "ref" || cmd == "dump") && ENVIRON["ALLIOLI_JSON_OUTPUT"] != "" && ENVIRON["ALLIOLI_JSON_OUTPUT"] != "0") {
|
||||
if (outputted_records == 0) {
|
||||
if (cmd == "ref") {
|
||||
print "Unknown reference: " ref
|
||||
exit 1
|
||||
}
|
||||
}
|
||||
|
||||
# Determine language flags
|
||||
only_latin = (ENVIRON["ALLIOLI_ONLY_LATIN"] != "" && ENVIRON["ALLIOLI_ONLY_LATIN"] != "0")
|
||||
only_german = (ENVIRON["ALLIOLI_ONLY_GERMAN"] != "" && ENVIRON["ALLIOLI_ONLY_GERMAN"] != "0")
|
||||
no_footnotes = (ENVIRON["ALLIOLI_NOFOOTNOTES"] != "" && ENVIRON["ALLIOLI_NOFOOTNOTES"] != "0")
|
||||
|
||||
# Start JSON output
|
||||
print "{"
|
||||
printf(" \"book\": {\n")
|
||||
printf(" \"name\": \"%s\",\n", json_book_name)
|
||||
printf(" \"abbreviation\": \"%s\",\n", json_book_abbr)
|
||||
printf(" \"number\": %d\n", json_book_num)
|
||||
printf(" },\n")
|
||||
# If we have multiple books (dump mode), output as array
|
||||
if (json_book_total > 1) {
|
||||
print "["
|
||||
}
|
||||
|
||||
# Output chapters
|
||||
for (c_idx = 1; c_idx <= json_chapter_total; c_idx++) {
|
||||
chapter = json_chapters[c_idx]
|
||||
# Output each book
|
||||
for (b_idx = 1; b_idx <= json_book_total; b_idx++) {
|
||||
book_key = json_books[b_idx]
|
||||
|
||||
# Handle introduction (chapter 0)
|
||||
if (chapter == 0) {
|
||||
printf(" \"introduction\": \"%s\"", json_intro)
|
||||
if (json_chapter_total > 1) {
|
||||
printf(",\n")
|
||||
# Start book object
|
||||
if (json_book_total > 1) {
|
||||
printf(" {\n")
|
||||
} else {
|
||||
printf("\n")
|
||||
}
|
||||
continue
|
||||
print "{"
|
||||
}
|
||||
|
||||
# Regular chapter
|
||||
printf(" \"chapter\": %d,\n", chapter)
|
||||
printf(" \"verses\": [\n")
|
||||
# Book metadata
|
||||
if (json_book_total > 1) {
|
||||
printf(" \"book\": {\n")
|
||||
printf(" \"name\": \"%s\",\n", json_book_name[book_key])
|
||||
printf(" \"abbreviation\": \"%s\",\n", json_book_abbr[book_key])
|
||||
printf(" \"number\": %d\n", json_book_num[book_key])
|
||||
printf(" },\n")
|
||||
} else {
|
||||
printf(" \"book\": {\n")
|
||||
printf(" \"name\": \"%s\",\n", json_book_name[book_key])
|
||||
printf(" \"abbreviation\": \"%s\",\n", json_book_abbr[book_key])
|
||||
printf(" \"number\": %d\n", json_book_num[book_key])
|
||||
printf(" },\n")
|
||||
}
|
||||
|
||||
# Output chapters (including chapter 0 for introduction)
|
||||
indent = json_book_total > 1 ? " " : " "
|
||||
for (c_idx = 1; c_idx <= json_chapter_total[book_key]; c_idx++) {
|
||||
chapter = json_chapters[book_key, c_idx]
|
||||
|
||||
# Output chapter number and verses (works for chapter 0 and regular chapters)
|
||||
printf("%s\"chapter\": %d,\n", indent, chapter)
|
||||
printf("%s\"verses\": [\n", indent)
|
||||
|
||||
# Sort verses numerically before output
|
||||
delete sorted_verses
|
||||
for (v_idx = 1; v_idx <= json_verse_count[chapter]; v_idx++) {
|
||||
sorted_verses[v_idx] = json_verses[chapter, v_idx]
|
||||
for (v_idx = 1; v_idx <= json_verse_count[book_key, chapter]; v_idx++) {
|
||||
sorted_verses[v_idx] = json_verses[book_key, chapter, v_idx]
|
||||
}
|
||||
# Simple bubble sort for numeric ordering
|
||||
for (i = 1; i <= json_verse_count[chapter]; i++) {
|
||||
for (j = i + 1; j <= json_verse_count[chapter]; j++) {
|
||||
for (i = 1; i <= json_verse_count[book_key, chapter]; i++) {
|
||||
for (j = i + 1; j <= json_verse_count[book_key, chapter]; j++) {
|
||||
if (sorted_verses[i] + 0 > sorted_verses[j] + 0) {
|
||||
temp = sorted_verses[i]
|
||||
sorted_verses[i] = sorted_verses[j]
|
||||
@@ -503,73 +518,94 @@ END {
|
||||
}
|
||||
|
||||
# Output verses in sorted order
|
||||
for (v_idx = 1; v_idx <= json_verse_count[chapter]; v_idx++) {
|
||||
for (v_idx = 1; v_idx <= json_verse_count[book_key, chapter]; v_idx++) {
|
||||
verse_num = sorted_verses[v_idx]
|
||||
|
||||
printf(" {\n")
|
||||
printf(" \"verse\": %d,\n", verse_num)
|
||||
printf("%s {\n", indent)
|
||||
printf("%s \"verse\": %d,\n", indent, verse_num)
|
||||
|
||||
# Text object
|
||||
printf(" \"text\": {")
|
||||
printf("%s \"text\": {", indent)
|
||||
|
||||
# Output text based on language flags
|
||||
if (only_latin) {
|
||||
printf("\n \"latin\": \"%s\"\n", json_latin[chapter, verse_num])
|
||||
printf("\n%s \"latin\": \"%s\"\n", indent, json_latin[book_key, chapter, verse_num])
|
||||
} else if (only_german) {
|
||||
# Remove superscript markers if footnotes disabled
|
||||
german_text = json_german[chapter, verse_num]
|
||||
german_text = json_german[book_key, chapter, verse_num]
|
||||
if (no_footnotes) {
|
||||
gsub(/[⁰¹²³⁴⁵⁶⁷⁸⁹]+/, "", german_text)
|
||||
}
|
||||
printf("\n \"german\": \"%s\"\n", german_text)
|
||||
printf("\n%s \"german\": \"%s\"\n", indent, german_text)
|
||||
} else {
|
||||
# Both languages
|
||||
german_text = json_german[chapter, verse_num]
|
||||
german_text = json_german[book_key, chapter, verse_num]
|
||||
if (no_footnotes) {
|
||||
gsub(/[⁰¹²³⁴⁵⁶⁷⁸⁹]+/, "", german_text)
|
||||
}
|
||||
if (json_latin[chapter, verse_num] != "") {
|
||||
printf("\n \"latin\": \"%s\",\n", json_latin[chapter, verse_num])
|
||||
if (json_latin[book_key, chapter, verse_num] != "") {
|
||||
printf("\n%s \"latin\": \"%s\",\n", indent, json_latin[book_key, chapter, verse_num])
|
||||
}
|
||||
if (german_text != "") {
|
||||
printf(" \"german\": \"%s\"\n", german_text)
|
||||
printf("%s \"german\": \"%s\"\n", indent, german_text)
|
||||
}
|
||||
}
|
||||
|
||||
printf(" }")
|
||||
printf("%s }", indent)
|
||||
|
||||
# Footnotes array (if not disabled)
|
||||
if (!no_footnotes && json_footnote_count[chapter, verse_num] > 0) {
|
||||
printf(",\n \"footnotes\": [\n")
|
||||
for (f_idx = 1; f_idx <= json_footnote_count[chapter, verse_num]; f_idx++) {
|
||||
fn_num = json_footnote_nums[chapter, verse_num, f_idx]
|
||||
fn_text = json_footnotes[chapter, verse_num, fn_num]
|
||||
printf(" {\n")
|
||||
printf(" \"number\": %d,\n", fn_num)
|
||||
printf(" \"text\": \"%s\"\n", fn_text)
|
||||
if (f_idx < json_footnote_count[chapter, verse_num]) {
|
||||
printf(" },\n")
|
||||
if (!no_footnotes && json_footnote_count[book_key, chapter, verse_num] > 0) {
|
||||
printf(",\n%s \"footnotes\": [\n", indent)
|
||||
for (f_idx = 1; f_idx <= json_footnote_count[book_key, chapter, verse_num]; f_idx++) {
|
||||
fn_num = json_footnote_nums[book_key, chapter, verse_num, f_idx]
|
||||
fn_text = json_footnotes[book_key, chapter, verse_num, fn_num]
|
||||
printf("%s {\n", indent)
|
||||
printf("%s \"number\": %d,\n", indent, fn_num)
|
||||
printf("%s \"text\": \"%s\"\n", indent, fn_text)
|
||||
if (f_idx < json_footnote_count[book_key, chapter, verse_num]) {
|
||||
printf("%s },\n", indent)
|
||||
} else {
|
||||
printf(" }\n")
|
||||
printf("%s }\n", indent)
|
||||
}
|
||||
}
|
||||
printf(" ]\n")
|
||||
printf("%s ]\n", indent)
|
||||
} else {
|
||||
printf("\n")
|
||||
}
|
||||
|
||||
# Close verse object
|
||||
if (v_idx < json_verse_count[chapter]) {
|
||||
if (v_idx < json_verse_count[book_key, chapter]) {
|
||||
printf("%s },\n", indent)
|
||||
} else {
|
||||
printf("%s }\n", indent)
|
||||
}
|
||||
}
|
||||
|
||||
printf("%s]\n", indent)
|
||||
|
||||
# Close chapter - add comma if not last chapter
|
||||
if (c_idx < json_chapter_total[book_key]) {
|
||||
printf(",\n")
|
||||
}
|
||||
}
|
||||
|
||||
# Close book object
|
||||
if (json_book_total > 1) {
|
||||
if (b_idx < json_book_total) {
|
||||
printf(" },\n")
|
||||
} else {
|
||||
printf(" }\n")
|
||||
}
|
||||
}
|
||||
|
||||
printf(" ]\n")
|
||||
}
|
||||
|
||||
} else {
|
||||
print "}"
|
||||
}
|
||||
}
|
||||
|
||||
# Close array if multiple books
|
||||
if (json_book_total > 1) {
|
||||
print "]"
|
||||
}
|
||||
|
||||
exit
|
||||
}
|
||||
|
||||
@@ -577,4 +613,5 @@ END {
|
||||
if (cmd == "ref" && outputted_records == 0) {
|
||||
print "Unknown reference: " ref
|
||||
}
|
||||
# dump mode doesn't need error handling - it outputs everything
|
||||
}
|
||||
|
||||
45518
allioli.tsv
45518
allioli.tsv
File diff suppressed because one or more lines are too long
Reference in New Issue
Block a user