Tried to simplify reading by making it the surrent directory.
This commit is contained in:
parent
8b4e83e2ea
commit
ea4cf06785
@ -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;
|
||||
|
||||
|
@ -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 *);
|
||||
|
@ -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;
|
||||
}
|
||||
|
@ -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,
|
||||
<newline> * { fail = "newline expected"; goto catch; }
|
||||
<skip> "\x00" { fail = "no newline at end of file"; goto catch; }
|
||||
<line> "\x00" { return 1; } /* End of day. */
|
||||
<line, skip, newline> "\n" => line { line++; continue; }
|
||||
<line, skip, newline> "\n" @s1 => line
|
||||
{ line++; lastnl = s1; continue; }
|
||||
<line> * :=> skip
|
||||
<line> "->" :=> place
|
||||
<line> "--" / [^-] :=> 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. */
|
||||
<bracket> [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; }
|
||||
<glider_remarks> * { fail = "glider remarks"; goto catch; }
|
||||
<glider_remarks> "\n" => line
|
||||
<glider_remarks> "\n" @s1 => line
|
||||
{ new_glider->remarks.a = new_glider->remarks.b = 0;
|
||||
new_glider = 0; line++; continue; }
|
||||
<glider_remarks> ws* @s0 anylabel @s1 "\n" => line
|
||||
new_glider = 0; line++; lastnl = s1; continue; }
|
||||
<glider_remarks> 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; }
|
||||
<flight_remarks> * { fail = "flight remarks"; goto catch; }
|
||||
<flight_remarks> "\n" => line
|
||||
<flight_remarks> "\n" @s1 => line
|
||||
{ new_flight->remarks.a = new_flight->remarks.b = 0;
|
||||
new_flight = 0; line++; continue; }
|
||||
<flight_remarks> ws* @s0 anylabel @s1 "\n" => line
|
||||
new_flight = 0; line++; lastnl = s1; continue; }
|
||||
<flight_remarks> 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,
|
||||
<input_text> ws { continue; }
|
||||
<input_text> "<<\n" @s0 => input_text_multi { // multi-line
|
||||
input.pair->a = s0;
|
||||
line++;
|
||||
line++; lastnl = s0;
|
||||
continue;
|
||||
}
|
||||
<input_text> @s0 anylabel? @s1 "\n" => line { // one line; last one
|
||||
fprintf(stderr, "text: <<%.*s>>\n", (int)(s1 - s0), s0);
|
||||
<input_text> @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 <<text>>"; goto catch; }
|
||||
line++;
|
||||
line++; lastnl = t0;
|
||||
continue;
|
||||
}
|
||||
<input_text_multi> [^\x00\n] { continue; }
|
||||
<input_text_multi> [\x00]
|
||||
{ fail = "missing closing \">>\""; goto catch; }
|
||||
<input_text_multi> "\n" { line++; continue; }
|
||||
<input_text_multi> "\n" @s1 { line++; lastnl = s1; continue; }
|
||||
<input_text_multi> @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 <<EOD\n"
|
||||
"# date, reg, sic, pic, source\n");
|
||||
struct flight_tree_iterator it = flight_tree_iterator(&scan->flights);
|
||||
|
Loading…
Reference in New Issue
Block a user