From fd1a6d47450e8828612afb43fadf7bb96cbb2cbc Mon Sep 17 00:00:00 2001 From: Neil Date: Tue, 24 May 2022 19:47:13 -0700 Subject: [PATCH] 1995agenda --- src/interpret.c | 31 +++++++++++++++++++++---------- 1 file changed, 21 insertions(+), 10 deletions(-) diff --git a/src/interpret.c b/src/interpret.c index 036ac97..e8c417b 100644 --- a/src/interpret.c +++ b/src/interpret.c @@ -106,24 +106,31 @@ struct page { struct char_array entry; struct lex_array lexx; }; -#define ARRAY_NAME page -#define ARRAY_TYPE struct page -#include "array.h" +#define POOL_NAME page +#define POOL_TYPE struct page +#include "pool.h" struct source { char *key, *desc; }; int main(int argc, char **argv) { + /* Return value. */ int success = EXIT_FAILURE; + + /* For reading in files, overwritten. */ DIR *dir = 0; struct dirent *de; struct int_array years = ARRAY_IDLE, months = ARRAY_IDLE, days = ARRAY_IDLE; - struct page_array pages = ARRAY_IDLE; int *y, *y_end; - /* Get the years list as directories matching a year in order. */ + /* Backing for individual pages; temporary page yet to be placed. */ + struct page_pool pages = POOL_IDLE; + struct page *page = 0; + errno = 0; if(argc != 2) { fprintf(stderr, "Needs journal location.\n" "(should contain //.txt)\n"); goto finally; } + + /* Get the years list as directories matching a year. */ if(chdir(argv[1]) == -1 || !(dir = opendir("."))) goto catch; while((de = readdir(dir))) { struct stat st; @@ -184,14 +191,14 @@ int main(int argc, char **argv) { fn, int_array_to_string(&days)); for(d = days.data, d_end = d + days.size; d < d_end; d++) { - struct page *page; - if(!(page = page_array_new(&pages))) goto catch; - char_array(&page->entry); - lex_array(&page->lexx); + union date32 d32; printf("Date: %d-%.2d-%.2d\n", *y, *m, *d); - if(!((page->date = date_to_32(*y, *m, *d))).year) + if(!(d32 = date_to_32(*y, *m, *d)).year) { errno = EILSEQ; goto catch; } sprintf(fn, "%.2d.txt", *d); + if(!(page = page_pool_new(&pages))) goto catch; + char_array(&page->entry); + lex_array(&page->lexx); if(!append_file(&page->entry, fn)) goto catch; printf("%s", page->entry.data); printf("Lexing:\n"); @@ -216,6 +223,8 @@ int main(int argc, char **argv) { } printf(".\n"); } + /* Transfer the temporary page to the journal. */ + page = 0; } int_array_clear(&days); @@ -234,6 +243,8 @@ finally: int_array_(&years); int_array_(&months); int_array_(&days); + /* Got up to creating a page, but didn't add to the journal. */ + if(page) { lex_array_(&page->lexx); char_array(&page->entry); } { struct page *page; while(page = page_array_pop(&pages))