From fe5ecb5f7d0d57019d4c28605fab23d2c3163a80 Mon Sep 17 00:00:00 2001 From: Thomas Schmucker Date: Thu, 18 Jun 2020 09:01:23 +0200 Subject: constness --- csv-test.c | 21 ++++++++++++++------- 1 file changed, 14 insertions(+), 7 deletions(-) diff --git a/csv-test.c b/csv-test.c index 0d9d6e1..d26fea9 100644 --- a/csv-test.c +++ b/csv-test.c @@ -9,7 +9,7 @@ #define INLINE static inline -/* === CSV Options Interface === */ +/* === CSV-OPTIONS Interface === */ typedef struct { char quote_symbol; @@ -18,7 +18,9 @@ typedef struct { void (*cb_func)(const char *, void *); } csv_options_t; -static csv_options_t default_csv_options = { +extern const csv_options_t csv_default_options; + +const csv_options_t csv_default_options = { .quote_symbol = '"', .sep_symbol = ',', .cb_func = NULL @@ -183,13 +185,13 @@ csv_field_free(csv_field_t *csv_field) /* === CSV Interface === */ typedef struct { - csv_options_t *csv_options; + const csv_options_t *csv_options; csv_string_t csv_string; csv_field_t csv_field; } csv_t; void csv_init(csv_t *csv); -void csv_init_opt(csv_t *csv, csv_options_t *csv_options); +void csv_init_opt(csv_t *csv, const csv_options_t * const csv_options); void csv_free(csv_t *csv); int csv_nfields(csv_t *csv); const char * csv_field(csv_t *csv, int idx); @@ -201,15 +203,20 @@ csv_init(csv_t *csv) { assert(csv != NULL); - csv_init_opt(csv, &default_csv_options); + csv_init_opt(csv, NULL); } void -csv_init_opt(csv_t *csv, csv_options_t *csv_options) +csv_init_opt(csv_t *csv, const csv_options_t * const csv_options) { assert(csv != NULL); - csv->csv_options = ( csv_options != NULL ) ? csv_options : &default_csv_options; + if ( csv_options != NULL ) { + csv->csv_options = csv_options; + } + else { + csv->csv_options = &csv_default_options; + } csv_string_init(&csv->csv_string); csv_field_init(&csv->csv_field); -- cgit v1.3