conf: split line parsing from CNF_ReadFile
This commit is contained in:
parent
70feea48f8
commit
7c7ab95e2e
2 changed files with 148 additions and 145 deletions
40
conf.c
40
conf.c
|
@ -305,31 +305,39 @@ CNF_ReadFile(const char *filename)
|
|||
{
|
||||
FILE *in;
|
||||
char line[2048];
|
||||
char *p, *command;
|
||||
const char *prev_processed_file;
|
||||
int prev_line_number;
|
||||
int i;
|
||||
|
||||
in = fopen(filename, "r");
|
||||
if (!in) {
|
||||
LOG_FATAL(LOGF_Configure, "Could not open configuration file %s", filename);
|
||||
} else {
|
||||
/* Save current line number in case this is an included file */
|
||||
prev_line_number = line_number;
|
||||
prev_processed_file = processed_file;
|
||||
return;
|
||||
}
|
||||
|
||||
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;
|
||||
|
||||
/* Success */
|
||||
while (fgets(line, sizeof(line), in)) {
|
||||
line_number++;
|
||||
line_number = number;
|
||||
|
||||
/* Remove extra white-space and comments */
|
||||
CPS_NormalizeLine(line);
|
||||
|
||||
/* Skip blank lines */
|
||||
if (!*line)
|
||||
continue;
|
||||
return;
|
||||
|
||||
/* We have a real line, now try to match commands */
|
||||
processed_command = command = line;
|
||||
|
@ -450,12 +458,6 @@ CNF_ReadFile(const char *filename)
|
|||
} else {
|
||||
other_parse_error("Invalid command");
|
||||
}
|
||||
}
|
||||
|
||||
line_number = prev_line_number;
|
||||
processed_file = prev_processed_file;
|
||||
fclose(in);
|
||||
}
|
||||
}
|
||||
|
||||
/* ================================================== */
|
||||
|
|
1
conf.h
1
conf.h
|
@ -34,6 +34,7 @@ extern void CNF_SetRestarted(int);
|
|||
extern char *CNF_GetRtcDevice(void);
|
||||
|
||||
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_AddSources(void);
|
||||
|
|
Loading…
Reference in a new issue