diff -aru parsecfg-3.6.7/src/parsecfg.c parsecfg-pb/src/parsecfg.c --- parsecfg-3.6.7/src/parsecfg.c Wed Jun 27 17:16:24 2001 +++ parsecfg-pb/src/parsecfg.c Wed Feb 6 17:20:17 2002 @@ -20,7 +20,7 @@ /* */ /**************************************************************************/ -/* $Id: parsecfg.c,v 1.15 2001/06/27 15:24:00 gm Exp $ */ +/* $Id: parsecfg.c,v 1.3 2002/02/05 13:50:16 padraig Exp $ */ #ifdef HAVE_CONFIG_H # include "config.h" @@ -46,6 +46,7 @@ static int store_value(cfgStruct cfg[], const char *parameter, const char *value, cfgFileType type, int section); static int parse_ini(const char *file, FILE *fp, char *ptr, cfgStruct cfg[], int *line, int *section); static int alloc_for_new_section(cfgStruct cfg[], int *section); +static void dealloc_for_sections(void); static char *get_single_line_without_first_spaces(FILE *fp, char **gotstr, int *line); static char *rm_first_spaces(char *ptr); @@ -108,6 +109,9 @@ return (-1); } + if (type == CFG_INI) + dealloc_for_sections(); + while ((ptr = get_single_line_without_first_spaces(fp, &line_buf, &line)) != NULL) { switch (type) { case CFG_SIMPLE: @@ -311,6 +315,103 @@ return (0); } +/* -------------------------------------------------- + NAME cfgStrError + FUNCTION convertparsecfg error number to string + INPUT cfgErrorCode .. errorcode + OUTPUT pointer to non modifiable error string + -------------------------------------------------- */ +/* TODO: Need to apply I18N to this */ +const char* cfgStrError(cfgErrorCode error_code) +{ + const char* retMsg="Unknown error"; + + switch (error_code) { + case CFG_OPEN_FAIL: + retMsg="Cannot open configuration file"; + break; + case CFG_CREATE_FAIL: + retMsg="Cannot create configuration file"; + break; + case CFG_SYNTAX_ERROR: + retMsg="Syntax error"; + break; + case CFG_WRONG_PARAMETER: + retMsg="Unrecognized parameter"; + break; + case CFG_INTERNAL_ERROR: + retMsg="Internal error"; + break; + case CFG_INVALID_NUMBER: + retMsg="Invalid number"; + break; + case CFG_OUT_OF_RANGE: + retMsg="Out of range"; + break; + case CFG_MEM_ALLOC_FAIL: + retMsg="Cannot allocate memory"; + break; + case CFG_BOOL_ERROR: + retMsg="It must be specified TRUE or FALSE"; + break; + case CFG_USED_SECTION: + retMsg="The section name is already used"; + break; + case CFG_NO_CLOSING_BRACE: + retMsg="There is no closing brace"; + break; + case CFG_JUST_RETURN_WITHOUT_MSG: + retMsg="Unspecified error"; + break; + default: + break; + } + + return retMsg; +} + +/* -------------------------------------------------- + NAME cfgFree + FUNCTION store the value according to cfg + INPUT cfg .......... array of possible variables + type ......... type of the configuration file + numSections .. Number of sections (1,2,...) + OUTPUT void + -------------------------------------------------- */ +void cfgFree(cfgStruct cfg[], cfgFileType type, int numSections) +{ + int num, section; + char* freeString; + char* freeStrings; + + switch(type) { + case CFG_INI: + for (num = 0; cfg[num].type != CFG_END; num++) { + freeStrings=*((char**) (cfg[num].value)); + if (freeStrings) { + for (section=0; section