From 2456047eec0fc9a53f56600cd632321eb6a97921 Mon Sep 17 00:00:00 2001 From: Jeff Squyres Date: Fri, 4 Feb 2005 16:14:33 +0000 Subject: [PATCH] Fixes for bug 1134. Not much worth explaining -- just adding some missed cases in the parsing. This commit was SVN r4287. --- src/mca/base/mca_base_parse_paramfile.c | 33 +++++++++++++++------ src/mca/base/mca_base_parse_paramfile_lex.l | 2 +- 2 files changed, 25 insertions(+), 10 deletions(-) diff --git a/src/mca/base/mca_base_parse_paramfile.c b/src/mca/base/mca_base_parse_paramfile.c index 18762b677a..97d78f2373 100644 --- a/src/mca/base/mca_base_parse_paramfile.c +++ b/src/mca/base/mca_base_parse_paramfile.c @@ -26,9 +26,12 @@ #include "mca/base/mca_base_parse_paramfile_lex.h" +static const char *filename; + + static int parse_line(void); static void save_value(char *name, char *value); -static void parse_error(void); +static void parse_error(int num); int mca_base_parse_paramfile(const char *paramfile) @@ -42,7 +45,9 @@ int mca_base_parse_paramfile(const char *paramfile) return OMPI_ERR_NOT_FOUND; } + filename = paramfile; mca_base_parse_done = false; + mca_base_yynewlines = 1; mca_base_param_init_buffer(mca_base_yyin); while (!mca_base_parse_done) { val = mca_base_yylex(); @@ -62,7 +67,7 @@ int mca_base_parse_paramfile(const char *paramfile) default: /* anything else is an error */ - parse_error(); + parse_error(1); break; } } @@ -85,7 +90,7 @@ static int parse_line(void) val = mca_base_yylex(); if (mca_base_parse_done || MCA_BASE_PARSE_EQUAL != val) { - parse_error(); + parse_error(2); free(name); return OMPI_ERROR; } @@ -96,7 +101,13 @@ static int parse_line(void) if (MCA_BASE_PARSE_SINGLE_WORD == val || MCA_BASE_PARSE_VALUE == val) { save_value(name, mca_base_yytext); - return OMPI_SUCCESS; + + /* Now we need to see the newline */ + + val = mca_base_yylex(); + if (MCA_BASE_PARSE_NEWLINE == val) { + return OMPI_SUCCESS; + } } /* Did we get an EOL or EOF? */ @@ -109,7 +120,7 @@ static int parse_line(void) /* Nope -- we got something unexpected. Bonk! */ - parse_error(); + parse_error(3); free(name); return OMPI_ERROR; } @@ -141,15 +152,19 @@ static void save_value(char *name, char *value) fv = OBJ_NEW(mca_base_param_file_value_t); if (NULL != fv) { fv->mbpfv_param = name; - fv->mbpfv_value = strdup(value); + if (NULL != value) { + fv->mbpfv_value = strdup(value); + } else { + fv->mbpfv_value = NULL; + } ompi_list_append(&mca_base_param_file_values, (ompi_list_item_t*) fv); } } -static void parse_error(void) +static void parse_error(int num) { /* JMS need better error/warning message here */ - ompi_output(0, "paramfile: error reading file at line %d, %s\n", - mca_base_yynewlines, mca_base_yytext); + ompi_output(0, "paramfile: error %d reading file %s at line %d:\n %s\n", + num, filename, mca_base_yynewlines, mca_base_yytext); } diff --git a/src/mca/base/mca_base_parse_paramfile_lex.l b/src/mca/base/mca_base_parse_paramfile_lex.l index 075bef9217..4d13473a37 100644 --- a/src/mca/base/mca_base_parse_paramfile_lex.l +++ b/src/mca/base/mca_base_parse_paramfile_lex.l @@ -54,7 +54,7 @@ CHAR [A-Za-z0-9_\-\.] {WHITE}+ ; /* whitespace */ {CHAR}+ { return MCA_BASE_PARSE_SINGLE_WORD; } -{WHITE}*\n { BEGIN(INITIAL); } +{WHITE}*\n { BEGIN(INITIAL); return MCA_BASE_PARSE_NEWLINE; } [^\n]*[^\t \n]/[\t ]*\n { return MCA_BASE_PARSE_VALUE; } . { return MCA_BASE_PARSE_ERROR; }