conf: split line parsing from CNF_ReadFile

This commit is contained in:
Miroslav Lichvar 2014-04-09 12:36:13 +02:00
parent 70feea48f8
commit 7c7ab95e2e
2 changed files with 148 additions and 145 deletions

40
conf.c
View file

@ -305,31 +305,39 @@ CNF_ReadFile(const char *filename)
{ {
FILE *in; FILE *in;
char line[2048]; char line[2048];
char *p, *command; int i;
const char *prev_processed_file;
int prev_line_number;
in = fopen(filename, "r"); in = fopen(filename, "r");
if (!in) { if (!in) {
LOG_FATAL(LOGF_Configure, "Could not open configuration file %s", filename); LOG_FATAL(LOGF_Configure, "Could not open configuration file %s", filename);
} else { return;
/* Save current line number in case this is an included file */ }
prev_line_number = line_number;
prev_processed_file = processed_file;
line_number = 0; for (i = 1; fgets(line, sizeof(line), in); i++) {
CNF_ParseLine(filename, i, line);
}
fclose(in);
}
/* ================================================== */
/* Parse one configuration line */
void
CNF_ParseLine(const char *filename, int number, char *line)
{
char *p, *command;
/* Set global variables used in error messages */
processed_file = filename; processed_file = filename;
line_number = number;
/* Success */
while (fgets(line, sizeof(line), in)) {
line_number++;
/* Remove extra white-space and comments */ /* Remove extra white-space and comments */
CPS_NormalizeLine(line); CPS_NormalizeLine(line);
/* Skip blank lines */ /* Skip blank lines */
if (!*line) if (!*line)
continue; return;
/* We have a real line, now try to match commands */ /* We have a real line, now try to match commands */
processed_command = command = line; processed_command = command = line;
@ -452,12 +460,6 @@ CNF_ReadFile(const char *filename)
} }
} }
line_number = prev_line_number;
processed_file = prev_processed_file;
fclose(in);
}
}
/* ================================================== */ /* ================================================== */
static int static int

1
conf.h
View file

@ -34,6 +34,7 @@ extern void CNF_SetRestarted(int);
extern char *CNF_GetRtcDevice(void); extern char *CNF_GetRtcDevice(void);
extern void CNF_ReadFile(const char *filename); extern void CNF_ReadFile(const char *filename);
extern void CNF_ParseLine(const char *filename, int number, char *line);
extern void CNF_AddInitSources(void); extern void CNF_AddInitSources(void);
extern void CNF_AddSources(void); extern void CNF_AddSources(void);