27 #include <sys/types.h> 44 applicationName
(_applicationName
),
58 applicationName
(_applicationName
),
71 if (!nextField.Empty ())
72 initialParameters.push_back (nextField);
76 BuildCmdLineParameters (initialParameters);
77 BuildExpandedParameterPairs ();
101 for (y = 1; y < argc; y++)
102 initialParameters.push_back (argv[y]);
105 BuildCmdLineParameters (initialParameters);
106 BuildExpandedParameterPairs ();
118 VectorKKStr::const_iterator idx;
119 for (idx = cmdFileStack.begin (); idx != cmdFileStack.end (); idx++)
121 if (*idx == cmdFileName)
135 while (x < argv.size ())
140 KKStr sUpper = s.ToUpper();
141 if ((sUpper ==
"-L") || (sUpper ==
"-LOGFILE"))
143 if (x < argv.size ())
145 if (argv[x][(kkint16)0] !=
'-')
147 logFileName = argv[x];
148 if (!logFileName.Empty ())
149 log.AttachFile (logFileName);
154 if (logFileName.Empty ())
156 log.Level (-1) << std::endl << std::endl;
157 log.Level (-1) << applicationName <<
" - Invalid Log File Parameter (-L)." << endl;
158 log.Level (-1) <<
" Name of log file required." << endl;
159 log.Level (-1) << endl;
165 else if (sUpper ==
"-CMDFILE")
167 KKStr cmdFileName =
"";
169 if (x < argv.size ())
171 if (argv[x][(kkint16)0] !=
'-')
173 cmdFileName = argv[x];
178 if (cmdFileName.Empty ())
180 log.Level (-1) << endl << endl << endl
181 << applicationName <<
" " <<
"BuildCmdLineParameters *** ERROR ***" << endl << endl
182 <<
"-CMDFILE option did not define a file name." << endl
190 if (FileInStack (cmdFileName, cmdFileStack))
192 log.Level (-1) << endl << endl << endl
193 << applicationName <<
" BuildCmdLineParameters *** ERROR ***" << endl
195 <<
"-CMDFILE [" << cmdFileName <<
"] is being called recursively." << endl
202 bool validFile =
true;
203 cmdFileStack.push_back (cmdFileName);
204 VectorKKStr cmdFileParameters;
205 ExtractParametersFromFile (cmdFileName, cmdFileParameters, validFile);
206 BuildCmdLineParameters (cmdFileParameters);
207 cmdFileStack.pop_back ();
216 expandedParameters.push_back (s);
227 expandedParameterPairs.clear ();
229 while (x < expandedParameters.size ())
231 const KKStr& nextField = expandedParameters[x];
234 KKStr parmSwitch =
"";
235 KKStr parmValue =
"";
237 if (!ParameterIsASwitch (nextField))
240 parmValue = nextField;
244 parmSwitch = nextField;
245 if (x < expandedParameters.size ())
247 if (!ParameterIsASwitch (expandedParameters[x]))
249 parmValue = expandedParameters[x];
255 expandedParameterPairs.push_back (KKStrPair (parmSwitch, parmValue));
274 double parmValue = 0.0;
292 log.Level (-1) << endl << endl << endl
293 <<
"ExtractParametersFromFile *** EROR ***" << endl
295 <<
" Invalid CmdFile[" << cmdFileName <<
"]" << endl
307 cmdFileParameters.push_back (token);
CmdLineExpander(const KKStr &_applicationName, RunLog &_log, const KKStr &_cmdLine)
Pass in the command line as a single string. Will parse first before processing.
char operator[](kkint16 i) const
KKB::KKStr osReadNextQuotedStr(FILE *in, const char *whiteSpaceCharacters, bool &eof)
Read the next Quoted String from the file.
CmdLineExpander(const KKStr &_applicationName, RunLog &_log, kkint32 argc, char **argv)
Constructor using the parameters passed through on the command line into main().
KKStr & TrimRight(const char *whiteSpaceChars="\n\r\t ")
unsigned __int32 kkuint32
bool ValidNum(double &value) const
KKStr & operator=(KKStr &&src)
kkuint32 Len() const
Returns the number of characters in the string.
Expands command line parameters, by parsing for special parameters and expanding them to their full v...
KKStr(const KKStr &str)
Copy Constructor.
bool FileInStack(const KKStr &cmdFileName, const VectorKKStr &cmdFileStack)
void TrimLeft(const char *whiteSpaceChars="\n\r\t ")
static KKStr Concat(const std::vector< std::string > &values)
Concatenates the list of 'std::string' strings.
KKStr ExtractQuotedStr(const char *delChars, bool decodeEscapeCharacters)
const char * Str() const
Returns a pointer to a ascii string.
FILE * osFOPEN(const char *fileName, const char *mode)
Used for logging messages.
void ExpandCmdLine(kkint32 argc, char **argv)