interface-file: break out source keyword handling
This commit is contained in:
parent
df9c0284b1
commit
4a11d4fdd8
1 changed files with 23 additions and 15 deletions
|
@ -95,6 +95,28 @@ handle_auto(struct lif_dict *collection, const char *filename, size_t lineno, ch
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static bool
|
||||||
|
handle_source(struct lif_dict *collection, const char *filename, size_t lineno, char *token, char *bufp)
|
||||||
|
{
|
||||||
|
(void) token;
|
||||||
|
|
||||||
|
char *source_filename = lif_next_token(&bufp);
|
||||||
|
if (!*source_filename)
|
||||||
|
{
|
||||||
|
report_error(filename, lineno, "missing filename to source");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!strcmp(filename, source_filename))
|
||||||
|
{
|
||||||
|
report_error(filename, lineno, "attempt to source %s would create infinite loop",
|
||||||
|
source_filename);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
return lif_interface_file_parse(collection, source_filename);
|
||||||
|
}
|
||||||
|
|
||||||
/* map keywords to parser functions */
|
/* map keywords to parser functions */
|
||||||
struct parser_keyword {
|
struct parser_keyword {
|
||||||
const char *token;
|
const char *token;
|
||||||
|
@ -103,6 +125,7 @@ struct parser_keyword {
|
||||||
|
|
||||||
static const struct parser_keyword keywords[] = {
|
static const struct parser_keyword keywords[] = {
|
||||||
{"auto", handle_auto},
|
{"auto", handle_auto},
|
||||||
|
{"source", handle_source},
|
||||||
};
|
};
|
||||||
|
|
||||||
static int
|
static int
|
||||||
|
@ -141,21 +164,6 @@ lif_interface_file_parse(struct lif_dict *collection, const char *filename)
|
||||||
if (!parserkw->handle(collection, filename, lineno, token, bufp))
|
if (!parserkw->handle(collection, filename, lineno, token, bufp))
|
||||||
goto parse_error;
|
goto parse_error;
|
||||||
}
|
}
|
||||||
else if (!strcmp(token, "source"))
|
|
||||||
{
|
|
||||||
char *source_filename = lif_next_token(&bufp);
|
|
||||||
if (!*source_filename)
|
|
||||||
goto parse_error;
|
|
||||||
|
|
||||||
if (!strcmp(filename, source_filename))
|
|
||||||
{
|
|
||||||
report_error(filename, lineno, "attempt to source %s would create infinite loop",
|
|
||||||
source_filename);
|
|
||||||
goto parse_error;
|
|
||||||
}
|
|
||||||
|
|
||||||
lif_interface_file_parse(collection, source_filename);
|
|
||||||
}
|
|
||||||
else if (!strcmp(token, "iface"))
|
else if (!strcmp(token, "iface"))
|
||||||
{
|
{
|
||||||
char *ifname = lif_next_token(&bufp);
|
char *ifname = lif_next_token(&bufp);
|
||||||
|
|
Loading…
Reference in a new issue