Changed the way we get the input; now interpret file in cwd.
This commit is contained in:
parent
af512793b0
commit
5d111433c3
3
derived/.gitignore
vendored
3
derived/.gitignore
vendored
@ -1,2 +1,5 @@
|
||||
*
|
||||
!.gitignore
|
||||
!interpret
|
||||
!kjv/
|
||||
!kjv/*
|
||||
|
1
derived/interpret
Normal file
1
derived/interpret
Normal file
@ -0,0 +1 @@
|
||||
../../journal/
|
53
src/driver.c
53
src/driver.c
@ -10,41 +10,73 @@
|
||||
#include <stdio.h>
|
||||
#include <errno.h>
|
||||
#include <assert.h>
|
||||
#include <unistd.h> /* getcwd, chdir */
|
||||
|
||||
int main(void) {
|
||||
const char *intent = "start";
|
||||
struct journal jrnl = {0};
|
||||
struct scan scn = {0};
|
||||
int showhelp = 1;
|
||||
FILE *fpwhere = 0;
|
||||
char cwd[PATH_MAX], jdir[PATH_MAX];
|
||||
|
||||
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();
|
||||
fprintf(stderr, "Journal: %s.\n", journal_to_string(&jrnl));
|
||||
if(errno) goto catch;
|
||||
|
||||
intent = cwd;
|
||||
if(chdir(cwd)) goto catch;
|
||||
|
||||
intent = "parse";
|
||||
scn = scan(&jrnl);
|
||||
//fprintf(stderr, "Scan: %s.\n", scan_to_string(&scrs));
|
||||
// <- Not sure what that would do.
|
||||
if(errno) goto catch;
|
||||
|
||||
intent = "derived/score.gnu";
|
||||
intent = "score.gnu";
|
||||
if(!freopen(intent, "w", stdout)) goto catch;
|
||||
scan_score_graph(&scn);
|
||||
|
||||
intent = "derived/glider.gnu";
|
||||
intent = "glider.gnu";
|
||||
if(!freopen(intent, "w", stdout)) goto catch;
|
||||
scan_glider_graph(&scn);
|
||||
|
||||
intent = "derived/flight.gnu";
|
||||
intent = "flight.gnu";
|
||||
if(!freopen(intent, "w", stdout)) goto catch;
|
||||
scan_flight_graph(&scn);
|
||||
|
||||
intent = "derived/kjv.gnu";
|
||||
intent = "kjv.gnu";
|
||||
if(!freopen(intent, "w", stdout)) goto catch;
|
||||
scan_kjv_graph(&scn);
|
||||
|
||||
intent = "derived/dream.gnu";
|
||||
intent = "dream.gnu";
|
||||
if(!freopen(intent, "w", stdout)) goto catch;
|
||||
scan_dream_graph(&scn);
|
||||
|
||||
@ -55,7 +87,16 @@ catch:
|
||||
finally:
|
||||
/* fixme: ~scan should be idempotent but it's not on disabling ASLR, which
|
||||
debug mode is in. */
|
||||
if(fpwhere && fclose(fpwhere) == EOF)
|
||||
intent = "interpret", perror(intent);
|
||||
scan_(&scn);
|
||||
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;
|
||||
}
|
||||
|
@ -215,7 +215,7 @@ struct journal journal(void/*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(!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. */
|
||||
|
@ -1166,7 +1166,7 @@ void scan_score_graph(struct scan *const scan) {
|
||||
"myTimeFmt = \"%%Y-%%m-%%d\"\n"
|
||||
"set format x myTimeFmt timedate\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 key out reverse Left noautotitle\n"
|
||||
"set style fill solid 0.5\n"
|
||||
|
Loading…
Reference in New Issue
Block a user