X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/f6bcfd974ef26faf6f91a62cac09827e09463fd1..f98de4487faac59af9d2d07e2ff23b8e852ce8eb:/src/common/cmdline.cpp?ds=inline diff --git a/src/common/cmdline.cpp b/src/common/cmdline.cpp index 965d1143de..3d8401f815 100644 --- a/src/common/cmdline.cpp +++ b/src/common/cmdline.cpp @@ -98,7 +98,7 @@ struct wxCmdLineOption void SetDateVal(const wxDateTime val) { Check(wxCMD_LINE_VAL_DATE); m_dateVal = val; m_hasVal = TRUE; } - void SetHasValue() { m_hasVal = TRUE; } + void SetHasValue(bool hasValue = TRUE) { m_hasVal = hasValue; } bool HasValue() const { return m_hasVal; } public: @@ -190,12 +190,50 @@ void wxCmdLineParserData::SetArguments(int argc, char **argv) } } -void wxCmdLineParserData::SetArguments(const wxString& WXUNUSED(cmdline)) +void wxCmdLineParserData::SetArguments(const wxString& cmdLine) { - // either use wxMSW wxApp::ConvertToStandardCommandArgs() or move its logic - // here and use this method from it - but don't duplicate the code + m_arguments.Empty(); + + m_arguments.Add(wxTheApp->GetAppName()); + + // Break up string + // Treat strings enclosed in double-quotes as single arguments + int i = 0; + int len = cmdLine.Length(); + while (i < len) + { + // Skip whitespace + while ((i < len) && wxIsspace(cmdLine.GetChar(i))) + i ++; + + if (i < len) + { + if (cmdLine.GetChar(i) == wxT('"')) // We found the start of a string + { + i ++; + int first = i; + while ((i < len) && (cmdLine.GetChar(i) != wxT('"'))) + i ++; + + wxString arg(cmdLine.Mid(first, (i - first))); + + m_arguments.Add(arg); + + if (i < len) + i ++; // Skip past 2nd quote + } + else // Unquoted argument + { + int first = i; + while ((i < len) && !wxIsspace(cmdLine.GetChar(i))) + i ++; - wxFAIL_MSG(_T("TODO")); + wxString arg(cmdLine.Mid(first, (i - first))); + + m_arguments.Add(arg); + } + } + } } int wxCmdLineParserData::FindOption(const wxString& name) @@ -437,6 +475,17 @@ wxString wxCmdLineParser::GetParam(size_t n) const return m_data->m_parameters[n]; } +// Resets switches and options +void wxCmdLineParser::Reset() +{ + for ( size_t i = 0; i < m_data->m_options.Count(); i++ ) + { + wxCmdLineOption& opt = m_data->m_options[i]; + opt.SetHasValue(FALSE); + } +} + + // ---------------------------------------------------------------------------- // the real work is done here // ---------------------------------------------------------------------------- @@ -452,6 +501,8 @@ int wxCmdLineParser::Parse() size_t countParam = m_data->m_paramDesc.GetCount(); + Reset(); + // parse everything wxString arg; size_t count = m_data->m_arguments.GetCount();