wxString wxCmdLineParser::GetParam(size_t n) const
{
+ wxCHECK_MSG( n < GetParamCount(), wxEmptyString, _T("invalid param index") );
+
return m_data->m_parameters[n];
}
// global functions
// ----------------------------------------------------------------------------
+/*
+ This function is mainly used under Windows (as under Unix we always get the
+ command line arguments as agrc/argv anyhow) and so it tries to handle the
+ Windows path names (separated by backslashes) correctly. For this it only
+ considers that a backslash may be used to escape another backslash (but
+ normally this is _not_ needed) or a quote but nothing else.
+
+ In particular, to pass a single argument containing a space to the program
+ it should be quoted:
+
+ myprog.exe foo bar -> argc = 3, argv[1] = "foo", argv[2] = "bar"
+ myprog.exe "foo bar" -> argc = 2, argv[1] = "foo bar"
+
+ To pass an argument containing spaces and quotes, the latter should be
+ escaped with a backslash:
+
+ myprog.exe "foo \"bar\"" -> argc = 2, argv[1] = "foo "bar""
+
+ This hopefully matches the conventions used by Explorer/command line
+ interpreter under Windows. If not, this function should be fixed.
+ */
+
/* static */
wxArrayString wxCmdLineParser::ConvertStringToArgs(const wxChar *p)
{
case _T(' '):
case _T('\t'):
- if ( isInsideQuotes || isQuotedByBS )
+ // we intentionally don't check for preceding backslash
+ // here as if we allowed it to be used to escape spaces the
+ // cmd line of the form "foo.exe a:\ c:\bar" wouldn't be
+ // parsed correctly
+ if ( isInsideQuotes )
{
// preserve it, skip endParam below
break;