diff --git a/PNMain.cpp b/PNMain.cpp index b7c379238e7e4265e6b49363237d8a91cd6b48e7..dedbc962810b11591d0eaa84db74d6bd19712a10 100644 --- a/PNMain.cpp +++ b/PNMain.cpp @@ -63,6 +63,9 @@ PNOptions *pn_options; YAML::Node basenode; +std::string YAMLInputFileName; + + enum { BED_SCRIPT_OPTION = CHAR_MAX+1, @@ -88,7 +91,8 @@ enum SET_CANARY_VALUE, SET_FLOATING_CANARY_OPTION, SET_DETECTION_POLICY_OPTION, - SET_DETECTION_EXIT_CODE_OPTION + SET_DETECTION_EXIT_CODE_OPTION, + SET_YAML_INPUT_OPTION }; @@ -119,6 +123,7 @@ static struct option const long_options[] = {"floating_canary",no_argument, nullptr, SET_FLOATING_CANARY_OPTION}, {"detection_policy",required_argument, nullptr, SET_DETECTION_POLICY_OPTION}, {"detection_exit_code",required_argument, nullptr, SET_DETECTION_EXIT_CODE_OPTION}, + { "yaml_spec", required_argument, nullptr, SET_YAML_INPUT_OPTION}, {nullptr, 0, NULL, 0} }; @@ -420,27 +425,37 @@ std::string getStepName(void) const override void parseYAML(void) { bool FileExists = false; - if (FILE *YAMLFile = fopen("SLX.yaml", "r")) + if (!YAMLInputFileName.empty()) { - FileExists = (0 == fclose(YAMLFile)); + if (FILE *YAMLFile = fopen(YAMLInputFileName.c_str(), "r")) + { + // YAML::LoadFile() will do its own file open; needs to close properly. + FileExists = (0 == fclose(YAMLFile)); + } + } + else + { + cout << "Option yaml_spec_input_file not provided" << endl; + return; } if (!FileExists) { - cout << "File SLX.yaml does not exist." << endl; + cout << "File " << YAMLInputFileName << " does not exist." << endl; return; } - basenode = YAML::LoadFile("SLX.yaml"); // load into global var basenode + basenode = YAML::LoadFile(YAMLInputFileName); // load into global var basenode if (basenode.IsNull()) { - cout << "ERROR: Failure to load file SLX.yaml" << endl; + cout << "ERROR: Failure to load file " << YAMLInputFileName << endl; return; } if (verbose_log) { // Dump basenode. + cout << "Verbose dump of YAML spec." << endl; cout << basenode << endl; } @@ -678,6 +693,11 @@ int parseArgs(const vector<string> step_args) break; } + case SET_YAML_INPUT_OPTION: + { + YAMLInputFileName = std::string(optarg); + break; + } case '?': { //error message already printed by getopt_long