#ifndef CFG_CONF_H
#define CFG_CONF_H
#include <stdio.h>
#include <stdlib.h>
#include <ucx/list.h>
#include <ucx/map.h>
#include <ucx/mempool.h>
#include <ucx/string.h>
#include "../util/object.h"
#ifdef __cplusplus
extern "C" {
#endif
#define OBJ_NEW(p, type) (type*)(p)->malloc((p)->pool,
sizeof(type))
#define OBJ_NEW_N(p, type) (type*)(p)->calloc((p)->pool,
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
typedef struct _cfg_line {
sstr_t line;
void *object;
int type;
} ConfigLine;
typedef int (*cfg_parse_f)(
void *, ConfigLine *, ConfigLine *,
sstr_t);
typedef struct _cfg_param {
sstr_t name;
sstr_t value;
} ConfigParam;
typedef struct _cfg_parser {
UcxAllocator *mp;
UcxList *lines;
cfg_parse_f parse;
} ConfigParser;
typedef struct _conf_tag ConfigTag;
struct _conf_tag {
ConfigLine *begin;
ConfigLine *end;
sstr_t name;
UcxList *param;
sstr_t param_str;
ConfigTag *parent;
ConfigTag *iftag;
int type_num;
};
typedef struct _conf_directive {
ConfigLine *begin;
ConfigLine *end;
sstr_t directive_type;
sstr_t value;
ConfigTag *condition;
int type_num;
} ConfigDirective;
int cfg_parse_basic_file(ConfigParser *parser,
FILE *in);
sstr_t cfg_readln(
FILE *file);
sstr_t cfg_trim_comment(
sstr_t line);
sstr_t cfg_param(
sstr_t params,
sstr_t *name,
sstr_t *value);
sstr_t cfg_param_get(UcxList *list,
sstr_t name);
ConfigDirective* cfg_parse_directive(
sstr_t line, UcxAllocator *mp);
UcxList* cfg_param_list(
sstr_t param_str, UcxAllocator *mp);
int cfg_get_directive_type_num(
sstr_t type);
int cfg_get_basic_type(
sstr_t line);
int cfg_get_line_type(
sstr_t line);
int cfg_get_tag_type(
sstr_t tag);
sstr_t cfg_get_end_tag_name(
sstr_t line);
ConfigTag* cfg_parse_begin_tag(
sstr_t line, UcxAllocator *mp);
ConfigDirective* cfg_directivelist_get(UcxList *dirs,
sstr_t name);
sstr_t cfg_directivelist_get_str(UcxList *dirs,
sstr_t name);
sstr_t cfg_directive_pstr1(ConfigDirective *dir);
void cfg_map_destr(UcxMempool *mp, UcxMap *map);
#ifdef __cplusplus
}
#endif
#endif