diff options
| author | Thomas Schmucker <ts@its1.de> | 2025-04-13 10:45:35 +0200 |
|---|---|---|
| committer | Thomas Schmucker <ts@its1.de> | 2025-04-13 10:45:35 +0200 |
| commit | 85fe3b67a67825dfc5e43959f001b2a7159dc23f (patch) | |
| tree | 51588584397d6147a77e5fd9d77aa2274b152c6a /lib/include/csv.h | |
| parent | 0402756330a118e55d3d7d31baa06e1420347320 (diff) | |
| download | libcsv-85fe3b67a67825dfc5e43959f001b2a7159dc23f.tar.gz libcsv-85fe3b67a67825dfc5e43959f001b2a7159dc23f.tar.bz2 libcsv-85fe3b67a67825dfc5e43959f001b2a7159dc23f.zip | |
new directory structure
Diffstat (limited to 'lib/include/csv.h')
| -rw-r--r-- | lib/include/csv.h | 71 |
1 files changed, 71 insertions, 0 deletions
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 @@ | |||
| 1 | #pragma once | ||
| 2 | |||
| 3 | #include <stddef.h> /* size_t */ | ||
| 4 | #include <stdio.h> /* FILE */ | ||
| 5 | |||
| 6 | #ifdef __cplusplus | ||
| 7 | extern "C" { | ||
| 8 | #endif | ||
| 9 | |||
| 10 | typedef enum { | ||
| 11 | CSV_ERR_OK = 0, | ||
| 12 | CSV_ERR_OUT_OF_MEMORY = -1, | ||
| 13 | CSV_ERR_OUT_OF_RANGE = -2, | ||
| 14 | CSV_ERR_IO_READ = -3, | ||
| 15 | CSV_ERR_IO_WRITE = -4 | ||
| 16 | } csv_err_t; | ||
| 17 | |||
| 18 | typedef struct { | ||
| 19 | int field_delimiter; | ||
| 20 | int field_separator; | ||
| 21 | |||
| 22 | void (*cb_error)(csv_err_t, void *); | ||
| 23 | void *cb_error_arg; | ||
| 24 | |||
| 25 | void *(*cb_allocate)(size_t, size_t, void *); | ||
| 26 | void *(*cb_reallocate)(void *, size_t, size_t, void *); | ||
| 27 | void (*cb_free)(void *, size_t, size_t, void *); | ||
| 28 | void *cb_memory_arg; | ||
| 29 | } csv_options_t; | ||
| 30 | |||
| 31 | extern const csv_options_t csv_default_options; | ||
| 32 | |||
| 33 | typedef struct { | ||
| 34 | char * str; | ||
| 35 | size_t cap, pos; | ||
| 36 | } csv_string_t; | ||
| 37 | |||
| 38 | typedef struct { | ||
| 39 | size_t *fields; | ||
| 40 | size_t cap, pos; | ||
| 41 | } csv_field_t; | ||
| 42 | |||
| 43 | typedef struct { | ||
| 44 | const csv_options_t *csv_options; | ||
| 45 | csv_string_t csv_string; | ||
| 46 | csv_field_t csv_field; | ||
| 47 | } csv_t; | ||
| 48 | |||
| 49 | /* version */ | ||
| 50 | extern const char csv_version[]; | ||
| 51 | |||
| 52 | /* initialization */ | ||
| 53 | void csv_init(csv_t *csv); | ||
| 54 | void csv_init_opt(csv_t *csv, const csv_options_t *const csv_options); | ||
| 55 | |||
| 56 | /* cleanup after error */ | ||
| 57 | void csv_cleanup(csv_t *csv); | ||
| 58 | |||
| 59 | /* read */ | ||
| 60 | size_t csv_read(csv_t *csv, FILE *in); | ||
| 61 | |||
| 62 | /* field access */ | ||
| 63 | size_t csv_nfields(const csv_t *const csv); | ||
| 64 | const char *csv_field(const csv_t *const csv, size_t idx); | ||
| 65 | |||
| 66 | /* error handling */ | ||
| 67 | const char *csv_err_str(csv_err_t csv_err); | ||
| 68 | |||
| 69 | #ifdef __cplusplus | ||
| 70 | } | ||
| 71 | #endif | ||
