From 85fe3b67a67825dfc5e43959f001b2a7159dc23f Mon Sep 17 00:00:00 2001 From: Thomas Schmucker Date: Sun, 13 Apr 2025 10:45:35 +0200 Subject: new directory structure --- lib/include/csv.h | 71 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 71 insertions(+) create mode 100644 lib/include/csv.h (limited to 'lib/include') diff --git a/lib/include/csv.h b/lib/include/csv.h new file mode 100644 index 0000000..9ac7c05 --- /dev/null +++ b/lib/include/csv.h @@ -0,0 +1,71 @@ +#pragma once + +#include /* size_t */ +#include /* FILE */ + +#ifdef __cplusplus +extern "C" { +#endif + +typedef enum { + CSV_ERR_OK = 0, + CSV_ERR_OUT_OF_MEMORY = -1, + CSV_ERR_OUT_OF_RANGE = -2, + CSV_ERR_IO_READ = -3, + CSV_ERR_IO_WRITE = -4 +} csv_err_t; + +typedef struct { + int field_delimiter; + int field_separator; + + void (*cb_error)(csv_err_t, void *); + void *cb_error_arg; + + void *(*cb_allocate)(size_t, size_t, void *); + void *(*cb_reallocate)(void *, size_t, size_t, void *); + void (*cb_free)(void *, size_t, size_t, void *); + void *cb_memory_arg; +} csv_options_t; + +extern const csv_options_t csv_default_options; + +typedef struct { + char * str; + size_t cap, pos; +} csv_string_t; + +typedef struct { + size_t *fields; + size_t cap, pos; +} csv_field_t; + +typedef struct { + const csv_options_t *csv_options; + csv_string_t csv_string; + csv_field_t csv_field; +} csv_t; + +/* version */ +extern const char csv_version[]; + +/* initialization */ +void csv_init(csv_t *csv); +void csv_init_opt(csv_t *csv, const csv_options_t *const csv_options); + +/* cleanup after error */ +void csv_cleanup(csv_t *csv); + +/* read */ +size_t csv_read(csv_t *csv, FILE *in); + +/* field access */ +size_t csv_nfields(const csv_t *const csv); +const char *csv_field(const csv_t *const csv, size_t idx); + +/* error handling */ +const char *csv_err_str(csv_err_t csv_err); + +#ifdef __cplusplus +} +#endif -- cgit v1.3