Various modules solving daily C developer tasks
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

73 lines
1.4 KiB

  1. /******************************************************************************
  2. *
  3. * Copyright (c) 2017-2019 by Löwenware Ltd
  4. * Please, refer LICENSE file for legal information
  5. *
  6. ******************************************************************************/
  7. /**
  8. * @file config.h
  9. * @author Ilja Kartašov <ik@lowenware.com>
  10. * @brief
  11. *
  12. * @see https://lowenware.com/
  13. */
  14. #include "retcode.h"
  15. #ifndef CSTUFF_CONFIG_H_6207A85E_26F1_4B64_818F_92C6286FC5F0
  16. #define CSTUFF_CONFIG_H_6207A85E_26F1_4B64_818F_92C6286FC5F0
  17. #ifndef CSTUFF_CONFIG_PATH_SIZE
  18. #define CSTUFF_CONFIG_PATH_SIZE 64
  19. #endif
  20. typedef enum {
  21. CSTUFF_CONFIG_NONE
  22. , CSTUFF_CONFIG_NODE
  23. , CSTUFF_CONFIG_PAIR
  24. , CSTUFF_CONFIG_ERROR
  25. } CStuffConfigEvent;
  26. struct cstuff_config_node {
  27. const char *name;
  28. int name_len;
  29. };
  30. struct cstuff_config_pair {
  31. const char *key;
  32. const char *val;
  33. int key_len;
  34. int val_len;
  35. };
  36. struct cstuff_config_error {
  37. const char *line_txt;
  38. const char *err_txt;
  39. int char_num;
  40. };
  41. struct cstuff_config {
  42. CStuffConfigEvent evt;
  43. int line_num;
  44. union {
  45. struct cstuff_config_node node;
  46. struct cstuff_config_pair pair;
  47. struct cstuff_config_error error;
  48. } data;
  49. };
  50. typedef struct cstuff_config * CStuffConfig;
  51. typedef int
  52. (* CStuffConfigCallback)(struct cstuff_config *config, void *u_ptr);
  53. CStuffRetcode
  54. cstuff_config_parse(const char *file, CStuffConfigCallback callback, void *u_ptr);
  55. #endif /* !CSTUFF_CONFIG_H */