csv

csv reading library
git clone git://bvnf.space/csv.git
Log | Files | Refs

commit e4ec4cd1bae79181039dffb502030f05c8c4cbfd
parent 26d5877cfa7410a385899f341ade2bca6b925f40
Author: aabacchus <ben@bvnf.space>
Date:   Wed, 24 Nov 2021 16:48:04 +0000

move testing stuff to own dir

Diffstat:
Dmain.c | 47-----------------------------------------------
Atest/main.c | 47+++++++++++++++++++++++++++++++++++++++++++++++
Rtest.csv -> test/test.csv | 0
3 files changed, 47 insertions(+), 47 deletions(-)

diff --git a/main.c b/main.c @@ -1,47 +0,0 @@ -#include <stdio.h> -#include <unistd.h> -#include "csv.h" - -int -main(int argc, char **argv) { - int c; - char flag_H = 0; - while ((c = getopt(argc, argv, "Hh")) != -1) { - switch (c) { - case 'H': - flag_H = 1; - break; - case 'h': - goto usage; - } - } - if (argc - optind > 1) { -usage: - fprintf(stderr, - "usage: %s [-H] [file]\n if no filename given, data is read from stdin\n" - " -H\tread data headers from first line\n", argv[0]); - return 1; - } - - FILE *f; - if (argc - optind == 0) { - f = stdin; - } else { - f = fopen(argv[optind], "r"); - if (f == NULL) { - perror(argv[optind]); - return 1; - } - } - struct csv *csv = csv_create(); - if (csv == NULL) { - perror("csv_create"); - return 1; - } - int ret = csv_read_file(f, csv, flag_H); - if (ret != 0) { - csv_destroy(csv); - return 1; - } - return 0; -} diff --git a/test/main.c b/test/main.c @@ -0,0 +1,47 @@ +#include <stdio.h> +#include <unistd.h> +#include <csv.h> + +int +main(int argc, char **argv) { + int c; + char flag_H = 0; + while ((c = getopt(argc, argv, "Hh")) != -1) { + switch (c) { + case 'H': + flag_H = 1; + break; + case 'h': + goto usage; + } + } + if (argc - optind > 1) { +usage: + fprintf(stderr, + "usage: %s [-H] [file]\n if no filename given, data is read from stdin\n" + " -H\tread data headers from first line\n", argv[0]); + return 1; + } + + FILE *f; + if (argc - optind == 0) { + f = stdin; + } else { + f = fopen(argv[optind], "r"); + if (f == NULL) { + perror(argv[optind]); + return 1; + } + } + struct csv *csv = csv_create(); + if (csv == NULL) { + perror("csv_create"); + return 1; + } + int ret = csv_read_file(f, csv, flag_H); + if (ret != 0) { + csv_destroy(csv); + return 1; + } + return 0; +} diff --git a/test.csv b/test/test.csv