#ifndef BOKF_VLIST_H #define BOKF_VLIST_H #include #include /* Voucher list ordering and stepping for the Verifikat view. Pure, so it is unit-tested in tests/test_tui.c. */ struct vlist_item { int64_t id; char series[16]; int64_t number; char date[16]; char *desc; /* owned by the caller */ int attachments; }; enum { VSORT_NUMBER = 0, /* series, then number, ascending */ VSORT_NUMBER_DESC, VSORT_DATE, /* date, then series and number, ascending */ VSORT_DATE_DESC, VSORT_COUNT, }; /* Sorts in place; ties fall back to the id so the order is stable. An out-of-range mode sorts by number. */ void vlist_sort(struct vlist_item *v, size_t n, int mode); /* Swedish label for the list title, e.g. "datum, fallande". */ const char *vlist_sort_label(int mode); /* Config value ("number", "number-desc", "date", "date-desc") and back; an unknown name gives VSORT_NUMBER. */ const char *vlist_sort_name(int mode); int vlist_sort_parse(const char *name); /* Index of the item with this id, or -1. */ int vlist_index(const struct vlist_item *v, size_t n, int64_t id); /* Index dir steps from idx, or -1 past either end or when idx is not in the list. */ int vlist_step(size_t n, int idx, int dir); #endif