1995agenda

This commit is contained in:
Neil 2022-05-24 19:47:13 -07:00
parent a97980ef59
commit fd1a6d4745
1 changed files with 21 additions and 10 deletions

View File

@ -106,24 +106,31 @@ struct page {
struct char_array entry; struct char_array entry;
struct lex_array lexx; struct lex_array lexx;
}; };
#define ARRAY_NAME page #define POOL_NAME page
#define ARRAY_TYPE struct page #define POOL_TYPE struct page
#include "array.h" #include "pool.h"
struct source { char *key, *desc; }; struct source { char *key, *desc; };
int main(int argc, char **argv) { int main(int argc, char **argv) {
/* Return value. */
int success = EXIT_FAILURE; int success = EXIT_FAILURE;
/* For reading in files, overwritten. */
DIR *dir = 0; DIR *dir = 0;
struct dirent *de; struct dirent *de;
struct int_array years = ARRAY_IDLE, months = ARRAY_IDLE, days = ARRAY_IDLE; struct int_array years = ARRAY_IDLE, months = ARRAY_IDLE, days = ARRAY_IDLE;
struct page_array pages = ARRAY_IDLE;
int *y, *y_end; 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; errno = 0;
if(argc != 2) { fprintf(stderr, "Needs journal location.\n" if(argc != 2) { fprintf(stderr, "Needs journal location.\n"
"(should contain <year>/<month>/<day>.txt)\n"); goto finally; } "(should contain <year>/<month>/<day>.txt)\n"); goto finally; }
/* Get the years list as directories matching a year. */
if(chdir(argv[1]) == -1 || !(dir = opendir("."))) goto catch; if(chdir(argv[1]) == -1 || !(dir = opendir("."))) goto catch;
while((de = readdir(dir))) { while((de = readdir(dir))) {
struct stat st; struct stat st;
@ -184,14 +191,14 @@ int main(int argc, char **argv) {
fn, int_array_to_string(&days)); fn, int_array_to_string(&days));
for(d = days.data, d_end = d + days.size; d < d_end; d++) { for(d = days.data, d_end = d + days.size; d < d_end; d++) {
struct page *page; union date32 d32;
if(!(page = page_array_new(&pages))) goto catch;
char_array(&page->entry);
lex_array(&page->lexx);
printf("Date: %d-%.2d-%.2d\n", *y, *m, *d); 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; } { errno = EILSEQ; goto catch; }
sprintf(fn, "%.2d.txt", *d); 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; if(!append_file(&page->entry, fn)) goto catch;
printf("%s", page->entry.data); printf("%s", page->entry.data);
printf("Lexing:\n"); printf("Lexing:\n");
@ -216,6 +223,8 @@ int main(int argc, char **argv) {
} }
printf(".\n"); printf(".\n");
} }
/* Transfer the temporary page to the journal. */
page = 0;
} }
int_array_clear(&days); int_array_clear(&days);
@ -234,6 +243,8 @@ finally:
int_array_(&years); int_array_(&years);
int_array_(&months); int_array_(&months);
int_array_(&days); 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; struct page *page;
while(page = page_array_pop(&pages)) while(page = page_array_pop(&pages))