diff options
Diffstat (limited to 'CPP/Common/CommandLineParser.cpp')
| -rw-r--r-- | CPP/Common/CommandLineParser.cpp | 40 |
1 files changed, 37 insertions, 3 deletions
diff --git a/CPP/Common/CommandLineParser.cpp b/CPP/Common/CommandLineParser.cpp index 465e0fd..319f27f 100644 --- a/CPP/Common/CommandLineParser.cpp +++ b/CPP/Common/CommandLineParser.cpp | |||
| @@ -6,6 +6,8 @@ | |||
| 6 | 6 | ||
| 7 | namespace NCommandLineParser { | 7 | namespace NCommandLineParser { |
| 8 | 8 | ||
| 9 | #ifdef _WIN32 | ||
| 10 | |||
| 9 | bool SplitCommandLine(const UString &src, UString &dest1, UString &dest2) | 11 | bool SplitCommandLine(const UString &src, UString &dest1, UString &dest2) |
| 10 | { | 12 | { |
| 11 | dest1.Empty(); | 13 | dest1.Empty(); |
| @@ -14,7 +16,7 @@ bool SplitCommandLine(const UString &src, UString &dest1, UString &dest2) | |||
| 14 | unsigned i; | 16 | unsigned i; |
| 15 | for (i = 0; i < src.Len(); i++) | 17 | for (i = 0; i < src.Len(); i++) |
| 16 | { | 18 | { |
| 17 | wchar_t c = src[i]; | 19 | const wchar_t c = src[i]; |
| 18 | if ((c == L' ' || c == L'\t') && !quoteMode) | 20 | if ((c == L' ' || c == L'\t') && !quoteMode) |
| 19 | { | 21 | { |
| 20 | dest2 = src.Ptr(i + 1); | 22 | dest2 = src.Ptr(i + 1); |
| @@ -30,6 +32,34 @@ bool SplitCommandLine(const UString &src, UString &dest1, UString &dest2) | |||
| 30 | 32 | ||
| 31 | void SplitCommandLine(const UString &s, UStringVector &parts) | 33 | void SplitCommandLine(const UString &s, UStringVector &parts) |
| 32 | { | 34 | { |
| 35 | #if 0 | ||
| 36 | /* we don't use CommandLineToArgvW() because | ||
| 37 | it can remove tail backslash: | ||
| 38 | "1\" | ||
| 39 | converted to | ||
| 40 | 1" | ||
| 41 | */ | ||
| 42 | parts.Clear(); | ||
| 43 | { | ||
| 44 | int nArgs; | ||
| 45 | LPWSTR *szArgList = CommandLineToArgvW(s, &nArgs); | ||
| 46 | if (szArgList) | ||
| 47 | { | ||
| 48 | for (int i = 0; i < nArgs; i++) | ||
| 49 | { | ||
| 50 | // printf("%2d: |%S|\n", i, szArglist[i]); | ||
| 51 | parts.Add(szArgList[i]); | ||
| 52 | } | ||
| 53 | LocalFree(szArgList); | ||
| 54 | return; | ||
| 55 | } | ||
| 56 | } | ||
| 57 | #endif | ||
| 58 | /* | ||
| 59 | #ifdef _UNICODE | ||
| 60 | throw 20240406; | ||
| 61 | #else | ||
| 62 | */ | ||
| 33 | UString sTemp (s); | 63 | UString sTemp (s); |
| 34 | sTemp.Trim(); | 64 | sTemp.Trim(); |
| 35 | parts.Clear(); | 65 | parts.Clear(); |
| @@ -42,7 +72,9 @@ void SplitCommandLine(const UString &s, UStringVector &parts) | |||
| 42 | break; | 72 | break; |
| 43 | sTemp = s2; | 73 | sTemp = s2; |
| 44 | } | 74 | } |
| 75 | // #endif | ||
| 45 | } | 76 | } |
| 77 | #endif | ||
| 46 | 78 | ||
| 47 | 79 | ||
| 48 | static const char * const kStopSwitchParsing = "--"; | 80 | static const char * const kStopSwitchParsing = "--"; |
| @@ -78,7 +110,7 @@ bool CParser::ParseString(const UString &s, const CSwitchForm *switchForms, unsi | |||
| 78 | for (unsigned i = 0; i < numSwitches; i++) | 110 | for (unsigned i = 0; i < numSwitches; i++) |
| 79 | { | 111 | { |
| 80 | const char * const key = switchForms[i].Key; | 112 | const char * const key = switchForms[i].Key; |
| 81 | unsigned switchLen = MyStringLen(key); | 113 | const unsigned switchLen = MyStringLen(key); |
| 82 | if ((int)switchLen <= maxLen || pos + switchLen > s.Len()) | 114 | if ((int)switchLen <= maxLen || pos + switchLen > s.Len()) |
| 83 | continue; | 115 | continue; |
| 84 | if (IsString1PrefixedByString2_NoCase_Ascii((const wchar_t *)s + pos, key)) | 116 | if (IsString1PrefixedByString2_NoCase_Ascii((const wchar_t *)s + pos, key)) |
| @@ -133,7 +165,7 @@ bool CParser::ParseString(const UString &s, const CSwitchForm *switchForms, unsi | |||
| 133 | case NSwitchType::kChar: | 165 | case NSwitchType::kChar: |
| 134 | if (rem == 1) | 166 | if (rem == 1) |
| 135 | { | 167 | { |
| 136 | wchar_t c = s[pos]; | 168 | const wchar_t c = s[pos]; |
| 137 | if (c <= 0x7F) | 169 | if (c <= 0x7F) |
| 138 | { | 170 | { |
| 139 | sw.PostCharIndex = FindCharPosInString(form.PostCharSet, (char)c); | 171 | sw.PostCharIndex = FindCharPosInString(form.PostCharSet, (char)c); |
| @@ -150,6 +182,8 @@ bool CParser::ParseString(const UString &s, const CSwitchForm *switchForms, unsi | |||
| 150 | sw.PostStrings.Add(s.Ptr(pos)); | 182 | sw.PostStrings.Add(s.Ptr(pos)); |
| 151 | return true; | 183 | return true; |
| 152 | } | 184 | } |
| 185 | // case NSwitchType::kSimple: | ||
| 186 | default: break; | ||
| 153 | } | 187 | } |
| 154 | 188 | ||
| 155 | if (pos != s.Len()) | 189 | if (pos != s.Len()) |
