--- libaitcfg/src/parse.c 2017/06/30 08:44:44 1.17 +++ libaitcfg/src/parse.c 2018/02/25 23:53:19 1.17.2.1 @@ -3,7 +3,7 @@ * by Michael Pounov * * $Author: misho $ -* $Id: parse.c,v 1.17 2017/06/30 08:44:44 misho Exp $ +* $Id: parse.c,v 1.17.2.1 2018/02/25 23:53:19 misho Exp $ * ************************************************************************** The ELWIX and AITNET software is distributed under the following @@ -12,7 +12,7 @@ terms: All of the documentation and software included in the ELWIX and AITNET Releases is copyrighted by ELWIX - Sofia/Bulgaria -Copyright 2004 - 2017 +Copyright 2004 - 2018 by Michael Pounov . All rights reserved. Redistribution and use in source and binary forms, with or without @@ -60,6 +60,7 @@ cfgReadConfig(FILE *f, cfg_root_t * __restrict cfg) struct tagCfg *av = NULL; int flg = 0; char *psAttr, *psVal, szSection[STRSIZ] = { 0 }; + FILE *ff; if (!f || !cfg) { cfg_SetErr(EINVAL, "Invalid parameter(s)"); @@ -97,6 +98,19 @@ cfgReadConfig(FILE *f, cfg_root_t * __restrict cfg) AIT_SET_STRCAT(&av->cfg_val, line); if (!flg && AIT_ADDR(&av->cfg_val)) str_Unquot((char*) AIT_GET_STR(&av->cfg_val)); + + /* read include file */ + if (!flg && AIT_ADDR(&av->cfg_val) && + *AIT_GET_STR(&av->cfg_attr) == '%' && + !strcmp(AIT_GET_STR(&av->cfg_attr), "%include")) { + ff = fopen(AIT_GET_STR(&av->cfg_val), "r"); + if (ff) { + cfgReadConfig(ff, cfg); + fclose(ff); + } else + EDEBUG(7, "Error:: Can't open %s file", + AIT_GET_STR(&av->cfg_val)); + } continue; } @@ -112,6 +126,12 @@ cfgReadConfig(FILE *f, cfg_root_t * __restrict cfg) CFG_RC_UNLOCK(cfg); } + /* check for comment or empty line */ + if (!*line || *line == '#' || *line == ';') { + AIT_SET_STR(&av->cfg_val, line); + continue; + } + /* check for continues line */ psAttr = line + (*line ? strlen(line) : 1) - 1; if (*psAttr == '\\') { @@ -119,11 +139,6 @@ cfgReadConfig(FILE *f, cfg_root_t * __restrict cfg) flg = 1; } - /* check for comment or empty line */ - if (!*line || *line == '#' || *line == ';') { - AIT_SET_STR(&av->cfg_val, line); - continue; - } /* section */ if (*line == '[') { psAttr = line + strlen(line) - 1; @@ -166,6 +181,18 @@ cfgReadConfig(FILE *f, cfg_root_t * __restrict cfg) CFG_RC_LOCK(cfg); RB_INSERT(tagRC, cfg, av); CFG_RC_UNLOCK(cfg); + + /* read include file */ + if (!flg && *AIT_GET_STR(&av->cfg_attr) == '%' && + !strcmp(AIT_GET_STR(&av->cfg_attr), "%include")) { + ff = fopen(AIT_GET_STR(&av->cfg_val), "r"); + if (ff) { + cfgReadConfig(ff, cfg); + fclose(ff); + } else + EDEBUG(7, "Error:: Can't open %s file", + AIT_GET_STR(&av->cfg_val)); + } } return 0;