scan faults.

This commit is contained in:
Neil 2023-04-21 20:11:57 -07:00
parent 78ff7dca30
commit d6c1b22b5d
5 changed files with 53 additions and 33 deletions

View File

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

View File

@ -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__
...<medical>...

29
src/driver.c Normal file
View File

@ -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 <stdio.h>
#include <errno.h>
#include <assert.h>
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;
}

View File

@ -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",

View File

@ -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 <errno.h>
#include <assert.h>
/** @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;
}