summaryrefslogtreecommitdiff
path: root/csv-test.c
diff options
context:
space:
mode:
authorThomas Schmucker <ts@its1.de>2020-06-11 19:52:08 +0200
committerThomas Schmucker <ts@its1.de>2020-06-11 19:52:08 +0200
commit6011411211d262d6f594cc9d239d57dbfc95047b (patch)
tree584defc3ba0cfb5049c8ae1b0dd1dfecc8b8b7db /csv-test.c
parent83e0456536ec0e3e833d09ba1d526c508feb8ebf (diff)
downloadlibcsv-6011411211d262d6f594cc9d239d57dbfc95047b.tar.gz
libcsv-6011411211d262d6f594cc9d239d57dbfc95047b.tar.bz2
libcsv-6011411211d262d6f594cc9d239d57dbfc95047b.zip
bessere Steuerung für inline/static
Diffstat (limited to 'csv-test.c')
-rw-r--r--csv-test.c22
1 files changed, 13 insertions, 9 deletions
diff --git a/csv-test.c b/csv-test.c
index c414c98..ccf9bad 100644
--- a/csv-test.c
+++ b/csv-test.c
@@ -4,6 +4,8 @@
4#include <time.h> 4#include <time.h>
5#include <stdbool.h> 5#include <stdbool.h>
6 6
7#define INLINE static inline
8
7/* === CSV-STRING Interface === */ 9/* === CSV-STRING Interface === */
8 10
9typedef struct { 11typedef struct {
@@ -11,7 +13,7 @@ typedef struct {
11 int cap, pos; 13 int cap, pos;
12} csv_string_t; 14} csv_string_t;
13 15
14static void 16INLINE void
15csv_string_init(csv_string_t *csv_string) 17csv_string_init(csv_string_t *csv_string)
16{ 18{
17 static const int INITIAL_CAP = 16; 19 static const int INITIAL_CAP = 16;
@@ -22,19 +24,19 @@ csv_string_init(csv_string_t *csv_string)
22 } 24 }
23} 25}
24 26
25static void 27INLINE void
26csv_string_reset(csv_string_t *csv_string) 28csv_string_reset(csv_string_t *csv_string)
27{ 29{
28 csv_string->pos = 0; 30 csv_string->pos = 0;
29} 31}
30 32
31static bool 33INLINE bool
32csv_string_empty(csv_string_t *csv_string) 34csv_string_empty(csv_string_t *csv_string)
33{ 35{
34 return ( csv_string->pos == 0 ) ? true : false; 36 return ( csv_string->pos == 0 ) ? true : false;
35} 37}
36 38
37inline static void 39INLINE void
38csv_string_append(csv_string_t *csv_string, int ch) 40csv_string_append(csv_string_t *csv_string, int ch)
39{ 41{
40 if ( csv_string->pos == csv_string->cap ) { /* grow if needed */ 42 if ( csv_string->pos == csv_string->cap ) { /* grow if needed */
@@ -50,7 +52,7 @@ csv_string_append(csv_string_t *csv_string, int ch)
50 csv_string->str[csv_string->pos++] = ch; /* append char */ 52 csv_string->str[csv_string->pos++] = ch; /* append char */
51} 53}
52 54
53static void 55INLINE void
54csv_string_free(csv_string_t *csv_string) 56csv_string_free(csv_string_t *csv_string)
55{ 57{
56 free(csv_string->str); 58 free(csv_string->str);
@@ -63,7 +65,7 @@ typedef struct {
63 int cap, pos; 65 int cap, pos;
64} csv_field_t; 66} csv_field_t;
65 67
66static void 68INLINE void
67csv_field_init(csv_field_t *csv_field) 69csv_field_init(csv_field_t *csv_field)
68{ 70{
69 static const size_t INITIAL_CAP = 16; 71 static const size_t INITIAL_CAP = 16;
@@ -74,13 +76,13 @@ csv_field_init(csv_field_t *csv_field)
74 } 76 }
75} 77}
76 78
77static void 79INLINE void
78csv_field_reset(csv_field_t *csv_field) 80csv_field_reset(csv_field_t *csv_field)
79{ 81{
80 csv_field->pos = 0; 82 csv_field->pos = 0;
81} 83}
82 84
83static void 85INLINE void
84csv_field_append(csv_field_t *csv_field, int idx) 86csv_field_append(csv_field_t *csv_field, int idx)
85{ 87{
86 if ( csv_field->pos == csv_field->cap ) { /* grow if needed */ 88 if ( csv_field->pos == csv_field->cap ) { /* grow if needed */
@@ -96,7 +98,7 @@ csv_field_append(csv_field_t *csv_field, int idx)
96 csv_field->fields[csv_field->pos++] = idx; /* append idx */ 98 csv_field->fields[csv_field->pos++] = idx; /* append idx */
97} 99}
98 100
99static void 101INLINE void
100csv_field_free(csv_field_t *csv_field) 102csv_field_free(csv_field_t *csv_field)
101{ 103{
102 free(csv_field->fields); 104 free(csv_field->fields);
@@ -297,6 +299,8 @@ main(void)
297 csv_t csv[1]; 299 csv_t csv[1];
298 int n, line = 0; 300 int n, line = 0;
299 301
302 setvbuf(stdin, NULL, _IOFBF, 16384);
303
300#if 0 304#if 0
301 char data[] = "\"\"aaa\",\"b\"\"bb\",\"ccc\"\n" 305 char data[] = "\"\"aaa\",\"b\"\"bb\",\"ccc\"\n"
302 "zzz,,yyy,xxx\n" 306 "zzz,,yyy,xxx\n"