12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455 |
- #ifndef CONFIG_H
- #define CONFIG_H
- #ifdef __linux__
- #include <stdio.h>
- #include <stdlib.h>
- #include <stdint.h>
- #include <string.h>
- #define OPT_TYPE_ERROR 0
- #define OPT_TYPE_INT 1
- #define OPT_TYPE_FLOAT 2
- #define OPT_TYPE_STRING 3
- union opt_value
- {
- int _int;
- double _float;
- char* _string;
- };
- typedef struct
- {
- char name[64];
- int type;
- union opt_value val;
- } opt_t;
- typedef struct
- {
- opt_t opts[128];
- int n;
- int line;
- int c;
- } config_t;
- void config_init(config_t *cfg, const char* path);
- void config_add_int(config_t* cfg, const char* name, int val);
- void config_add_float(config_t* cfg, const char* name, double val);
- void config_add_string(config_t* cfg, const char* name, const char* val);
- void config_add(config_t* cfg, const char* name, int type, union opt_value val);
- const char* config_get_string(config_t* cfg, const char* name);
- int config_get_int(config_t* cfg, const char* name);
- double config_get_float(config_t* cfg, const char* name);
- int config_get_type(config_t* cfg, const char* name);
- void config_free(config_t *cfg);
- void config_print(config_t *cfg);
- #endif
- #endif
|