-
/*-------------------------------------------------------------------------*/
/**
@file iniparser.c
/*-------------------------------------------------------------------------*/
/**
- @brief Remove blanks at the beginning and the end of a string.
- @param s String to parse.
- @return ptr to statically allocated string.
+ @brief Remove blanks at the beginning and the end of a string.
+ @param s String to parse.
+ @return ptr to statically allocated string.
This function returns a pointer to a statically allocated string,
which is identical to the input string, except that all blank
static char * strstrip(char * s)
{
static char l[ASCIILINESZ+1];
- char * last ;
-
+ char * last ;
+
if (s==NULL) return NULL ;
-
- while (isspace((int)*s) && *s) s++;
- memset(l, 0, ASCIILINESZ+1);
- strcpy(l, s);
- last = l + strlen(l);
- while (last > l) {
- if (!isspace((int)*(last-1)))
- break ;
- last -- ;
- }
- *last = (char)0;
- return (char*)l ;
+
+ while (isspace((int)*s) && *s) s++;
+ memset(l, 0, ASCIILINESZ+1);
+ strcpy(l, s);
+ last = l + strlen(l);
+ while (last > l) {
+ if (!isspace((int)*(last-1)))
+ break ;
+ last -- ;
+ }
+ *last = (char)0;
+ return (char*)l ;
}
/*-------------------------------------------------------------------------*/
/*-------------------------------------------------------------------------*/
/**
- @brief Load a single line from an INI file
+ @brief Load a single line from an INI file
@param input_line Input line, may be concatenated multi-line input
@param section Output space to store section
@param key Output space to store key
char * section,
char * key,
char * value)
-{
+{
line_status sta ;
char line[ASCIILINESZ+1];
int len ;
sta = LINE_EMPTY ;
} else if (line[0]=='#' || line[0]==';') {
/* Comment line */
- sta = LINE_COMMENT ;
+ sta = LINE_COMMENT ;
} else if (line[0]=='[' && line[len-1]==']') {
/* Section name */
sscanf(line, "[%[^]]", section);
dictionary * dict ;
if ((inifile=fopen(ininame, "r"))==NULL) {
- LOG(logtype_default, log_error, "iniparser: cannot open \"%s\"", ininame);
+ LOG(log_error, logtype_default, "iniparser: cannot open \"%s\"", ininame);
return NULL ;
}
continue;
/* Safety check against buffer overflows */
if (line[len]!='\n') {
- LOG(logtype_default, log_error, "iniparser: input line too long in \"%s\" (lineno: %d)",
+ LOG(log_error, logtype_default, "iniparser: input line too long in \"%s\" (lineno: %d)",
ininame, lineno);
dictionary_del(dict);
fclose(in);
case LINE_VALUE:
if (strcmp(key, "include") == 0) {
if ((include = fopen(val, "r")) == NULL) {
- LOG(logtype_default, log_error, "iniparser: cannot open \"%s\"", val);
+ LOG(log_error, logtype_default, "iniparser: cannot open \"%s\"", val);
continue;
}
in = include;
errs = dictionary_set(dict, section, key, val) ;
break ;
case LINE_ERROR:
- LOG(logtype_default, log_error, "iniparser: syntax error in %s (lineno: %d): %s",
+ LOG(log_error, logtype_default, "iniparser: syntax error in %s (lineno: %d): %s",
ininame, lineno, line);
errs++ ;
break;
memset(line, 0, ASCIILINESZ);
last=0;
if (errs<0) {
- LOG(logtype_default, log_error, "iniparser: memory allocation failure");
+ LOG(log_error, logtype_default, "iniparser: memory allocation failure");
break ;
}
}