config.h 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. #ifndef CONFIG_H
  2. #define CONFIG_H
  3. #ifdef __linux__
  4. #include <stdio.h>
  5. #include <stdlib.h>
  6. #include <stdint.h>
  7. #include <string.h>
  8. #define OPT_TYPE_ERROR 0
  9. #define OPT_TYPE_INT 1
  10. #define OPT_TYPE_FLOAT 2
  11. #define OPT_TYPE_STRING 3
  12. union opt_value
  13. {
  14. int _int;
  15. double _float;
  16. char* _string;
  17. };
  18. typedef struct
  19. {
  20. char name[64];
  21. int type;
  22. union opt_value val;
  23. } opt_t;
  24. typedef struct
  25. {
  26. opt_t opts[128];
  27. int n;
  28. int line;
  29. int c;
  30. } config_t;
  31. void config_init(config_t *cfg, const char* path);
  32. void config_add_int(config_t* cfg, const char* name, int val);
  33. void config_add_float(config_t* cfg, const char* name, double val);
  34. void config_add_string(config_t* cfg, const char* name, const char* val);
  35. void config_add(config_t* cfg, const char* name, int type, union opt_value val);
  36. const char* config_get_string(config_t* cfg, const char* name);
  37. int config_get_int(config_t* cfg, const char* name);
  38. double config_get_float(config_t* cfg, const char* name);
  39. int config_get_type(config_t* cfg, const char* name);
  40. void config_free(config_t *cfg);
  41. void config_print(config_t *cfg);
  42. #endif
  43. #endif