summaryrefslogtreecommitdiff
path: root/clients/vlist.h
diff options
context:
space:
mode:
Diffstat (limited to 'clients/vlist.h')
-rw-r--r--clients/vlist.h46
1 files changed, 46 insertions, 0 deletions
diff --git a/clients/vlist.h b/clients/vlist.h
new file mode 100644
index 0000000..8324ade
--- /dev/null
+++ b/clients/vlist.h
@@ -0,0 +1,46 @@
+#ifndef BOKF_VLIST_H
+#define BOKF_VLIST_H
+
+#include <stddef.h>
+#include <stdint.h>
+
+/* 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