ckplot

Unnamed repository
Log | Files | Refs

commit aea924ad6024503604067e50ae0b64a870bb9c96
parent c6adc9093fb429480d8a752308eac1b626f45957
Author: aabacchus <ben@bvnf.space>
Date:   Sun,  3 Oct 2021 00:26:29 +0100

kplot: allow reading from stdin

Diffstat:
Mkplot.c | 21++++++++++-----------
1 file changed, 10 insertions(+), 11 deletions(-)

diff --git a/kplot.c b/kplot.c @@ -9,7 +9,7 @@ void usage(char *argv0) { - fprintf(stderr, "usage: %s [-H] file.csv\n", argv0); + fprintf(stderr, "usage: %s [-H] [file.csv]\n", argv0); fprintf(stderr, " -H treat first line as header\n"); } @@ -28,17 +28,16 @@ main(int argc, char **argv) { } } + FILE *f; if (argc - optind == 0) { - usage(*argv); - return 1; - } - - argv += optind; - - FILE *f = fopen(*argv, "r"); - if (f == NULL) { - perror(*argv); - return 1; + f = stdin; + } else { + argv += optind; + f = fopen(*argv, "r"); + if (f == NULL) { + perror(*argv); + return 1; + } } struct csv *c = csv_create();