more work on config parser
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* parseconf
|
||||
* core/parseconf.c
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
@@ -10,12 +10,14 @@
|
||||
extern int verbosity;
|
||||
extern Configuration config;
|
||||
|
||||
#define CMP(a) (!strcmp(cptr, a))
|
||||
|
||||
/* ---------------------------------------------------------------- */
|
||||
int parse_config(char *fname, int flags)
|
||||
{
|
||||
FILE *fp;
|
||||
char line[SZ_STRINGS+1];
|
||||
|
||||
char line[SZ_STRINGS+1], *cptr;
|
||||
int numligne;
|
||||
|
||||
#if DEBUG_LEVEL
|
||||
fprintf(stderr, ">>> %s ( '%s' $%x )\n", fname, flags);
|
||||
@@ -28,19 +30,39 @@ if (NULL==(fp=fopen(fname, "r"))) {
|
||||
return -2;
|
||||
}
|
||||
|
||||
numligne = 0;
|
||||
|
||||
while (fgets(line, SZ_STRINGS, fp))
|
||||
{
|
||||
numligne++;
|
||||
if ('\0'==line[0]) {
|
||||
fprintf(stderr, "%s : short read line %d\n",
|
||||
fname, numligne);
|
||||
fclose(fp);
|
||||
return -1;
|
||||
}
|
||||
|
||||
/* massage the end of line */
|
||||
line[strlen(line)-1] = '\0'; /* kill EOL */
|
||||
if (verbosity) {
|
||||
fprintf(stderr, "%3d :\t%s\n", numligne, line);
|
||||
}
|
||||
|
||||
/* seek for the first token in this line */
|
||||
if (NULL==(cptr = strtok(line, " \t"))) {
|
||||
/* Got an empty line */
|
||||
continue;
|
||||
}
|
||||
|
||||
/* skip comments */
|
||||
if ('#'==*cptr) continue;
|
||||
|
||||
if(verbosity) fprintf(stderr, "[%s]\n", cptr);
|
||||
|
||||
/* seek for keyword */
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
fclose(fp);
|
||||
|
||||
return -1;
|
||||
|
||||
Reference in New Issue
Block a user