From ada3b11382b0514cebb178e0754c20e37c1a08be Mon Sep 17 00:00:00 2001 From: Francesco Romani Date: Sun, 6 Jul 2014 15:46:31 +0200 Subject: parser: extract function to handle .init Part-of: --- orc/orcparse.c | 28 +++++++++++++++++++--------- 1 file changed, 19 insertions(+), 9 deletions(-) (limited to 'orc') diff --git a/orc/orcparse.c b/orc/orcparse.c index 2fbb842..6ef13ed 100644 --- a/orc/orcparse.c +++ b/orc/orcparse.c @@ -92,6 +92,7 @@ static void orc_parse_sanity_check (OrcParser *parser, OrcProgram *program); static int orc_parse_handle_legacy (OrcParser *parser, const OrcLine *line); static int orc_parse_handle_function (OrcParser *parser, const OrcLine *line); +static int orc_parse_handle_init (OrcParser *parser, const OrcLine *line); static int orc_parse_handle_directive (OrcParser *parser, const OrcLine *line); static int orc_parse_handle_opcode (OrcParser *parser, const OrcLine *line); @@ -431,15 +432,7 @@ orc_parse_handle_legacy (OrcParser *parser, const OrcLine *line) const char **token = (const char **)(line->tokens); int n_tokens = line->n_tokens; - if (strcmp (token[0], ".init") == 0) { - free (parser->init_function); - parser->init_function = NULL; - if (n_tokens < 2) { - orc_parse_add_error (parser, ".init without function name"); - } else { - parser->init_function = strdup (token[1]); - } - } else if (strcmp (token[0], ".flags") == 0) { + if (strcmp (token[0], ".flags") == 0) { int i; for(i=1;iinit_function); + parser->init_function = NULL; + + if (line->n_tokens < 2) { + orc_parse_add_error (parser, ".init without function name"); + return 0; + } + + parser->init_function = strdup (line->tokens[1]); + + return 1; +} + static int orc_parse_handle_directive (OrcParser *parser, const OrcLine *line) { static const OrcDirective dirs[] = { { ".function", orc_parse_handle_function }, { ".backup", orc_parse_handle_backup }, + { ".init", orc_parse_handle_init }, { NULL, NULL } }; int i; -- cgit v1.2.1