224 return CX_PROPERTIES_NO_ERROR; |
224 return CX_PROPERTIES_NO_ERROR; |
225 } else { |
225 } else { |
226 return CX_PROPERTIES_INVALID_EMPTY_KEY; |
226 return CX_PROPERTIES_INVALID_EMPTY_KEY; |
227 } |
227 } |
228 } |
228 } |
229 // unreachable - either we returned or skipped a blank line |
|
230 assert(false); |
|
231 } |
229 } |
232 |
230 |
233 // when we come to this point, all data must have been read |
231 // when we come to this point, all data must have been read |
234 assert(cxBufferEof(&prop->buffer)); |
232 assert(cxBufferEof(&prop->buffer)); |
235 assert(cxBufferEof(&prop->input)); |
233 assert(cxBufferEof(&prop->input)); |
252 } |
250 } |
253 |
251 |
254 CxPropertiesSink cxPropertiesMapSink(CxMap *map) { |
252 CxPropertiesSink cxPropertiesMapSink(CxMap *map) { |
255 CxPropertiesSink sink; |
253 CxPropertiesSink sink; |
256 sink.sink = map; |
254 sink.sink = map; |
257 sink.data = cxDefaultAllocator; |
255 sink.data = (void*) cxDefaultAllocator; |
258 sink.sink_func = cx_properties_sink_map; |
256 sink.sink_func = cx_properties_sink_map; |
259 return sink; |
257 return sink; |
260 } |
258 } |
261 |
259 |
262 static int cx_properties_read_string( |
260 static int cx_properties_read_string( |
280 CxPropertiesSource *src, |
278 CxPropertiesSource *src, |
281 cxstring *target |
279 cxstring *target |
282 ) { |
280 ) { |
283 target->ptr = src->data_ptr; |
281 target->ptr = src->data_ptr; |
284 target->length = fread(src->data_ptr, 1, src->data_size, src->src); |
282 target->length = fread(src->data_ptr, 1, src->data_size, src->src); |
285 return ferror(src->src); |
283 return ferror((FILE*)src->src); |
286 } |
284 } |
287 |
285 |
288 static int cx_properties_read_init_file( |
286 static int cx_properties_read_init_file( |
289 cx_attr_unused CxProperties *prop, |
287 cx_attr_unused CxProperties *prop, |
290 CxPropertiesSource *src |
288 CxPropertiesSource *src |
371 break; |
370 break; |
372 } |
371 } |
373 |
372 |
374 // no more data - break |
373 // no more data - break |
375 if (input.length == 0) { |
374 if (input.length == 0) { |
376 status = found ? CX_PROPERTIES_NO_ERROR : CX_PROPERTIES_NO_DATA; |
375 if (found) { |
|
376 // something was found, check the last kv_status |
|
377 if (kv_status == CX_PROPERTIES_INCOMPLETE_DATA) { |
|
378 status = CX_PROPERTIES_INCOMPLETE_DATA; |
|
379 } else { |
|
380 status = CX_PROPERTIES_NO_ERROR; |
|
381 } |
|
382 } else { |
|
383 // nothing found |
|
384 status = CX_PROPERTIES_NO_DATA; |
|
385 } |
377 break; |
386 break; |
378 } |
387 } |
379 |
388 |
380 // set the input buffer and read the k/v-pairs |
389 // set the input buffer and read the k/v-pairs |
381 cxPropertiesFill(prop, input); |
390 cxPropertiesFill(prop, input); |
382 |
391 |
383 CxPropertiesStatus kv_status; |
|
384 do { |
392 do { |
385 cxstring key, value; |
393 cxstring key, value; |
386 kv_status = cxPropertiesNext(prop, &key, &value); |
394 kv_status = cxPropertiesNext(prop, &key, &value); |
387 if (kv_status == CX_PROPERTIES_NO_ERROR) { |
395 if (kv_status == CX_PROPERTIES_NO_ERROR) { |
388 found = true; |
396 found = true; |