Cleaned up journal.

This commit is contained in:
Neil 2023-02-01 22:23:35 -08:00
parent 04acf72734
commit ebe78d18cc
4 changed files with 47 additions and 46 deletions

View File

@ -1,4 +1,5 @@
#ifndef OMIT_BASE /* <!-- base */ #if defined BASE \
|| !defined BASE && !defined GENERIC && !defined PROTO /* <!-- base */
#include <stddef.h> #include <stddef.h>
#include <stdint.h> /* C99 */ #include <stdint.h> /* C99 */
/** Assumes: reverse ordering of byte-fields; unsigned is defined; C11 or GNU /** Assumes: reverse ordering of byte-fields; unsigned is defined; C11 or GNU
@ -12,12 +13,11 @@ union line64 {
struct { union date32 date; uint32_t line; }; /* C11, endian? */ struct { union date32 date; uint32_t line; }; /* C11, endian? */
uint64_t u64; /* C99 optional */ uint64_t u64; /* C99 optional */
}; };
#else /* base --><!-- !base */ #endif /* base --> */
#undef OMIT_BASE
#endif /* !base --> */
#ifndef OMIT_STRUCT /* <!-- external */ #if defined GENERIC \
|| !defined BASE && !defined GENERIC && !defined PROTO /* <!-- generic */
struct tree_day_node; struct tree_day_node;
struct tree_day_tree { struct tree_day_node *node; unsigned height; }; struct tree_day_tree { struct tree_day_node *node; unsigned height; };
struct day_tree { struct tree_day_tree root; }; struct day_tree { struct tree_day_tree root; };
@ -26,12 +26,11 @@ struct tree_day_iterator {
struct tree_day_tree *root; struct tree_day_ref ref; int seen; struct tree_day_tree *root; struct tree_day_ref ref; int seen;
}; };
struct day_tree_iterator { struct tree_day_iterator _; }; struct day_tree_iterator { struct tree_day_iterator _; };
#else /* external --><!-- internal */ #endif /* generic --> */
#undef OMIT_STRUCT
#endif /* internal --> */
#ifndef OMIT_PROTO /* <!-- proto */ #if defined PROTO \
|| !defined BASE && !defined GENERIC && !defined PROTO /* <!-- proto */
#include "text.h" #include "text.h"
struct journal { struct day_tree days; struct text backing; }; struct journal { struct day_tree days; struct text backing; };
struct journal_iterator { struct day_tree_iterator _; }; struct journal_iterator { struct day_tree_iterator _; };
@ -40,7 +39,15 @@ void journal_(struct journal *);
int journal_is_valid(const struct journal *); int journal_is_valid(const struct journal *);
const char *journal_to_string(const struct journal *); const char *journal_to_string(const struct journal *);
struct journal_iterator journal_begin(struct journal *const j); struct journal_iterator journal_begin(struct journal *const j);
int journal_next(struct journal_iterator *, union date32 *, /*union load ***/const char **); int journal_next(struct journal_iterator *, union date32 *, const char **);
#else /* proto --><!-- !proto */ #endif /* proto --> */
#undef OMIT_PROTO
#endif /* !proto --> */ #ifdef BASE
#undef BASE
#endif
#ifdef GENERIC
#undef GENERIC
#endif
#ifdef PROTO
#undef PROTO
#endif

View File

