summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorGeorge Hazan <ghazan@miranda.im>2019-03-25 20:40:13 +0300
committerGeorge Hazan <ghazan@miranda.im>2019-03-25 20:40:13 +0300
commitf2764176c58829d24fee7a830a3c9ac2b57d1906 (patch)
treed7331ad4a88e00ccb787a4013e6c1699c7b9f352 /src
parentacfe02b246ab39f97bf77a0f3a11fc97e3f7fb3d (diff)
major fix for the command-line parser
Diffstat (limited to 'src')
-rw-r--r--src/mir_core/src/cmdline.cpp42
-rw-r--r--src/mir_core/src/stdafx.h1
2 files changed, 16 insertions, 27 deletions
diff --git a/src/mir_core/src/cmdline.cpp b/src/mir_core/src/cmdline.cpp
index b0b98df2aa..29f4a8a83c 100644
--- a/src/mir_core/src/cmdline.cpp
+++ b/src/mir_core/src/cmdline.cpp
@@ -43,42 +43,30 @@ static OBJLIST<CmdLineParam> arParams(5, CompareParams);
MIR_CORE_DLL(void) CmdLine_Parse(const wchar_t *ptszCmdLine)
{
- bool bPrevSpace = true;
- for (wchar_t *p = NEWWSTR_ALLOCA(ptszCmdLine); *p; p++) {
- if (*p == ' ' || *p == '\t') {
- *p = 0;
- bPrevSpace = true;
- continue;
- }
+ int nArgs = 0;
+ wchar_t **pArgs = CommandLineToArgvW(ptszCmdLine, &nArgs);
+ if (pArgs == nullptr)
+ return;
- // new word beginning
- if (bPrevSpace) {
- bPrevSpace = false;
- if (*p != '/' && *p != '-') // not an option - skip it
- continue;
- }
- else continue; // skip a text that isn't an option
+ for (int i=0; i < nArgs; i++) {
+ wchar_t *pOptionName = pArgs[i], *p;
- wchar_t *pOptionName = p + 1;
- if ((p = wcspbrk(pOptionName, L" \t=:")) == nullptr) { // no more text in string
- arParams.insert(new CmdLineParam(pOptionName, L""));
- break;
- }
+ // not an option? skip it
+ if (*pOptionName != '/' && *pOptionName != '-')
+ continue;
- if (*p == ' ' || *p == '\t') {
+ pOptionName++;
+ if ((p = wcspbrk(pOptionName, L"=:")) == nullptr) { // no more text in string
arParams.insert(new CmdLineParam(pOptionName, L""));
- p--; // the cycle will wipe this space automatically
- continue;
+ break;
}
// parameter with value
*p = 0;
- arParams.insert(new CmdLineParam(pOptionName, ++p));
- if ((p = wcspbrk(p, L" \t")) == nullptr) // no more text in string
- break;
-
- p--; // the cycle will wipe this space automatically
+ arParams.insert(new CmdLineParam(pOptionName, p+1));
}
+
+ LocalFree(pArgs);
}
MIR_CORE_DLL(const wchar_t*) CmdLine_GetOption(const wchar_t* ptszParameter)
diff --git a/src/mir_core/src/stdafx.h b/src/mir_core/src/stdafx.h
index 6486e2fbfa..2c57073066 100644
--- a/src/mir_core/src/stdafx.h
+++ b/src/mir_core/src/stdafx.h
@@ -32,6 +32,7 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
#include <windowsx.h>
#include <shlobj.h>
#include <commctrl.h>
+#include <ShellAPI.h>
#include <vssym32.h>
#include <Uxtheme.h>
#include <Richedit.h>