diff options
Diffstat (limited to 'colitur-x.c')
| -rw-r--r-- | colitur-x.c | 17 |
1 files changed, 15 insertions, 2 deletions
diff --git a/colitur-x.c b/colitur-x.c index def42fa..06f2f1a 100644 --- a/colitur-x.c +++ b/colitur-x.c @@ -55,15 +55,28 @@ static int split(char *line, char **out) return n; } +/* The header line is DETECTED, not assumed. Skipping the first line + unconditionally punishes the obvious way to look at one month -- + `... | grep "^2027-04" | colitur-x` -- by silently eating the 1st, + which is a filter this program should compose with rather than fight. + A header is exactly the line beginning "date,"; anything else is a day. */ +static int is_header(const char *line) +{ + return strncmp(line, "date,", 5) == 0; +} + static void load(void) { char buf[4096]; - if (!fgets(buf, sizeof buf, stdin)) return; /* header */ + int first = 1; while (nrows < MAXDAYS && fgets(buf, sizeof buf, stdin)) { buf[strcspn(buf, "\n")] = 0; + if (first && is_header(buf)) { first = 0; continue; } + first = 0; + if (buf[0] == 0) continue; char *dup = strdup(buf); if (!dup) break; - if (split(dup, rows[nrows].f) >= 12) nrows++; + if (split(dup, rows[nrows].f) >= 12) nrows++; else free(dup); } } |
