diff --git a/src/flight.h b/src/flight.h index 87fb32e..01b4371 100644 --- a/src/flight.h +++ b/src/flight.h @@ -64,10 +64,13 @@ struct flight_tree_iterator { struct tree_flight_iterator _; }; || !defined BASE && !defined GENERIC && !defined PROTO /* */ #ifdef BASE diff --git a/src/flight.re.c b/src/flight.re.c index 57160e4..d1b97a0 100644 --- a/src/flight.re.c +++ b/src/flight.re.c @@ -239,16 +239,20 @@ finally: return f; } -#if 0 -struct flight *flights_add(struct flights *const flights, - const union line64 line) { - struct flight *flight; - assert(flights); - /* We assert that the flights are unique. */ - switch(flight_tree_try(&flights->_, line, &flight)) { - case TREE_PRESENT: errno = EDOM; - case TREE_ERROR: return 0; - case TREE_ABSENT: return flight; - } +const char *flights_to_string(const struct flights *const f) + { return flight_tree_to_string(&f->_); } + +struct flights_iterator flights_iterator(struct flights *const f) { + struct flights_iterator it = { flight_tree_iterator(&f->_) }; + assert(f); + return it; +} + +int flights_next(struct flights_iterator *const it, union line64 *const k, + const struct flight **const v) { + assert(it && k && v); + if(!flight_tree_next(&it->_)) return 0; + *k = flight_tree_key(&it->_); + *v = flight_tree_value(&it->_); + return 1; } -#endif diff --git a/src/flighthours.c b/src/flighthours.c index 54152d1..5fc1f13 100644 --- a/src/flighthours.c +++ b/src/flighthours.c @@ -10,6 +10,7 @@ #include #include #include +#include int main(void) { int success = EXIT_SUCCESS; @@ -19,24 +20,57 @@ int main(void) { struct flights f = flights(&j); if(errno) goto catch; - fprintf(stderr, "Journal: %s.\n", journal_to_string(&j)); + fprintf(stderr, "Journal: %s.\n" + "Flights: %s.\n", journal_to_string(&j), flights_to_string(&f)); printf("set term postscript eps enhanced\n" "set output \"flighthours.eps\"\n" "$Data <name.a) { errno = EDOM; goto catch; } + printf("%s\t%.*s\t", + datestr, (int)(src->name.b - src->name.a), src->name.a); + assert(flight); switch(flight->type) { + case GLIDER: + total += flight->glider.dual_min + flight->glider.pilot_min + + flight->glider.instr_min; + printf("%.*s\t%" PRIu32 "\t%" PRIu32 "\t%" PRIu32 "\n", + (int)(flight->glider.reg.b - flight->glider.reg.a), + flight->glider.reg.a, + flight->glider.dual_min, + flight->glider.pilot_min + flight->glider.instr_min, + total); + break; + case POWER: + total += flight->power.dual_min + flight->power.pilot_min; + printf("%.*s\t%" PRIu32 "\t%" PRIu32 "\t%" PRIu32 "\n", + (int)(flight->power.reg.b - flight->power.reg.a), + flight->power.reg.a, + flight->power.dual_min, + flight->power.pilot_min, + total); + break; + } + } printf("EOD\n" "set monochrome\n" "set xdata time\n" "set timefmt \"%%Y-%%m-%%d\"\n" "set xtics format \"%%Y-%%m-%%d\" rotate by -30\n" "set ylabel \"hours\"\n" - "set format y \"%%g%%%%\"\n" - "set key top left\n" "set grid\n" + "unset key\n" "unset border\n" + "set xrange [*:'2001-09-11']\n" "#set style fill solid 0.1 #pattern 5 (better, but restarts)\n" - "plot $Data using 1:($3) with fillsteps lw 2\n"); + "plot $Data using 1:($6/60) with fillsteps lw 2\n"); goto finally; catch: success = EXIT_FAILURE; diff --git a/src/journal.h b/src/journal.h index da3006d..8fe894a 100644 --- a/src/journal.h +++ b/src/journal.h @@ -35,7 +35,7 @@ struct journal { struct day_tree days; struct text backing; }; struct journal_iterator { struct day_tree_iterator _; }; struct journal journal(void); void journal_(struct journal *); -int journal_is_valid(const struct journal *); +//int journal_is_valid(const struct journal *); const char *journal_to_string(const struct journal *); struct journal_iterator journal_iterator(struct journal *const j); int journal_next(struct journal_iterator *, union date32 *, const char **); diff --git a/src/kjv.h b/src/kjv.h index 3265cf6..04f646b 100644 --- a/src/kjv.h +++ b/src/kjv.h @@ -111,6 +111,7 @@ struct kjv { struct kjv kjv(void); void kjv_(struct kjv *); int kjv_is_valid(const struct kjv *const kjv); +/* Only used in test. */ int kjv_add(struct kjv *const kjv, const union kjvcite cite); const char *kjv_to_string(const struct kjv *const kjv); const char *kjv_set_to_string(const struct kjv *const kjv); diff --git a/src/kjv.re.c b/src/kjv.re.c index c3a5ee9..f2ce3aa 100644 --- a/src/kjv.re.c +++ b/src/kjv.re.c @@ -54,7 +54,7 @@ static void kjvset_to_string(const union kjvcite x, char (*const a)[12]) #define TABLE_NAME kjvset #define TABLE_KEY union kjvcite #define TABLE_UINT uint32_t -#define TABLE_INVERSE +#define TABLE_UNHASH #define TABLE_TO_STRING #include "../src/table.h" @@ -67,7 +67,7 @@ static void verse_to_string(const union kjvcite x, const unsigned count, #define TABLE_KEY union kjvcite #define TABLE_UINT uint32_t #define TABLE_VALUE unsigned /* Count words. */ -#define TABLE_INVERSE +#define TABLE_UNHASH #define TABLE_DEFAULT 0 #define TABLE_TO_STRING #include "../src/table.h" @@ -223,7 +223,8 @@ finally: int kjv_is_valid(const struct kjv *const kjv) { return kjv && kjv->verses.buckets; } -/** Adds `cite` to `kjv` if not present. @return Is the kjv still valid. */ +/** Adds `cite` to `kjv` if not present. Only used in test. + @return Is the kjv still valid. */ int kjv_add(struct kjv *const kjv, const union kjvcite cite) { if(!kjv) return 0; kjv->words.verse = verse_table_get(&kjv->verses, cite); diff --git a/test/test_kjv.c b/test/test_kjv.c index 3561f32..71cfe58 100644 --- a/test/test_kjv.c +++ b/test/test_kjv.c @@ -1,3 +1,4 @@ +#define KJV_TEST #include "../src/kjv.h" #include #include /* C99 */