Updated all words.*.

This commit is contained in:
Neil 2022-12-29 21:51:44 -08:00
parent ccdee8a779
commit 947d448962
4 changed files with 15 additions and 13 deletions

View File

@ -107,7 +107,7 @@ struct verse_table {
struct kjv {
struct kjvset_table set;
struct verse_table verses;
size_t total_words, set_words;
struct { size_t total, set, verse; } words;
};
struct kjv kjv(void);
void kjv_(struct kjv *);

View File

@ -203,7 +203,7 @@ struct kjv kjv(void) {
case TABLE_ERROR: goto catch;
case TABLE_ABSENT: break;
}
*words = x.words, kjv.total_words += x.words;
*words = x.words, kjv.words.total += x.words;
}
if(x.error) { fprintf(stderr, "[%u]%s on line %zu\n",
b + 1, kjv_book_string[b], x.line); goto catch; }
@ -227,11 +227,13 @@ int kjv_is_valid(const struct kjv *const kjv)
/** Adds `cite` to `kjv` if not present. @return Is the kjv still valid. */
int kjv_add(struct kjv *const kjv, const union kjvcite cite) {
unsigned w;
if(!kjv) return 0;
w = verse_table_get(&kjv->verses, cite);
switch(kjvset_table_try(&kjv->set, cite)) {
case TABLE_ERROR: return 0;
case TABLE_ABSENT: kjv->set_words += verse_table_get(&kjv->verses, cite);
case TABLE_PRESENT: break;
case TABLE_ABSENT: kjv->words.set += w; /* Sic. */
case TABLE_PRESENT: kjv->words.verse = w; break;
}
return 1;
}

View File

@ -145,7 +145,7 @@ static int scan(union date32 date, const char *const buffer,
continue;
}
<book> engage => skip {
const size_t old_set_words = kj->set_words;
const size_t old_set_words = kj->words.set;
char citestr[12];
if(!chapter || !verse) { why = "missing information"; goto catch; }
if(verse_end && verse_end <= verse)
@ -160,10 +160,10 @@ static int scan(union date32 date, const char *const buffer,
}
if(verse_end) {
printf("%s\t%zu\t%zu\t# %s-%" PRIu32 "\n",
datestr, old_set_words, kj->set_words, citestr, verse_end);
datestr, old_set_words, kj->words.set, citestr, verse_end);
} else {
printf("%s\t%zu\t%zu\t# %s\n",
datestr, old_set_words, kj->set_words, citestr);
datestr, old_set_words, kj->words.set, citestr);
}
book = Revelation, chapter = 0, verse = 0, verse_end = 0;
continue;
@ -197,7 +197,7 @@ int main(void) {
printf("set term postscript eps enhanced\n"
"set output \"kjv.eps\"\n"
"$Data <<EOD\n"
"# date\told\tnew / %zu\n", kj.total_words);
"# date\told\tnew / %zu\n", kj.words.total);
it = journal_begin(&j), i = 0; while(journal_next(&it, &k, &v)) {
if(!scan(k, v->text, &kj)) goto catch;
/*if(++i > 32) break;*/
@ -213,7 +213,7 @@ int main(void) {
"set grid\n"
"unset border\n"
"plot $Data using 1:($3-$2)*100/%zu smooth cumulative "
"with steps lw 2\n", kj.total_words);
"with steps lw 2\n", kj.words.total);
goto finally;
catch:
success = EXIT_FAILURE;

View File

@ -7,14 +7,14 @@
int main(void) {
int success = EXIT_SUCCESS;
struct kjv k = kjv();
fprintf(stderr, "%zu total words, %s.\n", k.total_words, kjv_to_string(&k));
fprintf(stderr, "%zu total words, %s.\n", k.words.total, kjv_to_string(&k));
if(!kjv_is_valid(&k)) goto catch;
kjv_add(&k, (union kjvcite){ .book = Genesis, .chapter = 1, .verse = 1 });
kjv_add(&k, (union kjvcite){ .book = Genesis, .chapter = 1, .verse = 2 });
kjv_add(&k, (union kjvcite){ .book = Genesis, .chapter = 1, .verse = 1 });
fprintf(stderr, "%zu of which: %s.\n", k.set_words, kjv_set_to_string(&k));
assert(k.total_words == 789633);
assert(k.set_words == 39);
fprintf(stderr, "%zu of which: %s.\n", k.words.set, kjv_set_to_string(&k));
assert(k.words.total == 789633);
assert(k.words.set == 39);
goto finally;
catch:
success = EXIT_FAILURE, perror("kjv");