diff options
author | Arttu Tarkiainen <arttu.tarkiainen@qt.io> | 2022-04-06 13:33:38 +0300 |
---|---|---|
committer | Arttu Tarkiainen <arttu.tarkiainen@qt.io> | 2022-04-13 11:32:09 +0300 |
commit | 96ade47c182bf37a2efca2aa62922e54e5ff1660 (patch) | |
tree | 93ceee6c6f8984f563f3dfe83e56f98b66b40f3a /src/libs/7zip/win/CPP/Common | |
parent | 2d5f0ffaf1278516bbd74e3b60f9849f4c51cffa (diff) |
Move LZMA SDK to 3rdparty subdirectory
Also add attribution document.
Task-number: QTIFW-2336
Change-Id: I91546bc6c3ace244e4b546b945f40b7d204f7463
Reviewed-by: Katja Marttila <katja.marttila@qt.io>
Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org>
Diffstat (limited to 'src/libs/7zip/win/CPP/Common')
35 files changed, 0 insertions, 5771 deletions
diff --git a/src/libs/7zip/win/CPP/Common/ComTry.h b/src/libs/7zip/win/CPP/Common/ComTry.h deleted file mode 100644 index c8aa4aedc..000000000 --- a/src/libs/7zip/win/CPP/Common/ComTry.h +++ /dev/null @@ -1,17 +0,0 @@ -// ComTry.h - -#ifndef __COM_TRY_H -#define __COM_TRY_H - -#include "MyWindows.h" -// #include "Exception.h" -// #include "NewHandler.h" - -#define COM_TRY_BEGIN try { -#define COM_TRY_END } catch(...) { return E_OUTOFMEMORY; } - - // catch(const CNewException &) { return E_OUTOFMEMORY; } - // catch(const CSystemException &e) { return e.ErrorCode; } - // catch(...) { return E_FAIL; } - -#endif diff --git a/src/libs/7zip/win/CPP/Common/CommandLineParser.cpp b/src/libs/7zip/win/CPP/Common/CommandLineParser.cpp deleted file mode 100644 index ac9ae1960..000000000 --- a/src/libs/7zip/win/CPP/Common/CommandLineParser.cpp +++ /dev/null @@ -1,198 +0,0 @@ -// CommandLineParser.cpp - -#include "StdAfx.h" - -#include "CommandLineParser.h" - -static bool IsString1PrefixedByString2_NoCase(const wchar_t *u, const char *a) -{ - for (;;) - { - char c = *a; - if (c == 0) - return true; - if (MyCharLower_Ascii(c) != MyCharLower_Ascii(*u)) - return false; - a++; - u++; - } -} - -namespace NCommandLineParser { - -bool SplitCommandLine(const UString &src, UString &dest1, UString &dest2) -{ - dest1.Empty(); - dest2.Empty(); - bool quoteMode = false; - unsigned i; - for (i = 0; i < src.Len(); i++) - { - wchar_t c = src[i]; - if ((c == L' ' || c == L'\t') && !quoteMode) - { - dest2 = src.Ptr(i + 1); - return i != 0; - } - if (c == L'\"') - quoteMode = !quoteMode; - else - dest1 += c; - } - return i != 0; -} - -void SplitCommandLine(const UString &s, UStringVector &parts) -{ - UString sTemp = s; - sTemp.Trim(); - parts.Clear(); - for (;;) - { - UString s1, s2; - if (SplitCommandLine(sTemp, s1, s2)) - parts.Add(s1); - if (s2.IsEmpty()) - break; - sTemp = s2; - } -} - - -static const char *kStopSwitchParsing = "--"; - -static bool inline IsItSwitchChar(wchar_t c) -{ - return (c == '-'); -} - -CParser::CParser(unsigned numSwitches): - _numSwitches(numSwitches), - _switches(0) -{ - _switches = new CSwitchResult[numSwitches]; -} - -CParser::~CParser() -{ - delete []_switches; -} - - -// if (s) contains switch then function updates switch structures -// out: true, if (s) is a switch -bool CParser::ParseString(const UString &s, const CSwitchForm *switchForms) -{ - if (s.IsEmpty() || !IsItSwitchChar(s[0])) - return false; - - unsigned pos = 1; - unsigned switchIndex = 0; - int maxLen = -1; - - for (unsigned i = 0; i < _numSwitches; i++) - { - const char *key = switchForms[i].Key; - unsigned switchLen = MyStringLen(key); - if ((int)switchLen <= maxLen || pos + switchLen > s.Len()) - continue; - if (IsString1PrefixedByString2_NoCase((const wchar_t *)s + pos, key)) - { - switchIndex = i; - maxLen = switchLen; - } - } - - if (maxLen < 0) - { - ErrorMessage = "Unknown switch:"; - return false; - } - - pos += maxLen; - - CSwitchResult &sw = _switches[switchIndex]; - const CSwitchForm &form = switchForms[switchIndex]; - - if (!form.Multi && sw.ThereIs) - { - ErrorMessage = "Multiple instances for switch:"; - return false; - } - - sw.ThereIs = true; - - int rem = s.Len() - pos; - if (rem < form.MinLen) - { - ErrorMessage = "Too short switch:"; - return false; - } - - sw.WithMinus = false; - sw.PostCharIndex = -1; - - switch (form.Type) - { - case NSwitchType::kMinus: - if (rem != 0) - { - sw.WithMinus = (s[pos] == '-'); - if (sw.WithMinus) - pos++; - } - break; - - case NSwitchType::kChar: - if (rem != 0) - { - wchar_t c = s[pos]; - if (c <= 0x7F) - { - sw.PostCharIndex = FindCharPosInString(form.PostCharSet, (char)c); - if (sw.PostCharIndex >= 0) - pos++; - } - } - break; - - case NSwitchType::kString: - sw.PostStrings.Add((const wchar_t *)s + pos); - return true; - } - if (pos != s.Len()) - { - ErrorMessage = "Too long switch:"; - return false; - } - return true; -} - -bool CParser::ParseStrings(const CSwitchForm *switchForms, const UStringVector &commandStrings) -{ - ErrorLine.Empty(); - bool stopSwitch = false; - FOR_VECTOR (i, commandStrings) - { - const UString &s = commandStrings[i]; - if (!stopSwitch) - { - if (s.IsEqualTo(kStopSwitchParsing)) - { - stopSwitch = true; - continue; - } - if (!s.IsEmpty() && IsItSwitchChar(s[0])) - { - if (ParseString(s, switchForms)) - continue; - ErrorLine = s; - return false; - } - } - NonSwitchStrings.Add(s); - } - return true; -} - -} diff --git a/src/libs/7zip/win/CPP/Common/CommandLineParser.h b/src/libs/7zip/win/CPP/Common/CommandLineParser.h deleted file mode 100644 index e3e6e6b14..000000000 --- a/src/libs/7zip/win/CPP/Common/CommandLineParser.h +++ /dev/null @@ -1,63 +0,0 @@ -// Common/CommandLineParser.h - -#ifndef __COMMON_COMMAND_LINE_PARSER_H -#define __COMMON_COMMAND_LINE_PARSER_H - -#include "MyString.h" - -namespace NCommandLineParser { - -bool SplitCommandLine(const UString &src, UString &dest1, UString &dest2); -void SplitCommandLine(const UString &s, UStringVector &parts); - -namespace NSwitchType -{ - enum EEnum - { - kSimple, - kMinus, - kString, - kChar - }; -} - -struct CSwitchForm -{ - const char *Key; - Byte Type; - bool Multi; - Byte MinLen; - // int MaxLen; - const char *PostCharSet; -}; - -struct CSwitchResult -{ - bool ThereIs; - bool WithMinus; - int PostCharIndex; - UStringVector PostStrings; - - CSwitchResult(): ThereIs(false) {}; -}; - -class CParser -{ - unsigned _numSwitches; - CSwitchResult *_switches; - - bool ParseString(const UString &s, const CSwitchForm *switchForms); -public: - UStringVector NonSwitchStrings; - AString ErrorMessage; - UString ErrorLine; - - CParser(unsigned numSwitches); - ~CParser(); - bool ParseStrings(const CSwitchForm *switchForms, const UStringVector &commandStrings); - const CSwitchResult& operator[](size_t index) const { return _switches[index]; } -}; - -} - -#endif diff --git a/src/libs/7zip/win/CPP/Common/Common.h b/src/libs/7zip/win/CPP/Common/Common.h deleted file mode 100644 index 9dd30f4be..000000000 --- a/src/libs/7zip/win/CPP/Common/Common.h +++ /dev/null @@ -1,13 +0,0 @@ -// Common.h - -#ifndef __COMMON_COMMON_H -#define __COMMON_COMMON_H - -#include "../../C/Compiler.h" - -#include "MyWindows.h" -#include "NewHandler.h" - -#define ARRAY_SIZE(a) (sizeof(a) / sizeof((a)[1])) - -#endif diff --git a/src/libs/7zip/win/CPP/Common/Common.pri b/src/libs/7zip/win/CPP/Common/Common.pri deleted file mode 100644 index ecc997d89..000000000 --- a/src/libs/7zip/win/CPP/Common/Common.pri +++ /dev/null @@ -1,35 +0,0 @@ -HEADERS += $$7ZIP_BASE/CPP/Common/CommandLineParser.h \ - $$7ZIP_BASE/CPP/Common/ComTry.h \ - $$7ZIP_BASE/CPP/Common/Common.h \ - $$7ZIP_BASE/CPP/Common/Defs.h \ - $$7ZIP_BASE/CPP/Common/IntToString.h \ - $$7ZIP_BASE/CPP/Common/ListFileUtils.h \ - $$7ZIP_BASE/CPP/Common/MyBuffer.h \ - $$7ZIP_BASE/CPP/Common/MyCom.h \ - $$7ZIP_BASE/CPP/Common/MyException.h \ - $$7ZIP_BASE/CPP/Common/MyGuidDef.h \ - $$7ZIP_BASE/CPP/Common/MyInitGuid.h \ - $$7ZIP_BASE/CPP/Common/MyString.h \ - $$7ZIP_BASE/CPP/Common/MyTypes.h \ - $$7ZIP_BASE/CPP/Common/MyUnknown.h \ - $$7ZIP_BASE/CPP/Common/MyVector.h \ - $$7ZIP_BASE/CPP/Common/MyWindows.h \ - $$7ZIP_BASE/CPP/Common/NewHandler.h \ - $$7ZIP_BASE/CPP/Common/StdAfx.h \ - $$7ZIP_BASE/CPP/Common/StdOutStream.h \ - $$7ZIP_BASE/CPP/Common/StringConvert.h \ - $$7ZIP_BASE/CPP/Common/StringToInt.h \ - $$7ZIP_BASE/CPP/Common/UTFConvert.h \ - $$7ZIP_BASE/CPP/Common/Wildcard.h - -SOURCES += $$7ZIP_BASE/CPP/Common/CommandLineParser.cpp \ - $$7ZIP_BASE/CPP/Common/IntToString.cpp \ - $$7ZIP_BASE/CPP/Common/ListFileUtils.cpp \ - $$7ZIP_BASE/CPP/Common/MyString.cpp \ - $$7ZIP_BASE/CPP/Common/MyWindows.cpp \ - $$7ZIP_BASE/CPP/Common/NewHandler.cpp \ - $$7ZIP_BASE/CPP/Common/StdOutStream.cpp \ - $$7ZIP_BASE/CPP/Common/StringConvert.cpp \ - $$7ZIP_BASE/CPP/Common/StringToInt.cpp \ - $$7ZIP_BASE/CPP/Common/UTFConvert.cpp \ - $$7ZIP_BASE/CPP/Common/Wildcard.cpp diff --git a/src/libs/7zip/win/CPP/Common/Defs.h b/src/libs/7zip/win/CPP/Common/Defs.h deleted file mode 100644 index dad3ae8f1..000000000 --- a/src/libs/7zip/win/CPP/Common/Defs.h +++ /dev/null @@ -1,20 +0,0 @@ -// Common/Defs.h - -#ifndef __COMMON_DEFS_H -#define __COMMON_DEFS_H - -template <class T> inline T MyMin(T a, T b) - { return a < b ? a : b; } -template <class T> inline T MyMax(T a, T b) - { return a > b ? a : b; } - -template <class T> inline int MyCompare(T a, T b) - { return a < b ? -1 : (a == b ? 0 : 1); } - -inline int BoolToInt(bool value) - { return (value ? 1: 0); } - -inline bool IntToBool(int value) - { return (value != 0); } - -#endif diff --git a/src/libs/7zip/win/CPP/Common/IntToString.cpp b/src/libs/7zip/win/CPP/Common/IntToString.cpp deleted file mode 100644 index ed217c72c..000000000 --- a/src/libs/7zip/win/CPP/Common/IntToString.cpp +++ /dev/null @@ -1,146 +0,0 @@ -// Common/IntToString.cpp - -#include "StdAfx.h" - -#include "IntToString.h" - -#define CONVERT_INT_TO_STR(charType, tempSize) \ - unsigned char temp[tempSize]; unsigned i = 0; \ - while (val >= 10) { temp[i++] = (unsigned char)('0' + (unsigned)(val % 10)); val /= 10; } \ - *s++ = (charType)('0' + (unsigned)val); \ - while (i != 0) { i--; *s++ = temp[i]; } \ - *s = 0; - -void ConvertUInt32ToString(UInt32 val, char *s) throw() -{ - CONVERT_INT_TO_STR(char, 16); -} - -void ConvertUInt64ToString(UInt64 val, char *s) throw() -{ - if (val <= (UInt32)0xFFFFFFFF) - { - ConvertUInt32ToString((UInt32)val, s); - return; - } - CONVERT_INT_TO_STR(char, 24); -} - -void ConvertUInt64ToOct(UInt64 val, char *s) throw() -{ - UInt64 v = val; - unsigned i; - for (i = 1;; i++) - { - v >>= 3; - if (v == 0) - break; - } - s[i] = 0; - do - { - unsigned t = (unsigned)(val & 0x7); - val >>= 3; - s[--i] = (char)('0' + t); - } - while (i); -} - -void ConvertUInt32ToHex(UInt32 val, char *s) throw() -{ - UInt32 v = val; - unsigned i; - for (i = 1;; i++) - { - v >>= 4; - if (v == 0) - break; - } - s[i] = 0; - do - { - unsigned t = (unsigned)((val & 0xF)); - val >>= 4; - s[--i] = (char)((t < 10) ? ('0' + t) : ('A' + (t - 10))); - } - while (i); -} - -void ConvertUInt64ToHex(UInt64 val, char *s) throw() -{ - UInt64 v = val; - unsigned i; - for (i = 1;; i++) - { - v >>= 4; - if (v == 0) - break; - } - s[i] = 0; - do - { - unsigned t = (unsigned)((val & 0xF)); - val >>= 4; - s[--i] = (char)((t < 10) ? ('0' + t) : ('A' + (t - 10))); - } - while (i); -} - -void ConvertUInt32ToHex8Digits(UInt32 val, char *s) throw() -{ - s[8] = 0; - for (int i = 7; i >= 0; i--) - { - unsigned t = val & 0xF; - val >>= 4; - s[i] = (char)(((t < 10) ? ('0' + t) : ('A' + (t - 10)))); - } -} - -/* -void ConvertUInt32ToHex8Digits(UInt32 val, wchar_t *s) -{ - s[8] = 0; - for (int i = 7; i >= 0; i--) - { - unsigned t = val & 0xF; - val >>= 4; - s[i] = (wchar_t)(((t < 10) ? ('0' + t) : ('A' + (t - 10)))); - } -} -*/ - -void ConvertUInt32ToString(UInt32 val, wchar_t *s) throw() -{ - CONVERT_INT_TO_STR(wchar_t, 16); -} - -void ConvertUInt64ToString(UInt64 val, wchar_t *s) throw() -{ - if (val <= (UInt32)0xFFFFFFFF) - { - ConvertUInt32ToString((UInt32)val, s); - return; - } - CONVERT_INT_TO_STR(wchar_t, 24); -} - -void ConvertInt64ToString(Int64 val, char *s) throw() -{ - if (val < 0) - { - *s++ = '-'; - val = -val; - } - ConvertUInt64ToString(val, s); -} - -void ConvertInt64ToString(Int64 val, wchar_t *s) throw() -{ - if (val < 0) - { - *s++ = L'-'; - val = -val; - } - ConvertUInt64ToString(val, s); -} diff --git a/src/libs/7zip/win/CPP/Common/IntToString.h b/src/libs/7zip/win/CPP/Common/IntToString.h deleted file mode 100644 index 69605ab76..000000000 --- a/src/libs/7zip/win/CPP/Common/IntToString.h +++ /dev/null @@ -1,24 +0,0 @@ -// Common/IntToString.h - -#ifndef __COMMON_INT_TO_STRING_H -#define __COMMON_INT_TO_STRING_H - -#include "MyTypes.h" - -void ConvertUInt32ToString(UInt32 value, char *s) throw(); -void ConvertUInt64ToString(UInt64 value, char *s) throw(); - -void ConvertUInt32ToString(UInt32 value, wchar_t *s) throw(); -void ConvertUInt64ToString(UInt64 value, wchar_t *s) throw(); - -void ConvertUInt64ToOct(UInt64 value, char *s) throw(); - -void ConvertUInt32ToHex(UInt32 value, char *s) throw(); -void ConvertUInt64ToHex(UInt64 value, char *s) throw(); -void ConvertUInt32ToHex8Digits(UInt32 value, char *s) throw(); -// void ConvertUInt32ToHex8Digits(UInt32 value, wchar_t *s) throw(); - -void ConvertInt64ToString(Int64 value, char *s) throw(); -void ConvertInt64ToString(Int64 value, wchar_t *s) throw(); - -#endif diff --git a/src/libs/7zip/win/CPP/Common/ListFileUtils.cpp b/src/libs/7zip/win/CPP/Common/ListFileUtils.cpp deleted file mode 100644 index 4d7faeca3..000000000 --- a/src/libs/7zip/win/CPP/Common/ListFileUtils.cpp +++ /dev/null @@ -1,117 +0,0 @@ -// Common/ListFileUtils.cpp - -#include "StdAfx.h" - -#include "../../C/CpuArch.h" - -#include "../Windows/FileIO.h" - -#include "ListFileUtils.h" -#include "MyBuffer.h" -#include "StringConvert.h" -#include "UTFConvert.h" - -static const char kQuoteChar = '\"'; - -static void AddName(UStringVector &strings, UString &s) -{ - s.Trim(); - if (s.Len() >= 2 && s[0] == kQuoteChar && s.Back() == kQuoteChar) - { - s.DeleteBack(); - s.Delete(0); - } - if (!s.IsEmpty()) - strings.Add(s); -} - -bool ReadNamesFromListFile(CFSTR fileName, UStringVector &strings, UINT codePage) -{ - NWindows::NFile::NIO::CInFile file; - if (!file.Open(fileName)) - return false; - UInt64 fileSize; - if (!file.GetLength(fileSize)) - return false; - if (fileSize >= ((UInt32)1 << 31) - 32) - return false; - UString u; - if (codePage == MY__CP_UTF16 || codePage == MY__CP_UTF16BE) - { - if ((fileSize & 1) != 0) - return false; - CByteArr buf((size_t)fileSize); - UInt32 processed; - if (!file.Read(buf, (UInt32)fileSize, processed)) - return false; - if (processed != fileSize) - return false; - file.Close(); - unsigned num = (unsigned)fileSize / 2; - wchar_t *p = u.GetBuffer(num); - if (codePage == MY__CP_UTF16) - for (unsigned i = 0; i < num; i++) - { - wchar_t c = GetUi16(buf + i * 2); - if (c == 0) - return false; - p[i] = c; - } - else - for (unsigned i = 0; i < num; i++) - { - wchar_t c = (wchar_t)GetBe16(buf + i * 2); - if (c == 0) - return false; - p[i] = c; - } - u.ReleaseBuffer(num); - } - else - { - AString s; - char *p = s.GetBuffer((unsigned)fileSize); - UInt32 processed; - if (!file.Read(p, (UInt32)fileSize, processed)) - return false; - if (processed != fileSize) - return false; - file.Close(); - p[processed] = 0; - s.ReleaseBuffer(); - if (s.Len() != processed) - return false; - - // #ifdef CP_UTF8 - if (codePage == CP_UTF8) - { - if (!ConvertUTF8ToUnicode(s, u)) - return false; - } - else - // #endif - MultiByteToUnicodeString2(u, s, codePage); - } - - const wchar_t kGoodBOM = 0xFEFF; - const wchar_t kBadBOM = 0xFFFE; - - UString s; - unsigned i = 0; - for (; i < u.Len() && u[i] == kGoodBOM; i++); - for (; i < u.Len(); i++) - { - wchar_t c = u[i]; - if (c == kGoodBOM || c == kBadBOM) - return false; - if (c == L'\n' || c == 0xD) - { - AddName(strings, s); - s.Empty(); - } - else - s += c; - } - AddName(strings, s); - return true; -} diff --git a/src/libs/7zip/win/CPP/Common/ListFileUtils.h b/src/libs/7zip/win/CPP/Common/ListFileUtils.h deleted file mode 100644 index e8d833fdb..000000000 --- a/src/libs/7zip/win/CPP/Common/ListFileUtils.h +++ /dev/null @@ -1,14 +0,0 @@ -// Common/ListFileUtils.h - -#ifndef __COMMON_LIST_FILE_UTILS_H -#define __COMMON_LIST_FILE_UTILS_H - -#include "MyString.h" -#include "MyTypes.h" - -#define MY__CP_UTF16 1200 -#define MY__CP_UTF16BE 1201 - -bool ReadNamesFromListFile(CFSTR fileName, UStringVector &strings, UINT codePage = CP_OEMCP); - -#endif diff --git a/src/libs/7zip/win/CPP/Common/MyBuffer.h b/src/libs/7zip/win/CPP/Common/MyBuffer.h deleted file mode 100644 index 7bd79f6f4..000000000 --- a/src/libs/7zip/win/CPP/Common/MyBuffer.h +++ /dev/null @@ -1,237 +0,0 @@ -// Common/MyBuffer.h - -#ifndef __COMMON_MY_BUFFER_H -#define __COMMON_MY_BUFFER_H - -#include "Defs.h" - -template <class T> class CBuffer -{ - T *_items; - size_t _size; - - void CopyToEmpty(const CBuffer &buffer) - { - if (buffer._size > 0) - { - _items = new T[buffer._size]; - memcpy(_items, buffer._items, buffer._size * sizeof(T)); - _size = buffer._size; - } - } -public: - void Free() - { - if (_items) - { - delete []_items; - _items = 0; - } - _size = 0; - } - - CBuffer(): _items(0), _size(0) {}; - CBuffer(size_t size): _items(0), _size(0) { _items = new T[size]; _size = size; } - CBuffer(const CBuffer &buffer): _items(0), _size(0) { CopyToEmpty(buffer); } - ~CBuffer() { delete []_items; } - - operator T *() { return _items; }; - operator const T *() const { return _items; }; - size_t Size() const { return _size; } - - void Alloc(size_t size) - { - if (size != _size) - { - Free(); - if (size != 0) - { - _items = new T[size]; - _size = size; - } - } - } - - void AllocAtLeast(size_t size) - { - if (size > _size) - { - Free(); - _items = new T[size]; - _size = size; - } - } - - void CopyFrom(const T *data, size_t size) - { - Alloc(size); - memcpy(_items, data, size * sizeof(T)); - } - - void ChangeSize_KeepData(size_t newSize, size_t keepSize) - { - if (newSize == _size) - return; - T *newBuffer = NULL; - if (newSize > 0) - { - newBuffer = new T[newSize]; - if (_size > 0) - memcpy(newBuffer, _items, MyMin(MyMin(_size, keepSize), newSize) * sizeof(T)); - } - delete []_items; - _items = newBuffer; - _size = newSize; - } - - CBuffer& operator=(const CBuffer &buffer) - { - Free(); - CopyToEmpty(buffer); - return *this; - } -}; - -template <class T> -bool operator==(const CBuffer<T>& b1, const CBuffer<T>& b2) -{ - size_t size1 = b1.Size(); - if (size1 != b2.Size()) - return false; - return memcmp(b1, b2, size1 * sizeof(T)) == 0; -} - -template <class T> -bool operator!=(const CBuffer<T>& b1, const CBuffer<T>& b2) -{ - size_t size1 = b1.Size(); - if (size1 == b2.Size()) - return false; - return memcmp(b1, b2, size1 * sizeof(T)) != 0; -} - - -typedef CBuffer<char> CCharBuffer; -typedef CBuffer<wchar_t> CWCharBuffer; -typedef CBuffer<unsigned char> CByteBuffer; - - -template <class T> class CObjArray -{ -protected: - T *_items; -private: - // we disable constructors - CObjArray(const CObjArray &buffer); - void operator=(const CObjArray &buffer); -public: - void Free() - { - delete []_items; - _items = 0; - } - CObjArray(size_t size): _items(0) { if (size != 0) _items = new T[size]; } - CObjArray(): _items(0) {}; - ~CObjArray() { delete []_items; } - - operator T *() { return _items; }; - operator const T *() const { return _items; }; - - void Alloc(size_t newSize) - { - delete []_items; - _items = 0; - _items = new T[newSize]; - } -}; - -typedef CObjArray<unsigned char> CByteArr; -typedef CObjArray<bool> CBoolArr; -typedef CObjArray<int> CIntArr; - -// #define CRecArray CObjArray - -template <class T> class CObjArray2 -{ -// protected: - T *_items; - unsigned _size; - - CObjArray2(const CObjArray2 &buffer); - void operator=(const CObjArray2 &buffer); -public: - - void Free() - { - delete []_items; - _items = 0; - _size = 0; - } - CObjArray2(): _items(0), _size(0) {}; - /* - CObjArray2(const CObjArray2 &buffer): _items(0), _size(0) - { - size_t newSize = buffer._size; - if (newSize > 0) - { - T *newBuffer = new T[newSize];; - _items = newBuffer; - _size = newSize; - const T *src = buffer; - for (size_t i = 0; i < newSize; i++) - newBuffer[i] = src[i]; - } - } - */ - /* - CObjArray2(size_t size): _items(0), _size(0) - { - if (size != 0) - { - _items = new T[size]; - _size = size; - } - } - */ - - ~CObjArray2() { delete []_items; } - - operator T *() { return _items; }; - operator const T *() const { return _items; }; - - unsigned Size() const { return (unsigned)_size; } - bool IsEmpty() const { return _size == 0; } - - // SetSize doesn't keep old items. It allocates new array if size is not equal - void SetSize(unsigned size) - { - if (size == _size) - return; - T *newBuffer = NULL; - if (size > 0) - newBuffer = new T[size]; - delete []_items; - _items = newBuffer; - _size = size; - } - - /* - CObjArray2& operator=(const CObjArray2 &buffer) - { - Free(); - size_t newSize = buffer._size; - if (newSize > 0) - { - T *newBuffer = new T[newSize];; - _items = newBuffer; - _size = newSize; - const T *src = buffer; - for (size_t i = 0; i < newSize; i++) - newBuffer[i] = src[i]; - } - return *this; - } - */ -}; - -#endif diff --git a/src/libs/7zip/win/CPP/Common/MyCom.h b/src/libs/7zip/win/CPP/Common/MyCom.h deleted file mode 100644 index 466407cde..000000000 --- a/src/libs/7zip/win/CPP/Common/MyCom.h +++ /dev/null @@ -1,242 +0,0 @@ -// MyCom.h - -#ifndef __MY_COM_H -#define __MY_COM_H - -#include "MyWindows.h" -#include "NewHandler.h" - -#ifndef RINOK -#define RINOK(x) { HRESULT __result_ = (x); if (__result_ != S_OK) return __result_; } -#endif - -template <class T> -class CMyComPtr -{ - T* _p; -public: - CMyComPtr(): _p(NULL) {} - CMyComPtr(T* p) throw() { if ((_p = p) != NULL) p->AddRef(); } - CMyComPtr(const CMyComPtr<T>& lp) throw() { if ((_p = lp._p) != NULL) _p->AddRef(); } - ~CMyComPtr() { if (_p) _p->Release(); } - void Release() { if (_p) { _p->Release(); _p = NULL; } } - operator T*() const { return (T*)_p; } - // T& operator*() const { return *_p; } - T** operator&() { return &_p; } - T* operator->() const { return _p; } - T* operator=(T* p) - { - if (p) - p->AddRef(); - if (_p) - _p->Release(); - _p = p; - return p; - } - T* operator=(const CMyComPtr<T>& lp) { return (*this = lp._p); } - bool operator!() const { return (_p == NULL); } - // bool operator==(T* pT) const { return _p == pT; } - void Attach(T* p2) - { - Release(); - _p = p2; - } - T* Detach() - { - T* pt = _p; - _p = NULL; - return pt; - } - #ifdef _WIN32 - HRESULT CoCreateInstance(REFCLSID rclsid, REFIID iid, LPUNKNOWN pUnkOuter = NULL, DWORD dwClsContext = CLSCTX_ALL) - { - return ::CoCreateInstance(rclsid, pUnkOuter, dwClsContext, iid, (void**)&_p); - } - #endif - /* - HRESULT CoCreateInstance(LPCOLESTR szProgID, LPUNKNOWN pUnkOuter = NULL, DWORD dwClsContext = CLSCTX_ALL) - { - CLSID clsid; - HRESULT hr = CLSIDFromProgID(szProgID, &clsid); - ATLASSERT(_p == NULL); - if (SUCCEEDED(hr)) - hr = ::CoCreateInstance(clsid, pUnkOuter, dwClsContext, __uuidof(T), (void**)&_p); - return hr; - } - */ - template <class Q> - HRESULT QueryInterface(REFGUID iid, Q** pp) const throw() - { - return _p->QueryInterface(iid, (void**)pp); - } -}; - -////////////////////////////////////////////////////////// - -inline HRESULT StringToBstr(LPCOLESTR src, BSTR *bstr) -{ - *bstr = ::SysAllocString(src); - return (*bstr != NULL) ? S_OK : E_OUTOFMEMORY; -} - -class CMyComBSTR -{ - BSTR m_str; -public: - - CMyComBSTR(): m_str(NULL) {} - CMyComBSTR(LPCOLESTR src) { m_str = ::SysAllocString(src); } - // CMyComBSTR(int nSize) { m_str = ::SysAllocStringLen(NULL, nSize); } - // CMyComBSTR(int nSize, LPCOLESTR sz) { m_str = ::SysAllocStringLen(sz, nSize); } - CMyComBSTR(const CMyComBSTR& src) { m_str = src.MyCopy(); } - /* - CMyComBSTR(REFGUID src) - { - LPOLESTR szGuid; - StringFromCLSID(src, &szGuid); - m_str = ::SysAllocString(szGuid); - CoTaskMemFree(szGuid); - } - */ - ~CMyComBSTR() { ::SysFreeString(m_str); } - CMyComBSTR& operator=(const CMyComBSTR& src) - { - if (m_str != src.m_str) - { - if (m_str) - ::SysFreeString(m_str); - m_str = src.MyCopy(); - } - return *this; - } - CMyComBSTR& operator=(LPCOLESTR src) - { - ::SysFreeString(m_str); - m_str = ::SysAllocString(src); - return *this; - } - // unsigned Len() const { return ::SysStringLen(m_str); } - operator BSTR() const { return m_str; } - BSTR* operator&() { return &m_str; } - BSTR MyCopy() const - { - int byteLen = ::SysStringByteLen(m_str); - BSTR res = ::SysAllocStringByteLen(NULL, byteLen); - memcpy(res, m_str, byteLen); - return res; - } - /* - void Attach(BSTR src) { m_str = src; } - BSTR Detach() - { - BSTR s = m_str; - m_str = NULL; - return s; - } - */ - void Empty() - { - ::SysFreeString(m_str); - m_str = NULL; - } - bool operator!() const { return (m_str == NULL); } -}; - -////////////////////////////////////////////////////////// - -class CMyUnknownImp -{ -public: - ULONG __m_RefCount; - CMyUnknownImp(): __m_RefCount(0) {} -}; - -#define MY_QUERYINTERFACE_BEGIN STDMETHOD(QueryInterface) \ -(REFGUID iid, void **outObject) throw() { *outObject = NULL; - -#define MY_QUERYINTERFACE_ENTRY(i) else if (iid == IID_ ## i) \ - { *outObject = (void *)(i *)this; } - -#define MY_QUERYINTERFACE_ENTRY_UNKNOWN(i) if (iid == IID_IUnknown) \ - { *outObject = (void *)(IUnknown *)(i *)this; } - -#define MY_QUERYINTERFACE_BEGIN2(i) MY_QUERYINTERFACE_BEGIN \ - MY_QUERYINTERFACE_ENTRY_UNKNOWN(i) \ - MY_QUERYINTERFACE_ENTRY(i) - -#define MY_QUERYINTERFACE_END else return E_NOINTERFACE; AddRef(); return S_OK; } - -#define MY_ADDREF_RELEASE \ -STDMETHOD_(ULONG, AddRef)() throw() { return ++__m_RefCount; } \ -STDMETHOD_(ULONG, Release)() { if (--__m_RefCount != 0) \ - return __m_RefCount; delete this; return 0; } - -#define MY_UNKNOWN_IMP_SPEC(i) \ - MY_QUERYINTERFACE_BEGIN \ - i \ - MY_QUERYINTERFACE_END \ - MY_ADDREF_RELEASE - - -#define MY_UNKNOWN_IMP MY_QUERYINTERFACE_BEGIN \ - MY_QUERYINTERFACE_ENTRY_UNKNOWN(IUnknown) \ - MY_QUERYINTERFACE_END \ - MY_ADDREF_RELEASE - -#define MY_UNKNOWN_IMP1(i) MY_UNKNOWN_IMP_SPEC( \ - MY_QUERYINTERFACE_ENTRY_UNKNOWN(i) \ - MY_QUERYINTERFACE_ENTRY(i) \ - ) - -#define MY_UNKNOWN_IMP2(i1, i2) MY_UNKNOWN_IMP_SPEC( \ - MY_QUERYINTERFACE_ENTRY_UNKNOWN(i1) \ - MY_QUERYINTERFACE_ENTRY(i1) \ - MY_QUERYINTERFACE_ENTRY(i2) \ - ) - -#define MY_UNKNOWN_IMP3(i1, i2, i3) MY_UNKNOWN_IMP_SPEC( \ - MY_QUERYINTERFACE_ENTRY_UNKNOWN(i1) \ - MY_QUERYINTERFACE_ENTRY(i1) \ - MY_QUERYINTERFACE_ENTRY(i2) \ - MY_QUERYINTERFACE_ENTRY(i3) \ - ) - -#define MY_UNKNOWN_IMP4(i1, i2, i3, i4) MY_UNKNOWN_IMP_SPEC( \ - MY_QUERYINTERFACE_ENTRY_UNKNOWN(i1) \ - MY_QUERYINTERFACE_ENTRY(i1) \ - MY_QUERYINTERFACE_ENTRY(i2) \ - MY_QUERYINTERFACE_ENTRY(i3) \ - MY_QUERYINTERFACE_ENTRY(i4) \ - ) - -#define MY_UNKNOWN_IMP5(i1, i2, i3, i4, i5) MY_UNKNOWN_IMP_SPEC( \ - MY_QUERYINTERFACE_ENTRY_UNKNOWN(i1) \ - MY_QUERYINTERFACE_ENTRY(i1) \ - MY_QUERYINTERFACE_ENTRY(i2) \ - MY_QUERYINTERFACE_ENTRY(i3) \ - MY_QUERYINTERFACE_ENTRY(i4) \ - MY_QUERYINTERFACE_ENTRY(i5) \ - ) - -#define MY_UNKNOWN_IMP6(i1, i2, i3, i4, i5, i6) MY_UNKNOWN_IMP_SPEC( \ - MY_QUERYINTERFACE_ENTRY_UNKNOWN(i1) \ - MY_QUERYINTERFACE_ENTRY(i1) \ - MY_QUERYINTERFACE_ENTRY(i2) \ - MY_QUERYINTERFACE_ENTRY(i3) \ - MY_QUERYINTERFACE_ENTRY(i4) \ - MY_QUERYINTERFACE_ENTRY(i5) \ - MY_QUERYINTERFACE_ENTRY(i6) \ - ) - -#define MY_UNKNOWN_IMP7(i1, i2, i3, i4, i5, i6, i7) MY_UNKNOWN_IMP_SPEC( \ - MY_QUERYINTERFACE_ENTRY_UNKNOWN(i1) \ - MY_QUERYINTERFACE_ENTRY(i1) \ - MY_QUERYINTERFACE_ENTRY(i2) \ - MY_QUERYINTERFACE_ENTRY(i3) \ - MY_QUERYINTERFACE_ENTRY(i4) \ - MY_QUERYINTERFACE_ENTRY(i5) \ - MY_QUERYINTERFACE_ENTRY(i6) \ - MY_QUERYINTERFACE_ENTRY(i7) \ - ) - -#endif diff --git a/src/libs/7zip/win/CPP/Common/MyException.h b/src/libs/7zip/win/CPP/Common/MyException.h deleted file mode 100644 index f0ad11158..000000000 --- a/src/libs/7zip/win/CPP/Common/MyException.h +++ /dev/null @@ -1,14 +0,0 @@ -// Common/Exception.h - -#ifndef __COMMON_EXCEPTION_H -#define __COMMON_EXCEPTION_H - -#include "MyWindows.h" - -struct CSystemException -{ - HRESULT ErrorCode; - CSystemException(HRESULT errorCode): ErrorCode(errorCode) {} -}; - -#endif diff --git a/src/libs/7zip/win/CPP/Common/MyGuidDef.h b/src/libs/7zip/win/CPP/Common/MyGuidDef.h deleted file mode 100644 index 68745870e..000000000 --- a/src/libs/7zip/win/CPP/Common/MyGuidDef.h +++ /dev/null @@ -1,54 +0,0 @@ -// Common/MyGuidDef.h - -#ifndef GUID_DEFINED -#define GUID_DEFINED - -#include "MyTypes.h" - -typedef struct { - UInt32 Data1; - UInt16 Data2; - UInt16 Data3; - unsigned char Data4[8]; -} GUID; - -#ifdef __cplusplus -#define REFGUID const GUID & -#else -#define REFGUID const GUID * -#endif - -#define REFCLSID REFGUID -#define REFIID REFGUID - -#ifdef __cplusplus -inline int operator==(REFGUID g1, REFGUID g2) -{ - for (int i = 0; i < (int)sizeof(g1); i++) - if (((unsigned char *)&g1)[i] != ((unsigned char *)&g2)[i]) - return 0; - return 1; -} -inline int operator!=(REFGUID g1, REFGUID g2) { return !(g1 == g2); } -#endif - -#ifdef __cplusplus - #define MY_EXTERN_C extern "C" -#else - #define MY_EXTERN_C extern -#endif - -#endif - - -#ifdef DEFINE_GUID -#undef DEFINE_GUID -#endif - -#ifdef INITGUID - #define DEFINE_GUID(name, l, w1, w2, b1, b2, b3, b4, b5, b6, b7, b8) \ - MY_EXTERN_C const GUID name = { l, w1, w2, { b1, b2, b3, b4, b5, b6, b7, b8 } } -#else - #define DEFINE_GUID(name, l, w1, w2, b1, b2, b3, b4, b5, b6, b7, b8) \ - MY_EXTERN_C const GUID name -#endif diff --git a/src/libs/7zip/win/CPP/Common/MyInitGuid.h b/src/libs/7zip/win/CPP/Common/MyInitGuid.h deleted file mode 100644 index 279fba5d6..000000000 --- a/src/libs/7zip/win/CPP/Common/MyInitGuid.h +++ /dev/null @@ -1,45 +0,0 @@ -// Common/MyInitGuid.h - -#ifndef __COMMON_MY_INITGUID_H -#define __COMMON_MY_INITGUID_H - -/* -This file must be included only to one C++ file in project before -declarations of COM interfaces with DEFINE_GUID macro. - -Each GUID must be initialized exactly once in project. -There are two different versions of the DEFINE_GUID macro in guiddef.h (MyGuidDef.h): - - if INITGUID is not defined: DEFINE_GUID declares an external reference to the symbol name. - - if INITGUID is defined: DEFINE_GUID initializes the symbol name to the value of the GUID. - -Also we need IID_IUnknown that is initialized in some file for linking: - MSVC: by default the linker uses some lib file that contains IID_IUnknown - MinGW: add -luuid switch for linker - WinCE: we define IID_IUnknown in this file - Other: we define IID_IUnknown in this file -*/ - -#ifdef _WIN32 - -#ifdef UNDER_CE -#include <basetyps.h> -#endif - -#include <initguid.h> - -#ifdef UNDER_CE -DEFINE_GUID(IID_IUnknown, -0x00000000, 0x0000, 0x0000, 0xC0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x46); -#endif - -#else - -#define INITGUID -#include "MyGuidDef.h" -DEFINE_GUID(IID_IUnknown, -0x00000000, 0x0000, 0x0000, 0xC0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x46); - -#endif - - -#endif diff --git a/src/libs/7zip/win/CPP/Common/MyString.cpp b/src/libs/7zip/win/CPP/Common/MyString.cpp deleted file mode 100644 index 6fbfa334b..000000000 --- a/src/libs/7zip/win/CPP/Common/MyString.cpp +++ /dev/null @@ -1,1215 +0,0 @@ -// Common/MyString.cpp - -#include "StdAfx.h" - -#ifdef _WIN32 -#include <windows.h> -#include <wchar.h> -#else -#include <ctype.h> -#endif - -#if !defined(_UNICODE) || !defined(USE_UNICODE_FSTRING) -#include "StringConvert.h" -#endif - -#include "MyString.h" - -#define MY_STRING_NEW(_T_, _size_) new _T_[_size_] -// #define MY_STRING_NEW(_T_, _size_) ((_T_ *)my_new((size_t)(_size_) * sizeof(_T_))) - -/* -inline const char* MyStringGetNextCharPointer(const char *p) throw() -{ - #if defined(_WIN32) && !defined(UNDER_CE) - return CharNextA(p); - #else - return p + 1; - #endif -} -*/ - -int FindCharPosInString(const char *s, char c) throw() -{ - for (const char *p = s;; p++) - { - if (*p == c) - return (int)(p - s); - if (*p == 0) - return -1; - // MyStringGetNextCharPointer(p); - } -} - -int FindCharPosInString(const wchar_t *s, wchar_t c) throw() -{ - for (const wchar_t *p = s;; p++) - { - if (*p == c) - return (int)(p - s); - if (*p == 0) - return -1; - } -} - -/* -void MyStringUpper_Ascii(wchar_t *s) -{ - for (;;) - { - wchar_t c = *s; - if (c == 0) - return; - *s++ = MyCharUpper_Ascii(c); - } -} -*/ - -void MyStringLower_Ascii(wchar_t *s) throw() -{ - for (;;) - { - wchar_t c = *s; - if (c == 0) - return; - *s++ = MyCharLower_Ascii(c); - } -} - -#ifdef _WIN32 - -#ifdef _UNICODE - -// wchar_t * MyStringUpper(wchar_t *s) { return CharUpperW(s); } -// wchar_t * MyStringLower(wchar_t *s) { return CharLowerW(s); } -// for WinCE - FString - char -// const char *MyStringGetPrevCharPointer(const char * /* base */, const char *p) { return p - 1; } - -#else - -// const char * MyStringGetPrevCharPointer(const char *base, const char *p) throw() { return CharPrevA(base, p); } -// char * MyStringUpper(char *s) { return CharUpperA(s); } -// char * MyStringLower(char *s) { return CharLowerA(s); } - -wchar_t MyCharUpper_WIN(wchar_t c) throw() -{ - wchar_t *res = CharUpperW((LPWSTR)(UINT_PTR)(unsigned)c); - if (res != 0 || ::GetLastError() != ERROR_CALL_NOT_IMPLEMENTED) - return (wchar_t)(unsigned)(UINT_PTR)res; - const int kBufSize = 4; - char s[kBufSize + 1]; - int numChars = ::WideCharToMultiByte(CP_ACP, 0, &c, 1, s, kBufSize, 0, 0); - if (numChars == 0 || numChars > kBufSize) - return c; - s[numChars] = 0; - ::CharUpperA(s); - ::MultiByteToWideChar(CP_ACP, 0, s, numChars, &c, 1); - return c; -} - -/* -wchar_t MyCharLower_WIN(wchar_t c) -{ - wchar_t *res = CharLowerW((LPWSTR)(UINT_PTR)(unsigned)c); - if (res != 0 || ::GetLastError() != ERROR_CALL_NOT_IMPLEMENTED) - return (wchar_t)(unsigned)(UINT_PTR)res; - const int kBufSize = 4; - char s[kBufSize + 1]; - int numChars = ::WideCharToMultiByte(CP_ACP, 0, &c, 1, s, kBufSize, 0, 0); - if (numChars == 0 || numChars > kBufSize) - return c; - s[numChars] = 0; - ::CharLowerA(s); - ::MultiByteToWideChar(CP_ACP, 0, s, numChars, &c, 1); - return c; -} -*/ - -/* -wchar_t * MyStringUpper(wchar_t *s) -{ - if (s == 0) - return 0; - wchar_t *res = CharUpperW(s); - if (res != 0 || ::GetLastError() != ERROR_CALL_NOT_IMPLEMENTED) - return res; - AString a = UnicodeStringToMultiByte(s); - a.MakeUpper(); - MyStringCopy(s, (const wchar_t *)MultiByteToUnicodeString(a)); - return s; -} -*/ - -/* -wchar_t * MyStringLower(wchar_t *s) -{ - if (s == 0) - return 0; - wchar_t *res = CharLowerW(s); - if (res != 0 || ::GetLastError() != ERROR_CALL_NOT_IMPLEMENTED) - return res; - AString a = UnicodeStringToMultiByte(s); - a.MakeLower(); - MyStringCopy(s, (const wchar_t *)MultiByteToUnicodeString(a)); - return s; -} -*/ - -#endif - -#endif - -bool IsString1PrefixedByString2(const char *s1, const char *s2) throw() -{ - for (;;) - { - unsigned char c2 = (unsigned char)*s2++; if (c2 == 0) return true; - unsigned char c1 = (unsigned char)*s1++; if (c1 != c2) return false; - } -} - -bool StringsAreEqualNoCase(const wchar_t *s1, const wchar_t *s2) throw() -{ - for (;;) - { - wchar_t c1 = *s1++; - wchar_t c2 = *s2++; - if (c1 != c2 && MyCharUpper(c1) != MyCharUpper(c2)) return false; - if (c1 == 0) return true; - } -} - -// ---------- ASCII ---------- - -bool AString::IsPrefixedBy_Ascii_NoCase(const char *s) const throw() -{ - const char *s1 = _chars; - for (;;) - { - char c2 = *s++; - if (c2 == 0) - return true; - char c1 = *s1++; - if (MyCharLower_Ascii(c1) != - MyCharLower_Ascii(c2)) - return false; - } -} - -bool UString::IsPrefixedBy_Ascii_NoCase(const char *s) const throw() -{ - const wchar_t *s1 = _chars; - for (;;) - { - char c2 = *s++; - if (c2 == 0) - return true; - wchar_t c1 = *s1++; - if (MyCharLower_Ascii(c1) != (unsigned char)MyCharLower_Ascii(c2)) - return false; - } -} - -bool StringsAreEqual_Ascii(const wchar_t *u, const char *a) throw() -{ - for (;;) - { - unsigned char c = *a; - if (c != *u) - return false; - if (c == 0) - return true; - a++; - u++; - } -} - -bool StringsAreEqualNoCase_Ascii(const char *s1, const char *s2) throw() -{ - for (;;) - { - char c1 = *s1++; - char c2 = *s2++; - if (c1 != c2 && MyCharLower_Ascii(c1) != MyCharLower_Ascii(c2)) - return false; - if (c1 == 0) - return true; - } -} - -bool StringsAreEqualNoCase_Ascii(const wchar_t *s1, const wchar_t *s2) throw() -{ - for (;;) - { - wchar_t c1 = *s1++; - wchar_t c2 = *s2++; - if (c1 != c2 && MyCharLower_Ascii(c1) != MyCharLower_Ascii(c2)) - return false; - if (c1 == 0) - return true; - } -} - -bool StringsAreEqualNoCase_Ascii(const wchar_t *s1, const char *s2) throw() -{ - for (;;) - { - wchar_t c1 = *s1++; - char c2 = *s2++; - if (c1 != (unsigned char)c2 && (c1 > 0x7F || MyCharLower_Ascii(c1) != (unsigned char)MyCharLower_Ascii(c2))) - return false; - if (c1 == 0) - return true; - } -} - -bool IsString1PrefixedByString2(const wchar_t *s1, const wchar_t *s2) throw() -{ - for (;;) - { - wchar_t c2 = *s2++; if (c2 == 0) return true; - wchar_t c1 = *s1++; if (c1 != c2) return false; - } -} - -// NTFS order: uses upper case -int MyStringCompareNoCase(const wchar_t *s1, const wchar_t *s2) throw() -{ - for (;;) - { - wchar_t c1 = *s1++; - wchar_t c2 = *s2++; - if (c1 != c2) - { - wchar_t u1 = MyCharUpper(c1); - wchar_t u2 = MyCharUpper(c2); - if (u1 < u2) return -1; - if (u1 > u2) return 1; - } - if (c1 == 0) return 0; - } -} - -int MyStringCompareNoCase_N(const wchar_t *s1, const wchar_t *s2, unsigned num) throw() -{ - for (; num != 0; num--) - { - wchar_t c1 = *s1++; - wchar_t c2 = *s2++; - if (c1 != c2) - { - wchar_t u1 = MyCharUpper(c1); - wchar_t u2 = MyCharUpper(c2); - if (u1 < u2) return -1; - if (u1 > u2) return 1; - } - if (c1 == 0) return 0; - } - return 0; -} - - -// ---------- AString ---------- - -void AString::InsertSpace(unsigned &index, unsigned size) -{ - Grow(size); - MoveItems(index + size, index); -} - -void AString::ReAlloc(unsigned newLimit) -{ - if (newLimit < _len || newLimit >= 0x20000000) throw 20130220; - // MY_STRING_REALLOC(_chars, char, newLimit + 1, _len + 1); - char *newBuf = MY_STRING_NEW(char, newLimit + 1); - memcpy(newBuf, _chars, (size_t)(_len + 1)); \ - MY_STRING_DELETE(_chars); - _chars = newBuf; - - _limit = newLimit; -} - -void AString::SetStartLen(unsigned len) -{ - _chars = 0; - _chars = MY_STRING_NEW(char, len + 1); - _len = len; - _limit = len; -} - -void AString::Grow_1() -{ - unsigned next = _len; - next += next / 2; - next += 16; - next &= ~(unsigned)15; - ReAlloc(next - 1); -} - -void AString::Grow(unsigned n) -{ - unsigned freeSize = _limit - _len; - if (n <= freeSize) - return; - - unsigned next = _len + n; - next += next / 2; - next += 16; - next &= ~(unsigned)15; - ReAlloc(next - 1); -} - -/* -AString::AString(unsigned num, const char *s) -{ - unsigned len = MyStringLen(s); - if (num > len) - num = len; - SetStartLen(num); - memcpy(_chars, s, num); - _chars[num] = 0; -} -*/ - -AString::AString(unsigned num, const AString &s) -{ - if (num > s._len) - num = s._len; - SetStartLen(num); - memcpy(_chars, s._chars, num); - _chars[num] = 0; -} - -AString::AString(const AString &s, char c) -{ - SetStartLen(s.Len() + 1); - char *chars = _chars; - unsigned len = s.Len(); - memcpy(chars, s, len); - chars[len] = c; - chars[len + 1] = 0; -} - -AString::AString(const char *s1, unsigned num1, const char *s2, unsigned num2) -{ - SetStartLen(num1 + num2); - char *chars = _chars; - memcpy(chars, s1, num1); - memcpy(chars + num1, s2, num2 + 1); -} - -AString operator+(const AString &s1, const AString &s2) { return AString(s1, s1.Len(), s2, s2.Len()); } -AString operator+(const AString &s1, const char *s2) { return AString(s1, s1.Len(), s2, MyStringLen(s2)); } -AString operator+(const char *s1, const AString &s2) { return AString(s1, MyStringLen(s1), s2, s2.Len()); } - -AString::AString() -{ - _chars = 0; - _chars = MY_STRING_NEW(char, 4); - _len = 0; - _limit = 4 - 1; - _chars[0] = 0; -} - -AString::AString(char c) -{ - SetStartLen(1); - _chars[0] = c; - _chars[1] = 0; -} - -AString::AString(const char *s) -{ - SetStartLen(MyStringLen(s)); - MyStringCopy(_chars, s); -} - -AString::AString(const AString &s) -{ - SetStartLen(s._len); - MyStringCopy(_chars, s._chars); -} - -AString &AString::operator=(char c) -{ - if (1 > _limit) - { - char *newBuf = MY_STRING_NEW(char, 1 + 1); - MY_STRING_DELETE(_chars); - _chars = newBuf; - _limit = 1; - } - _len = 1; - _chars[0] = c; - _chars[1] = 0; - return *this; -} - -AString &AString::operator=(const char *s) -{ - unsigned len = MyStringLen(s); - if (len > _limit) - { - char *newBuf = MY_STRING_NEW(char, len + 1); - MY_STRING_DELETE(_chars); - _chars = newBuf; - _limit = len; - } - _len = len; - MyStringCopy(_chars, s); - return *this; -} - -AString &AString::operator=(const AString &s) -{ - if (&s == this) - return *this; - unsigned len = s._len; - if (len > _limit) - { - char *newBuf = MY_STRING_NEW(char, len + 1); - MY_STRING_DELETE(_chars); - _chars = newBuf; - _limit = len; - } - _len = len; - MyStringCopy(_chars, s._chars); - return *this; -} - -AString &AString::operator+=(const char *s) -{ - unsigned len = MyStringLen(s); - Grow(len); - MyStringCopy(_chars + _len, s); - _len += len; - return *this; -} - -AString &AString::operator+=(const AString &s) -{ - Grow(s._len); - MyStringCopy(_chars + _len, s._chars); - _len += s._len; - return *this; -} - -void AString::SetFrom(const char *s, unsigned len) // no check -{ - if (len > _limit) - { - char *newBuf = MY_STRING_NEW(char, len + 1); - MY_STRING_DELETE(_chars); - _chars = newBuf; - _limit = len; - } - memcpy(_chars, s, len); - _chars[len] = 0; - _len = len; -} - -int AString::Find(const AString &s, unsigned startIndex) const throw() -{ - if (s.IsEmpty()) - return startIndex; - for (; startIndex < _len; startIndex++) - { - unsigned j; - for (j = 0; j < s._len && startIndex + j < _len; j++) - if (_chars[startIndex + j] != s._chars[j]) - break; - if (j == s._len) - return (int)startIndex; - } - return -1; -} - -int AString::ReverseFind(char c) const throw() -{ - if (_len == 0) - return -1; - const char *p = _chars + _len - 1; - for (;;) - { - if (*p == c) - return (int)(p - _chars); - if (p == _chars) - return -1; - p--; // p = GetPrevCharPointer(_chars, p); - } -} - -void AString::TrimLeft() throw() -{ - const char *p = _chars; - for (;; p++) - { - char c = *p; - if (c != ' ' && c != '\n' && c != '\t') - break; - } - unsigned pos = (unsigned)(p - _chars); - if (pos != 0) - { - MoveItems(0, pos); - _len -= pos; - } -} - -void AString::TrimRight() throw() -{ - const char *p = _chars; - int i; - for (i = _len - 1; i >= 0; i--) - { - char c = p[i]; - if (c != ' ' && c != '\n' && c != '\t') - break; - } - i++; - if ((unsigned)i != _len) - { - _chars[i] = 0; - _len = i; - } -} - -void AString::InsertAtFront(char c) -{ - if (_limit == _len) - Grow_1(); - MoveItems(1, 0); - _chars[0] = c; - _len++; -} - -/* -void AString::Insert(unsigned index, char c) -{ - InsertSpace(index, 1); - _chars[index] = c; - _len++; -} -*/ - -void AString::Insert(unsigned index, const char *s) -{ - unsigned num = MyStringLen(s); - if (num != 0) - { - InsertSpace(index, num); - memcpy(_chars + index, s, num); - _len += num; - } -} - -void AString::Insert(unsigned index, const AString &s) -{ - unsigned num = s.Len(); - if (num != 0) - { - InsertSpace(index, num); - memcpy(_chars + index, s, num); - _len += num; - } -} - -void AString::RemoveChar(char ch) throw() -{ - int pos = Find(ch); - if (pos < 0) - return; - const char *src = _chars; - char *dest = _chars + pos; - pos++; - unsigned len = _len; - for (; (unsigned)pos < len; pos++) - { - char c = src[(unsigned)pos]; - if (c != ch) - *dest++ = c; - } - *dest = 0; - _len = (unsigned)(dest - _chars); -} - -// !!!!!!!!!!!!!!! test it if newChar = '\0' -void AString::Replace(char oldChar, char newChar) throw() -{ - if (oldChar == newChar) - return; // 0; - // unsigned number = 0; - int pos = 0; - while ((unsigned)pos < _len) - { - pos = Find(oldChar, pos); - if (pos < 0) - break; - _chars[pos] = newChar; - pos++; - // number++; - } - return; // number; -} - -void AString::Replace(const AString &oldString, const AString &newString) -{ - if (oldString.IsEmpty()) - return; // 0; - if (oldString == newString) - return; // 0; - unsigned oldLen = oldString.Len(); - unsigned newLen = newString.Len(); - // unsigned number = 0; - int pos = 0; - while ((unsigned)pos < _len) - { - pos = Find(oldString, pos); - if (pos < 0) - break; - Delete(pos, oldLen); - Insert(pos, newString); - pos += newLen; - // number++; - } - // return number; -} - -void AString::Delete(unsigned index) throw() -{ - MoveItems(index, index + 1); - _len--; -} - -void AString::Delete(unsigned index, unsigned count) throw() -{ - if (index + count > _len) - count = _len - index; - if (count > 0) - { - MoveItems(index, index + count); - _len -= count; - } -} - -void AString::DeleteFrontal(unsigned num) throw() -{ - if (num != 0) - { - MoveItems(0, num); - _len -= num; - } -} - -/* -AString operator+(const AString &s1, const AString &s2) -{ - AString result(s1); - result += s2; - return result; -} - -AString operator+(const AString &s, const char *chars) -{ - AString result(s); - result += chars; - return result; -} - -AString operator+(const char *chars, const AString &s) -{ - AString result(chars); - result += s; - return result; -} - -AString operator+(const AString &s, char c) -{ - AString result(s); - result += c; - return result; -} -*/ - -/* -AString operator+(char c, const AString &s) -{ - AString result(c); - result += s; - return result; -} -*/ - - - - -// ---------- UString ---------- - -void UString::InsertSpace(unsigned index, unsigned size) -{ - Grow(size); - MoveItems(index + size, index); -} - -void UString::ReAlloc(unsigned newLimit) -{ - if (newLimit < _len || newLimit >= 0x20000000) throw 20130221; - // MY_STRING_REALLOC(_chars, wchar_t, newLimit + 1, _len + 1); - wchar_t *newBuf = MY_STRING_NEW(wchar_t, newLimit + 1); - wmemcpy(newBuf, _chars, _len + 1); - MY_STRING_DELETE(_chars); - _chars = newBuf; - - _limit = newLimit; -} - -void UString::SetStartLen(unsigned len) -{ - _chars = 0; - _chars = MY_STRING_NEW(wchar_t, len + 1); - _len = len; - _limit = len; -} - -void UString::Grow_1() -{ - unsigned next = _len; - next += next / 2; - next += 16; - next &= ~(unsigned)15; - ReAlloc(next - 1); -} - -void UString::Grow(unsigned n) -{ - unsigned freeSize = _limit - _len; - if (n <= freeSize) - return; - - unsigned next = _len + n; - next += next / 2; - next += 16; - next &= ~(unsigned)15; - ReAlloc(next - 1); -} - - -UString::UString(unsigned num, const wchar_t *s) -{ - unsigned len = MyStringLen(s); - if (num > len) - num = len; - SetStartLen(num); - wmemcpy(_chars, s, num); - _chars[num] = 0; -} - - -UString::UString(unsigned num, const UString &s) -{ - if (num > s._len) - num = s._len; - SetStartLen(num); - wmemcpy(_chars, s._chars, num); - _chars[num] = 0; -} - -UString::UString(const UString &s, wchar_t c) -{ - SetStartLen(s.Len() + 1); - wchar_t *chars = _chars; - unsigned len = s.Len(); - wmemcpy(chars, s, len); - chars[len] = c; - chars[len + 1] = 0; -} - -UString::UString(const wchar_t *s1, unsigned num1, const wchar_t *s2, unsigned num2) -{ - SetStartLen(num1 + num2); - wchar_t *chars = _chars; - wmemcpy(chars, s1, num1); - wmemcpy(chars + num1, s2, num2 + 1); -} - -UString operator+(const UString &s1, const UString &s2) { return UString(s1, s1.Len(), s2, s2.Len()); } -UString operator+(const UString &s1, const wchar_t *s2) { return UString(s1, s1.Len(), s2, MyStringLen(s2)); } -UString operator+(const wchar_t *s1, const UString &s2) { return UString(s1, MyStringLen(s1), s2, s2.Len()); } - -UString::UString() -{ - _chars = 0; - _chars = MY_STRING_NEW(wchar_t, 4); - _len = 0; - _limit = 4 - 1; - _chars[0] = 0; -} - -UString::UString(wchar_t c) -{ - SetStartLen(1); - _chars[0] = c; - _chars[1] = 0; -} - -UString::UString(const wchar_t *s) -{ - SetStartLen(MyStringLen(s)); - MyStringCopy(_chars, s); -} - -UString::UString(const UString &s) -{ - SetStartLen(s._len); - MyStringCopy(_chars, s._chars); -} - -UString &UString::operator=(wchar_t c) -{ - if (1 > _limit) - { - wchar_t *newBuf = MY_STRING_NEW(wchar_t, 1 + 1); - MY_STRING_DELETE(_chars); - _chars = newBuf; - _limit = 1; - } - _len = 1; - _chars[0] = c; - _chars[1] = 0; - return *this; -} - -UString &UString::operator=(const wchar_t *s) -{ - unsigned len = MyStringLen(s); - if (len > _limit) - { - wchar_t *newBuf = MY_STRING_NEW(wchar_t, len + 1); - MY_STRING_DELETE(_chars); - _chars = newBuf; - _limit = len; - } - _len = len; - MyStringCopy(_chars, s); - return *this; -} - -UString &UString::operator=(const UString &s) -{ - if (&s == this) - return *this; - unsigned len = s._len; - if (len > _limit) - { - wchar_t *newBuf = MY_STRING_NEW(wchar_t, len + 1); - MY_STRING_DELETE(_chars); - _chars = newBuf; - _limit = len; - } - _len = len; - MyStringCopy(_chars, s._chars); - return *this; -} - -UString &UString::operator+=(const wchar_t *s) -{ - unsigned len = MyStringLen(s); - Grow(len); - MyStringCopy(_chars + _len, s); - _len += len; - return *this; -} - -UString &UString::operator+=(const UString &s) -{ - Grow(s._len); - MyStringCopy(_chars + _len, s._chars); - _len += s._len; - return *this; -} - -void UString::SetFrom(const wchar_t *s, unsigned len) // no check -{ - if (len > _limit) - { - wchar_t *newBuf = MY_STRING_NEW(wchar_t, len + 1); - MY_STRING_DELETE(_chars); - _chars = newBuf; - _limit = len; - } - wmemcpy(_chars, s, len); - _chars[len] = 0; - _len = len; -} - -void UString::SetFromAscii(const char *s) -{ - unsigned len = MyStringLen(s); - if (len > _limit) - { - wchar_t *newBuf = MY_STRING_NEW(wchar_t, len + 1); - MY_STRING_DELETE(_chars); - _chars = newBuf; - _limit = len; - } - wchar_t *chars = _chars; - for (unsigned i = 0; i < len; i++) - chars[i] = s[i]; - chars[len] = 0; - _len = len; -} - -void UString::AddAsciiStr(const char *s) -{ - unsigned len = MyStringLen(s); - Grow(len); - wchar_t *chars = _chars + _len; - for (unsigned i = 0; i < len; i++) - chars[i] = s[i]; - chars[len] = 0; - _len += len; -} - - - -int UString::Find(const UString &s, unsigned startIndex) const throw() -{ - if (s.IsEmpty()) - return startIndex; - for (; startIndex < _len; startIndex++) - { - unsigned j; - for (j = 0; j < s._len && startIndex + j < _len; j++) - if (_chars[startIndex + j] != s._chars[j]) - break; - if (j == s._len) - return (int)startIndex; - } - return -1; -} - -int UString::ReverseFind(wchar_t c) const throw() -{ - if (_len == 0) - return -1; - const wchar_t *p = _chars + _len - 1; - for (;;) - { - if (*p == c) - return (int)(p - _chars); - if (p == _chars) - return -1; - p--; - } -} - -void UString::TrimLeft() throw() -{ - const wchar_t *p = _chars; - for (;; p++) - { - wchar_t c = *p; - if (c != ' ' && c != '\n' && c != '\t') - break; - } - unsigned pos = (unsigned)(p - _chars); - if (pos != 0) - { - MoveItems(0, pos); - _len -= pos; - } -} - -void UString::TrimRight() throw() -{ - const wchar_t *p = _chars; - int i; - for (i = _len - 1; i >= 0; i--) - { - wchar_t c = p[i]; - if (c != ' ' && c != '\n' && c != '\t') - break; - } - i++; - if ((unsigned)i != _len) - { - _chars[i] = 0; - _len = i; - } -} - -void UString::InsertAtFront(wchar_t c) -{ - if (_limit == _len) - Grow_1(); - MoveItems(1, 0); - _chars[0] = c; - _len++; -} - -/* -void UString::Insert(unsigned index, wchar_t c) -{ - InsertSpace(index, 1); - _chars[index] = c; - _len++; -} -*/ - -void UString::Insert(unsigned index, const wchar_t *s) -{ - unsigned num = MyStringLen(s); - if (num != 0) - { - InsertSpace(index, num); - wmemcpy(_chars + index, s, num); - _len += num; - } -} - -void UString::Insert(unsigned index, const UString &s) -{ - unsigned num = s.Len(); - if (num != 0) - { - InsertSpace(index, num); - wmemcpy(_chars + index, s, num); - _len += num; - } -} - -void UString::RemoveChar(wchar_t ch) throw() -{ - int pos = Find(ch); - if (pos < 0) - return; - const wchar_t *src = _chars; - wchar_t *dest = _chars + pos; - pos++; - unsigned len = _len; - for (; (unsigned)pos < len; pos++) - { - wchar_t c = src[(unsigned)pos]; - if (c != ch) - *dest++ = c; - } - *dest = 0; - _len = (unsigned)(dest - _chars); -} - -// !!!!!!!!!!!!!!! test it if newChar = '\0' -void UString::Replace(wchar_t oldChar, wchar_t newChar) throw() -{ - if (oldChar == newChar) - return; // 0; - // unsigned number = 0; - int pos = 0; - while ((unsigned)pos < _len) - { - pos = Find(oldChar, pos); - if (pos < 0) - break; - _chars[pos] = newChar; - pos++; - // number++; - } - return; // number; -} - -void UString::Replace(const UString &oldString, const UString &newString) -{ - if (oldString.IsEmpty()) - return; // 0; - if (oldString == newString) - return; // 0; - unsigned oldLen = oldString.Len(); - unsigned newLen = newString.Len(); - // unsigned number = 0; - int pos = 0; - while ((unsigned)pos < _len) - { - pos = Find(oldString, pos); - if (pos < 0) - break; - Delete(pos, oldLen); - Insert(pos, newString); - pos += newLen; - // number++; - } - // return number; -} - -void UString::Delete(unsigned index) throw() -{ - MoveItems(index, index + 1); - _len--; -} - -void UString::Delete(unsigned index, unsigned count) throw() -{ - if (index + count > _len) - count = _len - index; - if (count > 0) - { - MoveItems(index, index + count); - _len -= count; - } -} - -void UString::DeleteFrontal(unsigned num) throw() -{ - if (num != 0) - { - MoveItems(0, num); - _len -= num; - } -} - - -// ---------------------------------------- - -/* -int MyStringCompareNoCase(const char *s1, const char *s2) -{ - return MyStringCompareNoCase(MultiByteToUnicodeString(s1), MultiByteToUnicodeString(s2)); -} -*/ - -static inline UINT GetCurrentCodePage() -{ - #if defined(UNDER_CE) || !defined(_WIN32) - return CP_ACP; - #else - return ::AreFileApisANSI() ? CP_ACP : CP_OEMCP; - #endif -} - -#ifdef USE_UNICODE_FSTRING - -#ifndef _UNICODE - -AString fs2fas(CFSTR s) -{ - return UnicodeStringToMultiByte(s, GetCurrentCodePage()); -} - -FString fas2fs(const AString &s) -{ - return MultiByteToUnicodeString(s, GetCurrentCodePage()); -} - -#endif - -#else - -UString fs2us(const FString &s) -{ - return MultiByteToUnicodeString((AString)s, GetCurrentCodePage()); -} - -FString us2fs(const wchar_t *s) -{ - return UnicodeStringToMultiByte(s, GetCurrentCodePage()); -} - -#endif diff --git a/src/libs/7zip/win/CPP/Common/MyString.h b/src/libs/7zip/win/CPP/Common/MyString.h deleted file mode 100644 index 8417815cf..000000000 --- a/src/libs/7zip/win/CPP/Common/MyString.h +++ /dev/null @@ -1,525 +0,0 @@ -// Common/String.h - -#ifndef __COMMON_STRING_H -#define __COMMON_STRING_H - -#include <string.h> - -#ifndef _WIN32 -#include <wctype.h> -#include <wchar.h> -#endif - -#include "MyTypes.h" -#include "MyVector.h" - -inline unsigned MyStringLen(const char *s) -{ - unsigned i; - for (i = 0; s[i] != 0; i++); - return i; -} - -inline void MyStringCopy(char *dest, const char *src) -{ - while ((*dest++ = *src++) != 0); -} - -inline char *MyStpCpy(char *dest, const char *src) -{ - for (;;) - { - char c = *src; - *dest = c; - if (c == 0) - return dest; - src++; - dest++; - } -} - -inline unsigned MyStringLen(const wchar_t *s) -{ - unsigned i; - for (i = 0; s[i] != 0; i++); - return i; -} - -inline void MyStringCopy(wchar_t *dest, const wchar_t *src) -{ - while ((*dest++ = *src++) != 0); -} - -int FindCharPosInString(const char *s, char c) throw(); -int FindCharPosInString(const wchar_t *s, wchar_t c) throw(); - -#ifdef _WIN32 - #ifndef _UNICODE - #define STRING_UNICODE_THROW - #endif -#endif - -#ifndef STRING_UNICODE_THROW - #define STRING_UNICODE_THROW throw() -#endif - -/* -inline char MyCharUpper_Ascii(char c) -{ - if (c >= 'a' && c <= 'z') - return (char)(c - 0x20); - return c; -} -inline wchar_t MyCharUpper_Ascii(wchar_t c) -{ - if (c >= 'a' && c <= 'z') - return (wchar_t)(c - 0x20); - return c; -} -*/ - -inline char MyCharLower_Ascii(char c) -{ - if (c >= 'A' && c <= 'Z') - return (char)(c + 0x20); - return c; -} - -inline wchar_t MyCharLower_Ascii(wchar_t c) -{ - if (c >= 'A' && c <= 'Z') - return (wchar_t)(c + 0x20); - return c; -} - -wchar_t MyCharUpper_WIN(wchar_t c) throw(); - -inline wchar_t MyCharUpper(wchar_t c) throw() -{ - if (c < 'a') return c; - if (c <= 'z') return (wchar_t)(c - 0x20); - if (c <= 0x7F) return c; - #ifdef _WIN32 - #ifdef _UNICODE - return (wchar_t)(unsigned)(UINT_PTR)CharUpperW((LPWSTR)(UINT_PTR)(unsigned)c); - #else - return (wchar_t)MyCharUpper_WIN(c); - #endif - #else - return (wchar_t)towupper(c); - #endif -} - -/* -wchar_t MyCharLower_WIN(wchar_t c) throw(); - -inline wchar_t MyCharLower(wchar_t c) throw() -{ - if (c < 'A') return c; - if (c <= 'Z') return (wchar_t)(c + 0x20); - if (c <= 0x7F) return c; - #ifdef _WIN32 - #ifdef _UNICODE - return (wchar_t)(unsigned)(UINT_PTR)CharLowerW((LPWSTR)(UINT_PTR)(unsigned)c); - #else - return (wchar_t)MyCharLower_WIN(c); - #endif - #else - return (wchar_t)tolower(c); - #endif -} -*/ - -// char *MyStringUpper(char *s) throw(); -// char *MyStringLower(char *s) throw(); - -// void MyStringUpper_Ascii(wchar_t *s) throw(); -void MyStringLower_Ascii(wchar_t *s) throw(); -// wchar_t *MyStringUpper(wchar_t *s) STRING_UNICODE_THROW; -// wchar_t *MyStringLower(wchar_t *s) STRING_UNICODE_THROW; - -bool StringsAreEqualNoCase(const wchar_t *s1, const wchar_t *s2) throw(); - -bool IsString1PrefixedByString2(const char *s1, const char *s2) throw(); -bool IsString1PrefixedByString2(const wchar_t *s1, const wchar_t *s2) throw(); - -int MyStringCompareNoCase(const wchar_t *s1, const wchar_t *s2) throw(); -int MyStringCompareNoCase_N(const wchar_t *s1, const wchar_t *s2, unsigned num) throw(); - -// ---------- ASCII ---------- -// char values in ASCII strings must be less then 128 -bool StringsAreEqual_Ascii(const wchar_t *u, const char *a) throw(); -bool StringsAreEqualNoCase_Ascii(const char *s1, const char *s2) throw(); -bool StringsAreEqualNoCase_Ascii(const wchar_t *s1, const char *s2) throw(); -bool StringsAreEqualNoCase_Ascii(const wchar_t *s1, const wchar_t *s2) throw(); - -#define MY_STRING_DELETE(_p_) delete []_p_; -// #define MY_STRING_DELETE(_p_) my_delete(_p_); - -class AString -{ - char *_chars; - unsigned _len; - unsigned _limit; - - void MoveItems(unsigned dest, unsigned src) - { - memmove(_chars + dest, _chars + src, (size_t)(_len - src + 1) * sizeof(char)); - } - - void InsertSpace(unsigned &index, unsigned size); - - void ReAlloc(unsigned newLimit); - void SetStartLen(unsigned len); - void Grow_1(); - void Grow(unsigned n); - - // AString(unsigned num, const char *s); - AString(unsigned num, const AString &s); - AString(const AString &s, char c); // it's for String + char - AString(const char *s1, unsigned num1, const char *s2, unsigned num2); - - friend AString operator+(const AString &s, char c) { return AString(s, c); } ; - // friend AString operator+(char c, const AString &s); // is not supported - - friend AString operator+(const AString &s1, const AString &s2); - friend AString operator+(const AString &s1, const char *s2); - friend AString operator+(const char *s1, const AString &s2); - -public: - AString(); - AString(char c); - AString(const char *s); - AString(const AString &s); - ~AString() { MY_STRING_DELETE(_chars); } - - unsigned Len() const { return _len; } - bool IsEmpty() const { return _len == 0; } - void Empty() { _len = 0; _chars[0] = 0; } - - operator const char *() const { return _chars; } - const char *Ptr() const { return _chars; } - const char *Ptr(unsigned pos) const { return _chars + pos; } - const char *RightPtr(unsigned num) const { return _chars + _len - num; } - char Back() const { return _chars[_len - 1]; } - - void ReplaceOneCharAtPos(unsigned pos, char c) { _chars[pos] = c; } - - // The minimum size of the character buffer in characters. - // This value does not include space for a null terminator. - char *GetBuffer(unsigned minBufLen) - { - if (minBufLen > _limit) - ReAlloc(minBufLen); - return _chars; - } - void ReleaseBuffer() { ReleaseBuffer(MyStringLen(_chars)); } - void ReleaseBuffer(unsigned newLen) { _len = newLen; _chars[newLen] = 0; } - - AString &operator=(char c); - AString &operator=(const char *s); - AString &operator=(const AString &s); - - AString &operator+=(char c) - { - if (_limit == _len) - Grow_1(); - unsigned len = _len; - char *chars = _chars; - chars[len++] = c; - chars[len] = 0; - _len = len; - return *this; - } - - AString &operator+=(const char *s); - AString &operator+=(const AString &s); - - void SetFrom(const char *s, unsigned len); // no check - // AString Mid(unsigned startIndex, unsigned count) const { return AString(count, _chars + startIndex); } - AString Left(unsigned count) const { return AString(count, *this); } - - // void MakeUpper() { MyStringUpper(_chars); } - // void MakeLower() { MyStringLower(_chars); } - - - // int Compare(const char *s) const { return MyStringCompare(_chars, s); } - // int Compare(const AString &s) const { return MyStringCompare(_chars, s._chars); } - // int CompareNoCase(const char *s) const { return MyStringCompareNoCase(_chars, s); } - // int CompareNoCase(const AString &s) const { return MyStringCompareNoCase(_chars, s._chars); } - bool IsPrefixedBy(const char *s) const { return IsString1PrefixedByString2(_chars, s); } - bool IsPrefixedBy_Ascii_NoCase(const char *s) const throw(); - - int Find(char c) const { return FindCharPosInString(_chars, c); } - int Find(char c, unsigned startIndex) const - { - int pos = FindCharPosInString(_chars + startIndex, c); - return pos < 0 ? -1 : (int)startIndex + pos; - } - int ReverseFind(char c) const throw(); - int Find(const AString &s) const { return Find(s, 0); } - int Find(const AString &s, unsigned startIndex) const throw(); - - void TrimLeft() throw(); - void TrimRight() throw(); - void Trim() - { - TrimRight(); - TrimLeft(); - } - - void InsertAtFront(char c); - // void Insert(unsigned index, char c); - void Insert(unsigned index, const char *s); - void Insert(unsigned index, const AString &s); - - void RemoveChar(char ch) throw(); - void Replace(char oldChar, char newChar) throw(); - void Replace(const AString &oldString, const AString &newString); - - void Delete(unsigned index) throw(); - void Delete(unsigned index, unsigned count) throw(); - void DeleteFrontal(unsigned num) throw(); - void DeleteBack() { _chars[--_len] = 0; } - void DeleteFrom(unsigned index) - { - if (index < _len) - { - _len = index; - _chars[index] = 0; - } - } -}; - -bool operator<(const AString &s1, const AString &s2); -bool operator>(const AString &s1, const AString &s2); - -/* -bool operator==(const AString &s1, const AString &s2); -bool operator==(const AString &s1, const char *s2); -bool operator==(const char *s1, const AString &s2); - -bool operator!=(const AString &s1, const AString &s2); -bool operator!=(const AString &s1, const char *s2); -bool operator!=(const char *s1, const AString &s2); -*/ - -inline bool operator==(const AString &s1, const AString &s2) { return s1.Len() == s2.Len() && strcmp(s1, s2) == 0; } -inline bool operator==(const AString &s1, const char *s2) { return strcmp(s1, s2) == 0; } -inline bool operator==(const char *s1, const AString &s2) { return strcmp(s1, s2) == 0; } - -inline bool operator!=(const AString &s1, const AString &s2) { return s1.Len() != s2.Len() || strcmp(s1, s2) != 0; } -inline bool operator!=(const AString &s1, const char *s2) { return strcmp(s1, s2) != 0; } -inline bool operator!=(const char *s1, const AString &s2) { return strcmp(s1, s2) != 0; } - - - -class UString -{ - wchar_t *_chars; - unsigned _len; - unsigned _limit; - - void MoveItems(unsigned dest, unsigned src) - { - memmove(_chars + dest, _chars + src, (size_t)(_len - src + 1) * sizeof(wchar_t)); - } - - void InsertSpace(unsigned index, unsigned size); - - void ReAlloc(unsigned newLimit); - void SetStartLen(unsigned len); - void Grow_1(); - void Grow(unsigned n); - - UString(unsigned num, const wchar_t *s); // for Mid - UString(unsigned num, const UString &s); // for Left - UString(const UString &s, wchar_t c); // it's for String + char - UString(const wchar_t *s1, unsigned num1, const wchar_t *s2, unsigned num2); - - friend UString operator+(const UString &s, wchar_t c) { return UString(s, c); } ; - // friend UString operator+(wchar_t c, const UString &s); // is not supported - - friend UString operator+(const UString &s1, const UString &s2); - friend UString operator+(const UString &s1, const wchar_t *s2); - friend UString operator+(const wchar_t *s1, const UString &s2); - -public: - UString(); - UString(wchar_t c); - UString(const wchar_t *s); - UString(const UString &s); - ~UString() { MY_STRING_DELETE(_chars); } - - unsigned Len() const { return _len; } - bool IsEmpty() const { return _len == 0; } - void Empty() { _len = 0; _chars[0] = 0; } - - operator const wchar_t *() const { return _chars; } - const wchar_t *Ptr() const { return _chars; } - const wchar_t *Ptr(unsigned pos) const { return _chars + pos; } - const wchar_t *RightPtr(unsigned num) const { return _chars + _len - num; } - wchar_t Back() const { return _chars[_len - 1]; } - - void ReplaceOneCharAtPos(unsigned pos, wchar_t c) { _chars[pos] = c; } - - // The minimum size of the character buffer in characters. - // This value does not include space for a null terminator. - wchar_t *GetBuffer(unsigned minBufLen) - { - if (minBufLen > _limit) - ReAlloc(minBufLen); - return _chars; - } - void ReleaseBuffer() { ReleaseBuffer(MyStringLen(_chars)); } - void ReleaseBuffer(unsigned newLen) { _len = newLen; _chars[newLen] = 0; } - - UString &operator=(wchar_t c); - UString &operator=(const wchar_t *s); - UString &operator=(const UString &s); - - UString &operator+=(wchar_t c) - { - if (_limit == _len) - Grow_1(); - unsigned len = _len; - wchar_t *chars = _chars; - chars[len++] = c; - chars[len] = 0; - _len = len; - return *this; - } - - UString &operator+=(const wchar_t *s); - UString &operator+=(const UString &s); - - void SetFrom(const wchar_t *s, unsigned len); // no check - - void SetFromAscii(const char *s); - void AddAsciiStr(const char *s); - - UString Mid(unsigned startIndex, unsigned count) const { return UString(count, _chars + startIndex); } - UString Left(unsigned count) const { return UString(count, *this); } - - // void MakeUpper() { MyStringUpper(_chars); } - // void MakeUpper() { MyStringUpper_Ascii(_chars); } - // void MakeUpper_Ascii() { MyStringUpper_Ascii(_chars); } - void MakeLower_Ascii() { MyStringLower_Ascii(_chars); } - - bool IsEqualTo(const char *s) const { return StringsAreEqual_Ascii(_chars, s); } - bool IsEqualToNoCase(const wchar_t *s) const { return StringsAreEqualNoCase(_chars, s); } - int Compare(const wchar_t *s) const { return wcscmp(_chars, s); } - // int Compare(const UString &s) const { return MyStringCompare(_chars, s._chars); } - // int CompareNoCase(const wchar_t *s) const { return MyStringCompareNoCase(_chars, s); } - // int CompareNoCase(const UString &s) const { return MyStringCompareNoCase(_chars, s._chars); } - bool IsPrefixedBy(const wchar_t *s) const { return IsString1PrefixedByString2(_chars, s); }; - bool IsPrefixedBy_Ascii_NoCase(const char *s) const throw(); - - int Find(wchar_t c) const { return FindCharPosInString(_chars, c); } - int Find(wchar_t c, unsigned startIndex) const - { - int pos = FindCharPosInString(_chars + startIndex, c); - return pos < 0 ? -1 : (int)startIndex + pos; - } - int Find(const UString &s) const { return Find(s, 0); } - int Find(const UString &s, unsigned startIndex) const throw(); - int ReverseFind(wchar_t c) const throw(); - - void TrimLeft() throw(); - void TrimRight() throw(); - void Trim() - { - TrimRight(); - TrimLeft(); - } - - void InsertAtFront(wchar_t c); - // void Insert(unsigned index, wchar_t c); - void Insert(unsigned index, const wchar_t *s); - void Insert(unsigned index, const UString &s); - - void RemoveChar(wchar_t ch) throw(); - void Replace(wchar_t oldChar, wchar_t newChar) throw(); - void Replace(const UString &oldString, const UString &newString); - - void Delete(unsigned index) throw(); - void Delete(unsigned index, unsigned count) throw(); - void DeleteFrontal(unsigned num) throw(); - void DeleteBack() { _chars[--_len] = 0; } - void DeleteFrom(unsigned index) - { - if (index < _len) - { - _len = index; - _chars[index] = 0; - } - } -}; - -bool operator<(const UString &s1, const UString &s2); -bool operator>(const UString &s1, const UString &s2); - -inline bool operator==(const UString &s1, const UString &s2) { return s1.Len() == s2.Len() && wcscmp(s1, s2) == 0; } -inline bool operator==(const UString &s1, const wchar_t *s2) { return wcscmp(s1, s2) == 0; } -inline bool operator==(const wchar_t *s1, const UString &s2) { return wcscmp(s1, s2) == 0; } - -inline bool operator!=(const UString &s1, const UString &s2) { return s1.Len() != s2.Len() || wcscmp(s1, s2) != 0; } -inline bool operator!=(const UString &s1, const wchar_t *s2) { return wcscmp(s1, s2) != 0; } -inline bool operator!=(const wchar_t *s1, const UString &s2) { return wcscmp(s1, s2) != 0; } - - -typedef CObjectVector<AString> AStringVector; -typedef CObjectVector<UString> UStringVector; - -#ifdef _UNICODE - typedef UString CSysString; -#else - typedef AString CSysString; -#endif - -typedef CObjectVector<CSysString> CSysStringVector; - - -// ---------- FString ---------- - -#ifdef _WIN32 - #define USE_UNICODE_FSTRING -#endif - -#ifdef USE_UNICODE_FSTRING - - #define __FTEXT(quote) L##quote - - typedef wchar_t FChar; - typedef UString FString; - - #define fs2us(_x_) (_x_) - #define us2fs(_x_) (_x_) - FString fas2fs(const AString &s); - AString fs2fas(const FChar *s); - -#else - - #define __FTEXT(quote) quote - - typedef char FChar; - typedef AString FString; - - UString fs2us(const FString &s); - FString us2fs(const wchar_t *s); - #define fas2fs(_x_) (_x_) - #define fs2fas(_x_) (_x_) - -#endif - -#define FTEXT(quote) __FTEXT(quote) - -#define FCHAR_PATH_SEPARATOR FTEXT(CHAR_PATH_SEPARATOR) -#define FSTRING_PATH_SEPARATOR FTEXT(STRING_PATH_SEPARATOR) -#define FCHAR_ANY_MASK FTEXT('*') -#define FSTRING_ANY_MASK FTEXT("*") -typedef const FChar *CFSTR; - -typedef CObjectVector<FString> FStringVector; - -#endif diff --git a/src/libs/7zip/win/CPP/Common/MyTypes.h b/src/libs/7zip/win/CPP/Common/MyTypes.h deleted file mode 100644 index d81788816..000000000 --- a/src/libs/7zip/win/CPP/Common/MyTypes.h +++ /dev/null @@ -1,30 +0,0 @@ -// Common/MyTypes.h - -#ifndef __COMMON_MY_TYPES_H -#define __COMMON_MY_TYPES_H - -#include "../../C/7zTypes.h" - -typedef int HRes; - -struct CBoolPair -{ - bool Val; - bool Def; - - CBoolPair(): Val(false), Def(false) {} - - void Init() - { - Val = false; - Def = false; - } - - void SetTrueTrue() - { - Val = true; - Def = true; - } -}; - -#endif diff --git a/src/libs/7zip/win/CPP/Common/MyUnknown.h b/src/libs/7zip/win/CPP/Common/MyUnknown.h deleted file mode 100644 index 8b95afd38..000000000 --- a/src/libs/7zip/win/CPP/Common/MyUnknown.h +++ /dev/null @@ -1,13 +0,0 @@ -// MyUnknown.h - -#ifndef __MY_UNKNOWN_H -#define __MY_UNKNOWN_H - -#ifdef _WIN32 -#include <basetyps.h> -#include <unknwn.h> -#else -#include "MyWindows.h" -#endif - -#endif diff --git a/src/libs/7zip/win/CPP/Common/MyVector.h b/src/libs/7zip/win/CPP/Common/MyVector.h deleted file mode 100644 index 7e61dec31..000000000 --- a/src/libs/7zip/win/CPP/Common/MyVector.h +++ /dev/null @@ -1,615 +0,0 @@ -// Common/MyVector.h - -#ifndef __COMMON_MY_VECTOR_H -#define __COMMON_MY_VECTOR_H - -template <class T> -class CRecordVector -{ - T *_items; - unsigned _size; - unsigned _capacity; - - void MoveItems(unsigned destIndex, unsigned srcIndex) - { - memmove(_items + destIndex, _items + srcIndex, (size_t)(_size - srcIndex) * (size_t)sizeof(T)); - } - - void ReserveOnePosition() - { - if (_size == _capacity) - { - unsigned newCapacity = _capacity + (_capacity >> 2) + 1; - T *p = new T[newCapacity]; - memcpy(p, _items, (size_t)_size * (size_t)sizeof(T)); - delete []_items; - _items = p; - _capacity = newCapacity; - } - } - -public: - - CRecordVector(): _items(0), _size(0), _capacity(0) {} - - CRecordVector(const CRecordVector &v): _items(0), _size(0), _capacity(0) - { - unsigned size = v.Size(); - if (size != 0) - { - _items = new T[size]; - _size = size; - _capacity = size; - memcpy(_items, v._items, (size_t)size * (size_t)sizeof(T)); - } - } - - unsigned Size() const { return _size; } - bool IsEmpty() const { return _size == 0; } - - void ConstructReserve(unsigned size) - { - if (size != 0) - { - _items = new T[size]; - _capacity = size; - } - } - - void Reserve(unsigned newCapacity) - { - if (newCapacity > _capacity) - { - T *p = new T[newCapacity]; - memcpy(p, _items, (size_t)_size * (size_t)sizeof(T)); - delete []_items; - _items = p; - _capacity = newCapacity; - } - } - - void ClearAndReserve(unsigned newCapacity) - { - Clear(); - if (newCapacity > _capacity) - { - delete []_items; - _items = NULL; - _capacity = 0; - _items = new T[newCapacity]; - _capacity = newCapacity; - } - } - - void ClearAndSetSize(unsigned newSize) - { - ClearAndReserve(newSize); - _size = newSize; - } - - void ChangeSize_KeepData(unsigned newSize) - { - if (newSize > _capacity) - { - T *p = new T[newSize]; - memcpy(p, _items, (size_t)_size * (size_t)sizeof(T)); - delete []_items; - _items = p; - _capacity = newSize; - } - _size = newSize; - } - - void ReserveDown() - { - if (_size == _capacity) - return; - T *p = NULL; - if (_size != 0) - { - p = new T[_size]; - memcpy(p, _items, (size_t)_size * (size_t)sizeof(T)); - } - delete []_items; - _items = p; - _capacity = _size; - } - - ~CRecordVector() { delete []_items; } - - void ClearAndFree() - { - delete []_items; - _items = NULL; - _size = 0; - _capacity = 0; - } - - void Clear() { _size = 0; } - - void DeleteBack() { _size--; } - - void DeleteFrom(unsigned index) - { - // if (index <= _size) - _size = index; - } - - void DeleteFrontal(unsigned num) - { - if (num != 0) - { - MoveItems(0, num); - _size -= num; - } - } - - void Delete(unsigned index) - { - MoveItems(index, index + 1); - _size -= 1; - } - - /* - void Delete(unsigned index, unsigned num) - { - if (num > 0) - { - MoveItems(index, index + num); - _size -= num; - } - } - */ - - CRecordVector& operator=(const CRecordVector &v) - { - unsigned size = v.Size(); - if (size > _capacity) - { - delete []_items; - _capacity = 0; - _size = 0; - _items = NULL; - _items = new T[size]; - _capacity = size; - } - _size = size; - memcpy(_items, v._items, (size_t)size * (size_t)sizeof(T)); - return *this; - } - - CRecordVector& operator+=(const CRecordVector &v) - { - unsigned size = v.Size(); - Reserve(_size + size); - memcpy(_items + _size, v._items, (size_t)size * (size_t)sizeof(T)); - _size += size; - return *this; - } - - unsigned Add(const T item) - { - ReserveOnePosition(); - _items[_size] = item; - return _size++; - } - - void AddInReserved(const T item) - { - _items[_size++] = item; - } - - void Insert(unsigned index, const T item) - { - ReserveOnePosition(); - MoveItems(index + 1, index); - _items[index] = item; - _size++; - } - - void MoveToFront(unsigned index) - { - if (index != 0) - { - T temp = _items[index]; - memmove(_items + 1, _items, (size_t)index * (size_t)sizeof(T)); - _items[0] = temp; - } - } - - const T& operator[](unsigned index) const { return _items[index]; } - T& operator[](unsigned index) { return _items[index]; } - const T& Front() const { return _items[0]; } - T& Front() { return _items[0]; } - const T& Back() const { return _items[_size - 1]; } - T& Back() { return _items[_size - 1]; } - - /* - void Swap(unsigned i, unsigned j) - { - T temp = _items[i]; - _items[i] = _items[j]; - _items[j] = temp; - } - */ - - int FindInSorted(const T item, unsigned left, unsigned right) const - { - while (left != right) - { - unsigned mid = (left + right) / 2; - const T midVal = (*this)[mid]; - if (item == midVal) - return mid; - if (item < midVal) - right = mid; - else - left = mid + 1; - } - return -1; - } - - int FindInSorted2(const T &item, unsigned left, unsigned right) const - { - while (left != right) - { - unsigned mid = (left + right) / 2; - const T& midVal = (*this)[mid]; - int comp = item.Compare(midVal); - if (comp == 0) - return mid; - if (comp < 0) - right = mid; - else - left = mid + 1; - } - return -1; - } - - int FindInSorted(const T item) const - { - return FindInSorted(item, 0, _size); - } - - int FindInSorted2(const T &item) const - { - return FindInSorted2(item, 0, _size); - } - - unsigned AddToUniqueSorted(const T item) - { - unsigned left = 0, right = _size; - while (left != right) - { - unsigned mid = (left + right) / 2; - const T midVal = (*this)[mid]; - if (item == midVal) - return mid; - if (item < midVal) - right = mid; - else - left = mid + 1; - } - Insert(right, item); - return right; - } - - unsigned AddToUniqueSorted2(const T &item) - { - unsigned left = 0, right = _size; - while (left != right) - { - unsigned mid = (left + right) / 2; - const T& midVal = (*this)[mid]; - int comp = item.Compare(midVal); - if (comp == 0) - return mid; - if (comp < 0) - right = mid; - else - left = mid + 1; - } - Insert(right, item); - return right; - } - - static void SortRefDown(T* p, unsigned k, unsigned size, int (*compare)(const T*, const T*, void *), void *param) - { - T temp = p[k]; - for (;;) - { - unsigned s = (k << 1); - if (s > size) - break; - if (s < size && compare(p + s + 1, p + s, param) > 0) - s++; - if (compare(&temp, p + s, param) >= 0) - break; - p[k] = p[s]; - k = s; - } - p[k] = temp; - } - - void Sort(int (*compare)(const T*, const T*, void *), void *param) - { - unsigned size = _size; - if (size <= 1) - return; - T* p = (&Front()) - 1; - { - unsigned i = size >> 1; - do - SortRefDown(p, i, size, compare, param); - while (--i != 0); - } - do - { - T temp = p[size]; - p[size--] = p[1]; - p[1] = temp; - SortRefDown(p, 1, size, compare, param); - } - while (size > 1); - } - - static void SortRefDown2(T* p, unsigned k, unsigned size) - { - T temp = p[k]; - for (;;) - { - unsigned s = (k << 1); - if (s > size) - break; - if (s < size && p[s + 1].Compare(p[s]) > 0) - s++; - if (temp.Compare(p[s]) >= 0) - break; - p[k] = p[s]; - k = s; - } - p[k] = temp; - } - - void Sort2() - { - unsigned size = _size; - if (size <= 1) - return; - T* p = (&Front()) - 1; - { - unsigned i = size >> 1; - do - SortRefDown2(p, i, size); - while (--i != 0); - } - do - { - T temp = p[size]; - p[size--] = p[1]; - p[1] = temp; - SortRefDown2(p, 1, size); - } - while (size > 1); - } -}; - -typedef CRecordVector<int> CIntVector; -typedef CRecordVector<unsigned int> CUIntVector; -typedef CRecordVector<bool> CBoolVector; -typedef CRecordVector<unsigned char> CByteVector; -typedef CRecordVector<void *> CPointerVector; - -template <class T> -class CObjectVector -{ - CPointerVector _v; -public: - unsigned Size() const { return _v.Size(); } - bool IsEmpty() const { return _v.IsEmpty(); } - void ReserveDown() { _v.ReserveDown(); } - // void Reserve(unsigned newCapacity) { _v.Reserve(newCapacity); } - void ClearAndReserve(unsigned newCapacity) { Clear(); _v.ClearAndReserve(newCapacity); } - - CObjectVector() {}; - CObjectVector(const CObjectVector &v) - { - unsigned size = v.Size(); - _v.ConstructReserve(size); - for (unsigned i = 0; i < size; i++) - _v.AddInReserved(new T(v[i])); - } - CObjectVector& operator=(const CObjectVector &v) - { - Clear(); - unsigned size = v.Size(); - _v.Reserve(size); - for (unsigned i = 0; i < size; i++) - _v.AddInReserved(new T(v[i])); - return *this; - } - - CObjectVector& operator+=(const CObjectVector &v) - { - unsigned size = v.Size(); - _v.Reserve(Size() + size); - for (unsigned i = 0; i < size; i++) - _v.AddInReserved(new T(v[i])); - return *this; - } - - const T& operator[](unsigned index) const { return *((T *)_v[index]); } - T& operator[](unsigned index) { return *((T *)_v[index]); } - const T& Front() const { return operator[](0); } - T& Front() { return operator[](0); } - const T& Back() const { return operator[](_v.Size() - 1); } - T& Back() { return operator[](_v.Size() - 1); } - - void MoveToFront(unsigned index) { _v.MoveToFront(index); } - - unsigned Add(const T& item) { return _v.Add(new T(item)); } - - void AddInReserved(const T& item) { _v.AddInReserved(new T(item)); } - - T& AddNew() - { - T *p = new T; - _v.Add(p); - return *p; - } - - T& AddNewInReserved() - { - T *p = new T; - _v.AddInReserved(p); - return *p; - } - - void Insert(unsigned index, const T& item) { _v.Insert(index, new T(item)); } - - T& InsertNew(unsigned index) - { - T *p = new T; - _v.Insert(index, p); - return *p; - } - - ~CObjectVector() - { - for (unsigned i = _v.Size(); i != 0;) - delete (T *)_v[--i]; - } - - void ClearAndFree() - { - Clear(); - _v.ClearAndFree(); - } - - void Clear() - { - for (unsigned i = _v.Size(); i != 0;) - delete (T *)_v[--i]; - _v.Clear(); - } - - void DeleteFrom(unsigned index) - { - unsigned size = _v.Size(); - for (unsigned i = index; i < size; i++) - delete (T *)_v[i]; - _v.DeleteFrom(index); - } - - void DeleteFrontal(unsigned num) - { - for (unsigned i = 0; i < num; i++) - delete (T *)_v[i]; - _v.DeleteFrontal(num); - } - - void DeleteBack() - { - delete (T *)_v[_v.Size() - 1]; - _v.DeleteBack(); - } - - void Delete(unsigned index) - { - delete (T *)_v[index]; - _v.Delete(index); - } - - /* - void Delete(unsigned index, unsigned num) - { - for (unsigned i = 0; i < num; i++) - delete (T *)_v[index + i]; - _v.Delete(index, num); - } - */ - - /* - int Find(const T& item) const - { - unsigned size = Size(); - for (unsigned i = 0; i < size; i++) - if (item == (*this)[i]) - return i; - return -1; - } - */ - - int FindInSorted(const T& item) const - { - unsigned left = 0, right = Size(); - while (left != right) - { - unsigned mid = (left + right) / 2; - const T& midVal = (*this)[mid]; - int comp = item.Compare(midVal); - if (comp == 0) - return mid; - if (comp < 0) - right = mid; - else - left = mid + 1; - } - return -1; - } - - unsigned AddToUniqueSorted(const T& item) - { - unsigned left = 0, right = Size(); - while (left != right) - { - unsigned mid = (left + right) / 2; - const T& midVal = (*this)[mid]; - int comp = item.Compare(midVal); - if (comp == 0) - return mid; - if (comp < 0) - right = mid; - else - left = mid + 1; - } - Insert(right, item); - return right; - } - - /* - unsigned AddToSorted(const T& item) - { - unsigned left = 0, right = Size(); - while (left != right) - { - unsigned mid = (left + right) / 2; - const T& midVal = (*this)[mid]; - int comp = item.Compare(midVal); - if (comp == 0) - { - right = mid + 1; - break; - } - if (comp < 0) - right = mid; - else - left = mid + 1; - } - Insert(right, item); - return right; - } - */ - - void Sort(int (*compare)(void *const *, void *const *, void *), void *param) - { _v.Sort(compare, param); } - - static int CompareObjectItems(void *const *a1, void *const *a2, void * /* param */) - { return (*(*((const T **)a1))).Compare(*(*((const T **)a2))); } - - void Sort() { _v.Sort(CompareObjectItems, 0); } -}; - -#define FOR_VECTOR(_i_, _v_) for (unsigned _i_ = 0; _i_ < (_v_).Size(); _i_++) - -#endif diff --git a/src/libs/7zip/win/CPP/Common/MyWindows.cpp b/src/libs/7zip/win/CPP/Common/MyWindows.cpp deleted file mode 100644 index 38c93fdb2..000000000 --- a/src/libs/7zip/win/CPP/Common/MyWindows.cpp +++ /dev/null @@ -1,145 +0,0 @@ -// MyWindows.cpp - -#include "StdAfx.h" - -#ifndef _WIN32 - -#include <stdlib.h> - -#include "MyWindows.h" - -static inline void *AllocateForBSTR(size_t cb) { return ::malloc(cb); } -static inline void FreeForBSTR(void *pv) { ::free(pv);} - -/* Win32 uses DWORD (32-bit) type to store size of string before (OLECHAR *) string. - We must select CBstrSizeType for another systems (not Win32): - - if (CBstrSizeType is UINT32), - then we support only strings smaller than 4 GB. - Win32 version always has that limitation. - - if (CBstrSizeType is UINT), - (UINT can be 16/32/64-bit) - We can support strings larger than 4 GB (if UINT is 64-bit), - but sizeof(UINT) can be different in parts compiled by - different compilers/settings, - and we can't send such BSTR strings between such parts. -*/ - -typedef UINT32 CBstrSizeType; -// typedef UINT CBstrSizeType; - -#define k_BstrSize_Max 0xFFFFFFFF -// #define k_BstrSize_Max UINT_MAX -// #define k_BstrSize_Max ((UINT)(INT)-1) - -BSTR SysAllocStringByteLen(LPCSTR s, UINT len) -{ - /* Original SysAllocStringByteLen in Win32 maybe fills only unaligned null OLECHAR at the end. - We provide also aligned null OLECHAR at the end. */ - - if (len >= (k_BstrSize_Max - sizeof(OLECHAR) - sizeof(OLECHAR) - sizeof(CBstrSizeType))) - return NULL; - - UINT size = (len + sizeof(OLECHAR) + sizeof(OLECHAR) - 1) & ~(sizeof(OLECHAR) - 1); - void *p = AllocateForBSTR(size + sizeof(CBstrSizeType)); - if (!p) - return NULL; - *(CBstrSizeType *)p = (CBstrSizeType)len; - BSTR bstr = (BSTR)((CBstrSizeType *)p + 1); - if (s) - memcpy(bstr, s, len); - for (; len < size; len++) - ((Byte *)bstr)[len] = 0; - return bstr; -} - -BSTR SysAllocStringLen(const OLECHAR *s, UINT len) -{ - if (len >= (k_BstrSize_Max - sizeof(OLECHAR) - sizeof(CBstrSizeType)) / sizeof(OLECHAR)) - return NULL; - - UINT size = len * sizeof(OLECHAR); - void *p = AllocateForBSTR(size + sizeof(CBstrSizeType) + sizeof(OLECHAR)); - if (!p) - return NULL; - *(CBstrSizeType *)p = (CBstrSizeType)size; - BSTR bstr = (BSTR)((CBstrSizeType *)p + 1); - if (s) - memcpy(bstr, s, size); - bstr[len] = 0; - return bstr; -} - -BSTR SysAllocString(const OLECHAR *s) -{ - if (!s) - return 0; - const OLECHAR *s2 = s; - while (*s2 != 0) - s2++; - return SysAllocStringLen(s, (UINT)(s2 - s)); -} - -void SysFreeString(BSTR bstr) -{ - if (bstr) - FreeForBSTR((CBstrSizeType *)bstr - 1); -} - -UINT SysStringByteLen(BSTR bstr) -{ - if (!bstr) - return 0; - return *((CBstrSizeType *)bstr - 1); -} - -UINT SysStringLen(BSTR bstr) -{ - if (!bstr) - return 0; - return *((CBstrSizeType *)bstr - 1) / sizeof(OLECHAR); -} - - -HRESULT VariantClear(VARIANTARG *prop) -{ - if (prop->vt == VT_BSTR) - SysFreeString(prop->bstrVal); - prop->vt = VT_EMPTY; - return S_OK; -} - -HRESULT VariantCopy(VARIANTARG *dest, const VARIANTARG *src) -{ - HRESULT res = ::VariantClear(dest); - if (res != S_OK) - return res; - if (src->vt == VT_BSTR) - { - dest->bstrVal = SysAllocStringByteLen((LPCSTR)src->bstrVal, - SysStringByteLen(src->bstrVal)); - if (!dest->bstrVal) - return E_OUTOFMEMORY; - dest->vt = VT_BSTR; - } - else - *dest = *src; - return S_OK; -} - -LONG CompareFileTime(const FILETIME* ft1, const FILETIME* ft2) -{ - if (ft1->dwHighDateTime < ft2->dwHighDateTime) return -1; - if (ft1->dwHighDateTime > ft2->dwHighDateTime) return 1; - if (ft1->dwLowDateTime < ft2->dwLowDateTime) return -1; - if (ft1->dwLowDateTime > ft2->dwLowDateTime) return 1; - return 0; -} - -DWORD GetLastError() -{ - return 0; -} - -#endif diff --git a/src/libs/7zip/win/CPP/Common/MyWindows.h b/src/libs/7zip/win/CPP/Common/MyWindows.h deleted file mode 100644 index 139a4e8b9..000000000 --- a/src/libs/7zip/win/CPP/Common/MyWindows.h +++ /dev/null @@ -1,216 +0,0 @@ -// MyWindows.h - -#ifndef __MY_WINDOWS_H -#define __MY_WINDOWS_H - -#ifdef _WIN32 - -#include <windows.h> - -#ifdef UNDER_CE - #undef VARIANT_TRUE - #define VARIANT_TRUE ((VARIANT_BOOL)-1) -#endif - -#else - -#include <stddef.h> // for wchar_t -#include <string.h> - -#include "MyGuidDef.h" - -#define WINAPI - -typedef char CHAR; -typedef unsigned char UCHAR; - -#undef BYTE -typedef unsigned char BYTE; - -typedef short SHORT; -typedef unsigned short USHORT; - -#undef WORD -typedef unsigned short WORD; -typedef short VARIANT_BOOL; - -typedef int INT; -typedef Int32 INT32; -typedef unsigned int UINT; -typedef UInt32 UINT32; -typedef INT32 LONG; // LONG, ULONG and DWORD must be 32-bit -typedef UINT32 ULONG; - -#undef DWORD -typedef UINT32 DWORD; - -typedef Int64 LONGLONG; -typedef UInt64 ULONGLONG; - -typedef struct _LARGE_INTEGER { LONGLONG QuadPart; } LARGE_INTEGER; -typedef struct _ULARGE_INTEGER { ULONGLONG QuadPart; } ULARGE_INTEGER; - -typedef const CHAR *LPCSTR; -typedef CHAR TCHAR; -typedef const TCHAR *LPCTSTR; -typedef wchar_t WCHAR; -typedef WCHAR OLECHAR; -typedef const WCHAR *LPCWSTR; -typedef OLECHAR *BSTR; -typedef const OLECHAR *LPCOLESTR; -typedef OLECHAR *LPOLESTR; - -typedef struct _FILETIME -{ - DWORD dwLowDateTime; - DWORD dwHighDateTime; -} FILETIME; - -#define HRESULT LONG -#define FAILED(Status) ((HRESULT)(Status)<0) -typedef ULONG PROPID; -typedef LONG SCODE; - -#define S_OK ((HRESULT)0x00000000L) -#define S_FALSE ((HRESULT)0x00000001L) -#define E_NOTIMPL ((HRESULT)0x80004001L) -#define E_NOINTERFACE ((HRESULT)0x80004002L) -#define E_ABORT ((HRESULT)0x80004004L) -#define E_FAIL ((HRESULT)0x80004005L) -#define STG_E_INVALIDFUNCTION ((HRESULT)0x80030001L) -#define E_OUTOFMEMORY ((HRESULT)0x8007000EL) -#define E_INVALIDARG ((HRESULT)0x80070057L) - -#ifdef _MSC_VER -#define STDMETHODCALLTYPE __stdcall -#else -#define STDMETHODCALLTYPE -#endif - -#define STDMETHOD_(t, f) virtual t STDMETHODCALLTYPE f -#define STDMETHOD(f) STDMETHOD_(HRESULT, f) -#define STDMETHODIMP_(type) type STDMETHODCALLTYPE -#define STDMETHODIMP STDMETHODIMP_(HRESULT) - -#define PURE = 0 - -#define MIDL_INTERFACE(x) struct - -#ifdef __cplusplus - -DEFINE_GUID(IID_IUnknown, -0x00000000, 0x0000, 0x0000, 0xC0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x46); -struct IUnknown -{ - STDMETHOD(QueryInterface) (REFIID iid, void **outObject) PURE; - STDMETHOD_(ULONG, AddRef)() PURE; - STDMETHOD_(ULONG, Release)() PURE; - #ifndef _WIN32 - virtual ~IUnknown() {} - #endif -}; - -typedef IUnknown *LPUNKNOWN; - -#endif - -#define VARIANT_TRUE ((VARIANT_BOOL)-1) -#define VARIANT_FALSE ((VARIANT_BOOL)0) - -enum VARENUM -{ - VT_EMPTY = 0, - VT_NULL = 1, - VT_I2 = 2, - VT_I4 = 3, - VT_R4 = 4, - VT_R8 = 5, - VT_CY = 6, - VT_DATE = 7, - VT_BSTR = 8, - VT_DISPATCH = 9, - VT_ERROR = 10, - VT_BOOL = 11, - VT_VARIANT = 12, - VT_UNKNOWN = 13, - VT_DECIMAL = 14, - VT_I1 = 16, - VT_UI1 = 17, - VT_UI2 = 18, - VT_UI4 = 19, - VT_I8 = 20, - VT_UI8 = 21, - VT_INT = 22, - VT_UINT = 23, - VT_VOID = 24, - VT_HRESULT = 25, - VT_FILETIME = 64 -}; - -typedef unsigned short VARTYPE; -typedef WORD PROPVAR_PAD1; -typedef WORD PROPVAR_PAD2; -typedef WORD PROPVAR_PAD3; - -typedef struct tagPROPVARIANT -{ - VARTYPE vt; - PROPVAR_PAD1 wReserved1; - PROPVAR_PAD2 wReserved2; - PROPVAR_PAD3 wReserved3; - union - { - CHAR cVal; - UCHAR bVal; - SHORT iVal; - USHORT uiVal; - LONG lVal; - ULONG ulVal; - INT intVal; - UINT uintVal; - LARGE_INTEGER hVal; - ULARGE_INTEGER uhVal; - VARIANT_BOOL boolVal; - SCODE scode; - FILETIME filetime; - BSTR bstrVal; - }; -} PROPVARIANT; - -typedef PROPVARIANT tagVARIANT; -typedef tagVARIANT VARIANT; -typedef VARIANT VARIANTARG; - -MY_EXTERN_C HRESULT VariantClear(VARIANTARG *prop); -MY_EXTERN_C HRESULT VariantCopy(VARIANTARG *dest, const VARIANTARG *src); - -typedef struct tagSTATPROPSTG -{ - LPOLESTR lpwstrName; - PROPID propid; - VARTYPE vt; -} STATPROPSTG; - -MY_EXTERN_C BSTR SysAllocStringByteLen(LPCSTR psz, UINT len); -MY_EXTERN_C BSTR SysAllocStringLen(const OLECHAR *sz, UINT len); -MY_EXTERN_C BSTR SysAllocString(const OLECHAR *sz); -MY_EXTERN_C void SysFreeString(BSTR bstr); -MY_EXTERN_C UINT SysStringByteLen(BSTR bstr); -MY_EXTERN_C UINT SysStringLen(BSTR bstr); - -MY_EXTERN_C DWORD GetLastError(); -MY_EXTERN_C LONG CompareFileTime(const FILETIME* ft1, const FILETIME* ft2); - -#define CP_ACP 0 -#define CP_OEMCP 1 -#define CP_UTF8 65001 - -typedef enum tagSTREAM_SEEK -{ - STREAM_SEEK_SET = 0, - STREAM_SEEK_CUR = 1, - STREAM_SEEK_END = 2 -} STREAM_SEEK; - -#endif -#endif diff --git a/src/libs/7zip/win/CPP/Common/NewHandler.cpp b/src/libs/7zip/win/CPP/Common/NewHandler.cpp deleted file mode 100644 index 9072376df..000000000 --- a/src/libs/7zip/win/CPP/Common/NewHandler.cpp +++ /dev/null @@ -1,162 +0,0 @@ -// NewHandler.cpp - -#include "StdAfx.h" - -#include <stdlib.h> - -#include "NewHandler.h" - -// #define DEBUG_MEMORY_LEAK - -#ifndef DEBUG_MEMORY_LEAK - -#ifdef _WIN32 - -/* -void * my_new(size_t size) -{ - // void *p = ::HeapAlloc(::GetProcessHeap(), 0, size); - void *p = ::malloc(size); - if (p == 0) - throw CNewException(); - return p; -} - -void my_delete(void *p) throw() -{ - // if (p == 0) return; ::HeapFree(::GetProcessHeap(), 0, p); - ::free(p); -} - -void * my_Realloc(void *p, size_t newSize, size_t oldSize) -{ - void *newBuf = my_new(newSize); - memcpy(newBuf, p, oldSize); - my_delete(p); - return newBuf; -} -*/ - -void * -#ifdef _MSC_VER -__cdecl -#endif -operator new(size_t size) -{ - // void *p = ::HeapAlloc(::GetProcessHeap(), 0, size); - void *p = ::malloc(size); - if (p == 0) - throw CNewException(); - return p; -} - -void -#ifdef _MSC_VER -__cdecl -#endif -operator delete(void *p) throw() -{ - // if (p == 0) return; ::HeapFree(::GetProcessHeap(), 0, p); - ::free(p); -} - -/* -void * -#ifdef _MSC_VER -__cdecl -#endif -operator new[](size_t size) -{ - // void *p = ::HeapAlloc(::GetProcessHeap(), 0, size); - void *p = ::malloc(size); - if (p == 0) - throw CNewException(); - return p; -} - -void -#ifdef _MSC_VER -__cdecl -#endif -operator delete[](void *p) throw() -{ - // if (p == 0) return; ::HeapFree(::GetProcessHeap(), 0, p); - ::free(p); -} -*/ - -#endif - -#else - -#include <stdio.h> - -// #pragma init_seg(lib) -const int kDebugSize = 1000000; -static void *a[kDebugSize]; -static int index = 0; - -static int numAllocs = 0; -void * __cdecl operator new(size_t size) -{ - numAllocs++; - void *p = HeapAlloc(GetProcessHeap(), 0, size); - if (index < kDebugSize) - { - a[index] = p; - index++; - } - if (p == 0) - throw CNewException(); - printf("Alloc %6d, size = %8d\n", numAllocs, size); - return p; -} - -class CC -{ -public: - CC() - { - for (int i = 0; i < kDebugSize; i++) - a[i] = 0; - } - ~CC() - { - for (int i = 0; i < kDebugSize; i++) - if (a[i] != 0) - return; - } -} g_CC; - - -void __cdecl operator delete(void *p) -{ - if (p == 0) - return; - /* - for (int i = 0; i < index; i++) - if (a[i] == p) - a[i] = 0; - */ - HeapFree(GetProcessHeap(), 0, p); - numAllocs--; - printf("Free %d\n", numAllocs); -} - -#endif - -/* -int MemErrorVC(size_t) -{ - throw CNewException(); - // return 1; -} -CNewHandlerSetter::CNewHandlerSetter() -{ - // MemErrorOldVCFunction = _set_new_handler(MemErrorVC); -} -CNewHandlerSetter::~CNewHandlerSetter() -{ - // _set_new_handler(MemErrorOldVCFunction); -} -*/ diff --git a/src/libs/7zip/win/CPP/Common/NewHandler.h b/src/libs/7zip/win/CPP/Common/NewHandler.h deleted file mode 100644 index e3e7422c8..000000000 --- a/src/libs/7zip/win/CPP/Common/NewHandler.h +++ /dev/null @@ -1,68 +0,0 @@ -// Common/NewHandler.h - -#ifndef __COMMON_NEW_HANDLER_H -#define __COMMON_NEW_HANDLER_H - -/* -This file must be included before any code that uses operators "delete" or "new". -Also you must compile and link "NewHandler.cpp", if you use MSVC 6.0. -The operator "new" in MSVC 6.0 doesn't throw exception "bad_alloc". -So we define another version of operator "new" that throws "CNewException" on failure. - -If you use compiler that throws exception in "new" operator (GCC or new version of MSVC), -you can compile without "NewHandler.cpp". So standard exception "bad_alloc" will be used. - -It's still allowed to use redefined version of operator "new" from "NewHandler.cpp" -with any compiler. 7-Zip's code can work with "bad_alloc" and "CNewException" exceptions. -But if you use some additional code (outside of 7-Zip's code), you must check -that redefined version of operator "new" (that throws CNewException) is not -problem for your code. - -Also we declare delete(void *p) throw() that creates smaller code. -*/ - - -class CNewException {}; - -#ifdef WIN32 -// We can compile my_new and my_delete with _fastcall -/* -void * my_new(size_t size); -void my_delete(void *p) throw(); -// void * my_Realloc(void *p, size_t newSize, size_t oldSize); -*/ -#endif - -#ifdef _WIN32 - -void * -#ifdef _MSC_VER -__cdecl -#endif -operator new(size_t size); - -void -#ifdef _MSC_VER -__cdecl -#endif -operator delete(void *p) throw(); - -#endif - -/* -#ifdef _WIN32 -void * -#ifdef _MSC_VER -__cdecl -#endif -operator new[](size_t size); - -void -#ifdef _MSC_VER -__cdecl -#endif -operator delete[](void *p) throw(); -#endif -*/ - -#endif diff --git a/src/libs/7zip/win/CPP/Common/StdAfx.h b/src/libs/7zip/win/CPP/Common/StdAfx.h deleted file mode 100644 index 420f5c326..000000000 --- a/src/libs/7zip/win/CPP/Common/StdAfx.h +++ /dev/null @@ -1,8 +0,0 @@ -// StdAfx.h - -#ifndef __STDAFX_H -#define __STDAFX_H - -#include "Common.h" - -#endif diff --git a/src/libs/7zip/win/CPP/Common/StdOutStream.cpp b/src/libs/7zip/win/CPP/Common/StdOutStream.cpp deleted file mode 100644 index 6aed31a31..000000000 --- a/src/libs/7zip/win/CPP/Common/StdOutStream.cpp +++ /dev/null @@ -1,106 +0,0 @@ -// Common/StdOutStream.cpp - -#include "StdAfx.h" - -#include <tchar.h> - -#include "IntToString.h" -#include "StdOutStream.h" -#include "StringConvert.h" -#include "UTFConvert.h" - -static const char kNewLineChar = '\n'; - -static const char *kFileOpenMode = "wt"; - -extern int g_CodePage; - -CStdOutStream g_StdOut(stdout); -CStdOutStream g_StdErr(stderr); - -bool CStdOutStream::Open(const char *fileName) throw() -{ - Close(); - _stream = fopen(fileName, kFileOpenMode); - _streamIsOpen = (_stream != 0); - return _streamIsOpen; -} - -bool CStdOutStream::Close() throw() -{ - if (!_streamIsOpen) - return true; - if (fclose(_stream) != 0) - return false; - _stream = 0; - _streamIsOpen = false; - return true; -} - -bool CStdOutStream::Flush() throw() -{ - return (fflush(_stream) == 0); -} - -CStdOutStream & endl(CStdOutStream & outStream) throw() -{ - return outStream << kNewLineChar; -} - -CStdOutStream & CStdOutStream::operator<<(const wchar_t *s) -{ - int codePage = g_CodePage; - if (codePage == -1) - codePage = CP_OEMCP; - AString dest; - if (codePage == CP_UTF8) - ConvertUnicodeToUTF8(s, dest); - else - UnicodeStringToMultiByte2(dest, s, (UINT)codePage); - return operator<<((const char *)dest); -} - -void StdOut_Convert_UString_to_AString(const UString &s, AString &temp) -{ - int codePage = g_CodePage; - if (codePage == -1) - codePage = CP_OEMCP; - if (codePage == CP_UTF8) - ConvertUnicodeToUTF8(s, temp); - else - UnicodeStringToMultiByte2(temp, s, (UINT)codePage); -} - -void CStdOutStream::PrintUString(const UString &s, AString &temp) -{ - StdOut_Convert_UString_to_AString(s, temp); - *this << (const char *)temp; -} - -CStdOutStream & CStdOutStream::operator<<(Int32 number) throw() -{ - char s[32]; - ConvertInt64ToString(number, s); - return operator<<(s); -} - -CStdOutStream & CStdOutStream::operator<<(Int64 number) throw() -{ - char s[32]; - ConvertInt64ToString(number, s); - return operator<<(s); -} - -CStdOutStream & CStdOutStream::operator<<(UInt32 number) throw() -{ - char s[16]; - ConvertUInt32ToString(number, s); - return operator<<(s); -} - -CStdOutStream & CStdOutStream::operator<<(UInt64 number) throw() -{ - char s[32]; - ConvertUInt64ToString(number, s); - return operator<<(s); -} diff --git a/src/libs/7zip/win/CPP/Common/StdOutStream.h b/src/libs/7zip/win/CPP/Common/StdOutStream.h deleted file mode 100644 index 0a8c0febb..000000000 --- a/src/libs/7zip/win/CPP/Common/StdOutStream.h +++ /dev/null @@ -1,62 +0,0 @@ -// Common/StdOutStream.h - -#ifndef __COMMON_STD_OUT_STREAM_H -#define __COMMON_STD_OUT_STREAM_H - -#include <stdio.h> - -#include "MyString.h" -#include "MyTypes.h" - -class CStdOutStream -{ - FILE *_stream; - bool _streamIsOpen; -public: - CStdOutStream(): _stream(0), _streamIsOpen(false) {}; - CStdOutStream(FILE *stream): _stream(stream), _streamIsOpen(false) {}; - ~CStdOutStream() { Close(); } - - // void AttachStdStream(FILE *stream) { _stream = stream; _streamIsOpen = false; } - // bool IsDefined() const { return _stream != NULL; } - - operator FILE *() { return _stream; } - bool Open(const char *fileName) throw(); - bool Close() throw(); - bool Flush() throw(); - - CStdOutStream & operator<<(CStdOutStream & (* func)(CStdOutStream &)) - { - (*func)(*this); - return *this; - } - - CStdOutStream & operator<<(const char *s) throw() - { - fputs(s, _stream); - return *this; - } - - CStdOutStream & operator<<(char c) throw() - { - fputc(c, _stream); - return *this; - } - - CStdOutStream & operator<<(Int32 number) throw(); - CStdOutStream & operator<<(Int64 number) throw(); - CStdOutStream & operator<<(UInt32 number) throw(); - CStdOutStream & operator<<(UInt64 number) throw(); - - CStdOutStream & operator<<(const wchar_t *s); - void PrintUString(const UString &s, AString &temp); -}; - -CStdOutStream & endl(CStdOutStream & outStream) throw(); - -extern CStdOutStream g_StdOut; -extern CStdOutStream g_StdErr; - -void StdOut_Convert_UString_to_AString(const UString &s, AString &temp); - -#endif diff --git a/src/libs/7zip/win/CPP/Common/StringConvert.cpp b/src/libs/7zip/win/CPP/Common/StringConvert.cpp deleted file mode 100644 index 0443a06ca..000000000 --- a/src/libs/7zip/win/CPP/Common/StringConvert.cpp +++ /dev/null @@ -1,165 +0,0 @@ -// Common/StringConvert.cpp - -#include "StdAfx.h" - -#include "StringConvert.h" - -#ifndef _WIN32 -#include <stdlib.h> -#endif - -#ifdef _WIN32 -UString MultiByteToUnicodeString(const AString &srcString, UINT codePage) -{ - UString resultString; - if (!srcString.IsEmpty()) - { - int numChars = MultiByteToWideChar(codePage, 0, srcString, - srcString.Len(), resultString.GetBuffer(srcString.Len()), - srcString.Len() + 1); - if (numChars == 0) - throw 282228; - resultString.ReleaseBuffer(numChars); - } - return resultString; -} - -void MultiByteToUnicodeString2(UString &dest, const AString &srcString, UINT codePage) -{ - dest.Empty(); - if (!srcString.IsEmpty()) - { - wchar_t *destBuf = dest.GetBuffer(srcString.Len()); - const char *sp = (const char *)srcString; - unsigned i; - for (i = 0;;) - { - char c = sp[i]; - if ((Byte)c >= 0x80 || c == 0) - break; - destBuf[i++] = (wchar_t)c; - } - - if (i != srcString.Len()) - { - unsigned numChars = MultiByteToWideChar(codePage, 0, sp + i, - srcString.Len() - i, destBuf + i, - srcString.Len() + 1 - i); - if (numChars == 0) - throw 282228; - i += numChars; - } - dest.ReleaseBuffer(i); - } -} - -void UnicodeStringToMultiByte2(AString &dest, const UString &s, UINT codePage, char defaultChar, bool &defaultCharWasUsed) -{ - dest.Empty(); - defaultCharWasUsed = false; - if (!s.IsEmpty()) - { - unsigned numRequiredBytes = s.Len() * 2; - char *destBuf = dest.GetBuffer(numRequiredBytes); - unsigned i; - const wchar_t *sp = (const wchar_t *)s; - for (i = 0;;) - { - wchar_t c = sp[i]; - if (c >= 0x80 || c == 0) - break; - destBuf[i++] = (char)c; - } - defaultCharWasUsed = false; - if (i != s.Len()) - { - BOOL defUsed; - unsigned numChars = WideCharToMultiByte(codePage, 0, sp + i, s.Len() - i, - destBuf + i, numRequiredBytes + 1 - i, - &defaultChar, &defUsed); - defaultCharWasUsed = (defUsed != FALSE); - if (numChars == 0) - throw 282229; - i += numChars; - } - dest.ReleaseBuffer(i); - } -} - -void UnicodeStringToMultiByte2(AString &dest, const UString &srcString, UINT codePage) -{ - bool defaultCharWasUsed; - UnicodeStringToMultiByte2(dest, srcString, codePage, '_', defaultCharWasUsed); -} - -AString UnicodeStringToMultiByte(const UString &s, UINT codePage, char defaultChar, bool &defaultCharWasUsed) -{ - AString dest; - defaultCharWasUsed = false; - if (!s.IsEmpty()) - { - unsigned numRequiredBytes = s.Len() * 2; - BOOL defUsed; - int numChars = WideCharToMultiByte(codePage, 0, s, s.Len(), - dest.GetBuffer(numRequiredBytes), numRequiredBytes + 1, - &defaultChar, &defUsed); - defaultCharWasUsed = (defUsed != FALSE); - if (numChars == 0) - throw 282229; - dest.ReleaseBuffer(numChars); - } - return dest; -} - -AString UnicodeStringToMultiByte(const UString &srcString, UINT codePage) -{ - bool defaultCharWasUsed; - return UnicodeStringToMultiByte(srcString, codePage, '_', defaultCharWasUsed); -} - -#ifndef UNDER_CE -AString SystemStringToOemString(const CSysString &srcString) -{ - AString result; - CharToOem(srcString, result.GetBuffer(srcString.Len() * 2)); - result.ReleaseBuffer(); - return result; -} -#endif - -#else - -UString MultiByteToUnicodeString(const AString &srcString, UINT codePage) -{ - UString resultString; - for (unsigned i = 0; i < srcString.Len(); i++) - resultString += (wchar_t)srcString[i]; - /* - if (!srcString.IsEmpty()) - { - int numChars = mbstowcs(resultString.GetBuffer(srcString.Len()), srcString, srcString.Len() + 1); - if (numChars < 0) throw "Your environment does not support UNICODE"; - resultString.ReleaseBuffer(numChars); - } - */ - return resultString; -} - -AString UnicodeStringToMultiByte(const UString &srcString, UINT codePage) -{ - AString resultString; - for (unsigned i = 0; i < srcString.Len(); i++) - resultString += (char)srcString[i]; - /* - if (!srcString.IsEmpty()) - { - int numRequiredBytes = srcString.Len() * 6 + 1; - int numChars = wcstombs(resultString.GetBuffer(numRequiredBytes), srcString, numRequiredBytes); - if (numChars < 0) throw "Your environment does not support UNICODE"; - resultString.ReleaseBuffer(numChars); - } - */ - return resultString; -} - -#endif diff --git a/src/libs/7zip/win/CPP/Common/StringConvert.h b/src/libs/7zip/win/CPP/Common/StringConvert.h deleted file mode 100644 index 8eea72ef2..000000000 --- a/src/libs/7zip/win/CPP/Common/StringConvert.h +++ /dev/null @@ -1,77 +0,0 @@ -// Common/StringConvert.h - -#ifndef __COMMON_STRING_CONVERT_H -#define __COMMON_STRING_CONVERT_H - -#include "MyString.h" -#include "MyWindows.h" - -UString MultiByteToUnicodeString(const AString &srcString, UINT codePage = CP_ACP); - -// optimized versions that work faster for ASCII strings -void MultiByteToUnicodeString2(UString &dest, const AString &srcString, UINT codePage = CP_ACP); -void UnicodeStringToMultiByte2(AString &dest, const UString &s, UINT codePage, char defaultChar, bool &defaultCharWasUsed); -void UnicodeStringToMultiByte2(AString &dest, const UString &srcString, UINT codePage); - -AString UnicodeStringToMultiByte(const UString &srcString, UINT codePage, char defaultChar, bool &defaultCharWasUsed); -AString UnicodeStringToMultiByte(const UString &srcString, UINT codePage = CP_ACP); - -inline const wchar_t* GetUnicodeString(const wchar_t* unicodeString) - { return unicodeString; } -inline const UString& GetUnicodeString(const UString &unicodeString) - { return unicodeString; } -inline UString GetUnicodeString(const AString &ansiString) - { return MultiByteToUnicodeString(ansiString); } -inline UString GetUnicodeString(const AString &multiByteString, UINT codePage) - { return MultiByteToUnicodeString(multiByteString, codePage); } -inline const wchar_t* GetUnicodeString(const wchar_t* unicodeString, UINT) - { return unicodeString; } -inline const UString& GetUnicodeString(const UString &unicodeString, UINT) - { return unicodeString; } - -inline const char* GetAnsiString(const char* ansiString) - { return ansiString; } -inline const AString& GetAnsiString(const AString &ansiString) - { return ansiString; } -inline AString GetAnsiString(const UString &unicodeString) - { return UnicodeStringToMultiByte(unicodeString); } - -inline const char* GetOemString(const char* oemString) - { return oemString; } -inline const AString& GetOemString(const AString &oemString) - { return oemString; } -inline AString GetOemString(const UString &unicodeString) - { return UnicodeStringToMultiByte(unicodeString, CP_OEMCP); } - - -#ifdef _UNICODE - inline const wchar_t* GetSystemString(const wchar_t* unicodeString) - { return unicodeString;} - inline const UString& GetSystemString(const UString &unicodeString) - { return unicodeString;} - inline const wchar_t* GetSystemString(const wchar_t* unicodeString, UINT /* codePage */) - { return unicodeString;} - inline const UString& GetSystemString(const UString &unicodeString, UINT /* codePage */) - { return unicodeString;} - inline UString GetSystemString(const AString &multiByteString, UINT codePage) - { return MultiByteToUnicodeString(multiByteString, codePage);} - inline UString GetSystemString(const AString &multiByteString) - { return MultiByteToUnicodeString(multiByteString);} -#else - inline const char* GetSystemString(const char *ansiString) - { return ansiString; } - inline const AString& GetSystemString(const AString &multiByteString, UINT) - { return multiByteString; } - inline const char * GetSystemString(const char *multiByteString, UINT) - { return multiByteString; } - inline AString GetSystemString(const UString &unicodeString) - { return UnicodeStringToMultiByte(unicodeString); } - inline AString GetSystemString(const UString &unicodeString, UINT codePage) - { return UnicodeStringToMultiByte(unicodeString, codePage); } -#endif - -#ifndef UNDER_CE -AString SystemStringToOemString(const CSysString &srcString); -#endif - -#endif diff --git a/src/libs/7zip/win/CPP/Common/StringToInt.cpp b/src/libs/7zip/win/CPP/Common/StringToInt.cpp deleted file mode 100644 index 2023fcc2c..000000000 --- a/src/libs/7zip/win/CPP/Common/StringToInt.cpp +++ /dev/null @@ -1,144 +0,0 @@ -// Common/StringToInt.cpp - -#include "StdAfx.h" - -#include "StringToInt.h" - -static const UInt32 k_UInt32_max = 0xFFFFFFFF; -static const UInt64 k_UInt64_max = UINT64_CONST(0xFFFFFFFFFFFFFFFF); -// static const UInt64 k_UInt64_max = (UInt64)(Int64)-1; - -#define CONVERT_STRING_TO_UINT_FUNC(uintType, charType) \ - uintType ConvertStringTo ## uintType(const charType *s, const charType **end) throw() { \ - if (end) *end = s; \ - uintType res = 0; \ - for (;; s++) { \ - charType c = *s; \ - if (c < '0' || c > '9') { if (end) *end = s; return res; } \ - if (res > (k_ ## uintType ## _max) / 10) return 0; \ - res *= 10; \ - unsigned v = (c - '0'); \ - if (res > (k_ ## uintType ## _max) - v) return 0; \ - res += v; }} - -CONVERT_STRING_TO_UINT_FUNC(UInt32, char) -CONVERT_STRING_TO_UINT_FUNC(UInt32, wchar_t) -CONVERT_STRING_TO_UINT_FUNC(UInt64, char) -CONVERT_STRING_TO_UINT_FUNC(UInt64, wchar_t) - -Int32 ConvertStringToInt32(const wchar_t *s, const wchar_t **end) throw() -{ - if (end) - *end = s; - const wchar_t *s2 = s; - if (*s == '-') - s2++; - if (*s2 == 0) - return 0; - const wchar_t *end2; - UInt32 res = ConvertStringToUInt32(s2, &end2); - if (*s == '-') - { - if (res > ((UInt32)1 << (32 - 1))) - return 0; - } - else if ((res & ((UInt32)1 << (32 - 1))) != 0) - return 0; - if (end) - *end = end2; - if (*s == '-') - return -(Int32)res; - return (Int32)res; -} - -UInt32 ConvertOctStringToUInt32(const char *s, const char **end) throw() -{ - if (end) - *end = s; - UInt32 res = 0; - for (;; s++) - { - char c = *s; - if (c < '0' || c > '7') - { - if (end) - *end = s; - return res; - } - if ((res & (UInt32)7 << (32 - 3)) != 0) - return 0; - res <<= 3; - res |= (unsigned)(c - '0'); - } -} - -UInt64 ConvertOctStringToUInt64(const char *s, const char **end) throw() -{ - if (end) - *end = s; - UInt64 res = 0; - for (;; s++) - { - char c = *s; - if (c < '0' || c > '7') - { - if (end) - *end = s; - return res; - } - if ((res & (UInt64)7 << (64 - 3)) != 0) - return 0; - res <<= 3; - res |= (unsigned)(c - '0'); - } -} - -UInt32 ConvertHexStringToUInt32(const char *s, const char **end) throw() -{ - if (end) - *end = s; - UInt32 res = 0; - for (;; s++) - { - char c = *s; - unsigned v; - if (c >= '0' && c <= '9') v = (c - '0'); - else if (c >= 'A' && c <= 'F') v = 10 + (c - 'A'); - else if (c >= 'a' && c <= 'f') v = 10 + (c - 'a'); - else - { - if (end) - *end = s; - return res; - } - if ((res & (UInt32)0xF << (32 - 4)) != 0) - return 0; - res <<= 4; - res |= v; - } -} - -UInt64 ConvertHexStringToUInt64(const char *s, const char **end) throw() -{ - if (end) - *end = s; - UInt64 res = 0; - for (;; s++) - { - char c = *s; - unsigned v; - if (c >= '0' && c <= '9') v = (c - '0'); - else if (c >= 'A' && c <= 'F') v = 10 + (c - 'A'); - else if (c >= 'a' && c <= 'f') v = 10 + (c - 'a'); - else - { - if (end) - *end = s; - return res; - } - if ((res & (UInt64)0xF << (64 - 4)) != 0) - return 0; - res <<= 4; - res |= v; - } -} diff --git a/src/libs/7zip/win/CPP/Common/StringToInt.h b/src/libs/7zip/win/CPP/Common/StringToInt.h deleted file mode 100644 index 5c5d7d7fe..000000000 --- a/src/libs/7zip/win/CPP/Common/StringToInt.h +++ /dev/null @@ -1,21 +0,0 @@ -// Common/StringToInt.h - -#ifndef __COMMON_STRING_TO_INT_H -#define __COMMON_STRING_TO_INT_H - -#include "MyTypes.h" - -UInt32 ConvertStringToUInt32(const char *s, const char **end) throw(); -UInt64 ConvertStringToUInt64(const char *s, const char **end) throw(); -UInt32 ConvertStringToUInt32(const wchar_t *s, const wchar_t **end) throw(); -UInt64 ConvertStringToUInt64(const wchar_t *s, const wchar_t **end) throw(); - -Int32 ConvertStringToInt32(const wchar_t *s, const wchar_t **end) throw(); - -UInt32 ConvertOctStringToUInt32(const char *s, const char **end) throw(); -UInt64 ConvertOctStringToUInt64(const char *s, const char **end) throw(); - -UInt32 ConvertHexStringToUInt32(const char *s, const char **end) throw(); -UInt64 ConvertHexStringToUInt64(const char *s, const char **end) throw(); - -#endif diff --git a/src/libs/7zip/win/CPP/Common/UTFConvert.cpp b/src/libs/7zip/win/CPP/Common/UTFConvert.cpp deleted file mode 100644 index 38bac3331..000000000 --- a/src/libs/7zip/win/CPP/Common/UTFConvert.cpp +++ /dev/null @@ -1,176 +0,0 @@ -// UTFConvert.cpp - -#include "StdAfx.h" - -#include "MyTypes.h" -#include "UTFConvert.h" - -static const Byte kUtf8Limits[5] = { 0xC0, 0xE0, 0xF0, 0xF8, 0xFC }; - -bool CheckUTF8(const char *src) throw() -{ - for (;;) - { - Byte c; - unsigned numAdds; - c = *src++; - if (c == 0) - return true; - - if (c < 0x80) - continue; - if (c < 0xC0) - return false; - for (numAdds = 1; numAdds < 5; numAdds++) - if (c < kUtf8Limits[numAdds]) - break; - UInt32 value = (c - kUtf8Limits[numAdds - 1]); - - do - { - Byte c2 = *src++; - if (c2 < 0x80 || c2 >= 0xC0) - return false; - value <<= 6; - value |= (c2 - 0x80); - } - while (--numAdds); - - if (value >= 0x110000) - return false; - } -} - - -static Bool Utf8_To_Utf16(wchar_t *dest, size_t *destLen, const char *src, size_t srcLen) throw() -{ - size_t destPos = 0, srcPos = 0; - for (;;) - { - Byte c; - unsigned numAdds; - if (srcPos == srcLen) - { - *destLen = destPos; - return True; - } - c = (Byte)src[srcPos++]; - - if (c < 0x80) - { - if (dest) - dest[destPos] = (wchar_t)c; - destPos++; - continue; - } - if (c < 0xC0) - break; - for (numAdds = 1; numAdds < 5; numAdds++) - if (c < kUtf8Limits[numAdds]) - break; - UInt32 value = (c - kUtf8Limits[numAdds - 1]); - - do - { - Byte c2; - if (srcPos == srcLen) - break; - c2 = (Byte)src[srcPos++]; - if (c2 < 0x80 || c2 >= 0xC0) - break; - value <<= 6; - value |= (c2 - 0x80); - } - while (--numAdds); - - if (value < 0x10000) - { - if (dest) - dest[destPos] = (wchar_t)value; - destPos++; - } - else - { - value -= 0x10000; - if (value >= 0x100000) - break; - if (dest) - { - dest[destPos + 0] = (wchar_t)(0xD800 + (value >> 10)); - dest[destPos + 1] = (wchar_t)(0xDC00 + (value & 0x3FF)); - } - destPos += 2; - } - } - *destLen = destPos; - return False; -} - -static Bool Utf16_To_Utf8(char *dest, size_t *destLen, const wchar_t *src, size_t srcLen) -{ - size_t destPos = 0, srcPos = 0; - for (;;) - { - unsigned numAdds; - UInt32 value; - if (srcPos == srcLen) - { - *destLen = destPos; - return True; - } - value = src[srcPos++]; - if (value < 0x80) - { - if (dest) - dest[destPos] = (char)value; - destPos++; - continue; - } - if (value >= 0xD800 && value < 0xE000) - { - UInt32 c2; - if (value >= 0xDC00 || srcPos == srcLen) - break; - c2 = src[srcPos++]; - if (c2 < 0xDC00 || c2 >= 0xE000) - break; - value = (((value - 0xD800) << 10) | (c2 - 0xDC00)) + 0x10000; - } - for (numAdds = 1; numAdds < 5; numAdds++) - if (value < (((UInt32)1) << (numAdds * 5 + 6))) - break; - if (dest) - dest[destPos] = (char)(kUtf8Limits[numAdds - 1] + (value >> (6 * numAdds))); - destPos++; - do - { - numAdds--; - if (dest) - dest[destPos] = (char)(0x80 + ((value >> (6 * numAdds)) & 0x3F)); - destPos++; - } - while (numAdds != 0); - } - *destLen = destPos; - return False; -} - -bool ConvertUTF8ToUnicode(const AString &src, UString &dest) -{ - dest.Empty(); - size_t destLen = 0; - Utf8_To_Utf16(NULL, &destLen, src, src.Len()); - Bool res = Utf8_To_Utf16(dest.GetBuffer((unsigned)destLen), &destLen, src, src.Len()); - dest.ReleaseBuffer((unsigned)destLen); - return res ? true : false; -} - -bool ConvertUnicodeToUTF8(const UString &src, AString &dest) -{ - dest.Empty(); - size_t destLen = 0; - Utf16_To_Utf8(NULL, &destLen, src, src.Len()); - Bool res = Utf16_To_Utf8(dest.GetBuffer((unsigned)destLen), &destLen, src, src.Len()); - dest.ReleaseBuffer((unsigned)destLen); - return res ? true : false; -} diff --git a/src/libs/7zip/win/CPP/Common/UTFConvert.h b/src/libs/7zip/win/CPP/Common/UTFConvert.h deleted file mode 100644 index 16b02fe45..000000000 --- a/src/libs/7zip/win/CPP/Common/UTFConvert.h +++ /dev/null @@ -1,12 +0,0 @@ -// Common/UTFConvert.h - -#ifndef __COMMON_UTF_CONVERT_H -#define __COMMON_UTF_CONVERT_H - -#include "MyString.h" - -bool CheckUTF8(const char *src) throw(); -bool ConvertUTF8ToUnicode(const AString &utfString, UString &resultString); -bool ConvertUnicodeToUTF8(const UString &unicodeString, AString &resultString); - -#endif diff --git a/src/libs/7zip/win/CPP/Common/Wildcard.cpp b/src/libs/7zip/win/CPP/Common/Wildcard.cpp deleted file mode 100644 index e88a1cf1c..000000000 --- a/src/libs/7zip/win/CPP/Common/Wildcard.cpp +++ /dev/null @@ -1,615 +0,0 @@ -// Common/Wildcard.cpp - -#include "StdAfx.h" - -#include "Wildcard.h" - -bool g_CaseSensitive = - #ifdef _WIN32 - false; - #else - true; - #endif - - -bool IsPath1PrefixedByPath2(const wchar_t *s1, const wchar_t *s2) -{ - if (g_CaseSensitive) - { - for (;;) - { - wchar_t c2 = *s2++; if (c2 == 0) return true; - wchar_t c1 = *s1++; - if (MyCharUpper(c1) != - MyCharUpper(c2)) - return false; - } - } - - for (;;) - { - wchar_t c2 = *s2++; if (c2 == 0) return true; - wchar_t c1 = *s1++; if (c1 != c2) return false; - } -} - -int CompareFileNames(const wchar_t *s1, const wchar_t *s2) STRING_UNICODE_THROW -{ - if (g_CaseSensitive) - return wcscmp(s1, s2); - return MyStringCompareNoCase(s1, s2); -} - -#ifndef USE_UNICODE_FSTRING -int CompareFileNames(const char *s1, const char *s2) -{ - if (g_CaseSensitive) - return wcscmp(fs2us(s1), fs2us(s2)); - return MyStringCompareNoCase(fs2us(s1), fs2us(s2)); -} -#endif - -// ----------------------------------------- -// this function compares name with mask -// ? - any char -// * - any char or empty - -static bool EnhancedMaskTest(const wchar_t *mask, const wchar_t *name) -{ - for (;;) - { - wchar_t m = *mask; - wchar_t c = *name; - if (m == 0) - return (c == 0); - if (m == '*') - { - if (EnhancedMaskTest(mask + 1, name)) - return true; - if (c == 0) - return false; - } - else - { - if (m == '?') - { - if (c == 0) - return false; - } - else if (m != c) - if (g_CaseSensitive || MyCharUpper(m) != MyCharUpper(c)) - return false; - mask++; - } - name++; - } -} - -// -------------------------------------------------- -// Splits path to strings - -void SplitPathToParts(const UString &path, UStringVector &pathParts) -{ - pathParts.Clear(); - unsigned len = path.Len(); - if (len == 0) - return; - UString name; - unsigned prev = 0; - for (unsigned i = 0; i < len; i++) - if (IsCharDirLimiter(path[i])) - { - name.SetFrom(path.Ptr(prev), i - prev); - pathParts.Add(name); - prev = i + 1; - } - name.SetFrom(path.Ptr(prev), len - prev); - pathParts.Add(name); -} - -void SplitPathToParts_2(const UString &path, UString &dirPrefix, UString &name) -{ - const wchar_t *start = path; - const wchar_t *p = start + path.Len(); - for (; p != start; p--) - if (IsCharDirLimiter(*(p - 1))) - break; - dirPrefix.SetFrom(path, (unsigned)(p - start)); - name = p; -} - -void SplitPathToParts_Smart(const UString &path, UString &dirPrefix, UString &name) -{ - const wchar_t *start = path; - const wchar_t *p = start + path.Len(); - if (p != start) - { - if (IsCharDirLimiter(*(p - 1))) - p--; - for (; p != start; p--) - if (IsCharDirLimiter(*(p - 1))) - break; - } - dirPrefix.SetFrom(path, (unsigned)(p - start)); - name = p; -} - -UString ExtractDirPrefixFromPath(const UString &path) -{ - const wchar_t *start = path; - const wchar_t *p = start + path.Len(); - for (; p != start; p--) - if (IsCharDirLimiter(*(p - 1))) - break; - return path.Left((unsigned)(p - start)); -} - -UString ExtractFileNameFromPath(const UString &path) -{ - const wchar_t *start = path; - const wchar_t *p = start + path.Len(); - for (; p != start; p--) - if (IsCharDirLimiter(*(p - 1))) - break; - return p; -} - - -bool DoesWildcardMatchName(const UString &mask, const UString &name) -{ - return EnhancedMaskTest(mask, name); -} - -bool DoesNameContainWildcard(const UString &path) -{ - for (unsigned i = 0; i < path.Len(); i++) - { - wchar_t c = path[i]; - if (c == '*' || c == '?') - return true; - } - return false; -} - - -// ----------------------------------------------------------' -// NWildcard - -namespace NWildcard { - - -#ifdef _WIN32 -bool IsDriveColonName(const wchar_t *s) -{ - wchar_t c = s[0]; - return c != 0 && s[1] == ':' && s[2] == 0 && (c >= 'a' && c <= 'z' || c >= 'A' && c <= 'Z'); -} -#endif - -/* - -M = MaskParts.Size(); -N = TestNameParts.Size(); - - File Dir -ForFile rec M<=N [N-M, N) - -!ForDir nonrec M=N [0, M) - - -ForDir rec M<N [0, M) ... [N-M-1, N-1) same as ForBoth-File -!ForFile nonrec [0, M) same as ForBoth-File - -ForFile rec m<=N [0, M) ... [N-M, N) same as ForBoth-File -ForDir nonrec [0, M) same as ForBoth-File - -*/ - -bool CItem::AreAllAllowed() const -{ - return ForFile && ForDir && WildcardMatching && PathParts.Size() == 1 && PathParts.Front() == L"*"; -} - -bool CItem::CheckPath(const UStringVector &pathParts, bool isFile) const -{ - if (!isFile && !ForDir) - return false; - int delta = (int)pathParts.Size() - (int)PathParts.Size(); - if (delta < 0) - return false; - int start = 0; - int finish = 0; - - if (isFile) - { - if (!ForDir) - { - if (Recursive) - start = delta; - else if (delta !=0) - return false; - } - if (!ForFile && delta == 0) - return false; - } - - if (Recursive) - { - finish = delta; - if (isFile && !ForFile) - finish = delta - 1; - } - - for (int d = start; d <= finish; d++) - { - unsigned i; - for (i = 0; i < PathParts.Size(); i++) - { - if (WildcardMatching) - { - if (!DoesWildcardMatchName(PathParts[i], pathParts[i + d])) - break; - } - else - { - if (CompareFileNames(PathParts[i], pathParts[i + d]) != 0) - break; - } - } - if (i == PathParts.Size()) - return true; - } - return false; -} - -bool CCensorNode::AreAllAllowed() const -{ - if (!Name.IsEmpty() || - !SubNodes.IsEmpty() || - !ExcludeItems.IsEmpty() || - IncludeItems.Size() != 1) - return false; - return IncludeItems.Front().AreAllAllowed(); -} - -int CCensorNode::FindSubNode(const UString &name) const -{ - FOR_VECTOR (i, SubNodes) - if (CompareFileNames(SubNodes[i].Name, name) == 0) - return i; - return -1; -} - -void CCensorNode::AddItemSimple(bool include, CItem &item) -{ - if (include) - IncludeItems.Add(item); - else - ExcludeItems.Add(item); -} - -void CCensorNode::AddItem(bool include, CItem &item) -{ - if (item.PathParts.Size() <= 1) - { - if (item.PathParts.Size() != 0 && item.WildcardMatching) - { - if (!DoesNameContainWildcard(item.PathParts.Front())) - item.WildcardMatching = false; - } - AddItemSimple(include, item); - return; - } - const UString &front = item.PathParts.Front(); - - // We can't ignore wildcard, since we don't allow wildcard in SubNodes[].Name - // if (item.Wildcard) - if (DoesNameContainWildcard(front)) - { - AddItemSimple(include, item); - return; - } - int index = FindSubNode(front); - if (index < 0) - index = SubNodes.Add(CCensorNode(front, this)); - item.PathParts.Delete(0); - SubNodes[index].AddItem(include, item); -} - -void CCensorNode::AddItem(bool include, const UString &path, bool recursive, bool forFile, bool forDir, bool wildcardMatching) -{ - CItem item; - SplitPathToParts(path, item.PathParts); - item.Recursive = recursive; - item.ForFile = forFile; - item.ForDir = forDir; - item.WildcardMatching = wildcardMatching; - AddItem(include, item); -} - -bool CCensorNode::NeedCheckSubDirs() const -{ - FOR_VECTOR (i, IncludeItems) - { - const CItem &item = IncludeItems[i]; - if (item.Recursive || item.PathParts.Size() > 1) - return true; - } - return false; -} - -bool CCensorNode::AreThereIncludeItems() const -{ - if (IncludeItems.Size() > 0) - return true; - FOR_VECTOR (i, SubNodes) - if (SubNodes[i].AreThereIncludeItems()) - return true; - return false; -} - -bool CCensorNode::CheckPathCurrent(bool include, const UStringVector &pathParts, bool isFile) const -{ - const CObjectVector<CItem> &items = include ? IncludeItems : ExcludeItems; - FOR_VECTOR (i, items) - if (items[i].CheckPath(pathParts, isFile)) - return true; - return false; -} - -bool CCensorNode::CheckPathVect(const UStringVector &pathParts, bool isFile, bool &include) const -{ - if (CheckPathCurrent(false, pathParts, isFile)) - { - include = false; - return true; - } - include = true; - bool finded = CheckPathCurrent(true, pathParts, isFile); - if (pathParts.Size() <= 1) - return finded; - int index = FindSubNode(pathParts.Front()); - if (index >= 0) - { - UStringVector pathParts2 = pathParts; - pathParts2.Delete(0); - if (SubNodes[index].CheckPathVect(pathParts2, isFile, include)) - return true; - } - return finded; -} - -bool CCensorNode::CheckPath2(bool isAltStream, const UString &path, bool isFile, bool &include) const -{ - UStringVector pathParts; - SplitPathToParts(path, pathParts); - if (CheckPathVect(pathParts, isFile, include)) - { - if (!include || !isAltStream) - return true; - } - if (isAltStream && !pathParts.IsEmpty()) - { - UString &back = pathParts.Back(); - int pos = back.Find(L':'); - if (pos > 0) - { - back.DeleteFrom(pos); - return CheckPathVect(pathParts, isFile, include); - } - } - return false; -} - -bool CCensorNode::CheckPath(bool isAltStream, const UString &path, bool isFile) const -{ - bool include; - if (CheckPath2(isAltStream, path, isFile, include)) - return include; - return false; -} - -bool CCensorNode::CheckPathToRoot(bool include, UStringVector &pathParts, bool isFile) const -{ - if (CheckPathCurrent(include, pathParts, isFile)) - return true; - if (Parent == 0) - return false; - pathParts.Insert(0, Name); - return Parent->CheckPathToRoot(include, pathParts, isFile); -} - -/* -bool CCensorNode::CheckPathToRoot(bool include, const UString &path, bool isFile) const -{ - UStringVector pathParts; - SplitPathToParts(path, pathParts); - return CheckPathToRoot(include, pathParts, isFile); -} -*/ - -void CCensorNode::AddItem2(bool include, const UString &path, bool recursive, bool wildcardMatching) -{ - if (path.IsEmpty()) - return; - bool forFile = true; - bool forFolder = true; - UString path2 = path; - if (IsCharDirLimiter(path.Back())) - { - path2.DeleteBack(); - forFile = false; - } - AddItem(include, path2, recursive, forFile, forFolder, wildcardMatching); -} - -void CCensorNode::ExtendExclude(const CCensorNode &fromNodes) -{ - ExcludeItems += fromNodes.ExcludeItems; - FOR_VECTOR (i, fromNodes.SubNodes) - { - const CCensorNode &node = fromNodes.SubNodes[i]; - int subNodeIndex = FindSubNode(node.Name); - if (subNodeIndex < 0) - subNodeIndex = SubNodes.Add(CCensorNode(node.Name, this)); - SubNodes[subNodeIndex].ExtendExclude(node); - } -} - -int CCensor::FindPrefix(const UString &prefix) const -{ - FOR_VECTOR (i, Pairs) - if (CompareFileNames(Pairs[i].Prefix, prefix) == 0) - return i; - return -1; -} - -void CCensor::AddItem(ECensorPathMode pathMode, bool include, const UString &path, bool recursive, bool wildcardMatching) -{ - UStringVector pathParts; - if (path.IsEmpty()) - throw "Empty file path"; - SplitPathToParts(path, pathParts); - bool forFile = true; - if (pathParts.Back().IsEmpty()) - { - forFile = false; - pathParts.DeleteBack(); - } - - UString prefix; - - if (pathMode != k_AbsPath) - { - const UString &front = pathParts.Front(); - bool isAbs = false; - - if (front.IsEmpty()) - isAbs = true; - else - { - #ifdef _WIN32 - - if (IsDriveColonName(front)) - isAbs = true; - else - - #endif - - FOR_VECTOR (i, pathParts) - { - const UString &part = pathParts[i]; - if (part == L".." || part == L".") - { - isAbs = true; - break; - } - } - } - - unsigned numAbsParts = 0; - if (isAbs) - if (pathParts.Size() > 1) - numAbsParts = pathParts.Size() - 1; - else - numAbsParts = 1; - - #ifdef _WIN32 - - // \\?\ case - if (numAbsParts >= 3) - { - if (pathParts[0].IsEmpty() && - pathParts[1].IsEmpty() && - pathParts[2] == L"?") - { - prefix = - WSTRING_PATH_SEPARATOR - WSTRING_PATH_SEPARATOR L"?" - WSTRING_PATH_SEPARATOR; - numAbsParts -= 3; - pathParts.DeleteFrontal(3); - } - } - - #endif - - if (numAbsParts > 1 && pathMode == k_FullPath) - numAbsParts = 1; - - // We can't ignore wildcard, since we don't allow wildcard in SubNodes[].Name - // if (wildcardMatching) - for (unsigned i = 0; i < numAbsParts; i++) - { - { - const UString &front = pathParts.Front(); - if (DoesNameContainWildcard(front)) - break; - prefix += front; - prefix += WCHAR_PATH_SEPARATOR; - } - pathParts.Delete(0); - } - } - - int index = FindPrefix(prefix); - if (index < 0) - index = Pairs.Add(CPair(prefix)); - - CItem item; - item.PathParts = pathParts; - item.ForDir = true; - item.ForFile = forFile; - item.Recursive = recursive; - item.WildcardMatching = wildcardMatching; - Pairs[index].Head.AddItem(include, item); -} - -bool CCensor::CheckPath(bool isAltStream, const UString &path, bool isFile) const -{ - bool finded = false; - FOR_VECTOR (i, Pairs) - { - bool include; - if (Pairs[i].Head.CheckPath2(isAltStream, path, isFile, include)) - { - if (!include) - return false; - finded = true; - } - } - return finded; -} - -void CCensor::ExtendExclude() -{ - unsigned i; - for (i = 0; i < Pairs.Size(); i++) - if (Pairs[i].Prefix.IsEmpty()) - break; - if (i == Pairs.Size()) - return; - unsigned index = i; - for (i = 0; i < Pairs.Size(); i++) - if (index != i) - Pairs[i].Head.ExtendExclude(Pairs[index].Head); -} - -void CCensor::AddPathsToCensor(ECensorPathMode censorPathMode) -{ - FOR_VECTOR(i, CensorPaths) - { - const CCensorPath &cp = CensorPaths[i]; - AddItem(censorPathMode, cp.Include, cp.Path, cp.Recursive, cp.WildcardMatching); - } - CensorPaths.Clear(); -} - -void CCensor::AddPreItem(bool include, const UString &path, bool recursive, bool wildcardMatching) -{ - CCensorPath &cp = CensorPaths.AddNew(); - cp.Path = path; - cp.Include = include; - cp.Recursive = recursive; - cp.WildcardMatching = wildcardMatching; -} - -} diff --git a/src/libs/7zip/win/CPP/Common/Wildcard.h b/src/libs/7zip/win/CPP/Common/Wildcard.h deleted file mode 100644 index 137d71ced..000000000 --- a/src/libs/7zip/win/CPP/Common/Wildcard.h +++ /dev/null @@ -1,157 +0,0 @@ -// Common/Wildcard.h - -#ifndef __COMMON_WILDCARD_H -#define __COMMON_WILDCARD_H - -#include "MyString.h" - -int CompareFileNames(const wchar_t *s1, const wchar_t *s2) STRING_UNICODE_THROW; -#ifndef USE_UNICODE_FSTRING - int CompareFileNames(const char *s1, const char *s2); -#endif - -bool IsPath1PrefixedByPath2(const wchar_t *s1, const wchar_t *s2); - -inline bool IsCharDirLimiter(wchar_t c) -{ - return c == WCHAR_PATH_SEPARATOR - #ifdef _WIN32 - || c == L'/' - #endif - ; -} - -void SplitPathToParts(const UString &path, UStringVector &pathParts); -void SplitPathToParts_2(const UString &path, UString &dirPrefix, UString &name); -void SplitPathToParts_Smart(const UString &path, UString &dirPrefix, UString &name); // ignores dir delimiter at the end of (path) - -UString ExtractDirPrefixFromPath(const UString &path); -UString ExtractFileNameFromPath(const UString &path); - -bool DoesNameContainWildcard(const UString &path); -bool DoesWildcardMatchName(const UString &mask, const UString &name); - -namespace NWildcard { - -#ifdef _WIN32 -// returns true, if name is like "a:", "c:", ... -bool IsDriveColonName(const wchar_t *s); -#endif - - -struct CItem -{ - UStringVector PathParts; - bool Recursive; - bool ForFile; - bool ForDir; - bool WildcardMatching; - - #ifdef _WIN32 - bool IsDriveItem() const - { - return PathParts.Size() == 1 && !ForFile && ForDir && IsDriveColonName(PathParts[0]); - } - #endif - - // CItem(): WildcardMatching(true) {} - - bool AreAllAllowed() const; - bool CheckPath(const UStringVector &pathParts, bool isFile) const; -}; - -class CCensorNode -{ - CCensorNode *Parent; - - bool CheckPathCurrent(bool include, const UStringVector &pathParts, bool isFile) const; - void AddItemSimple(bool include, CItem &item); - bool CheckPathVect(const UStringVector &pathParts, bool isFile, bool &include) const; -public: - CCensorNode(): Parent(0) { }; - CCensorNode(const UString &name, CCensorNode *parent): Name(name), Parent(parent) { }; - - UString Name; // wildcard is not allowed here - CObjectVector<CCensorNode> SubNodes; - CObjectVector<CItem> IncludeItems; - CObjectVector<CItem> ExcludeItems; - - bool AreAllAllowed() const; - - int FindSubNode(const UString &path) const; - - void AddItem(bool include, CItem &item); - void AddItem(bool include, const UString &path, bool recursive, bool forFile, bool forDir, bool wildcardMatching); - void AddItem2(bool include, const UString &path, bool recursive, bool wildcardMatching); - - bool NeedCheckSubDirs() const; - bool AreThereIncludeItems() const; - - bool CheckPath2(bool isAltStream, const UString &path, bool isFile, bool &include) const; - bool CheckPath(bool isAltStream, const UString &path, bool isFile) const; - - bool CheckPathToRoot(bool include, UStringVector &pathParts, bool isFile) const; - // bool CheckPathToRoot(const UString &path, bool isFile, bool include) const; - void ExtendExclude(const CCensorNode &fromNodes); -}; - -struct CPair -{ - UString Prefix; - CCensorNode Head; - - CPair(const UString &prefix): Prefix(prefix) { }; -}; - -enum ECensorPathMode -{ - k_RelatPath, // absolute prefix as Prefix, remain path in Tree - k_FullPath, // drive prefix as Prefix, remain path in Tree - k_AbsPath // full path in Tree -}; - -struct CCensorPath -{ - UString Path; - bool Include; - bool Recursive; - bool WildcardMatching; - - CCensorPath(): - Include(true), - Recursive(false), - WildcardMatching(true) - {} -}; - -class CCensor -{ - int FindPrefix(const UString &prefix) const; -public: - CObjectVector<CPair> Pairs; - - CObjectVector<NWildcard::CCensorPath> CensorPaths; - - bool AllAreRelative() const - { return (Pairs.Size() == 1 && Pairs.Front().Prefix.IsEmpty()); } - - void AddItem(ECensorPathMode pathMode, bool include, const UString &path, bool recursive, bool wildcardMatching); - bool CheckPath(bool isAltStream, const UString &path, bool isFile) const; - void ExtendExclude(); - - void AddPathsToCensor(NWildcard::ECensorPathMode censorPathMode); - void AddPreItem(bool include, const UString &path, bool recursive, bool wildcardMatching); - void AddPreItem(const UString &path) - { - AddPreItem(true, path, false, false); - } - void AddPreItem_Wildcard() - { - AddPreItem(true, L"*", false, true); - } -}; - - -} - -#endif |