@ -1,8 +1,7 @@
/** Reading all journal entries in yyyy/mm/dd.txt. /** Reading all journal entries in yyyy/mm/dd.txt.
@std GNU, C11, assumes reverse order unions. */ @std GNU, C11, assumes reverse order unions. */
#define OMIT_STRUCT #define BASE
#define OMIT_PROTO
#include "../src/journal.h" /* base */ #include "../src/journal.h" /* base */
#include <inttypes.h> /* C99 */ #include <inttypes.h> /* C99 */
#include <limits.h> #include <limits.h>
@ -14,25 +13,21 @@
#include <sys/stat.h> /* umask (POSIX) */ #include <sys/stat.h> /* umask (POSIX) */
#include <dirent.h> /* opendir readdir closedir */ #include <dirent.h> /* opendir readdir closedir */
void date32_to_string(const union date32 d, char (*const a)[12]) { void date32_to_string(const union date32 d, char (*const a)[12]) {
sprintf(*a, "%" PRIu32 "-%2.2" PRIu32 "-%2.2" PRIu32, sprintf(*a, "%" PRIu32 "-%2.2" PRIu32 "-%2.2" PRIu32,
d.year % 10000, d.month % 100, d.day % 100); d.year % 10000, d.month % 100, d.day % 100);
} }
static int day_compare(const union date32 a, const union date32 b) static int day_compare(const union date32 a, const union date32 b)
{ return a.u32 > b.u32; } { return a.u32 > b.u32; }
typedef const char *ccs; static void day_to_string(const union date32 d, const char *const*const entry,
static void day_to_string(const union date32 d,
/*const union load *const entry*/ccs *const entry,
char (*const a)[12]) { (void)entry; date32_to_string(d, a); } char (*const a)[12]) { (void)entry; date32_to_string(d, a); }
#define TREE_NAME day #define TREE_NAME day
#define TREE_KEY union date32 #define TREE_KEY union date32
#define TREE_VALUE /*union load*/ /*size_t*/ /*const char **/ ccs #define TREE_VALUE const char *
#define TREE_COMPARE #define TREE_COMPARE
#define TREE_TO_STRING #define TREE_TO_STRING
#include "../src/tree.h" #include "../src/tree.h"
/* Temporary filename arrangement. */ /* Temporary filename arrangement. */
#if INT_MAX >= 100000000000 #if INT_MAX >= 100000000000
#error int_to_string requires truncation on this compiler. #error int_to_string requires truncation on this compiler.
@ -48,7 +43,6 @@ static int int_cmp(const int *const a, const int *const b)
static int void_int_cmp(const void *const a, const void *const b) static int void_int_cmp(const void *const a, const void *const b)
{ return int_cmp(a, b); } { return int_cmp(a, b); }
/*!re2c /*!re2c
re2c:yyfill:enable = 0; re2c:yyfill:enable = 0;
re2c:define:YYCTYPE = char; re2c:define:YYCTYPE = char;
@ -105,9 +99,7 @@ static unsigned looks_like_day(const char *const a) {
*/ */
} }
#define PROTO
#define OMIT_BASE
#define OMIT_STRUCT
#include "../src/journal.h" /* Just prototypes. */ #include "../src/journal.h" /* Just prototypes. */
/** Dynamic memory allocation for `j` will be zero, <fn:journal_is_valid> will /** Dynamic memory allocation for `j` will be zero, <fn:journal_is_valid> will
@ -123,7 +115,6 @@ struct journal journal(void) {
const char *const dir_journal = "journal"; const char *const dir_journal = "journal";
struct journal j = {0}; struct journal j = {0};
char *intent = 0; char *intent = 0;
//union { const char **text; uintptr_t *offset; } v;
DIR *dir = 0; DIR *dir = 0;
struct dirent *de = 0; struct dirent *de = 0;
struct int_array years = int_array(), months = int_array(), struct int_array years = int_array(), months = int_array(),
@ -207,7 +198,6 @@ struct journal journal(void) {
} }
m = 0, int_array_clear(&months); m = 0, int_array_clear(&months);
if(chdir("..") == -1) goto catch; if(chdir("..") == -1) goto catch;
/*if(*y == 1993) break;*/
} }
if(chdir("..") == -1 || !day_tree_bulk_finish(&j.days)) goto catch; if(chdir("..") == -1 || !day_tree_bulk_finish(&j.days)) goto catch;
@ -227,8 +217,7 @@ catch:
dir_journal, y ? *y : 0, m ? *m : 0, d ? *d : 0 ); dir_journal, y ? *y : 0, m ? *m : 0, d ? *d : 0 );
if(intent) fprintf(stderr, "Explanation: %s.\n", intent); if(intent) fprintf(stderr, "Explanation: %s.\n", intent);
recatch: recatch:
day_tree_(&j.days); journal_(&j);
text_(&j.backing);
finally: finally:
if(dir) { if(closedir(dir)) { dir = 0; goto recatch; } dir = 0; } if(dir) { if(closedir(dir)) { dir = 0; goto recatch; } dir = 0; }
int_array_(&years), int_array_(&months), int_array_(&days); int_array_(&years), int_array_(&months), int_array_(&days);

