Sources works!?

This commit is contained in:
Neil 2023-02-11 22:08:35 -08:00
parent b69e40bc44
commit 9d1c80076a

View File

@ -50,7 +50,7 @@ static int source_compare(const union line64 a, const union line64 b)
#define TREE_VALUE size_t /* Index into source list. */
#define TREE_COMPARE
#define TREE_TO_STRING
#define TREE_DEFAULT (size_t)0
#define TREE_DEFAULT 0
#include "../src/tree.h"
@ -173,10 +173,13 @@ finally:
/** Lookup the last source in `range` in sources `s`. They are invalidated on
adding a source, (probably fine.) */
const struct source *source_lookup(struct sources *const s,
const union line64 range) {
union line64 line_source;
const union line64 x) {
struct source_tree_iterator it;
assert(s);
line_source = source_tree_less_or(&s->dates, range, (union line64){0});
sourcemap_table_get(&s->map, line_source);
return s->list.data + idx;
it = source_tree_less(&s->dates, x);
/* If it's before all elements of the journal or is not on the same date as
the source, this has no source, which is `list[0]` by <fn:sources>. */
if(!source_tree_has_element(&it)
|| x.date.u32 != source_tree_key(&it).date.u32) return s->list.data + 0;
return s->list.data + *source_tree_value(&it);
}