2004-08-31 13:49:56 +04:00
|
|
|
/*
|
2004-11-22 04:38:40 +03:00
|
|
|
* Copyright (c) 2004-2005 The Trustees of Indiana University.
|
|
|
|
* All rights reserved.
|
|
|
|
* Copyright (c) 2004-2005 The Trustees of the University of Tennessee.
|
|
|
|
* All rights reserved.
|
2004-11-28 23:09:25 +03:00
|
|
|
* Copyright (c) 2004-2005 High Performance Computing Center Stuttgart,
|
|
|
|
* University of Stuttgart. All rights reserved.
|
2005-03-24 15:43:37 +03:00
|
|
|
* Copyright (c) 2004-2005 The Regents of the University of California.
|
|
|
|
* All rights reserved.
|
2004-11-22 04:38:40 +03:00
|
|
|
* $COPYRIGHT$
|
|
|
|
*
|
|
|
|
* Additional copyrights may follow
|
|
|
|
*
|
2004-08-31 13:49:56 +04:00
|
|
|
* $HEADER$
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "ompi_config.h"
|
|
|
|
|
|
|
|
#include <stdio.h>
|
2004-11-05 10:52:30 +03:00
|
|
|
#include <string.h>
|
2004-08-31 13:49:56 +04:00
|
|
|
|
2004-11-05 10:52:30 +03:00
|
|
|
#include "include/constants.h"
|
2005-07-03 20:22:16 +04:00
|
|
|
#include "opal/class/opal_list.h"
|
2004-08-31 13:49:56 +04:00
|
|
|
#include "util/output.h"
|
|
|
|
#include "mca/mca.h"
|
|
|
|
#include "mca/base/base.h"
|
|
|
|
#include "mca/base/mca_base_param_internal.h"
|
|
|
|
#include "mca/base/mca_base_parse_paramfile_lex.h"
|
|
|
|
|
|
|
|
|
2005-02-04 19:14:33 +03:00
|
|
|
static const char *filename;
|
|
|
|
|
|
|
|
|
2004-08-31 13:49:56 +04:00
|
|
|
static int parse_line(void);
|
|
|
|
static void save_value(char *name, char *value);
|
2005-02-04 19:14:33 +03:00
|
|
|
static void parse_error(int num);
|
2004-08-31 13:49:56 +04:00
|
|
|
|
|
|
|
|
|
|
|
int mca_base_parse_paramfile(const char *paramfile)
|
|
|
|
{
|
|
|
|
int val;
|
|
|
|
|
|
|
|
/* Open the parameter file */
|
|
|
|
|
|
|
|
mca_base_yyin = fopen(paramfile, "r");
|
|
|
|
if (NULL == mca_base_yyin) {
|
|
|
|
return OMPI_ERR_NOT_FOUND;
|
|
|
|
}
|
|
|
|
|
2005-02-04 19:14:33 +03:00
|
|
|
filename = paramfile;
|
2004-08-31 13:49:56 +04:00
|
|
|
mca_base_parse_done = false;
|
2005-02-04 19:14:33 +03:00
|
|
|
mca_base_yynewlines = 1;
|
2004-10-15 15:42:54 +04:00
|
|
|
mca_base_param_init_buffer(mca_base_yyin);
|
2004-08-31 13:49:56 +04:00
|
|
|
while (!mca_base_parse_done) {
|
|
|
|
val = mca_base_yylex();
|
|
|
|
switch (val) {
|
|
|
|
case MCA_BASE_PARSE_DONE:
|
|
|
|
/* This will also set mca_base_parse_done to true, so just
|
|
|
|
break here */
|
|
|
|
break;
|
|
|
|
|
|
|
|
case MCA_BASE_PARSE_NEWLINE:
|
|
|
|
/* blank line! ignore it */
|
|
|
|
break;
|
|
|
|
|
|
|
|
case MCA_BASE_PARSE_SINGLE_WORD:
|
|
|
|
parse_line();
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
/* anything else is an error */
|
2005-02-04 19:14:33 +03:00
|
|
|
parse_error(1);
|
2004-08-31 13:49:56 +04:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
fclose(mca_base_yyin);
|
|
|
|
|
|
|
|
return OMPI_SUCCESS;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static int parse_line(void)
|
|
|
|
{
|
|
|
|
int val;
|
|
|
|
char *name;
|
|
|
|
|
|
|
|
/* Save the parameter name */
|
|
|
|
|
|
|
|
name = strdup(mca_base_yytext);
|
|
|
|
|
|
|
|
/* The first thing we have to see is an "=" */
|
|
|
|
|
|
|
|
val = mca_base_yylex();
|
|
|
|
if (mca_base_parse_done || MCA_BASE_PARSE_EQUAL != val) {
|
2005-02-04 19:14:33 +03:00
|
|
|
parse_error(2);
|
2004-08-31 13:49:56 +04:00
|
|
|
free(name);
|
|
|
|
return OMPI_ERROR;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Next we get the value */
|
|
|
|
|
|
|
|
val = mca_base_yylex();
|
|
|
|
if (MCA_BASE_PARSE_SINGLE_WORD == val ||
|
|
|
|
MCA_BASE_PARSE_VALUE == val) {
|
|
|
|
save_value(name, mca_base_yytext);
|
2005-02-04 19:14:33 +03:00
|
|
|
|
|
|
|
/* Now we need to see the newline */
|
|
|
|
|
|
|
|
val = mca_base_yylex();
|
|
|
|
if (MCA_BASE_PARSE_NEWLINE == val) {
|
|
|
|
return OMPI_SUCCESS;
|
|
|
|
}
|
2004-08-31 13:49:56 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Did we get an EOL or EOF? */
|
|
|
|
|
|
|
|
else if (MCA_BASE_PARSE_DONE == val ||
|
|
|
|
MCA_BASE_PARSE_NEWLINE == val) {
|
|
|
|
save_value(name, NULL);
|
|
|
|
return OMPI_SUCCESS;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Nope -- we got something unexpected. Bonk! */
|
|
|
|
|
2005-02-04 19:14:33 +03:00
|
|
|
parse_error(3);
|
2004-08-31 13:49:56 +04:00
|
|
|
free(name);
|
|
|
|
return OMPI_ERROR;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static void save_value(char *name, char *value)
|
|
|
|
{
|
2005-07-03 20:22:16 +04:00
|
|
|
opal_list_item_t *item;
|
2004-08-31 13:49:56 +04:00
|
|
|
mca_base_param_file_value_t *fv;
|
|
|
|
|
|
|
|
/* First traverse through the list and ensure that we don't
|
|
|
|
already have a param of this name. If we do, just replace the
|
|
|
|
value. */
|
|
|
|
|
2005-07-03 20:22:16 +04:00
|
|
|
for (item = opal_list_get_first(&mca_base_param_file_values);
|
|
|
|
opal_list_get_end(&mca_base_param_file_values) != item;
|
|
|
|
item = opal_list_get_next(item)) {
|
2004-08-31 13:49:56 +04:00
|
|
|
fv = (mca_base_param_file_value_t *) item;
|
|
|
|
if (0 == strcmp(name, fv->mbpfv_param)) {
|
|
|
|
free(name);
|
|
|
|
free(fv->mbpfv_value);
|
|
|
|
fv->mbpfv_value = strdup(value);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* We didn't already have the param, so append it to the list */
|
|
|
|
|
|
|
|
fv = OBJ_NEW(mca_base_param_file_value_t);
|
|
|
|
if (NULL != fv) {
|
|
|
|
fv->mbpfv_param = name;
|
2005-02-04 19:14:33 +03:00
|
|
|
if (NULL != value) {
|
|
|
|
fv->mbpfv_value = strdup(value);
|
|
|
|
} else {
|
|
|
|
fv->mbpfv_value = NULL;
|
|
|
|
}
|
2005-07-03 20:22:16 +04:00
|
|
|
opal_list_append(&mca_base_param_file_values, (opal_list_item_t*) fv);
|
2004-08-31 13:49:56 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2005-02-04 19:14:33 +03:00
|
|
|
static void parse_error(int num)
|
2004-08-31 13:49:56 +04:00
|
|
|
{
|
|
|
|
/* JMS need better error/warning message here */
|
2005-02-04 19:14:33 +03:00
|
|
|
ompi_output(0, "paramfile: error %d reading file %s at line %d:\n %s\n",
|
|
|
|
num, filename, mca_base_yynewlines, mca_base_yytext);
|
2004-08-31 13:49:56 +04:00
|
|
|
}
|