From ca5ddb429e95e11e5811053d6153628853942533 Mon Sep 17 00:00:00 2001 From: Scott Fennell Date: Mon, 1 Jul 2019 09:46:37 -0500 Subject: [PATCH 1/2] iss #837 make command line arguments position independent --- .../CommandLineArguments/CommandLineArguments.cpp | 13 +++++++++---- .../sim_services/InputProcessor/InputProcessor.cpp | 2 +- trick_source/sim_services/MasterSlave/MSSocket.cpp | 2 +- 3 files changed, 11 insertions(+), 6 deletions(-) diff --git a/trick_source/sim_services/CommandLineArguments/CommandLineArguments.cpp b/trick_source/sim_services/CommandLineArguments/CommandLineArguments.cpp index b46c747a..fc079c5c 100644 --- a/trick_source/sim_services/CommandLineArguments/CommandLineArguments.cpp +++ b/trick_source/sim_services/CommandLineArguments/CommandLineArguments.cpp @@ -158,9 +158,14 @@ int Trick::CommandLineArguments::process_sim_args(int nargs , char **args) { if ( argc > 1 ) { - /* First argument is the input file name: '/' */ - input_file = argv[1] ; - run_dir = argv[1] ; + /* First occurnance of "RUN_*" is the input file name: '/' */ + for(int ii = 1; ii < argc; ii++) { + if(std::string(argv[ii]).find("RUN_") != std::string::npos) { + input_file = argv[ii]; + run_dir = argv[ii]; + break; + } + } found = run_dir.find_last_of("/") ; if ( found != std::string::npos ) { @@ -176,7 +181,7 @@ int Trick::CommandLineArguments::process_sim_args(int nargs , char **args) { output_dir = run_dir ; - for (ii = 2; ii < argc; ii++) { + for (ii = 1; ii < argc; ii++) { if (!strncmp("-OO", argv[ii], (size_t) 3) || !strncmp("-O", argv[ii], (size_t) 2)) { if (ii == ( argc - 1 )) { std::cerr << "\nERROR: No directory specified after -O or -OO argument" << std::endl ; diff --git a/trick_source/sim_services/InputProcessor/InputProcessor.cpp b/trick_source/sim_services/InputProcessor/InputProcessor.cpp index 1b92cf58..f4d1b60e 100644 --- a/trick_source/sim_services/InputProcessor/InputProcessor.cpp +++ b/trick_source/sim_services/InputProcessor/InputProcessor.cpp @@ -36,7 +36,7 @@ int Trick::InputProcessor::process_sim_args() { input_file = command_line_args_get_input_file() ; /* Process all other calling arguments */ - for (i = 2; i < argc; i++) { + for (i = 1; i < argc; i++) { /* * If there are more than 2 calling arguments diff --git a/trick_source/sim_services/MasterSlave/MSSocket.cpp b/trick_source/sim_services/MasterSlave/MSSocket.cpp index f7654b11..2ef16124 100644 --- a/trick_source/sim_services/MasterSlave/MSSocket.cpp +++ b/trick_source/sim_services/MasterSlave/MSSocket.cpp @@ -77,7 +77,7 @@ int Trick::MSSocket::process_sim_args() { /** @par Detailed Design */ /** @li search for the "-p" argument. If found get the master identifier as the next argument */ - for (ii = 2; ii < argc; ii++) { + for (ii = 1; ii < argc; ii++) { if (!strncmp("-p", argv[ii], (size_t) 2)) { if (argc >= ii + 1) { sync_port_tag = argv[ii+1] ; From c2d2fee474670be0ce744fb06369d31f5af849f1 Mon Sep 17 00:00:00 2001 From: Scott Fennell Date: Mon, 8 Jul 2019 09:28:53 -0500 Subject: [PATCH 2/2] #837 default input file to first argument if RUN_ is not present --- .../CommandLineArguments.cpp | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) diff --git a/trick_source/sim_services/CommandLineArguments/CommandLineArguments.cpp b/trick_source/sim_services/CommandLineArguments/CommandLineArguments.cpp index fc079c5c..bdd9dbb0 100644 --- a/trick_source/sim_services/CommandLineArguments/CommandLineArguments.cpp +++ b/trick_source/sim_services/CommandLineArguments/CommandLineArguments.cpp @@ -158,14 +158,19 @@ int Trick::CommandLineArguments::process_sim_args(int nargs , char **args) { if ( argc > 1 ) { - /* First occurnance of "RUN_*" is the input file name: '/' */ - for(int ii = 1; ii < argc; ii++) { - if(std::string(argv[ii]).find("RUN_") != std::string::npos) { - input_file = argv[ii]; - run_dir = argv[ii]; - break; + /* First occurnance of "RUN_*" is the input file name: '/'. + If not found, defaults to first argument */ + + input_file = argv[1]; + run_dir = argv[1]; + + for(int ii = 1; ii < argc; ii++) { + if(std::string(argv[ii]).find("RUN_") != std::string::npos) { + input_file = argv[ii]; + run_dir = argv[ii]; + break; + } } - } found = run_dir.find_last_of("/") ; if ( found != std::string::npos ) {