Nilorea Library
C utilities for networking, threading, graphics
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{
14#endif
15
16#include "n_hash.h"
17#include "n_str.h"
18#include "n_log.h"
19
20
27#define MAX_CONFIG_LINE_LEN 1024
29#define CONFIG_SECTION_HASH_TABLE_LEN 16
30
32typedef struct CONFIG_FILE_SECTION
33{
34 char *section_name ;
35 HASH_TABLE *entries ;
37
38
40typedef struct CONFIG_FILE
41{
42 char *filename ;
43 LIST *sections ;
45
46/* load a config from a file */
47CONFIG_FILE *load_config_file( char *filename, int *errors);
48/* write file from config */
49int write_config_file( CONFIG_FILE *cfg_file, char *filename );
50/* get a loaded config value */
51char *get_config_section_value( CONFIG_FILE *cfg_file, char *section_name, int section_position, char *entry, int entry_position );
52/* get the number of section for section name */
53int get_nb_config_file_sections( CONFIG_FILE *cfg_file, char *section_name );
54/* get the number of entries for section_name/entry */
55int get_nb_config_file_sections_entries( CONFIG_FILE *cfg_file, char *section_name, int section_position, char *entry );
56/* destroy a loaded config */
57int destroy_config_file( CONFIG_FILE **cfg_file );
58
60#define config_foreach( __config , __section_name , __key , __val ) \
61 if( !__config || !__config -> sections ) \
62 { \
63 n_log( LOG_ERR , "No config file for %s" , #__config ); \
64 } \
65 else \
66 { \
67 list_foreach( listnode , __config -> sections ) \
68 { \
69 CONFIG_FILE_SECTION *__section = (CONFIG_FILE_SECTION *)listnode -> ptr ; \
70 __section_name = __section -> section_name ; \
71 ht_foreach( entry , __section -> entries ) \
72 { \
73 HASH_NODE *htnode = (HASH_NODE *)entry -> ptr ; \
74 if( htnode && htnode -> data . ptr ) \
75 { \
76 __key = htnode -> key ; \
77 __val = htnode -> data . ptr ;
78
80#define config_endfor \
81 } \
82 } \
83 } \
84 }
85
90#ifdef __cplusplus
91}
92#endif
93
94#endif /* #ifndef __N_CONFIG_FILE__ */
95
CONFIG_FILE * load_config_file(char *filename, int *errors)
load a config file
Definition: n_config_file.c:51
int write_config_file(CONFIG_FILE *cfg_file, char *filename)
write a config file
char * get_config_section_value(CONFIG_FILE *cfg_file, char *section_name, int section_position, char *entry, int entry_position)
Function to parse sections and get entries values.
int destroy_config_file(CONFIG_FILE **cfg_file)
Destroy a loaded config file.
int get_nb_config_file_sections(CONFIG_FILE *cfg_file, char *section_name)
Get the number of config file with section_name.
int get_nb_config_file_sections_entries(CONFIG_FILE *cfg_file, char *section_name, int section_position, char *entry)
Get the number of config file with section_name.
Structure of a config file.
Definition: n_config_file.h:41
Structure of a config section.
Definition: n_config_file.h:33
structure of a hash table
Definition: n_hash.h:109
Structure of a generic LIST container.
Definition: n_list.h:45
Hash functions and table.
Generic log system.
N_STR and string function declaration.