I think body/head is more understandable than proto/private/base.

This commit is contained in:
Neil 2023-03-18 21:30:13 -07:00
parent 2844eeffd5
commit ac983acf22
10 changed files with 48 additions and 162 deletions

View File

@ -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)

View File

@ -3,7 +3,6 @@
Date _vs_ hours flown. */
#include "journal.h"
#include "flights.h"
#include "source.h"
#include <stdlib.h>

View File

@ -1,5 +1,3 @@
#if defined BASE \
|| !defined BASE && !defined PRIVATE && !defined PROTO /* <!-- base */
#define LAUNCH_TYPE \
X(MotorCarTow),\
X(Winch),\
@ -43,26 +41,14 @@ struct flight {
union { struct glider glider; struct power power; };
};
/*void kjvcite_to_string(const union kjvcite, char (*)[12]);*/
#endif /* base --> */
#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 /* <!-- generic */
struct tree_flight_node;
struct tree_flight_tree { struct tree_flight_node *node; unsigned height; };
struct flight_tree { struct tree_flight_tree root; };
struct tree_flight_ref { struct tree_flight_node *node; unsigned height, idx; };
struct tree_flight_iterator {
struct tree_flight_tree *root; struct tree_flight_ref ref; int seen;
};
struct flight_tree_iterator { struct tree_flight_iterator _; };
#endif /* generic --> */
#if defined PROTO \
|| !defined BASE && !defined PRIVATE && !defined PROTO /* <!-- proto */
#include <stddef.h>
struct flights { struct flight_tree _; };
struct flights_iterator { struct flight_tree_iterator _; };
struct flights flights(/*const*/ struct journal *);
@ -71,14 +57,3 @@ const char *flights_to_string(const struct flights *);
struct flights_iterator flights_iterator(struct flights *);
int flights_next(struct flights_iterator *, union line64 *,
const struct flight **);
#endif /* proto --> */
#ifdef BASE
#undef BASE
#endif
#ifdef PRIVATE
#undef PRIVATE
#endif
#ifdef PROTO
#undef PROTO
#endif

View File

@ -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 <stdio.h>
#include <stdlib.h>
#include <assert.h>
@ -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,

View File

@ -1,7 +1,7 @@
#if defined BASE \
|| !defined BASE && !defined PRIVATE && !defined PROTO /* <!-- base */
#include <stddef.h>
#include <stdint.h> /* C99 */
#ifndef JOURNAL_H
#define JOURNAL_H
#include <stdint.h> /* uint32_t C99 */
/** Assumes: reverse ordering of byte-fields; unsigned is defined; C11 or GNU
anonymous unions. */
union date32 {
@ -13,23 +13,13 @@ union line64 {
struct { uint32_t line; union date32 date; }; /* C11, little-endian */
uint64_t u64; /* C99 optional */
};
#endif /* base --> */
#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 /* <!-- generic */
struct tree_day_node;
struct tree_day_tree { struct tree_day_node *node; unsigned height; };
struct day_tree { struct tree_day_tree root; };
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; };
struct day_tree_iterator { struct tree_day_iterator _; };
#endif /* generic --> */
#if defined PROTO \
|| !defined BASE && !defined PRIVATE && !defined PROTO /* <!-- proto */
#include "text.h"
struct journal { struct day_tree days; struct char_array backing; };
struct journal_iterator { struct day_tree_iterator _; };
@ -39,14 +29,5 @@ int journal_is_empty(const struct journal *);
const char *journal_to_string(const struct journal *);
struct journal_iterator journal_iterator(struct journal *const j);
int journal_next(struct journal_iterator *, union date32 *, const char **);
#endif /* proto --> */
#ifdef BASE
#undef BASE
#endif
#ifdef PRIVATE
#undef PRIVATE
#endif
#ifdef PROTO
#undef PROTO
#endif
#endif /* JOURNAL_H */

View File

@ -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 <inttypes.h> /* C99 */
#include <limits.h>
#include <stdio.h>
@ -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 /* <fn:day_compare> custom comparison. */
#define TREE_TO_STRING /* <fn:day_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;

View File

@ -1,45 +1,11 @@
#if defined BASE \
|| !defined BASE && !defined PRIVATE && !defined PROTO /* <!-- base */
#ifdef BASE
#define PUSH_BASE
#undef BASE
#endif
#ifdef PRIVATE
#define PUSH_PRIVATE
#undef PRIVATE
#endif
#ifdef PROTO
#define PUSH_PROTO
#undef PROTO
#endif
#include "kjvcount.h" /* Uses same conflicting system. */
#ifdef PUSH_BASE
#undef PUSH_BASE
#define BASE
#endif
#ifdef PUSH_PRIVATE
#undef PUSH_PRIVATE
#define PRIVATE
#endif
#ifdef PUSH_PROTO
#undef PUSH_PROTO
#define PROTO
#endif
#endif /* base --> */
#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 /* <!-- private */
struct tree_kjvline_node;
struct tree_kjvline_tree { struct tree_kjvline_node *node; unsigned height; };
struct kjvline_tree { struct tree_kjvline_tree root; };
struct tree_kjvline_ref
{ struct tree_kjvline_node *node; unsigned height, idx; };
struct tree_kjvline_iterator {
struct tree_kjvline_tree *root; struct tree_kjvline_ref ref; int seen;
};
struct kjvline_tree_iterator { struct tree_kjvline_iterator _; };
#endif /* private --> */
#if defined PROTO \

View File

@ -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 <inttypes.h> /* 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;

View File

@ -1,5 +1,3 @@
#if defined BASE \
|| !defined BASE && !defined PRIVATE && !defined PROTO /* <!-- base */
#define BOOKS \
X(Genesis),\
X(Exodus),\
@ -83,27 +81,23 @@ union kjvcite {
};
struct kjvrange { union kjvcite start; uint32_t verse_end; };
void kjvcite_to_string(const union kjvcite, char (*)[12]);
#endif /* base --> */
#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 /* <!-- private */
struct table_kjvset_bucket;
struct kjvset_table {
struct table_kjvset_bucket *buckets;
uint32_t log_capacity, size, top;
};
struct table_count_bucket;
struct count_table {
struct table_count_bucket *buckets;
uint32_t log_capacity, size, top;
};
#endif /* private --> */
#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 /* <!-- proto */
#include <stddef.h>
#include <stddef.h> /* size_t */
struct kjvcount {
struct count_table verses;
struct { size_t total, cumulative, set; } words;
@ -120,15 +114,3 @@ void kjv_set_(struct kjvset_table *);
int kjv_set_add(struct kjvset_table *const set,
struct kjvcount *const count, const union kjvcite cite);
const char *kjv_set_to_string(const struct kjvset_table *);
#endif /* proto --> */
#ifdef BASE
#undef BASE
#endif
#ifdef PRIVATE
#undef PRIVATE
#endif
#ifdef PROTO
#undef PROTO
#endif

View File

@ -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 <assert.h>
#include <dirent.h> /* opendir readdir closedir */
#include <unistd.h> /* chdir (POSIX) (because I'm lazy) */
/* #include <cmph.h> 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;