#ifndef CFG_CONF_H
#define CFG_CONF_H
#include <stdio.h>
#include <stdlib.h>
#include <cx/linked_list.h>
#include <cx/hash_map.h>
#include <cx/mempool.h>
#include <cx/string.h>
#include <cx/utils.h>
#include <cx/compare.h>
#include "../util/object.h"
#ifdef __cplusplus
extern "C" {
#endif
#define OBJ_NEW(p, type) (type*)cxMalloc(p,
sizeof(type))
#define OBJ_NEW_N(p, type) (type*)cxCalloc(p,
1,
sizeof(type))
#define LINE_OTHER 0
#define LINE_DIRECTIVE 1
#define LINE_BEGIN_TAG 2
#define LINE_END_TAG 3
#define LINE_MULTI 4
#define LINE_NOCONTENT 5
#define LINE_ERROR 6
#define TAG_OBJECT 0
#define TAG_IF 1
#define TAG_ELSEIF 2
#define TAG_ELSE 3
#define TAG_CLIENT 4
#define INIT_DIRECTIVE 16
#define CFG_LINE_ADD(list_begin, list_end, elm) \
cx_linked_list_add((
void**)list_begin, (
void**)list_end, offsetof(ConfigLineList, prev), offsetof(ConfigLineList, next), elm)
#define CFG_PARAM_ADD(list_begin, list_end, elm) \
cx_linked_list_add((
void**)list_begin, (
void**)list_end, -
1, offsetof(ConfigParam, next), elm)
#define CFG_DIRECTIVES_ADD(list, dir) \
cx_linked_list_add((
void**)list,
NULL, -
1, offsetof(ConfigDirectiveList, next), dir)
#define CFG_NUM_PARAMS(param) cx_linked_list_size(param, offsetof(ConfigParam, next))
typedef struct _cfg_line {
cxmutstr line;
void *object;
int type;
} ConfigLine;
typedef int (*cfg_parse_f)(
void *, ConfigLine *, ConfigLine *, cxmutstr);
typedef struct _cfg_param ConfigParam;
struct _cfg_param {
cxmutstr name;
cxmutstr value;
ConfigParam *next;
};
typedef struct ConfigLineList ConfigLineList;
struct ConfigLineList {
ConfigLine *line;
ConfigLineList *prev;
ConfigLineList *next;
};
typedef struct _cfg_parser {
CxAllocator *mp;
ConfigLineList *lines_begin;
ConfigLineList *lines_end;
cfg_parse_f parse;
} ConfigParser;
typedef struct _conf_tag ConfigTag;
struct _conf_tag {
ConfigLine *begin;
ConfigLine *end;
cxmutstr name;
ConfigParam *param;
cxmutstr param_str;
ConfigTag *parent;
ConfigTag *iftag;
int type_num;
};
typedef struct _conf_directive {
ConfigLine *begin;
ConfigLine *end;
cxmutstr directive_type;
cxmutstr value;
ConfigTag *condition;
int type_num;
} ConfigDirective;
typedef struct ConfigDirectiveList ConfigDirectiveList;
struct ConfigDirectiveList {
ConfigDirective *directive;
ConfigDirectiveList *next;
};
int cfg_parse_basic_file(ConfigParser *parser,
FILE *in);
cxmutstr cfg_readln(
FILE *file);
cxmutstr cfg_trim_comment(cxmutstr line);
cxmutstr cfg_param(cxmutstr params, cxmutstr *name, cxmutstr *value);
cxmutstr cfg_param_get(ConfigParam *list, cxstring name);
ConfigDirective* cfg_parse_directive(cxmutstr line, CxAllocator *mp);
ConfigParam* cfg_param_list(cxmutstr param_str, CxAllocator *mp);
int cfg_get_directive_type_num(cxstring type);
int cfg_get_basic_type(cxmutstr line);
int cfg_get_line_type(cxmutstr line);
int cfg_get_tag_type(cxstring tag);
cxmutstr cfg_get_end_tag_name(cxmutstr line);
ConfigTag* cfg_parse_begin_tag(cxmutstr line, CxAllocator *mp);
cxmutstr cfg_directive_pstr1(ConfigDirective *dir);
#ifdef __cplusplus
}
#endif
#endif