static void reset_collective(coll_config_t *coll_cf) { if (coll_cf->coll_name) { free (coll_cf->coll_name); coll_cf->coll_name = NULL; } coll_cf->coll_id = ML_UNDEFINED; reset_section(&coll_cf->section); }
/* * Parse a single file */ static int parse_file(char *filename) { int val; int ret = OMPI_SUCCESS; bool first_section = true, first_coll = true; coll_config_t coll_config; memset (&coll_config, 0, sizeof (coll_config)); reset_collective(&coll_config); /* Open the file */ coll_ml_config_yyin = fopen(filename, "r"); if (NULL == coll_ml_config_yyin) { ML_ERROR(("Failed to open config file %s", filename)); ret = OMPI_ERR_NOT_FOUND; goto cleanup; } /* Do the parsing */ coll_ml_config_parse_done = false; coll_ml_config_yynewlines = 1; coll_ml_config_init_buffer(coll_ml_config_yyin); while (!coll_ml_config_parse_done) { val = coll_ml_config_yylex(); switch (val) { case COLL_ML_CONFIG_PARSE_DONE: case COLL_ML_CONFIG_PARSE_NEWLINE: break; case COLL_ML_CONFIG_PARSE_COLLECTIVE: /* dump all the information to last section that was defined */ if (!first_coll) { ret = save_settings(&coll_config); if (OMPI_SUCCESS != ret) { ML_ERROR(("Error in syntax for collective %s", coll_config.coll_name)); goto cleanup; } } /* reset collective config */ reset_collective(&coll_config); first_coll = false; first_section = true; ret = set_collective_name(&coll_config); if (OMPI_SUCCESS != ret) { goto cleanup; } break; case COLL_ML_CONFIG_PARSE_SECTION: if (ML_UNDEFINED == coll_config.coll_id) { ML_ERROR(("Collective section wasn't defined !")); ret = OMPI_ERROR; goto cleanup; } if (!first_section) { /* dump all the information to last section that was defined */ ret = save_settings(&coll_config); if (OMPI_SUCCESS != ret) { ML_ERROR(("Error in syntax for collective %s section %s", coll_config.coll_name, coll_config.section.section_name)); goto cleanup; } } first_section = false; /* reset all section values */ reset_section(&coll_config.section); /* set new section name */ ret = set_section_name(&coll_config.section); if (OMPI_SUCCESS != ret) { goto cleanup; } break; case COLL_ML_CONFIG_PARSE_SINGLE_WORD: if (ML_UNDEFINED == coll_config.coll_id || ML_UNDEFINED == coll_config.section.section_id) { ML_ERROR(("Collective section or sub-section was not defined !")); ret = OMPI_ERROR; goto cleanup; } else { parse_line(&coll_config.section); } break; default: /* anything else is an error */ ML_ERROR(("Unexpected token!")); ret = OMPI_ERROR; goto cleanup; break; } } save_settings(&coll_config); fclose(coll_ml_config_yyin); coll_ml_config_yylex_destroy (); ret = OMPI_SUCCESS; cleanup: reset_collective(&coll_config); if (NULL != key_buffer) { free(key_buffer); key_buffer = NULL; key_buffer_len = 0; } return ret; }
/* * Parse a single file */ static int parse_file(char *filename) { int val; int ret = OMPI_SUCCESS; bool showed_no_section_warning = false; bool showed_unexpected_tokens_warning = false; parsed_section_values_t section; reset_section(false, §ion); /* Open the file */ ini_filename = filename; btl_openib_ini_yyin = fopen(filename, "r"); if (NULL == btl_openib_ini_yyin) { orte_show_help("help-mpi-btl-openib.txt", "ini file:file not found", true, filename); ret = OMPI_ERR_NOT_FOUND; goto cleanup; } /* Do the parsing */ btl_openib_ini_parse_done = false; btl_openib_ini_yynewlines = 1; btl_openib_ini_init_buffer(btl_openib_ini_yyin); while (!btl_openib_ini_parse_done) { val = btl_openib_ini_yylex(); switch (val) { case BTL_OPENIB_INI_PARSE_DONE: /* This will also set btl_openib_ini_parse_done to true, so just break here */ break; case BTL_OPENIB_INI_PARSE_NEWLINE: /* blank line! ignore it */ break; case BTL_OPENIB_INI_PARSE_SECTION: /* We're starting a new section; if we have previously parsed a section, go see if we can use its values. */ save_section(§ion); reset_section(true, §ion); section.name = strdup(btl_openib_ini_yytext); break; case BTL_OPENIB_INI_PARSE_SINGLE_WORD: if (NULL == section.name) { /* Warn that there is no current section, and ignore this parameter */ if (!showed_no_section_warning) { show_help("ini file:not in a section"); showed_no_section_warning = true; } /* Parse it and then dump it */ parse_line(§ion); reset_section(true, §ion); } else { parse_line(§ion); } break; default: /* anything else is an error */ if (!showed_unexpected_tokens_warning) { show_help("ini file:unexpected token"); showed_unexpected_tokens_warning = true; } break; } } save_section(§ion); fclose(btl_openib_ini_yyin); btl_openib_ini_yylex_destroy (); cleanup: reset_section(true, §ion); if (NULL != key_buffer) { free(key_buffer); key_buffer = NULL; key_buffer_len = 0; } return ret; }