interpret/src/journal.h

36 lines
1.1 KiB
C
Raw Normal View History

#ifndef JOURNAL_H
#define JOURNAL_H
#include <stdint.h> /* uint32_t C99 */
2023-02-01 08:58:51 +00:00
/** Assumes: reverse ordering of byte-fields; unsigned is defined; C11 or GNU
2022-12-28 04:45:57 +00:00
anonymous unions. */
union date32 {
struct { uint32_t day : 5, month : 4, year : 23; }; /* C11, reverse */
uint32_t u32;
};
2022-12-29 07:54:59 +00:00
void date32_to_string(const union date32 d, char (*const a)[12]);
2023-02-01 08:58:51 +00:00
union line64 {
2023-02-05 03:06:43 +00:00
struct { uint32_t line; union date32 date; }; /* C11, little-endian */
2023-02-01 08:58:51 +00:00
uint64_t u64; /* C99 optional */
};
2022-12-28 04:45:57 +00:00
#define TREE_NAME day
#define TREE_KEY union date32
#define TREE_VALUE const char *
#define TREE_HEAD
#include "../src/tree.h"
2022-12-28 04:45:57 +00:00
2023-05-13 05:25:58 +00:00
union date32 date32_last_month(union date32 d);
union date32 date32_next_month(union date32 d);
2022-12-28 08:03:55 +00:00
#include "text.h"
struct journal { struct day_tree days; struct char_array backing; };
2022-12-29 07:54:59 +00:00
struct journal_iterator { struct day_tree_iterator _; };
struct journal journal(void);
2022-12-28 04:45:57 +00:00
void journal_(struct journal *);
int journal_is_empty(const struct journal *);
2022-12-28 04:45:57 +00:00
const char *journal_to_string(const struct journal *);
struct journal_iterator journal_iterator(struct journal *const j);
2023-02-02 06:23:35 +00:00
int journal_next(struct journal_iterator *, union date32 *, const char **);
#endif /* JOURNAL_H */