Fixed tree iterating idle.

This commit is contained in:
Neil 2023-05-08 20:25:17 -07:00
parent 3e5acec91a
commit b670e7f822
3 changed files with 12 additions and 11 deletions

View File

@ -145,7 +145,7 @@ struct journal journal(const char *const dir_journal) {
if(closedir(dir)) { dir = 0; goto catch; } dir = 0;
/* Sort the years. */
qsort(years.data, years.size, sizeof *years.data, &void_int_cmp);
fprintf(stderr, "Years in <<%s>>: %s.\n",
fprintf(stderr, "Loading years in <<%s>>: %s.\n",
dir_journal, int_array_to_string(&years));
/* Go though each year. */

View File

@ -207,12 +207,12 @@ static int scan_day(struct scan *const scan, union date32 date,
<line> "->" :=> place
<line> "--" / [^-] :=> source
<line> "::" / [^:] :=> score
<line> "[glider]" :=> glider_type
<line> "[flight]" :=> flight_type
<line> "[" :=> bracket
/* ^"[" ... */
<bracket> * { fail = "bracket unrecognized"; goto catch; }
<bracket> "glider] " :=> glider_type
<bracket> "flight]" :=> flight_type
<bracket> "document: " :=> document
<bracket> "rem: " :=> remark
<bracket> "contact: " :=> contact
@ -222,6 +222,13 @@ static int scan_day(struct scan *const scan, union date32 date,
<bracket> "idea: " :=> idea
<bracket> "vaccine: " :=> vaccine
<bracket> "tax: " :=> tax
/* Whatsapp messages ignored. [11-03, 04:19] Contact: massage */
<bracket> [0-1][0-9] "-" [0-3][0-9] ", " [0-2][0-9] ":" [0-5][0-9] "] "
@s0 [^\x00\n:] @s1 ": " [^\x00\n] "\n" => line {
fprintf(stderr, "Whatsapp message from %.*s ignored.\n",
(int)(s1 - s0), s0);
continue;
}
<document> * { fail = "document title"; goto catch; }
<document> @s0 bralabel @s1 "]" => input_text {
@ -843,12 +850,8 @@ catch:
}
void scan_(struct scan *const scan) {
fprintf(stderr, "fixme: ~scan should be idempotent <<\n"); // now it is?
if(!scan) return;
// printing it made it so?
fprintf(stderr, "~scan kjv %s\n", kjv_tree_to_string(&scan->kjvs));
kjv_tree_(&scan->kjvs);
fprintf(stderr, "~scan finished kjv\n");
flight_tree_(&scan->flights);
glider_tree_(&scan->gliders);
linekvmoney_tree_(&scan->taxes);
@ -858,7 +861,6 @@ void scan_(struct scan *const scan) {
linekvpair_tree_(&scan->tvs);
linekvpair_tree_(&scan->books);
linekvpair_tree_(&scan->contacts);
fprintf(stderr, "~scan finished linekvpair\n");
linemap_tree_(&scan->scores.dates);
pair_map_table_(&scan->scores.map);
@ -879,7 +881,6 @@ void scan_(struct scan *const scan) {
linemap_tree_(&scan->sources.dates);
pair_map_table_(&scan->sources.map);
kvpair_array_(&scan->sources.array);
fprintf(stderr, "~scan finish >>\n");
}
/** @param[jrnl] Must be constant throughout the use of the returned value. */

View File

@ -245,7 +245,7 @@ static int PB_(next)(struct PB_(iterator) *const it) {
assert(it && it->root);
/* Tree empty. */
if(!it->root->node || it->root->height == UINT_MAX) return 0;
if(!it->root || !it->root->node || it->root->height == UINT_MAX) return 0;
/* Iterator empty; tree non-empty; point at first. */
if(!it->ref.node) {
@ -292,7 +292,7 @@ static int PB_(previous)(struct PB_(iterator) *const it) {
assert(it && it->root);
/* Tree empty. */
if(!it->root->node || it->root->height == UINT_MAX) return 0;
if(!it->root || !it->root->node || it->root->height == UINT_MAX) return 0;
/* Iterator empty; tree non-empty; point at last. */
if(!it->ref.node) {