conf.h 1.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. #ifndef CONFIG_FILE_H_
  2. #define CONFIG_FILE_H_
  3. #define CONF_HASHTAB_BITS 5
  4. #define CONF_HASHTAB_SIZE (1 << CONF_HASHTAB_BITS)
  5. #define CONF_HASHTAB_MASK (CONF_HASHTAB_SIZE - 1)
  6. struct config_item;
  7. struct config_section;
  8. struct config_file;
  9. struct config_item {
  10. struct config_section *section;
  11. char *name;
  12. char *value;
  13. struct config_item *next;
  14. };
  15. struct config_section {
  16. struct config_file *file;
  17. char *name;
  18. struct config_item *item_hashtab[CONF_HASHTAB_SIZE];
  19. struct config_section *next;
  20. };
  21. struct config_file {
  22. struct config_section *section_hashtab[CONF_HASHTAB_SIZE];
  23. };
  24. const char * config_get(struct config_file *f,
  25. const char *section,
  26. const char *item,
  27. const char *_default);
  28. int config_get_int(struct config_file *f,
  29. const char *section,
  30. const char *item,
  31. int _default);
  32. int config_get_bool(struct config_file *f,
  33. const char *section,
  34. const char *item,
  35. int _default);
  36. struct config_file * config_file_parse(const char *path);
  37. void config_file_free(struct config_file *f);
  38. #endif /* CONFIG_FILE_H_ */