aboutsummaryrefslogtreecommitdiff
path: root/csv.h
diff options
context:
space:
mode:
Diffstat (limited to 'csv.h')
-rw-r--r--csv.h51
1 files changed, 51 insertions, 0 deletions
diff --git a/csv.h b/csv.h
new file mode 100644
index 0000000..83755f3
--- /dev/null
+++ b/csv.h
@@ -0,0 +1,51 @@
1#ifndef ITS1_CSV_H_INCLUDED
2#define ITS1_CSV_H_INCLUDED
3
4#include <stdio.h> /* FILE */
5#include <stddef.h> /* size_t */
6
7#ifdef __cplusplus
8extern "C" {
9#endif
10
11typedef struct {
12 char quote_symbol;
13 char sep_symbol;
14 void *cb_arg;
15 void (*cb_error)(const char *, void *);
16 void *(*cb_allocate)(size_t, size_t, void *);
17 void *(*cb_reallocate)(void *, size_t, size_t, void *);
18 void (*cb_free)(void *, void *);
19} csv_options_t;
20
21extern const csv_options_t csv_default_options;
22
23typedef struct {
24 char *str;
25 int cap, pos;
26} csv_string_t;
27
28typedef struct {
29 int *fields;
30 int cap, pos;
31} csv_field_t;
32
33typedef struct {
34 const csv_options_t *csv_options;
35 csv_string_t csv_string;
36 csv_field_t csv_field;
37} csv_t;
38
39void csv_init(csv_t *csv);
40void csv_init_opt(csv_t *csv, const csv_options_t * const csv_options);
41void csv_free(csv_t *csv);
42int csv_nfields(csv_t *csv);
43const char * csv_field(csv_t *csv, int idx);
44int csv_read(csv_t *csv, FILE *in);
45void csv_write(FILE *out, int n, const char *fields[], const csv_options_t * const csv_options);
46
47#ifdef __cplusplus
48}
49#endif
50
51#endif