diff --git a/src/driver.c b/src/driver.c index bc07828..f90f046 100644 --- a/src/driver.c +++ b/src/driver.c @@ -17,8 +17,8 @@ int main(void) { struct scan scn = {0}; errno = 0; - intent = "../journal"; - jrnl = journal(intent); + intent = "journal (cwd)"; + jrnl = journal(); fprintf(stderr, "Journal: %s.\n", journal_to_string(&jrnl)); if(errno) goto catch; diff --git a/src/journal.h b/src/journal.h index 5dc9299..1155d5b 100644 --- a/src/journal.h +++ b/src/journal.h @@ -25,7 +25,7 @@ union date32 date32_next_month(union date32 d); #include "text.h" struct journal { struct day_tree days; struct char_array backing; }; struct journal_iterator { struct day_tree_iterator _; }; -struct journal journal(const char *); +struct journal journal(void); void journal_(struct journal *); int journal_is_empty(const struct journal *); const char *journal_to_string(const struct journal *); diff --git a/src/journal.re.c b/src/journal.re.c index e4340d1..1fae205 100644 --- a/src/journal.re.c +++ b/src/journal.re.c @@ -124,9 +124,9 @@ void journal_(struct journal *const j) { text_(&j->backing); } -/** @return A completed journal out of `dir_journal`. Any reading errors and - `errno` will be set, it will be idle. */ -struct journal journal(const char *const dir_journal) { +/** @return A completed journal. Any reading errors and `errno` will be set, + and will return will be idle. */ +struct journal journal(void/*const char *const dir_journal*/) { struct journal j = {0}; char *intent = 0; DIR *dir = 0; @@ -136,12 +136,10 @@ struct journal journal(const char *const dir_journal) { int *y = 0, *y_end, *m = 0, *m_end, *d = 0, *d_end; struct day_tree_iterator it; union { const char **text; uintptr_t *offset; } v; - char cwd[256]; - int is_dir_journal = 0; /* Get the years list as directories matching a year. */ - if(!getcwd(cwd, sizeof cwd) || chdir(dir_journal) == -1) goto catch; - is_dir_journal = 1; + /*if(!getcwd(cwd, sizeof cwd) || chdir(dir_journal) == -1) goto catch; + is_dir_journal = 1;*/ if(!(dir = opendir("."))) goto catch; while((de = readdir(dir))) { struct stat st; @@ -155,8 +153,7 @@ struct journal journal(const char *const dir_journal) { if(closedir(dir)) { dir = 0; goto catch; } dir = 0; /* Sort the years. */ qsort(years.data, years.size, sizeof *years.data, &void_int_cmp); - fprintf(stderr, "Loading years in <<%s>>: %s.\n", - dir_journal, int_array_to_string(&years)); + fprintf(stderr, "Loading years: %s.\n", int_array_to_string(&years)); /* Go though each year. */ for(y = years.data, y_end = y + years.size; y < y_end; y++) { @@ -218,7 +215,7 @@ struct journal journal(const char *const dir_journal) { m = 0, int_array_clear(&months); if(chdir("..") == -1) goto catch; } - if(chdir("../..") == -1 || !day_tree_bulk_finish(&j.days)) goto catch; + if(/*chdir("../..") == -1 ||*/ !day_tree_bulk_finish(&j.days)) goto catch; /* Structure is now stable because we aren't going to move it; convert all of offsets back to pointers. */ @@ -228,17 +225,17 @@ struct journal journal(const char *const dir_journal) { goto finally; catch: - fprintf(stderr, "On date: %s/%d-%.2d-%.2d.\n", - dir_journal, y ? *y : 0, m ? *m : 0, d ? *d : 0); + fprintf(stderr, "On date: %d-%.2d-%.2d.\n", + y ? *y : 0, m ? *m : 0, d ? *d : 0); if(intent) fprintf(stderr, "(%s)\n", intent); recatch: journal_(&j); finally: if(dir) { if(closedir(dir)) { dir = 0; goto recatch; } dir = 0; } - if(is_dir_journal) { + /*if(is_dir_journal) { if(chdir(cwd) == -1) { is_dir_journal = 0; goto recatch; } is_dir_journal = 0; - } + }*/ int_array_(&years), int_array_(&months), int_array_(&days); /* Temporary. */ return j; } diff --git a/src/scan.re.c b/src/scan.re.c index 937f69b..5d9b4b4 100644 --- a/src/scan.re.c +++ b/src/scan.re.c @@ -173,7 +173,7 @@ static int scan_day(struct scan *const scan, union date32 date, no content. */ size_t line = 1; char datestr[12] = {0}; - const char *fail = "perhaps a bat?"; + const char *fail = "perhaps a bat?", *lastnl = buffer; struct { enum YYCONDTYPE future; union { @@ -235,7 +235,8 @@ static int scan_day(struct scan *const scan, union date32 date, * { fail = "newline expected"; goto catch; } "\x00" { fail = "no newline at end of file"; goto catch; } "\x00" { return 1; } /* End of day. */ - "\n" => line { line++; continue; } + "\n" @s1 => line + { line++; lastnl = s1; continue; } * :=> skip "->" :=> place "--" / [^-] :=> source @@ -277,8 +278,7 @@ static int scan_day(struct scan *const scan, union date32 date, /* Whatsapp messages ignored. [11-03, 04:19] Contact: massage Hopefully they don't have a ':' in their name. */ [0-1][0-9] "-" [0-3][0-9] ", " [0-2][0-9] ":" [0-5][0-9] "] " - @s0 [^\x00\n:]+ @s1 ":" [^\x00\n]* "\n" => line { - line++; + @s0 [^\x00\n:]+ @s1 ":" [^\x00\n]* / "\n" => skip { fprintf(stderr, "Whatsapp message from %.*s ignored.\n", (int)(s1 - s0), s0); continue; @@ -730,12 +730,12 @@ static int scan_day(struct scan *const scan, union date32 date, &new_glider->instr_min)) { fail = "glider instr time"; goto catch; } continue; } * { fail = "glider remarks"; goto catch; } - "\n" => line + "\n" @s1 => line { new_glider->remarks.a = new_glider->remarks.b = 0; - new_glider = 0; line++; continue; } - ws* @s0 anylabel @s1 "\n" => line + new_glider = 0; line++; lastnl = s1; continue; } + ws* @s0 anylabel @s1 "\n" @t1 => line { new_glider->remarks.a = s0, new_glider->remarks.b = s1; - new_glider = 0; line++; continue; } + new_glider = 0; line++; lastnl = t1; continue; } /* type; registration; launch -- landing; pic; sic; @@ -802,12 +802,12 @@ static int scan_day(struct scan *const scan, union date32 date, &new_flight->ifr_min)) { fail = "flight ifr time"; goto catch; } continue; } * { fail = "flight remarks"; goto catch; } - "\n" => line + "\n" @s1 => line { new_flight->remarks.a = new_flight->remarks.b = 0; - new_flight = 0; line++; continue; } - ws* @s0 anylabel @s1 "\n" => line + new_flight = 0; line++; lastnl = s1; continue; } + ws* @s0 anylabel @s1 "\n" @t1 => line { new_flight->remarks.a = s0, new_flight->remarks.b = s1; - new_flight = 0; line++; continue; } + new_flight = 0; line++; lastnl = t1; continue; } /* Books in KJV. */ @@ -929,24 +929,24 @@ static int scan_day(struct scan *const scan, union date32 date, ws { continue; } "<<\n" @s0 => input_text_multi { // multi-line input.pair->a = s0; - line++; + line++; lastnl = s0; continue; } - @s0 anylabel? @s1 "\n" => line { // one line; last one - fprintf(stderr, "text: <<%.*s>>\n", (int)(s1 - s0), s0); + @s0 anylabel? @s1 "\n" @t0 => line { // one line; last one + /*fprintf(stderr, "text: <<%.*s>>\n", (int)(s1 - s0), s0);*/ input.pair->a = s0, input.pair->b = s1; if(input.future != yycnewline) { fail = "use <>"; goto catch; } - line++; + line++; lastnl = t0; continue; } [^\x00\n] { continue; } [\x00] { fail = "missing closing \">>\""; goto catch; } - "\n" { line++; continue; } + "\n" @s1 { line++; lastnl = s1; continue; } @s1 ">>" / [^>] /*future*/ { - fprintf(stderr, "text: <<\n%.*s>>\n", - (int)(s1 - input.pair->a), input.pair->a); + /*fprintf(stderr, "text: <<\n%.*s>>\n", + (int)(s1 - input.pair->a), input.pair->a);*/ input.pair->b = s1; condition = input.future; continue; @@ -971,7 +971,11 @@ static int scan_day(struct scan *const scan, union date32 date, catch: if(!errno) errno = EILSEQ; date32_to_string(date, &datestr); - fprintf(stderr, "%s line %zu fail: %s" /*" condition %d"*/ ".\n", + if(s1 = strchr(lastnl, '\n')) { + fprintf(stderr, "%.*s\n", (int)(s1 - lastnl), lastnl); + } + fprintf(stderr, + "%s line %zu fail: %s" /*" condition %d"*/ ".\n", datestr, line, fail/*, condition*/); return 0; } @@ -1266,7 +1270,7 @@ void scan_flight_graph(struct scan *const scan) { flight_tree_to_string(&scan->flights)); printf("set terminal pngcairo dashed transparent truecolor" " size 840, 480 fontscale 1\n" - "set output \"glider.png\"\n"); + "set output \"flight.png\"\n"); printf("$Data <flights);