Nilorea Library
C utilities for networking, threading, graphics
Loading...
Searching...
No Matches
n_config_file.h
Go to the documentation of this file.
1
9#ifndef __N_CONFIG_FILE__
10#define __N_CONFIG_FILE__
11
12#ifdef __cplusplus
13extern "C" {
14#endif
15
16#include "n_hash.h"
17#include "n_str.h"
18#include "n_log.h"
19
26#define MAX_CONFIG_LINE_LEN 1024
28#define CONFIG_SECTION_HASH_TABLE_LEN 16
29
35
37typedef struct CONFIG_FILE {
38 char* filename;
41
42/* load a config from a file */
43CONFIG_FILE* load_config_file(char* filename, int* errors);
44/* write file from config */
45int write_config_file(CONFIG_FILE* cfg_file, char* filename);
46/* get a loaded config value */
47char* get_config_section_value(CONFIG_FILE* cfg_file, char* section_name, size_t section_position, char* entry, size_t entry_position);
48/* get the number of section for section name */
49size_t get_nb_config_file_sections(CONFIG_FILE* cfg_file, char* section_name);
50/* get the number of entries for section_name/entry */
51size_t get_nb_config_file_sections_entries(CONFIG_FILE* cfg_file, char* section_name, size_t section_position, char* entry);
52/* destroy a loaded config */
53int destroy_config_file(CONFIG_FILE** cfg_file);
54
56#define config_foreach(__config, __section_name, __key, __val) \
57 if (!__config || !__config->sections) { \
58 n_log(LOG_ERR, "No config file for %s", #__config); \
59 } else { \
60 list_foreach(listnode, __config->sections) { \
61 CONFIG_FILE_SECTION* __section = (CONFIG_FILE_SECTION*)listnode->ptr; \
62 __section_name = __section->section_name; \
63 ht_foreach(entry, __section->entries) { \
64 HASH_NODE* htnode = (HASH_NODE*)entry->ptr; \
65 if (htnode && htnode->data.ptr) { \
66 __key = htnode->key; \
67 __val = htnode->data.ptr;
68
70#define config_endfor \
71 } \
72 } \
73 } \
74 }
75
80#ifdef __cplusplus
81}
82#endif
83
84#endif /* #ifndef __N_CONFIG_FILE__ */
HASH_TABLE * entries
char * filename
LIST * sections
CONFIG_FILE * load_config_file(char *filename, int *errors)
load a config file
int write_config_file(CONFIG_FILE *cfg_file, char *filename)
write a config file
size_t get_nb_config_file_sections_entries(CONFIG_FILE *cfg_file, char *section_name, size_t section_position, char *entry)
Get the number of config file with section_name.
int destroy_config_file(CONFIG_FILE **cfg_file)
Destroy a loaded config file.
char * get_config_section_value(CONFIG_FILE *cfg_file, char *section_name, size_t section_position, char *entry, size_t entry_position)
Function to parse sections and get entries values.
size_t get_nb_config_file_sections(CONFIG_FILE *cfg_file, char *section_name)
Get the number of config file with section_name.
Structure of a config file.
Structure of a config section.
structure of a hash table
Definition n_hash.h:117
Structure of a generic LIST container.
Definition n_list.h:40
Hash functions and table.
Generic log system.
N_STR and string function declaration.