1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
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
|