From d6c1b22b5dbb77001ebc662326fa80193b0bba2c Mon Sep 17 00:00:00 2001 From: Neil Date: Fri, 21 Apr 2023 20:11:57 -0700 Subject: [PATCH] scan faults. --- Makefile | 3 ++- language.txt | 37 +++++++++++++++---------------------- src/driver.c | 29 +++++++++++++++++++++++++++++ src/journal.re.c | 12 ++++-------- src/pair.c | 5 +++-- 5 files changed, 53 insertions(+), 33 deletions(-) create mode 100644 src/driver.c diff --git a/Makefile b/Makefile index 437e573..a16af21 100644 --- a/Makefile +++ b/Makefile @@ -30,7 +30,7 @@ else CF += -g endif -projects := bin/test-text bin/test-journal bin/test-source bin/test-kjv bin/kjv bin/flight bin/score +projects := bin/test-text bin/test-journal bin/test-source bin/test-kjv bin/kjv bin/flight bin/score bin/scan #docs := $(patsubst test/test_%.c, doc/%.md, $(wildcard test/test_*.c)) default: $(projects) @@ -43,6 +43,7 @@ bin/test-kjv: build/text.o build/pair.o build/kjvcite.o build/test_kjv.o bin/kjv: build/text.o build/pair.o build/journal.o build/kjvcite.o build/kjv.o build/source.o bin/flight: build/text.o build/pair.o build/journal.o build/source.o build/flights.o build/flighthours.o bin/score: build/text.o build/pair.o build/journal.o build/scores.o +bin/scan: build/text.o build/journal.o build/pair.o build/driver.o bin/%: @echo "\033[1;36mlinking $@\033[0m" diff --git a/language.txt b/language.txt index 583d9ff..31523a1 100644 --- a/language.txt +++ b/language.txt @@ -1,15 +1,10 @@ -!checked off -^crossed off -1. Numbered list -* Unordered list +__lines__ --label: string --label -# heading ->(#,#) label ->label [ed: date] string [contact: label] string -[medical] [book: title] string [tv: label] string [movie: label] string @@ -17,22 +12,20 @@ [vaccine: label] string [in: amount] string [flight] type; regn; apt1 -- apt2; pic1; pic2; dual; solo; ; ; +[gliding] ... [cra: line] amount [idea: string] string - -Whatsapp: -[DD-DD, DD:DD] name: message - -string << -free ->> - -[document: label] << -free ->> - -[mail: string] << -free ->> - +[document: label] string +[mail: string] string Bible 1:1 -- ignored +[DD-DD, DD:DD] name: message (Whatsapp) +!checked off +^crossed off +<-[[Y-]MM-]DD +[[Y-]MM-]DD-> +1. Numbered list +* Unordered list +# Heading + +__tags__ +...... diff --git a/src/driver.c b/src/driver.c new file mode 100644 index 0000000..ea6ed64 --- /dev/null +++ b/src/driver.c @@ -0,0 +1,29 @@ +/** @license 2023 Neil Edelman, distributed under the terms of the + [MIT License](https://opensource.org/licenses/MIT). + + Scan source files for meanings. + + @std C99 */ + +#include "journal.h" +#include +#include +#include + +int main(void) { + const char *fail = 0; + struct journal jrnl = {0}; + errno = 0; + + jrnl = journal("../journal"); + fprintf(stderr, "Journal: %s.\n", journal_to_string(&jrnl)); + if(errno) goto catch; + + goto finally; +catch: + if(!fail) fail = "scan"; + perror(fail); +finally: + journal_(&jrnl); + return fail ? EXIT_FAILURE : EXIT_SUCCESS; +} diff --git a/src/journal.re.c b/src/journal.re.c index dedf01a..065e53b 100644 --- a/src/journal.re.c +++ b/src/journal.re.c @@ -44,8 +44,10 @@ static void int_to_string(const int *const n, char (*const a)[12]) #define ARRAY_TYPE int #define ARRAY_TO_STRING #include "../src/array.h" +/** Comparator of `a`, `b`. */ static int int_cmp(const int *const a, const int *const b) { return (*b < *a) - (*a < *b); } +/** For `qsort`. */ static int void_int_cmp(const void *const a, const void *const b) { return int_cmp(a, b); } @@ -211,14 +213,8 @@ struct journal journal(const char *const dir_journal) { /* Structure is now stable because we aren't going to move it; convert all of offsets back to pointers. */ it = day_tree_iterator(&j.days); - while(day_tree_next(&it)) { - v.text = day_tree_value(&it); - /*printf("[%zu]...", *v.offset);*/ - *v.text = j.backing.data + *v.offset; - /*printf("<%.32s>\n", *v.text);*/ - } - /*fprintf(stderr, "Journal has entries: %s\n", - day_tree_to_string(&j.days));*/ + while(day_tree_next(&it)) + *(v.text = day_tree_value(&it)) = j.backing.data + *v.offset; goto finally; catch: fprintf(stderr, "On date: %s/%d-%.2d-%.2d.\n", diff --git a/src/pair.c b/src/pair.c index 1587206..b0da5e1 100644 --- a/src/pair.c +++ b/src/pair.c @@ -1,7 +1,7 @@ /** @license 2023 Neil Edelman, distributed under the terms of the [MIT License](https://opensource.org/licenses/MIT). - A `pair` is `[a, b)` pair of pointers to char. + A `pair` is `[a, b)` pair of pointers to char. Used in most string parsing. @std C99 */ @@ -10,9 +10,10 @@ #include #include -/** @return Constructs `a` and `b` as a pair. */ +/** @return Constructs `a` and `b` as a pair [or else (0,0)?]. */ struct pair pair(const char *const a, const char *const b) { struct pair p; + assert(a && a <= b); p.a = a, p.b = b; return p; }