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