Skip to content
Permalink
Browse files Browse the repository at this point in the history
Hide errored line content during parsing configuration INI file on de…
…fault
  • Loading branch information
ziajka committed May 8, 2019
1 parent 94cbf67 commit 2eb0d1d
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 7 deletions.
18 changes: 13 additions & 5 deletions src/iniparser/iniparser.c
Expand Up @@ -626,7 +626,7 @@ static line_status iniparser_line(
The returned dictionary must be freed using iniparser_freedict().
*/
/*--------------------------------------------------------------------------*/
dictionary * iniparser_load(const char * ininame)
dictionary * iniparser_load(const char * ininame, load_options options)
{
FILE * in ;

Expand Down Expand Up @@ -707,10 +707,18 @@ dictionary * iniparser_load(const char * ininame)
break ;

case LINE_ERROR:
fprintf(stderr, "iniparser: syntax error in %s (%d):\n",
ininame,
lineno);
fprintf(stderr, "-> %s\n", line);

if(options & HIDE_ERRORED_LINE_CONTENT) {
fprintf(stderr, "iniparser: syntax error in %s (%d)\n",
ininame,
lineno);
}
else {
fprintf(stderr, "iniparser: syntax error in %s (%d):\n",
ininame,
lineno);
fprintf(stderr, "-> %s\n", line);
}
errs++ ;
break;

Expand Down
7 changes: 6 additions & 1 deletion src/iniparser/iniparser.h
Expand Up @@ -31,6 +31,10 @@
extern "C" {
#endif

typedef enum {
HIDE_ERRORED_LINE_CONTENT = (1<<0)
} load_options;

/*-------------------------------------------------------------------------*/
/**
@brief Get number of sections in a dictionary
Expand Down Expand Up @@ -286,6 +290,7 @@ int iniparser_find_entry(const dictionary * ini, const char * entry) ;
/**
@brief Parse an ini file and return an allocated dictionary object
@param ininame Name of the ini file to read.
@param options Name of the ini file to read.
@return Pointer to newly allocated dictionary
This is the parser for ini files. This function is called, providing
Expand All @@ -296,7 +301,7 @@ int iniparser_find_entry(const dictionary * ini, const char * entry) ;
The returned dictionary must be freed using iniparser_freedict().
*/
/*--------------------------------------------------------------------------*/
dictionary * iniparser_load(const char * ininame);
dictionary * iniparser_load(const char * ininame, load_options options);

/*-------------------------------------------------------------------------*/
/**
Expand Down
2 changes: 1 addition & 1 deletion src/parse.c
Expand Up @@ -186,7 +186,7 @@ int parse_config(char *filename, bridge_t **bridges)
const char *bridge_name;
int i, nsec;

if ((ubridge_config = iniparser_load(filename)) == NULL) {
if ((ubridge_config = iniparser_load(filename, HIDE_ERRORED_LINE_CONTENT)) == NULL) {
return FALSE;
}

Expand Down

0 comments on commit 2eb0d1d

Please sign in to comment.