diff options
Diffstat (limited to 'src/libs/7zip/unix/CPP/Common')
-rw-r--r-- | src/libs/7zip/unix/CPP/Common/DynamicBuffer.h | 2 | ||||
-rw-r--r-- | src/libs/7zip/unix/CPP/Common/Lang.cpp | 130 | ||||
-rw-r--r-- | src/libs/7zip/unix/CPP/Common/Lang.h | 28 | ||||
-rw-r--r-- | src/libs/7zip/unix/CPP/Common/MyMap.cpp | 140 | ||||
-rw-r--r-- | src/libs/7zip/unix/CPP/Common/MyMap.h | 28 | ||||
-rw-r--r-- | src/libs/7zip/unix/CPP/Common/MyXml.cpp | 209 | ||||
-rw-r--r-- | src/libs/7zip/unix/CPP/Common/MyXml.h | 40 | ||||
-rw-r--r-- | src/libs/7zip/unix/CPP/Common/TextConfig.cpp | 138 | ||||
-rw-r--r-- | src/libs/7zip/unix/CPP/Common/TextConfig.h | 22 |
9 files changed, 1 insertions, 736 deletions
diff --git a/src/libs/7zip/unix/CPP/Common/DynamicBuffer.h b/src/libs/7zip/unix/CPP/Common/DynamicBuffer.h index b5fd97823..eaac123e1 100644 --- a/src/libs/7zip/unix/CPP/Common/DynamicBuffer.h +++ b/src/libs/7zip/unix/CPP/Common/DynamicBuffer.h @@ -31,7 +31,7 @@ public: this->Free(); if (buffer._capacity > 0) { - SetCapacity(buffer._capacity); + this->SetCapacity(buffer._capacity); memmove(this->_items, buffer._items, buffer._capacity * sizeof(T)); } return *this; diff --git a/src/libs/7zip/unix/CPP/Common/Lang.cpp b/src/libs/7zip/unix/CPP/Common/Lang.cpp deleted file mode 100644 index 75dfed426..000000000 --- a/src/libs/7zip/unix/CPP/Common/Lang.cpp +++ /dev/null @@ -1,130 +0,0 @@ -// Common/Lang.cpp - -#include "StdAfx.h" - -#include "Lang.h" -#include "TextConfig.h" - -#include "../Windows/FileIO.h" -#include "UTFConvert.h" -#include "Defs.h" - -static bool HexStringToNumber(const UString &s, UInt32 &value) -{ - value = 0; - if (s.IsEmpty()) - return false; - for (int i = 0; i < s.Length(); i++) - { - wchar_t c = s[i]; - int a; - if (c >= L'0' && c <= L'9') - a = c - L'0'; - else if (c >= L'A' && c <= L'F') - a = 10 + c - L'A'; - else if (c >= L'a' && c <= L'f') - a = 10 + c - L'a'; - else - return false; - value *= 0x10; - value += a; - } - return true; -} - - -static bool WaitNextLine(const AString &s, int &pos) -{ - for (; pos < s.Length(); pos++) - if (s[pos] == 0x0A) - return true; - return false; -} - -static int CompareLangItems(void *const *elem1, void *const *elem2, void *) -{ - const CLangPair &langPair1 = *(*((const CLangPair **)elem1)); - const CLangPair &langPair2 = *(*((const CLangPair **)elem2)); - return MyCompare(langPair1.Value, langPair2.Value); -} - -bool CLang::Open(LPCWSTR fileName) -{ - _langPairs.Clear(); - NWindows::NFile::NIO::CInFile file; - if (!file.Open(fileName)) - return false; - UInt64 length; - if (!file.GetLength(length)) - return false; - if (length > (1 << 20)) - return false; - AString s; - char *p = s.GetBuffer((int)length + 1); - UInt32 processed; - if (!file.Read(p, (UInt32)length, processed)) - return false; - p[(UInt32)length] = 0; - s.ReleaseBuffer(); - file.Close(); - int pos = 0; - if (s.Length() >= 3) - { - if (Byte(s[0]) == 0xEF && Byte(s[1]) == 0xBB && Byte(s[2]) == 0xBF) - pos += 3; - } - - ///////////////////// - // read header - - AString stringID = ";!@Lang@!UTF-8!"; - if (s.Mid(pos, stringID.Length()) != stringID) - return false; - pos += stringID.Length(); - - if (!WaitNextLine(s, pos)) - return false; - - CObjectVector<CTextConfigPair> pairs; - if (!GetTextConfig(s.Mid(pos), pairs)) - return false; - - _langPairs.Reserve(_langPairs.Size()); - for (int i = 0; i < pairs.Size(); i++) - { - CTextConfigPair textConfigPair = pairs[i]; - CLangPair langPair; - if (!HexStringToNumber(textConfigPair.ID, langPair.Value)) - return false; - langPair.String = textConfigPair.String; - _langPairs.Add(langPair); - } - _langPairs.Sort(CompareLangItems, NULL); - return true; -} - -int CLang::FindItem(UInt32 value) const -{ - int left = 0, right = _langPairs.Size(); - while (left != right) - { - UInt32 mid = (left + right) / 2; - UInt32 midValue = _langPairs[mid].Value; - if (value == midValue) - return mid; - if (value < midValue) - right = mid; - else - left = mid + 1; - } - return -1; -} - -bool CLang::GetMessage(UInt32 value, UString &message) const -{ - int index = FindItem(value); - if (index < 0) - return false; - message = _langPairs[index].String; - return true; -} diff --git a/src/libs/7zip/unix/CPP/Common/Lang.h b/src/libs/7zip/unix/CPP/Common/Lang.h deleted file mode 100644 index cf978758e..000000000 --- a/src/libs/7zip/unix/CPP/Common/Lang.h +++ /dev/null @@ -1,28 +0,0 @@ -// Common/Lang.h - -#ifndef __COMMON_LANG_H -#define __COMMON_LANG_H - -#include "MyVector.h" -#include "MyString.h" -#include "Types.h" - -struct CLangPair -{ - UInt32 Value; - UString String; -}; - -class CLang -{ - CObjectVector<CLangPair> _langPairs; -public: - bool Open(LPCWSTR fileName); - void Clear() { _langPairs.Clear(); } - int FindItem(UInt32 value) const; - bool GetMessage(UInt32 value, UString &message) const; -}; - -#endif - - diff --git a/src/libs/7zip/unix/CPP/Common/MyMap.cpp b/src/libs/7zip/unix/CPP/Common/MyMap.cpp deleted file mode 100644 index 0ee11e8cd..000000000 --- a/src/libs/7zip/unix/CPP/Common/MyMap.cpp +++ /dev/null @@ -1,140 +0,0 @@ -// MyMap.cpp - -#include "StdAfx.h" - -#include "MyMap.h" - -static const unsigned kNumBitsMax = sizeof(UInt32) * 8; - -static UInt32 GetSubBits(UInt32 value, unsigned startPos, unsigned numBits) -{ - if (startPos == sizeof(value) * 8) - return 0; - value >>= startPos; - if (numBits == sizeof(value) * 8) - return value; - return value & (((UInt32)1 << numBits) - 1); -} - -static inline unsigned GetSubBit(UInt32 v, unsigned n) { return (unsigned)(v >> n) & 1; } - -bool CMap32::Find(UInt32 key, UInt32 &valueRes) const -{ - valueRes = (UInt32)(Int32)-1; - if (Nodes.Size() == 0) - return false; - if (Nodes.Size() == 1) - { - const CNode &n = Nodes[0]; - if (n.Len == kNumBitsMax) - { - valueRes = n.Values[0]; - return (key == n.Key); - } - } - - int cur = 0; - unsigned bitPos = kNumBitsMax; - for (;;) - { - const CNode &n = Nodes[cur]; - bitPos -= n.Len; - if (GetSubBits(key, bitPos, n.Len) != GetSubBits(n.Key, bitPos, n.Len)) - return false; - unsigned bit = GetSubBit(key, --bitPos); - if (n.IsLeaf[bit]) - { - valueRes = n.Values[bit]; - return (key == n.Keys[bit]); - } - cur = (int)n.Keys[bit]; - } -} - -bool CMap32::Set(UInt32 key, UInt32 value) -{ - if (Nodes.Size() == 0) - { - CNode n; - n.Key = n.Keys[0] = n.Keys[1] = key; - n.Values[0] = n.Values[1] = value; - n.IsLeaf[0] = n.IsLeaf[1] = 1; - n.Len = kNumBitsMax; - Nodes.Add(n); - return false; - } - if (Nodes.Size() == 1) - { - CNode &n = Nodes[0]; - if (n.Len == kNumBitsMax) - { - if (key == n.Key) - { - n.Values[0] = n.Values[1] = value; - return true; - } - unsigned i = kNumBitsMax - 1; - for (;GetSubBit(key, i) == GetSubBit(n.Key, i); i--); - n.Len = (UInt16)(kNumBitsMax - (1 + i)); - unsigned newBit = GetSubBit(key, i); - n.Values[newBit] = value; - n.Keys[newBit] = key; - return false; - } - } - - int cur = 0; - unsigned bitPos = kNumBitsMax; - for (;;) - { - CNode &n = Nodes[cur]; - bitPos -= n.Len; - if (GetSubBits(key, bitPos, n.Len) != GetSubBits(n.Key, bitPos, n.Len)) - { - unsigned i = n.Len - 1; - for (; GetSubBit(key, bitPos + i) == GetSubBit(n.Key, bitPos + i); i--); - - CNode e2(n); - e2.Len = (UInt16)i; - - n.Len = (UInt16)(n.Len - (1 + i)); - unsigned newBit = GetSubBit(key, bitPos + i); - n.Values[newBit] = value; - n.IsLeaf[newBit] = 1; - n.IsLeaf[1 - newBit] = 0; - n.Keys[newBit] = key; - n.Keys[1 - newBit] = Nodes.Size(); - Nodes.Add(e2); - return false; - } - unsigned bit = GetSubBit(key, --bitPos); - - if (n.IsLeaf[bit]) - { - if (key == n.Keys[bit]) - { - n.Values[bit] = value; - return true; - } - unsigned i = bitPos - 1; - for (;GetSubBit(key, i) == GetSubBit(n.Keys[bit], i); i--); - - CNode e2; - - unsigned newBit = GetSubBit(key, i); - e2.Values[newBit] = value; - e2.Values[1 - newBit] = n.Values[bit]; - e2.IsLeaf[newBit] = e2.IsLeaf[1 - newBit] = 1; - e2.Keys[newBit] = key; - e2.Keys[1 - newBit] = e2.Key = n.Keys[bit]; - e2.Len = (UInt16)(bitPos - (1 + i)); - - n.IsLeaf[bit] = 0; - n.Keys[bit] = Nodes.Size(); - - Nodes.Add(e2); - return false; - } - cur = (int)n.Keys[bit]; - } -} diff --git a/src/libs/7zip/unix/CPP/Common/MyMap.h b/src/libs/7zip/unix/CPP/Common/MyMap.h deleted file mode 100644 index d0dd43f53..000000000 --- a/src/libs/7zip/unix/CPP/Common/MyMap.h +++ /dev/null @@ -1,28 +0,0 @@ -// MyMap.h - -#ifndef __COMMON_MYMAP_H -#define __COMMON_MYMAP_H - -#include "MyVector.h" -#include "Types.h" - -class CMap32 -{ - struct CNode - { - UInt32 Key; - UInt32 Keys[2]; - UInt32 Values[2]; - UInt16 Len; - Byte IsLeaf[2]; - }; - CRecordVector<CNode> Nodes; - -public: - - void Clear() { Nodes.Clear(); } - bool Find(UInt32 key, UInt32 &valueRes) const; - bool Set(UInt32 key, UInt32 value); // returns true, if there is such key already -}; - -#endif diff --git a/src/libs/7zip/unix/CPP/Common/MyXml.cpp b/src/libs/7zip/unix/CPP/Common/MyXml.cpp deleted file mode 100644 index 8aa9ce8cd..000000000 --- a/src/libs/7zip/unix/CPP/Common/MyXml.cpp +++ /dev/null @@ -1,209 +0,0 @@ -// MyXml.cpp - -#include "StdAfx.h" - -#include "MyXml.h" - -static bool IsValidChar(char c) -{ - return - c >= 'a' && c <= 'z' || - c >= 'A' && c <= 'Z' || - c >= '0' && c <= '9' || - c == '-'; -} - -static bool IsSpaceChar(char c) -{ - return (c == ' ' || c == '\t' || c == 0x0D || c == 0x0A); -} - -#define SKIP_SPACES(s, pos) while (IsSpaceChar(s[pos])) pos++; - -static bool ReadProperty(const AString &s, int &pos, CXmlProp &prop) -{ - prop.Name.Empty(); - prop.Value.Empty(); - for (; pos < s.Length(); pos++) - { - char c = s[pos]; - if (!IsValidChar(c)) - break; - prop.Name += c; - } - - if (prop.Name.IsEmpty()) - return false; - - SKIP_SPACES(s, pos); - if (s[pos++] != '=') - return false; - - SKIP_SPACES(s, pos); - if (s[pos++] != '\"') - return false; - - while (pos < s.Length()) - { - char c = s[pos++]; - if (c == '\"') - return true; - prop.Value += c; - } - return false; -} - -int CXmlItem::FindProperty(const AString &propName) const -{ - for (int i = 0; i < Props.Size(); i++) - if (Props[i].Name == propName) - return i; - return -1; -} - -AString CXmlItem::GetPropertyValue(const AString &propName) const -{ - int index = FindProperty(propName); - if (index >= 0) - return Props[index].Value; - return AString(); -} - -bool CXmlItem::IsTagged(const AString &tag) const -{ - return (IsTag && Name == tag); -} - -int CXmlItem::FindSubTag(const AString &tag) const -{ - for (int i = 0; i < SubItems.Size(); i++) - if (SubItems[i].IsTagged(tag)) - return i; - return -1; -} - -AString CXmlItem::GetSubString() const -{ - if (SubItems.Size() == 1) - { - const CXmlItem &item = SubItems[0]; - if (!item.IsTag) - return item.Name; - } - return AString(); -} - -AString CXmlItem::GetSubStringForTag(const AString &tag) const -{ - int index = FindSubTag(tag); - if (index >= 0) - return SubItems[index].GetSubString(); - return AString(); -} - -bool CXmlItem::ParseItems(const AString &s, int &pos, int numAllowedLevels) -{ - if (numAllowedLevels == 0) - return false; - SubItems.Clear(); - AString finishString = "</"; - for (;;) - { - SKIP_SPACES(s, pos); - - if (s.Mid(pos, finishString.Length()) == finishString) - return true; - - CXmlItem item; - if (!item.ParseItem(s, pos, numAllowedLevels - 1)) - return false; - SubItems.Add(item); - } -} - -bool CXmlItem::ParseItem(const AString &s, int &pos, int numAllowedLevels) -{ - SKIP_SPACES(s, pos); - - int pos2 = s.Find('<', pos); - if (pos2 < 0) - return false; - if (pos2 != pos) - { - IsTag = false; - Name += s.Mid(pos, pos2 - pos); - pos = pos2; - return true; - } - IsTag = true; - - pos++; - SKIP_SPACES(s, pos); - - for (; pos < s.Length(); pos++) - { - char c = s[pos]; - if (!IsValidChar(c)) - break; - Name += c; - } - if (Name.IsEmpty() || pos == s.Length()) - return false; - - int posTemp = pos; - for (;;) - { - SKIP_SPACES(s, pos); - if (s[pos] == '/') - { - pos++; - // SKIP_SPACES(s, pos); - return (s[pos++] == '>'); - } - if (s[pos] == '>') - { - if (!ParseItems(s, ++pos, numAllowedLevels)) - return false; - AString finishString = AString("</") + Name + AString(">"); - if (s.Mid(pos, finishString.Length()) != finishString) - return false; - pos += finishString.Length(); - return true; - } - if (posTemp == pos) - return false; - - CXmlProp prop; - if (!ReadProperty(s, pos, prop)) - return false; - Props.Add(prop); - posTemp = pos; - } -} - -static bool SkipHeader(const AString &s, int &pos, const AString &startString, const AString &endString) -{ - SKIP_SPACES(s, pos); - if (s.Mid(pos, startString.Length()) == startString) - { - pos = s.Find(endString, pos); - if (pos < 0) - return false; - pos += endString.Length(); - SKIP_SPACES(s, pos); - } - return true; -} - -bool CXml::Parse(const AString &s) -{ - int pos = 0; - if (!SkipHeader(s, pos, "<?xml", "?>")) - return false; - if (!SkipHeader(s, pos, "<!DOCTYPE", ">")) - return false; - if (!Root.ParseItem(s, pos, 1000)) - return false; - SKIP_SPACES(s, pos); - return (pos == s.Length() && Root.IsTag); -} diff --git a/src/libs/7zip/unix/CPP/Common/MyXml.h b/src/libs/7zip/unix/CPP/Common/MyXml.h deleted file mode 100644 index c6e8829ad..000000000 --- a/src/libs/7zip/unix/CPP/Common/MyXml.h +++ /dev/null @@ -1,40 +0,0 @@ -// MyXml.h - -#ifndef __MYXML_H -#define __MYXML_H - -#include "MyString.h" - -struct CXmlProp -{ - AString Name; - AString Value; -}; - -class CXmlItem -{ - bool ParseItems(const AString &s, int &pos, int numAllowedLevels); - -public: - AString Name; - bool IsTag; - CObjectVector<CXmlProp> Props; - CObjectVector<CXmlItem> SubItems; - - bool ParseItem(const AString &s, int &pos, int numAllowedLevels); - - bool IsTagged(const AString &tag) const; - int FindProperty(const AString &propName) const; - AString GetPropertyValue(const AString &propName) const; - AString GetSubString() const; - int FindSubTag(const AString &tag) const; - AString GetSubStringForTag(const AString &tag) const; -}; - -struct CXml -{ - CXmlItem Root; - bool Parse(const AString &s); -}; - -#endif diff --git a/src/libs/7zip/unix/CPP/Common/TextConfig.cpp b/src/libs/7zip/unix/CPP/Common/TextConfig.cpp deleted file mode 100644 index 6a55012c3..000000000 --- a/src/libs/7zip/unix/CPP/Common/TextConfig.cpp +++ /dev/null @@ -1,138 +0,0 @@ -// Common/TextConfig.cpp - -#include "StdAfx.h" - -#include "TextConfig.h" - -#include "Defs.h" -#include "UTFConvert.h" - -static bool IsDelimitChar(char c) -{ - return (c == ' ' || c == 0x0A || c == 0x0D || - c == '\0' || c == '\t'); -} - -static AString GetIDString(const char *string, int &finishPos) -{ - AString result; - for (finishPos = 0; ; finishPos++) - { - char c = string[finishPos]; - if (IsDelimitChar(c) || c == '=') - break; - result += c; - } - return result; -} - -static bool WaitNextLine(const AString &string, int &pos) -{ - for (;pos < string.Length(); pos++) - if (string[pos] == 0x0A) - return true; - return false; -} - -static bool SkipSpaces(const AString &string, int &pos) -{ - for (;pos < string.Length(); pos++) - { - char c = string[pos]; - if (!IsDelimitChar(c)) - { - if (c != ';') - return true; - if (!WaitNextLine(string, pos)) - return false; - } - } - return false; -} - -bool GetTextConfig(const AString &string, CObjectVector<CTextConfigPair> &pairs) -{ - pairs.Clear(); - int pos = 0; - - ///////////////////// - // read strings - - for (;;) - { - if (!SkipSpaces(string, pos)) - break; - CTextConfigPair pair; - int finishPos; - AString temp = GetIDString(((const char *)string) + pos, finishPos); - if (!ConvertUTF8ToUnicode(temp, pair.ID)) - return false; - if (finishPos == 0) - return false; - pos += finishPos; - if (!SkipSpaces(string, pos)) - return false; - if (string[pos] != '=') - return false; - pos++; - if (!SkipSpaces(string, pos)) - return false; - if (string[pos] != '\"') - return false; - pos++; - AString message; - for (;;) - { - if (pos >= string.Length()) - return false; - char c = string[pos++]; - if (c == '\"') - break; - if (c == '\\') // FIXME ? - { - char c = string[pos++]; - switch(c) - { - case 'n': - message += '\n'; - break; - case 't': - message += '\t'; - break; - case '\\': // FIXME ? - message += '\\'; - break; - case '\"': - message += '\"'; - break; - default: - message += '\\'; // FIXME ? - message += c; - break; - } - } - else - message += c; - } - if (!ConvertUTF8ToUnicode(message, pair.String)) - return false; - pairs.Add(pair); - } - return true; -} - -int FindTextConfigItem(const CObjectVector<CTextConfigPair> &pairs, const UString &id) -{ - for (int i = 0; i < pairs.Size(); i++) - if (pairs[i].ID.Compare(id) == 0) - return i; - return -1; -} - -UString GetTextConfigValue(const CObjectVector<CTextConfigPair> &pairs, const UString &id) -{ - int index = FindTextConfigItem(pairs, id); - if (index < 0) - return UString(); - return pairs[index].String; -} diff --git a/src/libs/7zip/unix/CPP/Common/TextConfig.h b/src/libs/7zip/unix/CPP/Common/TextConfig.h deleted file mode 100644 index a25142a70..000000000 --- a/src/libs/7zip/unix/CPP/Common/TextConfig.h +++ /dev/null @@ -1,22 +0,0 @@ -// Common/TextConfig.h - -#ifndef __COMMON_TEXTCONFIG_H -#define __COMMON_TEXTCONFIG_H - -#include "MyVector.h" -#include "MyString.h" - -struct CTextConfigPair -{ - UString ID; - UString String; -}; - -bool GetTextConfig(const AString &text, CObjectVector<CTextConfigPair> &pairs); - -int FindTextConfigItem(const CObjectVector<CTextConfigPair> &pairs, const UString &id); -UString GetTextConfigValue(const CObjectVector<CTextConfigPair> &pairs, const UString &id); - -#endif - - |