summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorThomas Schmucker <ts@its1.de>2020-06-18 09:01:23 +0200
committerThomas Schmucker <ts@its1.de>2020-06-18 09:01:23 +0200
commitfe5ecb5f7d0d57019d4c28605fab23d2c3163a80 (patch)
tree688a771ec662edda0ae980f5dfd61bf20670bbe1
parentfbc7b6aa36b2496e65c4f56ba68c50d10f52eb79 (diff)
downloadlibcsv-fe5ecb5f7d0d57019d4c28605fab23d2c3163a80.tar.gz
libcsv-fe5ecb5f7d0d57019d4c28605fab23d2c3163a80.tar.bz2
libcsv-fe5ecb5f7d0d57019d4c28605fab23d2c3163a80.zip
constness
-rw-r--r--csv-test.c21
1 files 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 @@
9 9
10#define INLINE static inline 10#define INLINE static inline
11 11
12/* === CSV Options Interface === */ 12/* === CSV-OPTIONS Interface === */
13 13
14typedef struct { 14typedef struct {
15 char quote_symbol; 15 char quote_symbol;
@@ -18,7 +18,9 @@ typedef struct {
18 void (*cb_func)(const char *, void *); 18 void (*cb_func)(const char *, void *);
19} csv_options_t; 19} csv_options_t;
20 20
21static csv_options_t default_csv_options = { 21extern const csv_options_t csv_default_options;
22
23const csv_options_t csv_default_options = {
22 .quote_symbol = '"', 24 .quote_symbol = '"',
23 .sep_symbol = ',', 25 .sep_symbol = ',',
24 .cb_func = NULL 26 .cb_func = NULL
@@ -183,13 +185,13 @@ csv_field_free(csv_field_t *csv_field)
183/* === CSV Interface === */ 185/* === CSV Interface === */
184 186
185typedef struct { 187typedef struct {
186 csv_options_t *csv_options; 188 const csv_options_t *csv_options;
187 csv_string_t csv_string; 189 csv_string_t csv_string;
188 csv_field_t csv_field; 190 csv_field_t csv_field;
189} csv_t; 191} csv_t;
190 192
191void csv_init(csv_t *csv); 193void csv_init(csv_t *csv);
192void csv_init_opt(csv_t *csv, csv_options_t *csv_options); 194void csv_init_opt(csv_t *csv, const csv_options_t * const csv_options);
193void csv_free(csv_t *csv); 195void csv_free(csv_t *csv);
194int csv_nfields(csv_t *csv); 196int csv_nfields(csv_t *csv);
195const char * csv_field(csv_t *csv, int idx); 197const char * csv_field(csv_t *csv, int idx);
@@ -201,15 +203,20 @@ csv_init(csv_t *csv)
201{ 203{
202 assert(csv != NULL); 204 assert(csv != NULL);
203 205
204 csv_init_opt(csv, &default_csv_options); 206 csv_init_opt(csv, NULL);
205} 207}
206 208
207void 209void
208csv_init_opt(csv_t *csv, csv_options_t *csv_options) 210csv_init_opt(csv_t *csv, const csv_options_t * const csv_options)
209{ 211{
210 assert(csv != NULL); 212 assert(csv != NULL);
211 213
212 csv->csv_options = ( csv_options != NULL ) ? csv_options : &default_csv_options; 214 if ( csv_options != NULL ) {
215 csv->csv_options = csv_options;
216 }
217 else {
218 csv->csv_options = &csv_default_options;
219 }
213 220
214 csv_string_init(&csv->csv_string); 221 csv_string_init(&csv->csv_string);
215 csv_field_init(&csv->csv_field); 222 csv_field_init(&csv->csv_field);