Changed the way we get the input; now interpret file in cwd.

This commit is contained in:
Neil 2023-08-23 15:33:21 -07:00
parent af512793b0
commit 5d111433c3
72 changed files with 53 additions and 8 deletions

3
derived/.gitignore vendored
View File

@ -1,2 +1,5 @@
* *
!.gitignore !.gitignore
!interpret
!kjv/
!kjv/*

1
derived/interpret Normal file
View File

@ -0,0 +1 @@
../../journal/

View File

@ -10,41 +10,73 @@
#include <stdio.h> #include <stdio.h>
#include <errno.h> #include <errno.h>
#include <assert.h> #include <assert.h>
#include <unistd.h> /* getcwd, chdir */
int main(void) { int main(void) {
const char *intent = "start"; const char *intent = "start";
struct journal jrnl = {0}; struct journal jrnl = {0};
struct scan scn = {0}; struct scan scn = {0};
int showhelp = 1;
FILE *fpwhere = 0;
char cwd[PATH_MAX], jdir[PATH_MAX];
errno = 0; errno = 0;
intent = "journal (cwd)"; intent = "current directory";
if(!getcwd(cwd, sizeof(cwd))) goto catch;
intent = "interpret";
if(!(fpwhere = fopen(intent, "r"))) goto catch;
if(!fgets(jdir, sizeof jdir, fpwhere)) {
if(!errno) errno = EDOM;
fprintf(stderr, "first line error\n");
goto catch;
}
if(fgetc(fpwhere) != EOF) {
fprintf(stderr, "expected eof\n");
errno = EDOM; goto catch;
}
/* Could be something other than EOF. */
if(errno || (fclose(fpwhere) == EOF && (fpwhere = 0, 1))) goto catch;
fpwhere = 0;
jdir[strcspn(jdir, "\n")] = '\0'; /* Strip. */
if(chdir(jdir)) {
fprintf(stderr, "while switching to directory: %s\n", jdir);
goto catch;
}
showhelp = 0;
intent = "journal";
jrnl = journal(); jrnl = journal();
fprintf(stderr, "Journal: %s.\n", journal_to_string(&jrnl)); fprintf(stderr, "Journal: %s.\n", journal_to_string(&jrnl));
if(errno) goto catch; if(errno) goto catch;
intent = cwd;
if(chdir(cwd)) goto catch;
intent = "parse"; intent = "parse";
scn = scan(&jrnl); scn = scan(&jrnl);
//fprintf(stderr, "Scan: %s.\n", scan_to_string(&scrs)); //fprintf(stderr, "Scan: %s.\n", scan_to_string(&scrs));
// <- Not sure what that would do. // <- Not sure what that would do.
if(errno) goto catch; if(errno) goto catch;
intent = "derived/score.gnu"; intent = "score.gnu";
if(!freopen(intent, "w", stdout)) goto catch; if(!freopen(intent, "w", stdout)) goto catch;
scan_score_graph(&scn); scan_score_graph(&scn);
intent = "derived/glider.gnu"; intent = "glider.gnu";
if(!freopen(intent, "w", stdout)) goto catch; if(!freopen(intent, "w", stdout)) goto catch;
scan_glider_graph(&scn); scan_glider_graph(&scn);
intent = "derived/flight.gnu"; intent = "flight.gnu";
if(!freopen(intent, "w", stdout)) goto catch; if(!freopen(intent, "w", stdout)) goto catch;
scan_flight_graph(&scn); scan_flight_graph(&scn);
intent = "derived/kjv.gnu"; intent = "kjv.gnu";
if(!freopen(intent, "w", stdout)) goto catch; if(!freopen(intent, "w", stdout)) goto catch;
scan_kjv_graph(&scn); scan_kjv_graph(&scn);
intent = "derived/dream.gnu"; intent = "dream.gnu";
if(!freopen(intent, "w", stdout)) goto catch; if(!freopen(intent, "w", stdout)) goto catch;
scan_dream_graph(&scn); scan_dream_graph(&scn);
@ -55,7 +87,16 @@ catch:
finally: finally:
/* fixme: ~scan should be idempotent but it's not on disabling ASLR, which /* fixme: ~scan should be idempotent but it's not on disabling ASLR, which
debug mode is in. */ debug mode is in. */
if(fpwhere && fclose(fpwhere) == EOF)
intent = "interpret", perror(intent);
scan_(&scn); scan_(&scn);
journal_(&jrnl); journal_(&jrnl);
if(intent && showhelp)
fprintf(stderr, "\nMeant to be run in a directory with a file called "
"\"interpret\".\n"
"The contents of that file shall be a directory wherein\n"
"<year>/<month>/<day>.txt, eg 2000/12/01.txt.\n"
"Loads all journal entries and parses them, outputting to the "
"current directory.\n\n");
return intent ? EXIT_FAILURE : EXIT_SUCCESS; return intent ? EXIT_FAILURE : EXIT_SUCCESS;
} }

View File

@ -215,7 +215,7 @@ struct journal journal(void/*const char *const dir_journal*/) {
m = 0, int_array_clear(&months); m = 0, int_array_clear(&months);
if(chdir("..") == -1) goto catch; if(chdir("..") == -1) goto catch;
} }
if(/*chdir("../..") == -1 ||*/ !day_tree_bulk_finish(&j.days)) goto catch; if(!day_tree_bulk_finish(&j.days)) goto catch;
/* Structure is now stable because we aren't going to move it; /* Structure is now stable because we aren't going to move it;
convert all of offsets back to pointers. */ convert all of offsets back to pointers. */

View File

@ -1166,7 +1166,7 @@ void scan_score_graph(struct scan *const scan) {
"myTimeFmt = \"%%Y-%%m-%%d\"\n" "myTimeFmt = \"%%Y-%%m-%%d\"\n"
"set format x myTimeFmt timedate\n" "set format x myTimeFmt timedate\n"
"set xtics format myTimeFmt rotate by -30\n" "set xtics format myTimeFmt rotate by -30\n"
"set ylabel \"meaning CDF (person·day)\"\n" "set ylabel \"person·day cdf\"\n"
"set grid\n" "set grid\n"
"set key out reverse Left noautotitle\n" "set key out reverse Left noautotitle\n"
"set style fill solid 0.5\n" "set style fill solid 0.5\n"