From ac983acf226eedb1a3cb1fa335e22605b1cd3f17 Mon Sep 17 00:00:00 2001 From: Neil Date: Sat, 18 Mar 2023 21:30:13 -0700 Subject: [PATCH] I think body/head is more understandable than proto/private/base. --- Makefile | 2 +- src/flighthours.c | 1 - src/flights.h | 37 ++++++------------------------------- src/flights.re.c | 9 ++------- src/journal.h | 39 ++++++++++----------------------------- src/journal.re.c | 13 +++++-------- src/kjv.h | 46 ++++++---------------------------------------- src/kjv.re.c | 10 ++-------- src/kjvcount.h | 46 ++++++++++++++-------------------------------- src/kjvcount.re.c | 7 ++----- 10 files changed, 48 insertions(+), 162 deletions(-) diff --git a/Makefile b/Makefile index 2c65f9a..628d755 100644 --- a/Makefile +++ b/Makefile @@ -71,7 +71,7 @@ build/%.c: src/%.re.c # # https://github.com/neil-edelman/cdoc documentation # -cdoc -o $@ $< -.SECONDARY: build/kjv.c build/journal.c build/source.c build/scan_kjv.c build/flight.c build/kjvcount.c +.SECONDARY: build/kjv.c build/journal.c build/source.c build/scan_kjv.c build/flights.c build/kjvcount.c .PHONY: clean release test test: $(projects) diff --git a/src/flighthours.c b/src/flighthours.c index 75051b6..22d987f 100644 --- a/src/flighthours.c +++ b/src/flighthours.c @@ -3,7 +3,6 @@ Date _vs_ hours flown. */ -#include "journal.h" #include "flights.h" #include "source.h" #include diff --git a/src/flights.h b/src/flights.h index c0da942..0acca33 100644 --- a/src/flights.h +++ b/src/flights.h @@ -1,5 +1,3 @@ -#if defined BASE \ - || !defined BASE && !defined PRIVATE && !defined PROTO /* */ +#include "../src/journal.h" /* line64 */ +#define TREE_NAME flight +#define TREE_KEY union line64 +#define TREE_VALUE struct flight +#define TREE_HEAD +#include "../src/tree.h" -#if defined PRIVATE \ - || !defined BASE && !defined PRIVATE && !defined PROTO /* */ - - -#if defined PROTO \ - || !defined BASE && !defined PRIVATE && !defined PROTO /* */ - -#ifdef BASE -#undef BASE -#endif -#ifdef PRIVATE -#undef PRIVATE -#endif -#ifdef PROTO -#undef PROTO -#endif diff --git a/src/flights.re.c b/src/flights.re.c index 5593730..36cff4d 100644 --- a/src/flights.re.c +++ b/src/flights.re.c @@ -1,9 +1,7 @@ /** @license 2023 Neil Edelman, distributed under the terms of the [MIT License](https://opensource.org/licenses/MIT). @std C11 */ -#define BASE -#include "../src/flights.h" /* base */ -#include "../src/journal.h" +#include "../src/flights.h" #include #include #include @@ -18,13 +16,10 @@ static int flight_compare(const union line64 a, const union line64 b) #define TREE_VALUE struct flight #define TREE_COMPARE #define TREE_TO_STRING +#define TREE_BODY #include "../src/tree.h" -#define PROTO -#include "../src/flights.h" /* proto */ - - /*!conditions:re2c*/ static int scan(struct flights *const f, diff --git a/src/journal.h b/src/journal.h index b328314..728abb5 100644 --- a/src/journal.h +++ b/src/journal.h @@ -1,7 +1,7 @@ -#if defined BASE \ - || !defined BASE && !defined PRIVATE && !defined PROTO /* */ +#define TREE_NAME day +#define TREE_KEY union date32 +#define TREE_VALUE const char * +#define TREE_HEAD +#include "../src/tree.h" -#if defined PRIVATE \ - || !defined BASE && !defined PRIVATE && !defined PROTO /* */ - - -#if defined PROTO \ - || !defined BASE && !defined PRIVATE && !defined PROTO /* */ -#ifdef BASE -#undef BASE -#endif -#ifdef PRIVATE -#undef PRIVATE -#endif -#ifdef PROTO -#undef PROTO -#endif +#endif /* JOURNAL_H */ diff --git a/src/journal.re.c b/src/journal.re.c index 5071298..d824575 100644 --- a/src/journal.re.c +++ b/src/journal.re.c @@ -6,8 +6,7 @@ telling the recursion to go into a directory. @std GNU, C11, assumes reverse order unions. */ -#define BASE -#include "../src/journal.h" /* base */ +#include "../src/journal.h" #include /* C99 */ #include #include @@ -30,11 +29,12 @@ static void day_to_string(const union date32 d, const char *const*const entry, #define TREE_NAME day #define TREE_KEY union date32 #define TREE_VALUE const char * -#define TREE_COMPARE /* custom comparison. */ -#define TREE_TO_STRING /* printing day. */ +#define TREE_COMPARE +#define TREE_TO_STRING +#define TREE_BODY #include "../src/tree.h" -/* Temporary filename arrangement in directory. */ +/* Temporary filename arrangement in directory; private. */ #if INT_MAX >= 100000000000 #error int_to_string requires truncation on this compiler. #endif @@ -105,9 +105,6 @@ static unsigned looks_like_day(const char *const a) { */ } -#define PROTO -#include "../src/journal.h" /* Just prototypes. */ - /** Erases memory allocation for `j`. */ void journal_(struct journal *const j) { if(!j) return; diff --git a/src/kjv.h b/src/kjv.h index eae24a1..db5b2e5 100644 --- a/src/kjv.h +++ b/src/kjv.h @@ -1,45 +1,11 @@ -#if defined BASE \ - || !defined BASE && !defined PRIVATE && !defined PROTO /* */ +#include "kjvcount.h" +#define TREE_NAME kjvline +#define TREE_KEY union line64 +#define TREE_VALUE struct kjvrange +#define TREE_HEAD +#include "../src/tree.h" -#if defined PRIVATE \ - || !defined BASE && !defined PRIVATE && !defined PROTO /* */ #if defined PROTO \ diff --git a/src/kjv.re.c b/src/kjv.re.c index 93fa460..4d8e701 100644 --- a/src/kjv.re.c +++ b/src/kjv.re.c @@ -3,8 +3,7 @@ Scan journal entries for kjv references. */ -#include "../src/journal.h" -#define BASE +#include "../src/source.h" #include "../src/kjv.h" #include "../src/pair.h" #include /* C99 */ @@ -24,13 +23,10 @@ static int kjvline_compare(const union line64 a, const union line64 b) #define TREE_VALUE struct kjvrange #define TREE_COMPARE #define TREE_TO_STRING +#define TREE_BODY #include "../src/tree.h" -#define PROTO -#include "../src/kjv.h" /* proto */ - - /*!conditions:re2c*/ static int scan(union date32 date, const char *const buffer, @@ -242,8 +238,6 @@ int kjv_line_next(struct kjvline_tree_iterator *const it, union line64 *const k, -#include "../src/source.h" - int main(void) { int success = EXIT_SUCCESS; const char *reason = 0; diff --git a/src/kjvcount.h b/src/kjvcount.h index 2e4eadb..5a2208a 100644 --- a/src/kjvcount.h +++ b/src/kjvcount.h @@ -1,5 +1,3 @@ -#if defined BASE \ - || !defined BASE && !defined PRIVATE && !defined PROTO /* */ +#define TABLE_NAME kjvset +#define TABLE_KEY union kjvcite +#define TABLE_UINT uint32_t +#define TABLE_UNHASH +#define TABLE_HEAD +#include "../src/table.h" -#if defined PRIVATE \ - || !defined BASE && !defined PRIVATE && !defined PROTO /* */ +#define TABLE_NAME count +#define TABLE_KEY union kjvcite +#define TABLE_UINT uint32_t +#define TABLE_VALUE unsigned +#define TABLE_UNHASH +#define TABLE_HEAD +#include "../src/table.h" - -#if defined PROTO \ - || !defined BASE && !defined PRIVATE && !defined PROTO /* */ - - -#ifdef BASE -#undef BASE -#endif -#ifdef PRIVATE -#undef PRIVATE -#endif -#ifdef PROTO -#undef PROTO -#endif diff --git a/src/kjvcount.re.c b/src/kjvcount.re.c index baca586..e777b8c 100644 --- a/src/kjvcount.re.c +++ b/src/kjvcount.re.c @@ -8,7 +8,6 @@ "All included Bible translations are in the public domain." @std C11 */ -#define BASE #include "../src/kjvcount.h" #include "../src/text.h" #include "../src/pair.h" @@ -18,7 +17,6 @@ #include #include /* opendir readdir closedir */ #include /* chdir (POSIX) (because I'm lazy) */ -/* #include No; overkill. */ void kjvcite_to_string(const union kjvcite x, char (*const a)[12]) @@ -58,6 +56,7 @@ static void kjvset_to_string(const union kjvcite x, char (*const a)[12]) #define TABLE_UINT uint32_t #define TABLE_UNHASH #define TABLE_TO_STRING +#define TABLE_BODY #include "../src/table.h" /* Derived information on verse word count. */ @@ -72,6 +71,7 @@ static void count_to_string(const union kjvcite x, const unsigned count, #define TABLE_UNHASH #define TABLE_DEFAULT 0 #define TABLE_TO_STRING +#define TABLE_BODY #include "../src/table.h" @@ -145,9 +145,6 @@ scan: } -#define PROTO -#include "../src/kjvcount.h" /* Just the kjv and prototypes. */ - /** Frees `kjv`. */ void kjvcount_(struct kjvcount *const count) { if(!count) return;