2023-04-29 21:29:27 -07:00
|
|
|
#include "../src/scan.h"
|
2023-02-02 18:53:59 -08:00
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <assert.h>
|
2023-02-03 11:50:10 -08:00
|
|
|
#include <errno.h>
|
2023-02-02 18:53:59 -08:00
|
|
|
|
|
|
|
int main(void) {
|
|
|
|
int success = EXIT_SUCCESS;
|
2023-03-10 20:06:11 -08:00
|
|
|
errno = 0; /* `errno` is not set correctly to 0 in some debug situations. */
|
2023-04-29 21:29:27 -07:00
|
|
|
struct journal jrnl = journal("../journal");
|
|
|
|
struct scan scn = scan(&jrnl);
|
2023-02-02 18:53:59 -08:00
|
|
|
if(errno) goto catch;
|
2023-02-04 19:06:43 -08:00
|
|
|
|
|
|
|
const union line64 agenda = {{4,{{20,04,1996}}}},
|
|
|
|
before = {{1,{{1,1,1900}}}},
|
|
|
|
noentry = {{3,{{1,6,1995}}}};
|
2023-05-07 00:22:58 -07:00
|
|
|
const struct kvpair *source;
|
2023-02-04 19:06:43 -08:00
|
|
|
|
2023-04-29 21:29:27 -07:00
|
|
|
source = scan_source_lookup(&scn, agenda);
|
2023-02-04 19:06:43 -08:00
|
|
|
printf("agenda: <%.*s>\n",
|
2023-05-07 00:22:58 -07:00
|
|
|
(int)(source->key.b - source->key.a), source->key.a);
|
|
|
|
assert(pair_is_string(source->key, "1995agenda"));
|
2023-02-04 19:06:43 -08:00
|
|
|
|
2023-04-29 21:29:27 -07:00
|
|
|
source = scan_source_lookup(&scn, before);
|
2023-02-04 19:06:43 -08:00
|
|
|
printf("before: <%.*s>\n",
|
2023-05-07 00:22:58 -07:00
|
|
|
(int)(source->key.b - source->key.a), source->key.a);
|
|
|
|
assert(pair_is_string(source->key, 0));
|
2023-02-04 19:06:43 -08:00
|
|
|
|
2023-04-29 21:29:27 -07:00
|
|
|
source = scan_source_lookup(&scn, noentry);
|
2023-02-04 19:06:43 -08:00
|
|
|
printf("noentry: <%.*s>\n",
|
2023-05-07 00:22:58 -07:00
|
|
|
(int)(source->key.b - source->key.a), source->key.a);
|
|
|
|
assert(pair_is_string(source->key, 0));
|
2023-02-04 19:06:43 -08:00
|
|
|
|
2023-02-02 18:53:59 -08:00
|
|
|
goto finally;
|
|
|
|
catch:
|
|
|
|
success = EXIT_FAILURE, perror("source");
|
|
|
|
finally:
|
2023-04-29 21:29:27 -07:00
|
|
|
scan_(&scn);
|
|
|
|
journal_(&jrnl);
|
2023-02-02 18:53:59 -08:00
|
|
|
return success;
|
|
|
|
}
|