Tue, 22 Oct 2024 22:20:50 +0200
make both gcc and clang happy with how cx_json_value_nothing is initialized
923
45da884269c8
add ucx2.1 style interface for a properties parser
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
1 | /* |
45da884269c8
add ucx2.1 style interface for a properties parser
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
2 | * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. |
45da884269c8
add ucx2.1 style interface for a properties parser
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
3 | * |
45da884269c8
add ucx2.1 style interface for a properties parser
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
4 | * Copyright 2024 Mike Becker, Olaf Wintermann All rights reserved. |
45da884269c8
add ucx2.1 style interface for a properties parser
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
5 | * |
45da884269c8
add ucx2.1 style interface for a properties parser
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
6 | * Redistribution and use in source and binary forms, with or without |
45da884269c8
add ucx2.1 style interface for a properties parser
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
7 | * modification, are permitted provided that the following conditions are met: |
45da884269c8
add ucx2.1 style interface for a properties parser
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
8 | * |
45da884269c8
add ucx2.1 style interface for a properties parser
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
9 | * 1. Redistributions of source code must retain the above copyright |
45da884269c8
add ucx2.1 style interface for a properties parser
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
10 | * notice, this list of conditions and the following disclaimer. |
45da884269c8
add ucx2.1 style interface for a properties parser
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
11 | * |
45da884269c8
add ucx2.1 style interface for a properties parser
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
12 | * 2. Redistributions in binary form must reproduce the above copyright |
45da884269c8
add ucx2.1 style interface for a properties parser
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
13 | * notice, this list of conditions and the following disclaimer in the |
45da884269c8
add ucx2.1 style interface for a properties parser
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
14 | * documentation and/or other materials provided with the distribution. |
45da884269c8
add ucx2.1 style interface for a properties parser
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
15 | * |
45da884269c8
add ucx2.1 style interface for a properties parser
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
16 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" |
45da884269c8
add ucx2.1 style interface for a properties parser
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
17 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
45da884269c8
add ucx2.1 style interface for a properties parser
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
18 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE |
45da884269c8
add ucx2.1 style interface for a properties parser
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
19 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE |
45da884269c8
add ucx2.1 style interface for a properties parser
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
20 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR |
45da884269c8
add ucx2.1 style interface for a properties parser
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
21 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF |
45da884269c8
add ucx2.1 style interface for a properties parser
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
22 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS |
45da884269c8
add ucx2.1 style interface for a properties parser
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
23 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN |
45da884269c8
add ucx2.1 style interface for a properties parser
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
24 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) |
45da884269c8
add ucx2.1 style interface for a properties parser
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
25 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE |
45da884269c8
add ucx2.1 style interface for a properties parser
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
26 | * POSSIBILITY OF SUCH DAMAGE. |
45da884269c8
add ucx2.1 style interface for a properties parser
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
27 | */ |
45da884269c8
add ucx2.1 style interface for a properties parser
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
28 | |
45da884269c8
add ucx2.1 style interface for a properties parser
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
29 | #include "cx/properties.h" |
45da884269c8
add ucx2.1 style interface for a properties parser
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
30 | |
924
3c90dfc35f06
add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
923
diff
changeset
|
31 | #include <string.h> |
3c90dfc35f06
add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
923
diff
changeset
|
32 | #include <assert.h> |
3c90dfc35f06
add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
923
diff
changeset
|
33 | |
3c90dfc35f06
add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
923
diff
changeset
|
34 | static const int CX_PROPERTIES_FLAG_USE_STACK = 0x01; |
3c90dfc35f06
add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
923
diff
changeset
|
35 | |
923
45da884269c8
add ucx2.1 style interface for a properties parser
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
36 | const CxPropertiesConfig cx_properties_config_default = { |
45da884269c8
add ucx2.1 style interface for a properties parser
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
37 | '=', |
924
3c90dfc35f06
add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
923
diff
changeset
|
38 | //'\\', |
923
45da884269c8
add ucx2.1 style interface for a properties parser
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
39 | '#', |
45da884269c8
add ucx2.1 style interface for a properties parser
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
40 | '\0', |
45da884269c8
add ucx2.1 style interface for a properties parser
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
41 | '\0' |
45da884269c8
add ucx2.1 style interface for a properties parser
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
42 | }; |
924
3c90dfc35f06
add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
923
diff
changeset
|
43 | |
3c90dfc35f06
add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
923
diff
changeset
|
44 | void cxPropertiesInit( |
3c90dfc35f06
add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
923
diff
changeset
|
45 | CxProperties *prop, |
3c90dfc35f06
add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
923
diff
changeset
|
46 | CxPropertiesConfig config |
3c90dfc35f06
add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
923
diff
changeset
|
47 | ) { |
3c90dfc35f06
add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
923
diff
changeset
|
48 | memset(prop, 0, sizeof(CxProperties)); |
3c90dfc35f06
add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
923
diff
changeset
|
49 | prop->config = config; |
3c90dfc35f06
add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
923
diff
changeset
|
50 | } |
3c90dfc35f06
add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
923
diff
changeset
|
51 | |
3c90dfc35f06
add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
923
diff
changeset
|
52 | void cxPropertiesDestroy(CxProperties *prop) { |
3c90dfc35f06
add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
923
diff
changeset
|
53 | if (0 == (prop->flags & CX_PROPERTIES_FLAG_USE_STACK)) { |
3c90dfc35f06
add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
923
diff
changeset
|
54 | free(prop->buf); |
3c90dfc35f06
add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
923
diff
changeset
|
55 | } |
3c90dfc35f06
add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
923
diff
changeset
|
56 | prop->buf = NULL; |
3c90dfc35f06
add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
923
diff
changeset
|
57 | prop->buf_capacity = prop->buf_size = 0; |
3c90dfc35f06
add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
923
diff
changeset
|
58 | } |
3c90dfc35f06
add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
923
diff
changeset
|
59 | |
3c90dfc35f06
add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
923
diff
changeset
|
60 | static int cx_properties_ensure_buf_capacity(CxProperties *prop, size_t cap) { |
3c90dfc35f06
add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
923
diff
changeset
|
61 | if (prop->buf_capacity >= cap) { |
3c90dfc35f06
add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
923
diff
changeset
|
62 | return 0; |
3c90dfc35f06
add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
923
diff
changeset
|
63 | } |
3c90dfc35f06
add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
923
diff
changeset
|
64 | |
3c90dfc35f06
add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
923
diff
changeset
|
65 | // not enough capacity - are we on the stack right now? |
3c90dfc35f06
add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
923
diff
changeset
|
66 | if ((prop->flags & CX_PROPERTIES_FLAG_USE_STACK) != 0) { |
3c90dfc35f06
add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
923
diff
changeset
|
67 | // move to the heap |
3c90dfc35f06
add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
923
diff
changeset
|
68 | char *newbuf = malloc(cap); |
3c90dfc35f06
add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
923
diff
changeset
|
69 | if (newbuf == NULL) return 1; |
3c90dfc35f06
add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
923
diff
changeset
|
70 | memcpy(newbuf, prop->buf, prop->buf_size); |
3c90dfc35f06
add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
923
diff
changeset
|
71 | prop->buf = newbuf; |
3c90dfc35f06
add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
923
diff
changeset
|
72 | prop->flags &= CX_PROPERTIES_FLAG_USE_STACK; |
3c90dfc35f06
add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
923
diff
changeset
|
73 | } else { |
3c90dfc35f06
add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
923
diff
changeset
|
74 | // we are on the heap already, reallocate |
3c90dfc35f06
add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
923
diff
changeset
|
75 | // this is legit, because realloc() behaves like malloc() when the |
3c90dfc35f06
add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
923
diff
changeset
|
76 | // current pointer is NULL |
3c90dfc35f06
add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
923
diff
changeset
|
77 | char *newbuf = realloc(prop->buf, cap); |
3c90dfc35f06
add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
923
diff
changeset
|
78 | if (newbuf == NULL) return 1; |
3c90dfc35f06
add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
923
diff
changeset
|
79 | prop->buf = newbuf; |
3c90dfc35f06
add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
923
diff
changeset
|
80 | } |
3c90dfc35f06
add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
923
diff
changeset
|
81 | |
3c90dfc35f06
add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
923
diff
changeset
|
82 | // store new capacity and return |
3c90dfc35f06
add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
923
diff
changeset
|
83 | prop->buf_capacity = cap; |
3c90dfc35f06
add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
923
diff
changeset
|
84 | return 0; |
3c90dfc35f06
add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
923
diff
changeset
|
85 | } |
3c90dfc35f06
add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
923
diff
changeset
|
86 | |
3c90dfc35f06
add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
923
diff
changeset
|
87 | static int cx_properties_rescuen_input(CxProperties *prop, size_t len) { |
3c90dfc35f06
add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
923
diff
changeset
|
88 | if (cx_properties_ensure_buf_capacity(prop, prop->buf_size + len)) { |
3c90dfc35f06
add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
923
diff
changeset
|
89 | return 1; |
3c90dfc35f06
add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
923
diff
changeset
|
90 | } |
3c90dfc35f06
add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
923
diff
changeset
|
91 | const char *src = prop->text + prop->text_pos; |
3c90dfc35f06
add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
923
diff
changeset
|
92 | char *dest = prop->buf + prop->buf_size; |
3c90dfc35f06
add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
923
diff
changeset
|
93 | memcpy(dest, src, len); |
3c90dfc35f06
add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
923
diff
changeset
|
94 | prop->buf_size += len; |
928
d2d42cb1d59e
add source/sink facility for properties - fixes #430
Mike Becker <universe@uap-core.de>
parents:
924
diff
changeset
|
95 | prop->text_pos += len; |
924
3c90dfc35f06
add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
923
diff
changeset
|
96 | return 0; |
3c90dfc35f06
add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
923
diff
changeset
|
97 | } |
3c90dfc35f06
add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
923
diff
changeset
|
98 | |
3c90dfc35f06
add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
923
diff
changeset
|
99 | static int cx_properties_rescue_input(CxProperties *prop) { |
3c90dfc35f06
add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
923
diff
changeset
|
100 | // someone fucked around with our integers, exit immediately |
3c90dfc35f06
add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
923
diff
changeset
|
101 | if (prop->text_pos > prop->text_size) return 0; |
3c90dfc35f06
add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
923
diff
changeset
|
102 | |
3c90dfc35f06
add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
923
diff
changeset
|
103 | // determine the bytes needed |
3c90dfc35f06
add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
923
diff
changeset
|
104 | size_t len = prop->text_size - prop->text_pos; |
3c90dfc35f06
add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
923
diff
changeset
|
105 | |
3c90dfc35f06
add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
923
diff
changeset
|
106 | return cx_properties_rescuen_input(prop, len); |
3c90dfc35f06
add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
923
diff
changeset
|
107 | } |
3c90dfc35f06
add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
923
diff
changeset
|
108 | |
3c90dfc35f06
add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
923
diff
changeset
|
109 | void cxPropertiesInput( |
3c90dfc35f06
add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
923
diff
changeset
|
110 | CxProperties *prop, |
3c90dfc35f06
add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
923
diff
changeset
|
111 | const char *buf, |
3c90dfc35f06
add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
923
diff
changeset
|
112 | size_t len |
3c90dfc35f06
add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
923
diff
changeset
|
113 | ) { |
3c90dfc35f06
add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
923
diff
changeset
|
114 | prop->text = buf; |
3c90dfc35f06
add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
923
diff
changeset
|
115 | prop->text_size = len; |
3c90dfc35f06
add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
923
diff
changeset
|
116 | prop->text_pos = 0; |
3c90dfc35f06
add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
923
diff
changeset
|
117 | } |
3c90dfc35f06
add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
923
diff
changeset
|
118 | |
3c90dfc35f06
add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
923
diff
changeset
|
119 | int cxPropertiesFill( |
3c90dfc35f06
add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
923
diff
changeset
|
120 | CxProperties *prop, |
3c90dfc35f06
add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
923
diff
changeset
|
121 | const char *buf, |
3c90dfc35f06
add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
923
diff
changeset
|
122 | size_t len |
3c90dfc35f06
add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
923
diff
changeset
|
123 | ) { |
3c90dfc35f06
add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
923
diff
changeset
|
124 | if (cx_properties_rescue_input(prop)) return 1; |
3c90dfc35f06
add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
923
diff
changeset
|
125 | cxPropertiesInput(prop, buf, len); |
3c90dfc35f06
add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
923
diff
changeset
|
126 | return 0; |
3c90dfc35f06
add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
923
diff
changeset
|
127 | } |
3c90dfc35f06
add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
923
diff
changeset
|
128 | |
3c90dfc35f06
add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
923
diff
changeset
|
129 | void cxPropertiesUseStack( |
3c90dfc35f06
add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
923
diff
changeset
|
130 | CxProperties *prop, |
3c90dfc35f06
add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
923
diff
changeset
|
131 | char *buf, |
3c90dfc35f06
add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
923
diff
changeset
|
132 | size_t capacity |
3c90dfc35f06
add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
923
diff
changeset
|
133 | ) { |
929
192a440b99df
fix totally bugged assertion in cxPropertiesUseStack()
Mike Becker <universe@uap-core.de>
parents:
928
diff
changeset
|
134 | assert(prop->buf == NULL); |
924
3c90dfc35f06
add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
923
diff
changeset
|
135 | prop->buf = buf; |
3c90dfc35f06
add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
923
diff
changeset
|
136 | prop->buf_capacity = capacity; |
3c90dfc35f06
add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
923
diff
changeset
|
137 | prop->buf_size = 0; |
3c90dfc35f06
add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
923
diff
changeset
|
138 | prop->flags |= CX_PROPERTIES_FLAG_USE_STACK; |
3c90dfc35f06
add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
923
diff
changeset
|
139 | } |
3c90dfc35f06
add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
923
diff
changeset
|
140 | |
928
d2d42cb1d59e
add source/sink facility for properties - fixes #430
Mike Becker <universe@uap-core.de>
parents:
924
diff
changeset
|
141 | CxPropertiesStatus cxPropertiesNext( |
924
3c90dfc35f06
add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
923
diff
changeset
|
142 | CxProperties *prop, |
3c90dfc35f06
add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
923
diff
changeset
|
143 | cxstring *key, |
3c90dfc35f06
add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
923
diff
changeset
|
144 | cxstring *value |
3c90dfc35f06
add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
923
diff
changeset
|
145 | ) { |
3c90dfc35f06
add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
923
diff
changeset
|
146 | // check if we have a text buffer |
3c90dfc35f06
add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
923
diff
changeset
|
147 | if (prop->text == NULL) { |
3c90dfc35f06
add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
923
diff
changeset
|
148 | return CX_PROPERTIES_NULL_INPUT; |
3c90dfc35f06
add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
923
diff
changeset
|
149 | } |
3c90dfc35f06
add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
923
diff
changeset
|
150 | // check if we have rescued data |
3c90dfc35f06
add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
923
diff
changeset
|
151 | if (prop->buf_size > 0) { |
3c90dfc35f06
add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
923
diff
changeset
|
152 | // check if we can now get a complete line |
3c90dfc35f06
add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
923
diff
changeset
|
153 | const char *buf = prop->text + prop->text_pos; |
3c90dfc35f06
add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
923
diff
changeset
|
154 | size_t len = prop->text_size - prop->text_pos; |
3c90dfc35f06
add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
923
diff
changeset
|
155 | cxstring str = cx_strn(buf, len); |
3c90dfc35f06
add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
923
diff
changeset
|
156 | cxstring nl = cx_strchr(str, '\n'); |
3c90dfc35f06
add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
923
diff
changeset
|
157 | if(nl.length > 0) { |
3c90dfc35f06
add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
923
diff
changeset
|
158 | // we add as much data to the rescue buffer as we need |
3c90dfc35f06
add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
923
diff
changeset
|
159 | // to complete the line |
3c90dfc35f06
add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
923
diff
changeset
|
160 | size_t len_until_nl = (size_t)(nl.ptr - buf) + 1; |
3c90dfc35f06
add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
923
diff
changeset
|
161 | |
3c90dfc35f06
add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
923
diff
changeset
|
162 | if (cx_properties_rescuen_input(prop, len_until_nl)) { |
3c90dfc35f06
add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
923
diff
changeset
|
163 | return CX_PROPERTIES_BUFFER_ALLOC_FAILED; |
3c90dfc35f06
add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
923
diff
changeset
|
164 | } |
3c90dfc35f06
add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
923
diff
changeset
|
165 | |
3c90dfc35f06
add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
923
diff
changeset
|
166 | // the tmp buffer contains exactly one line now |
3c90dfc35f06
add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
923
diff
changeset
|
167 | // we use a trick here: we swap the buffers and recurse |
3c90dfc35f06
add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
923
diff
changeset
|
168 | const char *orig_text = prop->text; |
3c90dfc35f06
add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
923
diff
changeset
|
169 | size_t orig_size = prop->text_size; |
3c90dfc35f06
add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
923
diff
changeset
|
170 | prop->text = prop->buf; |
3c90dfc35f06
add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
923
diff
changeset
|
171 | prop->text_size = prop->buf_size; |
3c90dfc35f06
add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
923
diff
changeset
|
172 | prop->text_pos = 0; |
3c90dfc35f06
add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
923
diff
changeset
|
173 | prop->buf_size = 0; |
3c90dfc35f06
add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
923
diff
changeset
|
174 | |
928
d2d42cb1d59e
add source/sink facility for properties - fixes #430
Mike Becker <universe@uap-core.de>
parents:
924
diff
changeset
|
175 | CxPropertiesStatus result; |
924
3c90dfc35f06
add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
923
diff
changeset
|
176 | result = cxPropertiesNext(prop, key, value); |
3c90dfc35f06
add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
923
diff
changeset
|
177 | |
3c90dfc35f06
add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
923
diff
changeset
|
178 | // restore original buffer |
3c90dfc35f06
add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
923
diff
changeset
|
179 | prop->text = orig_text; |
3c90dfc35f06
add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
923
diff
changeset
|
180 | prop->text_size = orig_size; |
3c90dfc35f06
add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
923
diff
changeset
|
181 | |
3c90dfc35f06
add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
923
diff
changeset
|
182 | // set the position to after the newline |
3c90dfc35f06
add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
923
diff
changeset
|
183 | prop->text_pos = len_until_nl; |
3c90dfc35f06
add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
923
diff
changeset
|
184 | |
3c90dfc35f06
add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
923
diff
changeset
|
185 | // check the result |
3c90dfc35f06
add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
923
diff
changeset
|
186 | if (result == CX_PROPERTIES_NO_ERROR) { |
3c90dfc35f06
add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
923
diff
changeset
|
187 | // reset the rescue buffer and return with the result |
3c90dfc35f06
add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
923
diff
changeset
|
188 | prop->buf_size = 0; |
3c90dfc35f06
add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
923
diff
changeset
|
189 | return result; |
3c90dfc35f06
add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
923
diff
changeset
|
190 | } else if (result == CX_PROPERTIES_NO_DATA) { |
3c90dfc35f06
add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
923
diff
changeset
|
191 | // rescue buffer contained only blanks or comments |
3c90dfc35f06
add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
923
diff
changeset
|
192 | // reset the rescue buffer and retry with text buffer |
3c90dfc35f06
add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
923
diff
changeset
|
193 | prop->buf_size = 0; |
3c90dfc35f06
add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
923
diff
changeset
|
194 | return cxPropertiesNext(prop, key, value); |
3c90dfc35f06
add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
923
diff
changeset
|
195 | } else { |
3c90dfc35f06
add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
923
diff
changeset
|
196 | // CX_PROPERTIES_INCOMPLETE_DATA is not possible |
3c90dfc35f06
add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
923
diff
changeset
|
197 | // so it must have been another error |
3c90dfc35f06
add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
923
diff
changeset
|
198 | // do not reset the rescue buffer and return the error |
3c90dfc35f06
add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
923
diff
changeset
|
199 | return result; |
3c90dfc35f06
add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
923
diff
changeset
|
200 | } |
3c90dfc35f06
add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
923
diff
changeset
|
201 | } else { |
3c90dfc35f06
add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
923
diff
changeset
|
202 | // still not enough data |
928
d2d42cb1d59e
add source/sink facility for properties - fixes #430
Mike Becker <universe@uap-core.de>
parents:
924
diff
changeset
|
203 | if (cx_properties_rescue_input(prop)) { |
d2d42cb1d59e
add source/sink facility for properties - fixes #430
Mike Becker <universe@uap-core.de>
parents:
924
diff
changeset
|
204 | return CX_PROPERTIES_BUFFER_ALLOC_FAILED; |
d2d42cb1d59e
add source/sink facility for properties - fixes #430
Mike Becker <universe@uap-core.de>
parents:
924
diff
changeset
|
205 | } |
924
3c90dfc35f06
add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
923
diff
changeset
|
206 | return CX_PROPERTIES_INCOMPLETE_DATA; |
3c90dfc35f06
add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
923
diff
changeset
|
207 | } |
3c90dfc35f06
add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
923
diff
changeset
|
208 | } |
3c90dfc35f06
add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
923
diff
changeset
|
209 | |
3c90dfc35f06
add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
923
diff
changeset
|
210 | char comment1 = prop->config.comment1; |
3c90dfc35f06
add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
923
diff
changeset
|
211 | char comment2 = prop->config.comment2; |
3c90dfc35f06
add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
923
diff
changeset
|
212 | char comment3 = prop->config.comment3; |
3c90dfc35f06
add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
923
diff
changeset
|
213 | char delimiter = prop->config.delimiter; |
3c90dfc35f06
add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
923
diff
changeset
|
214 | |
3c90dfc35f06
add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
923
diff
changeset
|
215 | // get one line and parse it |
3c90dfc35f06
add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
923
diff
changeset
|
216 | while (prop->text_pos < prop->text_size) { |
3c90dfc35f06
add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
923
diff
changeset
|
217 | const char *buf = prop->text + prop->text_pos; |
3c90dfc35f06
add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
923
diff
changeset
|
218 | size_t len = prop->text_size - prop->text_pos; |
3c90dfc35f06
add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
923
diff
changeset
|
219 | |
3c90dfc35f06
add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
923
diff
changeset
|
220 | /* |
3c90dfc35f06
add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
923
diff
changeset
|
221 | * First we check if we have at least one line. We also get indices of |
3c90dfc35f06
add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
923
diff
changeset
|
222 | * delimiter and comment chars |
3c90dfc35f06
add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
923
diff
changeset
|
223 | */ |
3c90dfc35f06
add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
923
diff
changeset
|
224 | size_t delimiter_index = 0; |
3c90dfc35f06
add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
923
diff
changeset
|
225 | size_t comment_index = 0; |
3c90dfc35f06
add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
923
diff
changeset
|
226 | bool has_comment = false; |
3c90dfc35f06
add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
923
diff
changeset
|
227 | |
3c90dfc35f06
add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
923
diff
changeset
|
228 | size_t i = 0; |
3c90dfc35f06
add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
923
diff
changeset
|
229 | char c = 0; |
3c90dfc35f06
add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
923
diff
changeset
|
230 | for (; i < len; i++) { |
3c90dfc35f06
add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
923
diff
changeset
|
231 | c = buf[i]; |
3c90dfc35f06
add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
923
diff
changeset
|
232 | if (c == comment1 || c == comment2 || c == comment3) { |
3c90dfc35f06
add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
923
diff
changeset
|
233 | if (comment_index == 0) { |
3c90dfc35f06
add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
923
diff
changeset
|
234 | comment_index = i; |
3c90dfc35f06
add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
923
diff
changeset
|
235 | has_comment = true; |
3c90dfc35f06
add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
923
diff
changeset
|
236 | } |
3c90dfc35f06
add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
923
diff
changeset
|
237 | } else if (c == delimiter) { |
3c90dfc35f06
add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
923
diff
changeset
|
238 | if (delimiter_index == 0 && !has_comment) { |
3c90dfc35f06
add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
923
diff
changeset
|
239 | delimiter_index = i; |
3c90dfc35f06
add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
923
diff
changeset
|
240 | } |
3c90dfc35f06
add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
923
diff
changeset
|
241 | } else if (c == '\n') { |
3c90dfc35f06
add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
923
diff
changeset
|
242 | break; |
3c90dfc35f06
add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
923
diff
changeset
|
243 | } |
3c90dfc35f06
add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
923
diff
changeset
|
244 | } |
3c90dfc35f06
add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
923
diff
changeset
|
245 | |
3c90dfc35f06
add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
923
diff
changeset
|
246 | if (c != '\n') { |
3c90dfc35f06
add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
923
diff
changeset
|
247 | // we don't have enough data for a line |
928
d2d42cb1d59e
add source/sink facility for properties - fixes #430
Mike Becker <universe@uap-core.de>
parents:
924
diff
changeset
|
248 | if (cx_properties_rescue_input(prop)) { |
d2d42cb1d59e
add source/sink facility for properties - fixes #430
Mike Becker <universe@uap-core.de>
parents:
924
diff
changeset
|
249 | return CX_PROPERTIES_BUFFER_ALLOC_FAILED; |
d2d42cb1d59e
add source/sink facility for properties - fixes #430
Mike Becker <universe@uap-core.de>
parents:
924
diff
changeset
|
250 | } |
924
3c90dfc35f06
add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
923
diff
changeset
|
251 | return CX_PROPERTIES_INCOMPLETE_DATA; |
3c90dfc35f06
add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
923
diff
changeset
|
252 | } |
3c90dfc35f06
add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
923
diff
changeset
|
253 | |
3c90dfc35f06
add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
923
diff
changeset
|
254 | cxstring line = has_comment ? |
3c90dfc35f06
add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
923
diff
changeset
|
255 | cx_strn(buf, comment_index) : |
3c90dfc35f06
add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
923
diff
changeset
|
256 | cx_strn(buf, i); |
3c90dfc35f06
add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
923
diff
changeset
|
257 | // check line |
3c90dfc35f06
add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
923
diff
changeset
|
258 | if (delimiter_index == 0) { |
3c90dfc35f06
add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
923
diff
changeset
|
259 | // if line is not blank ... |
3c90dfc35f06
add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
923
diff
changeset
|
260 | line = cx_strtrim(line); |
3c90dfc35f06
add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
923
diff
changeset
|
261 | // ... either no delimiter found, or key is empty |
3c90dfc35f06
add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
923
diff
changeset
|
262 | if (line.length > 0) { |
3c90dfc35f06
add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
923
diff
changeset
|
263 | if (line.ptr[0] == delimiter) { |
3c90dfc35f06
add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
923
diff
changeset
|
264 | return CX_PROPERTIES_INVALID_EMPTY_KEY; |
3c90dfc35f06
add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
923
diff
changeset
|
265 | } else { |
3c90dfc35f06
add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
923
diff
changeset
|
266 | return CX_PROPERTIES_INVALID_MISSING_DELIMITER; |
3c90dfc35f06
add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
923
diff
changeset
|
267 | } |
3c90dfc35f06
add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
923
diff
changeset
|
268 | } |
3c90dfc35f06
add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
923
diff
changeset
|
269 | } else { |
3c90dfc35f06
add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
923
diff
changeset
|
270 | cxstring k = cx_strn(buf, delimiter_index); |
3c90dfc35f06
add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
923
diff
changeset
|
271 | cxstring val = cx_strn( |
3c90dfc35f06
add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
923
diff
changeset
|
272 | buf + delimiter_index + 1, |
3c90dfc35f06
add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
923
diff
changeset
|
273 | line.length - delimiter_index - 1); |
3c90dfc35f06
add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
923
diff
changeset
|
274 | k = cx_strtrim(k); |
3c90dfc35f06
add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
923
diff
changeset
|
275 | val = cx_strtrim(val); |
3c90dfc35f06
add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
923
diff
changeset
|
276 | if (k.length > 0) { |
3c90dfc35f06
add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
923
diff
changeset
|
277 | *key = k; |
3c90dfc35f06
add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
923
diff
changeset
|
278 | *value = val; |
3c90dfc35f06
add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
923
diff
changeset
|
279 | prop->text_pos += i + 1; |
3c90dfc35f06
add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
923
diff
changeset
|
280 | assert(prop->text_pos <= prop->text_size); |
3c90dfc35f06
add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
923
diff
changeset
|
281 | return CX_PROPERTIES_NO_ERROR; |
3c90dfc35f06
add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
923
diff
changeset
|
282 | } else { |
3c90dfc35f06
add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
923
diff
changeset
|
283 | return CX_PROPERTIES_INVALID_EMPTY_KEY; |
3c90dfc35f06
add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
923
diff
changeset
|
284 | } |
3c90dfc35f06
add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
923
diff
changeset
|
285 | } |
3c90dfc35f06
add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
923
diff
changeset
|
286 | |
3c90dfc35f06
add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
923
diff
changeset
|
287 | prop->text_pos += i + 1; |
3c90dfc35f06
add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
923
diff
changeset
|
288 | } |
3c90dfc35f06
add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
923
diff
changeset
|
289 | |
3c90dfc35f06
add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
923
diff
changeset
|
290 | // when we come to this point, all data must have been read |
3c90dfc35f06
add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
923
diff
changeset
|
291 | assert(prop->text_pos == prop->text_size); |
3c90dfc35f06
add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
923
diff
changeset
|
292 | return CX_PROPERTIES_NO_DATA; |
3c90dfc35f06
add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
923
diff
changeset
|
293 | } |
928
d2d42cb1d59e
add source/sink facility for properties - fixes #430
Mike Becker <universe@uap-core.de>
parents:
924
diff
changeset
|
294 | |
d2d42cb1d59e
add source/sink facility for properties - fixes #430
Mike Becker <universe@uap-core.de>
parents:
924
diff
changeset
|
295 | static int cx_properties_sink_map( |
d2d42cb1d59e
add source/sink facility for properties - fixes #430
Mike Becker <universe@uap-core.de>
parents:
924
diff
changeset
|
296 | __attribute__((__unused__)) CxProperties *prop, |
d2d42cb1d59e
add source/sink facility for properties - fixes #430
Mike Becker <universe@uap-core.de>
parents:
924
diff
changeset
|
297 | CxPropertiesSink *sink, |
d2d42cb1d59e
add source/sink facility for properties - fixes #430
Mike Becker <universe@uap-core.de>
parents:
924
diff
changeset
|
298 | cxstring key, |
d2d42cb1d59e
add source/sink facility for properties - fixes #430
Mike Becker <universe@uap-core.de>
parents:
924
diff
changeset
|
299 | cxstring value |
d2d42cb1d59e
add source/sink facility for properties - fixes #430
Mike Becker <universe@uap-core.de>
parents:
924
diff
changeset
|
300 | ) { |
d2d42cb1d59e
add source/sink facility for properties - fixes #430
Mike Becker <universe@uap-core.de>
parents:
924
diff
changeset
|
301 | CxMap *map = sink->sink; |
d2d42cb1d59e
add source/sink facility for properties - fixes #430
Mike Becker <universe@uap-core.de>
parents:
924
diff
changeset
|
302 | CxAllocator *alloc = sink->data; |
d2d42cb1d59e
add source/sink facility for properties - fixes #430
Mike Becker <universe@uap-core.de>
parents:
924
diff
changeset
|
303 | cxmutstr v = cx_strdup_a(alloc, value); |
d2d42cb1d59e
add source/sink facility for properties - fixes #430
Mike Becker <universe@uap-core.de>
parents:
924
diff
changeset
|
304 | int r = cx_map_put_cxstr(map, key, v.ptr); |
d2d42cb1d59e
add source/sink facility for properties - fixes #430
Mike Becker <universe@uap-core.de>
parents:
924
diff
changeset
|
305 | if (r != 0) cx_strfree_a(alloc, &v); |
d2d42cb1d59e
add source/sink facility for properties - fixes #430
Mike Becker <universe@uap-core.de>
parents:
924
diff
changeset
|
306 | return r; |
d2d42cb1d59e
add source/sink facility for properties - fixes #430
Mike Becker <universe@uap-core.de>
parents:
924
diff
changeset
|
307 | } |
d2d42cb1d59e
add source/sink facility for properties - fixes #430
Mike Becker <universe@uap-core.de>
parents:
924
diff
changeset
|
308 | |
d2d42cb1d59e
add source/sink facility for properties - fixes #430
Mike Becker <universe@uap-core.de>
parents:
924
diff
changeset
|
309 | CxPropertiesSink cxPropertiesMapSink(CxMap *map) { |
d2d42cb1d59e
add source/sink facility for properties - fixes #430
Mike Becker <universe@uap-core.de>
parents:
924
diff
changeset
|
310 | CxPropertiesSink sink; |
d2d42cb1d59e
add source/sink facility for properties - fixes #430
Mike Becker <universe@uap-core.de>
parents:
924
diff
changeset
|
311 | sink.sink = map; |
d2d42cb1d59e
add source/sink facility for properties - fixes #430
Mike Becker <universe@uap-core.de>
parents:
924
diff
changeset
|
312 | sink.data = cxDefaultAllocator; |
d2d42cb1d59e
add source/sink facility for properties - fixes #430
Mike Becker <universe@uap-core.de>
parents:
924
diff
changeset
|
313 | sink.sink_func = cx_properties_sink_map; |
d2d42cb1d59e
add source/sink facility for properties - fixes #430
Mike Becker <universe@uap-core.de>
parents:
924
diff
changeset
|
314 | return sink; |
d2d42cb1d59e
add source/sink facility for properties - fixes #430
Mike Becker <universe@uap-core.de>
parents:
924
diff
changeset
|
315 | } |
d2d42cb1d59e
add source/sink facility for properties - fixes #430
Mike Becker <universe@uap-core.de>
parents:
924
diff
changeset
|
316 | |
d2d42cb1d59e
add source/sink facility for properties - fixes #430
Mike Becker <universe@uap-core.de>
parents:
924
diff
changeset
|
317 | static int cx_properties_read_string( |
d2d42cb1d59e
add source/sink facility for properties - fixes #430
Mike Becker <universe@uap-core.de>
parents:
924
diff
changeset
|
318 | CxProperties *prop, |
d2d42cb1d59e
add source/sink facility for properties - fixes #430
Mike Becker <universe@uap-core.de>
parents:
924
diff
changeset
|
319 | CxPropertiesSource *src, |
d2d42cb1d59e
add source/sink facility for properties - fixes #430
Mike Becker <universe@uap-core.de>
parents:
924
diff
changeset
|
320 | cxstring *target |
d2d42cb1d59e
add source/sink facility for properties - fixes #430
Mike Becker <universe@uap-core.de>
parents:
924
diff
changeset
|
321 | ) { |
d2d42cb1d59e
add source/sink facility for properties - fixes #430
Mike Becker <universe@uap-core.de>
parents:
924
diff
changeset
|
322 | if (prop->text == src->src) { |
d2d42cb1d59e
add source/sink facility for properties - fixes #430
Mike Becker <universe@uap-core.de>
parents:
924
diff
changeset
|
323 | // when the input buffer already contains the string |
d2d42cb1d59e
add source/sink facility for properties - fixes #430
Mike Becker <universe@uap-core.de>
parents:
924
diff
changeset
|
324 | // we have nothing more to provide |
d2d42cb1d59e
add source/sink facility for properties - fixes #430
Mike Becker <universe@uap-core.de>
parents:
924
diff
changeset
|
325 | target->length = 0; |
d2d42cb1d59e
add source/sink facility for properties - fixes #430
Mike Becker <universe@uap-core.de>
parents:
924
diff
changeset
|
326 | } else { |
d2d42cb1d59e
add source/sink facility for properties - fixes #430
Mike Becker <universe@uap-core.de>
parents:
924
diff
changeset
|
327 | target->ptr = src->src; |
d2d42cb1d59e
add source/sink facility for properties - fixes #430
Mike Becker <universe@uap-core.de>
parents:
924
diff
changeset
|
328 | target->length = src->data_size; |
d2d42cb1d59e
add source/sink facility for properties - fixes #430
Mike Becker <universe@uap-core.de>
parents:
924
diff
changeset
|
329 | } |
d2d42cb1d59e
add source/sink facility for properties - fixes #430
Mike Becker <universe@uap-core.de>
parents:
924
diff
changeset
|
330 | return 0; |
d2d42cb1d59e
add source/sink facility for properties - fixes #430
Mike Becker <universe@uap-core.de>
parents:
924
diff
changeset
|
331 | } |
d2d42cb1d59e
add source/sink facility for properties - fixes #430
Mike Becker <universe@uap-core.de>
parents:
924
diff
changeset
|
332 | |
d2d42cb1d59e
add source/sink facility for properties - fixes #430
Mike Becker <universe@uap-core.de>
parents:
924
diff
changeset
|
333 | static int cx_properties_read_file( |
d2d42cb1d59e
add source/sink facility for properties - fixes #430
Mike Becker <universe@uap-core.de>
parents:
924
diff
changeset
|
334 | __attribute__((__unused__)) CxProperties *prop, |
d2d42cb1d59e
add source/sink facility for properties - fixes #430
Mike Becker <universe@uap-core.de>
parents:
924
diff
changeset
|
335 | CxPropertiesSource *src, |
d2d42cb1d59e
add source/sink facility for properties - fixes #430
Mike Becker <universe@uap-core.de>
parents:
924
diff
changeset
|
336 | cxstring *target |
d2d42cb1d59e
add source/sink facility for properties - fixes #430
Mike Becker <universe@uap-core.de>
parents:
924
diff
changeset
|
337 | ) { |
d2d42cb1d59e
add source/sink facility for properties - fixes #430
Mike Becker <universe@uap-core.de>
parents:
924
diff
changeset
|
338 | target->ptr = src->data_ptr; |
d2d42cb1d59e
add source/sink facility for properties - fixes #430
Mike Becker <universe@uap-core.de>
parents:
924
diff
changeset
|
339 | target->length = fread(src->data_ptr, 1, src->data_size, src->src); |
d2d42cb1d59e
add source/sink facility for properties - fixes #430
Mike Becker <universe@uap-core.de>
parents:
924
diff
changeset
|
340 | return ferror(src->src); |
d2d42cb1d59e
add source/sink facility for properties - fixes #430
Mike Becker <universe@uap-core.de>
parents:
924
diff
changeset
|
341 | } |
d2d42cb1d59e
add source/sink facility for properties - fixes #430
Mike Becker <universe@uap-core.de>
parents:
924
diff
changeset
|
342 | |
d2d42cb1d59e
add source/sink facility for properties - fixes #430
Mike Becker <universe@uap-core.de>
parents:
924
diff
changeset
|
343 | static int cx_properties_read_init_file( |
d2d42cb1d59e
add source/sink facility for properties - fixes #430
Mike Becker <universe@uap-core.de>
parents:
924
diff
changeset
|
344 | __attribute__((__unused__)) CxProperties *prop, |
d2d42cb1d59e
add source/sink facility for properties - fixes #430
Mike Becker <universe@uap-core.de>
parents:
924
diff
changeset
|
345 | CxPropertiesSource *src |
d2d42cb1d59e
add source/sink facility for properties - fixes #430
Mike Becker <universe@uap-core.de>
parents:
924
diff
changeset
|
346 | ) { |
d2d42cb1d59e
add source/sink facility for properties - fixes #430
Mike Becker <universe@uap-core.de>
parents:
924
diff
changeset
|
347 | src->data_ptr = malloc(src->data_size); |
d2d42cb1d59e
add source/sink facility for properties - fixes #430
Mike Becker <universe@uap-core.de>
parents:
924
diff
changeset
|
348 | if (src->data_ptr == NULL) return 1; |
d2d42cb1d59e
add source/sink facility for properties - fixes #430
Mike Becker <universe@uap-core.de>
parents:
924
diff
changeset
|
349 | return 0; |
d2d42cb1d59e
add source/sink facility for properties - fixes #430
Mike Becker <universe@uap-core.de>
parents:
924
diff
changeset
|
350 | } |
d2d42cb1d59e
add source/sink facility for properties - fixes #430
Mike Becker <universe@uap-core.de>
parents:
924
diff
changeset
|
351 | |
d2d42cb1d59e
add source/sink facility for properties - fixes #430
Mike Becker <universe@uap-core.de>
parents:
924
diff
changeset
|
352 | static void cx_properties_read_clean_file( |
d2d42cb1d59e
add source/sink facility for properties - fixes #430
Mike Becker <universe@uap-core.de>
parents:
924
diff
changeset
|
353 | __attribute__((__unused__)) CxProperties *prop, |
d2d42cb1d59e
add source/sink facility for properties - fixes #430
Mike Becker <universe@uap-core.de>
parents:
924
diff
changeset
|
354 | CxPropertiesSource *src |
d2d42cb1d59e
add source/sink facility for properties - fixes #430
Mike Becker <universe@uap-core.de>
parents:
924
diff
changeset
|
355 | ) { |
d2d42cb1d59e
add source/sink facility for properties - fixes #430
Mike Becker <universe@uap-core.de>
parents:
924
diff
changeset
|
356 | free(src->data_ptr); |
d2d42cb1d59e
add source/sink facility for properties - fixes #430
Mike Becker <universe@uap-core.de>
parents:
924
diff
changeset
|
357 | } |
d2d42cb1d59e
add source/sink facility for properties - fixes #430
Mike Becker <universe@uap-core.de>
parents:
924
diff
changeset
|
358 | |
d2d42cb1d59e
add source/sink facility for properties - fixes #430
Mike Becker <universe@uap-core.de>
parents:
924
diff
changeset
|
359 | CxPropertiesSource cxPropertiesStringSource(cxstring str) { |
d2d42cb1d59e
add source/sink facility for properties - fixes #430
Mike Becker <universe@uap-core.de>
parents:
924
diff
changeset
|
360 | CxPropertiesSource src; |
d2d42cb1d59e
add source/sink facility for properties - fixes #430
Mike Becker <universe@uap-core.de>
parents:
924
diff
changeset
|
361 | src.src = (void*) str.ptr; |
d2d42cb1d59e
add source/sink facility for properties - fixes #430
Mike Becker <universe@uap-core.de>
parents:
924
diff
changeset
|
362 | src.data_size = str.length; |
d2d42cb1d59e
add source/sink facility for properties - fixes #430
Mike Becker <universe@uap-core.de>
parents:
924
diff
changeset
|
363 | src.read_func = cx_properties_read_string; |
d2d42cb1d59e
add source/sink facility for properties - fixes #430
Mike Becker <universe@uap-core.de>
parents:
924
diff
changeset
|
364 | src.read_init_func = NULL; |
d2d42cb1d59e
add source/sink facility for properties - fixes #430
Mike Becker <universe@uap-core.de>
parents:
924
diff
changeset
|
365 | src.read_clean_func = NULL; |
d2d42cb1d59e
add source/sink facility for properties - fixes #430
Mike Becker <universe@uap-core.de>
parents:
924
diff
changeset
|
366 | return src; |
d2d42cb1d59e
add source/sink facility for properties - fixes #430
Mike Becker <universe@uap-core.de>
parents:
924
diff
changeset
|
367 | } |
d2d42cb1d59e
add source/sink facility for properties - fixes #430
Mike Becker <universe@uap-core.de>
parents:
924
diff
changeset
|
368 | |
d2d42cb1d59e
add source/sink facility for properties - fixes #430
Mike Becker <universe@uap-core.de>
parents:
924
diff
changeset
|
369 | CxPropertiesSource cxPropertiesCstrnSource(const char *str, size_t len) { |
d2d42cb1d59e
add source/sink facility for properties - fixes #430
Mike Becker <universe@uap-core.de>
parents:
924
diff
changeset
|
370 | CxPropertiesSource src; |
d2d42cb1d59e
add source/sink facility for properties - fixes #430
Mike Becker <universe@uap-core.de>
parents:
924
diff
changeset
|
371 | src.src = (void*) str; |
d2d42cb1d59e
add source/sink facility for properties - fixes #430
Mike Becker <universe@uap-core.de>
parents:
924
diff
changeset
|
372 | src.data_size = len; |
d2d42cb1d59e
add source/sink facility for properties - fixes #430
Mike Becker <universe@uap-core.de>
parents:
924
diff
changeset
|
373 | src.read_func = cx_properties_read_string; |
d2d42cb1d59e
add source/sink facility for properties - fixes #430
Mike Becker <universe@uap-core.de>
parents:
924
diff
changeset
|
374 | src.read_init_func = NULL; |
d2d42cb1d59e
add source/sink facility for properties - fixes #430
Mike Becker <universe@uap-core.de>
parents:
924
diff
changeset
|
375 | src.read_clean_func = NULL; |
d2d42cb1d59e
add source/sink facility for properties - fixes #430
Mike Becker <universe@uap-core.de>
parents:
924
diff
changeset
|
376 | return src; |
d2d42cb1d59e
add source/sink facility for properties - fixes #430
Mike Becker <universe@uap-core.de>
parents:
924
diff
changeset
|
377 | } |
d2d42cb1d59e
add source/sink facility for properties - fixes #430
Mike Becker <universe@uap-core.de>
parents:
924
diff
changeset
|
378 | |
d2d42cb1d59e
add source/sink facility for properties - fixes #430
Mike Becker <universe@uap-core.de>
parents:
924
diff
changeset
|
379 | CxPropertiesSource cxPropertiesCstrSource(const char *str) { |
d2d42cb1d59e
add source/sink facility for properties - fixes #430
Mike Becker <universe@uap-core.de>
parents:
924
diff
changeset
|
380 | CxPropertiesSource src; |
d2d42cb1d59e
add source/sink facility for properties - fixes #430
Mike Becker <universe@uap-core.de>
parents:
924
diff
changeset
|
381 | src.src = (void*) str; |
d2d42cb1d59e
add source/sink facility for properties - fixes #430
Mike Becker <universe@uap-core.de>
parents:
924
diff
changeset
|
382 | src.data_size = strlen(str); |
d2d42cb1d59e
add source/sink facility for properties - fixes #430
Mike Becker <universe@uap-core.de>
parents:
924
diff
changeset
|
383 | src.read_func = cx_properties_read_string; |
d2d42cb1d59e
add source/sink facility for properties - fixes #430
Mike Becker <universe@uap-core.de>
parents:
924
diff
changeset
|
384 | src.read_init_func = NULL; |
d2d42cb1d59e
add source/sink facility for properties - fixes #430
Mike Becker <universe@uap-core.de>
parents:
924
diff
changeset
|
385 | src.read_clean_func = NULL; |
d2d42cb1d59e
add source/sink facility for properties - fixes #430
Mike Becker <universe@uap-core.de>
parents:
924
diff
changeset
|
386 | return src; |
d2d42cb1d59e
add source/sink facility for properties - fixes #430
Mike Becker <universe@uap-core.de>
parents:
924
diff
changeset
|
387 | } |
d2d42cb1d59e
add source/sink facility for properties - fixes #430
Mike Becker <universe@uap-core.de>
parents:
924
diff
changeset
|
388 | |
d2d42cb1d59e
add source/sink facility for properties - fixes #430
Mike Becker <universe@uap-core.de>
parents:
924
diff
changeset
|
389 | CxPropertiesSource cxPropertiesFileSource(FILE *file, size_t chunk_size) { |
d2d42cb1d59e
add source/sink facility for properties - fixes #430
Mike Becker <universe@uap-core.de>
parents:
924
diff
changeset
|
390 | CxPropertiesSource src; |
d2d42cb1d59e
add source/sink facility for properties - fixes #430
Mike Becker <universe@uap-core.de>
parents:
924
diff
changeset
|
391 | src.src = file; |
d2d42cb1d59e
add source/sink facility for properties - fixes #430
Mike Becker <universe@uap-core.de>
parents:
924
diff
changeset
|
392 | src.data_size = chunk_size; |
d2d42cb1d59e
add source/sink facility for properties - fixes #430
Mike Becker <universe@uap-core.de>
parents:
924
diff
changeset
|
393 | src.read_func = cx_properties_read_file; |
d2d42cb1d59e
add source/sink facility for properties - fixes #430
Mike Becker <universe@uap-core.de>
parents:
924
diff
changeset
|
394 | src.read_init_func = cx_properties_read_init_file; |
d2d42cb1d59e
add source/sink facility for properties - fixes #430
Mike Becker <universe@uap-core.de>
parents:
924
diff
changeset
|
395 | src.read_clean_func = cx_properties_read_clean_file; |
d2d42cb1d59e
add source/sink facility for properties - fixes #430
Mike Becker <universe@uap-core.de>
parents:
924
diff
changeset
|
396 | return src; |
d2d42cb1d59e
add source/sink facility for properties - fixes #430
Mike Becker <universe@uap-core.de>
parents:
924
diff
changeset
|
397 | } |
d2d42cb1d59e
add source/sink facility for properties - fixes #430
Mike Becker <universe@uap-core.de>
parents:
924
diff
changeset
|
398 | |
d2d42cb1d59e
add source/sink facility for properties - fixes #430
Mike Becker <universe@uap-core.de>
parents:
924
diff
changeset
|
399 | CxPropertiesStatus cxPropertiesLoad( |
d2d42cb1d59e
add source/sink facility for properties - fixes #430
Mike Becker <universe@uap-core.de>
parents:
924
diff
changeset
|
400 | CxProperties *prop, |
d2d42cb1d59e
add source/sink facility for properties - fixes #430
Mike Becker <universe@uap-core.de>
parents:
924
diff
changeset
|
401 | CxPropertiesSink sink, |
d2d42cb1d59e
add source/sink facility for properties - fixes #430
Mike Becker <universe@uap-core.de>
parents:
924
diff
changeset
|
402 | CxPropertiesSource source |
d2d42cb1d59e
add source/sink facility for properties - fixes #430
Mike Becker <universe@uap-core.de>
parents:
924
diff
changeset
|
403 | ) { |
d2d42cb1d59e
add source/sink facility for properties - fixes #430
Mike Becker <universe@uap-core.de>
parents:
924
diff
changeset
|
404 | assert(source.read_func != NULL); |
d2d42cb1d59e
add source/sink facility for properties - fixes #430
Mike Becker <universe@uap-core.de>
parents:
924
diff
changeset
|
405 | assert(sink.sink_func != NULL); |
d2d42cb1d59e
add source/sink facility for properties - fixes #430
Mike Becker <universe@uap-core.de>
parents:
924
diff
changeset
|
406 | |
d2d42cb1d59e
add source/sink facility for properties - fixes #430
Mike Becker <universe@uap-core.de>
parents:
924
diff
changeset
|
407 | // initialize reader |
d2d42cb1d59e
add source/sink facility for properties - fixes #430
Mike Becker <universe@uap-core.de>
parents:
924
diff
changeset
|
408 | if (source.read_init_func != NULL) { |
d2d42cb1d59e
add source/sink facility for properties - fixes #430
Mike Becker <universe@uap-core.de>
parents:
924
diff
changeset
|
409 | if (source.read_init_func(prop, &source)) { |
d2d42cb1d59e
add source/sink facility for properties - fixes #430
Mike Becker <universe@uap-core.de>
parents:
924
diff
changeset
|
410 | return CX_PROPERTIES_READ_INIT_FAILED; |
d2d42cb1d59e
add source/sink facility for properties - fixes #430
Mike Becker <universe@uap-core.de>
parents:
924
diff
changeset
|
411 | } |
d2d42cb1d59e
add source/sink facility for properties - fixes #430
Mike Becker <universe@uap-core.de>
parents:
924
diff
changeset
|
412 | } |
d2d42cb1d59e
add source/sink facility for properties - fixes #430
Mike Becker <universe@uap-core.de>
parents:
924
diff
changeset
|
413 | |
d2d42cb1d59e
add source/sink facility for properties - fixes #430
Mike Becker <universe@uap-core.de>
parents:
924
diff
changeset
|
414 | // transfer the data from the source to the sink |
d2d42cb1d59e
add source/sink facility for properties - fixes #430
Mike Becker <universe@uap-core.de>
parents:
924
diff
changeset
|
415 | CxPropertiesStatus status; |
d2d42cb1d59e
add source/sink facility for properties - fixes #430
Mike Becker <universe@uap-core.de>
parents:
924
diff
changeset
|
416 | bool found = false; |
d2d42cb1d59e
add source/sink facility for properties - fixes #430
Mike Becker <universe@uap-core.de>
parents:
924
diff
changeset
|
417 | while (true) { |
d2d42cb1d59e
add source/sink facility for properties - fixes #430
Mike Becker <universe@uap-core.de>
parents:
924
diff
changeset
|
418 | // read input |
d2d42cb1d59e
add source/sink facility for properties - fixes #430
Mike Becker <universe@uap-core.de>
parents:
924
diff
changeset
|
419 | cxstring input; |
d2d42cb1d59e
add source/sink facility for properties - fixes #430
Mike Becker <universe@uap-core.de>
parents:
924
diff
changeset
|
420 | if (source.read_func(prop, &source, &input)) { |
d2d42cb1d59e
add source/sink facility for properties - fixes #430
Mike Becker <universe@uap-core.de>
parents:
924
diff
changeset
|
421 | status = CX_PROPERTIES_READ_FAILED; |
d2d42cb1d59e
add source/sink facility for properties - fixes #430
Mike Becker <universe@uap-core.de>
parents:
924
diff
changeset
|
422 | break; |
d2d42cb1d59e
add source/sink facility for properties - fixes #430
Mike Becker <universe@uap-core.de>
parents:
924
diff
changeset
|
423 | } |
d2d42cb1d59e
add source/sink facility for properties - fixes #430
Mike Becker <universe@uap-core.de>
parents:
924
diff
changeset
|
424 | |
d2d42cb1d59e
add source/sink facility for properties - fixes #430
Mike Becker <universe@uap-core.de>
parents:
924
diff
changeset
|
425 | // no more data - break |
d2d42cb1d59e
add source/sink facility for properties - fixes #430
Mike Becker <universe@uap-core.de>
parents:
924
diff
changeset
|
426 | if (input.length == 0) { |
d2d42cb1d59e
add source/sink facility for properties - fixes #430
Mike Becker <universe@uap-core.de>
parents:
924
diff
changeset
|
427 | status = found ? CX_PROPERTIES_NO_ERROR : CX_PROPERTIES_NO_DATA; |
d2d42cb1d59e
add source/sink facility for properties - fixes #430
Mike Becker <universe@uap-core.de>
parents:
924
diff
changeset
|
428 | break; |
d2d42cb1d59e
add source/sink facility for properties - fixes #430
Mike Becker <universe@uap-core.de>
parents:
924
diff
changeset
|
429 | } |
d2d42cb1d59e
add source/sink facility for properties - fixes #430
Mike Becker <universe@uap-core.de>
parents:
924
diff
changeset
|
430 | |
d2d42cb1d59e
add source/sink facility for properties - fixes #430
Mike Becker <universe@uap-core.de>
parents:
924
diff
changeset
|
431 | // set the input buffer and read the k/v-pairs |
d2d42cb1d59e
add source/sink facility for properties - fixes #430
Mike Becker <universe@uap-core.de>
parents:
924
diff
changeset
|
432 | cxPropertiesInput(prop, input.ptr, input.length); |
d2d42cb1d59e
add source/sink facility for properties - fixes #430
Mike Becker <universe@uap-core.de>
parents:
924
diff
changeset
|
433 | |
d2d42cb1d59e
add source/sink facility for properties - fixes #430
Mike Becker <universe@uap-core.de>
parents:
924
diff
changeset
|
434 | CxPropertiesStatus kv_status; |
d2d42cb1d59e
add source/sink facility for properties - fixes #430
Mike Becker <universe@uap-core.de>
parents:
924
diff
changeset
|
435 | do { |
d2d42cb1d59e
add source/sink facility for properties - fixes #430
Mike Becker <universe@uap-core.de>
parents:
924
diff
changeset
|
436 | cxstring key, value; |
d2d42cb1d59e
add source/sink facility for properties - fixes #430
Mike Becker <universe@uap-core.de>
parents:
924
diff
changeset
|
437 | kv_status = cxPropertiesNext(prop, &key, &value); |
d2d42cb1d59e
add source/sink facility for properties - fixes #430
Mike Becker <universe@uap-core.de>
parents:
924
diff
changeset
|
438 | if (kv_status == CX_PROPERTIES_NO_ERROR) { |
d2d42cb1d59e
add source/sink facility for properties - fixes #430
Mike Becker <universe@uap-core.de>
parents:
924
diff
changeset
|
439 | found = true; |
d2d42cb1d59e
add source/sink facility for properties - fixes #430
Mike Becker <universe@uap-core.de>
parents:
924
diff
changeset
|
440 | if (sink.sink_func(prop, &sink, key, value)) { |
d2d42cb1d59e
add source/sink facility for properties - fixes #430
Mike Becker <universe@uap-core.de>
parents:
924
diff
changeset
|
441 | kv_status = CX_PROPERTIES_SINK_FAILED; |
d2d42cb1d59e
add source/sink facility for properties - fixes #430
Mike Becker <universe@uap-core.de>
parents:
924
diff
changeset
|
442 | } |
d2d42cb1d59e
add source/sink facility for properties - fixes #430
Mike Becker <universe@uap-core.de>
parents:
924
diff
changeset
|
443 | } |
d2d42cb1d59e
add source/sink facility for properties - fixes #430
Mike Becker <universe@uap-core.de>
parents:
924
diff
changeset
|
444 | } while (kv_status == CX_PROPERTIES_NO_ERROR); |
d2d42cb1d59e
add source/sink facility for properties - fixes #430
Mike Becker <universe@uap-core.de>
parents:
924
diff
changeset
|
445 | |
d2d42cb1d59e
add source/sink facility for properties - fixes #430
Mike Becker <universe@uap-core.de>
parents:
924
diff
changeset
|
446 | if (kv_status > CX_PROPERTIES_OK) { |
d2d42cb1d59e
add source/sink facility for properties - fixes #430
Mike Becker <universe@uap-core.de>
parents:
924
diff
changeset
|
447 | status = kv_status; |
d2d42cb1d59e
add source/sink facility for properties - fixes #430
Mike Becker <universe@uap-core.de>
parents:
924
diff
changeset
|
448 | break; |
d2d42cb1d59e
add source/sink facility for properties - fixes #430
Mike Becker <universe@uap-core.de>
parents:
924
diff
changeset
|
449 | } |
d2d42cb1d59e
add source/sink facility for properties - fixes #430
Mike Becker <universe@uap-core.de>
parents:
924
diff
changeset
|
450 | } |
d2d42cb1d59e
add source/sink facility for properties - fixes #430
Mike Becker <universe@uap-core.de>
parents:
924
diff
changeset
|
451 | |
d2d42cb1d59e
add source/sink facility for properties - fixes #430
Mike Becker <universe@uap-core.de>
parents:
924
diff
changeset
|
452 | if (source.read_clean_func != NULL) { |
d2d42cb1d59e
add source/sink facility for properties - fixes #430
Mike Becker <universe@uap-core.de>
parents:
924
diff
changeset
|
453 | source.read_clean_func(prop, &source); |
d2d42cb1d59e
add source/sink facility for properties - fixes #430
Mike Becker <universe@uap-core.de>
parents:
924
diff
changeset
|
454 | } |
d2d42cb1d59e
add source/sink facility for properties - fixes #430
Mike Becker <universe@uap-core.de>
parents:
924
diff
changeset
|
455 | |
d2d42cb1d59e
add source/sink facility for properties - fixes #430
Mike Becker <universe@uap-core.de>
parents:
924
diff
changeset
|
456 | return status; |
d2d42cb1d59e
add source/sink facility for properties - fixes #430
Mike Becker <universe@uap-core.de>
parents:
924
diff
changeset
|
457 | } |