From: David Elliott Date: Thu, 25 Oct 2007 18:01:36 +0000 (+0000) Subject: Look for and remove any "-NSKey" "value" types of options from argv just like X-Git-Url: https://git.saurik.com/wxWidgets.git/commitdiff_plain/04453a9e1e53ff185f26b1979a2febe1df7c656a?ds=inline Look for and remove any "-NSKey" "value" types of options from argv just like the -psn_XXXX option is removed. This allows Cocoa debug options like -NSShowAllViews YES to be used as with any other Cocoa program. git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@49438 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775 --- diff --git a/src/cocoa/app.mm b/src/cocoa/app.mm index c5e4f3dc32..6bafffa555 100644 --- a/src/cocoa/app.mm +++ b/src/cocoa/app.mm @@ -124,6 +124,37 @@ bool wxApp::Initialize(int& argc, wxChar **argv) } } + /* + Cocoa supports -Key value options which set the user defaults key "Key" + to the value "value" Some of them are very handy for debugging like + -NSShowAllViews YES. Cocoa picks these up from the real argv so + our removal of them from the wx copy of it does not affect Cocoa's + ability to see them. + + We basically just assume that any "-NS" option and its following + argument needs to be removed from argv. We hope that user code does + not expect to see -NS options and indeed it's probably a safe bet + since most user code accepting options is probably using the + double-dash GNU-style syntax. + */ + for(int i=1; i < argc; ++i) + { + static const wxChar *ARG_NS = wxT("-NS"); + static const int ARG_NS_LEN = wxStrlen(ARG_NS); + if( wxStrncmp(argv[i], ARG_NS, ARG_NS_LEN) == 0 ) + { + // Only eat this option if it has an argument + if( (i + 1) < argc ) + { + argc -= 2; + memmove(argv + i, argv + i + 2, argc * sizeof(wxChar*)); + // drop back one position so the next run through the loop + // reprocesses the argument at our current index. + --i; + } + } + } + return wxAppBase::Initialize(argc, argv); }