diff --git a/cli.cpp b/cli.cpp index 310a379..2eecf5b 100644 --- a/cli.cpp +++ b/cli.cpp @@ -8,7 +8,8 @@ #include #ifdef WITH_PBRST -extern "C" char* brst_scan_string(char *string, int correct_raw, int correct_differ, int correct_cover, int show_dump); +extern "C" char* brst_scan_string(char *string, int correct_raw, int correct_differ, + int correct_cover, int correct_versification, int show_dump); // #include "statements/pbrst.tab.h" // use flex/bison parser for bibref statements (brst) #include "pbrst.tab.h" // the statements folder must be included among the folders #endif @@ -852,7 +853,7 @@ void processGetrefsCmd(string input) { #ifdef WITH_PBRST void processStatementCmd(string input) { - char *output = brst_scan_string((char*)input.c_str(), 0, 0, 0, 0); + char *output = brst_scan_string((char*)input.c_str(), 0, 0, 0, 0, 0); string output_s(output); vector statementAnalysis; boost::split(statementAnalysis, output_s, boost::is_any_of("\n")); diff --git a/qt/statementwindow.cpp b/qt/statementwindow.cpp index 0b1b840..df02922 100644 --- a/qt/statementwindow.cpp +++ b/qt/statementwindow.cpp @@ -10,7 +10,8 @@ #include #include -extern "C" char* brst_scan_string(char *string, int correct_raw, int correct_differ, int correct_cover, int show_dump); +extern "C" char* brst_scan_string(char *string, int correct_raw, int correct_differ, + int correct_cover, int correct_versification, int show_dump); #include "pbrst.tab.h" // the statements folder must be included among the folders using namespace std; @@ -118,7 +119,7 @@ void StatementWindow::setupFileMenu() void StatementWindow::parse() { #ifdef WITH_PBRST - char* output = brst_scan_string((char*)editor->toPlainText().toStdString().c_str(), 0, 0, 0, 0); + char* output = brst_scan_string((char*)editor->toPlainText().toStdString().c_str(), 0, 0, 0, 0, 0); string output_s(output); vector statementAnalysis; boost::split(statementAnalysis, output_s, boost::is_any_of("\n")); diff --git a/statements/pbrst-cli.c b/statements/pbrst-cli.c index 4624aa4..3c814aa 100644 --- a/statements/pbrst-cli.c +++ b/statements/pbrst-cli.c @@ -63,6 +63,7 @@ int main(int ac, char **av) extern int correct_raw; extern int correct_differ; extern int correct_cover; + extern int correct_versification; extern int show_dump; bool colorize = false; @@ -70,13 +71,14 @@ int main(int ac, char **av) correct_raw = 0; correct_differ = 0; correct_cover = 0; + correct_versification = 0; show_dump = 0; bool show_only_dump = false; while (ac>1 && (!strcmp(av[1], "-d") || !strcmp(av[1], "-c") || !strcmp(av[1], "-g") || !strcmp(av[1], "-r") || !strcmp(av[1], "-D") || !strcmp(av[1], "-C") - || !strcmp(av[1], "-h") + || !strcmp(av[1], "-h") || !strcmp(av[1], "-v") || !strcmp(av[1], "-u") || !strcmp(av[1], "-U"))) { if (!strcmp(av[1], "-h")) { @@ -89,6 +91,7 @@ int main(int ac, char **av) printf(" -r\tcorrect raw positions\n"); printf(" -D\tcorrect differings\n"); printf(" -C\tcorrect coverings\n"); + printf(" -v\tcorrect versification from KJV to LXX\n"); printf(" -u\tshow BRST dump\n"); printf(" -U\tshow only BRST dump\n"); exit(0); @@ -118,6 +121,10 @@ int main(int ac, char **av) correct_cover = 1; ac--; av++; } + if (!strcmp(av[1], "-v")) { + correct_versification = 1; ac--; av++; + } + if (!strcmp(av[1], "-u")) { show_dump = 1; ac--; av++; } diff --git a/statements/pbrst.y b/statements/pbrst.y index b20678f..d958987 100644 --- a/statements/pbrst.y +++ b/statements/pbrst.y @@ -81,6 +81,7 @@ bool fatal = false; int correct_raw = 0; // fix raw positions if possible int correct_differ = 0; // fix differing percents if possible int correct_cover = 0; // fix covering percents if possible +int correct_versification = 0; // fix versification related issues if possible int show_dump = 0; // if requested, print internal dump in BRST format #ifdef IN_BIBREF @@ -247,7 +248,7 @@ void check_fragment(char *passage, char *ay_nt, char *ay_ot); double myatof(char *arr); void create_diagram(); void create_dump(); -void reset_data(int cr, int cd, int cc, int sd); +void reset_data(int cr, int cd, int cc, int cv, int sd); } %% @@ -495,6 +496,72 @@ int detect_ot_book(char *book, char *info) { return -1; // not found } +char *versification_to_lxx(char *book, char *info, char *verse) { + if (strcmp(book, "LXX") != 0) return NULL; + int c, c0, v1, v2, o1, o2, n, f; + f = 1; + n = sscanf(verse, "%d:%d+%d %d:%d-%d", &c, &v1, &o1, &c0, &v2, &o2); + if (n<6) { + f = 2; + n = sscanf(verse, "%d:%d %d:%d-%d", &c, &v1, &c0, &v2, &o2); + if (n<5) { + f = 3; + n = sscanf(verse, "%d:%d+%d %d:%d", &c, &v1, &o1, &c0, &v2); + if (n<5) { + f = 4; + n = sscanf(verse, "%d:%d %d:%d", &c, &v1, &c0, &v2); + if (n<4) { + f = 5; + v2 = -1; // unused + n = sscanf(verse, "%d:%d", &c, &v1); + if (n<2) { + f = 0; // unsuccessful + } + } + } + } + } + if (f==0) return NULL; + + if (strcmp(info, "Psalms") == 0) { + // Shifting the verse number by 1 (or 2): + if (c>2 && c<150 && c!=14 && c!=16 && c!=24 && c!=32 + && c!=78 && c!=82 && c!=91 && c!=94 && c!=95 && c!=104 + && c!=109 && c!=110 && c!=112 && c!=114 && c!=116 && c!=117 && c!=118 && c!=132) { + if (v1>=1) { + v1++; + if (c==51) v1++; + } + if (v2>=1) { + v2++; + if (c==51) v2++; + } + } + // Shifting the chapter number by 1 (or 2): + if (c>10) { + if (c!=115 && !(c==116 && v1<10)) c--; + else c-=2; + } + // Now c contains the new chapter. + // Some verse numbers need to have further adjustments: + if (c==115) { + if (v1>=1) v1-=9; + if (v2>=1) v2-=9; + } + if (c==113) { + if (v1>=1) v1+=8; + if (v2>=1) v2+=8; + } + } // Psalms + + char *ret = malloc(MAX_VERSE_LENGTH + 1); + if (f==1) sprintf(ret, "%d:%d+%d %d:%d-%d", c, v1, o1, c, v2, o2); + if (f==2) sprintf(ret, "%d:%d %d:%d-%d", c, v1, c, v2, o2); + if (f==3) sprintf(ret, "%d:%d+%d %d:%d", c, v1, o1, c, v2); + if (f==4) sprintf(ret, "%d:%d %d:%d", c, v1, c, v2); + if (f==5) sprintf(ret, "%d:%d", c, v1); + return ret; +} void check_ot_passage(char *book, char *info, char *verse) @@ -504,18 +571,29 @@ check_ot_passage(char *book, char *info, char *verse) #ifdef IN_BIBREF char *l; bool err = false; // be optimistic - l = lookupVerse1(info, book, verse); + char *verse_fixed = NULL; + if (correct_versification == 1) { + add_parseinfo("%d,%d: debug: attempt to correct verse in %s %s %s\n", yylineno, yycolumn, book, info, verse); + verse_fixed = versification_to_lxx(book, info, verse); + } + if (verse_fixed == NULL) { + ot_verse = strdup(verse); + } + else { + ot_verse = strdup(verse_fixed); + add_parseinfo("%d,%d: corrected: verse in %s %s %s changed to %s\n", yylineno, yycolumn, book, info, verse, verse_fixed); + } + l = lookupVerse1(info, book, ot_verse); if (strstr(l, "error: ") != NULL) { add_parseinfo("%d,%d: %s\n", yylineno, yycolumn, l); free(l); fatal = true; return; // this is fatal } else { - add_parseinfo("%d,%d: info: `lookup1 %s %s %s` = %s\n", yylineno, yycolumn, book, info, verse, l); + add_parseinfo("%d,%d: info: `lookup1 %s %s %s` = %s\n", yylineno, yycolumn, book, info, ot_verse, l); } ot_info = strdup(info); ot_book = strdup(book); - ot_verse = strdup(verse); // Get passage as raw text: char *r; int length = intervals[iv_counter-1][1] - intervals[iv_counter-1][0] +1; @@ -1463,7 +1541,7 @@ void create_dump() { "dump: brst: end\n", D); } -void reset_data(int cr, int cd, int cc, int sd) { // important if a previous run was already performed +void reset_data(int cr, int cd, int cc, int cv, int sd) { // important if a previous run was already performed extern int yycolumn; addbooks_done = true; // we assume it was already called yycolumn = 0; @@ -1485,6 +1563,7 @@ void reset_data(int cr, int cd, int cc, int sd) { // important if a previous run correct_raw = cr; correct_differ = cd; correct_cover = cc; + correct_versification = cv; show_dump = sd; // yydebug = 1; @@ -1506,8 +1585,8 @@ extern int yyparse(); extern YY_BUFFER_STATE yy_scan_string(char * str); extern void yy_delete_buffer(YY_BUFFER_STATE buffer); -char* brst_scan_string(char *string, int cr, int cd, int cc, int sd) { - reset_data(cr, cd, cc, sd); +char* brst_scan_string(char *string, int cr, int cd, int cc, int cv, int sd) { + reset_data(cr, cd, cc, cv, sd); YY_BUFFER_STATE buffer = yy_scan_string(string); yyparse(); yy_delete_buffer(buffer);