#ifndef __CFG_H__ #define __CFG_H__ #ifdef __cplusplus extern "C" { #endif #include "mfile.h" #ifndef __DJGPP__ #ifndef strlwr #define strlwr _strlwr #endif #ifndef stricmp #define stricmp _stricmp #endif extern char *_strlwr(char *); extern int _stricmp(char *, char *); #endif #ifndef TRUE #define TRUE 1 #define FALSE 0 #endif typedef enum NODE_TYPE { node_var = 1, node_comment, node_command, node_section, node_subsection, node_file } NODE_TYPE; typedef enum ID_TYPE { id_num = 1, id_env_var, id_sq_str, id_dq_str, id_bare_str, id_multiple_str, id_semi_comment, id_hash_comment } ID_TYPE; typedef struct CFG_NODE { NODE_TYPE typeofnode; // self explanatory??? ID_TYPE node_id; // type of entry int nested; // is section nested ?? unsigned int number; // number of entry in file char *name; // name of node. char *search_name; // name of node.used for searching char *data; // data struct CFG_NODE *parent_node; // points to section containing the entry or section struct CFG_NODE *child_node; // points to next section struct CFG_NODE *previous_node; // points to prev entry in section struct CFG_NODE *next_node; // points to next entry in section } CFG_NODE; #define set_cfg_option(cfg, opt) ({ if(cfg) (cfg)->options.opt=1; }) #define unset_cfg_option(cfg, opt) ({ if(cfg) (cfg)->options.opt=0; }) /* in the loaded file, options may be set or unset by specifing ':option' * and a space deliminated list of options to enable, or disable by adding * 'no' before the option (no space) */ typedef struct CFG_OPTIONS { int concat; // if set, multiple defined vars wil be 'strcat'ed. int simple; // if set, loader will be able to load regular .ini style cnf files. even inside sections } CFG_OPTIONS; typedef struct CFG_FILE { int dirty; char *name; mfile *mem_file; char *section_sep_character; CFG_OPTIONS options; char *section_name; CFG_NODE *list; } CFG_FILE; inline void set_section_sep_char(CFG_FILE *, char*); void close_cfg(CFG_FILE *); void set_cfg_string(CFG_FILE *, char *, char *, char *); void set_cfg_int(CFG_FILE *, char *, char *, int); void set_cfg_hex(CFG_FILE *, char *, char *, int); void set_cfg_float(CFG_FILE *, char *, char *, float ); void _set_cfg_string(CFG_FILE *, char *, char *, char *, ID_TYPE); void set_cfg_var_type(CFG_FILE *, char *, char *, ID_TYPE); void set_section(CFG_FILE *, char *); int get_cfg_int(CFG_FILE *, char *, char *, int); int get_cfg_truth(CFG_FILE *, char *, char *); int get_cfg_hex(CFG_FILE *, char *, char *, int); int read_cfg(CFG_FILE *, char *); int flush_cfg(CFG_FILE *); int write_cfg(CFG_FILE *); int save_cfg(CFG_FILE *, char *); float get_cfg_float(CFG_FILE *, char *, char *, float); char *escape_str(char *); char *unescape_str(char *); char *get_cfg_string(CFG_FILE *, char *, char *, char *); char **get_cfg_argv(CFG_FILE *, char *, char *, int *); CFG_FILE *new_cfg(void); CFG_FILE *load_cfg(char *); #ifdef __cplusplus } #endif #endif /* __CFG_H__ */