View File

@ -1,4 +1,5 @@
#ifndef OMIT_BASE /* <!-- base */ #if defined BASE \
|| !defined BASE && !defined GENERIC && !defined PROTO /* <!-- base */
#define BOOKS \ #define BOOKS \
X(Genesis),\ X(Genesis),\
X(Exodus),\ X(Exodus),\
@ -81,12 +82,11 @@ union kjvcite {
uint32_t u32; uint32_t u32;
}; };
void kjvcite_to_string(const union kjvcite, char (*)[12]); void kjvcite_to_string(const union kjvcite, char (*)[12]);
#else /* base --><!-- !base */ #endif /* base --> */
#undef OMIT_BASE
#endif /* !base --> */
#ifndef OMIT_VERSES /* <!-- verses: For external inclusion. */ #if defined GENERIC \
|| !defined BASE && !defined GENERIC && !defined PROTO /* <!-- generic */
struct table_kjvset_bucket; struct table_kjvset_bucket;
struct kjvset_table { struct kjvset_table {
struct table_kjvset_bucket *buckets; struct table_kjvset_bucket *buckets;
@ -97,12 +97,11 @@ struct verse_table {
struct table_verse_bucket *buckets; struct table_verse_bucket *buckets;
uint32_t log_capacity, size, top; uint32_t log_capacity, size, top;
}; };
#else /* verses --><!-- !verses */ #endif /* generic --> */
#undef OMIT_VERSES
#endif /* !verses --> */
#ifndef OMIT_PROTO /* <!-- proto */ #if defined PROTO \
|| !defined BASE && !defined GENERIC && !defined PROTO /* <!-- proto */
#include <stddef.h> #include <stddef.h>
struct kjv { struct kjv {
struct kjvset_table set; struct kjvset_table set;
@ -115,6 +114,14 @@ int kjv_is_valid(const struct kjv *const kjv);
int kjv_add(struct kjv *const kjv, const union kjvcite cite); int kjv_add(struct kjv *const kjv, const union kjvcite cite);
const char *kjv_to_string(const struct kjv *const kjv); const char *kjv_to_string(const struct kjv *const kjv);
const char *kjv_set_to_string(const struct kjv *const kjv); const char *kjv_set_to_string(const struct kjv *const kjv);
#else /* proto --><!-- !proto */ #endif /* proto --> */
#undef OMIT_PROTO
#endif /* !proto --> */ #ifdef BASE
#undef BASE
#endif
#ifdef GENERIC
#undef GENERIC
#endif
#ifdef PROTO
#undef PROTO
#endif

View File

@ -7,10 +7,9 @@
"All included Bible translations are in the public domain." "All included Bible translations are in the public domain."
@std C11 */ @std C11 */
#include "../src/text.h" #define BASE
#define OMIT_VERSES
#define OMIT_PROTO
#include "../src/kjv.h" /* Just the base data. */ #include "../src/kjv.h" /* Just the base data. */
#include "../src/text.h"
#include "../src/helper.h" #include "../src/helper.h"
#include <inttypes.h> #include <inttypes.h>
#include <stdio.h> #include <stdio.h>
@ -144,8 +143,7 @@ scan:
} }
#define OMIT_BASE #define PROTO
#define OMIT_VERSES
#include "../src/kjv.h" /* Just the kjv and prototypes. */ #include "../src/kjv.h" /* Just the kjv and prototypes. */
/** Frees `kjv`. */ /** Frees `kjv`. */