New helper function to allocate the file input_descriptor. Signed-off-by: Pablo Neira Ayuso <pablo@xxxxxxxxxxxxx> --- src/scanner.l | 26 +++++++++++++++++--------- 1 file changed, 17 insertions(+), 9 deletions(-) diff --git a/src/scanner.l b/src/scanner.l index fe70df5c18ec..56f6e9956791 100644 --- a/src/scanner.l +++ b/src/scanner.l @@ -665,6 +665,22 @@ addrstring ({macaddr}|{ip4addr}|{ip6addr}) %% +static struct input_descriptor * +indesc_file_alloc(FILE *f, const char *filename, const struct location *loc) +{ + struct input_descriptor *indesc; + + indesc = xzalloc(sizeof(struct input_descriptor)); + if (loc != NULL) + indesc->location = *loc; + indesc->type = INDESC_FILE; + indesc->name = xstrdup(filename); + indesc->f = f; + init_pos(indesc); + + return indesc; +} + static void scanner_push_indesc(struct parser_state *state, struct input_descriptor *indesc) { @@ -702,15 +718,7 @@ static void scanner_push_file(struct nft_ctx *nft, void *scanner, b = yy_create_buffer(f, YY_BUF_SIZE, scanner); yypush_buffer_state(b, scanner); - indesc = xzalloc(sizeof(struct input_descriptor)); - - if (loc != NULL) - indesc->location = *loc; - indesc->type = INDESC_FILE; - indesc->name = xstrdup(filename); - indesc->f = f; - init_pos(indesc); - + indesc = indesc_file_alloc(f, filename, loc); scanner_push_indesc(state, indesc); } -- 2.11.0