cfg_parse  1.0
Simple config file parser in C
cfg_parse.h
Go to the documentation of this file.
1 
11 #ifndef CFG_PARSE_H_
12 #define CFG_PARSE_H_
13 
14 #include <stddef.h>
15 
23 #define CFG_MAX_LINE 256
24 
25 /* Opaque data structure holding config in memory */
26 struct cfg_struct;
27 
28 /* Declare C-style name mangling,
29  this makes mixing with c++ compilers possible */
30 #ifdef __cplusplus
31 extern "C" {
32 #endif
33 
37 struct cfg_struct* cfg_init();
38 
42 void cfg_free(struct cfg_struct* cfg);
43 
47 int cfg_load(struct cfg_struct* cfg, const char* filename);
48 
52 int cfg_save(const struct cfg_struct* cfg, const char* filename);
53 
57 const char* cfg_get(const struct cfg_struct* cfg, const char* key);
58 
62 char** cfg_get_keys(const struct cfg_struct* cfg, size_t* count);
63 
67 void cfg_set(struct cfg_struct* cfg, const char* key, const char* value);
68 
72 void cfg_set_array(struct cfg_struct* cfg, const char* keys[], const char* values[], size_t count);
73 
77 void cfg_delete(struct cfg_struct* cfg, const char* key);
78 
82 void cfg_delete_array(struct cfg_struct* cfg, const char* keys[], size_t count);
83 
87 void cfg_prune(struct cfg_struct* cfg, const char* keys[], size_t count);
88 
89 #ifdef __cplusplus
90 }
91 #endif
92 
93 #endif
int cfg_load(struct cfg_struct *cfg, const char *filename)
Loads key=value pairs from a file into cfg_struct.
Definition: cfg_parse.c:175
int cfg_save(const struct cfg_struct *cfg, const char *filename)
Saves a cfg_struct to a file as key=value pairs.
Definition: cfg_parse.c:222
void cfg_delete(struct cfg_struct *cfg, const char *key)
Deletes a key (and associated value) from a cfg_struct.
Definition: cfg_parse.c:420
void cfg_free(struct cfg_struct *cfg)
Frees a cfg_struct.
Definition: cfg_parse.c:145
void cfg_prune(struct cfg_struct *cfg, const char *keys[], size_t count)
Deletes all entries not found in keys[] from a cfg_struct.
Definition: cfg_parse.c:496
struct cfg_struct * cfg_init()
Creates a cfg_struct.
Definition: cfg_parse.c:131
void cfg_delete_array(struct cfg_struct *cfg, const char *keys[], size_t count)
Deletes multiple keys (and associated values) from a cfg_struct.
Definition: cfg_parse.c:474
char ** cfg_get_keys(const struct cfg_struct *cfg, size_t *count)
Retrieves a list of all keys in a cfg_struct.
Definition: cfg_parse.c:301
void cfg_set_array(struct cfg_struct *cfg, const char *keys[], const char *values[], size_t count)
Sets multiple key, value pairs in a cfg_struct.
Definition: cfg_parse.c:402
void cfg_set(struct cfg_struct *cfg, const char *key, const char *value)
Sets a key, value pair in a cfg_struct.
Definition: cfg_parse.c:341
const char * cfg_get(const struct cfg_struct *cfg, const char *key)
Retrieves a value from a cfg_struct for a specified key.
Definition: cfg_parse.c:262