config.h 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. #ifndef CONFIG_FILE_H_
  2. #define CONFIG_FILE_H_
  3. #include "razer_private.h"
  4. struct config_item;
  5. struct config_section;
  6. struct config_file;
  7. struct config_item {
  8. struct config_section *section;
  9. char *name;
  10. char *value;
  11. struct config_item *next;
  12. };
  13. struct config_section {
  14. struct config_file *file;
  15. char *name;
  16. struct config_section *next;
  17. struct config_item *items;
  18. };
  19. struct config_file {
  20. char *path;
  21. struct config_section *sections;
  22. };
  23. enum {
  24. CONF_SECT_NOCASE = (1 << 0), /* Ignore case on section names. */
  25. CONF_ITEM_NOCASE = (1 << 1), /* Ignore case on item names. */
  26. CONF_VALUE_NOCASE = (1 << 2), /* Ignore case on item values (only for bool). */
  27. CONF_NOCASE = CONF_SECT_NOCASE | CONF_ITEM_NOCASE | CONF_VALUE_NOCASE,
  28. };
  29. void config_for_each_item(struct config_file *f,
  30. void *context, void *data,
  31. const char *section,
  32. bool (*func)(struct config_file *f,
  33. void *context, void *data,
  34. const char *section,
  35. const char *item,
  36. const char *value));
  37. void config_for_each_section(struct config_file *f,
  38. void *context, void *data,
  39. bool (*func)(struct config_file *f,
  40. void *context, void *data,
  41. const char *section));
  42. const char * config_get(struct config_file *f,
  43. const char *section,
  44. const char *item,
  45. const char *_default,
  46. unsigned int flags);
  47. int config_get_int(struct config_file *f,
  48. const char *section,
  49. const char *item,
  50. int _default,
  51. unsigned int flags);
  52. int config_get_bool(struct config_file *f,
  53. const char *section,
  54. const char *item,
  55. int _default,
  56. unsigned int flags);
  57. struct config_file * config_file_parse(const char *path, bool ignore_enoent);
  58. void config_file_free(struct config_file *f);
  59. #endif /* CONFIG_FILE_H_ */