Cleaned up journal.
This commit is contained in:
parent
04acf72734
commit
ebe78d18cc
@ -1,4 +1,5 @@
|
||||
#ifndef OMIT_BASE /* <!-- base */
|
||||
#if defined BASE \
|
||||
|| !defined BASE && !defined GENERIC && !defined PROTO /* <!-- base */
|
||||
#include <stddef.h>
|
||||
#include <stdint.h> /* C99 */
|
||||
/** 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? */
|
||||
uint64_t u64; /* C99 optional */
|
||||
};
|
||||
#else /* base --><!-- !base */
|
||||
#undef OMIT_BASE
|
||||
#endif /* !base --> */
|
||||
#endif /* base --> */
|
||||
|
||||
|
||||
#ifndef OMIT_STRUCT /* <!-- external */
|
||||
#if defined GENERIC \
|
||||
|| !defined BASE && !defined GENERIC && !defined PROTO /* <!-- generic */
|
||||
struct tree_day_node;
|
||||
struct tree_day_tree { struct tree_day_node *node; unsigned height; };
|
||||
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 day_tree_iterator { struct tree_day_iterator _; };
|
||||
#else /* external --><!-- internal */
|
||||
#undef OMIT_STRUCT
|
||||
#endif /* internal --> */
|
||||
#endif /* generic --> */
|
||||
|
||||
|
||||
#ifndef OMIT_PROTO /* <!-- proto */
|
||||
#if defined PROTO \
|
||||
|| !defined BASE && !defined GENERIC && !defined PROTO /* <!-- proto */
|
||||
#include "text.h"
|
||||
struct journal { struct day_tree days; struct text backing; };
|
||||
struct journal_iterator { struct day_tree_iterator _; };
|
||||
@ -40,7 +39,15 @@ void journal_(struct journal *);
|
||||
int journal_is_valid(const struct journal *);
|
||||
const char *journal_to_string(const struct journal *);
|
||||
struct journal_iterator journal_begin(struct journal *const j);
|
||||
int journal_next(struct journal_iterator *, union date32 *, /*union load ***/const char **);
|
||||
#else /* proto --><!-- !proto */
|
||||
#undef OMIT_PROTO
|
||||
#endif /* !proto --> */
|
||||
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
|
||||
|
@ -1,8 +1,7 @@
|
||||
/** Reading all journal entries in yyyy/mm/dd.txt.
|
||||
@std GNU, C11, assumes reverse order unions. */
|
||||
|
||||
#define OMIT_STRUCT
|
||||
#define OMIT_PROTO
|
||||
#define BASE
|
||||
#include "../src/journal.h" /* base */
|
||||
#include <inttypes.h> /* C99 */
|
||||
#include <limits.h>
|
||||
@ -14,25 +13,21 @@
|
||||
#include <sys/stat.h> /* umask (POSIX) */
|
||||
#include <dirent.h> /* opendir readdir closedir */
|
||||
|
||||
|
||||
void date32_to_string(const union date32 d, char (*const a)[12]) {
|
||||
sprintf(*a, "%" PRIu32 "-%2.2" PRIu32 "-%2.2" PRIu32,
|
||||
d.year % 10000, d.month % 100, d.day % 100);
|
||||
}
|
||||
static int day_compare(const union date32 a, const union date32 b)
|
||||
{ return a.u32 > b.u32; }
|
||||
typedef const char *ccs;
|
||||
static void day_to_string(const union date32 d,
|
||||
/*const union load *const entry*/ccs *const entry,
|
||||
static void day_to_string(const union date32 d, const char *const*const entry,
|
||||
char (*const a)[12]) { (void)entry; date32_to_string(d, a); }
|
||||
#define TREE_NAME day
|
||||
#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_TO_STRING
|
||||
#include "../src/tree.h"
|
||||
|
||||
|
||||
/* Temporary filename arrangement. */
|
||||
#if INT_MAX >= 100000000000
|
||||
#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)
|
||||
{ return int_cmp(a, b); }
|
||||
|
||||
|
||||
/*!re2c
|
||||
re2c:yyfill:enable = 0;
|
||||
re2c:define:YYCTYPE = char;
|
||||
@ -105,9 +99,7 @@ static unsigned looks_like_day(const char *const a) {
|
||||
*/
|
||||
}
|
||||
|
||||
|
||||
#define OMIT_BASE
|
||||
#define OMIT_STRUCT
|
||||
#define PROTO
|
||||
#include "../src/journal.h" /* Just prototypes. */
|
||||
|
||||
/** 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";
|
||||
struct journal j = {0};
|
||||
char *intent = 0;
|
||||
//union { const char **text; uintptr_t *offset; } v;
|
||||
DIR *dir = 0;
|
||||
struct dirent *de = 0;
|
||||
struct int_array years = int_array(), months = int_array(),
|
||||
@ -207,7 +198,6 @@ struct journal journal(void) {
|
||||
}
|
||||
m = 0, int_array_clear(&months);
|
||||
if(chdir("..") == -1) goto catch;
|
||||
/*if(*y == 1993) break;*/
|
||||
}
|
||||
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 );
|
||||
if(intent) fprintf(stderr, "Explanation: %s.\n", intent);
|
||||
recatch:
|
||||
day_tree_(&j.days);
|
||||
text_(&j.backing);
|
||||
journal_(&j);
|
||||
finally:
|
||||
if(dir) { if(closedir(dir)) { dir = 0; goto recatch; } dir = 0; }
|
||||
int_array_(&years), int_array_(&months), int_array_(&days);
|
||||
|
31
src/kjv.h
31
src/kjv.h
@ -1,4 +1,5 @@
|
||||
#ifndef OMIT_BASE /* <!-- base */
|
||||
#if defined BASE \
|
||||
|| !defined BASE && !defined GENERIC && !defined PROTO /* <!-- base */
|
||||
#define BOOKS \
|
||||
X(Genesis),\
|
||||
X(Exodus),\
|
||||
@ -81,12 +82,11 @@ union kjvcite {
|
||||
uint32_t u32;
|
||||
};
|
||||
void kjvcite_to_string(const union kjvcite, char (*)[12]);
|
||||
#else /* base --><!-- !base */
|
||||
#undef OMIT_BASE
|
||||
#endif /* !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 kjvset_table {
|
||||
struct table_kjvset_bucket *buckets;
|
||||
@ -97,12 +97,11 @@ struct verse_table {
|
||||
struct table_verse_bucket *buckets;
|
||||
uint32_t log_capacity, size, top;
|
||||
};
|
||||
#else /* verses --><!-- !verses */
|
||||
#undef OMIT_VERSES
|
||||
#endif /* !verses --> */
|
||||
#endif /* generic --> */
|
||||
|
||||
|
||||
#ifndef OMIT_PROTO /* <!-- proto */
|
||||
#if defined PROTO \
|
||||
|| !defined BASE && !defined GENERIC && !defined PROTO /* <!-- proto */
|
||||
#include <stddef.h>
|
||||
struct kjv {
|
||||
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);
|
||||
const char *kjv_to_string(const struct kjv *const kjv);
|
||||
const char *kjv_set_to_string(const struct kjv *const kjv);
|
||||
#else /* proto --><!-- !proto */
|
||||
#undef OMIT_PROTO
|
||||
#endif /* !proto --> */
|
||||
#endif /* proto --> */
|
||||
|
||||
#ifdef BASE
|
||||
#undef BASE
|
||||
#endif
|
||||
#ifdef GENERIC
|
||||
#undef GENERIC
|
||||
#endif
|
||||
#ifdef PROTO
|
||||
#undef PROTO
|
||||
#endif
|
||||
|
@ -7,10 +7,9 @@
|
||||
"All included Bible translations are in the public domain."
|
||||
@std C11 */
|
||||
|
||||
#include "../src/text.h"
|
||||
#define OMIT_VERSES
|
||||
#define OMIT_PROTO
|
||||
#define BASE
|
||||
#include "../src/kjv.h" /* Just the base data. */
|
||||
#include "../src/text.h"
|
||||
#include "../src/helper.h"
|
||||
#include <inttypes.h>
|
||||
#include <stdio.h>
|
||||
@ -144,8 +143,7 @@ scan:
|
||||
}
|
||||
|
||||
|
||||
#define OMIT_BASE
|
||||
#define OMIT_VERSES
|
||||
#define PROTO
|
||||
#include "../src/kjv.h" /* Just the kjv and prototypes. */
|
||||
|
||||
/** Frees `kjv`. */
|
||||
|
Loading…
Reference in New Issue
Block a user