version 1.10.2.1, 2012/08/06 15:08:26
|
version 1.10.2.2, 2012/08/30 13:49:44
|
Line 363 cfgReadLines(FILE *f, const char *delim, const char *e
|
Line 363 cfgReadLines(FILE *f, const char *delim, const char *e
|
struct tagCfg *d, *av = NULL; |
struct tagCfg *d, *av = NULL; |
char *psAttr, *psVal = NULL; |
char *psAttr, *psVal = NULL; |
|
|
|
if (!cfg) |
|
return -1; |
|
if (!delim) |
|
delim = ATR_LINES_DELIM; |
|
|
while (!feof(f)) { |
while (!feof(f)) { |
memset(line, 0, sizeof line); |
memset(line, 0, sizeof line); |
fgets(line, sizeof line - 1, f); |
fgets(line, sizeof line - 1, f); |
Line 421 cfgReadLines(FILE *f, const char *delim, const char *e
|
Line 426 cfgReadLines(FILE *f, const char *delim, const char *e
|
return 0; |
return 0; |
} |
} |
|
|
|
/* |
|
* cfgWriteLines() - Write custom lines and export data to variable |
|
* |
|
* @f = File resource |
|
* @delim = Custom delimiter, if =NULL default is '=' |
|
* @eol = End of line string, if =NULL default is "\n" |
|
* @section = Export only section, if =NULL default is all |
|
* @cfg = Config root |
|
* return: =NULL error or !=NULL exported data, must be free after use with io_freeVar() |
|
*/ |
|
ait_val_t * |
|
cfgWriteLines(FILE *f, const char *delim, const char *eol, const char *section, cfg_root_t * __restrict cfg) |
|
{ |
|
ait_val_t *v = NULL; |
|
struct tagCfg *av; |
|
|
|
if (!cfg) |
|
return NULL; |
|
if (!delim) |
|
delim = ATR_LINES_DELIM; |
|
if (!eol) |
|
eol = EOL_LINES_DELIM; |
|
if (!(v = io_allocVar())) { |
|
cfg_SetErr(io_GetErrno(), "%s", io_GetError()); |
|
return NULL; |
|
} else |
|
AIT_INIT_VAL2(v, string); |
|
|
|
SLIST_FOREACH(av, cfg, cfg_next) { |
|
if (AIT_ISEMPTY(&av->cfg_attr)) |
|
continue; |
|
if (section) { |
|
if (!AIT_ISEMPTY(&av->cfg_sec) && *section) |
|
continue; |
|
if (strcmp(section, AIT_GET_STR(&av->cfg_sec))) |
|
continue; |
|
} |
|
|
|
if (!AIT_ISEMPTY(&av->cfg_sec)) { |
|
AIT_SET_STRCAT(v, AIT_GET_STR(&av->cfg_sec)); |
|
AIT_SET_STRCAT(v, SEC_LINES_DELIM); |
|
} |
|
AIT_SET_STRCAT(v, AIT_GET_STR(&av->cfg_attr)); |
|
AIT_SET_STRCAT(v, delim); |
|
if (!AIT_ISEMPTY(&av->cfg_val)) |
|
AIT_SET_STRCAT(v, AIT_GET_STR(&av->cfg_val)); |
|
AIT_SET_STRCAT(v, eol); |
|
} |
|
|
|
if (f) |
|
fputs(AIT_GET_STR(v), f); |
|
return v; |
|
} |