ucx/cx/properties.h

changeset 471
063a9f29098c
parent 440
7c4b9cba09ca
equal deleted inserted replaced
470:118e2386d5b4 471:063a9f29098c
57 * This is '=' by default. 57 * This is '=' by default.
58 */ 58 */
59 char delimiter; 59 char delimiter;
60 60
61 /** 61 /**
62 * The first comment character.
63 * This is '#' by default.
64 */
65 char comment1;
66
67 /**
68 * The second comment character.
69 * This is not set by default.
70 */
71 char comment2;
72
73 /**
74 * The third comment character.
75 * This is not set by default.
76 */
77 char comment3;
78
79 /*
62 * The character, when appearing at the end of a line, continues that line. 80 * The character, when appearing at the end of a line, continues that line.
63 * This is '\' by default. 81 * This is '\' by default.
64 */ 82 */
65 // char continuation; // TODO: line continuation in properties 83 /**
66 84 * Reserved for future use.
67 /** 85 */
68 * The first comment character. 86 char continuation;
69 * This is '#' by default.
70 */
71 char comment1;
72
73 /**
74 * The second comment character.
75 * This is not set by default.
76 */
77 char comment2;
78
79 /**
80 * The third comment character.
81 * This is not set by default.
82 */
83 char comment3;
84 }; 87 };
85 88
86 /** 89 /**
87 * Typedef for the properties config. 90 * Typedef for the properties config.
88 */ 91 */
89 typedef struct cx_properties_config_s CxPropertiesConfig; 92 typedef struct cx_properties_config_s CxPropertiesConfig;
90 93
91 /** 94 /**
92 * Default properties configuration. 95 * Default properties configuration.
93 */ 96 */
97 cx_attr_export
94 extern const CxPropertiesConfig cx_properties_config_default; 98 extern const CxPropertiesConfig cx_properties_config_default;
95 99
96 /** 100 /**
97 * Status codes for the properties interface. 101 * Status codes for the properties interface.
98 */ 102 */
325 * @param prop the properties interface 329 * @param prop the properties interface
326 * @param config the properties configuration 330 * @param config the properties configuration
327 * @see cxPropertiesInitDefault() 331 * @see cxPropertiesInitDefault()
328 */ 332 */
329 cx_attr_nonnull 333 cx_attr_nonnull
334 cx_attr_export
330 void cxPropertiesInit(CxProperties *prop, CxPropertiesConfig config); 335 void cxPropertiesInit(CxProperties *prop, CxPropertiesConfig config);
331 336
332 /** 337 /**
333 * Destroys the properties interface. 338 * Destroys the properties interface.
334 * 339 *
339 * add call to this function. 344 * add call to this function.
340 * 345 *
341 * @param prop the properties interface 346 * @param prop the properties interface
342 */ 347 */
343 cx_attr_nonnull 348 cx_attr_nonnull
349 cx_attr_export
344 void cxPropertiesDestroy(CxProperties *prop); 350 void cxPropertiesDestroy(CxProperties *prop);
345 351
346 /** 352 /**
347 * Destroys and re-initializes the properties interface. 353 * Destroys and re-initializes the properties interface.
348 * 354 *
388 * @retval non-zero a memory allocation was necessary but failed 394 * @retval non-zero a memory allocation was necessary but failed
389 * @see cxPropertiesFill() 395 * @see cxPropertiesFill()
390 */ 396 */
391 cx_attr_nonnull 397 cx_attr_nonnull
392 cx_attr_access_r(2, 3) 398 cx_attr_access_r(2, 3)
399 cx_attr_export
393 int cxPropertiesFilln( 400 int cxPropertiesFilln(
394 CxProperties *prop, 401 CxProperties *prop,
395 const char *buf, 402 const char *buf,
396 size_t len 403 size_t len
397 ); 404 );
493 * @param prop the properties interface 500 * @param prop the properties interface
494 * @param buf a pointer to stack memory 501 * @param buf a pointer to stack memory
495 * @param capacity the capacity of the stack memory 502 * @param capacity the capacity of the stack memory
496 */ 503 */
497 cx_attr_nonnull 504 cx_attr_nonnull
505 cx_attr_export
498 void cxPropertiesUseStack( 506 void cxPropertiesUseStack(
499 CxProperties *prop, 507 CxProperties *prop,
500 char *buf, 508 char *buf,
501 size_t capacity 509 size_t capacity
502 ); 510 );
531 * @retval CX_PROPERTIES_INVALID_MISSING_DELIMITER the properties data contains a line without delimiter 539 * @retval CX_PROPERTIES_INVALID_MISSING_DELIMITER the properties data contains a line without delimiter
532 * @retval CX_PROPERTIES_BUFFER_ALLOC_FAILED an internal allocation was necessary but failed 540 * @retval CX_PROPERTIES_BUFFER_ALLOC_FAILED an internal allocation was necessary but failed
533 */ 541 */
534 cx_attr_nonnull 542 cx_attr_nonnull
535 cx_attr_nodiscard 543 cx_attr_nodiscard
544 cx_attr_export
536 CxPropertiesStatus cxPropertiesNext( 545 CxPropertiesStatus cxPropertiesNext(
537 CxProperties *prop, 546 CxProperties *prop,
538 cxstring *key, 547 cxstring *key,
539 cxstring *value 548 cxstring *value
540 ); 549 );
551 * @return the sink 560 * @return the sink
552 * @see cxPropertiesLoad() 561 * @see cxPropertiesLoad()
553 */ 562 */
554 cx_attr_nonnull 563 cx_attr_nonnull
555 cx_attr_nodiscard 564 cx_attr_nodiscard
565 cx_attr_export
556 CxPropertiesSink cxPropertiesMapSink(CxMap *map); 566 CxPropertiesSink cxPropertiesMapSink(CxMap *map);
557 567
558 /** 568 /**
559 * Creates a properties source based on an UCX string. 569 * Creates a properties source based on an UCX string.
560 * 570 *
561 * @param str the string 571 * @param str the string
562 * @return the properties source 572 * @return the properties source
563 * @see cxPropertiesLoad() 573 * @see cxPropertiesLoad()
564 */ 574 */
565 cx_attr_nodiscard 575 cx_attr_nodiscard
576 cx_attr_export
566 CxPropertiesSource cxPropertiesStringSource(cxstring str); 577 CxPropertiesSource cxPropertiesStringSource(cxstring str);
567 578
568 /** 579 /**
569 * Creates a properties source based on C string with the specified length. 580 * Creates a properties source based on C string with the specified length.
570 * 581 *
574 * @see cxPropertiesLoad() 585 * @see cxPropertiesLoad()
575 */ 586 */
576 cx_attr_nonnull 587 cx_attr_nonnull
577 cx_attr_nodiscard 588 cx_attr_nodiscard
578 cx_attr_access_r(1, 2) 589 cx_attr_access_r(1, 2)
590 cx_attr_export
579 CxPropertiesSource cxPropertiesCstrnSource(const char *str, size_t len); 591 CxPropertiesSource cxPropertiesCstrnSource(const char *str, size_t len);
580 592
581 /** 593 /**
582 * Creates a properties source based on a C string. 594 * Creates a properties source based on a C string.
583 * 595 *
589 * @see cxPropertiesLoad() 601 * @see cxPropertiesLoad()
590 */ 602 */
591 cx_attr_nonnull 603 cx_attr_nonnull
592 cx_attr_nodiscard 604 cx_attr_nodiscard
593 cx_attr_cstr_arg(1) 605 cx_attr_cstr_arg(1)
606 cx_attr_export
594 CxPropertiesSource cxPropertiesCstrSource(const char *str); 607 CxPropertiesSource cxPropertiesCstrSource(const char *str);
595 608
596 /** 609 /**
597 * Creates a properties source based on an FILE. 610 * Creates a properties source based on an FILE.
598 * 611 *
603 * @see cxPropertiesLoad() 616 * @see cxPropertiesLoad()
604 */ 617 */
605 cx_attr_nonnull 618 cx_attr_nonnull
606 cx_attr_nodiscard 619 cx_attr_nodiscard
607 cx_attr_access_r(1) 620 cx_attr_access_r(1)
621 cx_attr_export
608 CxPropertiesSource cxPropertiesFileSource(FILE *file, size_t chunk_size); 622 CxPropertiesSource cxPropertiesFileSource(FILE *file, size_t chunk_size);
609 623
610 624
611 /** 625 /**
612 * Loads properties data from a source and transfers it to a sink. 626 * Loads properties data from a source and transfers it to a sink.
614 * This function tries to read as much data from the source as possible. 628 * This function tries to read as much data from the source as possible.
615 * When the source was completely consumed and at least on k/v-pair was found, 629 * When the source was completely consumed and at least on k/v-pair was found,
616 * the return value will be #CX_PROPERTIES_NO_ERROR. 630 * the return value will be #CX_PROPERTIES_NO_ERROR.
617 * When the source was consumed but no k/v-pairs were found, the return value 631 * When the source was consumed but no k/v-pairs were found, the return value
618 * will be #CX_PROPERTIES_NO_DATA. 632 * will be #CX_PROPERTIES_NO_DATA.
633 * In case the source data ends unexpectedly, the #CX_PROPERTIES_INCOMPLETE_DATA
634 * is returned. In that case you should call this function again with the same
635 * sink and either an updated source or the same source if the source is able to
636 * yield the missing data.
637 *
619 * The other result codes apply, according to their description. 638 * The other result codes apply, according to their description.
620 * 639 *
621 * @param prop the properties interface 640 * @param prop the properties interface
622 * @param sink the sink 641 * @param sink the sink
623 * @param source the source 642 * @param source the source
624 * @retval CX_PROPERTIES_NO_ERROR (zero) a key/value pair was found 643 * @retval CX_PROPERTIES_NO_ERROR (zero) a key/value pair was found
625 * @retval CX_PROPERTIES_READ_INIT_FAILED initializing the source failed 644 * @retval CX_PROPERTIES_READ_INIT_FAILED initializing the source failed
626 * @retval CX_PROPERTIES_READ_FAILED reading from the source failed 645 * @retval CX_PROPERTIES_READ_FAILED reading from the source failed
627 * @retval CX_PROPERTIES_SINK_FAILED sinking the properties into the sink failed 646 * @retval CX_PROPERTIES_SINK_FAILED sinking the properties into the sink failed
628 * @retval CX_PROPERTIES_NO_DATA the source did not provide any key/value pairs 647 * @retval CX_PROPERTIES_NO_DATA the source did not provide any key/value pairs
648 * @retval CX_PROPERTIES_INCOMPLETE_DATA the source did not provide enough data
629 * @retval CX_PROPERTIES_INVALID_EMPTY_KEY the properties data contains an illegal empty key 649 * @retval CX_PROPERTIES_INVALID_EMPTY_KEY the properties data contains an illegal empty key
630 * @retval CX_PROPERTIES_INVALID_MISSING_DELIMITER the properties data contains a line without delimiter 650 * @retval CX_PROPERTIES_INVALID_MISSING_DELIMITER the properties data contains a line without delimiter
631 * @retval CX_PROPERTIES_BUFFER_ALLOC_FAILED an internal allocation was necessary but failed 651 * @retval CX_PROPERTIES_BUFFER_ALLOC_FAILED an internal allocation was necessary but failed
632 */ 652 */
633 cx_attr_nonnull 653 cx_attr_nonnull
654 cx_attr_export
634 CxPropertiesStatus cxPropertiesLoad( 655 CxPropertiesStatus cxPropertiesLoad(
635 CxProperties *prop, 656 CxProperties *prop,
636 CxPropertiesSink sink, 657 CxPropertiesSink sink,
637 CxPropertiesSource source 658 CxPropertiesSource source
638 ); 659 );

mercurial