diff options
author | Igor Pavlov <87184205+ip7z@users.noreply.github.com> | 2023-06-21 00:00:00 +0000 |
---|---|---|
committer | Igor Pavlov <87184205+ip7z@users.noreply.github.com> | 2023-12-17 14:59:19 +0500 |
commit | 5b39dc76f1bc82f941d5c800ab9f34407a06b53a (patch) | |
tree | fe5e17420300b715021a76328444088d32047963 /CPP/Common | |
parent | 93be7d4abfd4233228f58ee1fbbcd76d91be66a4 (diff) | |
download | 7zip-5b39dc76f1bc82f941d5c800ab9f34407a06b53a.tar.gz 7zip-5b39dc76f1bc82f941d5c800ab9f34407a06b53a.tar.bz2 7zip-5b39dc76f1bc82f941d5c800ab9f34407a06b53a.zip |
23.0123.01
Diffstat (limited to 'CPP/Common')
55 files changed, 1456 insertions, 658 deletions
diff --git a/CPP/Common/AutoPtr.h b/CPP/Common/AutoPtr.h index 006d315..0be8a7a 100644 --- a/CPP/Common/AutoPtr.h +++ b/CPP/Common/AutoPtr.h | |||
@@ -1,13 +1,13 @@ | |||
1 | // Common/AutoPtr.h | 1 | // Common/AutoPtr.h |
2 | 2 | ||
3 | #ifndef __COMMON_AUTOPTR_H | 3 | #ifndef ZIP7_INC_COMMON_AUTOPTR_H |
4 | #define __COMMON_AUTOPTR_H | 4 | #define ZIP7_INC_COMMON_AUTOPTR_H |
5 | 5 | ||
6 | template<class T> class CMyAutoPtr | 6 | template<class T> class CMyAutoPtr |
7 | { | 7 | { |
8 | T *_p; | 8 | T *_p; |
9 | public: | 9 | public: |
10 | CMyAutoPtr(T *p = 0) : _p(p) {} | 10 | CMyAutoPtr(T *p = NULL) : _p(p) {} |
11 | CMyAutoPtr(CMyAutoPtr<T>& p): _p(p.release()) {} | 11 | CMyAutoPtr(CMyAutoPtr<T>& p): _p(p.release()) {} |
12 | CMyAutoPtr<T>& operator=(CMyAutoPtr<T>& p) | 12 | CMyAutoPtr<T>& operator=(CMyAutoPtr<T>& p) |
13 | { | 13 | { |
@@ -21,10 +21,10 @@ public: | |||
21 | T* release() | 21 | T* release() |
22 | { | 22 | { |
23 | T *tmp = _p; | 23 | T *tmp = _p; |
24 | _p = 0; | 24 | _p = NULL; |
25 | return tmp; | 25 | return tmp; |
26 | } | 26 | } |
27 | void reset(T* p = 0) | 27 | void reset(T* p = NULL) |
28 | { | 28 | { |
29 | if (p != _p) | 29 | if (p != _p) |
30 | delete _p; | 30 | delete _p; |
diff --git a/CPP/Common/C_FileIO.h b/CPP/Common/C_FileIO.h index 6818558..12d9439 100644 --- a/CPP/Common/C_FileIO.h +++ b/CPP/Common/C_FileIO.h | |||
@@ -1,6 +1,6 @@ | |||
1 | // Common/C_FileIO.h | 1 | // Common/C_FileIO.h |
2 | 2 | ||
3 | #ifndef __COMMON_C_FILEIO_H | 3 | #ifndef ZIP7_INC_COMMON_C_FILEIO_H |
4 | #define __COMMON_C_FILEIO_H | 4 | #define ZIP7_INC_COMMON_C_FILEIO_H |
5 | 5 | ||
6 | #endif | 6 | #endif |
diff --git a/CPP/Common/CksumReg.cpp b/CPP/Common/CksumReg.cpp index 29d9f82..8c9c449 100644 --- a/CPP/Common/CksumReg.cpp +++ b/CPP/Common/CksumReg.cpp | |||
@@ -7,35 +7,30 @@ | |||
7 | #include "../Common/MyCom.h" | 7 | #include "../Common/MyCom.h" |
8 | 8 | ||
9 | #include "../7zip/Common/RegisterCodec.h" | 9 | #include "../7zip/Common/RegisterCodec.h" |
10 | |||
11 | #include "../7zip/Compress/BZip2Crc.h" | 10 | #include "../7zip/Compress/BZip2Crc.h" |
12 | 11 | ||
13 | class CCksumHasher: | 12 | Z7_CLASS_IMP_COM_1( |
14 | public IHasher, | 13 | CCksumHasher |
15 | public CMyUnknownImp | 14 | , IHasher |
16 | { | 15 | ) |
17 | CBZip2Crc _crc; | 16 | CBZip2Crc _crc; |
18 | UInt64 _size; | 17 | UInt64 _size; |
19 | Byte mtDummy[1 << 7]; | ||
20 | |||
21 | public: | 18 | public: |
19 | // Byte _mtDummy[1 << 7]; | ||
22 | CCksumHasher() | 20 | CCksumHasher() |
23 | { | 21 | { |
24 | _crc.Init(0); | 22 | _crc.Init(0); |
25 | _size = 0; | 23 | _size = 0; |
26 | } | 24 | } |
27 | |||
28 | MY_UNKNOWN_IMP1(IHasher) | ||
29 | INTERFACE_IHasher(;) | ||
30 | }; | 25 | }; |
31 | 26 | ||
32 | STDMETHODIMP_(void) CCksumHasher::Init() throw() | 27 | Z7_COM7F_IMF2(void, CCksumHasher::Init()) |
33 | { | 28 | { |
34 | _crc.Init(0); | 29 | _crc.Init(0); |
35 | _size = 0; | 30 | _size = 0; |
36 | } | 31 | } |
37 | 32 | ||
38 | STDMETHODIMP_(void) CCksumHasher::Update(const void *data, UInt32 size) throw() | 33 | Z7_COM7F_IMF2(void, CCksumHasher::Update(const void *data, UInt32 size)) |
39 | { | 34 | { |
40 | _size += size; | 35 | _size += size; |
41 | CBZip2Crc crc = _crc; | 36 | CBZip2Crc crc = _crc; |
@@ -44,7 +39,7 @@ STDMETHODIMP_(void) CCksumHasher::Update(const void *data, UInt32 size) throw() | |||
44 | _crc = crc; | 39 | _crc = crc; |
45 | } | 40 | } |
46 | 41 | ||
47 | STDMETHODIMP_(void) CCksumHasher::Final(Byte *digest) throw() | 42 | Z7_COM7F_IMF2(void, CCksumHasher::Final(Byte *digest)) |
48 | { | 43 | { |
49 | UInt64 size = _size; | 44 | UInt64 size = _size; |
50 | CBZip2Crc crc = _crc; | 45 | CBZip2Crc crc = _crc; |
@@ -54,7 +49,7 @@ STDMETHODIMP_(void) CCksumHasher::Final(Byte *digest) throw() | |||
54 | size >>= 8; | 49 | size >>= 8; |
55 | } | 50 | } |
56 | const UInt32 val = crc.GetDigest(); | 51 | const UInt32 val = crc.GetDigest(); |
57 | SetUi32(digest, val); | 52 | SetUi32(digest, val) |
58 | } | 53 | } |
59 | 54 | ||
60 | REGISTER_HASHER(CCksumHasher, 0x203, "CKSUM", 4) | 55 | REGISTER_HASHER(CCksumHasher, 0x203, "CKSUM", 4) |
diff --git a/CPP/Common/ComTry.h b/CPP/Common/ComTry.h index 297c407..84746a7 100644 --- a/CPP/Common/ComTry.h +++ b/CPP/Common/ComTry.h | |||
@@ -1,7 +1,7 @@ | |||
1 | // ComTry.h | 1 | // ComTry.h |
2 | 2 | ||
3 | #ifndef __COM_TRY_H | 3 | #ifndef ZIP7_INC_COM_TRY_H |
4 | #define __COM_TRY_H | 4 | #define ZIP7_INC_COM_TRY_H |
5 | 5 | ||
6 | #include "MyWindows.h" | 6 | #include "MyWindows.h" |
7 | // #include "Exception.h" | 7 | // #include "Exception.h" |
diff --git a/CPP/Common/CommandLineParser.h b/CPP/Common/CommandLineParser.h index fbd4fa5..fc6f028 100644 --- a/CPP/Common/CommandLineParser.h +++ b/CPP/Common/CommandLineParser.h | |||
@@ -1,7 +1,7 @@ | |||
1 | // Common/CommandLineParser.h | 1 | // Common/CommandLineParser.h |
2 | 2 | ||
3 | #ifndef __COMMON_COMMAND_LINE_PARSER_H | 3 | #ifndef ZIP7_INC_COMMON_COMMAND_LINE_PARSER_H |
4 | #define __COMMON_COMMAND_LINE_PARSER_H | 4 | #define ZIP7_INC_COMMON_COMMAND_LINE_PARSER_H |
5 | 5 | ||
6 | #include "MyString.h" | 6 | #include "MyString.h" |
7 | 7 | ||
diff --git a/CPP/Common/Common.h b/CPP/Common/Common.h index 72db7a8..0c77ab4 100644 --- a/CPP/Common/Common.h +++ b/CPP/Common/Common.h | |||
@@ -1,7 +1,13 @@ | |||
1 | // Common.h | 1 | // Common.h |
2 | 2 | ||
3 | #ifndef __COMMON_COMMON_H | 3 | #if defined(_MSC_VER) && _MSC_VER >= 1800 |
4 | #define __COMMON_COMMON_H | 4 | #pragma warning(disable : 4464) // relative include path contains '..' |
5 | #endif | ||
6 | |||
7 | #ifndef ZIP7_INC_COMMON_H | ||
8 | #define ZIP7_INC_COMMON_H | ||
9 | |||
10 | #include "../../C/Compiler.h" | ||
5 | 11 | ||
6 | /* | 12 | /* |
7 | This file is included to all cpp files in 7-Zip. | 13 | This file is included to all cpp files in 7-Zip. |
@@ -16,42 +22,292 @@ If you don't need some things that are used in 7-Zip, | |||
16 | you can change this h file or h files included in this file. | 22 | you can change this h file or h files included in this file. |
17 | */ | 23 | */ |
18 | 24 | ||
19 | // compiler pragmas to disable some warnings | 25 | #ifdef _MSC_VER |
20 | #include "../../C/Compiler.h" | 26 | #pragma warning(disable : 4710) // function not inlined |
27 | // 'CUncopyable::CUncopyable': | ||
28 | #pragma warning(disable : 4514) // unreferenced inline function has been removed | ||
29 | #if _MSC_VER < 1300 | ||
30 | #pragma warning(disable : 4702) // unreachable code | ||
31 | #pragma warning(disable : 4714) // function marked as __forceinline not inlined | ||
32 | #pragma warning(disable : 4786) // identifier was truncated to '255' characters in the debug information | ||
33 | #endif | ||
34 | #if _MSC_VER < 1400 | ||
35 | #pragma warning(disable : 4511) // copy constructor could not be generated // #pragma warning(disable : 4512) // assignment operator could not be generated | ||
36 | #pragma warning(disable : 4512) // assignment operator could not be generated | ||
37 | #endif | ||
38 | #if _MSC_VER > 1400 && _MSC_VER <= 1900 | ||
39 | // #pragma warning(disable : 4996) | ||
40 | // strcat: This function or variable may be unsafe | ||
41 | // GetVersion was declared deprecated | ||
42 | #endif | ||
21 | 43 | ||
22 | // it's <windows.h> or code that defines windows things, if it's not _WIN32 | 44 | #if _MSC_VER > 1200 |
23 | #include "MyWindows.h" | 45 | // -Wall warnings |
24 | 46 | ||
25 | // NewHandler.h and NewHandler.cpp redefine operator new() to throw exceptions, if compiled with old MSVC compilers | 47 | #if _MSC_VER <= 1600 |
26 | #include "NewHandler.h" | 48 | #pragma warning(disable : 4917) // 'OLE_HANDLE' : a GUID can only be associated with a class, interface or namespace |
49 | #endif | ||
27 | 50 | ||
51 | // #pragma warning(disable : 4061) // enumerator '' in switch of enum '' is not explicitly handled by a case label | ||
52 | // #pragma warning(disable : 4266) // no override available for virtual member function from base ''; function is hidden | ||
53 | #pragma warning(disable : 4625) // copy constructor was implicitly defined as deleted | ||
54 | #pragma warning(disable : 4626) // assignment operator was implicitly defined as deleted | ||
55 | #if _MSC_VER >= 1600 && _MSC_VER < 1920 | ||
56 | #pragma warning(disable : 4571) // Informational: catch(...) semantics changed since Visual C++ 7.1; structured exceptions (SEH) are no longer caught | ||
57 | #endif | ||
58 | #if _MSC_VER >= 1600 | ||
59 | #pragma warning(disable : 4365) // 'initializing' : conversion from 'int' to 'unsigned int', signed / unsigned mismatch | ||
60 | #endif | ||
61 | #if _MSC_VER < 1800 | ||
62 | // we disable the warning, if we don't use 'final' in class | ||
63 | #pragma warning(disable : 4265) // class has virtual functions, but destructor is not virtual | ||
64 | #endif | ||
65 | |||
66 | #if _MSC_VER >= 1900 | ||
67 | #pragma warning(disable : 5026) // move constructor was implicitly defined as deleted | ||
68 | #pragma warning(disable : 5027) // move assignment operator was implicitly defined as deleted | ||
69 | #endif | ||
70 | #if _MSC_VER >= 1912 | ||
71 | #pragma warning(disable : 5039) // pointer or reference to potentially throwing function passed to 'extern "C"' function under - EHc.Undefined behavior may occur if this function throws an exception. | ||
72 | #endif | ||
73 | #if _MSC_VER >= 1925 | ||
74 | // #pragma warning(disable : 5204) // 'ISequentialInStream' : class has virtual functions, but its trivial destructor is not virtual; instances of objects derived from this class may not be destructed correctly | ||
75 | #endif | ||
76 | #if _MSC_VER >= 1934 | ||
77 | // #pragma warning(disable : 5264) // const variable is not used | ||
78 | #endif | ||
28 | 79 | ||
80 | #endif // _MSC_VER > 1200 | ||
81 | #endif // _MSC_VER | ||
29 | 82 | ||
30 | #define ARRAY_SIZE(a) (sizeof(a) / sizeof((a)[0])) | 83 | |
84 | #if defined(_MSC_VER) // && !defined(__clang__) | ||
85 | #define Z7_DECLSPEC_NOTHROW __declspec(nothrow) | ||
86 | #elif defined(__clang__) || defined(__GNUC__) | ||
87 | #define Z7_DECLSPEC_NOTHROW __attribute__((nothrow)) | ||
88 | #else | ||
89 | #define Z7_DECLSPEC_NOTHROW | ||
90 | #endif | ||
91 | |||
92 | /* | ||
93 | #if defined (_MSC_VER) && _MSC_VER >= 1900 \ | ||
94 | || defined(__clang__) && __clang_major__ >= 6 \ | ||
95 | || defined(__GNUC__) && __GNUC__ >= 6 | ||
96 | #define Z7_noexcept noexcept | ||
97 | #else | ||
98 | #define Z7_noexcept throw() | ||
99 | #endif | ||
100 | */ | ||
101 | |||
102 | |||
103 | #if defined(__clang__) | ||
104 | |||
105 | // noexcept, final, = delete | ||
106 | #pragma GCC diagnostic ignored "-Wc++98-compat" | ||
107 | #if __clang_major__ >= 4 | ||
108 | // throw() dynamic exception specifications are deprecated | ||
109 | #pragma GCC diagnostic ignored "-Wdeprecated-dynamic-exception-spec" | ||
110 | #endif | ||
111 | #pragma GCC diagnostic ignored "-Wold-style-cast" | ||
112 | #pragma GCC diagnostic ignored "-Wglobal-constructors" | ||
113 | #pragma GCC diagnostic ignored "-Wexit-time-destructors" | ||
114 | |||
115 | // #pragma GCC diagnostic ignored "-Wunused-private-field" | ||
116 | // #pragma GCC diagnostic ignored "-Wnonportable-system-include-path" | ||
117 | // #pragma GCC diagnostic ignored "-Wsuggest-override" | ||
118 | // #pragma GCC diagnostic ignored "-Wsign-conversion" | ||
119 | // #pragma GCC diagnostic ignored "-Winconsistent-missing-override" | ||
120 | // #pragma GCC diagnostic ignored "-Wsuggest-destructor-override" | ||
121 | // #pragma GCC diagnostic ignored "-Wnon-virtual-dtor" | ||
122 | // #pragma GCC diagnostic ignored "-Wdeprecated-copy-with-user-provided-dtor" | ||
123 | // #pragma GCC diagnostic ignored "-Wdeprecated-copy-dtor" | ||
124 | // #ifndef _WIN32 | ||
125 | // #pragma GCC diagnostic ignored "-Wweak-vtables" | ||
126 | // #endif | ||
127 | /* | ||
128 | #if defined(Z7_GCC_VERSION) && (Z7_GCC_VERSION >= 40400) \ | ||
129 | || defined(Z7_CLANG_VERSION) && (Z7_CLANG_VERSION >= 30000) | ||
130 | // enumeration values not explicitly handled in switch | ||
131 | #pragma GCC diagnostic ignored "-Wswitch-enum" | ||
132 | #endif | ||
133 | */ | ||
134 | #endif // __clang__ | ||
135 | |||
136 | |||
137 | #ifdef __GNUC__ | ||
138 | // #pragma GCC diagnostic ignored "-Wdelete-non-virtual-dtor" | ||
139 | #endif | ||
31 | 140 | ||
32 | 141 | ||
33 | /* There is BUG in MSVC 6.0 compiler for operator new[]: | 142 | /* There is BUG in MSVC 6.0 compiler for operator new[]: |
34 | It doesn't check overflow, when it calculates size in bytes for allocated array. | 143 | It doesn't check overflow, when it calculates size in bytes for allocated array. |
35 | So we can use MY_ARRAY_NEW macro instead of new[] operator. */ | 144 | So we can use Z7_ARRAY_NEW macro instead of new[] operator. */ |
36 | 145 | ||
37 | #if defined(_MSC_VER) && (_MSC_VER == 1200) && !defined(_WIN64) | 146 | #if defined(_MSC_VER) && (_MSC_VER == 1200) && !defined(_WIN64) |
38 | #define MY_ARRAY_NEW(p, T, size) p = new T[((size) > (unsigned)0xFFFFFFFF / sizeof(T)) ? (unsigned)0xFFFFFFFF / sizeof(T) : (size)]; | 147 | #define Z7_ARRAY_NEW(p, T, size) p = new T[((size) > (unsigned)0xFFFFFFFF / sizeof(T)) ? (unsigned)0xFFFFFFFF / sizeof(T) : (size)]; |
39 | #else | 148 | #else |
40 | #define MY_ARRAY_NEW(p, T, size) p = new T[size]; | 149 | #define Z7_ARRAY_NEW(p, T, size) p = new T[size]; |
41 | #endif | 150 | #endif |
42 | 151 | ||
43 | #if (defined(__GNUC__) && (__GNUC__ >= 8)) | 152 | #if (defined(__GNUC__) && (__GNUC__ >= 8)) |
44 | #define MY_ATTR_NORETURN __attribute__((noreturn)) | 153 | #define Z7_ATTR_NORETURN __attribute__((noreturn)) |
45 | #elif (defined(__clang__) && (__clang_major__ >= 3)) | 154 | #elif (defined(__clang__) && (__clang_major__ >= 3)) |
46 | #if __has_feature(cxx_attributes) | 155 | #if __has_feature(cxx_attributes) |
47 | #define MY_ATTR_NORETURN [[noreturn]] | 156 | #define Z7_ATTR_NORETURN [[noreturn]] |
48 | #else | 157 | #else |
49 | #define MY_ATTR_NORETURN __attribute__ ((noreturn)) | 158 | #define Z7_ATTR_NORETURN __attribute__((noreturn)) |
50 | #endif | 159 | #endif |
51 | #elif (defined(_MSC_VER) && (_MSC_VER >= 1900)) | 160 | #elif (defined(_MSC_VER) && (_MSC_VER >= 1900)) |
52 | #define MY_ATTR_NORETURN [[noreturn]] | 161 | #define Z7_ATTR_NORETURN [[noreturn]] |
162 | #else | ||
163 | #define Z7_ATTR_NORETURN | ||
164 | #endif | ||
165 | |||
166 | |||
167 | // final in "GCC 4.7.0" | ||
168 | // In C++98 and C++03 code the alternative spelling __final can be used instead (this is a GCC extension.) | ||
169 | |||
170 | #if defined (__cplusplus) && __cplusplus >= 201103L \ | ||
171 | || defined(_MSC_VER) && _MSC_VER >= 1800 \ | ||
172 | || defined(__clang__) && __clang_major__ >= 4 \ | ||
173 | /* || defined(__GNUC__) && __GNUC__ >= 9 */ | ||
174 | #define Z7_final final | ||
175 | #if defined(__clang__) && __cplusplus < 201103L | ||
176 | #pragma GCC diagnostic ignored "-Wc++11-extensions" | ||
177 | #endif | ||
178 | #elif defined (__cplusplus) && __cplusplus >= 199711L \ | ||
179 | && defined(__GNUC__) && __GNUC__ >= 4 && !defined(__clang__) | ||
180 | #define Z7_final __final | ||
53 | #else | 181 | #else |
54 | #define MY_ATTR_NORETURN | 182 | #define Z7_final |
183 | #if defined(__clang__) && __clang_major__ >= 4 \ | ||
184 | || defined(__GNUC__) && __GNUC__ >= 4 | ||
185 | #pragma GCC diagnostic ignored "-Wnon-virtual-dtor" | ||
186 | #pragma GCC diagnostic ignored "-Wdelete-non-virtual-dtor" | ||
187 | #endif | ||
55 | #endif | 188 | #endif |
56 | 189 | ||
190 | #define Z7_class_final(c) class c Z7_final | ||
191 | |||
192 | |||
193 | #if defined (__cplusplus) && __cplusplus >= 201103L \ | ||
194 | || (defined(_MSC_VER) && _MSC_VER >= 1800) | ||
195 | #define Z7_CPP_IS_SUPPORTED_default | ||
196 | #define Z7_eq_delete = delete | ||
197 | // #define Z7_DECL_DEFAULT_COPY_CONSTRUCTOR_IF_SUPPORTED(c) c(const c& k) = default; | ||
198 | #else | ||
199 | #define Z7_eq_delete | ||
200 | // #define Z7_DECL_DEFAULT_COPY_CONSTRUCTOR_IF_SUPPORTED(c) | ||
57 | #endif | 201 | #endif |
202 | |||
203 | |||
204 | #if defined(__cplusplus) && (__cplusplus >= 201103L) \ | ||
205 | || defined(_MSC_VER) && (_MSC_VER >= 1400) /* && (_MSC_VER != 1600) */ \ | ||
206 | || defined(__clang__) && __clang_major__ >= 4 | ||
207 | #if defined(_MSC_VER) && (_MSC_VER == 1600) /* && (_MSC_VER != 1600) */ | ||
208 | #pragma warning(disable : 4481) // nonstandard extension used: override specifier 'override' | ||
209 | #define Z7_DESTRUCTOR_override | ||
210 | #else | ||
211 | #define Z7_DESTRUCTOR_override override | ||
212 | #endif | ||
213 | #define Z7_override override | ||
214 | #else | ||
215 | #define Z7_override | ||
216 | #define Z7_DESTRUCTOR_override | ||
217 | #endif | ||
218 | |||
219 | |||
220 | |||
221 | #define Z7_CLASS_NO_COPY(cls) \ | ||
222 | private: \ | ||
223 | cls(const cls &) Z7_eq_delete; \ | ||
224 | cls &operator=(const cls &) Z7_eq_delete; | ||
225 | |||
226 | class CUncopyable | ||
227 | { | ||
228 | protected: | ||
229 | CUncopyable() {} // allow constructor | ||
230 | // ~CUncopyable() {} | ||
231 | Z7_CLASS_NO_COPY(CUncopyable) | ||
232 | }; | ||
233 | |||
234 | #define MY_UNCOPYABLE :private CUncopyable | ||
235 | // #define MY_UNCOPYABLE | ||
236 | |||
237 | |||
238 | typedef void (*Z7_void_Function)(void); | ||
239 | |||
240 | #if defined(__clang__) || defined(__GNUC__) | ||
241 | #define Z7_CAST_FUNC(t, e) reinterpret_cast<t>(reinterpret_cast<Z7_void_Function>(e)) | ||
242 | #else | ||
243 | #define Z7_CAST_FUNC(t, e) reinterpret_cast<t>(reinterpret_cast<void*>(e)) | ||
244 | // #define Z7_CAST_FUNC(t, e) reinterpret_cast<t>(e) | ||
245 | #endif | ||
246 | |||
247 | #define Z7_GET_PROC_ADDRESS(func_type, hmodule, func_name) \ | ||
248 | Z7_CAST_FUNC(func_type, GetProcAddress(hmodule, func_name)) | ||
249 | |||
250 | // || defined(__clang__) | ||
251 | // || defined(__GNUC__) | ||
252 | |||
253 | #if defined(_MSC_VER) && (_MSC_VER >= 1400) | ||
254 | #define Z7_DECLSPEC_NOVTABLE __declspec(novtable) | ||
255 | #else | ||
256 | #define Z7_DECLSPEC_NOVTABLE | ||
257 | #endif | ||
258 | |||
259 | #ifdef __clang__ | ||
260 | #define Z7_PURE_INTERFACES_BEGIN \ | ||
261 | _Pragma("GCC diagnostic push") \ | ||
262 | _Pragma("GCC diagnostic ignored \"-Wnon-virtual-dtor\"") | ||
263 | _Pragma("GCC diagnostic ignored \"-Wweak-vtables\"") | ||
264 | #define Z7_PURE_INTERFACES_END \ | ||
265 | _Pragma("GCC diagnostic pop") | ||
266 | #else | ||
267 | #define Z7_PURE_INTERFACES_BEGIN | ||
268 | #define Z7_PURE_INTERFACES_END | ||
269 | #endif | ||
270 | |||
271 | // NewHandler.h and NewHandler.cpp redefine operator new() to throw exceptions, if compiled with old MSVC compilers | ||
272 | #include "NewHandler.h" | ||
273 | |||
274 | /* | ||
275 | // #define ARRAY_SIZE(a) (sizeof(a) / sizeof((a)[0])) | ||
276 | #ifndef ARRAY_SIZE | ||
277 | #define ARRAY_SIZE(a) Z7_ARRAY_SIZE(a) | ||
278 | #endif | ||
279 | */ | ||
280 | |||
281 | #endif // ZIP7_INC_COMMON_H | ||
282 | |||
283 | |||
284 | |||
285 | // #define Z7_REDEFINE_NULL | ||
286 | |||
287 | #if defined(Z7_REDEFINE_NULL) /* && (!defined(__clang__) || defined(_MSC_VER)) */ | ||
288 | |||
289 | // NULL is defined in <stddef.h> | ||
290 | #include <stddef.h> | ||
291 | #undef NULL | ||
292 | |||
293 | #ifdef __cplusplus | ||
294 | #if defined (__cplusplus) && __cplusplus >= 201103L \ | ||
295 | || (defined(_MSC_VER) && _MSC_VER >= 1800) | ||
296 | #define NULL nullptr | ||
297 | #else | ||
298 | #define NULL 0 | ||
299 | #endif | ||
300 | #else | ||
301 | #define NULL ((void *)0) | ||
302 | #endif | ||
303 | |||
304 | #else // Z7_REDEFINE_NULL | ||
305 | |||
306 | #if defined(__clang__) && __clang_major__ >= 5 | ||
307 | #pragma GCC diagnostic ignored "-Wzero-as-null-pointer-constant" | ||
308 | #endif | ||
309 | |||
310 | #endif // Z7_REDEFINE_NULL | ||
311 | |||
312 | // for precompiler: | ||
313 | #include "MyWindows.h" | ||
diff --git a/CPP/Common/CrcReg.cpp b/CPP/Common/CrcReg.cpp index fdbba77..6cda892 100644 --- a/CPP/Common/CrcReg.cpp +++ b/CPP/Common/CrcReg.cpp | |||
@@ -11,42 +11,39 @@ | |||
11 | 11 | ||
12 | EXTERN_C_BEGIN | 12 | EXTERN_C_BEGIN |
13 | 13 | ||
14 | typedef UInt32 (MY_FAST_CALL *CRC_FUNC)(UInt32 v, const void *data, size_t size, const UInt32 *table); | 14 | // UInt32 Z7_FASTCALL CrcUpdateT1(UInt32 v, const void *data, size_t size, const UInt32 *table); |
15 | |||
16 | UInt32 MY_FAST_CALL CrcUpdateT1(UInt32 v, const void *data, size_t size, const UInt32 *table); | ||
17 | 15 | ||
18 | extern CRC_FUNC g_CrcUpdate; | 16 | extern CRC_FUNC g_CrcUpdate; |
19 | extern CRC_FUNC g_CrcUpdateT4; | 17 | // extern CRC_FUNC g_CrcUpdateT4; |
20 | extern CRC_FUNC g_CrcUpdateT8; | 18 | extern CRC_FUNC g_CrcUpdateT8; |
21 | extern CRC_FUNC g_CrcUpdateT0_32; | 19 | extern CRC_FUNC g_CrcUpdateT0_32; |
22 | extern CRC_FUNC g_CrcUpdateT0_64; | 20 | extern CRC_FUNC g_CrcUpdateT0_64; |
23 | 21 | ||
24 | EXTERN_C_END | 22 | EXTERN_C_END |
25 | 23 | ||
26 | class CCrcHasher: | 24 | Z7_CLASS_IMP_COM_2( |
27 | public IHasher, | 25 | CCrcHasher |
28 | public ICompressSetCoderProperties, | 26 | , IHasher |
29 | public CMyUnknownImp | 27 | , ICompressSetCoderProperties |
30 | { | 28 | ) |
31 | UInt32 _crc; | 29 | UInt32 _crc; |
32 | CRC_FUNC _updateFunc; | 30 | CRC_FUNC _updateFunc; |
33 | Byte mtDummy[1 << 7]; | 31 | |
34 | 32 | Z7_CLASS_NO_COPY(CCrcHasher) | |
33 | |||
35 | bool SetFunctions(UInt32 tSize); | 34 | bool SetFunctions(UInt32 tSize); |
36 | public: | 35 | public: |
37 | CCrcHasher(): _crc(CRC_INIT_VAL) { SetFunctions(0); } | 36 | Byte _mtDummy[1 << 7]; // it's public to eliminate clang warning: unused private field |
38 | 37 | ||
39 | MY_UNKNOWN_IMP2(IHasher, ICompressSetCoderProperties) | 38 | CCrcHasher(): _crc(CRC_INIT_VAL) { SetFunctions(0); } |
40 | INTERFACE_IHasher(;) | ||
41 | STDMETHOD(SetCoderProperties)(const PROPID *propIDs, const PROPVARIANT *props, UInt32 numProps); | ||
42 | }; | 39 | }; |
43 | 40 | ||
44 | bool CCrcHasher::SetFunctions(UInt32 tSize) | 41 | bool CCrcHasher::SetFunctions(UInt32 tSize) |
45 | { | 42 | { |
46 | CRC_FUNC f = NULL; | 43 | CRC_FUNC f = NULL; |
47 | if (tSize == 0) f = g_CrcUpdate; | 44 | if (tSize == 0) f = g_CrcUpdate; |
48 | else if (tSize == 1) f = CrcUpdateT1; | 45 | // else if (tSize == 1) f = CrcUpdateT1; |
49 | else if (tSize == 4) f = g_CrcUpdateT4; | 46 | // else if (tSize == 4) f = g_CrcUpdateT4; |
50 | else if (tSize == 8) f = g_CrcUpdateT8; | 47 | else if (tSize == 8) f = g_CrcUpdateT8; |
51 | else if (tSize == 32) f = g_CrcUpdateT0_32; | 48 | else if (tSize == 32) f = g_CrcUpdateT0_32; |
52 | else if (tSize == 64) f = g_CrcUpdateT0_64; | 49 | else if (tSize == 64) f = g_CrcUpdateT0_64; |
@@ -60,13 +57,13 @@ bool CCrcHasher::SetFunctions(UInt32 tSize) | |||
60 | return true; | 57 | return true; |
61 | } | 58 | } |
62 | 59 | ||
63 | STDMETHODIMP CCrcHasher::SetCoderProperties(const PROPID *propIDs, const PROPVARIANT *coderProps, UInt32 numProps) | 60 | Z7_COM7F_IMF(CCrcHasher::SetCoderProperties(const PROPID *propIDs, const PROPVARIANT *coderProps, UInt32 numProps)) |
64 | { | 61 | { |
65 | for (UInt32 i = 0; i < numProps; i++) | 62 | for (UInt32 i = 0; i < numProps; i++) |
66 | { | 63 | { |
67 | const PROPVARIANT &prop = coderProps[i]; | ||
68 | if (propIDs[i] == NCoderPropID::kDefaultProp) | 64 | if (propIDs[i] == NCoderPropID::kDefaultProp) |
69 | { | 65 | { |
66 | const PROPVARIANT &prop = coderProps[i]; | ||
70 | if (prop.vt != VT_UI4) | 67 | if (prop.vt != VT_UI4) |
71 | return E_INVALIDARG; | 68 | return E_INVALIDARG; |
72 | if (!SetFunctions(prop.ulVal)) | 69 | if (!SetFunctions(prop.ulVal)) |
@@ -76,20 +73,20 @@ STDMETHODIMP CCrcHasher::SetCoderProperties(const PROPID *propIDs, const PROPVAR | |||
76 | return S_OK; | 73 | return S_OK; |
77 | } | 74 | } |
78 | 75 | ||
79 | STDMETHODIMP_(void) CCrcHasher::Init() throw() | 76 | Z7_COM7F_IMF2(void, CCrcHasher::Init()) |
80 | { | 77 | { |
81 | _crc = CRC_INIT_VAL; | 78 | _crc = CRC_INIT_VAL; |
82 | } | 79 | } |
83 | 80 | ||
84 | STDMETHODIMP_(void) CCrcHasher::Update(const void *data, UInt32 size) throw() | 81 | Z7_COM7F_IMF2(void, CCrcHasher::Update(const void *data, UInt32 size)) |
85 | { | 82 | { |
86 | _crc = _updateFunc(_crc, data, size, g_CrcTable); | 83 | _crc = _updateFunc(_crc, data, size, g_CrcTable); |
87 | } | 84 | } |
88 | 85 | ||
89 | STDMETHODIMP_(void) CCrcHasher::Final(Byte *digest) throw() | 86 | Z7_COM7F_IMF2(void, CCrcHasher::Final(Byte *digest)) |
90 | { | 87 | { |
91 | UInt32 val = CRC_GET_DIGEST(_crc); | 88 | const UInt32 val = CRC_GET_DIGEST(_crc); |
92 | SetUi32(digest, val); | 89 | SetUi32(digest, val) |
93 | } | 90 | } |
94 | 91 | ||
95 | REGISTER_HASHER(CCrcHasher, 0x1, "CRC32", 4) | 92 | REGISTER_HASHER(CCrcHasher, 0x1, "CRC32", 4) |
diff --git a/CPP/Common/Defs.h b/CPP/Common/Defs.h index 9adb88c..e302f35 100644 --- a/CPP/Common/Defs.h +++ b/CPP/Common/Defs.h | |||
@@ -1,7 +1,7 @@ | |||
1 | // Common/Defs.h | 1 | // Common/Defs.h |
2 | 2 | ||
3 | #ifndef __COMMON_DEFS_H | 3 | #ifndef ZIP7_INC_COMMON_DEFS_H |
4 | #define __COMMON_DEFS_H | 4 | #define ZIP7_INC_COMMON_DEFS_H |
5 | 5 | ||
6 | template <class T> inline T MyMin(T a, T b) { return a < b ? a : b; } | 6 | template <class T> inline T MyMin(T a, T b) { return a < b ? a : b; } |
7 | template <class T> inline T MyMax(T a, T b) { return a > b ? a : b; } | 7 | template <class T> inline T MyMax(T a, T b) { return a > b ? a : b; } |
@@ -10,7 +10,7 @@ template <class T> inline int MyCompare(T a, T b) | |||
10 | { return a == b ? 0 : (a < b ? -1 : 1); } | 10 | { return a == b ? 0 : (a < b ? -1 : 1); } |
11 | 11 | ||
12 | inline int BoolToInt(bool v) { return (v ? 1 : 0); } | 12 | inline int BoolToInt(bool v) { return (v ? 1 : 0); } |
13 | inline unsigned BoolToUInt(bool v) { return (v ? (unsigned)1 : (unsigned)0); } | 13 | inline unsigned BoolToUInt(bool v) { return (v ? 1u : 0u); } |
14 | inline bool IntToBool(int v) { return (v != 0); } | 14 | inline bool IntToBool(int v) { return (v != 0); } |
15 | 15 | ||
16 | #endif | 16 | #endif |
diff --git a/CPP/Common/DynLimBuf.cpp b/CPP/Common/DynLimBuf.cpp index 7914104..1d92af3 100644 --- a/CPP/Common/DynLimBuf.cpp +++ b/CPP/Common/DynLimBuf.cpp | |||
@@ -7,7 +7,7 @@ | |||
7 | 7 | ||
8 | CDynLimBuf::CDynLimBuf(size_t limit) throw() | 8 | CDynLimBuf::CDynLimBuf(size_t limit) throw() |
9 | { | 9 | { |
10 | _chars = 0; | 10 | _chars = NULL; |
11 | _pos = 0; | 11 | _pos = 0; |
12 | _size = 0; | 12 | _size = 0; |
13 | _sizeLimit = limit; | 13 | _sizeLimit = limit; |
diff --git a/CPP/Common/DynLimBuf.h b/CPP/Common/DynLimBuf.h index e80a7e7..af22f07 100644 --- a/CPP/Common/DynLimBuf.h +++ b/CPP/Common/DynLimBuf.h | |||
@@ -1,7 +1,7 @@ | |||
1 | // Common/DynLimBuf.h | 1 | // Common/DynLimBuf.h |
2 | 2 | ||
3 | #ifndef __COMMON_DYN_LIM_BUF_H | 3 | #ifndef ZIP7_INC_COMMON_DYN_LIM_BUF_H |
4 | #define __COMMON_DYN_LIM_BUF_H | 4 | #define ZIP7_INC_COMMON_DYN_LIM_BUF_H |
5 | 5 | ||
6 | #include <string.h> | 6 | #include <string.h> |
7 | 7 | ||
diff --git a/CPP/Common/DynamicBuffer.h b/CPP/Common/DynamicBuffer.h index f6f6b15..714be4a 100644 --- a/CPP/Common/DynamicBuffer.h +++ b/CPP/Common/DynamicBuffer.h | |||
@@ -1,7 +1,11 @@ | |||
1 | // Common/DynamicBuffer.h | 1 | // Common/DynamicBuffer.h |
2 | 2 | ||
3 | #ifndef __COMMON_DYNAMIC_BUFFER_H | 3 | #ifndef ZIP7_INC_COMMON_DYNAMIC_BUFFER_H |
4 | #define __COMMON_DYNAMIC_BUFFER_H | 4 | #define ZIP7_INC_COMMON_DYNAMIC_BUFFER_H |
5 | |||
6 | #include <string.h> | ||
7 | |||
8 | #include "Common.h" | ||
5 | 9 | ||
6 | template <class T> class CDynamicBuffer | 10 | template <class T> class CDynamicBuffer |
7 | { | 11 | { |
@@ -34,7 +38,7 @@ template <class T> class CDynamicBuffer | |||
34 | } | 38 | } |
35 | 39 | ||
36 | public: | 40 | public: |
37 | CDynamicBuffer(): _items(0), _size(0), _pos(0) {} | 41 | CDynamicBuffer(): _items(NULL), _size(0), _pos(0) {} |
38 | // operator T *() { return _items; } | 42 | // operator T *() { return _items; } |
39 | operator const T *() const { return _items; } | 43 | operator const T *() const { return _items; } |
40 | ~CDynamicBuffer() { delete []_items; } | 44 | ~CDynamicBuffer() { delete []_items; } |
diff --git a/CPP/Common/IntToString.cpp b/CPP/Common/IntToString.cpp index c87643c..21b0680 100644 --- a/CPP/Common/IntToString.cpp +++ b/CPP/Common/IntToString.cpp | |||
@@ -16,7 +16,7 @@ | |||
16 | 16 | ||
17 | char * ConvertUInt32ToString(UInt32 val, char *s) throw() | 17 | char * ConvertUInt32ToString(UInt32 val, char *s) throw() |
18 | { | 18 | { |
19 | CONVERT_INT_TO_STR(char, 16); | 19 | CONVERT_INT_TO_STR(char, 16) |
20 | } | 20 | } |
21 | 21 | ||
22 | char * ConvertUInt64ToString(UInt64 val, char *s) throw() | 22 | char * ConvertUInt64ToString(UInt64 val, char *s) throw() |
@@ -25,7 +25,7 @@ char * ConvertUInt64ToString(UInt64 val, char *s) throw() | |||
25 | { | 25 | { |
26 | return ConvertUInt32ToString((UInt32)val, s); | 26 | return ConvertUInt32ToString((UInt32)val, s); |
27 | } | 27 | } |
28 | CONVERT_INT_TO_STR(char, 24); | 28 | CONVERT_INT_TO_STR(char, 24) |
29 | } | 29 | } |
30 | 30 | ||
31 | void ConvertUInt64ToOct(UInt64 val, char *s) throw() | 31 | void ConvertUInt64ToOct(UInt64 val, char *s) throw() |
@@ -102,7 +102,7 @@ void ConvertUInt32ToHex8Digits(UInt32 val, char *s) throw() | |||
102 | { | 102 | { |
103 | unsigned t = val & 0xF; | 103 | unsigned t = val & 0xF; |
104 | val >>= 4; | 104 | val >>= 4; |
105 | s[i] = GET_HEX_CHAR(t);; | 105 | s[i] = GET_HEX_CHAR(t); |
106 | } | 106 | } |
107 | } | 107 | } |
108 | 108 | ||
@@ -121,7 +121,7 @@ void ConvertUInt32ToHex8Digits(UInt32 val, wchar_t *s) | |||
121 | 121 | ||
122 | wchar_t * ConvertUInt32ToString(UInt32 val, wchar_t *s) throw() | 122 | wchar_t * ConvertUInt32ToString(UInt32 val, wchar_t *s) throw() |
123 | { | 123 | { |
124 | CONVERT_INT_TO_STR(wchar_t, 16); | 124 | CONVERT_INT_TO_STR(wchar_t, 16) |
125 | } | 125 | } |
126 | 126 | ||
127 | wchar_t * ConvertUInt64ToString(UInt64 val, wchar_t *s) throw() | 127 | wchar_t * ConvertUInt64ToString(UInt64 val, wchar_t *s) throw() |
@@ -130,7 +130,7 @@ wchar_t * ConvertUInt64ToString(UInt64 val, wchar_t *s) throw() | |||
130 | { | 130 | { |
131 | return ConvertUInt32ToString((UInt32)val, s); | 131 | return ConvertUInt32ToString((UInt32)val, s); |
132 | } | 132 | } |
133 | CONVERT_INT_TO_STR(wchar_t, 24); | 133 | CONVERT_INT_TO_STR(wchar_t, 24) |
134 | } | 134 | } |
135 | 135 | ||
136 | void ConvertInt64ToString(Int64 val, char *s) throw() | 136 | void ConvertInt64ToString(Int64 val, char *s) throw() |
diff --git a/CPP/Common/IntToString.h b/CPP/Common/IntToString.h index d0a96ef..f4fc662 100644 --- a/CPP/Common/IntToString.h +++ b/CPP/Common/IntToString.h | |||
@@ -1,7 +1,7 @@ | |||
1 | // Common/IntToString.h | 1 | // Common/IntToString.h |
2 | 2 | ||
3 | #ifndef __COMMON_INT_TO_STRING_H | 3 | #ifndef ZIP7_INC_COMMON_INT_TO_STRING_H |
4 | #define __COMMON_INT_TO_STRING_H | 4 | #define ZIP7_INC_COMMON_INT_TO_STRING_H |
5 | 5 | ||
6 | #include "MyTypes.h" | 6 | #include "MyTypes.h" |
7 | 7 | ||
diff --git a/CPP/Common/Lang.cpp b/CPP/Common/Lang.cpp index 35d3752..b0b4342 100644 --- a/CPP/Common/Lang.cpp +++ b/CPP/Common/Lang.cpp | |||
@@ -12,85 +12,95 @@ void CLang::Clear() throw() | |||
12 | { | 12 | { |
13 | _ids.Clear(); | 13 | _ids.Clear(); |
14 | _offsets.Clear(); | 14 | _offsets.Clear(); |
15 | Comments.Clear(); | ||
15 | delete []_text; | 16 | delete []_text; |
16 | _text = 0; | 17 | _text = NULL; |
17 | } | 18 | } |
18 | 19 | ||
19 | static const char * const kLangSignature = ";!@Lang2@!UTF-8!"; | 20 | static const char * const kLangSignature = ";!@Lang2@!UTF-8!\n"; |
20 | 21 | ||
21 | bool CLang::OpenFromString(const AString &s2) | 22 | bool CLang::OpenFromString(const AString &s2) |
22 | { | 23 | { |
23 | UString s; | 24 | UString su; |
24 | if (!ConvertUTF8ToUnicode(s2, s)) | 25 | if (!ConvertUTF8ToUnicode(s2, su)) |
25 | return false; | 26 | return false; |
26 | unsigned i = 0; | 27 | if (su.IsEmpty()) |
27 | if (s.IsEmpty()) | ||
28 | return false; | 28 | return false; |
29 | if (s[0] == 0xFEFF) | 29 | const wchar_t *s = su; |
30 | i++; | 30 | const wchar_t *sLim = s + su.Len(); |
31 | 31 | if (*s == 0xFEFF) | |
32 | for (const char *p = kLangSignature;; i++) | 32 | s++; |
33 | for (const char *p = kLangSignature;; s++) | ||
33 | { | 34 | { |
34 | Byte c = (Byte)(*p++); | 35 | const Byte c = (Byte)(*p++); |
35 | if (c == 0) | 36 | if (c == 0) |
36 | break; | 37 | break; |
37 | if (s[i] != c) | 38 | if (*s != c) |
38 | return false; | 39 | return false; |
39 | } | 40 | } |
40 | 41 | ||
41 | _text = new wchar_t[s.Len() - i + 1]; | 42 | wchar_t *text = new wchar_t[(size_t)(sLim - s) + 1]; |
42 | wchar_t *text = _text; | 43 | _text = text; |
43 | 44 | ||
44 | Int32 id = -100; | 45 | UString comment; |
45 | UInt32 pos = 0; | 46 | Int32 id = -1024; |
47 | unsigned pos = 0; | ||
46 | 48 | ||
47 | while (i < s.Len()) | 49 | while (s != sLim) |
48 | { | 50 | { |
49 | unsigned start = pos; | 51 | const unsigned start = pos; |
50 | do | 52 | do |
51 | { | 53 | { |
52 | wchar_t c = s[i++]; | 54 | wchar_t c = *s++; |
53 | if (c == '\n') | 55 | if (c == '\n') |
54 | break; | 56 | break; |
55 | if (c == '\\') | 57 | if (c == '\\') |
56 | { | 58 | { |
57 | if (i == s.Len()) | 59 | if (s == sLim) |
58 | return false; | 60 | return false; |
59 | c = s[i++]; | 61 | c = *s++; |
60 | switch (c) | 62 | switch (c) |
61 | { | 63 | { |
62 | case '\n': return false; | 64 | case '\n': return false; |
63 | case 'n': c = '\n'; break; | 65 | case 'n': c = '\n'; break; |
64 | case 't': c = '\t'; break; | 66 | case 't': c = '\t'; break; |
65 | case '\\': c = '\\'; break; | 67 | case '\\': /* c = '\\'; */ break; |
66 | default: text[pos++] = L'\\'; break; | 68 | default: text[pos++] = L'\\'; break; |
67 | } | 69 | } |
68 | } | 70 | } |
69 | text[pos++] = c; | 71 | text[pos++] = c; |
70 | } | 72 | } |
71 | while (i < s.Len()); | 73 | while (s != sLim); |
72 | 74 | ||
73 | { | 75 | { |
74 | unsigned j = start; | 76 | unsigned j = start; |
75 | for (; j < pos; j++) | 77 | for (; j < pos; j++) |
76 | if (text[j] != ' ') | 78 | if (text[j] != ' ' && text[j] != '\t') |
77 | break; | 79 | break; |
78 | if (j == pos) | 80 | if (j == pos) |
79 | { | 81 | { |
80 | id++; | 82 | id++; |
83 | pos = start; | ||
81 | continue; | 84 | continue; |
82 | } | 85 | } |
83 | } | 86 | } |
87 | |||
88 | // start != pos | ||
89 | text[pos++] = 0; | ||
90 | |||
84 | if (text[start] == ';') | 91 | if (text[start] == ';') |
85 | { | 92 | { |
86 | pos = start; | 93 | comment = text + start; |
94 | comment.TrimRight(); | ||
95 | if (comment.Len() != 1) | ||
96 | Comments.Add(comment); | ||
87 | id++; | 97 | id++; |
98 | pos = start; | ||
88 | continue; | 99 | continue; |
89 | } | 100 | } |
90 | 101 | ||
91 | text[pos++] = 0; | ||
92 | const wchar_t *end; | 102 | const wchar_t *end; |
93 | UInt32 id32 = ConvertStringToUInt32(text + start, &end); | 103 | const UInt32 id32 = ConvertStringToUInt32(text + start, &end); |
94 | if (*end == 0) | 104 | if (*end == 0) |
95 | { | 105 | { |
96 | if (id32 > ((UInt32)1 << 30) || (Int32)id32 < id) | 106 | if (id32 > ((UInt32)1 << 30) || (Int32)id32 < id) |
@@ -134,7 +144,7 @@ bool CLang::Open(CFSTR fileName, const char *id) | |||
134 | char *p2 = p; | 144 | char *p2 = p; |
135 | for (unsigned i = 0; i < len; i++) | 145 | for (unsigned i = 0; i < len; i++) |
136 | { | 146 | { |
137 | char c = p[i]; | 147 | const char c = p[i]; |
138 | if (c == 0) | 148 | if (c == 0) |
139 | break; | 149 | break; |
140 | if (c != 0x0D) | 150 | if (c != 0x0D) |
@@ -156,7 +166,7 @@ bool CLang::Open(CFSTR fileName, const char *id) | |||
156 | 166 | ||
157 | const wchar_t *CLang::Get(UInt32 id) const throw() | 167 | const wchar_t *CLang::Get(UInt32 id) const throw() |
158 | { | 168 | { |
159 | int index = _ids.FindInSorted(id); | 169 | const int index = _ids.FindInSorted(id); |
160 | if (index < 0) | 170 | if (index < 0) |
161 | return NULL; | 171 | return NULL; |
162 | return _text + (size_t)_offsets[(unsigned)index]; | 172 | return _text + (size_t)_offsets[(unsigned)index]; |
diff --git a/CPP/Common/Lang.h b/CPP/Common/Lang.h index cc66677..76d5418 100644 --- a/CPP/Common/Lang.h +++ b/CPP/Common/Lang.h | |||
@@ -1,23 +1,30 @@ | |||
1 | // Common/Lang.h | 1 | // Common/Lang.h |
2 | 2 | ||
3 | #ifndef __COMMON_LANG_H | 3 | #ifndef ZIP7_INC_COMMON_LANG_H |
4 | #define __COMMON_LANG_H | 4 | #define ZIP7_INC_COMMON_LANG_H |
5 | 5 | ||
6 | #include "MyString.h" | 6 | #include "MyString.h" |
7 | 7 | ||
8 | class CLang | 8 | class CLang |
9 | { | 9 | { |
10 | wchar_t *_text; | 10 | wchar_t *_text; |
11 | CRecordVector<UInt32> _ids; | ||
12 | CRecordVector<UInt32> _offsets; | ||
13 | 11 | ||
14 | bool OpenFromString(const AString &s); | 12 | bool OpenFromString(const AString &s); |
15 | public: | 13 | public: |
16 | CLang(): _text(0) {} | 14 | CRecordVector<UInt32> _ids; |
15 | CRecordVector<UInt32> _offsets; | ||
16 | UStringVector Comments; | ||
17 | |||
18 | CLang(): _text(NULL) {} | ||
17 | ~CLang() { Clear(); } | 19 | ~CLang() { Clear(); } |
18 | bool Open(CFSTR fileName, const char *id); | 20 | bool Open(CFSTR fileName, const char *id); |
19 | void Clear() throw(); | 21 | void Clear() throw(); |
22 | bool IsEmpty() const { return _ids.IsEmpty(); } | ||
20 | const wchar_t *Get(UInt32 id) const throw(); | 23 | const wchar_t *Get(UInt32 id) const throw(); |
24 | const wchar_t *Get_by_index(unsigned index) const throw() | ||
25 | { | ||
26 | return _text + (size_t)_offsets[index]; | ||
27 | } | ||
21 | }; | 28 | }; |
22 | 29 | ||
23 | #endif | 30 | #endif |
diff --git a/CPP/Common/ListFileUtils.cpp b/CPP/Common/ListFileUtils.cpp index b361b37..e43dbc9 100644 --- a/CPP/Common/ListFileUtils.cpp +++ b/CPP/Common/ListFileUtils.cpp | |||
@@ -66,7 +66,7 @@ bool ReadNamesFromListFile2(CFSTR fileName, UStringVector &strings, UINT codePag | |||
66 | if (fileSize >= ((UInt32)1 << 31) - 32) | 66 | if (fileSize >= ((UInt32)1 << 31) - 32) |
67 | return false; | 67 | return false; |
68 | UString u; | 68 | UString u; |
69 | if (codePage == MY__CP_UTF16 || codePage == MY__CP_UTF16BE) | 69 | if (codePage == Z7_WIN_CP_UTF16 || codePage == Z7_WIN_CP_UTF16BE) |
70 | { | 70 | { |
71 | if ((fileSize & 1) != 0) | 71 | if ((fileSize & 1) != 0) |
72 | return false; | 72 | return false; |
@@ -78,7 +78,7 @@ bool ReadNamesFromListFile2(CFSTR fileName, UStringVector &strings, UINT codePag | |||
78 | file.Close(); | 78 | file.Close(); |
79 | const unsigned num = (unsigned)fileSize / 2; | 79 | const unsigned num = (unsigned)fileSize / 2; |
80 | wchar_t *p = u.GetBuf(num); | 80 | wchar_t *p = u.GetBuf(num); |
81 | if (codePage == MY__CP_UTF16) | 81 | if (codePage == Z7_WIN_CP_UTF16) |
82 | for (unsigned i = 0; i < num; i++) | 82 | for (unsigned i = 0; i < num; i++) |
83 | { | 83 | { |
84 | wchar_t c = GetUi16(buf + (size_t)i * 2); | 84 | wchar_t c = GetUi16(buf + (size_t)i * 2); |
diff --git a/CPP/Common/ListFileUtils.h b/CPP/Common/ListFileUtils.h index a91e4b1..d43cc37 100644 --- a/CPP/Common/ListFileUtils.h +++ b/CPP/Common/ListFileUtils.h | |||
@@ -1,13 +1,13 @@ | |||
1 | // Common/ListFileUtils.h | 1 | // Common/ListFileUtils.h |
2 | 2 | ||
3 | #ifndef __COMMON_LIST_FILE_UTILS_H | 3 | #ifndef ZIP7_INC_COMMON_LIST_FILE_UTILS_H |
4 | #define __COMMON_LIST_FILE_UTILS_H | 4 | #define ZIP7_INC_COMMON_LIST_FILE_UTILS_H |
5 | 5 | ||
6 | #include "MyString.h" | 6 | #include "MyString.h" |
7 | #include "MyTypes.h" | 7 | #include "MyTypes.h" |
8 | 8 | ||
9 | #define MY__CP_UTF16 1200 | 9 | #define Z7_WIN_CP_UTF16 1200 |
10 | #define MY__CP_UTF16BE 1201 | 10 | #define Z7_WIN_CP_UTF16BE 1201 |
11 | 11 | ||
12 | // bool ReadNamesFromListFile(CFSTR fileName, UStringVector &strings, UINT codePage = CP_OEMCP); | 12 | // bool ReadNamesFromListFile(CFSTR fileName, UStringVector &strings, UINT codePage = CP_OEMCP); |
13 | 13 | ||
diff --git a/CPP/Common/MyBuffer.h b/CPP/Common/MyBuffer.h index 18ab6fa..bc829f4 100644 --- a/CPP/Common/MyBuffer.h +++ b/CPP/Common/MyBuffer.h | |||
@@ -1,13 +1,15 @@ | |||
1 | // Common/MyBuffer.h | 1 | // Common/MyBuffer.h |
2 | 2 | ||
3 | #ifndef __COMMON_MY_BUFFER_H | 3 | #ifndef ZIP7_INC_COMMON_MY_BUFFER_H |
4 | #define __COMMON_MY_BUFFER_H | 4 | #define ZIP7_INC_COMMON_MY_BUFFER_H |
5 | |||
6 | #include <string.h> | ||
5 | 7 | ||
6 | #include "Defs.h" | 8 | #include "Defs.h" |
7 | #include "MyTypes.h" | 9 | #include "MyTypes.h" |
8 | 10 | ||
9 | /* 7-Zip now uses CBuffer only as CByteBuffer. | 11 | /* 7-Zip now uses CBuffer only as CByteBuffer. |
10 | So there is no need to use MY_ARRAY_NEW macro in CBuffer code. */ | 12 | So there is no need to use Z7_ARRAY_NEW macro in CBuffer code. */ |
11 | 13 | ||
12 | template <class T> class CBuffer | 14 | template <class T> class CBuffer |
13 | { | 15 | { |
@@ -20,16 +22,23 @@ public: | |||
20 | if (_items) | 22 | if (_items) |
21 | { | 23 | { |
22 | delete []_items; | 24 | delete []_items; |
23 | _items = 0; | 25 | _items = NULL; |
24 | } | 26 | } |
25 | _size = 0; | 27 | _size = 0; |
26 | } | 28 | } |
27 | 29 | ||
28 | CBuffer(): _items(0), _size(0) {}; | 30 | CBuffer(): _items(NULL), _size(0) {} |
29 | CBuffer(size_t size): _items(0), _size(0) { _items = new T[size]; _size = size; } | 31 | CBuffer(size_t size): _items(NULL), _size(0) |
30 | CBuffer(const CBuffer &buffer): _items(0), _size(0) | 32 | { |
33 | if (size != 0) | ||
34 | { | ||
35 | _items = new T[size]; | ||
36 | _size = size; | ||
37 | } | ||
38 | } | ||
39 | CBuffer(const CBuffer &buffer): _items(NULL), _size(0) | ||
31 | { | 40 | { |
32 | size_t size = buffer._size; | 41 | const size_t size = buffer._size; |
33 | if (size != 0) | 42 | if (size != 0) |
34 | { | 43 | { |
35 | _items = new T[size]; | 44 | _items = new T[size]; |
@@ -136,7 +145,7 @@ typedef CBuffer<unsigned char> CByteBuffer; | |||
136 | 145 | ||
137 | class CByteBuffer_Wipe: public CByteBuffer | 146 | class CByteBuffer_Wipe: public CByteBuffer |
138 | { | 147 | { |
139 | CLASS_NO_COPY(CByteBuffer_Wipe) | 148 | Z7_CLASS_NO_COPY(CByteBuffer_Wipe) |
140 | public: | 149 | public: |
141 | // CByteBuffer_Wipe(): CBuffer<unsigned char>() {} | 150 | // CByteBuffer_Wipe(): CBuffer<unsigned char>() {} |
142 | CByteBuffer_Wipe(size_t size): CBuffer<unsigned char>(size) {} | 151 | CByteBuffer_Wipe(size_t size): CBuffer<unsigned char>(size) {} |
@@ -157,17 +166,17 @@ public: | |||
157 | void Free() | 166 | void Free() |
158 | { | 167 | { |
159 | delete []_items; | 168 | delete []_items; |
160 | _items = 0; | 169 | _items = NULL; |
161 | } | 170 | } |
162 | CObjArray(size_t size): _items(0) | 171 | CObjArray(size_t size): _items(NULL) |
163 | { | 172 | { |
164 | if (size != 0) | 173 | if (size != 0) |
165 | { | 174 | { |
166 | MY_ARRAY_NEW(_items, T, size) | 175 | Z7_ARRAY_NEW(_items, T, size) |
167 | // _items = new T[size]; | 176 | // _items = new T[size]; |
168 | } | 177 | } |
169 | } | 178 | } |
170 | CObjArray(): _items(0) {}; | 179 | CObjArray(): _items(NULL) {} |
171 | ~CObjArray() { delete []_items; } | 180 | ~CObjArray() { delete []_items; } |
172 | 181 | ||
173 | operator T *() { return _items; } | 182 | operator T *() { return _items; } |
@@ -176,8 +185,8 @@ public: | |||
176 | void Alloc(size_t newSize) | 185 | void Alloc(size_t newSize) |
177 | { | 186 | { |
178 | delete []_items; | 187 | delete []_items; |
179 | _items = 0; | 188 | _items = NULL; |
180 | MY_ARRAY_NEW(_items, T, newSize) | 189 | Z7_ARRAY_NEW(_items, T, newSize) |
181 | // _items = new T[newSize]; | 190 | // _items = new T[newSize]; |
182 | } | 191 | } |
183 | }; | 192 | }; |
@@ -201,12 +210,12 @@ public: | |||
201 | void Free() | 210 | void Free() |
202 | { | 211 | { |
203 | delete []_items; | 212 | delete []_items; |
204 | _items = 0; | 213 | _items = NULL; |
205 | _size = 0; | 214 | _size = 0; |
206 | } | 215 | } |
207 | CObjArray2(): _items(0), _size(0) {}; | 216 | CObjArray2(): _items(NULL), _size(0) {} |
208 | /* | 217 | /* |
209 | CObjArray2(const CObjArray2 &buffer): _items(0), _size(0) | 218 | CObjArray2(const CObjArray2 &buffer): _items(NULL), _size(0) |
210 | { | 219 | { |
211 | size_t newSize = buffer._size; | 220 | size_t newSize = buffer._size; |
212 | if (newSize != 0) | 221 | if (newSize != 0) |
@@ -221,7 +230,7 @@ public: | |||
221 | } | 230 | } |
222 | */ | 231 | */ |
223 | /* | 232 | /* |
224 | CObjArray2(size_t size): _items(0), _size(0) | 233 | CObjArray2(size_t size): _items(NULL), _size(0) |
225 | { | 234 | { |
226 | if (size != 0) | 235 | if (size != 0) |
227 | { | 236 | { |
@@ -247,7 +256,7 @@ public: | |||
247 | T *newBuffer = NULL; | 256 | T *newBuffer = NULL; |
248 | if (size != 0) | 257 | if (size != 0) |
249 | { | 258 | { |
250 | MY_ARRAY_NEW(newBuffer, T, size) | 259 | Z7_ARRAY_NEW(newBuffer, T, size) |
251 | // newBuffer = new T[size]; | 260 | // newBuffer = new T[size]; |
252 | } | 261 | } |
253 | delete []_items; | 262 | delete []_items; |
diff --git a/CPP/Common/MyBuffer2.h b/CPP/Common/MyBuffer2.h index 372d478..23394f8 100644 --- a/CPP/Common/MyBuffer2.h +++ b/CPP/Common/MyBuffer2.h | |||
@@ -1,7 +1,7 @@ | |||
1 | // Common/MyBuffer2.h | 1 | // Common/MyBuffer2.h |
2 | 2 | ||
3 | #ifndef __COMMON_MY_BUFFER2_H | 3 | #ifndef ZIP7_INC_COMMON_MY_BUFFER2_H |
4 | #define __COMMON_MY_BUFFER2_H | 4 | #define ZIP7_INC_COMMON_MY_BUFFER2_H |
5 | 5 | ||
6 | #include "../../C/Alloc.h" | 6 | #include "../../C/Alloc.h" |
7 | 7 | ||
@@ -12,7 +12,7 @@ class CMidBuffer | |||
12 | Byte *_data; | 12 | Byte *_data; |
13 | size_t _size; | 13 | size_t _size; |
14 | 14 | ||
15 | CLASS_NO_COPY(CMidBuffer) | 15 | Z7_CLASS_NO_COPY(CMidBuffer) |
16 | 16 | ||
17 | public: | 17 | public: |
18 | CMidBuffer(): _data(NULL), _size(0) {} | 18 | CMidBuffer(): _data(NULL), _size(0) {} |
@@ -56,12 +56,37 @@ public: | |||
56 | }; | 56 | }; |
57 | 57 | ||
58 | 58 | ||
59 | class CAlignedBuffer1 | ||
60 | { | ||
61 | Byte *_data; | ||
62 | |||
63 | Z7_CLASS_NO_COPY(CAlignedBuffer1) | ||
64 | |||
65 | public: | ||
66 | ~CAlignedBuffer1() | ||
67 | { | ||
68 | ISzAlloc_Free(&g_AlignedAlloc, _data); | ||
69 | } | ||
70 | |||
71 | CAlignedBuffer1(size_t size) | ||
72 | { | ||
73 | _data = NULL; | ||
74 | _data = (Byte *)ISzAlloc_Alloc(&g_AlignedAlloc, size); | ||
75 | if (!_data) | ||
76 | throw 1; | ||
77 | } | ||
78 | |||
79 | operator Byte *() { return _data; } | ||
80 | operator const Byte *() const { return _data; } | ||
81 | }; | ||
82 | |||
83 | |||
59 | class CAlignedBuffer | 84 | class CAlignedBuffer |
60 | { | 85 | { |
61 | Byte *_data; | 86 | Byte *_data; |
62 | size_t _size; | 87 | size_t _size; |
63 | 88 | ||
64 | CLASS_NO_COPY(CAlignedBuffer) | 89 | Z7_CLASS_NO_COPY(CAlignedBuffer) |
65 | 90 | ||
66 | public: | 91 | public: |
67 | CAlignedBuffer(): _data(NULL), _size(0) {} | 92 | CAlignedBuffer(): _data(NULL), _size(0) {} |
diff --git a/CPP/Common/MyCom.h b/CPP/Common/MyCom.h index ff54278..65c4330 100644 --- a/CPP/Common/MyCom.h +++ b/CPP/Common/MyCom.h | |||
@@ -1,15 +1,11 @@ | |||
1 | // MyCom.h | 1 | // MyCom.h |
2 | 2 | ||
3 | #ifndef __MY_COM_H | 3 | #ifndef ZIP7_INC_MY_COM_H |
4 | #define __MY_COM_H | 4 | #define ZIP7_INC_MY_COM_H |
5 | 5 | ||
6 | #include "MyWindows.h" | 6 | #include "MyWindows.h" |
7 | #include "MyTypes.h" | 7 | #include "MyTypes.h" |
8 | 8 | ||
9 | #ifndef RINOK | ||
10 | #define RINOK(x) { HRESULT __result_ = (x); if (__result_ != S_OK) return __result_; } | ||
11 | #endif | ||
12 | |||
13 | template <class T> | 9 | template <class T> |
14 | class CMyComPtr | 10 | class CMyComPtr |
15 | { | 11 | { |
@@ -72,6 +68,10 @@ public: | |||
72 | } | 68 | } |
73 | }; | 69 | }; |
74 | 70 | ||
71 | #define Z7_DECL_CMyComPtr_QI_FROM(i, v, unk) \ | ||
72 | CMyComPtr<i> v; (unk)->QueryInterface(IID_ ## i, (void **)&v); | ||
73 | |||
74 | |||
75 | ////////////////////////////////////////////////////////// | 75 | ////////////////////////////////////////////////////////// |
76 | 76 | ||
77 | inline HRESULT StringToBstr(LPCOLESTR src, BSTR *bstr) | 77 | inline HRESULT StringToBstr(LPCOLESTR src, BSTR *bstr) |
@@ -83,7 +83,7 @@ inline HRESULT StringToBstr(LPCOLESTR src, BSTR *bstr) | |||
83 | class CMyComBSTR | 83 | class CMyComBSTR |
84 | { | 84 | { |
85 | BSTR m_str; | 85 | BSTR m_str; |
86 | CLASS_NO_COPY(CMyComBSTR) | 86 | Z7_CLASS_NO_COPY(CMyComBSTR) |
87 | public: | 87 | public: |
88 | CMyComBSTR(): m_str(NULL) {} | 88 | CMyComBSTR(): m_str(NULL) {} |
89 | ~CMyComBSTR() { ::SysFreeString(m_str); } | 89 | ~CMyComBSTR() { ::SysFreeString(m_str); } |
@@ -174,7 +174,7 @@ private: | |||
174 | 174 | ||
175 | class CMyComBSTR_Wipe: public CMyComBSTR | 175 | class CMyComBSTR_Wipe: public CMyComBSTR |
176 | { | 176 | { |
177 | CLASS_NO_COPY(CMyComBSTR_Wipe) | 177 | Z7_CLASS_NO_COPY(CMyComBSTR_Wipe) |
178 | public: | 178 | public: |
179 | CMyComBSTR_Wipe(): CMyComBSTR() {} | 179 | CMyComBSTR_Wipe(): CMyComBSTR() {} |
180 | ~CMyComBSTR_Wipe() { Wipe_and_Free(); } | 180 | ~CMyComBSTR_Wipe() { Wipe_and_Free(); } |
@@ -185,123 +185,325 @@ public: | |||
185 | /* | 185 | /* |
186 | If CMyUnknownImp doesn't use virtual destructor, the code size is smaller. | 186 | If CMyUnknownImp doesn't use virtual destructor, the code size is smaller. |
187 | But if some class_1 derived from CMyUnknownImp | 187 | But if some class_1 derived from CMyUnknownImp |
188 | uses MY_ADDREF_RELEASE and IUnknown::Release() | 188 | uses Z7_COM_ADDREF_RELEASE and IUnknown::Release() |
189 | and some another class_2 is derived from class_1, | 189 | and some another class_2 is derived from class_1, |
190 | then class_1 must use virtual destructor: | 190 | then class_1 must use virtual destructor: |
191 | virtual ~class_1(); | 191 | virtual ~class_1(); |
192 | In that case, class_1::Release() calls correct destructor of class_2. | 192 | In that case, class_1::Release() calls correct destructor of class_2. |
193 | 193 | We can use virtual ~CMyUnknownImp() to disable warning | |
194 | We use virtual ~CMyUnknownImp() to disable warning | ||
195 | "class has virtual functions, but destructor is not virtual". | 194 | "class has virtual functions, but destructor is not virtual". |
196 | 195 | Also we can use virtual ~IUnknown() {} in MyWindows.h | |
197 | also we can use virtual ~IUnknown() {} in MyWindows.h | ||
198 | */ | 196 | */ |
199 | 197 | ||
200 | class CMyUnknownImp | 198 | class CMyUnknownImp |
201 | { | 199 | { |
202 | CLASS_NO_COPY(CMyUnknownImp) | 200 | Z7_CLASS_NO_COPY(CMyUnknownImp) |
203 | public: | 201 | protected: |
204 | ULONG __m_RefCount; | 202 | ULONG _m_RefCount; |
205 | CMyUnknownImp(): __m_RefCount(0) {} | 203 | CMyUnknownImp(): _m_RefCount(0) {} |
206 | 204 | ||
207 | #ifdef _WIN32 | 205 | #ifdef _WIN32 |
208 | #if defined(__GNUC__) || defined(__clang__) | 206 | #if defined(__GNUC__) || defined(__clang__) |
209 | virtual // to disable GCC/CLANG varnings | 207 | // virtual ~CMyUnknownImp() {} // to disable GCC/CLANG varnings |
210 | #endif | 208 | #endif |
211 | #endif | 209 | #endif |
212 | ~CMyUnknownImp() {} | ||
213 | }; | 210 | }; |
214 | 211 | ||
215 | 212 | ||
216 | 213 | ||
217 | #define MY_QUERYINTERFACE_BEGIN STDMETHOD(QueryInterface) \ | 214 | #define Z7_COM_QI_BEGIN \ |
218 | (REFGUID iid, void **outObject) throw() { *outObject = NULL; | 215 | private: STDMETHOD(QueryInterface) (REFGUID iid, void **outObject) throw() Z7_override Z7_final \ |
216 | { *outObject = NULL; | ||
217 | |||
218 | #define Z7_COM_QI_ENTRY(i) \ | ||
219 | else if (iid == IID_ ## i) \ | ||
220 | { i *ti = this; *outObject = ti; } | ||
221 | // { *outObject = (void *)(i *)this; } | ||
219 | 222 | ||
220 | #define MY_QUERYINTERFACE_ENTRY(i) else if (iid == IID_ ## i) \ | 223 | #define Z7_COM_QI_ENTRY_UNKNOWN_0 \ |
221 | { *outObject = (void *)(i *)this; } | 224 | if (iid == IID_IUnknown) \ |
225 | { IUnknown *tu = this; *outObject = tu; } | ||
222 | 226 | ||
223 | #define MY_QUERYINTERFACE_ENTRY_UNKNOWN(i) if (iid == IID_IUnknown) \ | 227 | #define Z7_COM_QI_ENTRY_UNKNOWN(i) \ |
224 | { *outObject = (void *)(IUnknown *)(i *)this; } | 228 | if (iid == IID_IUnknown) \ |
229 | { i *ti = this; IUnknown *tu = ti; *outObject = tu; } | ||
230 | // { *outObject = (void *)(IUnknown *)(i *)this; } | ||
225 | 231 | ||
226 | #define MY_QUERYINTERFACE_BEGIN2(i) MY_QUERYINTERFACE_BEGIN \ | 232 | #define Z7_COM_QI_BEGIN2(i) \ |
227 | MY_QUERYINTERFACE_ENTRY_UNKNOWN(i) \ | 233 | Z7_COM_QI_BEGIN \ |
228 | MY_QUERYINTERFACE_ENTRY(i) | 234 | Z7_COM_QI_ENTRY_UNKNOWN(i) \ |
235 | Z7_COM_QI_ENTRY(i) | ||
229 | 236 | ||
230 | #define MY_QUERYINTERFACE_END else return E_NOINTERFACE; ++__m_RefCount; /* AddRef(); */ return S_OK; } | 237 | #define Z7_COM_QI_END \ |
238 | else return E_NOINTERFACE; \ | ||
239 | ++_m_RefCount; /* AddRef(); */ return S_OK; } | ||
231 | 240 | ||
232 | #define MY_ADDREF_RELEASE \ | 241 | #define Z7_COM_ADDREF_RELEASE \ |
233 | STDMETHOD_(ULONG, AddRef)() throw() { return ++__m_RefCount; } \ | 242 | private: \ |
234 | STDMETHOD_(ULONG, Release)() { if (--__m_RefCount != 0) return __m_RefCount; \ | 243 | STDMETHOD_(ULONG, AddRef)() throw() Z7_override Z7_final \ |
235 | delete this; return 0; } | 244 | { return ++_m_RefCount; } \ |
245 | STDMETHOD_(ULONG, Release)() throw() Z7_override Z7_final \ | ||
246 | { if (--_m_RefCount != 0) return _m_RefCount; delete this; return 0; } \ | ||
236 | 247 | ||
237 | #define MY_UNKNOWN_IMP_SPEC(i) \ | 248 | #define Z7_COM_UNKNOWN_IMP_SPEC(i) \ |
238 | MY_QUERYINTERFACE_BEGIN \ | 249 | Z7_COM_QI_BEGIN \ |
239 | i \ | 250 | i \ |
240 | MY_QUERYINTERFACE_END \ | 251 | Z7_COM_QI_END \ |
241 | MY_ADDREF_RELEASE | 252 | Z7_COM_ADDREF_RELEASE |
242 | 253 | ||
243 | 254 | ||
244 | #define MY_UNKNOWN_IMP MY_QUERYINTERFACE_BEGIN \ | 255 | #define Z7_COM_UNKNOWN_IMP_0 \ |
245 | MY_QUERYINTERFACE_ENTRY_UNKNOWN(IUnknown) \ | 256 | Z7_COM_QI_BEGIN \ |
246 | MY_QUERYINTERFACE_END \ | 257 | Z7_COM_QI_ENTRY_UNKNOWN_0 \ |
247 | MY_ADDREF_RELEASE | 258 | Z7_COM_QI_END \ |
259 | Z7_COM_ADDREF_RELEASE | ||
248 | 260 | ||
249 | #define MY_UNKNOWN_IMP1(i) MY_UNKNOWN_IMP_SPEC( \ | 261 | #define Z7_COM_UNKNOWN_IMP_1(i) \ |
250 | MY_QUERYINTERFACE_ENTRY_UNKNOWN(i) \ | 262 | Z7_COM_UNKNOWN_IMP_SPEC( \ |
251 | MY_QUERYINTERFACE_ENTRY(i) \ | 263 | Z7_COM_QI_ENTRY_UNKNOWN(i) \ |
264 | Z7_COM_QI_ENTRY(i) \ | ||
252 | ) | 265 | ) |
253 | 266 | ||
254 | #define MY_UNKNOWN_IMP2(i1, i2) MY_UNKNOWN_IMP_SPEC( \ | 267 | #define Z7_COM_UNKNOWN_IMP_2(i1, i2) \ |
255 | MY_QUERYINTERFACE_ENTRY_UNKNOWN(i1) \ | 268 | Z7_COM_UNKNOWN_IMP_SPEC( \ |
256 | MY_QUERYINTERFACE_ENTRY(i1) \ | 269 | Z7_COM_QI_ENTRY_UNKNOWN(i1) \ |
257 | MY_QUERYINTERFACE_ENTRY(i2) \ | 270 | Z7_COM_QI_ENTRY(i1) \ |
271 | Z7_COM_QI_ENTRY(i2) \ | ||
258 | ) | 272 | ) |
259 | 273 | ||
260 | #define MY_UNKNOWN_IMP3(i1, i2, i3) MY_UNKNOWN_IMP_SPEC( \ | 274 | #define Z7_COM_UNKNOWN_IMP_3(i1, i2, i3) \ |
261 | MY_QUERYINTERFACE_ENTRY_UNKNOWN(i1) \ | 275 | Z7_COM_UNKNOWN_IMP_SPEC( \ |
262 | MY_QUERYINTERFACE_ENTRY(i1) \ | 276 | Z7_COM_QI_ENTRY_UNKNOWN(i1) \ |
263 | MY_QUERYINTERFACE_ENTRY(i2) \ | 277 | Z7_COM_QI_ENTRY(i1) \ |
264 | MY_QUERYINTERFACE_ENTRY(i3) \ | 278 | Z7_COM_QI_ENTRY(i2) \ |
279 | Z7_COM_QI_ENTRY(i3) \ | ||
265 | ) | 280 | ) |
266 | 281 | ||
267 | #define MY_UNKNOWN_IMP4(i1, i2, i3, i4) MY_UNKNOWN_IMP_SPEC( \ | 282 | #define Z7_COM_UNKNOWN_IMP_4(i1, i2, i3, i4) \ |
268 | MY_QUERYINTERFACE_ENTRY_UNKNOWN(i1) \ | 283 | Z7_COM_UNKNOWN_IMP_SPEC( \ |
269 | MY_QUERYINTERFACE_ENTRY(i1) \ | 284 | Z7_COM_QI_ENTRY_UNKNOWN(i1) \ |
270 | MY_QUERYINTERFACE_ENTRY(i2) \ | 285 | Z7_COM_QI_ENTRY(i1) \ |
271 | MY_QUERYINTERFACE_ENTRY(i3) \ | 286 | Z7_COM_QI_ENTRY(i2) \ |
272 | MY_QUERYINTERFACE_ENTRY(i4) \ | 287 | Z7_COM_QI_ENTRY(i3) \ |
288 | Z7_COM_QI_ENTRY(i4) \ | ||
273 | ) | 289 | ) |
274 | 290 | ||
275 | #define MY_UNKNOWN_IMP5(i1, i2, i3, i4, i5) MY_UNKNOWN_IMP_SPEC( \ | 291 | #define Z7_COM_UNKNOWN_IMP_5(i1, i2, i3, i4, i5) \ |
276 | MY_QUERYINTERFACE_ENTRY_UNKNOWN(i1) \ | 292 | Z7_COM_UNKNOWN_IMP_SPEC( \ |
277 | MY_QUERYINTERFACE_ENTRY(i1) \ | 293 | Z7_COM_QI_ENTRY_UNKNOWN(i1) \ |
278 | MY_QUERYINTERFACE_ENTRY(i2) \ | 294 | Z7_COM_QI_ENTRY(i1) \ |
279 | MY_QUERYINTERFACE_ENTRY(i3) \ | 295 | Z7_COM_QI_ENTRY(i2) \ |
280 | MY_QUERYINTERFACE_ENTRY(i4) \ | 296 | Z7_COM_QI_ENTRY(i3) \ |
281 | MY_QUERYINTERFACE_ENTRY(i5) \ | 297 | Z7_COM_QI_ENTRY(i4) \ |
298 | Z7_COM_QI_ENTRY(i5) \ | ||
282 | ) | 299 | ) |
283 | 300 | ||
284 | #define MY_UNKNOWN_IMP6(i1, i2, i3, i4, i5, i6) MY_UNKNOWN_IMP_SPEC( \ | 301 | #define Z7_COM_UNKNOWN_IMP_6(i1, i2, i3, i4, i5, i6) \ |
285 | MY_QUERYINTERFACE_ENTRY_UNKNOWN(i1) \ | 302 | Z7_COM_UNKNOWN_IMP_SPEC( \ |
286 | MY_QUERYINTERFACE_ENTRY(i1) \ | 303 | Z7_COM_QI_ENTRY_UNKNOWN(i1) \ |
287 | MY_QUERYINTERFACE_ENTRY(i2) \ | 304 | Z7_COM_QI_ENTRY(i1) \ |
288 | MY_QUERYINTERFACE_ENTRY(i3) \ | 305 | Z7_COM_QI_ENTRY(i2) \ |
289 | MY_QUERYINTERFACE_ENTRY(i4) \ | 306 | Z7_COM_QI_ENTRY(i3) \ |
290 | MY_QUERYINTERFACE_ENTRY(i5) \ | 307 | Z7_COM_QI_ENTRY(i4) \ |
291 | MY_QUERYINTERFACE_ENTRY(i6) \ | 308 | Z7_COM_QI_ENTRY(i5) \ |
309 | Z7_COM_QI_ENTRY(i6) \ | ||
292 | ) | 310 | ) |
293 | 311 | ||
294 | #define MY_UNKNOWN_IMP7(i1, i2, i3, i4, i5, i6, i7) MY_UNKNOWN_IMP_SPEC( \ | 312 | #define Z7_COM_UNKNOWN_IMP_7(i1, i2, i3, i4, i5, i6, i7) \ |
295 | MY_QUERYINTERFACE_ENTRY_UNKNOWN(i1) \ | 313 | Z7_COM_UNKNOWN_IMP_SPEC( \ |
296 | MY_QUERYINTERFACE_ENTRY(i1) \ | 314 | Z7_COM_QI_ENTRY_UNKNOWN(i1) \ |
297 | MY_QUERYINTERFACE_ENTRY(i2) \ | 315 | Z7_COM_QI_ENTRY(i1) \ |
298 | MY_QUERYINTERFACE_ENTRY(i3) \ | 316 | Z7_COM_QI_ENTRY(i2) \ |
299 | MY_QUERYINTERFACE_ENTRY(i4) \ | 317 | Z7_COM_QI_ENTRY(i3) \ |
300 | MY_QUERYINTERFACE_ENTRY(i5) \ | 318 | Z7_COM_QI_ENTRY(i4) \ |
301 | MY_QUERYINTERFACE_ENTRY(i6) \ | 319 | Z7_COM_QI_ENTRY(i5) \ |
302 | MY_QUERYINTERFACE_ENTRY(i7) \ | 320 | Z7_COM_QI_ENTRY(i6) \ |
321 | Z7_COM_QI_ENTRY(i7) \ | ||
303 | ) | 322 | ) |
304 | 323 | ||
305 | const HRESULT k_My_HRESULT_WritingWasCut = 0x20000010; | 324 | |
325 | #define Z7_IFACES_IMP_UNK_1(i1) \ | ||
326 | Z7_COM_UNKNOWN_IMP_1(i1) \ | ||
327 | Z7_IFACE_COM7_IMP(i1) \ | ||
328 | |||
329 | #define Z7_IFACES_IMP_UNK_2(i1, i2) \ | ||
330 | Z7_COM_UNKNOWN_IMP_2(i1, i2) \ | ||
331 | Z7_IFACE_COM7_IMP(i1) \ | ||
332 | Z7_IFACE_COM7_IMP(i2) \ | ||
333 | |||
334 | #define Z7_IFACES_IMP_UNK_3(i1, i2, i3) \ | ||
335 | Z7_COM_UNKNOWN_IMP_3(i1, i2, i3) \ | ||
336 | Z7_IFACE_COM7_IMP(i1) \ | ||
337 | Z7_IFACE_COM7_IMP(i2) \ | ||
338 | Z7_IFACE_COM7_IMP(i3) \ | ||
339 | |||
340 | #define Z7_IFACES_IMP_UNK_4(i1, i2, i3, i4) \ | ||
341 | Z7_COM_UNKNOWN_IMP_4(i1, i2, i3, i4) \ | ||
342 | Z7_IFACE_COM7_IMP(i1) \ | ||
343 | Z7_IFACE_COM7_IMP(i2) \ | ||
344 | Z7_IFACE_COM7_IMP(i3) \ | ||
345 | Z7_IFACE_COM7_IMP(i4) \ | ||
346 | |||
347 | #define Z7_IFACES_IMP_UNK_5(i1, i2, i3, i4, i5) \ | ||
348 | Z7_COM_UNKNOWN_IMP_5(i1, i2, i3, i4, i5) \ | ||
349 | Z7_IFACE_COM7_IMP(i1) \ | ||
350 | Z7_IFACE_COM7_IMP(i2) \ | ||
351 | Z7_IFACE_COM7_IMP(i3) \ | ||
352 | Z7_IFACE_COM7_IMP(i4) \ | ||
353 | Z7_IFACE_COM7_IMP(i5) \ | ||
354 | |||
355 | #define Z7_IFACES_IMP_UNK_6(i1, i2, i3, i4, i5, i6) \ | ||
356 | Z7_COM_UNKNOWN_IMP_6(i1, i2, i3, i4, i5, i6) \ | ||
357 | Z7_IFACE_COM7_IMP(i1) \ | ||
358 | Z7_IFACE_COM7_IMP(i2) \ | ||
359 | Z7_IFACE_COM7_IMP(i3) \ | ||
360 | Z7_IFACE_COM7_IMP(i4) \ | ||
361 | Z7_IFACE_COM7_IMP(i5) \ | ||
362 | Z7_IFACE_COM7_IMP(i6) \ | ||
363 | |||
364 | |||
365 | #define Z7_CLASS_IMP_COM_0(c) \ | ||
366 | Z7_class_final(c) : \ | ||
367 | public IUnknown, \ | ||
368 | public CMyUnknownImp { \ | ||
369 | Z7_COM_UNKNOWN_IMP_0 \ | ||
370 | private: | ||
371 | |||
372 | #define Z7_CLASS_IMP_COM_1(c, i1) \ | ||
373 | Z7_class_final(c) : \ | ||
374 | public i1, \ | ||
375 | public CMyUnknownImp { \ | ||
376 | Z7_IFACES_IMP_UNK_1(i1) \ | ||
377 | private: | ||
378 | |||
379 | #define Z7_CLASS_IMP_COM_2(c, i1, i2) \ | ||
380 | Z7_class_final(c) : \ | ||
381 | public i1, \ | ||
382 | public i2, \ | ||
383 | public CMyUnknownImp { \ | ||
384 | Z7_IFACES_IMP_UNK_2(i1, i2) \ | ||
385 | private: | ||
386 | |||
387 | #define Z7_CLASS_IMP_COM_3(c, i1, i2, i3) \ | ||
388 | Z7_class_final(c) : \ | ||
389 | public i1, \ | ||
390 | public i2, \ | ||
391 | public i3, \ | ||
392 | public CMyUnknownImp { \ | ||
393 | Z7_IFACES_IMP_UNK_3(i1, i2, i3) \ | ||
394 | private: | ||
395 | |||
396 | #define Z7_CLASS_IMP_COM_4(c, i1, i2, i3, i4) \ | ||
397 | Z7_class_final(c) : \ | ||
398 | public i1, \ | ||
399 | public i2, \ | ||
400 | public i3, \ | ||
401 | public i4, \ | ||
402 | public CMyUnknownImp { \ | ||
403 | Z7_IFACES_IMP_UNK_4(i1, i2, i3, i4) \ | ||
404 | private: | ||
405 | |||
406 | #define Z7_CLASS_IMP_COM_5(c, i1, i2, i3, i4, i5) \ | ||
407 | Z7_class_final(c) : \ | ||
408 | public i1, \ | ||
409 | public i2, \ | ||
410 | public i3, \ | ||
411 | public i4, \ | ||
412 | public i5, \ | ||
413 | public CMyUnknownImp { \ | ||
414 | Z7_IFACES_IMP_UNK_5(i1, i2, i3, i4, i5) \ | ||
415 | private: | ||
416 | |||
417 | #define Z7_CLASS_IMP_COM_6(c, i1, i2, i3, i4, i5, i6) \ | ||
418 | Z7_class_final(c) : \ | ||
419 | public i1, \ | ||
420 | public i2, \ | ||
421 | public i3, \ | ||
422 | public i4, \ | ||
423 | public i5, \ | ||
424 | public i6, \ | ||
425 | public CMyUnknownImp { \ | ||
426 | Z7_IFACES_IMP_UNK_6(i1, i2, i3, i4, i5, i6) \ | ||
427 | private: | ||
428 | |||
429 | |||
430 | /* | ||
431 | #define Z7_CLASS_IMP_NOQIB_0(c) \ | ||
432 | Z7_class_final(c) : \ | ||
433 | public IUnknown, \ | ||
434 | public CMyUnknownImp { \ | ||
435 | Z7_COM_UNKNOWN_IMP_0 \ | ||
436 | private: | ||
437 | */ | ||
438 | |||
439 | #define Z7_CLASS_IMP_NOQIB_1(c, i1) \ | ||
440 | Z7_class_final(c) : \ | ||
441 | public i1, \ | ||
442 | public CMyUnknownImp { \ | ||
443 | Z7_COM_UNKNOWN_IMP_0 \ | ||
444 | Z7_IFACE_COM7_IMP(i1) \ | ||
445 | private: | ||
446 | |||
447 | #define Z7_CLASS_IMP_NOQIB_2(c, i1, i2) \ | ||
448 | Z7_class_final(c) : \ | ||
449 | public i1, \ | ||
450 | public i2, \ | ||
451 | public CMyUnknownImp { \ | ||
452 | Z7_COM_UNKNOWN_IMP_1(i2) \ | ||
453 | Z7_IFACE_COM7_IMP(i1) \ | ||
454 | Z7_IFACE_COM7_IMP(i2) \ | ||
455 | private: | ||
456 | |||
457 | #define Z7_CLASS_IMP_NOQIB_3(c, i1, i2, i3) \ | ||
458 | Z7_class_final(c) : \ | ||
459 | public i1, \ | ||
460 | public i2, \ | ||
461 | public i3, \ | ||
462 | public CMyUnknownImp { \ | ||
463 | Z7_COM_UNKNOWN_IMP_2(i2, i3) \ | ||
464 | Z7_IFACE_COM7_IMP(i1) \ | ||
465 | Z7_IFACE_COM7_IMP(i2) \ | ||
466 | Z7_IFACE_COM7_IMP(i3) \ | ||
467 | private: | ||
468 | |||
469 | #define Z7_CLASS_IMP_NOQIB_4(c, i1, i2, i3, i4) \ | ||
470 | Z7_class_final(c) : \ | ||
471 | public i1, \ | ||
472 | public i2, \ | ||
473 | public i3, \ | ||
474 | public i4, \ | ||
475 | public CMyUnknownImp { \ | ||
476 | Z7_COM_UNKNOWN_IMP_3(i2, i3, i4) \ | ||
477 | Z7_IFACE_COM7_IMP(i1) \ | ||
478 | Z7_IFACE_COM7_IMP(i2) \ | ||
479 | Z7_IFACE_COM7_IMP(i3) \ | ||
480 | Z7_IFACE_COM7_IMP(i4) \ | ||
481 | |||
482 | /* | ||
483 | #define Z7_CLASS_IMP_NOQIB_5(c, i1, i2, i3, i4, i5) \ | ||
484 | Z7_class_final(c) : \ | ||
485 | public i1, \ | ||
486 | public i2, \ | ||
487 | public i3, \ | ||
488 | public i4, \ | ||
489 | public i5, \ | ||
490 | public CMyUnknownImp { \ | ||
491 | Z7_COM_UNKNOWN_IMP_4(i2, i3, i4, i5) \ | ||
492 | Z7_IFACE_COM7_IMP(i1) \ | ||
493 | Z7_IFACE_COM7_IMP(i2) \ | ||
494 | Z7_IFACE_COM7_IMP(i3) \ | ||
495 | Z7_IFACE_COM7_IMP(i4) \ | ||
496 | Z7_IFACE_COM7_IMP(i5) \ | ||
497 | */ | ||
498 | |||
499 | |||
500 | #define Z7_CLASS_IMP_IInStream(c) \ | ||
501 | class c Z7_final : \ | ||
502 | public IInStream, \ | ||
503 | public CMyUnknownImp { \ | ||
504 | Z7_IFACES_IMP_UNK_2(ISequentialInStream, IInStream) \ | ||
505 | |||
506 | |||
507 | #define k_My_HRESULT_WritingWasCut 0x20000010 | ||
306 | 508 | ||
307 | #endif | 509 | #endif |
diff --git a/CPP/Common/MyException.h b/CPP/Common/MyException.h index f0ad111..06fbdea 100644 --- a/CPP/Common/MyException.h +++ b/CPP/Common/MyException.h | |||
@@ -1,7 +1,7 @@ | |||
1 | // Common/Exception.h | 1 | // Common/Exception.h |
2 | 2 | ||
3 | #ifndef __COMMON_EXCEPTION_H | 3 | #ifndef ZIP7_INC_COMMON_EXCEPTION_H |
4 | #define __COMMON_EXCEPTION_H | 4 | #define ZIP7_INC_COMMON_EXCEPTION_H |
5 | 5 | ||
6 | #include "MyWindows.h" | 6 | #include "MyWindows.h" |
7 | 7 | ||
diff --git a/CPP/Common/MyGuidDef.h b/CPP/Common/MyGuidDef.h index 38aad6e..ab9993b 100644 --- a/CPP/Common/MyGuidDef.h +++ b/CPP/Common/MyGuidDef.h | |||
@@ -1,8 +1,12 @@ | |||
1 | // Common/MyGuidDef.h | 1 | // Common/MyGuidDef.h |
2 | 2 | ||
3 | // #pragma message "Common/MyGuidDef.h" | ||
4 | |||
3 | #ifndef GUID_DEFINED | 5 | #ifndef GUID_DEFINED |
4 | #define GUID_DEFINED | 6 | #define GUID_DEFINED |
5 | 7 | ||
8 | // #pragma message "GUID_DEFINED" | ||
9 | |||
6 | #include "MyTypes.h" | 10 | #include "MyTypes.h" |
7 | 11 | ||
8 | typedef struct { | 12 | typedef struct { |
@@ -27,31 +31,33 @@ typedef GUID CLSID; | |||
27 | #ifdef __cplusplus | 31 | #ifdef __cplusplus |
28 | inline int operator==(REFGUID g1, REFGUID g2) | 32 | inline int operator==(REFGUID g1, REFGUID g2) |
29 | { | 33 | { |
30 | for (int i = 0; i < (int)sizeof(g1); i++) | 34 | for (unsigned i = 0; i < sizeof(g1); i++) |
31 | if (((unsigned char *)&g1)[i] != ((unsigned char *)&g2)[i]) | 35 | if (((const unsigned char *)&g1)[i] != ((const unsigned char *)&g2)[i]) |
32 | return 0; | 36 | return 0; |
33 | return 1; | 37 | return 1; |
34 | } | 38 | } |
35 | inline int operator!=(REFGUID g1, REFGUID g2) { return !(g1 == g2); } | 39 | inline int operator!=(REFGUID g1, REFGUID g2) { return !(g1 == g2); } |
36 | #endif | 40 | #endif |
37 | 41 | ||
42 | #endif // GUID_DEFINED | ||
43 | |||
44 | #ifndef EXTERN_C | ||
38 | #ifdef __cplusplus | 45 | #ifdef __cplusplus |
39 | #define MY_EXTERN_C extern "C" | 46 | #define EXTERN_C extern "C" |
40 | #else | 47 | #else |
41 | #define MY_EXTERN_C extern | 48 | #define EXTERN_C extern |
42 | #endif | 49 | #endif |
43 | |||
44 | #endif | 50 | #endif |
45 | 51 | ||
46 | |||
47 | #ifdef DEFINE_GUID | 52 | #ifdef DEFINE_GUID |
48 | #undef DEFINE_GUID | 53 | #undef DEFINE_GUID |
49 | #endif | 54 | #endif |
50 | 55 | ||
51 | #ifdef INITGUID | 56 | #ifdef INITGUID |
52 | #define DEFINE_GUID(name, l, w1, w2, b1, b2, b3, b4, b5, b6, b7, b8) \ | 57 | #define DEFINE_GUID(name, l, w1, w2, b1, b2, b3, b4, b5, b6, b7, b8) \ |
53 | MY_EXTERN_C const GUID name = { l, w1, w2, { b1, b2, b3, b4, b5, b6, b7, b8 } } | 58 | EXTERN_C const GUID name; \ |
59 | EXTERN_C const GUID name = { l, w1, w2, { b1, b2, b3, b4, b5, b6, b7, b8 } } | ||
54 | #else | 60 | #else |
55 | #define DEFINE_GUID(name, l, w1, w2, b1, b2, b3, b4, b5, b6, b7, b8) \ | 61 | #define DEFINE_GUID(name, l, w1, w2, b1, b2, b3, b4, b5, b6, b7, b8) \ |
56 | MY_EXTERN_C const GUID name | 62 | EXTERN_C const GUID name |
57 | #endif | 63 | #endif |
diff --git a/CPP/Common/MyInitGuid.h b/CPP/Common/MyInitGuid.h index 04d77e2..3745c79 100644 --- a/CPP/Common/MyInitGuid.h +++ b/CPP/Common/MyInitGuid.h | |||
@@ -1,7 +1,7 @@ | |||
1 | // Common/MyInitGuid.h | 1 | // Common/MyInitGuid.h |
2 | 2 | ||
3 | #ifndef __COMMON_MY_INITGUID_H | 3 | #ifndef ZIP7_INC_COMMON_MY_INITGUID_H |
4 | #define __COMMON_MY_INITGUID_H | 4 | #define ZIP7_INC_COMMON_MY_INITGUID_H |
5 | 5 | ||
6 | /* | 6 | /* |
7 | This file must be included only to one C++ file in project before | 7 | This file must be included only to one C++ file in project before |
@@ -19,31 +19,39 @@ Also we need IID_IUnknown that is initialized in some file for linking: | |||
19 | Other: we define IID_IUnknown in this file | 19 | Other: we define IID_IUnknown in this file |
20 | */ | 20 | */ |
21 | 21 | ||
22 | #ifdef __clang__ | 22 | // #include "Common.h" |
23 | #pragma clang diagnostic ignored "-Wmissing-variable-declarations" | 23 | /* vc6 without sdk needs <objbase.h> before <initguid.h>, |
24 | #endif | 24 | but it doesn't work in new msvc. |
25 | So we include full "MyWindows.h" instead of <objbase.h> */ | ||
26 | // #include <objbase.h> | ||
27 | #include "MyWindows.h" | ||
25 | 28 | ||
26 | #ifdef _WIN32 | 29 | #ifdef _WIN32 |
27 | 30 | ||
31 | #ifdef __clang__ | ||
32 | // #pragma GCC diagnostic ignored "-Wmissing-variable-declarations" | ||
33 | #endif | ||
34 | |||
28 | #ifdef UNDER_CE | 35 | #ifdef UNDER_CE |
29 | #include <basetyps.h> | 36 | #include <basetyps.h> |
30 | #endif | 37 | #endif |
31 | 38 | ||
32 | #include <InitGuid.h> | 39 | // for vc6 without sdk we must define INITGUID here |
40 | #define INITGUID | ||
41 | #include <initguid.h> | ||
33 | 42 | ||
34 | #ifdef UNDER_CE | 43 | #ifdef UNDER_CE |
35 | DEFINE_GUID(IID_IUnknown, | 44 | DEFINE_GUID(IID_IUnknown, |
36 | 0x00000000, 0x0000, 0x0000, 0xC0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x46); | 45 | 0x00000000, 0x0000, 0x0000, 0xC0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x46); |
37 | #endif | 46 | #endif |
38 | 47 | ||
39 | #else | 48 | #else // _WIN32 |
40 | 49 | ||
41 | #define INITGUID | 50 | #define INITGUID |
42 | #include "MyGuidDef.h" | 51 | #include "MyGuidDef.h" |
43 | DEFINE_GUID(IID_IUnknown, | 52 | DEFINE_GUID(IID_IUnknown, |
44 | 0x00000000, 0x0000, 0x0000, 0xC0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x46); | 53 | 0x00000000, 0x0000, 0x0000, 0xC0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x46); |
45 | 54 | ||
46 | #endif | 55 | #endif // _WIN32 |
47 | |||
48 | 56 | ||
49 | #endif | 57 | #endif |
diff --git a/CPP/Common/MyLinux.h b/CPP/Common/MyLinux.h index 98b453c..a8454d7 100644 --- a/CPP/Common/MyLinux.h +++ b/CPP/Common/MyLinux.h | |||
@@ -1,7 +1,7 @@ | |||
1 | // MyLinux.h | 1 | // MyLinux.h |
2 | 2 | ||
3 | #ifndef __MY_LIN_LINUX_H | 3 | #ifndef ZIP7_INC_COMMON_MY_LINUX_H |
4 | #define __MY_LIN_LINUX_H | 4 | #define ZIP7_INC_COMMON_MY_LINUX_H |
5 | 5 | ||
6 | // #include "../../C/7zTypes.h" | 6 | // #include "../../C/7zTypes.h" |
7 | 7 | ||
diff --git a/CPP/Common/MyMap.cpp b/CPP/Common/MyMap.cpp index 923846a..0a200f0 100644 --- a/CPP/Common/MyMap.cpp +++ b/CPP/Common/MyMap.cpp | |||
@@ -76,7 +76,7 @@ bool CMap32::Set(UInt32 key, UInt32 value) | |||
76 | unsigned i = kNumBitsMax - 1; | 76 | unsigned i = kNumBitsMax - 1; |
77 | for (; GetSubBit(key, i) == GetSubBit(n.Key, i); i--); | 77 | for (; GetSubBit(key, i) == GetSubBit(n.Key, i); i--); |
78 | n.Len = (UInt16)(kNumBitsMax - (1 + i)); | 78 | n.Len = (UInt16)(kNumBitsMax - (1 + i)); |
79 | unsigned newBit = GetSubBit(key, i); | 79 | const unsigned newBit = GetSubBit(key, i); |
80 | n.Values[newBit] = value; | 80 | n.Values[newBit] = value; |
81 | n.Keys[newBit] = key; | 81 | n.Keys[newBit] = key; |
82 | return false; | 82 | return false; |
@@ -91,7 +91,7 @@ bool CMap32::Set(UInt32 key, UInt32 value) | |||
91 | bitPos -= n.Len; | 91 | bitPos -= n.Len; |
92 | if (GetSubBits(key, bitPos, n.Len) != GetSubBits(n.Key, bitPos, n.Len)) | 92 | if (GetSubBits(key, bitPos, n.Len) != GetSubBits(n.Key, bitPos, n.Len)) |
93 | { | 93 | { |
94 | unsigned i = n.Len - 1; | 94 | unsigned i = (unsigned)n.Len - 1; |
95 | for (; GetSubBit(key, bitPos + i) == GetSubBit(n.Key, bitPos + i); i--); | 95 | for (; GetSubBit(key, bitPos + i) == GetSubBit(n.Key, bitPos + i); i--); |
96 | 96 | ||
97 | CNode e2(n); | 97 | CNode e2(n); |
@@ -107,7 +107,7 @@ bool CMap32::Set(UInt32 key, UInt32 value) | |||
107 | Nodes.Add(e2); | 107 | Nodes.Add(e2); |
108 | return false; | 108 | return false; |
109 | } | 109 | } |
110 | unsigned bit = GetSubBit(key, --bitPos); | 110 | const unsigned bit = GetSubBit(key, --bitPos); |
111 | 111 | ||
112 | if (n.IsLeaf[bit]) | 112 | if (n.IsLeaf[bit]) |
113 | { | 113 | { |
@@ -121,7 +121,7 @@ bool CMap32::Set(UInt32 key, UInt32 value) | |||
121 | 121 | ||
122 | CNode e2; | 122 | CNode e2; |
123 | 123 | ||
124 | unsigned newBit = GetSubBit(key, i); | 124 | const unsigned newBit = GetSubBit(key, i); |
125 | e2.Values[newBit] = value; | 125 | e2.Values[newBit] = value; |
126 | e2.Values[1 - newBit] = n.Values[bit]; | 126 | e2.Values[1 - newBit] = n.Values[bit]; |
127 | e2.IsLeaf[newBit] = e2.IsLeaf[1 - newBit] = 1; | 127 | e2.IsLeaf[newBit] = e2.IsLeaf[1 - newBit] = 1; |
diff --git a/CPP/Common/MyMap.h b/CPP/Common/MyMap.h index cbcbadd..9ca5566 100644 --- a/CPP/Common/MyMap.h +++ b/CPP/Common/MyMap.h | |||
@@ -1,7 +1,7 @@ | |||
1 | // MyMap.h | 1 | // MyMap.h |
2 | 2 | ||
3 | #ifndef __COMMON_MYMAP_H | 3 | #ifndef ZIP7_INC_COMMON_MY_MAP_H |
4 | #define __COMMON_MYMAP_H | 4 | #define ZIP7_INC_COMMON_MY_MAP_H |
5 | 5 | ||
6 | #include "MyTypes.h" | 6 | #include "MyTypes.h" |
7 | #include "MyVector.h" | 7 | #include "MyVector.h" |
diff --git a/CPP/Common/MyString.cpp b/CPP/Common/MyString.cpp index bf1638e..51c1c3b 100644 --- a/CPP/Common/MyString.cpp +++ b/CPP/Common/MyString.cpp | |||
@@ -408,7 +408,7 @@ void AString::ReAlloc(unsigned newLimit) | |||
408 | // MY_STRING_REALLOC(_chars, char, (size_t)newLimit + 1, (size_t)_len + 1); | 408 | // MY_STRING_REALLOC(_chars, char, (size_t)newLimit + 1, (size_t)_len + 1); |
409 | char *newBuf = MY_STRING_NEW_char((size_t)newLimit + 1); | 409 | char *newBuf = MY_STRING_NEW_char((size_t)newLimit + 1); |
410 | memcpy(newBuf, _chars, (size_t)_len + 1); | 410 | memcpy(newBuf, _chars, (size_t)_len + 1); |
411 | MY_STRING_DELETE(_chars); | 411 | MY_STRING_DELETE(_chars) |
412 | _chars = newBuf; | 412 | _chars = newBuf; |
413 | _limit = newLimit; | 413 | _limit = newLimit; |
414 | } | 414 | } |
@@ -419,9 +419,10 @@ void AString::ReAlloc2(unsigned newLimit) | |||
419 | // MY_STRING_REALLOC(_chars, char, (size_t)newLimit + 1, 0); | 419 | // MY_STRING_REALLOC(_chars, char, (size_t)newLimit + 1, 0); |
420 | char *newBuf = MY_STRING_NEW_char((size_t)newLimit + 1); | 420 | char *newBuf = MY_STRING_NEW_char((size_t)newLimit + 1); |
421 | newBuf[0] = 0; | 421 | newBuf[0] = 0; |
422 | MY_STRING_DELETE(_chars); | 422 | MY_STRING_DELETE(_chars) |
423 | _chars = newBuf; | 423 | _chars = newBuf; |
424 | _limit = newLimit; | 424 | _limit = newLimit; |
425 | _len = 0; | ||
425 | } | 426 | } |
426 | 427 | ||
427 | void AString::SetStartLen(unsigned len) | 428 | void AString::SetStartLen(unsigned len) |
@@ -541,7 +542,7 @@ AString &AString::operator=(char c) | |||
541 | if (1 > _limit) | 542 | if (1 > _limit) |
542 | { | 543 | { |
543 | char *newBuf = MY_STRING_NEW_char(1 + 1); | 544 | char *newBuf = MY_STRING_NEW_char(1 + 1); |
544 | MY_STRING_DELETE(_chars); | 545 | MY_STRING_DELETE(_chars) |
545 | _chars = newBuf; | 546 | _chars = newBuf; |
546 | _limit = 1; | 547 | _limit = 1; |
547 | } | 548 | } |
@@ -558,7 +559,7 @@ AString &AString::operator=(const char *s) | |||
558 | if (len > _limit) | 559 | if (len > _limit) |
559 | { | 560 | { |
560 | char *newBuf = MY_STRING_NEW_char((size_t)len + 1); | 561 | char *newBuf = MY_STRING_NEW_char((size_t)len + 1); |
561 | MY_STRING_DELETE(_chars); | 562 | MY_STRING_DELETE(_chars) |
562 | _chars = newBuf; | 563 | _chars = newBuf; |
563 | _limit = len; | 564 | _limit = len; |
564 | } | 565 | } |
@@ -575,7 +576,7 @@ AString &AString::operator=(const AString &s) | |||
575 | if (len > _limit) | 576 | if (len > _limit) |
576 | { | 577 | { |
577 | char *newBuf = MY_STRING_NEW_char((size_t)len + 1); | 578 | char *newBuf = MY_STRING_NEW_char((size_t)len + 1); |
578 | MY_STRING_DELETE(_chars); | 579 | MY_STRING_DELETE(_chars) |
579 | _chars = newBuf; | 580 | _chars = newBuf; |
580 | _limit = len; | 581 | _limit = len; |
581 | } | 582 | } |
@@ -600,7 +601,7 @@ void AString::SetFromWStr_if_Ascii(const wchar_t *s) | |||
600 | if (len > _limit) | 601 | if (len > _limit) |
601 | { | 602 | { |
602 | char *newBuf = MY_STRING_NEW_char((size_t)len + 1); | 603 | char *newBuf = MY_STRING_NEW_char((size_t)len + 1); |
603 | MY_STRING_DELETE(_chars); | 604 | MY_STRING_DELETE(_chars) |
604 | _chars = newBuf; | 605 | _chars = newBuf; |
605 | _limit = len; | 606 | _limit = len; |
606 | } | 607 | } |
@@ -624,7 +625,7 @@ void AString::SetFromBstr_if_Ascii(BSTR s) | |||
624 | if (len > _limit) | 625 | if (len > _limit) |
625 | { | 626 | { |
626 | char *newBuf = MY_STRING_NEW_char((size_t)len + 1); | 627 | char *newBuf = MY_STRING_NEW_char((size_t)len + 1); |
627 | MY_STRING_DELETE(_chars); | 628 | MY_STRING_DELETE(_chars) |
628 | _chars = newBuf; | 629 | _chars = newBuf; |
629 | _limit = len; | 630 | _limit = len; |
630 | } | 631 | } |
@@ -641,6 +642,8 @@ void AString::Add_Space() { operator+=(' '); } | |||
641 | void AString::Add_Space_if_NotEmpty() { if (!IsEmpty()) Add_Space(); } | 642 | void AString::Add_Space_if_NotEmpty() { if (!IsEmpty()) Add_Space(); } |
642 | void AString::Add_LF() { operator+=('\n'); } | 643 | void AString::Add_LF() { operator+=('\n'); } |
643 | void AString::Add_Slash() { operator+=('/'); } | 644 | void AString::Add_Slash() { operator+=('/'); } |
645 | void AString::Add_Dot() { operator+=('.'); } | ||
646 | void AString::Add_Minus() { operator+=('-'); } | ||
644 | 647 | ||
645 | AString &AString::operator+=(const char *s) | 648 | AString &AString::operator+=(const char *s) |
646 | { | 649 | { |
@@ -694,7 +697,7 @@ void AString::SetFrom(const char *s, unsigned len) // no check | |||
694 | if (len > _limit) | 697 | if (len > _limit) |
695 | { | 698 | { |
696 | char *newBuf = MY_STRING_NEW_char((size_t)len + 1); | 699 | char *newBuf = MY_STRING_NEW_char((size_t)len + 1); |
697 | MY_STRING_DELETE(_chars); | 700 | MY_STRING_DELETE(_chars) |
698 | _chars = newBuf; | 701 | _chars = newBuf; |
699 | _limit = len; | 702 | _limit = len; |
700 | } | 703 | } |
@@ -766,7 +769,7 @@ int AString::ReverseFind_PathSepar() const throw() | |||
766 | const char *p = _chars + _len - 1; | 769 | const char *p = _chars + _len - 1; |
767 | for (;;) | 770 | for (;;) |
768 | { | 771 | { |
769 | char c = *p; | 772 | const char c = *p; |
770 | if (IS_PATH_SEPAR(c)) | 773 | if (IS_PATH_SEPAR(c)) |
771 | return (int)(p - _chars); | 774 | return (int)(p - _chars); |
772 | if (p == _chars) | 775 | if (p == _chars) |
@@ -1001,7 +1004,7 @@ void UString::ReAlloc(unsigned newLimit) | |||
1001 | // MY_STRING_REALLOC(_chars, wchar_t, (size_t)newLimit + 1, (size_t)_len + 1); | 1004 | // MY_STRING_REALLOC(_chars, wchar_t, (size_t)newLimit + 1, (size_t)_len + 1); |
1002 | wchar_t *newBuf = MY_STRING_NEW_wchar_t((size_t)newLimit + 1); | 1005 | wchar_t *newBuf = MY_STRING_NEW_wchar_t((size_t)newLimit + 1); |
1003 | wmemcpy(newBuf, _chars, _len + 1); | 1006 | wmemcpy(newBuf, _chars, _len + 1); |
1004 | MY_STRING_DELETE(_chars); | 1007 | MY_STRING_DELETE(_chars) |
1005 | _chars = newBuf; | 1008 | _chars = newBuf; |
1006 | _limit = newLimit; | 1009 | _limit = newLimit; |
1007 | } | 1010 | } |
@@ -1012,14 +1015,15 @@ void UString::ReAlloc2(unsigned newLimit) | |||
1012 | // MY_STRING_REALLOC(_chars, wchar_t, newLimit + 1, 0); | 1015 | // MY_STRING_REALLOC(_chars, wchar_t, newLimit + 1, 0); |
1013 | wchar_t *newBuf = MY_STRING_NEW_wchar_t((size_t)newLimit + 1); | 1016 | wchar_t *newBuf = MY_STRING_NEW_wchar_t((size_t)newLimit + 1); |
1014 | newBuf[0] = 0; | 1017 | newBuf[0] = 0; |
1015 | MY_STRING_DELETE(_chars); | 1018 | MY_STRING_DELETE(_chars) |
1016 | _chars = newBuf; | 1019 | _chars = newBuf; |
1017 | _limit = newLimit; | 1020 | _limit = newLimit; |
1021 | _len = 0; | ||
1018 | } | 1022 | } |
1019 | 1023 | ||
1020 | void UString::SetStartLen(unsigned len) | 1024 | void UString::SetStartLen(unsigned len) |
1021 | { | 1025 | { |
1022 | _chars = 0; | 1026 | _chars = NULL; |
1023 | _chars = MY_STRING_NEW_wchar_t((size_t)len + 1); | 1027 | _chars = MY_STRING_NEW_wchar_t((size_t)len + 1); |
1024 | _len = len; | 1028 | _len = len; |
1025 | _limit = len; | 1029 | _limit = len; |
@@ -1101,7 +1105,7 @@ UString operator+(const wchar_t *s1, const UString &s2) { return UString(s1, MyS | |||
1101 | 1105 | ||
1102 | UString::UString() | 1106 | UString::UString() |
1103 | { | 1107 | { |
1104 | _chars = 0; | 1108 | _chars = NULL; |
1105 | _chars = MY_STRING_NEW_wchar_t(kStartStringCapacity); | 1109 | _chars = MY_STRING_NEW_wchar_t(kStartStringCapacity); |
1106 | _len = 0; | 1110 | _len = 0; |
1107 | _limit = kStartStringCapacity - 1; | 1111 | _limit = kStartStringCapacity - 1; |
@@ -1163,7 +1167,7 @@ UString &UString::operator=(wchar_t c) | |||
1163 | if (1 > _limit) | 1167 | if (1 > _limit) |
1164 | { | 1168 | { |
1165 | wchar_t *newBuf = MY_STRING_NEW_wchar_t(1 + 1); | 1169 | wchar_t *newBuf = MY_STRING_NEW_wchar_t(1 + 1); |
1166 | MY_STRING_DELETE(_chars); | 1170 | MY_STRING_DELETE(_chars) |
1167 | _chars = newBuf; | 1171 | _chars = newBuf; |
1168 | _limit = 1; | 1172 | _limit = 1; |
1169 | } | 1173 | } |
@@ -1180,7 +1184,7 @@ UString &UString::operator=(const wchar_t *s) | |||
1180 | if (len > _limit) | 1184 | if (len > _limit) |
1181 | { | 1185 | { |
1182 | wchar_t *newBuf = MY_STRING_NEW_wchar_t((size_t)len + 1); | 1186 | wchar_t *newBuf = MY_STRING_NEW_wchar_t((size_t)len + 1); |
1183 | MY_STRING_DELETE(_chars); | 1187 | MY_STRING_DELETE(_chars) |
1184 | _chars = newBuf; | 1188 | _chars = newBuf; |
1185 | _limit = len; | 1189 | _limit = len; |
1186 | } | 1190 | } |
@@ -1197,7 +1201,7 @@ UString &UString::operator=(const UString &s) | |||
1197 | if (len > _limit) | 1201 | if (len > _limit) |
1198 | { | 1202 | { |
1199 | wchar_t *newBuf = MY_STRING_NEW_wchar_t((size_t)len + 1); | 1203 | wchar_t *newBuf = MY_STRING_NEW_wchar_t((size_t)len + 1); |
1200 | MY_STRING_DELETE(_chars); | 1204 | MY_STRING_DELETE(_chars) |
1201 | _chars = newBuf; | 1205 | _chars = newBuf; |
1202 | _limit = len; | 1206 | _limit = len; |
1203 | } | 1207 | } |
@@ -1211,7 +1215,7 @@ void UString::SetFrom(const wchar_t *s, unsigned len) // no check | |||
1211 | if (len > _limit) | 1215 | if (len > _limit) |
1212 | { | 1216 | { |
1213 | wchar_t *newBuf = MY_STRING_NEW_wchar_t((size_t)len + 1); | 1217 | wchar_t *newBuf = MY_STRING_NEW_wchar_t((size_t)len + 1); |
1214 | MY_STRING_DELETE(_chars); | 1218 | MY_STRING_DELETE(_chars) |
1215 | _chars = newBuf; | 1219 | _chars = newBuf; |
1216 | _limit = len; | 1220 | _limit = len; |
1217 | } | 1221 | } |
@@ -1249,7 +1253,7 @@ void UString::SetFromBstr(LPCOLESTR s) | |||
1249 | if (len > _limit) | 1253 | if (len > _limit) |
1250 | { | 1254 | { |
1251 | wchar_t *newBuf = MY_STRING_NEW_wchar_t((size_t)len + 1); | 1255 | wchar_t *newBuf = MY_STRING_NEW_wchar_t((size_t)len + 1); |
1252 | MY_STRING_DELETE(_chars); | 1256 | MY_STRING_DELETE(_chars) |
1253 | _chars = newBuf; | 1257 | _chars = newBuf; |
1254 | _limit = len; | 1258 | _limit = len; |
1255 | } | 1259 | } |
@@ -1289,7 +1293,7 @@ UString &UString::operator=(const char *s) | |||
1289 | if (len > _limit) | 1293 | if (len > _limit) |
1290 | { | 1294 | { |
1291 | wchar_t *newBuf = MY_STRING_NEW_wchar_t((size_t)len + 1); | 1295 | wchar_t *newBuf = MY_STRING_NEW_wchar_t((size_t)len + 1); |
1292 | MY_STRING_DELETE(_chars); | 1296 | MY_STRING_DELETE(_chars) |
1293 | _chars = newBuf; | 1297 | _chars = newBuf; |
1294 | _limit = len; | 1298 | _limit = len; |
1295 | } | 1299 | } |
@@ -1301,6 +1305,7 @@ UString &UString::operator=(const char *s) | |||
1301 | return *this; | 1305 | return *this; |
1302 | } | 1306 | } |
1303 | 1307 | ||
1308 | void UString::Add_Dot() { operator+=(L'.'); } | ||
1304 | void UString::Add_Space() { operator+=(L' '); } | 1309 | void UString::Add_Space() { operator+=(L' '); } |
1305 | void UString::Add_Space_if_NotEmpty() { if (!IsEmpty()) Add_Space(); } | 1310 | void UString::Add_Space_if_NotEmpty() { if (!IsEmpty()) Add_Space(); } |
1306 | 1311 | ||
@@ -1393,31 +1398,26 @@ int UString::ReverseFind(wchar_t c) const throw() | |||
1393 | { | 1398 | { |
1394 | if (_len == 0) | 1399 | if (_len == 0) |
1395 | return -1; | 1400 | return -1; |
1396 | const wchar_t *p = _chars + _len - 1; | 1401 | const wchar_t *p = _chars + _len; |
1397 | for (;;) | 1402 | do |
1398 | { | 1403 | { |
1399 | if (*p == c) | 1404 | if (*(--p) == c) |
1400 | return (int)(p - _chars); | 1405 | return (int)(p - _chars); |
1401 | if (p == _chars) | ||
1402 | return -1; | ||
1403 | p--; | ||
1404 | } | 1406 | } |
1407 | while (p != _chars); | ||
1408 | return -1; | ||
1405 | } | 1409 | } |
1406 | 1410 | ||
1407 | int UString::ReverseFind_PathSepar() const throw() | 1411 | int UString::ReverseFind_PathSepar() const throw() |
1408 | { | 1412 | { |
1409 | if (_len == 0) | 1413 | const wchar_t *p = _chars + _len; |
1410 | return -1; | 1414 | while (p != _chars) |
1411 | const wchar_t *p = _chars + _len - 1; | ||
1412 | for (;;) | ||
1413 | { | 1415 | { |
1414 | wchar_t c = *p; | 1416 | const wchar_t c = *(--p); |
1415 | if (IS_PATH_SEPAR(c)) | 1417 | if (IS_PATH_SEPAR(c)) |
1416 | return (int)(p - _chars); | 1418 | return (int)(p - _chars); |
1417 | if (p == _chars) | ||
1418 | return -1; | ||
1419 | p--; | ||
1420 | } | 1419 | } |
1420 | return -1; | ||
1421 | } | 1421 | } |
1422 | 1422 | ||
1423 | void UString::TrimLeft() throw() | 1423 | void UString::TrimLeft() throw() |
@@ -1601,7 +1601,7 @@ void UString2::ReAlloc2(unsigned newLimit) | |||
1601 | // MY_STRING_REALLOC(_chars, wchar_t, newLimit + 1, 0); | 1601 | // MY_STRING_REALLOC(_chars, wchar_t, newLimit + 1, 0); |
1602 | if (_chars) | 1602 | if (_chars) |
1603 | { | 1603 | { |
1604 | MY_STRING_DELETE(_chars); | 1604 | MY_STRING_DELETE(_chars) |
1605 | _chars = NULL; | 1605 | _chars = NULL; |
1606 | // _len = 0; | 1606 | // _len = 0; |
1607 | } | 1607 | } |
@@ -1651,7 +1651,7 @@ UString2 &UString2::operator=(wchar_t c) | |||
1651 | { | 1651 | { |
1652 | wchar_t *newBuf = MY_STRING_NEW_wchar_t(1 + 1); | 1652 | wchar_t *newBuf = MY_STRING_NEW_wchar_t(1 + 1); |
1653 | if (_chars) | 1653 | if (_chars) |
1654 | MY_STRING_DELETE(_chars); | 1654 | MY_STRING_DELETE(_chars) |
1655 | _chars = newBuf; | 1655 | _chars = newBuf; |
1656 | } | 1656 | } |
1657 | _len = 1; | 1657 | _len = 1; |
@@ -1669,7 +1669,7 @@ UString2 &UString2::operator=(const wchar_t *s) | |||
1669 | { | 1669 | { |
1670 | wchar_t *newBuf = MY_STRING_NEW_wchar_t((size_t)len + 1); | 1670 | wchar_t *newBuf = MY_STRING_NEW_wchar_t((size_t)len + 1); |
1671 | if (_chars) | 1671 | if (_chars) |
1672 | MY_STRING_DELETE(_chars); | 1672 | MY_STRING_DELETE(_chars) |
1673 | _chars = newBuf; | 1673 | _chars = newBuf; |
1674 | } | 1674 | } |
1675 | _len = len; | 1675 | _len = len; |
@@ -1684,7 +1684,7 @@ void UString2::SetFromAscii(const char *s) | |||
1684 | { | 1684 | { |
1685 | wchar_t *newBuf = MY_STRING_NEW_wchar_t((size_t)len + 1); | 1685 | wchar_t *newBuf = MY_STRING_NEW_wchar_t((size_t)len + 1); |
1686 | if (_chars) | 1686 | if (_chars) |
1687 | MY_STRING_DELETE(_chars); | 1687 | MY_STRING_DELETE(_chars) |
1688 | _chars = newBuf; | 1688 | _chars = newBuf; |
1689 | } | 1689 | } |
1690 | wchar_t *chars = _chars; | 1690 | wchar_t *chars = _chars; |
@@ -1703,7 +1703,7 @@ UString2 &UString2::operator=(const UString2 &s) | |||
1703 | { | 1703 | { |
1704 | wchar_t *newBuf = MY_STRING_NEW_wchar_t((size_t)len + 1); | 1704 | wchar_t *newBuf = MY_STRING_NEW_wchar_t((size_t)len + 1); |
1705 | if (_chars) | 1705 | if (_chars) |
1706 | MY_STRING_DELETE(_chars); | 1706 | MY_STRING_DELETE(_chars) |
1707 | _chars = newBuf; | 1707 | _chars = newBuf; |
1708 | } | 1708 | } |
1709 | _len = len; | 1709 | _len = len; |
@@ -1793,3 +1793,67 @@ FString us2fs(const wchar_t *s) | |||
1793 | } | 1793 | } |
1794 | 1794 | ||
1795 | #endif // USE_UNICODE_FSTRING | 1795 | #endif // USE_UNICODE_FSTRING |
1796 | |||
1797 | |||
1798 | bool CStringFinder::FindWord_In_LowCaseAsciiList_NoCase(const char *p, const wchar_t *str) | ||
1799 | { | ||
1800 | _temp.Empty(); | ||
1801 | for (;;) | ||
1802 | { | ||
1803 | const wchar_t c = *str++; | ||
1804 | if (c == 0) | ||
1805 | break; | ||
1806 | if (c <= 0x20 || c > 0x7f) | ||
1807 | return false; | ||
1808 | _temp += (char)MyCharLower_Ascii((char)c); | ||
1809 | } | ||
1810 | |||
1811 | while (*p != 0) | ||
1812 | { | ||
1813 | const char *s2 = _temp.Ptr(); | ||
1814 | char c, c2; | ||
1815 | do | ||
1816 | { | ||
1817 | c = *p++; | ||
1818 | c2 = *s2++; | ||
1819 | } | ||
1820 | while (c == c2); | ||
1821 | |||
1822 | if (c == ' ') | ||
1823 | { | ||
1824 | if (c2 == 0) | ||
1825 | return true; | ||
1826 | continue; | ||
1827 | } | ||
1828 | |||
1829 | while (*p++ != ' '); | ||
1830 | } | ||
1831 | |||
1832 | return false; | ||
1833 | } | ||
1834 | |||
1835 | |||
1836 | void SplitString(const UString &srcString, UStringVector &destStrings) | ||
1837 | { | ||
1838 | destStrings.Clear(); | ||
1839 | unsigned len = srcString.Len(); | ||
1840 | if (len == 0) | ||
1841 | return; | ||
1842 | UString s; | ||
1843 | for (unsigned i = 0; i < len; i++) | ||
1844 | { | ||
1845 | const wchar_t c = srcString[i]; | ||
1846 | if (c == ' ') | ||
1847 | { | ||
1848 | if (!s.IsEmpty()) | ||
1849 | { | ||
1850 | destStrings.Add(s); | ||
1851 | s.Empty(); | ||
1852 | } | ||
1853 | } | ||
1854 | else | ||
1855 | s += c; | ||
1856 | } | ||
1857 | if (!s.IsEmpty()) | ||
1858 | destStrings.Add(s); | ||
1859 | } | ||
diff --git a/CPP/Common/MyString.h b/CPP/Common/MyString.h index c777c8c..e5ce18a 100644 --- a/CPP/Common/MyString.h +++ b/CPP/Common/MyString.h | |||
@@ -1,7 +1,7 @@ | |||
1 | // Common/MyString.h | 1 | // Common/MyString.h |
2 | 2 | ||
3 | #ifndef __COMMON_MY_STRING_H | 3 | #ifndef ZIP7_INC_COMMON_MY_STRING_H |
4 | #define __COMMON_MY_STRING_H | 4 | #define ZIP7_INC_COMMON_MY_STRING_H |
5 | 5 | ||
6 | #include <string.h> | 6 | #include <string.h> |
7 | 7 | ||
@@ -10,6 +10,7 @@ | |||
10 | #include <wchar.h> | 10 | #include <wchar.h> |
11 | #endif | 11 | #endif |
12 | 12 | ||
13 | #include "Common.h" | ||
13 | #include "MyWindows.h" | 14 | #include "MyWindows.h" |
14 | #include "MyTypes.h" | 15 | #include "MyTypes.h" |
15 | #include "MyVector.h" | 16 | #include "MyVector.h" |
@@ -70,7 +71,7 @@ inline char *MyStpCpy(char *dest, const char *src) | |||
70 | { | 71 | { |
71 | for (;;) | 72 | for (;;) |
72 | { | 73 | { |
73 | char c = *src; | 74 | const char c = *src; |
74 | *dest = c; | 75 | *dest = c; |
75 | if (c == 0) | 76 | if (c == 0) |
76 | return dest; | 77 | return dest; |
@@ -79,6 +80,13 @@ inline char *MyStpCpy(char *dest, const char *src) | |||
79 | } | 80 | } |
80 | } | 81 | } |
81 | 82 | ||
83 | inline void MyStringCat(char *dest, const char *src) | ||
84 | { | ||
85 | for (; *dest != 0; dest++); | ||
86 | while ((*dest++ = *src++) != 0); | ||
87 | // MyStringCopy(dest + MyStringLen(dest), src); | ||
88 | } | ||
89 | |||
82 | inline unsigned MyStringLen(const wchar_t *s) | 90 | inline unsigned MyStringLen(const wchar_t *s) |
83 | { | 91 | { |
84 | unsigned i; | 92 | unsigned i; |
@@ -93,7 +101,9 @@ inline void MyStringCopy(wchar_t *dest, const wchar_t *src) | |||
93 | 101 | ||
94 | inline void MyStringCat(wchar_t *dest, const wchar_t *src) | 102 | inline void MyStringCat(wchar_t *dest, const wchar_t *src) |
95 | { | 103 | { |
96 | MyStringCopy(dest + MyStringLen(dest), src); | 104 | for (; *dest != 0; dest++); |
105 | while ((*dest++ = *src++) != 0); | ||
106 | // MyStringCopy(dest + MyStringLen(dest), src); | ||
97 | } | 107 | } |
98 | 108 | ||
99 | 109 | ||
@@ -102,7 +112,7 @@ inline wchar_t *MyWcpCpy(wchar_t *dest, const wchar_t *src) | |||
102 | { | 112 | { |
103 | for (;;) | 113 | for (;;) |
104 | { | 114 | { |
105 | wchar_t c = *src; | 115 | const wchar_t c = *src; |
106 | *dest = c; | 116 | *dest = c; |
107 | if (c == 0) | 117 | if (c == 0) |
108 | return dest; | 118 | return dest; |
@@ -225,7 +235,7 @@ bool StringsAreEqualNoCase_Ascii(const char *s1, const char *s2) throw(); | |||
225 | bool StringsAreEqualNoCase_Ascii(const wchar_t *s1, const char *s2) throw(); | 235 | bool StringsAreEqualNoCase_Ascii(const wchar_t *s1, const char *s2) throw(); |
226 | bool StringsAreEqualNoCase_Ascii(const wchar_t *s1, const wchar_t *s2) throw(); | 236 | bool StringsAreEqualNoCase_Ascii(const wchar_t *s1, const wchar_t *s2) throw(); |
227 | 237 | ||
228 | #define MY_STRING_DELETE(_p_) delete []_p_; | 238 | #define MY_STRING_DELETE(_p_) { delete [](_p_); } |
229 | // #define MY_STRING_DELETE(_p_) my_delete(_p_); | 239 | // #define MY_STRING_DELETE(_p_) my_delete(_p_); |
230 | 240 | ||
231 | 241 | ||
@@ -312,7 +322,7 @@ public: | |||
312 | explicit AString(char c); | 322 | explicit AString(char c); |
313 | explicit AString(const char *s); | 323 | explicit AString(const char *s); |
314 | AString(const AString &s); | 324 | AString(const AString &s); |
315 | ~AString() { MY_STRING_DELETE(_chars); } | 325 | ~AString() { MY_STRING_DELETE(_chars) } |
316 | 326 | ||
317 | unsigned Len() const { return _len; } | 327 | unsigned Len() const { return _len; } |
318 | bool IsEmpty() const { return _len == 0; } | 328 | bool IsEmpty() const { return _len == 0; } |
@@ -322,6 +332,7 @@ public: | |||
322 | char *Ptr_non_const() const { return _chars; } | 332 | char *Ptr_non_const() const { return _chars; } |
323 | const char *Ptr() const { return _chars; } | 333 | const char *Ptr() const { return _chars; } |
324 | const char *Ptr(unsigned pos) const { return _chars + pos; } | 334 | const char *Ptr(unsigned pos) const { return _chars + pos; } |
335 | const char *Ptr(int pos) const { return _chars + (unsigned)pos; } | ||
325 | const char *RightPtr(unsigned num) const { return _chars + _len - num; } | 336 | const char *RightPtr(unsigned num) const { return _chars + _len - num; } |
326 | char Back() const { return _chars[(size_t)_len - 1]; } | 337 | char Back() const { return _chars[(size_t)_len - 1]; } |
327 | 338 | ||
@@ -379,6 +390,8 @@ public: | |||
379 | void Add_OptSpaced(const char *s); | 390 | void Add_OptSpaced(const char *s); |
380 | void Add_LF(); | 391 | void Add_LF(); |
381 | void Add_Slash(); | 392 | void Add_Slash(); |
393 | void Add_Dot(); | ||
394 | void Add_Minus(); | ||
382 | void Add_PathSepar() { operator+=(CHAR_PATH_SEPARATOR); } | 395 | void Add_PathSepar() { operator+=(CHAR_PATH_SEPARATOR); } |
383 | 396 | ||
384 | AString &operator+=(const char *s); | 397 | AString &operator+=(const char *s); |
@@ -389,6 +402,10 @@ public: | |||
389 | 402 | ||
390 | void AddFrom(const char *s, unsigned len); // no check | 403 | void AddFrom(const char *s, unsigned len); // no check |
391 | void SetFrom(const char *s, unsigned len); // no check | 404 | void SetFrom(const char *s, unsigned len); // no check |
405 | void SetFrom(const char* s, int len) // no check | ||
406 | { | ||
407 | SetFrom(s, (unsigned)len); // no check | ||
408 | } | ||
392 | void SetFrom_CalcLen(const char *s, unsigned len); | 409 | void SetFrom_CalcLen(const char *s, unsigned len); |
393 | 410 | ||
394 | AString Mid(unsigned startIndex, unsigned count) const { return AString(count, _chars + startIndex); } | 411 | AString Mid(unsigned startIndex, unsigned count) const { return AString(count, _chars + startIndex); } |
@@ -419,9 +436,13 @@ public: | |||
419 | int Find(char c) const { return FindCharPosInString(_chars, c); } | 436 | int Find(char c) const { return FindCharPosInString(_chars, c); } |
420 | int Find(char c, unsigned startIndex) const | 437 | int Find(char c, unsigned startIndex) const |
421 | { | 438 | { |
422 | int pos = FindCharPosInString(_chars + startIndex, c); | 439 | const int pos = FindCharPosInString(_chars + startIndex, c); |
423 | return pos < 0 ? -1 : (int)startIndex + pos; | 440 | return pos < 0 ? -1 : (int)startIndex + pos; |
424 | } | 441 | } |
442 | int Find(char c, int startIndex) const | ||
443 | { | ||
444 | return Find(c, (unsigned)startIndex); | ||
445 | } | ||
425 | 446 | ||
426 | int ReverseFind(char c) const throw(); | 447 | int ReverseFind(char c) const throw(); |
427 | int ReverseFind_Dot() const throw() { return ReverseFind('.'); } | 448 | int ReverseFind_Dot() const throw() { return ReverseFind('.'); } |
@@ -460,6 +481,11 @@ public: | |||
460 | _chars[index] = 0; | 481 | _chars[index] = 0; |
461 | } | 482 | } |
462 | } | 483 | } |
484 | void DeleteFrom(int index) | ||
485 | { | ||
486 | DeleteFrom((unsigned)index); | ||
487 | } | ||
488 | |||
463 | 489 | ||
464 | void Wipe_and_Empty() | 490 | void Wipe_and_Empty() |
465 | { | 491 | { |
@@ -474,7 +500,7 @@ public: | |||
474 | 500 | ||
475 | class AString_Wipe: public AString | 501 | class AString_Wipe: public AString |
476 | { | 502 | { |
477 | CLASS_NO_COPY(AString_Wipe) | 503 | Z7_CLASS_NO_COPY(AString_Wipe) |
478 | public: | 504 | public: |
479 | AString_Wipe(): AString() {} | 505 | AString_Wipe(): AString() {} |
480 | // AString_Wipe(const AString &s): AString(s) {} | 506 | // AString_Wipe(const AString &s): AString(s) {} |
@@ -582,7 +608,7 @@ public: | |||
582 | explicit UString(const AString &s); | 608 | explicit UString(const AString &s); |
583 | UString(const wchar_t *s); | 609 | UString(const wchar_t *s); |
584 | UString(const UString &s); | 610 | UString(const UString &s); |
585 | ~UString() { MY_STRING_DELETE(_chars); } | 611 | ~UString() { MY_STRING_DELETE(_chars) } |
586 | 612 | ||
587 | unsigned Len() const { return _len; } | 613 | unsigned Len() const { return _len; } |
588 | bool IsEmpty() const { return _len == 0; } | 614 | bool IsEmpty() const { return _len == 0; } |
@@ -591,6 +617,7 @@ public: | |||
591 | operator const wchar_t *() const { return _chars; } | 617 | operator const wchar_t *() const { return _chars; } |
592 | wchar_t *Ptr_non_const() const { return _chars; } | 618 | wchar_t *Ptr_non_const() const { return _chars; } |
593 | const wchar_t *Ptr() const { return _chars; } | 619 | const wchar_t *Ptr() const { return _chars; } |
620 | const wchar_t *Ptr(int pos) const { return _chars + (unsigned)pos; } | ||
594 | const wchar_t *Ptr(unsigned pos) const { return _chars + pos; } | 621 | const wchar_t *Ptr(unsigned pos) const { return _chars + pos; } |
595 | const wchar_t *RightPtr(unsigned num) const { return _chars + _len - num; } | 622 | const wchar_t *RightPtr(unsigned num) const { return _chars + _len - num; } |
596 | wchar_t Back() const { return _chars[(size_t)_len - 1]; } | 623 | wchar_t Back() const { return _chars[(size_t)_len - 1]; } |
@@ -599,6 +626,14 @@ public: | |||
599 | 626 | ||
600 | wchar_t *GetBuf() { return _chars; } | 627 | wchar_t *GetBuf() { return _chars; } |
601 | 628 | ||
629 | /* | ||
630 | wchar_t *GetBuf_GetMaxAvail(unsigned &availBufLen) | ||
631 | { | ||
632 | availBufLen = _limit; | ||
633 | return _chars; | ||
634 | } | ||
635 | */ | ||
636 | |||
602 | wchar_t *GetBuf(unsigned minLen) | 637 | wchar_t *GetBuf(unsigned minLen) |
603 | { | 638 | { |
604 | if (minLen > _limit) | 639 | if (minLen > _limit) |
@@ -650,6 +685,7 @@ public: | |||
650 | void Add_Space(); | 685 | void Add_Space(); |
651 | void Add_Space_if_NotEmpty(); | 686 | void Add_Space_if_NotEmpty(); |
652 | void Add_LF(); | 687 | void Add_LF(); |
688 | void Add_Dot(); | ||
653 | void Add_PathSepar() { operator+=(WCHAR_PATH_SEPARATOR); } | 689 | void Add_PathSepar() { operator+=(WCHAR_PATH_SEPARATOR); } |
654 | 690 | ||
655 | UString &operator+=(const wchar_t *s); | 691 | UString &operator+=(const wchar_t *s); |
@@ -662,6 +698,7 @@ public: | |||
662 | 698 | ||
663 | UString Mid(unsigned startIndex, unsigned count) const { return UString(count, _chars + startIndex); } | 699 | UString Mid(unsigned startIndex, unsigned count) const { return UString(count, _chars + startIndex); } |
664 | UString Left(unsigned count) const { return UString(count, *this); } | 700 | UString Left(unsigned count) const { return UString(count, *this); } |
701 | UString Left(int count) const { return Left((unsigned)count); } | ||
665 | 702 | ||
666 | // void MakeUpper() { MyStringUpper(_chars); } | 703 | // void MakeUpper() { MyStringUpper(_chars); } |
667 | // void MakeUpper() { MyStringUpper_Ascii(_chars); } | 704 | // void MakeUpper() { MyStringUpper_Ascii(_chars); } |
@@ -720,10 +757,12 @@ public: | |||
720 | void Replace(wchar_t oldChar, wchar_t newChar) throw(); | 757 | void Replace(wchar_t oldChar, wchar_t newChar) throw(); |
721 | void Replace(const UString &oldString, const UString &newString); | 758 | void Replace(const UString &oldString, const UString &newString); |
722 | 759 | ||
760 | void Delete(int index) throw() { Delete((unsigned)index); } | ||
723 | void Delete(unsigned index) throw(); | 761 | void Delete(unsigned index) throw(); |
724 | void Delete(unsigned index, unsigned count) throw(); | 762 | void Delete(unsigned index, unsigned count) throw(); |
725 | void DeleteFrontal(unsigned num) throw(); | 763 | void DeleteFrontal(unsigned num) throw(); |
726 | void DeleteBack() { _chars[--_len] = 0; } | 764 | void DeleteBack() { _chars[--_len] = 0; } |
765 | void DeleteFrom(int index) { DeleteFrom((unsigned)index); } | ||
727 | void DeleteFrom(unsigned index) | 766 | void DeleteFrom(unsigned index) |
728 | { | 767 | { |
729 | if (index < _len) | 768 | if (index < _len) |
@@ -746,7 +785,7 @@ public: | |||
746 | 785 | ||
747 | class UString_Wipe: public UString | 786 | class UString_Wipe: public UString |
748 | { | 787 | { |
749 | CLASS_NO_COPY(UString_Wipe) | 788 | Z7_CLASS_NO_COPY(UString_Wipe) |
750 | public: | 789 | public: |
751 | UString_Wipe(): UString() {} | 790 | UString_Wipe(): UString() {} |
752 | // UString_Wipe(const UString &s): UString(s) {} | 791 | // UString_Wipe(const UString &s): UString(s) {} |
@@ -834,7 +873,7 @@ public: | |||
834 | UString2(): _chars(NULL), _len(0) {} | 873 | UString2(): _chars(NULL), _len(0) {} |
835 | UString2(const wchar_t *s); | 874 | UString2(const wchar_t *s); |
836 | UString2(const UString2 &s); | 875 | UString2(const UString2 &s); |
837 | ~UString2() { if (_chars) MY_STRING_DELETE(_chars); } | 876 | ~UString2() { if (_chars) { MY_STRING_DELETE(_chars) } } |
838 | 877 | ||
839 | unsigned Len() const { return _len; } | 878 | unsigned Len() const { return _len; } |
840 | bool IsEmpty() const { return _len == 0; } | 879 | bool IsEmpty() const { return _len == 0; } |
@@ -912,7 +951,7 @@ typedef CObjectVector<CSysString> CSysStringVector; | |||
912 | 951 | ||
913 | #ifdef USE_UNICODE_FSTRING | 952 | #ifdef USE_UNICODE_FSTRING |
914 | 953 | ||
915 | #define __FTEXT(quote) L##quote | 954 | #define MY_FTEXT(quote) L##quote |
916 | 955 | ||
917 | typedef wchar_t FChar; | 956 | typedef wchar_t FChar; |
918 | typedef UString FString; | 957 | typedef UString FString; |
@@ -923,9 +962,9 @@ typedef CObjectVector<CSysString> CSysStringVector; | |||
923 | FString fas2fs(const AString &s); | 962 | FString fas2fs(const AString &s); |
924 | AString fs2fas(const FChar *s); | 963 | AString fs2fas(const FChar *s); |
925 | 964 | ||
926 | #else | 965 | #else // USE_UNICODE_FSTRING |
927 | 966 | ||
928 | #define __FTEXT(quote) quote | 967 | #define MY_FTEXT(quote) quote |
929 | 968 | ||
930 | typedef char FChar; | 969 | typedef char FChar; |
931 | 970 | ||
@@ -979,9 +1018,9 @@ typedef CObjectVector<CSysString> CSysStringVector; | |||
979 | FString us2fs(const wchar_t *s); | 1018 | FString us2fs(const wchar_t *s); |
980 | #define fs2fas(_x_) (_x_) | 1019 | #define fs2fas(_x_) (_x_) |
981 | 1020 | ||
982 | #endif | 1021 | #endif // USE_UNICODE_FSTRING |
983 | 1022 | ||
984 | #define FTEXT(quote) __FTEXT(quote) | 1023 | #define FTEXT(quote) MY_FTEXT(quote) |
985 | 1024 | ||
986 | #define FCHAR_PATH_SEPARATOR FTEXT(CHAR_PATH_SEPARATOR) | 1025 | #define FCHAR_PATH_SEPARATOR FTEXT(CHAR_PATH_SEPARATOR) |
987 | #define FSTRING_PATH_SEPARATOR FTEXT(STRING_PATH_SEPARATOR) | 1026 | #define FSTRING_PATH_SEPARATOR FTEXT(STRING_PATH_SEPARATOR) |
@@ -993,6 +1032,18 @@ typedef const FChar *CFSTR; | |||
993 | 1032 | ||
994 | typedef CObjectVector<FString> FStringVector; | 1033 | typedef CObjectVector<FString> FStringVector; |
995 | 1034 | ||
1035 | |||
1036 | class CStringFinder | ||
1037 | { | ||
1038 | AString _temp; | ||
1039 | public: | ||
1040 | // list - is list of low case Ascii strings separated by space " ". | ||
1041 | // the function returns true, if it can find exact word (str) in (list). | ||
1042 | bool FindWord_In_LowCaseAsciiList_NoCase(const char *list, const wchar_t *str); | ||
1043 | }; | ||
1044 | |||
1045 | void SplitString(const UString &srcString, UStringVector &destStrings); | ||
1046 | |||
996 | #endif | 1047 | #endif |
997 | 1048 | ||
998 | 1049 | ||
@@ -1000,10 +1051,10 @@ typedef CObjectVector<FString> FStringVector; | |||
1000 | #if defined(_WIN32) | 1051 | #if defined(_WIN32) |
1001 | // #include <wchar.h> | 1052 | // #include <wchar.h> |
1002 | // WCHAR_MAX is defined as ((wchar_t)-1) | 1053 | // WCHAR_MAX is defined as ((wchar_t)-1) |
1003 | #define _WCHART_IS_16BIT 1 | 1054 | #define Z7_WCHART_IS_16BIT 1 |
1004 | #elif (defined(WCHAR_MAX) && (WCHAR_MAX <= 0xffff)) \ | 1055 | #elif (defined(WCHAR_MAX) && (WCHAR_MAX <= 0xffff)) \ |
1005 | || (defined(__SIZEOF_WCHAR_T__) && (__SIZEOF_WCHAR_T__ == 2)) | 1056 | || (defined(__SIZEOF_WCHAR_T__) && (__SIZEOF_WCHAR_T__ == 2)) |
1006 | #define _WCHART_IS_16BIT 1 | 1057 | #define Z7_WCHART_IS_16BIT 1 |
1007 | #endif | 1058 | #endif |
1008 | 1059 | ||
1009 | #if WCHAR_PATH_SEPARATOR == L'\\' | 1060 | #if WCHAR_PATH_SEPARATOR == L'\\' |
diff --git a/CPP/Common/MyTypes.h b/CPP/Common/MyTypes.h index 71b8e7f..8f44f67 100644 --- a/CPP/Common/MyTypes.h +++ b/CPP/Common/MyTypes.h | |||
@@ -1,9 +1,10 @@ | |||
1 | // Common/MyTypes.h | 1 | // Common/MyTypes.h |
2 | 2 | ||
3 | #ifndef __COMMON_MY_TYPES_H | 3 | #ifndef ZIP7_INC_COMMON_MY_TYPES_H |
4 | #define __COMMON_MY_TYPES_H | 4 | #define ZIP7_INC_COMMON_MY_TYPES_H |
5 | 5 | ||
6 | #include "../../C/7zTypes.h" | 6 | #include "../../C/7zTypes.h" |
7 | #include "Common.h" | ||
7 | 8 | ||
8 | typedef int HRes; | 9 | typedef int HRes; |
9 | 10 | ||
@@ -33,20 +34,4 @@ struct CBoolPair | |||
33 | } | 34 | } |
34 | }; | 35 | }; |
35 | 36 | ||
36 | #define CLASS_NO_COPY(cls) \ | ||
37 | private: \ | ||
38 | cls(const cls &); \ | ||
39 | cls &operator=(const cls &); | ||
40 | |||
41 | class CUncopyable | ||
42 | { | ||
43 | protected: | ||
44 | CUncopyable() {} // allow constructor | ||
45 | // ~CUncopyable() {} | ||
46 | CLASS_NO_COPY(CUncopyable) | ||
47 | }; | ||
48 | |||
49 | #define MY_UNCOPYABLE :private CUncopyable | ||
50 | // #define MY_UNCOPYABLE | ||
51 | |||
52 | #endif | 37 | #endif |
diff --git a/CPP/Common/MyUnknown.h b/CPP/Common/MyUnknown.h index ff025cb..75ee96f 100644 --- a/CPP/Common/MyUnknown.h +++ b/CPP/Common/MyUnknown.h | |||
@@ -1,17 +1,8 @@ | |||
1 | // MyUnknown.h | 1 | // MyUnknown.h |
2 | 2 | ||
3 | #ifndef __MY_UNKNOWN_H | 3 | #ifndef ZIP7_INC_MY_UNKNOWN_H |
4 | #define __MY_UNKNOWN_H | 4 | #define ZIP7_INC_MY_UNKNOWN_H |
5 | 5 | ||
6 | #include "MyWindows.h" | 6 | #include "MyWindows.h" |
7 | 7 | ||
8 | /* | ||
9 | #ifdef _WIN32 | ||
10 | #include <basetyps.h> | ||
11 | #include <unknwn.h> | ||
12 | #else | ||
13 | #include "MyWindows.h" | ||
14 | #endif | ||
15 | */ | ||
16 | |||
17 | #endif | 8 | #endif |
diff --git a/CPP/Common/MyVector.h b/CPP/Common/MyVector.h index 3417a17..9ee7105 100644 --- a/CPP/Common/MyVector.h +++ b/CPP/Common/MyVector.h | |||
@@ -1,10 +1,12 @@ | |||
1 | // Common/MyVector.h | 1 | // Common/MyVector.h |
2 | 2 | ||
3 | #ifndef __COMMON_MY_VECTOR_H | 3 | #ifndef ZIP7_INC_COMMON_MY_VECTOR_H |
4 | #define __COMMON_MY_VECTOR_H | 4 | #define ZIP7_INC_COMMON_MY_VECTOR_H |
5 | 5 | ||
6 | #include <string.h> | 6 | #include <string.h> |
7 | 7 | ||
8 | #include "Common.h" | ||
9 | |||
8 | const unsigned k_VectorSizeMax = ((unsigned)1 << 31) - 1; | 10 | const unsigned k_VectorSizeMax = ((unsigned)1 << 31) - 1; |
9 | 11 | ||
10 | template <class T> | 12 | template <class T> |
@@ -22,7 +24,7 @@ class CRecordVector | |||
22 | void ReAllocForNewCapacity(const unsigned newCapacity) | 24 | void ReAllocForNewCapacity(const unsigned newCapacity) |
23 | { | 25 | { |
24 | T *p; | 26 | T *p; |
25 | MY_ARRAY_NEW(p, T, newCapacity); | 27 | Z7_ARRAY_NEW(p, T, newCapacity) |
26 | // p = new T[newCapacity]; | 28 | // p = new T[newCapacity]; |
27 | if (_size != 0) | 29 | if (_size != 0) |
28 | memcpy(p, _items, (size_t)_size * sizeof(T)); | 30 | memcpy(p, _items, (size_t)_size * sizeof(T)); |
@@ -53,7 +55,7 @@ public: | |||
53 | const unsigned size = v.Size(); | 55 | const unsigned size = v.Size(); |
54 | if (size != 0) | 56 | if (size != 0) |
55 | { | 57 | { |
56 | // MY_ARRAY_NEW(_items, T, size) | 58 | // Z7_ARRAY_NEW(_items, T, size) |
57 | _items = new T[size]; | 59 | _items = new T[size]; |
58 | _size = size; | 60 | _size = size; |
59 | _capacity = size; | 61 | _capacity = size; |
@@ -68,7 +70,7 @@ public: | |||
68 | { | 70 | { |
69 | if (size != 0) | 71 | if (size != 0) |
70 | { | 72 | { |
71 | MY_ARRAY_NEW(_items, T, size) | 73 | Z7_ARRAY_NEW(_items, T, size) |
72 | // _items = new T[size]; | 74 | // _items = new T[size]; |
73 | _capacity = size; | 75 | _capacity = size; |
74 | } | 76 | } |
@@ -100,7 +102,7 @@ public: | |||
100 | delete []_items; | 102 | delete []_items; |
101 | _items = NULL; | 103 | _items = NULL; |
102 | _capacity = 0; | 104 | _capacity = 0; |
103 | MY_ARRAY_NEW(_items, T, newCapacity) | 105 | Z7_ARRAY_NEW(_items, T, newCapacity) |
104 | // _items = new T[newCapacity]; | 106 | // _items = new T[newCapacity]; |
105 | _capacity = newCapacity; | 107 | _capacity = newCapacity; |
106 | } | 108 | } |
@@ -119,7 +121,7 @@ public: | |||
119 | T *p = NULL; | 121 | T *p = NULL; |
120 | if (_size != 0) | 122 | if (_size != 0) |
121 | { | 123 | { |
122 | // MY_ARRAY_NEW(p, T, _size) | 124 | // Z7_ARRAY_NEW(p, T, _size) |
123 | p = new T[_size]; | 125 | p = new T[_size]; |
124 | memcpy(p, _items, (size_t)_size * sizeof(T)); | 126 | memcpy(p, _items, (size_t)_size * sizeof(T)); |
125 | } | 127 | } |
@@ -264,6 +266,8 @@ public: | |||
264 | 266 | ||
265 | const T& operator[](unsigned index) const { return _items[index]; } | 267 | const T& operator[](unsigned index) const { return _items[index]; } |
266 | T& operator[](unsigned index) { return _items[index]; } | 268 | T& operator[](unsigned index) { return _items[index]; } |
269 | const T& operator[](int index) const { return _items[(unsigned)index]; } | ||
270 | T& operator[](int index) { return _items[(unsigned)index]; } | ||
267 | const T& Front() const { return _items[0]; } | 271 | const T& Front() const { return _items[0]; } |
268 | T& Front() { return _items[0]; } | 272 | T& Front() { return _items[0]; } |
269 | const T& Back() const { return _items[(size_t)_size - 1]; } | 273 | const T& Back() const { return _items[(size_t)_size - 1]; } |
@@ -497,6 +501,8 @@ public: | |||
497 | 501 | ||
498 | const T& operator[](unsigned index) const { return *((T *)_v[index]); } | 502 | const T& operator[](unsigned index) const { return *((T *)_v[index]); } |
499 | T& operator[](unsigned index) { return *((T *)_v[index]); } | 503 | T& operator[](unsigned index) { return *((T *)_v[index]); } |
504 | const T& operator[](int index) const { return *((T *)_v[(unsigned)index]); } | ||
505 | T& operator[](int index) { return *((T *)_v[(unsigned)index]); } | ||
500 | const T& Front() const { return operator[](0); } | 506 | const T& Front() const { return operator[](0); } |
501 | T& Front() { return operator[](0); } | 507 | T& Front() { return operator[](0); } |
502 | const T& Back() const { return *(T *)_v.Back(); } | 508 | const T& Back() const { return *(T *)_v.Back(); } |
@@ -604,6 +610,7 @@ public: | |||
604 | delete (T *)_v[index]; | 610 | delete (T *)_v[index]; |
605 | _v.Delete(index); | 611 | _v.Delete(index); |
606 | } | 612 | } |
613 | // void Delete(int index) { Delete((unsigned)index); } | ||
607 | 614 | ||
608 | /* | 615 | /* |
609 | void Delete(unsigned index, unsigned num) | 616 | void Delete(unsigned index, unsigned num) |
diff --git a/CPP/Common/MyWindows.cpp b/CPP/Common/MyWindows.cpp index 88f312f..ae284eb 100644 --- a/CPP/Common/MyWindows.cpp +++ b/CPP/Common/MyWindows.cpp | |||
@@ -78,7 +78,7 @@ BSTR SysAllocStringLen(const OLECHAR *s, UINT len) | |||
78 | BSTR SysAllocString(const OLECHAR *s) | 78 | BSTR SysAllocString(const OLECHAR *s) |
79 | { | 79 | { |
80 | if (!s) | 80 | if (!s) |
81 | return 0; | 81 | return NULL; |
82 | const OLECHAR *s2 = s; | 82 | const OLECHAR *s2 = s; |
83 | while (*s2 != 0) | 83 | while (*s2 != 0) |
84 | s2++; | 84 | s2++; |
@@ -181,7 +181,7 @@ BOOL WINAPI FileTimeToLocalFileTime(const FILETIME *fileTime, FILETIME *localFil | |||
181 | { | 181 | { |
182 | UInt64 v = GET_TIME_64(fileTime); | 182 | UInt64 v = GET_TIME_64(fileTime); |
183 | v = (UInt64)((Int64)v - (Int64)TIME_GetBias() * TICKS_PER_SEC); | 183 | v = (UInt64)((Int64)v - (Int64)TIME_GetBias() * TICKS_PER_SEC); |
184 | SET_FILETIME(localFileTime, v); | 184 | SET_FILETIME(localFileTime, v) |
185 | return TRUE; | 185 | return TRUE; |
186 | } | 186 | } |
187 | 187 | ||
@@ -189,7 +189,7 @@ BOOL WINAPI LocalFileTimeToFileTime(const FILETIME *localFileTime, FILETIME *fil | |||
189 | { | 189 | { |
190 | UInt64 v = GET_TIME_64(localFileTime); | 190 | UInt64 v = GET_TIME_64(localFileTime); |
191 | v = (UInt64)((Int64)v + (Int64)TIME_GetBias() * TICKS_PER_SEC); | 191 | v = (UInt64)((Int64)v + (Int64)TIME_GetBias() * TICKS_PER_SEC); |
192 | SET_FILETIME(fileTime, v); | 192 | SET_FILETIME(fileTime, v) |
193 | return TRUE; | 193 | return TRUE; |
194 | } | 194 | } |
195 | 195 | ||
@@ -203,7 +203,7 @@ VOID WINAPI GetSystemTimeAsFileTime(FILETIME *ft) | |||
203 | t = tv.tv_sec * (UInt64)TICKS_PER_SEC + TICKS_1601_TO_1970; | 203 | t = tv.tv_sec * (UInt64)TICKS_PER_SEC + TICKS_1601_TO_1970; |
204 | t += tv.tv_usec * 10; | 204 | t += tv.tv_usec * 10; |
205 | } | 205 | } |
206 | SET_FILETIME(ft, t); | 206 | SET_FILETIME(ft, t) |
207 | } | 207 | } |
208 | */ | 208 | */ |
209 | 209 | ||
diff --git a/CPP/Common/MyWindows.h b/CPP/Common/MyWindows.h index 15db524..a76e14b 100644 --- a/CPP/Common/MyWindows.h +++ b/CPP/Common/MyWindows.h | |||
@@ -1,16 +1,25 @@ | |||
1 | // MyWindows.h | 1 | // MyWindows.h |
2 | 2 | ||
3 | #ifndef __MY_WINDOWS_H | 3 | #ifdef Z7_DEFINE_GUID |
4 | #define __MY_WINDOWS_H | 4 | #undef Z7_DEFINE_GUID |
5 | #endif | ||
5 | 6 | ||
6 | #ifdef _WIN32 | 7 | #ifdef INITGUID |
8 | #define Z7_DEFINE_GUID(name, l, w1, w2, b1, b2, b3, b4, b5, b6, b7, b8) \ | ||
9 | EXTERN_C const GUID name; \ | ||
10 | EXTERN_C const GUID name = { l, w1, w2, { b1, b2, b3, b4, b5, b6, b7, b8 } } | ||
11 | #else | ||
12 | #define Z7_DEFINE_GUID(name, l, w1, w2, b1, b2, b3, b4, b5, b6, b7, b8) \ | ||
13 | EXTERN_C const GUID name | ||
14 | #endif | ||
7 | 15 | ||
8 | #include <Windows.h> | ||
9 | 16 | ||
10 | #ifdef UNDER_CE | 17 | #ifndef ZIP7_INC_MY_WINDOWS_H |
11 | #undef VARIANT_TRUE | 18 | #define ZIP7_INC_MY_WINDOWS_H |
12 | #define VARIANT_TRUE ((VARIANT_BOOL)-1) | 19 | |
13 | #endif | 20 | #ifdef _WIN32 |
21 | |||
22 | #include "../../C/7zWindows.h" | ||
14 | 23 | ||
15 | #else // _WIN32 | 24 | #else // _WIN32 |
16 | 25 | ||
@@ -18,11 +27,11 @@ | |||
18 | #include <string.h> | 27 | #include <string.h> |
19 | // #include <stdint.h> // for uintptr_t | 28 | // #include <stdint.h> // for uintptr_t |
20 | 29 | ||
30 | #include "../../C/7zTypes.h" | ||
21 | #include "MyGuidDef.h" | 31 | #include "MyGuidDef.h" |
22 | 32 | ||
23 | // WINAPI is __stdcall in Windows-MSVC in windef.h | 33 | // WINAPI is __stdcall in Windows-MSVC in windef.h |
24 | #define WINAPI | 34 | #define WINAPI |
25 | #define EXTERN_C MY_EXTERN_C | ||
26 | 35 | ||
27 | typedef char CHAR; | 36 | typedef char CHAR; |
28 | typedef unsigned char UCHAR; | 37 | typedef unsigned char UCHAR; |
@@ -103,31 +112,78 @@ typedef LONG SCODE; | |||
103 | 112 | ||
104 | #define STDAPI EXTERN_C HRESULT STDAPICALLTYPE | 113 | #define STDAPI EXTERN_C HRESULT STDAPICALLTYPE |
105 | 114 | ||
106 | #define STDMETHOD_(t, f) virtual t STDMETHODCALLTYPE f | 115 | #ifndef DECLSPEC_NOTHROW |
107 | #define STDMETHOD(f) STDMETHOD_(HRESULT, f) | 116 | #define DECLSPEC_NOTHROW Z7_DECLSPEC_NOTHROW |
108 | #define STDMETHODIMP_(type) type STDMETHODCALLTYPE | 117 | #endif |
109 | #define STDMETHODIMP STDMETHODIMP_(HRESULT) | 118 | |
119 | #ifndef DECLSPEC_NOVTABLE | ||
120 | #define DECLSPEC_NOVTABLE Z7_DECLSPEC_NOVTABLE | ||
121 | #endif | ||
122 | |||
123 | #ifndef COM_DECLSPEC_NOTHROW | ||
124 | #ifdef COM_STDMETHOD_CAN_THROW | ||
125 | #define COM_DECLSPEC_NOTHROW | ||
126 | #else | ||
127 | #define COM_DECLSPEC_NOTHROW DECLSPEC_NOTHROW | ||
128 | #endif | ||
129 | #endif | ||
130 | |||
131 | #define DECLARE_INTERFACE(iface) struct DECLSPEC_NOVTABLE iface | ||
132 | #define DECLARE_INTERFACE_(iface, baseiface) struct DECLSPEC_NOVTABLE iface : public baseiface | ||
133 | |||
134 | #define STDMETHOD_(t, f) virtual COM_DECLSPEC_NOTHROW t STDMETHODCALLTYPE f | ||
135 | #define STDMETHOD(f) STDMETHOD_(HRESULT, f) | ||
136 | #define STDMETHODIMP_(t) COM_DECLSPEC_NOTHROW t STDMETHODCALLTYPE | ||
137 | #define STDMETHODIMP STDMETHODIMP_(HRESULT) | ||
138 | |||
110 | 139 | ||
111 | #define PURE = 0 | 140 | #define PURE = 0 |
112 | 141 | ||
113 | #define MIDL_INTERFACE(x) struct | 142 | // #define MIDL_INTERFACE(x) struct |
143 | |||
114 | 144 | ||
115 | #ifdef __cplusplus | 145 | #ifdef __cplusplus |
116 | 146 | ||
147 | /* | ||
148 | p7zip and 7-Zip before v23 used virtual destructor in IUnknown, | ||
149 | if _WIN32 is not defined. | ||
150 | It used virtual destructor, because some compilers don't like virtual | ||
151 | interfaces without virtual destructor. | ||
152 | IUnknown in Windows (_WIN32) doesn't use virtual destructor in IUnknown. | ||
153 | We still can define Z7_USE_VIRTUAL_DESTRUCTOR_IN_IUNKNOWN here, | ||
154 | if we want to be compatible with old plugin interface of p7zip and 7-Zip before v23. | ||
155 | |||
156 | v23: | ||
157 | In new 7-Zip v23 we try to be more compatible with original IUnknown from _WIN32. | ||
158 | So we do not define Z7_USE_VIRTUAL_DESTRUCTOR_IN_IUNKNOWN here, | ||
159 | */ | ||
160 | // #define Z7_USE_VIRTUAL_DESTRUCTOR_IN_IUNKNOWN | ||
161 | |||
162 | #ifdef Z7_USE_VIRTUAL_DESTRUCTOR_IN_IUNKNOWN | ||
163 | #if defined(__clang__) | ||
164 | #pragma GCC diagnostic ignored "-Winconsistent-missing-destructor-override" | ||
165 | #endif | ||
166 | #endif | ||
167 | |||
168 | Z7_PURE_INTERFACES_BEGIN | ||
169 | |||
117 | DEFINE_GUID(IID_IUnknown, | 170 | DEFINE_GUID(IID_IUnknown, |
118 | 0x00000000, 0x0000, 0x0000, 0xC0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x46); | 171 | 0x00000000, 0x0000, 0x0000, 0xC0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x46); |
119 | struct IUnknown | 172 | struct IUnknown |
120 | { | 173 | { |
121 | STDMETHOD(QueryInterface) (REFIID iid, void **outObject) PURE; | 174 | STDMETHOD(QueryInterface) (REFIID iid, void **outObject) =0; |
122 | STDMETHOD_(ULONG, AddRef)() PURE; | 175 | STDMETHOD_(ULONG, AddRef)() =0; |
123 | STDMETHOD_(ULONG, Release)() PURE; | 176 | STDMETHOD_(ULONG, Release)() =0; |
177 | #ifdef Z7_USE_VIRTUAL_DESTRUCTOR_IN_IUNKNOWN | ||
124 | virtual ~IUnknown() {} | 178 | virtual ~IUnknown() {} |
125 | // We use virtual ~IUnknown() here for binary compatibility with 7z.so from p7zip | 179 | #endif |
126 | }; | 180 | }; |
127 | 181 | ||
128 | typedef IUnknown *LPUNKNOWN; | 182 | typedef IUnknown *LPUNKNOWN; |
129 | 183 | ||
130 | #endif | 184 | Z7_PURE_INTERFACES_END |
185 | |||
186 | #endif // __cplusplus | ||
131 | 187 | ||
132 | #define VARIANT_TRUE ((VARIANT_BOOL)-1) | 188 | #define VARIANT_TRUE ((VARIANT_BOOL)-1) |
133 | #define VARIANT_FALSE ((VARIANT_BOOL)0) | 189 | #define VARIANT_FALSE ((VARIANT_BOOL)0) |
@@ -197,8 +253,8 @@ typedef PROPVARIANT tagVARIANT; | |||
197 | typedef tagVARIANT VARIANT; | 253 | typedef tagVARIANT VARIANT; |
198 | typedef VARIANT VARIANTARG; | 254 | typedef VARIANT VARIANTARG; |
199 | 255 | ||
200 | MY_EXTERN_C HRESULT VariantClear(VARIANTARG *prop); | 256 | EXTERN_C HRESULT VariantClear(VARIANTARG *prop); |
201 | MY_EXTERN_C HRESULT VariantCopy(VARIANTARG *dest, const VARIANTARG *src); | 257 | EXTERN_C HRESULT VariantCopy(VARIANTARG *dest, const VARIANTARG *src); |
202 | 258 | ||
203 | typedef struct tagSTATPROPSTG | 259 | typedef struct tagSTATPROPSTG |
204 | { | 260 | { |
@@ -207,19 +263,19 @@ typedef struct tagSTATPROPSTG | |||
207 | VARTYPE vt; | 263 | VARTYPE vt; |
208 | } STATPROPSTG; | 264 | } STATPROPSTG; |
209 | 265 | ||
210 | MY_EXTERN_C BSTR SysAllocStringByteLen(LPCSTR psz, UINT len); | 266 | EXTERN_C BSTR SysAllocStringByteLen(LPCSTR psz, UINT len); |
211 | MY_EXTERN_C BSTR SysAllocStringLen(const OLECHAR *sz, UINT len); | 267 | EXTERN_C BSTR SysAllocStringLen(const OLECHAR *sz, UINT len); |
212 | MY_EXTERN_C BSTR SysAllocString(const OLECHAR *sz); | 268 | EXTERN_C BSTR SysAllocString(const OLECHAR *sz); |
213 | MY_EXTERN_C void SysFreeString(BSTR bstr); | 269 | EXTERN_C void SysFreeString(BSTR bstr); |
214 | MY_EXTERN_C UINT SysStringByteLen(BSTR bstr); | 270 | EXTERN_C UINT SysStringByteLen(BSTR bstr); |
215 | MY_EXTERN_C UINT SysStringLen(BSTR bstr); | 271 | EXTERN_C UINT SysStringLen(BSTR bstr); |
216 | 272 | ||
217 | MY_EXTERN_C DWORD GetLastError(); | 273 | EXTERN_C DWORD GetLastError(); |
218 | MY_EXTERN_C void SetLastError(DWORD dwCode); | 274 | EXTERN_C void SetLastError(DWORD dwCode); |
219 | MY_EXTERN_C LONG CompareFileTime(const FILETIME* ft1, const FILETIME* ft2); | 275 | EXTERN_C LONG CompareFileTime(const FILETIME* ft1, const FILETIME* ft2); |
220 | 276 | ||
221 | MY_EXTERN_C DWORD GetCurrentThreadId(); | 277 | EXTERN_C DWORD GetCurrentThreadId(); |
222 | MY_EXTERN_C DWORD GetCurrentProcessId(); | 278 | EXTERN_C DWORD GetCurrentProcessId(); |
223 | 279 | ||
224 | #define MAX_PATH 1024 | 280 | #define MAX_PATH 1024 |
225 | 281 | ||
diff --git a/CPP/Common/MyXml.cpp b/CPP/Common/MyXml.cpp index e014518..a879d34 100644 --- a/CPP/Common/MyXml.cpp +++ b/CPP/Common/MyXml.cpp | |||
@@ -81,7 +81,7 @@ AString CXmlItem::GetSubStringForTag(const char *tag) const | |||
81 | 81 | ||
82 | const char * CXmlItem::ParseItem(const char *s, int numAllowedLevels) | 82 | const char * CXmlItem::ParseItem(const char *s, int numAllowedLevels) |
83 | { | 83 | { |
84 | SKIP_SPACES(s); | 84 | SKIP_SPACES(s) |
85 | 85 | ||
86 | const char *beg = s; | 86 | const char *beg = s; |
87 | for (;;) | 87 | for (;;) |
@@ -102,7 +102,7 @@ const char * CXmlItem::ParseItem(const char *s, int numAllowedLevels) | |||
102 | IsTag = true; | 102 | IsTag = true; |
103 | 103 | ||
104 | s++; | 104 | s++; |
105 | SKIP_SPACES(s); | 105 | SKIP_SPACES(s) |
106 | 106 | ||
107 | beg = s; | 107 | beg = s; |
108 | for (;; s++) | 108 | for (;; s++) |
@@ -115,11 +115,11 @@ const char * CXmlItem::ParseItem(const char *s, int numAllowedLevels) | |||
115 | for (;;) | 115 | for (;;) |
116 | { | 116 | { |
117 | beg = s; | 117 | beg = s; |
118 | SKIP_SPACES(s); | 118 | SKIP_SPACES(s) |
119 | if (*s == '/') | 119 | if (*s == '/') |
120 | { | 120 | { |
121 | s++; | 121 | s++; |
122 | // SKIP_SPACES(s); | 122 | // SKIP_SPACES(s) |
123 | if (*s != '>') | 123 | if (*s != '>') |
124 | return NULL; | 124 | return NULL; |
125 | return s + 1; | 125 | return s + 1; |
@@ -132,7 +132,7 @@ const char * CXmlItem::ParseItem(const char *s, int numAllowedLevels) | |||
132 | SubItems.Clear(); | 132 | SubItems.Clear(); |
133 | for (;;) | 133 | for (;;) |
134 | { | 134 | { |
135 | SKIP_SPACES(s); | 135 | SKIP_SPACES(s) |
136 | if (s[0] == '<' && s[1] == '/') | 136 | if (s[0] == '<' && s[1] == '/') |
137 | break; | 137 | break; |
138 | CXmlItem &item = SubItems.AddNew(); | 138 | CXmlItem &item = SubItems.AddNew(); |
@@ -168,11 +168,11 @@ const char * CXmlItem::ParseItem(const char *s, int numAllowedLevels) | |||
168 | return NULL; | 168 | return NULL; |
169 | prop.Name.SetFrom(beg, (unsigned)(s - beg)); | 169 | prop.Name.SetFrom(beg, (unsigned)(s - beg)); |
170 | 170 | ||
171 | SKIP_SPACES(s); | 171 | SKIP_SPACES(s) |
172 | if (*s != '=') | 172 | if (*s != '=') |
173 | return NULL; | 173 | return NULL; |
174 | s++; | 174 | s++; |
175 | SKIP_SPACES(s); | 175 | SKIP_SPACES(s) |
176 | if (*s != '\"') | 176 | if (*s != '\"') |
177 | return NULL; | 177 | return NULL; |
178 | s++; | 178 | s++; |
@@ -194,7 +194,7 @@ const char * CXmlItem::ParseItem(const char *s, int numAllowedLevels) | |||
194 | 194 | ||
195 | static const char * SkipHeader(const char *s, const char *startString, const char *endString) | 195 | static const char * SkipHeader(const char *s, const char *startString, const char *endString) |
196 | { | 196 | { |
197 | SKIP_SPACES(s); | 197 | SKIP_SPACES(s) |
198 | if (IsString1PrefixedByString2(s, startString)) | 198 | if (IsString1PrefixedByString2(s, startString)) |
199 | { | 199 | { |
200 | s = strstr(s, endString); | 200 | s = strstr(s, endString); |
@@ -215,7 +215,7 @@ void CXmlItem::AppendTo(AString &s) const | |||
215 | FOR_VECTOR (i, Props) | 215 | FOR_VECTOR (i, Props) |
216 | { | 216 | { |
217 | const CXmlProp &prop = Props[i]; | 217 | const CXmlProp &prop = Props[i]; |
218 | s += ' '; | 218 | s.Add_Space(); |
219 | s += prop.Name; | 219 | s += prop.Name; |
220 | s += '='; | 220 | s += '='; |
221 | s += '\"'; | 221 | s += '\"'; |
@@ -228,7 +228,7 @@ void CXmlItem::AppendTo(AString &s) const | |||
228 | { | 228 | { |
229 | const CXmlItem &item = SubItems[i]; | 229 | const CXmlItem &item = SubItems[i]; |
230 | if (i != 0 && !SubItems[i - 1].IsTag) | 230 | if (i != 0 && !SubItems[i - 1].IsTag) |
231 | s += ' '; | 231 | s.Add_Space(); |
232 | item.AppendTo(s); | 232 | item.AppendTo(s); |
233 | } | 233 | } |
234 | if (IsTag) | 234 | if (IsTag) |
@@ -248,7 +248,7 @@ bool CXml::Parse(const char *s) | |||
248 | s = Root.ParseItem(s, 1000); | 248 | s = Root.ParseItem(s, 1000); |
249 | if (!s || !Root.IsTag) | 249 | if (!s || !Root.IsTag) |
250 | return false; | 250 | return false; |
251 | SKIP_SPACES(s); | 251 | SKIP_SPACES(s) |
252 | return *s == 0; | 252 | return *s == 0; |
253 | } | 253 | } |
254 | 254 | ||
diff --git a/CPP/Common/MyXml.h b/CPP/Common/MyXml.h index 00b7113..5362602 100644 --- a/CPP/Common/MyXml.h +++ b/CPP/Common/MyXml.h | |||
@@ -1,7 +1,7 @@ | |||
1 | // MyXml.h | 1 | // MyXml.h |
2 | 2 | ||
3 | #ifndef __MY_XML_H | 3 | #ifndef ZIP7_INC_MY_XML_H |
4 | #define __MY_XML_H | 4 | #define ZIP7_INC_MY_XML_H |
5 | 5 | ||
6 | #include "MyString.h" | 6 | #include "MyString.h" |
7 | 7 | ||
diff --git a/CPP/Common/NewHandler.cpp b/CPP/Common/NewHandler.cpp index 65ef41d..c95833e 100644 --- a/CPP/Common/NewHandler.cpp +++ b/CPP/Common/NewHandler.cpp | |||
@@ -10,21 +10,23 @@ | |||
10 | 10 | ||
11 | #ifndef DEBUG_MEMORY_LEAK | 11 | #ifndef DEBUG_MEMORY_LEAK |
12 | 12 | ||
13 | #ifdef _7ZIP_REDEFINE_OPERATOR_NEW | 13 | #ifdef Z7_REDEFINE_OPERATOR_NEW |
14 | 14 | ||
15 | /* | 15 | /* |
16 | void * my_new(size_t size) | 16 | void * my_new(size_t size) |
17 | { | 17 | { |
18 | // void *p = ::HeapAlloc(::GetProcessHeap(), 0, size); | 18 | // void *p = ::HeapAlloc(::GetProcessHeap(), 0, size); |
19 | if (size == 0) | ||
20 | size = 1; | ||
19 | void *p = ::malloc(size); | 21 | void *p = ::malloc(size); |
20 | if (p == 0) | 22 | if (!p) |
21 | throw CNewException(); | 23 | throw CNewException(); |
22 | return p; | 24 | return p; |
23 | } | 25 | } |
24 | 26 | ||
25 | void my_delete(void *p) throw() | 27 | void my_delete(void *p) throw() |
26 | { | 28 | { |
27 | // if (p == 0) return; ::HeapFree(::GetProcessHeap(), 0, p); | 29 | // if (!p) return; ::HeapFree(::GetProcessHeap(), 0, p); |
28 | ::free(p); | 30 | ::free(p); |
29 | } | 31 | } |
30 | 32 | ||
@@ -44,9 +46,21 @@ __cdecl | |||
44 | #endif | 46 | #endif |
45 | operator new(size_t size) | 47 | operator new(size_t size) |
46 | { | 48 | { |
49 | /* by C++ specification: | ||
50 | if (size == 0), operator new(size) returns non_NULL pointer. | ||
51 | If (operator new(0) returns NULL), it's out of specification. | ||
52 | but some calling code can work correctly even in this case too. */ | ||
53 | // if (size == 0) return NULL; // for debug only. don't use it | ||
54 | |||
55 | /* malloc(0) returns non_NULL in main compilers, as we need here. | ||
56 | But specification also allows malloc(0) to return NULL. | ||
57 | So we change (size=0) to (size=1) here to get real non_NULL pointer */ | ||
58 | if (size == 0) | ||
59 | size = 1; | ||
47 | // void *p = ::HeapAlloc(::GetProcessHeap(), 0, size); | 60 | // void *p = ::HeapAlloc(::GetProcessHeap(), 0, size); |
61 | // void *p = ::MyAlloc(size); // note: MyAlloc(0) returns NULL | ||
48 | void *p = ::malloc(size); | 62 | void *p = ::malloc(size); |
49 | if (p == 0) | 63 | if (!p) |
50 | throw CNewException(); | 64 | throw CNewException(); |
51 | return p; | 65 | return p; |
52 | } | 66 | } |
@@ -57,7 +71,8 @@ __cdecl | |||
57 | #endif | 71 | #endif |
58 | operator delete(void *p) throw() | 72 | operator delete(void *p) throw() |
59 | { | 73 | { |
60 | // if (p == 0) return; ::HeapFree(::GetProcessHeap(), 0, p); | 74 | // if (!p) return; ::HeapFree(::GetProcessHeap(), 0, p); |
75 | // MyFree(p); | ||
61 | ::free(p); | 76 | ::free(p); |
62 | } | 77 | } |
63 | 78 | ||
@@ -69,8 +84,10 @@ __cdecl | |||
69 | operator new[](size_t size) | 84 | operator new[](size_t size) |
70 | { | 85 | { |
71 | // void *p = ::HeapAlloc(::GetProcessHeap(), 0, size); | 86 | // void *p = ::HeapAlloc(::GetProcessHeap(), 0, size); |
87 | if (size == 0) | ||
88 | size = 1; | ||
72 | void *p = ::malloc(size); | 89 | void *p = ::malloc(size); |
73 | if (p == 0) | 90 | if (!p) |
74 | throw CNewException(); | 91 | throw CNewException(); |
75 | return p; | 92 | return p; |
76 | } | 93 | } |
@@ -81,7 +98,7 @@ __cdecl | |||
81 | #endif | 98 | #endif |
82 | operator delete[](void *p) throw() | 99 | operator delete[](void *p) throw() |
83 | { | 100 | { |
84 | // if (p == 0) return; ::HeapFree(::GetProcessHeap(), 0, p); | 101 | // if (!p) return; ::HeapFree(::GetProcessHeap(), 0, p); |
85 | ::free(p); | 102 | ::free(p); |
86 | } | 103 | } |
87 | */ | 104 | */ |
@@ -93,16 +110,43 @@ operator delete[](void *p) throw() | |||
93 | #include <stdio.h> | 110 | #include <stdio.h> |
94 | 111 | ||
95 | // #pragma init_seg(lib) | 112 | // #pragma init_seg(lib) |
113 | /* | ||
96 | const int kDebugSize = 1000000; | 114 | const int kDebugSize = 1000000; |
97 | static void *a[kDebugSize]; | 115 | static void *a[kDebugSize]; |
98 | static int index = 0; | 116 | static int g_index = 0; |
117 | |||
118 | class CC | ||
119 | { | ||
120 | public: | ||
121 | CC() | ||
122 | { | ||
123 | for (int i = 0; i < kDebugSize; i++) | ||
124 | a[i] = 0; | ||
125 | } | ||
126 | ~CC() | ||
127 | { | ||
128 | printf("\nDestructor: %d\n", numAllocs); | ||
129 | for (int i = 0; i < kDebugSize; i++) | ||
130 | if (a[i] != 0) | ||
131 | return; | ||
132 | } | ||
133 | } g_CC; | ||
134 | */ | ||
99 | 135 | ||
136 | #ifdef _WIN32 | ||
100 | static bool wasInit = false; | 137 | static bool wasInit = false; |
101 | static CRITICAL_SECTION cs; | 138 | static CRITICAL_SECTION cs; |
139 | #endif | ||
102 | 140 | ||
103 | static int numAllocs = 0; | 141 | static int numAllocs = 0; |
104 | void * __cdecl operator new(size_t size) | 142 | |
143 | void * | ||
144 | #ifdef _MSC_VER | ||
145 | __cdecl | ||
146 | #endif | ||
147 | operator new(size_t size) | ||
105 | { | 148 | { |
149 | #ifdef _WIN32 | ||
106 | if (!wasInit) | 150 | if (!wasInit) |
107 | { | 151 | { |
108 | InitializeCriticalSection(&cs); | 152 | InitializeCriticalSection(&cs); |
@@ -114,52 +158,126 @@ void * __cdecl operator new(size_t size) | |||
114 | int loc = numAllocs; | 158 | int loc = numAllocs; |
115 | void *p = HeapAlloc(GetProcessHeap(), 0, size); | 159 | void *p = HeapAlloc(GetProcessHeap(), 0, size); |
116 | /* | 160 | /* |
117 | if (index < kDebugSize) | 161 | if (g_index < kDebugSize) |
118 | { | 162 | { |
119 | a[index] = p; | 163 | a[g_index] = p; |
120 | index++; | 164 | g_index++; |
121 | } | 165 | } |
122 | */ | 166 | */ |
123 | printf("Alloc %6d, size = %8u\n", loc, (unsigned)size); | 167 | printf("Alloc %6d, size = %8u\n", loc, (unsigned)size); |
124 | LeaveCriticalSection(&cs); | 168 | LeaveCriticalSection(&cs); |
125 | if (p == 0) | 169 | if (!p) |
126 | throw CNewException(); | 170 | throw CNewException(); |
127 | return p; | 171 | return p; |
128 | } | 172 | #else |
129 | 173 | numAllocs++; | |
130 | class CC | 174 | int loc = numAllocs; |
131 | { | 175 | if (size == 0) |
132 | public: | 176 | size = 1; |
133 | CC() | 177 | void *p = malloc(size); |
134 | { | 178 | /* |
135 | for (int i = 0; i < kDebugSize; i++) | 179 | if (g_index < kDebugSize) |
136 | a[i] = 0; | ||
137 | } | ||
138 | ~CC() | ||
139 | { | 180 | { |
140 | printf("\nDestructor: %d\n", numAllocs); | 181 | a[g_index] = p; |
141 | for (int i = 0; i < kDebugSize; i++) | 182 | g_index++; |
142 | if (a[i] != 0) | ||
143 | return; | ||
144 | } | 183 | } |
145 | } g_CC; | 184 | */ |
146 | 185 | printf("Alloc %6d, size = %8u\n", loc, (unsigned)size); | |
186 | if (!p) | ||
187 | throw CNewException(); | ||
188 | return p; | ||
189 | #endif | ||
190 | } | ||
147 | 191 | ||
148 | void __cdecl operator delete(void *p) | 192 | void |
193 | #ifdef _MSC_VER | ||
194 | __cdecl | ||
195 | #endif | ||
196 | operator delete(void *p) throw() | ||
149 | { | 197 | { |
150 | if (p == 0) | 198 | if (!p) |
151 | return; | 199 | return; |
200 | #ifdef _WIN32 | ||
152 | EnterCriticalSection(&cs); | 201 | EnterCriticalSection(&cs); |
153 | /* | 202 | /* |
154 | for (int i = 0; i < index; i++) | 203 | for (int i = 0; i < g_index; i++) |
155 | if (a[i] == p) | 204 | if (a[i] == p) |
156 | a[i] = 0; | 205 | a[i] = 0; |
157 | */ | 206 | */ |
158 | HeapFree(GetProcessHeap(), 0, p); | 207 | HeapFree(GetProcessHeap(), 0, p); |
208 | if (numAllocs == 0) | ||
209 | numAllocs = numAllocs; // ERROR | ||
159 | numAllocs--; | 210 | numAllocs--; |
211 | if (numAllocs == 0) | ||
212 | numAllocs = numAllocs; // OK: all objects were deleted | ||
160 | printf("Free %d\n", numAllocs); | 213 | printf("Free %d\n", numAllocs); |
161 | LeaveCriticalSection(&cs); | 214 | LeaveCriticalSection(&cs); |
215 | #else | ||
216 | free(p); | ||
217 | numAllocs--; | ||
218 | printf("Free %d\n", numAllocs); | ||
219 | #endif | ||
220 | } | ||
221 | |||
222 | /* | ||
223 | void * | ||
224 | #ifdef _MSC_VER | ||
225 | __cdecl | ||
226 | #endif | ||
227 | operator new[](size_t size) | ||
228 | { | ||
229 | printf("operator_new[] : "); | ||
230 | return operator new(size); | ||
231 | } | ||
232 | |||
233 | void | ||
234 | #ifdef _MSC_VER | ||
235 | __cdecl | ||
236 | #endif | ||
237 | operator delete(void *p, size_t sz) throw(); | ||
238 | |||
239 | void | ||
240 | #ifdef _MSC_VER | ||
241 | __cdecl | ||
242 | #endif | ||
243 | operator delete(void *p, size_t sz) throw() | ||
244 | { | ||
245 | if (!p) | ||
246 | return; | ||
247 | printf("operator_delete_size : size=%d : ", (unsigned)sz); | ||
248 | operator delete(p); | ||
249 | } | ||
250 | |||
251 | void | ||
252 | #ifdef _MSC_VER | ||
253 | __cdecl | ||
254 | #endif | ||
255 | operator delete[](void *p) throw() | ||
256 | { | ||
257 | if (!p) | ||
258 | return; | ||
259 | printf("operator_delete[] : "); | ||
260 | operator delete(p); | ||
261 | } | ||
262 | |||
263 | void | ||
264 | #ifdef _MSC_VER | ||
265 | __cdecl | ||
266 | #endif | ||
267 | operator delete[](void *p, size_t sz) throw(); | ||
268 | |||
269 | void | ||
270 | #ifdef _MSC_VER | ||
271 | __cdecl | ||
272 | #endif | ||
273 | operator delete[](void *p, size_t sz) throw() | ||
274 | { | ||
275 | if (!p) | ||
276 | return; | ||
277 | printf("operator_delete_size[] : size=%d : ", (unsigned)sz); | ||
278 | operator delete(p); | ||
162 | } | 279 | } |
280 | */ | ||
163 | 281 | ||
164 | #endif | 282 | #endif |
165 | 283 | ||
diff --git a/CPP/Common/NewHandler.h b/CPP/Common/NewHandler.h index aedeca6..50f6d0a 100644 --- a/CPP/Common/NewHandler.h +++ b/CPP/Common/NewHandler.h | |||
@@ -1,7 +1,7 @@ | |||
1 | // Common/NewHandler.h | 1 | // Common/NewHandler.h |
2 | 2 | ||
3 | #ifndef __COMMON_NEW_HANDLER_H | 3 | #ifndef ZIP7_INC_COMMON_NEW_HANDLER_H |
4 | #define __COMMON_NEW_HANDLER_H | 4 | #define ZIP7_INC_COMMON_NEW_HANDLER_H |
5 | 5 | ||
6 | /* | 6 | /* |
7 | NewHandler.h and NewHandler.cpp allows to solve problem with compilers that | 7 | NewHandler.h and NewHandler.cpp allows to solve problem with compilers that |
@@ -10,6 +10,16 @@ don't throw exception in operator new(). | |||
10 | This file must be included before any code that uses operators new() or delete() | 10 | This file must be included before any code that uses operators new() or delete() |
11 | and you must compile and link "NewHandler.cpp", if you use some old MSVC compiler. | 11 | and you must compile and link "NewHandler.cpp", if you use some old MSVC compiler. |
12 | 12 | ||
13 | DOCs: | ||
14 | Since ISO C++98, operator new throws std::bad_alloc when memory allocation fails. | ||
15 | MSVC 6.0 returned a null pointer on an allocation failure. | ||
16 | Beginning in VS2002, operator new conforms to the standard and throws on failure. | ||
17 | |||
18 | By default, the compiler also generates defensive null checks to prevent | ||
19 | these older-style allocators from causing an immediate crash on failure. | ||
20 | The /Zc:throwingNew option tells the compiler to leave out these null checks, | ||
21 | on the assumption that all linked memory allocators conform to the standard. | ||
22 | |||
13 | The operator new() in some MSVC versions doesn't throw exception std::bad_alloc. | 23 | The operator new() in some MSVC versions doesn't throw exception std::bad_alloc. |
14 | MSVC 6.0 (_MSC_VER == 1200) doesn't throw exception. | 24 | MSVC 6.0 (_MSC_VER == 1200) doesn't throw exception. |
15 | The code produced by some another MSVC compilers also can be linked | 25 | The code produced by some another MSVC compilers also can be linked |
@@ -36,13 +46,13 @@ void my_delete(void *p) throw(); | |||
36 | #endif | 46 | #endif |
37 | 47 | ||
38 | 48 | ||
39 | #if defined(_MSC_VER) && (_MSC_VER < 1900) | 49 | #if defined(_MSC_VER) && (_MSC_VER < 1600) |
40 | // If you want to use default operator new(), you can disable the following line | 50 | // If you want to use default operator new(), you can disable the following line |
41 | #define _7ZIP_REDEFINE_OPERATOR_NEW | 51 | #define Z7_REDEFINE_OPERATOR_NEW |
42 | #endif | 52 | #endif |
43 | 53 | ||
44 | 54 | ||
45 | #ifdef _7ZIP_REDEFINE_OPERATOR_NEW | 55 | #ifdef Z7_REDEFINE_OPERATOR_NEW |
46 | 56 | ||
47 | // std::bad_alloc can require additional DLL dependency. | 57 | // std::bad_alloc can require additional DLL dependency. |
48 | // So we don't define CNewException as std::bad_alloc here. | 58 | // So we don't define CNewException as std::bad_alloc here. |
diff --git a/CPP/Common/Random.h b/CPP/Common/Random.h index e784e98..283869e 100644 --- a/CPP/Common/Random.h +++ b/CPP/Common/Random.h | |||
@@ -1,7 +1,7 @@ | |||
1 | // Common/Random.h | 1 | // Common/Random.h |
2 | 2 | ||
3 | #ifndef __COMMON_RANDOM_H | 3 | #ifndef ZIP7_INC_COMMON_RANDOM_H |
4 | #define __COMMON_RANDOM_H | 4 | #define ZIP7_INC_COMMON_RANDOM_H |
5 | 5 | ||
6 | class CRandom | 6 | class CRandom |
7 | { | 7 | { |
diff --git a/CPP/Common/Sha1Reg.cpp b/CPP/Common/Sha1Reg.cpp index 0cb2baf..64eef34 100644 --- a/CPP/Common/Sha1Reg.cpp +++ b/CPP/Common/Sha1Reg.cpp | |||
@@ -9,13 +9,14 @@ | |||
9 | 9 | ||
10 | #include "../7zip/Common/RegisterCodec.h" | 10 | #include "../7zip/Common/RegisterCodec.h" |
11 | 11 | ||
12 | class CSha1Hasher: | 12 | Z7_CLASS_IMP_COM_2( |
13 | public IHasher, | 13 | CSha1Hasher |
14 | public ICompressSetCoderProperties, | 14 | , IHasher |
15 | public CMyUnknownImp | 15 | , ICompressSetCoderProperties |
16 | { | 16 | ) |
17 | CAlignedBuffer _buf; | 17 | CAlignedBuffer1 _buf; |
18 | Byte mtDummy[1 << 7]; | 18 | public: |
19 | Byte _mtDummy[1 << 7]; | ||
19 | 20 | ||
20 | CSha1 *Sha() { return (CSha1 *)(void *)(Byte *)_buf; } | 21 | CSha1 *Sha() { return (CSha1 *)(void *)(Byte *)_buf; } |
21 | public: | 22 | public: |
@@ -25,36 +26,32 @@ public: | |||
25 | Sha1_SetFunction(Sha(), 0); | 26 | Sha1_SetFunction(Sha(), 0); |
26 | Sha1_InitState(Sha()); | 27 | Sha1_InitState(Sha()); |
27 | } | 28 | } |
28 | |||
29 | MY_UNKNOWN_IMP2(IHasher, ICompressSetCoderProperties) | ||
30 | INTERFACE_IHasher(;) | ||
31 | STDMETHOD(SetCoderProperties)(const PROPID *propIDs, const PROPVARIANT *props, UInt32 numProps); | ||
32 | }; | 29 | }; |
33 | 30 | ||
34 | STDMETHODIMP_(void) CSha1Hasher::Init() throw() | 31 | Z7_COM7F_IMF2(void, CSha1Hasher::Init()) |
35 | { | 32 | { |
36 | Sha1_InitState(Sha()); | 33 | Sha1_InitState(Sha()); |
37 | } | 34 | } |
38 | 35 | ||
39 | STDMETHODIMP_(void) CSha1Hasher::Update(const void *data, UInt32 size) throw() | 36 | Z7_COM7F_IMF2(void, CSha1Hasher::Update(const void *data, UInt32 size)) |
40 | { | 37 | { |
41 | Sha1_Update(Sha(), (const Byte *)data, size); | 38 | Sha1_Update(Sha(), (const Byte *)data, size); |
42 | } | 39 | } |
43 | 40 | ||
44 | STDMETHODIMP_(void) CSha1Hasher::Final(Byte *digest) throw() | 41 | Z7_COM7F_IMF2(void, CSha1Hasher::Final(Byte *digest)) |
45 | { | 42 | { |
46 | Sha1_Final(Sha(), digest); | 43 | Sha1_Final(Sha(), digest); |
47 | } | 44 | } |
48 | 45 | ||
49 | 46 | ||
50 | STDMETHODIMP CSha1Hasher::SetCoderProperties(const PROPID *propIDs, const PROPVARIANT *coderProps, UInt32 numProps) | 47 | Z7_COM7F_IMF(CSha1Hasher::SetCoderProperties(const PROPID *propIDs, const PROPVARIANT *coderProps, UInt32 numProps)) |
51 | { | 48 | { |
52 | unsigned algo = 0; | 49 | unsigned algo = 0; |
53 | for (UInt32 i = 0; i < numProps; i++) | 50 | for (UInt32 i = 0; i < numProps; i++) |
54 | { | 51 | { |
55 | const PROPVARIANT &prop = coderProps[i]; | ||
56 | if (propIDs[i] == NCoderPropID::kDefaultProp) | 52 | if (propIDs[i] == NCoderPropID::kDefaultProp) |
57 | { | 53 | { |
54 | const PROPVARIANT &prop = coderProps[i]; | ||
58 | if (prop.vt != VT_UI4) | 55 | if (prop.vt != VT_UI4) |
59 | return E_INVALIDARG; | 56 | return E_INVALIDARG; |
60 | if (prop.ulVal > 2) | 57 | if (prop.ulVal > 2) |
diff --git a/CPP/Common/Sha256Reg.cpp b/CPP/Common/Sha256Reg.cpp index 5f3a35b..b5689c4 100644 --- a/CPP/Common/Sha256Reg.cpp +++ b/CPP/Common/Sha256Reg.cpp | |||
@@ -9,13 +9,14 @@ | |||
9 | 9 | ||
10 | #include "../7zip/Common/RegisterCodec.h" | 10 | #include "../7zip/Common/RegisterCodec.h" |
11 | 11 | ||
12 | class CSha256Hasher: | 12 | Z7_CLASS_IMP_COM_2( |
13 | public IHasher, | 13 | CSha256Hasher |
14 | public ICompressSetCoderProperties, | 14 | , IHasher |
15 | public CMyUnknownImp | 15 | , ICompressSetCoderProperties |
16 | { | 16 | ) |
17 | CAlignedBuffer _buf; | 17 | CAlignedBuffer1 _buf; |
18 | Byte mtDummy[1 << 7]; | 18 | public: |
19 | Byte _mtDummy[1 << 7]; | ||
19 | 20 | ||
20 | CSha256 *Sha() { return (CSha256 *)(void *)(Byte *)_buf; } | 21 | CSha256 *Sha() { return (CSha256 *)(void *)(Byte *)_buf; } |
21 | public: | 22 | public: |
@@ -25,36 +26,32 @@ public: | |||
25 | Sha256_SetFunction(Sha(), 0); | 26 | Sha256_SetFunction(Sha(), 0); |
26 | Sha256_InitState(Sha()); | 27 | Sha256_InitState(Sha()); |
27 | } | 28 | } |
28 | |||
29 | MY_UNKNOWN_IMP2(IHasher, ICompressSetCoderProperties) | ||
30 | INTERFACE_IHasher(;) | ||
31 | STDMETHOD(SetCoderProperties)(const PROPID *propIDs, const PROPVARIANT *props, UInt32 numProps); | ||
32 | }; | 29 | }; |
33 | 30 | ||
34 | STDMETHODIMP_(void) CSha256Hasher::Init() throw() | 31 | Z7_COM7F_IMF2(void, CSha256Hasher::Init()) |
35 | { | 32 | { |
36 | Sha256_InitState(Sha()); | 33 | Sha256_InitState(Sha()); |
37 | } | 34 | } |
38 | 35 | ||
39 | STDMETHODIMP_(void) CSha256Hasher::Update(const void *data, UInt32 size) throw() | 36 | Z7_COM7F_IMF2(void, CSha256Hasher::Update(const void *data, UInt32 size)) |
40 | { | 37 | { |
41 | Sha256_Update(Sha(), (const Byte *)data, size); | 38 | Sha256_Update(Sha(), (const Byte *)data, size); |
42 | } | 39 | } |
43 | 40 | ||
44 | STDMETHODIMP_(void) CSha256Hasher::Final(Byte *digest) throw() | 41 | Z7_COM7F_IMF2(void, CSha256Hasher::Final(Byte *digest)) |
45 | { | 42 | { |
46 | Sha256_Final(Sha(), digest); | 43 | Sha256_Final(Sha(), digest); |
47 | } | 44 | } |
48 | 45 | ||
49 | 46 | ||
50 | STDMETHODIMP CSha256Hasher::SetCoderProperties(const PROPID *propIDs, const PROPVARIANT *coderProps, UInt32 numProps) | 47 | Z7_COM7F_IMF(CSha256Hasher::SetCoderProperties(const PROPID *propIDs, const PROPVARIANT *coderProps, UInt32 numProps)) |
51 | { | 48 | { |
52 | unsigned algo = 0; | 49 | unsigned algo = 0; |
53 | for (UInt32 i = 0; i < numProps; i++) | 50 | for (UInt32 i = 0; i < numProps; i++) |
54 | { | 51 | { |
55 | const PROPVARIANT &prop = coderProps[i]; | ||
56 | if (propIDs[i] == NCoderPropID::kDefaultProp) | 52 | if (propIDs[i] == NCoderPropID::kDefaultProp) |
57 | { | 53 | { |
54 | const PROPVARIANT &prop = coderProps[i]; | ||
58 | if (prop.vt != VT_UI4) | 55 | if (prop.vt != VT_UI4) |
59 | return E_INVALIDARG; | 56 | return E_INVALIDARG; |
60 | if (prop.ulVal > 2) | 57 | if (prop.ulVal > 2) |
diff --git a/CPP/Common/StdAfx.h b/CPP/Common/StdAfx.h index 420f5c3..a5228b0 100644 --- a/CPP/Common/StdAfx.h +++ b/CPP/Common/StdAfx.h | |||
@@ -1,7 +1,7 @@ | |||
1 | // StdAfx.h | 1 | // StdAfx.h |
2 | 2 | ||
3 | #ifndef __STDAFX_H | 3 | #ifndef ZIP7_INC_STDAFX_H |
4 | #define __STDAFX_H | 4 | #define ZIP7_INC_STDAFX_H |
5 | 5 | ||
6 | #include "Common.h" | 6 | #include "Common.h" |
7 | 7 | ||
diff --git a/CPP/Common/StdInStream.cpp b/CPP/Common/StdInStream.cpp index abad34b..7b209f1 100644 --- a/CPP/Common/StdInStream.cpp +++ b/CPP/Common/StdInStream.cpp | |||
@@ -14,10 +14,12 @@ | |||
14 | // #define kReadErrorMessage "Error reading input stream" | 14 | // #define kReadErrorMessage "Error reading input stream" |
15 | // #define kIllegalCharMessage "Illegal zero character in input stream" | 15 | // #define kIllegalCharMessage "Illegal zero character in input stream" |
16 | 16 | ||
17 | #define kFileOpenMode TEXT("r") | ||
18 | 17 | ||
19 | CStdInStream g_StdIn(stdin); | 18 | CStdInStream g_StdIn(stdin); |
20 | 19 | ||
20 | /* | ||
21 | #define kFileOpenMode TEXT("r") | ||
22 | |||
21 | bool CStdInStream::Open(LPCTSTR fileName) throw() | 23 | bool CStdInStream::Open(LPCTSTR fileName) throw() |
22 | { | 24 | { |
23 | Close(); | 25 | Close(); |
@@ -39,6 +41,7 @@ bool CStdInStream::Close() throw() | |||
39 | _streamIsOpen = (fclose(_stream) != 0); | 41 | _streamIsOpen = (fclose(_stream) != 0); |
40 | return !_streamIsOpen; | 42 | return !_streamIsOpen; |
41 | } | 43 | } |
44 | */ | ||
42 | 45 | ||
43 | bool CStdInStream::ScanAStringUntilNewLine(AString &s) | 46 | bool CStdInStream::ScanAStringUntilNewLine(AString &s) |
44 | { | 47 | { |
diff --git a/CPP/Common/StdInStream.h b/CPP/Common/StdInStream.h index 71578eb..81ca3bf 100644 --- a/CPP/Common/StdInStream.h +++ b/CPP/Common/StdInStream.h | |||
@@ -1,7 +1,7 @@ | |||
1 | // Common/StdInStream.h | 1 | // Common/StdInStream.h |
2 | 2 | ||
3 | #ifndef __COMMON_STD_IN_STREAM_H | 3 | #ifndef ZIP7_INC_COMMON_STD_IN_STREAM_H |
4 | #define __COMMON_STD_IN_STREAM_H | 4 | #define ZIP7_INC_COMMON_STD_IN_STREAM_H |
5 | 5 | ||
6 | #include <stdio.h> | 6 | #include <stdio.h> |
7 | 7 | ||
@@ -11,20 +11,22 @@ | |||
11 | class CStdInStream | 11 | class CStdInStream |
12 | { | 12 | { |
13 | FILE *_stream; | 13 | FILE *_stream; |
14 | bool _streamIsOpen; | 14 | // bool _streamIsOpen; |
15 | public: | 15 | public: |
16 | int CodePage; | 16 | int CodePage; |
17 | 17 | ||
18 | CStdInStream(FILE *stream = NULL): | 18 | CStdInStream(FILE *stream = NULL): |
19 | _stream(stream), | 19 | _stream(stream), |
20 | _streamIsOpen(false), | 20 | // _streamIsOpen(false), |
21 | CodePage(-1) | 21 | CodePage(-1) |
22 | {}; | 22 | {} |
23 | 23 | ||
24 | /* | ||
24 | ~CStdInStream() { Close(); } | 25 | ~CStdInStream() { Close(); } |
25 | 26 | ||
26 | bool Open(LPCTSTR fileName) throw(); | 27 | bool Open(LPCTSTR fileName) throw(); |
27 | bool Close() throw(); | 28 | bool Close() throw(); |
29 | */ | ||
28 | 30 | ||
29 | // returns: | 31 | // returns: |
30 | // false, if ZERO character in stream | 32 | // false, if ZERO character in stream |
diff --git a/CPP/Common/StdOutStream.cpp b/CPP/Common/StdOutStream.cpp index 40799e2..cfa5fde 100644 --- a/CPP/Common/StdOutStream.cpp +++ b/CPP/Common/StdOutStream.cpp | |||
@@ -11,11 +11,12 @@ | |||
11 | #include "StringConvert.h" | 11 | #include "StringConvert.h" |
12 | #include "UTFConvert.h" | 12 | #include "UTFConvert.h" |
13 | 13 | ||
14 | #define kFileOpenMode "wt" | ||
15 | |||
16 | CStdOutStream g_StdOut(stdout); | 14 | CStdOutStream g_StdOut(stdout); |
17 | CStdOutStream g_StdErr(stderr); | 15 | CStdOutStream g_StdErr(stderr); |
18 | 16 | ||
17 | /* | ||
18 | // #define kFileOpenMode "wt" | ||
19 | |||
19 | bool CStdOutStream::Open(const char *fileName) throw() | 20 | bool CStdOutStream::Open(const char *fileName) throw() |
20 | { | 21 | { |
21 | Close(); | 22 | Close(); |
@@ -34,6 +35,7 @@ bool CStdOutStream::Close() throw() | |||
34 | _streamIsOpen = false; | 35 | _streamIsOpen = false; |
35 | return true; | 36 | return true; |
36 | } | 37 | } |
38 | */ | ||
37 | 39 | ||
38 | bool CStdOutStream::Flush() throw() | 40 | bool CStdOutStream::Flush() throw() |
39 | { | 41 | { |
@@ -73,7 +75,7 @@ void CStdOutStream::Convert_UString_to_AString(const UString &src, AString &dest | |||
73 | 75 | ||
74 | static const wchar_t kReplaceChar = '_'; | 76 | static const wchar_t kReplaceChar = '_'; |
75 | 77 | ||
76 | void CStdOutStream::Normalize_UString__LF_Allowed(UString &s) | 78 | void CStdOutStream::Normalize_UString_LF_Allowed(UString &s) |
77 | { | 79 | { |
78 | unsigned len = s.Len(); | 80 | unsigned len = s.Len(); |
79 | wchar_t *d = s.GetBuf(); | 81 | wchar_t *d = s.GetBuf(); |
diff --git a/CPP/Common/StdOutStream.h b/CPP/Common/StdOutStream.h index 93f1dfa..bd15d7c 100644 --- a/CPP/Common/StdOutStream.h +++ b/CPP/Common/StdOutStream.h | |||
@@ -1,7 +1,7 @@ | |||
1 | // Common/StdOutStream.h | 1 | // Common/StdOutStream.h |
2 | 2 | ||
3 | #ifndef __COMMON_STD_OUT_STREAM_H | 3 | #ifndef ZIP7_INC_COMMON_STD_OUT_STREAM_H |
4 | #define __COMMON_STD_OUT_STREAM_H | 4 | #define ZIP7_INC_COMMON_STD_OUT_STREAM_H |
5 | 5 | ||
6 | #include <stdio.h> | 6 | #include <stdio.h> |
7 | 7 | ||
@@ -11,26 +11,28 @@ | |||
11 | class CStdOutStream | 11 | class CStdOutStream |
12 | { | 12 | { |
13 | FILE *_stream; | 13 | FILE *_stream; |
14 | bool _streamIsOpen; | 14 | // bool _streamIsOpen; |
15 | public: | 15 | public: |
16 | bool IsTerminalMode; | 16 | bool IsTerminalMode; |
17 | int CodePage; | 17 | int CodePage; |
18 | 18 | ||
19 | CStdOutStream(FILE *stream = 0): | 19 | CStdOutStream(FILE *stream = NULL): |
20 | _stream(stream), | 20 | _stream(stream), |
21 | _streamIsOpen(false), | 21 | // _streamIsOpen(false), |
22 | IsTerminalMode(false), | 22 | IsTerminalMode(false), |
23 | CodePage(-1) | 23 | CodePage(-1) |
24 | {}; | 24 | {} |
25 | 25 | ||
26 | ~CStdOutStream() { Close(); } | 26 | // ~CStdOutStream() { Close(); } |
27 | 27 | ||
28 | // void AttachStdStream(FILE *stream) { _stream = stream; _streamIsOpen = false; } | 28 | // void AttachStdStream(FILE *stream) { _stream = stream; _streamIsOpen = false; } |
29 | // bool IsDefined() const { return _stream != NULL; } | 29 | // bool IsDefined() const { return _stream != NULL; } |
30 | 30 | ||
31 | operator FILE *() { return _stream; } | 31 | operator FILE *() { return _stream; } |
32 | /* | ||
32 | bool Open(const char *fileName) throw(); | 33 | bool Open(const char *fileName) throw(); |
33 | bool Close() throw(); | 34 | bool Close() throw(); |
35 | */ | ||
34 | bool Flush() throw(); | 36 | bool Flush() throw(); |
35 | 37 | ||
36 | CStdOutStream & operator<<(CStdOutStream & (* func)(CStdOutStream &)) | 38 | CStdOutStream & operator<<(CStdOutStream & (* func)(CStdOutStream &)) |
@@ -60,7 +62,7 @@ public: | |||
60 | void PrintUString(const UString &s, AString &temp); | 62 | void PrintUString(const UString &s, AString &temp); |
61 | void Convert_UString_to_AString(const UString &src, AString &dest); | 63 | void Convert_UString_to_AString(const UString &src, AString &dest); |
62 | 64 | ||
63 | void Normalize_UString__LF_Allowed(UString &s); | 65 | void Normalize_UString_LF_Allowed(UString &s); |
64 | void Normalize_UString(UString &s); | 66 | void Normalize_UString(UString &s); |
65 | 67 | ||
66 | void NormalizePrint_UString(const UString &s, UString &tempU, AString &tempA); | 68 | void NormalizePrint_UString(const UString &s, UString &tempU, AString &tempA); |
diff --git a/CPP/Common/StringConvert.cpp b/CPP/Common/StringConvert.cpp index c0bde0f..f25396a 100644 --- a/CPP/Common/StringConvert.cpp +++ b/CPP/Common/StringConvert.cpp | |||
@@ -534,6 +534,7 @@ AString UnicodeStringToMultiByte(const UString &src, UINT codePage) | |||
534 | 534 | ||
535 | 535 | ||
536 | 536 | ||
537 | #if !defined(_WIN32) || defined(ENV_HAVE_LOCALE) | ||
537 | 538 | ||
538 | #ifdef _WIN32 | 539 | #ifdef _WIN32 |
539 | #define U_to_A(a, b, c) UnicodeStringToMultiByte2 | 540 | #define U_to_A(a, b, c) UnicodeStringToMultiByte2 |
@@ -544,8 +545,6 @@ AString UnicodeStringToMultiByte(const UString &src, UINT codePage) | |||
544 | // #define A_to_U(a, b, c) MultiByteToUnicodeString2_Native(a, b) | 545 | // #define A_to_U(a, b, c) MultiByteToUnicodeString2_Native(a, b) |
545 | #endif | 546 | #endif |
546 | 547 | ||
547 | #if !defined(_WIN32) || defined(ENV_HAVE_LOCALE) | ||
548 | |||
549 | bool IsNativeUTF8() | 548 | bool IsNativeUTF8() |
550 | { | 549 | { |
551 | UString u; | 550 | UString u; |
diff --git a/CPP/Common/StringConvert.h b/CPP/Common/StringConvert.h index 865c025..2092a2d 100644 --- a/CPP/Common/StringConvert.h +++ b/CPP/Common/StringConvert.h | |||
@@ -1,7 +1,7 @@ | |||
1 | // Common/StringConvert.h | 1 | // Common/StringConvert.h |
2 | 2 | ||
3 | #ifndef __COMMON_STRING_CONVERT_H | 3 | #ifndef ZIP7_INC_COMMON_STRING_CONVERT_H |
4 | #define __COMMON_STRING_CONVERT_H | 4 | #define ZIP7_INC_COMMON_STRING_CONVERT_H |
5 | 5 | ||
6 | #include "MyString.h" | 6 | #include "MyString.h" |
7 | #include "MyWindows.h" | 7 | #include "MyWindows.h" |
diff --git a/CPP/Common/StringToInt.h b/CPP/Common/StringToInt.h index 4057e49..c9dce7d 100644 --- a/CPP/Common/StringToInt.h +++ b/CPP/Common/StringToInt.h | |||
@@ -1,7 +1,7 @@ | |||
1 | // Common/StringToInt.h | 1 | // Common/StringToInt.h |
2 | 2 | ||
3 | #ifndef __COMMON_STRING_TO_INT_H | 3 | #ifndef ZIP7_INC_COMMON_STRING_TO_INT_H |
4 | #define __COMMON_STRING_TO_INT_H | 4 | #define ZIP7_INC_COMMON_STRING_TO_INT_H |
5 | 5 | ||
6 | #include "MyTypes.h" | 6 | #include "MyTypes.h" |
7 | 7 | ||
diff --git a/CPP/Common/TextConfig.cpp b/CPP/Common/TextConfig.cpp index 1428aab..d3e561c 100644 --- a/CPP/Common/TextConfig.cpp +++ b/CPP/Common/TextConfig.cpp | |||
@@ -15,7 +15,7 @@ static AString GetIDString(const char *s, unsigned &finishPos) | |||
15 | AString result; | 15 | AString result; |
16 | for (finishPos = 0; ; finishPos++) | 16 | for (finishPos = 0; ; finishPos++) |
17 | { | 17 | { |
18 | char c = s[finishPos]; | 18 | const char c = s[finishPos]; |
19 | if (IsDelimitChar(c) || c == '=') | 19 | if (IsDelimitChar(c) || c == '=') |
20 | break; | 20 | break; |
21 | result += c; | 21 | result += c; |
@@ -35,7 +35,7 @@ static bool SkipSpaces(const AString &s, unsigned &pos) | |||
35 | { | 35 | { |
36 | for (; pos < s.Len(); pos++) | 36 | for (; pos < s.Len(); pos++) |
37 | { | 37 | { |
38 | char c = s[pos]; | 38 | const char c = s[pos]; |
39 | if (!IsDelimitChar(c)) | 39 | if (!IsDelimitChar(c)) |
40 | { | 40 | { |
41 | if (c != ';') | 41 | if (c != ';') |
@@ -111,13 +111,13 @@ int FindTextConfigItem(const CObjectVector<CTextConfigPair> &pairs, const char * | |||
111 | { | 111 | { |
112 | FOR_VECTOR (i, pairs) | 112 | FOR_VECTOR (i, pairs) |
113 | if (pairs[i].ID.IsEqualTo(id)) | 113 | if (pairs[i].ID.IsEqualTo(id)) |
114 | return i; | 114 | return (int)i; |
115 | return -1; | 115 | return -1; |
116 | } | 116 | } |
117 | 117 | ||
118 | UString GetTextConfigValue(const CObjectVector<CTextConfigPair> &pairs, const char *id) | 118 | UString GetTextConfigValue(const CObjectVector<CTextConfigPair> &pairs, const char *id) |
119 | { | 119 | { |
120 | int index = FindTextConfigItem(pairs, id); | 120 | const int index = FindTextConfigItem(pairs, id); |
121 | if (index < 0) | 121 | if (index < 0) |
122 | return UString(); | 122 | return UString(); |
123 | return pairs[index].String; | 123 | return pairs[index].String; |
diff --git a/CPP/Common/TextConfig.h b/CPP/Common/TextConfig.h index cc7ce41..2263a44 100644 --- a/CPP/Common/TextConfig.h +++ b/CPP/Common/TextConfig.h | |||
@@ -1,7 +1,7 @@ | |||
1 | // Common/TextConfig.h | 1 | // Common/TextConfig.h |
2 | 2 | ||
3 | #ifndef __COMMON_TEXT_CONFIG_H | 3 | #ifndef ZIP7_INC_COMMON_TEXT_CONFIG_H |
4 | #define __COMMON_TEXT_CONFIG_H | 4 | #define ZIP7_INC_COMMON_TEXT_CONFIG_H |
5 | 5 | ||
6 | #include "MyString.h" | 6 | #include "MyString.h" |
7 | 7 | ||
diff --git a/CPP/Common/UTFConvert.cpp b/CPP/Common/UTFConvert.cpp index ac069db..fb166b7 100644 --- a/CPP/Common/UTFConvert.cpp +++ b/CPP/Common/UTFConvert.cpp | |||
@@ -8,17 +8,17 @@ | |||
8 | #include "UTFConvert.h" | 8 | #include "UTFConvert.h" |
9 | 9 | ||
10 | 10 | ||
11 | #ifndef _WCHART_IS_16BIT | 11 | #ifndef Z7_WCHART_IS_16BIT |
12 | #ifndef __APPLE__ | 12 | #ifndef __APPLE__ |
13 | // we define it if the system supports files with non-utf8 symbols: | 13 | // we define it if the system supports files with non-utf8 symbols: |
14 | #define _UTF8_RAW_NON_UTF8_SUPPORTED | 14 | #define MY_UTF8_RAW_NON_UTF8_SUPPORTED |
15 | #endif | 15 | #endif |
16 | #endif | 16 | #endif |
17 | 17 | ||
18 | /* | 18 | /* |
19 | _UTF8_START(n) - is a base value for start byte (head), if there are (n) additional bytes after start byte | 19 | MY_UTF8_START(n) - is a base value for start byte (head), if there are (n) additional bytes after start byte |
20 | 20 | ||
21 | n : _UTF8_START(n) : Bits of code point | 21 | n : MY_UTF8_START(n) : Bits of code point |
22 | 22 | ||
23 | 0 : 0x80 : : unused | 23 | 0 : 0x80 : : unused |
24 | 1 : 0xC0 : 11 : | 24 | 1 : 0xC0 : 11 : |
@@ -30,13 +30,13 @@ | |||
30 | 7 : 0xFF : | 30 | 7 : 0xFF : |
31 | */ | 31 | */ |
32 | 32 | ||
33 | #define _UTF8_START(n) (0x100 - (1 << (7 - (n)))) | 33 | #define MY_UTF8_START(n) (0x100 - (1 << (7 - (n)))) |
34 | 34 | ||
35 | #define _UTF8_HEAD_PARSE2(n) \ | 35 | #define MY_UTF8_HEAD_PARSE2(n) \ |
36 | if (c < _UTF8_START((n) + 1)) \ | 36 | if (c < MY_UTF8_START((n) + 1)) \ |
37 | { numBytes = (n); val -= _UTF8_START(n); } | 37 | { numBytes = (n); val -= MY_UTF8_START(n); } |
38 | 38 | ||
39 | #ifndef _WCHART_IS_16BIT | 39 | #ifndef Z7_WCHART_IS_16BIT |
40 | 40 | ||
41 | /* | 41 | /* |
42 | if (wchar_t is 32-bit), we can support large points in long UTF-8 sequence, | 42 | if (wchar_t is 32-bit), we can support large points in long UTF-8 sequence, |
@@ -46,30 +46,30 @@ | |||
46 | (_UTF8_NUM_TAIL_BYTES_MAX == 6) : (36-bit hack) | 46 | (_UTF8_NUM_TAIL_BYTES_MAX == 6) : (36-bit hack) |
47 | */ | 47 | */ |
48 | 48 | ||
49 | #define _UTF8_NUM_TAIL_BYTES_MAX 5 | 49 | #define MY_UTF8_NUM_TAIL_BYTES_MAX 5 |
50 | #endif | 50 | #endif |
51 | 51 | ||
52 | /* | 52 | /* |
53 | #define _UTF8_HEAD_PARSE \ | 53 | #define MY_UTF8_HEAD_PARSE \ |
54 | UInt32 val = c; \ | 54 | UInt32 val = c; \ |
55 | _UTF8_HEAD_PARSE2(1) \ | 55 | MY_UTF8_HEAD_PARSE2(1) \ |
56 | else _UTF8_HEAD_PARSE2(2) \ | 56 | else MY_UTF8_HEAD_PARSE2(2) \ |
57 | else _UTF8_HEAD_PARSE2(3) \ | 57 | else MY_UTF8_HEAD_PARSE2(3) \ |
58 | else _UTF8_HEAD_PARSE2(4) \ | 58 | else MY_UTF8_HEAD_PARSE2(4) \ |
59 | else _UTF8_HEAD_PARSE2(5) \ | 59 | else MY_UTF8_HEAD_PARSE2(5) \ |
60 | #if _UTF8_NUM_TAIL_BYTES_MAX >= 6 | 60 | #if MY_UTF8_NUM_TAIL_BYTES_MAX >= 6 |
61 | else _UTF8_HEAD_PARSE2(6) | 61 | else MY_UTF8_HEAD_PARSE2(6) |
62 | #endif | 62 | #endif |
63 | */ | 63 | */ |
64 | 64 | ||
65 | #define _UTF8_HEAD_PARSE_MAX_3_BYTES \ | 65 | #define MY_UTF8_HEAD_PARSE_MAX_3_BYTES \ |
66 | UInt32 val = c; \ | 66 | UInt32 val = c; \ |
67 | _UTF8_HEAD_PARSE2(1) \ | 67 | MY_UTF8_HEAD_PARSE2(1) \ |
68 | else _UTF8_HEAD_PARSE2(2) \ | 68 | else MY_UTF8_HEAD_PARSE2(2) \ |
69 | else { numBytes = 3; val -= _UTF8_START(3); } | 69 | else { numBytes = 3; val -= MY_UTF8_START(3); } |
70 | 70 | ||
71 | 71 | ||
72 | #define _UTF8_RANGE(n) (((UInt32)1) << ((n) * 5 + 6)) | 72 | #define MY_UTF8_RANGE(n) (((UInt32)1) << ((n) * 5 + 6)) |
73 | 73 | ||
74 | 74 | ||
75 | #define START_POINT_FOR_SURROGATE 0x10000 | 75 | #define START_POINT_FOR_SURROGATE 0x10000 |
@@ -82,7 +82,7 @@ | |||
82 | */ | 82 | */ |
83 | 83 | ||
84 | 84 | ||
85 | #if defined(_WCHART_IS_16BIT) | 85 | #if defined(Z7_WCHART_IS_16BIT) |
86 | 86 | ||
87 | #define UTF_ESCAPE_PLANE 0 | 87 | #define UTF_ESCAPE_PLANE 0 |
88 | 88 | ||
@@ -102,7 +102,7 @@ we can place 128 ESCAPE chars to | |||
102 | #define UTF_ESCAPE_PLANE 0 | 102 | #define UTF_ESCAPE_PLANE 0 |
103 | 103 | ||
104 | /* | 104 | /* |
105 | if (UTF_FLAG__FROM_UTF8__USE_ESCAPE is set) | 105 | if (Z7_UTF_FLAG_FROM_UTF8_USE_ESCAPE is set) |
106 | { | 106 | { |
107 | if (UTF_ESCAPE_PLANE is UTF_ESCAPE_PLANE_HIGH) | 107 | if (UTF_ESCAPE_PLANE is UTF_ESCAPE_PLANE_HIGH) |
108 | { | 108 | { |
@@ -111,13 +111,13 @@ we can place 128 ESCAPE chars to | |||
111 | So we still need a way to extract 8-bit Escapes and BMP-Escapes-8 | 111 | So we still need a way to extract 8-bit Escapes and BMP-Escapes-8 |
112 | from same BMP-Escapes-16 stored in 7z. | 112 | from same BMP-Escapes-16 stored in 7z. |
113 | And if we want to restore any 8-bit from 7z archive, | 113 | And if we want to restore any 8-bit from 7z archive, |
114 | we still must use UTF_FLAG__FROM_UTF8__BMP_ESCAPE_CONVERT for (utf-8 -> utf-16) | 114 | we still must use Z7_UTF_FLAG_FROM_UTF8_BMP_ESCAPE_CONVERT for (utf-8 -> utf-16) |
115 | Also we need additional Conversions to tranform from utf-16 to utf-16-With-Escapes-21 | 115 | Also we need additional Conversions to tranform from utf-16 to utf-16-With-Escapes-21 |
116 | } | 116 | } |
117 | else (UTF_ESCAPE_PLANE == 0) | 117 | else (UTF_ESCAPE_PLANE == 0) |
118 | { | 118 | { |
119 | we must convert original 3-bytes utf-8 BMP-Escape point to sequence | 119 | we must convert original 3-bytes utf-8 BMP-Escape point to sequence |
120 | of 3 BMP-Escape-16 points with UTF_FLAG__FROM_UTF8__BMP_ESCAPE_CONVERT | 120 | of 3 BMP-Escape-16 points with Z7_UTF_FLAG_FROM_UTF8_BMP_ESCAPE_CONVERT |
121 | so we can extract original RAW-UTF-8 from UTFD-16 later. | 121 | so we can extract original RAW-UTF-8 from UTFD-16 later. |
122 | } | 122 | } |
123 | } | 123 | } |
@@ -138,7 +138,7 @@ we can place 128 ESCAPE chars to | |||
138 | #define IS_LOW_SURROGATE_POINT(v) (((v) & (UInt32)0xfffffC00) == 0xdc00) | 138 | #define IS_LOW_SURROGATE_POINT(v) (((v) & (UInt32)0xfffffC00) == 0xdc00) |
139 | 139 | ||
140 | 140 | ||
141 | #define _ERROR_UTF8_CHECK \ | 141 | #define UTF_ERROR_UTF8_CHECK \ |
142 | { NonUtf = true; continue; } | 142 | { NonUtf = true; continue; } |
143 | 143 | ||
144 | void CUtf8Check::Check_Buf(const char *src, size_t size) throw() | 144 | void CUtf8Check::Check_Buf(const char *src, size_t size) throw() |
@@ -168,19 +168,19 @@ void CUtf8Check::Check_Buf(const char *src, size_t size) throw() | |||
168 | if (c < 0x80) | 168 | if (c < 0x80) |
169 | continue; | 169 | continue; |
170 | 170 | ||
171 | if (c < 0xc0 + 2)// it's limit for 0x140000 unicode codes : win32 compatibility | 171 | if (c < 0xc0 + 2) // it's limit for 0x140000 unicode codes : win32 compatibility |
172 | _ERROR_UTF8_CHECK | 172 | UTF_ERROR_UTF8_CHECK |
173 | 173 | ||
174 | unsigned numBytes; | 174 | unsigned numBytes; |
175 | 175 | ||
176 | UInt32 val = c; | 176 | UInt32 val = c; |
177 | _UTF8_HEAD_PARSE2(1) | 177 | MY_UTF8_HEAD_PARSE2(1) |
178 | else _UTF8_HEAD_PARSE2(2) | 178 | else MY_UTF8_HEAD_PARSE2(2) |
179 | else _UTF8_HEAD_PARSE2(4) | 179 | else MY_UTF8_HEAD_PARSE2(4) |
180 | else _UTF8_HEAD_PARSE2(5) | 180 | else MY_UTF8_HEAD_PARSE2(5) |
181 | else | 181 | else |
182 | { | 182 | { |
183 | _ERROR_UTF8_CHECK | 183 | UTF_ERROR_UTF8_CHECK |
184 | } | 184 | } |
185 | 185 | ||
186 | unsigned pos = 0; | 186 | unsigned pos = 0; |
@@ -206,7 +206,7 @@ void CUtf8Check::Check_Buf(const char *src, size_t size) throw() | |||
206 | if (pos == size) | 206 | if (pos == size) |
207 | Truncated = true; | 207 | Truncated = true; |
208 | else | 208 | else |
209 | _ERROR_UTF8_CHECK | 209 | UTF_ERROR_UTF8_CHECK |
210 | } | 210 | } |
211 | 211 | ||
212 | #ifdef UTF_ESCAPE_BASE | 212 | #ifdef UTF_ESCAPE_BASE |
@@ -268,7 +268,7 @@ bool CheckUTF8(const char *src, bool allowReduced) throw() | |||
268 | return false; | 268 | return false; |
269 | 269 | ||
270 | unsigned numBytes; | 270 | unsigned numBytes; |
271 | _UTF8_HEAD_PARSE | 271 | MY_UTF8_HEAD_PARSE |
272 | else | 272 | else |
273 | return false; | 273 | return false; |
274 | 274 | ||
@@ -285,7 +285,7 @@ bool CheckUTF8(const char *src, bool allowReduced) throw() | |||
285 | } | 285 | } |
286 | while (--numBytes); | 286 | while (--numBytes); |
287 | 287 | ||
288 | if (val < _UTF8_RANGE(pos - 1)) | 288 | if (val < MY_UTF8_RANGE(pos - 1)) |
289 | return false; | 289 | return false; |
290 | 290 | ||
291 | if (val >= 0x110000) | 291 | if (val >= 0x110000) |
@@ -303,18 +303,18 @@ bool CheckUTF8(const char *src, bool allowReduced) throw() | |||
303 | 303 | ||
304 | 304 | ||
305 | #define UTF_ESCAPE(c) \ | 305 | #define UTF_ESCAPE(c) \ |
306 | ((flags & UTF_FLAG__FROM_UTF8__USE_ESCAPE) ? \ | 306 | ((flags & Z7_UTF_FLAG_FROM_UTF8_USE_ESCAPE) ? \ |
307 | UTF_ESCAPE_PLANE + UTF_ESCAPE_BASE + (c) : UTF_REPLACEMENT_CHAR) | 307 | UTF_ESCAPE_PLANE + UTF_ESCAPE_BASE + (c) : UTF_REPLACEMENT_CHAR) |
308 | 308 | ||
309 | /* | 309 | /* |
310 | #define _HARD_ERROR_UTF8 | 310 | #define UTF_HARD_ERROR_UTF8 |
311 | { if (dest) dest[destPos] = (wchar_t)UTF_ESCAPE(c); \ | 311 | { if (dest) dest[destPos] = (wchar_t)UTF_ESCAPE(c); \ |
312 | destPos++; ok = false; continue; } | 312 | destPos++; ok = false; continue; } |
313 | */ | 313 | */ |
314 | 314 | ||
315 | // we ignore utf errors, and don't change (ok) variable! | 315 | // we ignore utf errors, and don't change (ok) variable! |
316 | 316 | ||
317 | #define _ERROR_UTF8 \ | 317 | #define UTF_ERROR_UTF8 \ |
318 | { if (dest) dest[destPos] = (wchar_t)UTF_ESCAPE(c); \ | 318 | { if (dest) dest[destPos] = (wchar_t)UTF_ESCAPE(c); \ |
319 | destPos++; continue; } | 319 | destPos++; continue; } |
320 | 320 | ||
@@ -362,12 +362,12 @@ static bool Utf8_To_Utf16(wchar_t *dest, size_t *destLen, const char *src, const | |||
362 | if (c < 0xc0 + 2 | 362 | if (c < 0xc0 + 2 |
363 | || c >= 0xf5) // it's limit for 0x140000 unicode codes : win32 compatibility | 363 | || c >= 0xf5) // it's limit for 0x140000 unicode codes : win32 compatibility |
364 | { | 364 | { |
365 | _ERROR_UTF8 | 365 | UTF_ERROR_UTF8 |
366 | } | 366 | } |
367 | 367 | ||
368 | unsigned numBytes; | 368 | unsigned numBytes; |
369 | 369 | ||
370 | _UTF8_HEAD_PARSE_MAX_3_BYTES | 370 | MY_UTF8_HEAD_PARSE_MAX_3_BYTES |
371 | 371 | ||
372 | unsigned pos = 0; | 372 | unsigned pos = 0; |
373 | do | 373 | do |
@@ -387,7 +387,7 @@ static bool Utf8_To_Utf16(wchar_t *dest, size_t *destLen, const char *src, const | |||
387 | break; | 387 | break; |
388 | if (numBytes == 2) | 388 | if (numBytes == 2) |
389 | { | 389 | { |
390 | if (flags & UTF_FLAG__FROM_UTF8__SURROGATE_ERROR) | 390 | if (flags & Z7_UTF_FLAG_FROM_UTF8_SURROGATE_ERROR) |
391 | if ((val & (0xF800 >> 6)) == (0xd800 >> 6)) | 391 | if ((val & (0xF800 >> 6)) == (0xd800 >> 6)) |
392 | break; | 392 | break; |
393 | } | 393 | } |
@@ -399,27 +399,27 @@ static bool Utf8_To_Utf16(wchar_t *dest, size_t *destLen, const char *src, const | |||
399 | 399 | ||
400 | if (numBytes != 0) | 400 | if (numBytes != 0) |
401 | { | 401 | { |
402 | if ((flags & UTF_FLAG__FROM_UTF8__USE_ESCAPE) == 0) | 402 | if ((flags & Z7_UTF_FLAG_FROM_UTF8_USE_ESCAPE) == 0) |
403 | { | 403 | { |
404 | // the following code to emit the 0xfffd chars as win32 Utf8 function. | 404 | // the following code to emit the 0xfffd chars as win32 Utf8 function. |
405 | // disable the folling line, if you need 0xfffd for each incorrect byte as in Escape mode | 405 | // disable the folling line, if you need 0xfffd for each incorrect byte as in Escape mode |
406 | src += pos; | 406 | src += pos; |
407 | } | 407 | } |
408 | _ERROR_UTF8 | 408 | UTF_ERROR_UTF8 |
409 | } | 409 | } |
410 | 410 | ||
411 | /* | 411 | /* |
412 | if (val < _UTF8_RANGE(pos - 1)) | 412 | if (val < MY_UTF8_RANGE(pos - 1)) |
413 | _ERROR_UTF8 | 413 | UTF_ERROR_UTF8 |
414 | */ | 414 | */ |
415 | 415 | ||
416 | #ifdef UTF_ESCAPE_BASE | 416 | #ifdef UTF_ESCAPE_BASE |
417 | 417 | ||
418 | if ((flags & UTF_FLAG__FROM_UTF8__BMP_ESCAPE_CONVERT) | 418 | if ((flags & Z7_UTF_FLAG_FROM_UTF8_BMP_ESCAPE_CONVERT) |
419 | && IS_ESCAPE_POINT(val, 0)) | 419 | && IS_ESCAPE_POINT(val, 0)) |
420 | { | 420 | { |
421 | // We will emit 3 utf16-Escape-16-21 points from one Escape-16 point (3 bytes) | 421 | // We will emit 3 utf16-Escape-16-21 points from one Escape-16 point (3 bytes) |
422 | _ERROR_UTF8 | 422 | UTF_ERROR_UTF8 |
423 | } | 423 | } |
424 | 424 | ||
425 | #endif | 425 | #endif |
@@ -434,11 +434,11 @@ static bool Utf8_To_Utf16(wchar_t *dest, size_t *destLen, const char *src, const | |||
434 | if (val < START_POINT_FOR_SURROGATE) | 434 | if (val < START_POINT_FOR_SURROGATE) |
435 | { | 435 | { |
436 | /* | 436 | /* |
437 | if ((flags & UTF_FLAG__FROM_UTF8__SURROGATE_ERROR) | 437 | if ((flags & Z7_UTF_FLAG_FROM_UTF8_SURROGATE_ERROR) |
438 | && IS_SURROGATE_POINT(val)) | 438 | && IS_SURROGATE_POINT(val)) |
439 | { | 439 | { |
440 | // We will emit 3 utf16-Escape-16-21 points from one Surrogate-16 point (3 bytes) | 440 | // We will emit 3 utf16-Escape-16-21 points from one Surrogate-16 point (3 bytes) |
441 | _ERROR_UTF8 | 441 | UTF_ERROR_UTF8 |
442 | } | 442 | } |
443 | */ | 443 | */ |
444 | if (dest) | 444 | if (dest) |
@@ -451,7 +451,7 @@ static bool Utf8_To_Utf16(wchar_t *dest, size_t *destLen, const char *src, const | |||
451 | if (val >= 0x110000) | 451 | if (val >= 0x110000) |
452 | { | 452 | { |
453 | // We will emit utf16-Escape-16-21 point from each source byte | 453 | // We will emit utf16-Escape-16-21 point from each source byte |
454 | _ERROR_UTF8 | 454 | UTF_ERROR_UTF8 |
455 | } | 455 | } |
456 | */ | 456 | */ |
457 | if (dest) | 457 | if (dest) |
@@ -467,8 +467,8 @@ static bool Utf8_To_Utf16(wchar_t *dest, size_t *destLen, const char *src, const | |||
467 | 467 | ||
468 | 468 | ||
469 | 469 | ||
470 | #define _UTF8_HEAD(n, val) ((char)(_UTF8_START(n) + (val >> (6 * (n))))) | 470 | #define MY_UTF8_HEAD(n, val) ((char)(MY_UTF8_START(n) + (val >> (6 * (n))))) |
471 | #define _UTF8_CHAR(n, val) ((char)(0x80 + (((val) >> (6 * (n))) & 0x3F))) | 471 | #define MY_UTF8_CHAR(n, val) ((char)(0x80 + (((val) >> (6 * (n))) & 0x3F))) |
472 | 472 | ||
473 | static size_t Utf16_To_Utf8_Calc(const wchar_t *src, const wchar_t *srcLim, unsigned flags) | 473 | static size_t Utf16_To_Utf8_Calc(const wchar_t *src, const wchar_t *srcLim, unsigned flags) |
474 | { | 474 | { |
@@ -483,7 +483,7 @@ static size_t Utf16_To_Utf8_Calc(const wchar_t *src, const wchar_t *srcLim, unsi | |||
483 | if (val < 0x80) | 483 | if (val < 0x80) |
484 | continue; | 484 | continue; |
485 | 485 | ||
486 | if (val < _UTF8_RANGE(1)) | 486 | if (val < MY_UTF8_RANGE(1)) |
487 | { | 487 | { |
488 | size++; | 488 | size++; |
489 | continue; | 489 | continue; |
@@ -492,12 +492,12 @@ static size_t Utf16_To_Utf8_Calc(const wchar_t *src, const wchar_t *srcLim, unsi | |||
492 | #ifdef UTF_ESCAPE_BASE | 492 | #ifdef UTF_ESCAPE_BASE |
493 | 493 | ||
494 | #if UTF_ESCAPE_PLANE != 0 | 494 | #if UTF_ESCAPE_PLANE != 0 |
495 | if (flags & UTF_FLAG__TO_UTF8__PARSE_HIGH_ESCAPE) | 495 | if (flags & Z7_UTF_FLAG_TO_UTF8_PARSE_HIGH_ESCAPE) |
496 | if (IS_ESCAPE_POINT(val, UTF_ESCAPE_PLANE)) | 496 | if (IS_ESCAPE_POINT(val, UTF_ESCAPE_PLANE)) |
497 | continue; | 497 | continue; |
498 | #endif | 498 | #endif |
499 | 499 | ||
500 | if (flags & UTF_FLAG__TO_UTF8__EXTRACT_BMP_ESCAPE) | 500 | if (flags & Z7_UTF_FLAG_TO_UTF8_EXTRACT_BMP_ESCAPE) |
501 | if (IS_ESCAPE_POINT(val, 0)) | 501 | if (IS_ESCAPE_POINT(val, 0)) |
502 | continue; | 502 | continue; |
503 | 503 | ||
@@ -517,18 +517,18 @@ static size_t Utf16_To_Utf8_Calc(const wchar_t *src, const wchar_t *srcLim, unsi | |||
517 | continue; | 517 | continue; |
518 | } | 518 | } |
519 | 519 | ||
520 | #ifdef _WCHART_IS_16BIT | 520 | #ifdef Z7_WCHART_IS_16BIT |
521 | 521 | ||
522 | size += 2; | 522 | size += 2; |
523 | 523 | ||
524 | #else | 524 | #else |
525 | 525 | ||
526 | if (val < _UTF8_RANGE(2)) size += 2; | 526 | if (val < MY_UTF8_RANGE(2)) size += 2; |
527 | else if (val < _UTF8_RANGE(3)) size += 3; | 527 | else if (val < MY_UTF8_RANGE(3)) size += 3; |
528 | else if (val < _UTF8_RANGE(4)) size += 4; | 528 | else if (val < MY_UTF8_RANGE(4)) size += 4; |
529 | else if (val < _UTF8_RANGE(5)) size += 5; | 529 | else if (val < MY_UTF8_RANGE(5)) size += 5; |
530 | else | 530 | else |
531 | #if _UTF8_NUM_TAIL_BYTES_MAX >= 6 | 531 | #if MY_UTF8_NUM_TAIL_BYTES_MAX >= 6 |
532 | size += 6; | 532 | size += 6; |
533 | #else | 533 | #else |
534 | size += 3; | 534 | size += 3; |
@@ -554,10 +554,10 @@ static char *Utf16_To_Utf8(char *dest, const wchar_t *src, const wchar_t *srcLim | |||
554 | continue; | 554 | continue; |
555 | } | 555 | } |
556 | 556 | ||
557 | if (val < _UTF8_RANGE(1)) | 557 | if (val < MY_UTF8_RANGE(1)) |
558 | { | 558 | { |
559 | dest[0] = _UTF8_HEAD(1, val); | 559 | dest[0] = MY_UTF8_HEAD(1, val); |
560 | dest[1] = _UTF8_CHAR(0, val); | 560 | dest[1] = MY_UTF8_CHAR(0, val); |
561 | dest += 2; | 561 | dest += 2; |
562 | continue; | 562 | continue; |
563 | } | 563 | } |
@@ -567,11 +567,11 @@ static char *Utf16_To_Utf8(char *dest, const wchar_t *src, const wchar_t *srcLim | |||
567 | #if UTF_ESCAPE_PLANE != 0 | 567 | #if UTF_ESCAPE_PLANE != 0 |
568 | /* | 568 | /* |
569 | if (wchar_t is 32-bit) | 569 | if (wchar_t is 32-bit) |
570 | && (UTF_FLAG__TO_UTF8__PARSE_HIGH_ESCAPE is set) | 570 | && (Z7_UTF_FLAG_TO_UTF8_PARSE_HIGH_ESCAPE is set) |
571 | && (point is virtual escape plane) | 571 | && (point is virtual escape plane) |
572 | we extract 8-bit byte from virtual HIGH-ESCAPE PLANE. | 572 | we extract 8-bit byte from virtual HIGH-ESCAPE PLANE. |
573 | */ | 573 | */ |
574 | if (flags & UTF_FLAG__TO_UTF8__PARSE_HIGH_ESCAPE) | 574 | if (flags & Z7_UTF_FLAG_TO_UTF8_PARSE_HIGH_ESCAPE) |
575 | if (IS_ESCAPE_POINT(val, UTF_ESCAPE_PLANE)) | 575 | if (IS_ESCAPE_POINT(val, UTF_ESCAPE_PLANE)) |
576 | { | 576 | { |
577 | *dest++ = (char)(val); | 577 | *dest++ = (char)(val); |
@@ -579,10 +579,10 @@ static char *Utf16_To_Utf8(char *dest, const wchar_t *src, const wchar_t *srcLim | |||
579 | } | 579 | } |
580 | #endif // UTF_ESCAPE_PLANE != 0 | 580 | #endif // UTF_ESCAPE_PLANE != 0 |
581 | 581 | ||
582 | /* if (UTF_FLAG__TO_UTF8__EXTRACT_BMP_ESCAPE is defined) | 582 | /* if (Z7_UTF_FLAG_TO_UTF8_EXTRACT_BMP_ESCAPE is defined) |
583 | we extract 8-bit byte from BMP-ESCAPE PLANE. */ | 583 | we extract 8-bit byte from BMP-ESCAPE PLANE. */ |
584 | 584 | ||
585 | if (flags & UTF_FLAG__TO_UTF8__EXTRACT_BMP_ESCAPE) | 585 | if (flags & Z7_UTF_FLAG_TO_UTF8_EXTRACT_BMP_ESCAPE) |
586 | if (IS_ESCAPE_POINT(val, 0)) | 586 | if (IS_ESCAPE_POINT(val, 0)) |
587 | { | 587 | { |
588 | *dest++ = (char)(val); | 588 | *dest++ = (char)(val); |
@@ -601,46 +601,46 @@ static char *Utf16_To_Utf8(char *dest, const wchar_t *src, const wchar_t *srcLim | |||
601 | { | 601 | { |
602 | src++; | 602 | src++; |
603 | val = (((val - 0xd800) << 10) | (c2 - 0xdc00)) + 0x10000; | 603 | val = (((val - 0xd800) << 10) | (c2 - 0xdc00)) + 0x10000; |
604 | dest[0] = _UTF8_HEAD(3, val); | 604 | dest[0] = MY_UTF8_HEAD(3, val); |
605 | dest[1] = _UTF8_CHAR(2, val); | 605 | dest[1] = MY_UTF8_CHAR(2, val); |
606 | dest[2] = _UTF8_CHAR(1, val); | 606 | dest[2] = MY_UTF8_CHAR(1, val); |
607 | dest[3] = _UTF8_CHAR(0, val); | 607 | dest[3] = MY_UTF8_CHAR(0, val); |
608 | dest += 4; | 608 | dest += 4; |
609 | continue; | 609 | continue; |
610 | } | 610 | } |
611 | } | 611 | } |
612 | if (flags & UTF_FLAG__TO_UTF8__SURROGATE_ERROR) | 612 | if (flags & Z7_UTF_FLAG_TO_UTF8_SURROGATE_ERROR) |
613 | val = UTF_REPLACEMENT_CHAR; // WIN32 function does it | 613 | val = UTF_REPLACEMENT_CHAR; // WIN32 function does it |
614 | } | 614 | } |
615 | 615 | ||
616 | #ifndef _WCHART_IS_16BIT | 616 | #ifndef Z7_WCHART_IS_16BIT |
617 | if (val < _UTF8_RANGE(2)) | 617 | if (val < MY_UTF8_RANGE(2)) |
618 | #endif | 618 | #endif |
619 | { | 619 | { |
620 | dest[0] = _UTF8_HEAD(2, val); | 620 | dest[0] = MY_UTF8_HEAD(2, val); |
621 | dest[1] = _UTF8_CHAR(1, val); | 621 | dest[1] = MY_UTF8_CHAR(1, val); |
622 | dest[2] = _UTF8_CHAR(0, val); | 622 | dest[2] = MY_UTF8_CHAR(0, val); |
623 | dest += 3; | 623 | dest += 3; |
624 | continue; | 624 | continue; |
625 | } | 625 | } |
626 | 626 | ||
627 | #ifndef _WCHART_IS_16BIT | 627 | #ifndef Z7_WCHART_IS_16BIT |
628 | 628 | ||
629 | // we don't expect this case. so we can throw exception | 629 | // we don't expect this case. so we can throw exception |
630 | // throw 20210407; | 630 | // throw 20210407; |
631 | 631 | ||
632 | char b; | 632 | char b; |
633 | unsigned numBits; | 633 | unsigned numBits; |
634 | if (val < _UTF8_RANGE(3)) { numBits = 6 * 3; b = _UTF8_HEAD(3, val); } | 634 | if (val < MY_UTF8_RANGE(3)) { numBits = 6 * 3; b = MY_UTF8_HEAD(3, val); } |
635 | else if (val < _UTF8_RANGE(4)) { numBits = 6 * 4; b = _UTF8_HEAD(4, val); } | 635 | else if (val < MY_UTF8_RANGE(4)) { numBits = 6 * 4; b = MY_UTF8_HEAD(4, val); } |
636 | else if (val < _UTF8_RANGE(5)) { numBits = 6 * 5; b = _UTF8_HEAD(5, val); } | 636 | else if (val < MY_UTF8_RANGE(5)) { numBits = 6 * 5; b = MY_UTF8_HEAD(5, val); } |
637 | #if _UTF8_NUM_TAIL_BYTES_MAX >= 6 | 637 | #if MY_UTF8_NUM_TAIL_BYTES_MAX >= 6 |
638 | else { numBits = 6 * 6; b = (char)_UTF8_START(6); } | 638 | else { numBits = 6 * 6; b = (char)MY_UTF8_START(6); } |
639 | #else | 639 | #else |
640 | else | 640 | else |
641 | { | 641 | { |
642 | val = UTF_REPLACEMENT_CHAR; | 642 | val = UTF_REPLACEMENT_CHAR; |
643 | { numBits = 6 * 3; b = _UTF8_HEAD(3, val); } | 643 | { numBits = 6 * 3; b = MY_UTF8_HEAD(3, val); } |
644 | } | 644 | } |
645 | #endif | 645 | #endif |
646 | 646 | ||
@@ -675,11 +675,11 @@ bool ConvertUTF8ToUnicode_Flags(const AString &src, UString &dest, unsigned flag | |||
675 | 675 | ||
676 | static | 676 | static |
677 | unsigned g_UTF8_To_Unicode_Flags = | 677 | unsigned g_UTF8_To_Unicode_Flags = |
678 | UTF_FLAG__FROM_UTF8__USE_ESCAPE | 678 | Z7_UTF_FLAG_FROM_UTF8_USE_ESCAPE |
679 | #ifndef _WCHART_IS_16BIT | 679 | #ifndef Z7_WCHART_IS_16BIT |
680 | | UTF_FLAG__FROM_UTF8__SURROGATE_ERROR | 680 | | Z7_UTF_FLAG_FROM_UTF8_SURROGATE_ERROR |
681 | #ifdef _UTF8_RAW_NON_UTF8_SUPPORTED | 681 | #ifdef MY_UTF8_RAW_NON_UTF8_SUPPORTED |
682 | | UTF_FLAG__FROM_UTF8__BMP_ESCAPE_CONVERT | 682 | | Z7_UTF_FLAG_FROM_UTF8_BMP_ESCAPE_CONVERT |
683 | #endif | 683 | #endif |
684 | #endif | 684 | #endif |
685 | ; | 685 | ; |
@@ -729,13 +729,13 @@ void ConvertUnicodeToUTF8_Flags(const UString &src, AString &dest, unsigned flag | |||
729 | 729 | ||
730 | 730 | ||
731 | unsigned g_Unicode_To_UTF8_Flags = | 731 | unsigned g_Unicode_To_UTF8_Flags = |
732 | // UTF_FLAG__TO_UTF8__PARSE_HIGH_ESCAPE | 732 | // Z7_UTF_FLAG_TO_UTF8_PARSE_HIGH_ESCAPE |
733 | 0 | 733 | 0 |
734 | #ifndef _WIN32 | 734 | #ifndef _WIN32 |
735 | #ifdef _UTF8_RAW_NON_UTF8_SUPPORTED | 735 | #ifdef MY_UTF8_RAW_NON_UTF8_SUPPORTED |
736 | | UTF_FLAG__TO_UTF8__EXTRACT_BMP_ESCAPE | 736 | | Z7_UTF_FLAG_TO_UTF8_EXTRACT_BMP_ESCAPE |
737 | #else | 737 | #else |
738 | | UTF_FLAG__TO_UTF8__SURROGATE_ERROR; | 738 | | Z7_UTF_FLAG_TO_UTF8_SURROGATE_ERROR |
739 | #endif | 739 | #endif |
740 | #endif | 740 | #endif |
741 | ; | 741 | ; |
@@ -840,7 +840,7 @@ bool Unicode_IsThere_Utf16SurrogateError(const UString &src) | |||
840 | } | 840 | } |
841 | */ | 841 | */ |
842 | 842 | ||
843 | #ifndef _WCHART_IS_16BIT | 843 | #ifndef Z7_WCHART_IS_16BIT |
844 | 844 | ||
845 | void Convert_UnicodeEsc16_To_UnicodeEscHigh | 845 | void Convert_UnicodeEsc16_To_UnicodeEscHigh |
846 | #if UTF_ESCAPE_PLANE == 0 | 846 | #if UTF_ESCAPE_PLANE == 0 |
diff --git a/CPP/Common/UTFConvert.h b/CPP/Common/UTFConvert.h index 37c4975..94a8024 100644 --- a/CPP/Common/UTFConvert.h +++ b/CPP/Common/UTFConvert.h | |||
@@ -1,7 +1,7 @@ | |||
1 | // Common/UTFConvert.h | 1 | // Common/UTFConvert.h |
2 | 2 | ||
3 | #ifndef __COMMON_UTF_CONVERT_H | 3 | #ifndef ZIP7_INC_COMMON_UTF_CONVERT_H |
4 | #define __COMMON_UTF_CONVERT_H | 4 | #define ZIP7_INC_COMMON_UTF_CONVERT_H |
5 | 5 | ||
6 | #include "MyBuffer.h" | 6 | #include "MyBuffer.h" |
7 | #include "MyString.h" | 7 | #include "MyString.h" |
@@ -88,12 +88,12 @@ if (allowReduced == true) - it allows truncated last character-Utf8-sequence | |||
88 | bool Check_UTF8_Buf(const char *src, size_t size, bool allowReduced) throw(); | 88 | bool Check_UTF8_Buf(const char *src, size_t size, bool allowReduced) throw(); |
89 | bool CheckUTF8_AString(const AString &s) throw(); | 89 | bool CheckUTF8_AString(const AString &s) throw(); |
90 | 90 | ||
91 | #define UTF_FLAG__FROM_UTF8__SURROGATE_ERROR (1 << 0) | 91 | #define Z7_UTF_FLAG_FROM_UTF8_SURROGATE_ERROR (1 << 0) |
92 | #define UTF_FLAG__FROM_UTF8__USE_ESCAPE (1 << 1) | 92 | #define Z7_UTF_FLAG_FROM_UTF8_USE_ESCAPE (1 << 1) |
93 | #define UTF_FLAG__FROM_UTF8__BMP_ESCAPE_CONVERT (1 << 2) | 93 | #define Z7_UTF_FLAG_FROM_UTF8_BMP_ESCAPE_CONVERT (1 << 2) |
94 | 94 | ||
95 | /* | 95 | /* |
96 | UTF_FLAG__FROM_UTF8__SURROGATE_ERROR | 96 | Z7_UTF_FLAG_FROM_UTF8_SURROGATE_ERROR |
97 | 97 | ||
98 | if (flag is NOT set) | 98 | if (flag is NOT set) |
99 | { | 99 | { |
@@ -108,14 +108,14 @@ UTF_FLAG__FROM_UTF8__SURROGATE_ERROR | |||
108 | 108 | ||
109 | if (flag is set) | 109 | if (flag is set) |
110 | { | 110 | { |
111 | if (UTF_FLAG__FROM_UTF8__USE_ESCAPE is defined) | 111 | if (Z7_UTF_FLAG_FROM_UTF8_USE_ESCAPE is defined) |
112 | it generates ESCAPE for SINGLE-SURROGATE-8, | 112 | it generates ESCAPE for SINGLE-SURROGATE-8, |
113 | if (UTF_FLAG__FROM_UTF8__USE_ESCAPE is not defined) | 113 | if (Z7_UTF_FLAG_FROM_UTF8_USE_ESCAPE is not defined) |
114 | it generates U+fffd for SINGLE-SURROGATE-8, | 114 | it generates U+fffd for SINGLE-SURROGATE-8, |
115 | } | 115 | } |
116 | 116 | ||
117 | 117 | ||
118 | UTF_FLAG__FROM_UTF8__USE_ESCAPE | 118 | Z7_UTF_FLAG_FROM_UTF8_USE_ESCAPE |
119 | 119 | ||
120 | if (flag is NOT set) | 120 | if (flag is NOT set) |
121 | it generates (U+fffd) code for non-UTF-8 (invalid) characters | 121 | it generates (U+fffd) code for non-UTF-8 (invalid) characters |
@@ -126,7 +126,7 @@ UTF_FLAG__FROM_UTF8__USE_ESCAPE | |||
126 | And later we can restore original UTF-8-RAW characters from (ESCAPE-16-21) codes. | 126 | And later we can restore original UTF-8-RAW characters from (ESCAPE-16-21) codes. |
127 | } | 127 | } |
128 | 128 | ||
129 | UTF_FLAG__FROM_UTF8__BMP_ESCAPE_CONVERT | 129 | Z7_UTF_FLAG_FROM_UTF8_BMP_ESCAPE_CONVERT |
130 | 130 | ||
131 | if (flag is NOT set) | 131 | if (flag is NOT set) |
132 | { | 132 | { |
@@ -146,9 +146,9 @@ Main USE CASES with UTF-8 <-> UTF-16 conversions: | |||
146 | 146 | ||
147 | WIN32: UTF-16-RAW -> UTF-8 (Archive) -> UTF-16-RAW | 147 | WIN32: UTF-16-RAW -> UTF-8 (Archive) -> UTF-16-RAW |
148 | { | 148 | { |
149 | set UTF_FLAG__FROM_UTF8__USE_ESCAPE | 149 | set Z7_UTF_FLAG_FROM_UTF8_USE_ESCAPE |
150 | Do NOT set UTF_FLAG__FROM_UTF8__SURROGATE_ERROR | 150 | Do NOT set Z7_UTF_FLAG_FROM_UTF8_SURROGATE_ERROR |
151 | Do NOT set UTF_FLAG__FROM_UTF8__BMP_ESCAPE_CONVERT | 151 | Do NOT set Z7_UTF_FLAG_FROM_UTF8_BMP_ESCAPE_CONVERT |
152 | 152 | ||
153 | So we restore original SINGLE-SURROGATE-16 from single SINGLE-SURROGATE-8. | 153 | So we restore original SINGLE-SURROGATE-16 from single SINGLE-SURROGATE-8. |
154 | } | 154 | } |
@@ -157,17 +157,17 @@ Main USE CASES with UTF-8 <-> UTF-16 conversions: | |||
157 | { | 157 | { |
158 | we want restore original UTF-8-RAW sequence later from that ESCAPE-16. | 158 | we want restore original UTF-8-RAW sequence later from that ESCAPE-16. |
159 | Set the flags: | 159 | Set the flags: |
160 | UTF_FLAG__FROM_UTF8__SURROGATE_ERROR | 160 | Z7_UTF_FLAG_FROM_UTF8_SURROGATE_ERROR |
161 | UTF_FLAG__FROM_UTF8__USE_ESCAPE | 161 | Z7_UTF_FLAG_FROM_UTF8_USE_ESCAPE |
162 | UTF_FLAG__FROM_UTF8__BMP_ESCAPE_CONVERT | 162 | Z7_UTF_FLAG_FROM_UTF8_BMP_ESCAPE_CONVERT |
163 | } | 163 | } |
164 | 164 | ||
165 | MacOS: UTF-8-RAW -> UTF-16 (Intermediate / Archive) -> UTF-8-RAW | 165 | MacOS: UTF-8-RAW -> UTF-16 (Intermediate / Archive) -> UTF-8-RAW |
166 | { | 166 | { |
167 | we want to restore correct UTF-8 without any BMP processing: | 167 | we want to restore correct UTF-8 without any BMP processing: |
168 | Set the flags: | 168 | Set the flags: |
169 | UTF_FLAG__FROM_UTF8__SURROGATE_ERROR | 169 | Z7_UTF_FLAG_FROM_UTF8_SURROGATE_ERROR |
170 | UTF_FLAG__FROM_UTF8__USE_ESCAPE | 170 | Z7_UTF_FLAG_FROM_UTF8_USE_ESCAPE |
171 | } | 171 | } |
172 | 172 | ||
173 | */ | 173 | */ |
@@ -178,12 +178,12 @@ bool Convert_UTF8_Buf_To_Unicode(const char *src, size_t srcSize, UString &dest, | |||
178 | bool ConvertUTF8ToUnicode_Flags(const AString &src, UString &dest, unsigned flags = 0); | 178 | bool ConvertUTF8ToUnicode_Flags(const AString &src, UString &dest, unsigned flags = 0); |
179 | bool ConvertUTF8ToUnicode(const AString &src, UString &dest); | 179 | bool ConvertUTF8ToUnicode(const AString &src, UString &dest); |
180 | 180 | ||
181 | #define UTF_FLAG__TO_UTF8__SURROGATE_ERROR (1 << 8) | 181 | #define Z7_UTF_FLAG_TO_UTF8_SURROGATE_ERROR (1 << 8) |
182 | #define UTF_FLAG__TO_UTF8__EXTRACT_BMP_ESCAPE (1 << 9) | 182 | #define Z7_UTF_FLAG_TO_UTF8_EXTRACT_BMP_ESCAPE (1 << 9) |
183 | // #define UTF_FLAG__TO_UTF8__PARSE_HIGH_ESCAPE (1 << 10) | 183 | // #define Z7_UTF_FLAG_TO_UTF8_PARSE_HIGH_ESCAPE (1 << 10) |
184 | 184 | ||
185 | /* | 185 | /* |
186 | UTF_FLAG__TO_UTF8__SURROGATE_ERROR | 186 | Z7_UTF_FLAG_TO_UTF8_SURROGATE_ERROR |
187 | 187 | ||
188 | if (flag is NOT set) | 188 | if (flag is NOT set) |
189 | { | 189 | { |
@@ -193,7 +193,7 @@ UTF_FLAG__TO_UTF8__SURROGATE_ERROR | |||
193 | 193 | ||
194 | In Linux : | 194 | In Linux : |
195 | use-case-1: UTF-8 -> UTF-16 -> UTF-8 doesn't generate UTF-16 SINGLE-SURROGATE, | 195 | use-case-1: UTF-8 -> UTF-16 -> UTF-8 doesn't generate UTF-16 SINGLE-SURROGATE, |
196 | if (UTF_FLAG__FROM_UTF8__SURROGATE_ERROR) is used. | 196 | if (Z7_UTF_FLAG_FROM_UTF8_SURROGATE_ERROR) is used. |
197 | use-case 2: UTF-16-7z (with SINGLE-SURROGATE from Windows) -> UTF-8 (Linux) | 197 | use-case 2: UTF-16-7z (with SINGLE-SURROGATE from Windows) -> UTF-8 (Linux) |
198 | will generate SINGLE-SURROGATE-UTF-8 here. | 198 | will generate SINGLE-SURROGATE-UTF-8 here. |
199 | } | 199 | } |
@@ -206,17 +206,17 @@ UTF_FLAG__TO_UTF8__SURROGATE_ERROR | |||
206 | } | 206 | } |
207 | 207 | ||
208 | 208 | ||
209 | UTF_FLAG__TO_UTF8__EXTRACT_BMP_ESCAPE | 209 | Z7_UTF_FLAG_TO_UTF8_EXTRACT_BMP_ESCAPE |
210 | 210 | ||
211 | if (flag is NOT set) it doesn't extract raw 8-bit symbol from Escape-Plane-16 | 211 | if (flag is NOT set) it doesn't extract raw 8-bit symbol from Escape-Plane-16 |
212 | if (flag is set) it extracts raw 8-bit symbol from Escape-Plane-16 | 212 | if (flag is set) it extracts raw 8-bit symbol from Escape-Plane-16 |
213 | 213 | ||
214 | in Linux we need some way to extract NON-UTF8 RAW 8-bits from BMP (UTF-16 7z archive): | 214 | in Linux we need some way to extract NON-UTF8 RAW 8-bits from BMP (UTF-16 7z archive): |
215 | if (we use High-Escape-Plane), we can transfer BMP escapes to High-Escape-Plane. | 215 | if (we use High-Escape-Plane), we can transfer BMP escapes to High-Escape-Plane. |
216 | if (we don't use High-Escape-Plane), we must use UTF_FLAG__TO_UTF8__EXTRACT_BMP_ESCAPE. | 216 | if (we don't use High-Escape-Plane), we must use Z7_UTF_FLAG_TO_UTF8_EXTRACT_BMP_ESCAPE. |
217 | 217 | ||
218 | 218 | ||
219 | UTF_FLAG__TO_UTF8__PARSE_HIGH_ESCAPE | 219 | Z7_UTF_FLAG_TO_UTF8_PARSE_HIGH_ESCAPE |
220 | // that flag affects the code only if (wchar_t is 32-bit) | 220 | // that flag affects the code only if (wchar_t is 32-bit) |
221 | // that mode with high-escape can be disabled now in UTFConvert.cpp | 221 | // that mode with high-escape can be disabled now in UTFConvert.cpp |
222 | if (flag is NOT set) | 222 | if (flag is NOT set) |
@@ -228,19 +228,19 @@ Main use cases: | |||
228 | 228 | ||
229 | WIN32 : UTF-16-RAW -> UTF-8 (archive) -> UTF-16-RAW | 229 | WIN32 : UTF-16-RAW -> UTF-8 (archive) -> UTF-16-RAW |
230 | { | 230 | { |
231 | Do NOT set UTF_FLAG__TO_UTF8__EXTRACT_BMP_ESCAPE. | 231 | Do NOT set Z7_UTF_FLAG_TO_UTF8_EXTRACT_BMP_ESCAPE. |
232 | Do NOT set UTF_FLAG__TO_UTF8__SURROGATE_ERROR. | 232 | Do NOT set Z7_UTF_FLAG_TO_UTF8_SURROGATE_ERROR. |
233 | So we restore original UTF-16-RAW. | 233 | So we restore original UTF-16-RAW. |
234 | } | 234 | } |
235 | 235 | ||
236 | Linix : UTF-8 with Escapes -> UTF-16 (7z archive) -> UTF-8 with Escapes | 236 | Linix : UTF-8 with Escapes -> UTF-16 (7z archive) -> UTF-8 with Escapes |
237 | set UTF_FLAG__TO_UTF8__EXTRACT_BMP_ESCAPE to extract non-UTF from 7z archive | 237 | set Z7_UTF_FLAG_TO_UTF8_EXTRACT_BMP_ESCAPE to extract non-UTF from 7z archive |
238 | set UTF_FLAG__TO_UTF8__PARSE_HIGH_ESCAPE for intermediate UTF-16. | 238 | set Z7_UTF_FLAG_TO_UTF8_PARSE_HIGH_ESCAPE for intermediate UTF-16. |
239 | Note: high esacape mode can be ignored now in UTFConvert.cpp | 239 | Note: high esacape mode can be ignored now in UTFConvert.cpp |
240 | 240 | ||
241 | macOS: | 241 | macOS: |
242 | the system doesn't support incorrect UTF-8 in file names. | 242 | the system doesn't support incorrect UTF-8 in file names. |
243 | set UTF_FLAG__TO_UTF8__SURROGATE_ERROR | 243 | set Z7_UTF_FLAG_TO_UTF8_SURROGATE_ERROR |
244 | */ | 244 | */ |
245 | 245 | ||
246 | extern unsigned g_Unicode_To_UTF8_Flags; | 246 | extern unsigned g_Unicode_To_UTF8_Flags; |
@@ -261,7 +261,7 @@ bool Unicode_IsThere_BmpEscape(const UString &src); | |||
261 | bool Unicode_IsThere_Utf16SurrogateError(const UString &src); | 261 | bool Unicode_IsThere_Utf16SurrogateError(const UString &src); |
262 | */ | 262 | */ |
263 | 263 | ||
264 | #ifdef _WCHART_IS_16BIT | 264 | #ifdef Z7_WCHART_IS_16BIT |
265 | #define Convert_UnicodeEsc16_To_UnicodeEscHigh(s) | 265 | #define Convert_UnicodeEsc16_To_UnicodeEscHigh(s) |
266 | #else | 266 | #else |
267 | void Convert_UnicodeEsc16_To_UnicodeEscHigh(UString &s); | 267 | void Convert_UnicodeEsc16_To_UnicodeEscHigh(UString &s); |
diff --git a/CPP/Common/Wildcard.cpp b/CPP/Common/Wildcard.cpp index 861f3f7..798cbd9 100644 --- a/CPP/Common/Wildcard.cpp +++ b/CPP/Common/Wildcard.cpp | |||
@@ -125,8 +125,8 @@ static bool EnhancedMaskTest(const wchar_t *mask, const wchar_t *name) | |||
125 | { | 125 | { |
126 | for (;;) | 126 | for (;;) |
127 | { | 127 | { |
128 | wchar_t m = *mask; | 128 | const wchar_t m = *mask; |
129 | wchar_t c = *name; | 129 | const wchar_t c = *name; |
130 | if (m == 0) | 130 | if (m == 0) |
131 | return (c == 0); | 131 | return (c == 0); |
132 | if (m == '*') | 132 | if (m == '*') |
@@ -526,12 +526,10 @@ int CCensor::FindPairForPrefix(const UString &prefix) const | |||
526 | 526 | ||
527 | bool IsDriveColonName(const wchar_t *s) | 527 | bool IsDriveColonName(const wchar_t *s) |
528 | { | 528 | { |
529 | wchar_t c = s[0]; | 529 | unsigned c = s[0]; |
530 | return c != 0 | 530 | c |= 0x20; |
531 | && s[1] == ':' | 531 | c -= 'a'; |
532 | && s[2] == 0 | 532 | return c <= (unsigned)('z' - 'a') && s[1] == ':' && s[2] == 0; |
533 | && ((c >= 'a' && c <= 'z') | ||
534 | || (c >= 'A' && c <= 'Z')); | ||
535 | } | 533 | } |
536 | 534 | ||
537 | unsigned GetNumPrefixParts_if_DrivePath(UStringVector &pathParts) | 535 | unsigned GetNumPrefixParts_if_DrivePath(UStringVector &pathParts) |
diff --git a/CPP/Common/Wildcard.h b/CPP/Common/Wildcard.h index 0fa4887..4f81da9 100644 --- a/CPP/Common/Wildcard.h +++ b/CPP/Common/Wildcard.h | |||
@@ -1,7 +1,7 @@ | |||
1 | // Common/Wildcard.h | 1 | // Common/Wildcard.h |
2 | 2 | ||
3 | #ifndef __COMMON_WILDCARD_H | 3 | #ifndef ZIP7_INC_COMMON_WILDCARD_H |
4 | #define __COMMON_WILDCARD_H | 4 | #define ZIP7_INC_COMMON_WILDCARD_H |
5 | 5 | ||
6 | #include "MyString.h" | 6 | #include "MyString.h" |
7 | 7 | ||
@@ -83,7 +83,7 @@ public: | |||
83 | CCensorNode(): | 83 | CCensorNode(): |
84 | Parent(NULL) | 84 | Parent(NULL) |
85 | // , ExcludeDirItems(false) | 85 | // , ExcludeDirItems(false) |
86 | {}; | 86 | {} |
87 | 87 | ||
88 | CCensorNode(const UString &name, CCensorNode *parent): | 88 | CCensorNode(const UString &name, CCensorNode *parent): |
89 | Parent(parent) | 89 | Parent(parent) |
diff --git a/CPP/Common/XzCrc64Reg.cpp b/CPP/Common/XzCrc64Reg.cpp index 33b5249..e9e67ef 100644 --- a/CPP/Common/XzCrc64Reg.cpp +++ b/CPP/Common/XzCrc64Reg.cpp | |||
@@ -9,34 +9,31 @@ | |||
9 | 9 | ||
10 | #include "../7zip/Common/RegisterCodec.h" | 10 | #include "../7zip/Common/RegisterCodec.h" |
11 | 11 | ||
12 | class CXzCrc64Hasher: | 12 | Z7_CLASS_IMP_COM_1( |
13 | public IHasher, | 13 | CXzCrc64Hasher |
14 | public CMyUnknownImp | 14 | , IHasher |
15 | { | 15 | ) |
16 | UInt64 _crc; | 16 | UInt64 _crc; |
17 | Byte mtDummy[1 << 7]; | ||
18 | |||
19 | public: | 17 | public: |
20 | CXzCrc64Hasher(): _crc(CRC64_INIT_VAL) {} | 18 | Byte _mtDummy[1 << 7]; // it's public to eliminate clang warning: unused private field |
21 | 19 | ||
22 | MY_UNKNOWN_IMP1(IHasher) | 20 | CXzCrc64Hasher(): _crc(CRC64_INIT_VAL) {} |
23 | INTERFACE_IHasher(;) | ||
24 | }; | 21 | }; |
25 | 22 | ||
26 | STDMETHODIMP_(void) CXzCrc64Hasher::Init() throw() | 23 | Z7_COM7F_IMF2(void, CXzCrc64Hasher::Init()) |
27 | { | 24 | { |
28 | _crc = CRC64_INIT_VAL; | 25 | _crc = CRC64_INIT_VAL; |
29 | } | 26 | } |
30 | 27 | ||
31 | STDMETHODIMP_(void) CXzCrc64Hasher::Update(const void *data, UInt32 size) throw() | 28 | Z7_COM7F_IMF2(void, CXzCrc64Hasher::Update(const void *data, UInt32 size)) |
32 | { | 29 | { |
33 | _crc = Crc64Update(_crc, data, size); | 30 | _crc = Crc64Update(_crc, data, size); |
34 | } | 31 | } |
35 | 32 | ||
36 | STDMETHODIMP_(void) CXzCrc64Hasher::Final(Byte *digest) throw() | 33 | Z7_COM7F_IMF2(void, CXzCrc64Hasher::Final(Byte *digest)) |
37 | { | 34 | { |
38 | UInt64 val = CRC64_GET_DIGEST(_crc); | 35 | const UInt64 val = CRC64_GET_DIGEST(_crc); |
39 | SetUi64(digest, val); | 36 | SetUi64(digest, val) |
40 | } | 37 | } |
41 | 38 | ||
42 | REGISTER_HASHER(CXzCrc64Hasher, 0x4, "CRC64", 8) | 39 | REGISTER_HASHER(CXzCrc64Hasher, 0x4, "CRC64", 8) |