interpret/src/journal.h

53 lines
1.7 KiB
C
Raw Normal View History

2023-02-02 06:23:35 +00:00
#if defined BASE \
|| !defined BASE && !defined GENERIC && !defined PROTO /* <!-- base */
2022-12-29 07:54:59 +00:00
#include <stddef.h>
2022-12-28 04:45:57 +00:00
#include <stdint.h> /* 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 */
};
2023-02-02 06:23:35 +00:00
#endif /* base --> */
2022-12-27 07:31:08 +00:00
2022-12-28 04:45:57 +00:00
2023-02-02 06:23:35 +00:00
#if defined GENERIC \
|| !defined BASE && !defined GENERIC && !defined PROTO /* <!-- generic */
2022-12-28 04:45:57 +00:00
struct tree_day_node;
struct tree_day_tree { struct tree_day_node *node; unsigned height; };
struct day_tree { struct tree_day_tree root; };
2022-12-29 07:54:59 +00:00
struct tree_day_ref { struct tree_day_node *node; unsigned height, idx; };
struct tree_day_iterator
{ struct tree_day_tree *root; struct tree_day_ref ref; };
2022-12-29 07:54:59 +00:00
struct day_tree_iterator { struct tree_day_iterator _; };
2023-02-02 06:23:35 +00:00
#endif /* generic --> */
2022-12-28 04:45:57 +00:00
2023-02-02 06:23:35 +00:00
#if defined PROTO \
|| !defined BASE && !defined GENERIC && !defined PROTO /* <!-- proto */
2022-12-28 08:03:55 +00:00
#include "text.h"
struct journal { struct day_tree days; struct text backing; };
2022-12-29 07:54:59 +00:00
struct journal_iterator { struct day_tree_iterator _; };
2022-12-28 04:45:57 +00:00
struct journal journal(void);
void journal_(struct journal *);
int journal_is_valid(const struct journal *);
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 /* proto --> */
#ifdef BASE
#undef BASE
#endif
#ifdef GENERIC
#undef GENERIC
#endif
#ifdef PROTO
#undef PROTO
#endif