diff options
author | Igor Pavlov <87184205+ip7z@users.noreply.github.com> | 2024-05-14 00:00:00 +0000 |
---|---|---|
committer | Igor Pavlov <87184205+ip7z@users.noreply.github.com> | 2024-05-15 23:55:04 +0500 |
commit | fc662341e6f85da78ada0e443f6116b978f79f22 (patch) | |
tree | 1be1cc402a7a9cbc18d4eeea6b141354c2d559e3 /CPP/Common | |
parent | 5b39dc76f1bc82f941d5c800ab9f34407a06b53a (diff) | |
download | 7zip-fc662341e6f85da78ada0e443f6116b978f79f22.tar.gz 7zip-fc662341e6f85da78ada0e443f6116b978f79f22.tar.bz2 7zip-fc662341e6f85da78ada0e443f6116b978f79f22.zip |
24.0524.05
Diffstat (limited to 'CPP/Common')
35 files changed, 1416 insertions, 711 deletions
diff --git a/CPP/Common/AutoPtr.h b/CPP/Common/AutoPtr.h index 0be8a7a..e3c5763 100644 --- a/CPP/Common/AutoPtr.h +++ b/CPP/Common/AutoPtr.h | |||
@@ -3,20 +3,32 @@ | |||
3 | #ifndef ZIP7_INC_COMMON_AUTOPTR_H | 3 | #ifndef ZIP7_INC_COMMON_AUTOPTR_H |
4 | #define ZIP7_INC_COMMON_AUTOPTR_H | 4 | #define ZIP7_INC_COMMON_AUTOPTR_H |
5 | 5 | ||
6 | template<class T> class CMyAutoPtr | 6 | template<class T> class CMyUniquePtr |
7 | // CMyAutoPtr | ||
7 | { | 8 | { |
8 | T *_p; | 9 | T *_p; |
9 | public: | 10 | |
10 | CMyAutoPtr(T *p = NULL) : _p(p) {} | 11 | CMyUniquePtr(CMyUniquePtr<T>& p); // : _p(p.release()) {} |
11 | CMyAutoPtr(CMyAutoPtr<T>& p): _p(p.release()) {} | 12 | CMyUniquePtr<T>& operator=(T *p); |
12 | CMyAutoPtr<T>& operator=(CMyAutoPtr<T>& p) | 13 | CMyUniquePtr<T>& operator=(CMyUniquePtr<T>& p); |
14 | /* | ||
13 | { | 15 | { |
14 | reset(p.release()); | 16 | reset(p.release()); |
15 | return (*this); | 17 | return (*this); |
16 | } | 18 | } |
17 | ~CMyAutoPtr() { delete _p; } | 19 | */ |
20 | void reset(T* p = NULL) | ||
21 | { | ||
22 | if (p != _p) | ||
23 | delete _p; | ||
24 | _p = p; | ||
25 | } | ||
26 | public: | ||
27 | CMyUniquePtr(T *p = NULL) : _p(p) {} | ||
28 | ~CMyUniquePtr() { delete _p; } | ||
18 | T& operator*() const { return *_p; } | 29 | T& operator*() const { return *_p; } |
19 | // T* operator->() const { return (&**this); } | 30 | T* operator->() const { return _p; } |
31 | // operator bool() const { return _p != NULL; } | ||
20 | T* get() const { return _p; } | 32 | T* get() const { return _p; } |
21 | T* release() | 33 | T* release() |
22 | { | 34 | { |
@@ -24,11 +36,10 @@ public: | |||
24 | _p = NULL; | 36 | _p = NULL; |
25 | return tmp; | 37 | return tmp; |
26 | } | 38 | } |
27 | void reset(T* p = NULL) | 39 | void Create_if_Empty() |
28 | { | 40 | { |
29 | if (p != _p) | 41 | if (!_p) |
30 | delete _p; | 42 | _p = new T; |
31 | _p = p; | ||
32 | } | 43 | } |
33 | }; | 44 | }; |
34 | 45 | ||
diff --git a/CPP/Common/CommandLineParser.cpp b/CPP/Common/CommandLineParser.cpp index 465e0fd..319f27f 100644 --- a/CPP/Common/CommandLineParser.cpp +++ b/CPP/Common/CommandLineParser.cpp | |||
@@ -6,6 +6,8 @@ | |||
6 | 6 | ||
7 | namespace NCommandLineParser { | 7 | namespace NCommandLineParser { |
8 | 8 | ||
9 | #ifdef _WIN32 | ||
10 | |||
9 | bool SplitCommandLine(const UString &src, UString &dest1, UString &dest2) | 11 | bool SplitCommandLine(const UString &src, UString &dest1, UString &dest2) |
10 | { | 12 | { |
11 | dest1.Empty(); | 13 | dest1.Empty(); |
@@ -14,7 +16,7 @@ bool SplitCommandLine(const UString &src, UString &dest1, UString &dest2) | |||
14 | unsigned i; | 16 | unsigned i; |
15 | for (i = 0; i < src.Len(); i++) | 17 | for (i = 0; i < src.Len(); i++) |
16 | { | 18 | { |
17 | wchar_t c = src[i]; | 19 | const wchar_t c = src[i]; |
18 | if ((c == L' ' || c == L'\t') && !quoteMode) | 20 | if ((c == L' ' || c == L'\t') && !quoteMode) |
19 | { | 21 | { |
20 | dest2 = src.Ptr(i + 1); | 22 | dest2 = src.Ptr(i + 1); |
@@ -30,6 +32,34 @@ bool SplitCommandLine(const UString &src, UString &dest1, UString &dest2) | |||
30 | 32 | ||
31 | void SplitCommandLine(const UString &s, UStringVector &parts) | 33 | void SplitCommandLine(const UString &s, UStringVector &parts) |
32 | { | 34 | { |
35 | #if 0 | ||
36 | /* we don't use CommandLineToArgvW() because | ||
37 | it can remove tail backslash: | ||
38 | "1\" | ||
39 | converted to | ||
40 | 1" | ||
41 | */ | ||
42 | parts.Clear(); | ||
43 | { | ||
44 | int nArgs; | ||
45 | LPWSTR *szArgList = CommandLineToArgvW(s, &nArgs); | ||
46 | if (szArgList) | ||
47 | { | ||
48 | for (int i = 0; i < nArgs; i++) | ||
49 | { | ||
50 | // printf("%2d: |%S|\n", i, szArglist[i]); | ||
51 | parts.Add(szArgList[i]); | ||
52 | } | ||
53 | LocalFree(szArgList); | ||
54 | return; | ||
55 | } | ||
56 | } | ||
57 | #endif | ||
58 | /* | ||
59 | #ifdef _UNICODE | ||
60 | throw 20240406; | ||
61 | #else | ||
62 | */ | ||
33 | UString sTemp (s); | 63 | UString sTemp (s); |
34 | sTemp.Trim(); | 64 | sTemp.Trim(); |
35 | parts.Clear(); | 65 | parts.Clear(); |
@@ -42,7 +72,9 @@ void SplitCommandLine(const UString &s, UStringVector &parts) | |||
42 | break; | 72 | break; |
43 | sTemp = s2; | 73 | sTemp = s2; |
44 | } | 74 | } |
75 | // #endif | ||
45 | } | 76 | } |
77 | #endif | ||
46 | 78 | ||
47 | 79 | ||
48 | static const char * const kStopSwitchParsing = "--"; | 80 | static const char * const kStopSwitchParsing = "--"; |
@@ -78,7 +110,7 @@ bool CParser::ParseString(const UString &s, const CSwitchForm *switchForms, unsi | |||
78 | for (unsigned i = 0; i < numSwitches; i++) | 110 | for (unsigned i = 0; i < numSwitches; i++) |
79 | { | 111 | { |
80 | const char * const key = switchForms[i].Key; | 112 | const char * const key = switchForms[i].Key; |
81 | unsigned switchLen = MyStringLen(key); | 113 | const unsigned switchLen = MyStringLen(key); |
82 | if ((int)switchLen <= maxLen || pos + switchLen > s.Len()) | 114 | if ((int)switchLen <= maxLen || pos + switchLen > s.Len()) |
83 | continue; | 115 | continue; |
84 | if (IsString1PrefixedByString2_NoCase_Ascii((const wchar_t *)s + pos, key)) | 116 | if (IsString1PrefixedByString2_NoCase_Ascii((const wchar_t *)s + pos, key)) |
@@ -133,7 +165,7 @@ bool CParser::ParseString(const UString &s, const CSwitchForm *switchForms, unsi | |||
133 | case NSwitchType::kChar: | 165 | case NSwitchType::kChar: |
134 | if (rem == 1) | 166 | if (rem == 1) |
135 | { | 167 | { |
136 | wchar_t c = s[pos]; | 168 | const wchar_t c = s[pos]; |
137 | if (c <= 0x7F) | 169 | if (c <= 0x7F) |
138 | { | 170 | { |
139 | sw.PostCharIndex = FindCharPosInString(form.PostCharSet, (char)c); | 171 | sw.PostCharIndex = FindCharPosInString(form.PostCharSet, (char)c); |
@@ -150,6 +182,8 @@ bool CParser::ParseString(const UString &s, const CSwitchForm *switchForms, unsi | |||
150 | sw.PostStrings.Add(s.Ptr(pos)); | 182 | sw.PostStrings.Add(s.Ptr(pos)); |
151 | return true; | 183 | return true; |
152 | } | 184 | } |
185 | // case NSwitchType::kSimple: | ||
186 | default: break; | ||
153 | } | 187 | } |
154 | 188 | ||
155 | if (pos != s.Len()) | 189 | if (pos != s.Len()) |
diff --git a/CPP/Common/Common.h b/CPP/Common/Common.h index 0c77ab4..cde0c38 100644 --- a/CPP/Common/Common.h +++ b/CPP/Common/Common.h | |||
@@ -7,7 +7,9 @@ | |||
7 | #ifndef ZIP7_INC_COMMON_H | 7 | #ifndef ZIP7_INC_COMMON_H |
8 | #define ZIP7_INC_COMMON_H | 8 | #define ZIP7_INC_COMMON_H |
9 | 9 | ||
10 | #include "../../C/Compiler.h" | 10 | #include "../../C/Precomp.h" |
11 | #include "Common0.h" | ||
12 | #include "MyWindows.h" | ||
11 | 13 | ||
12 | /* | 14 | /* |
13 | This file is included to all cpp files in 7-Zip. | 15 | This file is included to all cpp files in 7-Zip. |
@@ -17,297 +19,10 @@ So 7-Zip includes "Common.h" in both modes: | |||
17 | and | 19 | and |
18 | without precompiled StdAfx.h | 20 | without precompiled StdAfx.h |
19 | 21 | ||
20 | If you use 7-Zip code, you must include "Common.h" before other h files of 7-zip. | 22 | include "Common.h" before other h files of 7-zip, |
21 | If you don't need some things that are used in 7-Zip, | 23 | if you need predefined macros. |
22 | you can change this h file or h files included in this file. | 24 | do not include "Common.h", if you need only interfaces, |
23 | */ | 25 | and you don't need predefined macros. |
24 | |||
25 | #ifdef _MSC_VER | ||
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 | ||
43 | |||
44 | #if _MSC_VER > 1200 | ||
45 | // -Wall warnings | ||
46 | |||
47 | #if _MSC_VER <= 1600 | ||
48 | #pragma warning(disable : 4917) // 'OLE_HANDLE' : a GUID can only be associated with a class, interface or namespace | ||
49 | #endif | ||
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 | ||
79 | |||
80 | #endif // _MSC_VER > 1200 | ||
81 | #endif // _MSC_VER | ||
82 | |||
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 | ||
140 | |||
141 | |||
142 | /* There is BUG in MSVC 6.0 compiler for operator new[]: | ||
143 | It doesn't check overflow, when it calculates size in bytes for allocated array. | ||
144 | So we can use Z7_ARRAY_NEW macro instead of new[] operator. */ | ||
145 | |||
146 | #if defined(_MSC_VER) && (_MSC_VER == 1200) && !defined(_WIN64) | ||
147 | #define Z7_ARRAY_NEW(p, T, size) p = new T[((size) > (unsigned)0xFFFFFFFF / sizeof(T)) ? (unsigned)0xFFFFFFFF / sizeof(T) : (size)]; | ||
148 | #else | ||
149 | #define Z7_ARRAY_NEW(p, T, size) p = new T[size]; | ||
150 | #endif | ||
151 | |||
152 | #if (defined(__GNUC__) && (__GNUC__ >= 8)) | ||
153 | #define Z7_ATTR_NORETURN __attribute__((noreturn)) | ||
154 | #elif (defined(__clang__) && (__clang_major__ >= 3)) | ||
155 | #if __has_feature(cxx_attributes) | ||
156 | #define Z7_ATTR_NORETURN [[noreturn]] | ||
157 | #else | ||
158 | #define Z7_ATTR_NORETURN __attribute__((noreturn)) | ||
159 | #endif | ||
160 | #elif (defined(_MSC_VER) && (_MSC_VER >= 1900)) | ||
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 | ||
181 | #else | ||
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 | ||
188 | #endif | ||
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) | ||
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 | */ | 26 | */ |
280 | 27 | ||
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 | 28 | #endif |
309 | |||
310 | #endif // Z7_REDEFINE_NULL | ||
311 | |||
312 | // for precompiler: | ||
313 | #include "MyWindows.h" | ||
diff --git a/CPP/Common/Common0.h b/CPP/Common/Common0.h new file mode 100644 index 0000000..55606cd --- /dev/null +++ b/CPP/Common/Common0.h | |||
@@ -0,0 +1,330 @@ | |||
1 | // Common0.h | ||
2 | |||
3 | #if defined(_MSC_VER) && _MSC_VER >= 1800 | ||
4 | #pragma warning(disable : 4464) // relative include path contains '..' | ||
5 | #endif | ||
6 | |||
7 | #ifndef ZIP7_INC_COMMON0_H | ||
8 | #define ZIP7_INC_COMMON0_H | ||
9 | |||
10 | #include "../../C/Compiler.h" | ||
11 | |||
12 | /* | ||
13 | This file contains compiler related things for cpp files. | ||
14 | This file is included to all cpp files in 7-Zip via "Common.h". | ||
15 | Also this file is included in "IDecl.h" (that is included in interface files). | ||
16 | So external modules can use 7-Zip interfaces without | ||
17 | predefined macros defined in "Common.h". | ||
18 | */ | ||
19 | |||
20 | #ifdef _MSC_VER | ||
21 | #pragma warning(disable : 4710) // function not inlined | ||
22 | // 'CUncopyable::CUncopyable': | ||
23 | #pragma warning(disable : 4514) // unreferenced inline function has been removed | ||
24 | #if _MSC_VER < 1300 | ||
25 | #pragma warning(disable : 4702) // unreachable code | ||
26 | #pragma warning(disable : 4714) // function marked as __forceinline not inlined | ||
27 | #pragma warning(disable : 4786) // identifier was truncated to '255' characters in the debug information | ||
28 | #endif | ||
29 | #if _MSC_VER < 1400 | ||
30 | #pragma warning(disable : 4511) // copy constructor could not be generated // #pragma warning(disable : 4512) // assignment operator could not be generated | ||
31 | #pragma warning(disable : 4512) // assignment operator could not be generated | ||
32 | #endif | ||
33 | #if _MSC_VER > 1400 && _MSC_VER <= 1900 | ||
34 | // #pragma warning(disable : 4996) | ||
35 | // strcat: This function or variable may be unsafe | ||
36 | // GetVersion was declared deprecated | ||
37 | #endif | ||
38 | |||
39 | #if _MSC_VER > 1200 | ||
40 | // -Wall warnings | ||
41 | |||
42 | #if _MSC_VER <= 1600 | ||
43 | #pragma warning(disable : 4917) // 'OLE_HANDLE' : a GUID can only be associated with a class, interface or namespace | ||
44 | #endif | ||
45 | |||
46 | // #pragma warning(disable : 4061) // enumerator '' in switch of enum '' is not explicitly handled by a case label | ||
47 | // #pragma warning(disable : 4266) // no override available for virtual member function from base ''; function is hidden | ||
48 | #pragma warning(disable : 4625) // copy constructor was implicitly defined as deleted | ||
49 | #pragma warning(disable : 4626) // assignment operator was implicitly defined as deleted | ||
50 | #if _MSC_VER >= 1600 && _MSC_VER < 1920 | ||
51 | #pragma warning(disable : 4571) // Informational: catch(...) semantics changed since Visual C++ 7.1; structured exceptions (SEH) are no longer caught | ||
52 | #endif | ||
53 | #if _MSC_VER >= 1600 | ||
54 | #pragma warning(disable : 4365) // 'initializing' : conversion from 'int' to 'unsigned int', signed / unsigned mismatch | ||
55 | #endif | ||
56 | #if _MSC_VER < 1800 | ||
57 | // we disable the warning, if we don't use 'final' in class | ||
58 | #pragma warning(disable : 4265) // class has virtual functions, but destructor is not virtual | ||
59 | #endif | ||
60 | |||
61 | #if _MSC_VER >= 1900 | ||
62 | #pragma warning(disable : 5026) // move constructor was implicitly defined as deleted | ||
63 | #pragma warning(disable : 5027) // move assignment operator was implicitly defined as deleted | ||
64 | #endif | ||
65 | #if _MSC_VER >= 1912 | ||
66 | #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. | ||
67 | #endif | ||
68 | #if _MSC_VER >= 1925 | ||
69 | // #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 | ||
70 | #endif | ||
71 | #if _MSC_VER >= 1934 | ||
72 | // #pragma warning(disable : 5264) // const variable is not used | ||
73 | #endif | ||
74 | |||
75 | #endif // _MSC_VER > 1200 | ||
76 | #endif // _MSC_VER | ||
77 | |||
78 | |||
79 | #if defined(_MSC_VER) // && !defined(__clang__) | ||
80 | #define Z7_DECLSPEC_NOTHROW __declspec(nothrow) | ||
81 | #elif defined(__clang__) || defined(__GNUC__) | ||
82 | #define Z7_DECLSPEC_NOTHROW __attribute__((nothrow)) | ||
83 | #else | ||
84 | #define Z7_DECLSPEC_NOTHROW | ||
85 | #endif | ||
86 | |||
87 | /* | ||
88 | #if defined (_MSC_VER) && _MSC_VER >= 1900 \ | ||
89 | || defined(__clang__) && __clang_major__ >= 6 \ | ||
90 | || defined(__GNUC__) && __GNUC__ >= 6 | ||
91 | #define Z7_noexcept noexcept | ||
92 | #else | ||
93 | #define Z7_noexcept throw() | ||
94 | #endif | ||
95 | */ | ||
96 | |||
97 | |||
98 | #if defined(__clang__) | ||
99 | |||
100 | #if /* defined(_WIN32) && */ __clang_major__ >= 16 | ||
101 | #pragma GCC diagnostic ignored "-Wc++98-compat-pedantic" | ||
102 | #endif | ||
103 | |||
104 | #if __clang_major__ >= 4 && __clang_major__ < 12 && !defined(_WIN32) | ||
105 | /* | ||
106 | if compiled with new GCC libstdc++, GCC libstdc++ can use: | ||
107 | 13.2.0/include/c++/ | ||
108 | <new> : #define _NEW | ||
109 | <stdlib.h> : #define _GLIBCXX_STDLIB_H 1 | ||
110 | */ | ||
111 | #pragma GCC diagnostic ignored "-Wreserved-id-macro" | ||
112 | #endif | ||
113 | |||
114 | // noexcept, final, = delete | ||
115 | #pragma GCC diagnostic ignored "-Wc++98-compat" | ||
116 | #if __clang_major__ >= 4 | ||
117 | // throw() dynamic exception specifications are deprecated | ||
118 | #pragma GCC diagnostic ignored "-Wdeprecated-dynamic-exception-spec" | ||
119 | #endif | ||
120 | |||
121 | #if __clang_major__ <= 6 // check it | ||
122 | #pragma GCC diagnostic ignored "-Wsign-conversion" | ||
123 | #endif | ||
124 | |||
125 | #pragma GCC diagnostic ignored "-Wold-style-cast" | ||
126 | #pragma GCC diagnostic ignored "-Wglobal-constructors" | ||
127 | #pragma GCC diagnostic ignored "-Wexit-time-destructors" | ||
128 | |||
129 | #if defined(Z7_LLVM_CLANG_VERSION) && __clang_major__ >= 18 // 18.1.0RC | ||
130 | #pragma GCC diagnostic ignored "-Wswitch-default" | ||
131 | #endif | ||
132 | // #pragma GCC diagnostic ignored "-Wunused-private-field" | ||
133 | // #pragma GCC diagnostic ignored "-Wnonportable-system-include-path" | ||
134 | // #pragma GCC diagnostic ignored "-Wsuggest-override" | ||
135 | // #pragma GCC diagnostic ignored "-Wsign-conversion" | ||
136 | // #pragma GCC diagnostic ignored "-Winconsistent-missing-override" | ||
137 | // #pragma GCC diagnostic ignored "-Wsuggest-destructor-override" | ||
138 | // #pragma GCC diagnostic ignored "-Wnon-virtual-dtor" | ||
139 | // #pragma GCC diagnostic ignored "-Wdeprecated-copy-with-user-provided-dtor" | ||
140 | // #pragma GCC diagnostic ignored "-Wdeprecated-copy-dtor" | ||
141 | // #ifndef _WIN32 | ||
142 | // #pragma GCC diagnostic ignored "-Wweak-vtables" | ||
143 | // #endif | ||
144 | /* | ||
145 | #if defined(Z7_GCC_VERSION) && (Z7_GCC_VERSION >= 40400) \ | ||
146 | || defined(Z7_CLANG_VERSION) && (Z7_CLANG_VERSION >= 30000) | ||
147 | // enumeration values not explicitly handled in switch | ||
148 | #pragma GCC diagnostic ignored "-Wswitch-enum" | ||
149 | #endif | ||
150 | */ | ||
151 | #endif // __clang__ | ||
152 | |||
153 | |||
154 | #ifdef __GNUC__ | ||
155 | // #pragma GCC diagnostic ignored "-Wdelete-non-virtual-dtor" | ||
156 | #endif | ||
157 | |||
158 | |||
159 | /* There is BUG in MSVC 6.0 compiler for operator new[]: | ||
160 | It doesn't check overflow, when it calculates size in bytes for allocated array. | ||
161 | So we can use Z7_ARRAY_NEW macro instead of new[] operator. */ | ||
162 | |||
163 | #if defined(_MSC_VER) && (_MSC_VER == 1200) && !defined(_WIN64) | ||
164 | #define Z7_ARRAY_NEW(p, T, size) p = new T[((size) > 0xFFFFFFFFu / sizeof(T)) ? 0xFFFFFFFFu / sizeof(T) : (size)]; | ||
165 | #else | ||
166 | #define Z7_ARRAY_NEW(p, T, size) p = new T[size]; | ||
167 | #endif | ||
168 | |||
169 | #if (defined(__GNUC__) && (__GNUC__ >= 8)) | ||
170 | #define Z7_ATTR_NORETURN __attribute__((noreturn)) | ||
171 | #elif (defined(__clang__) && (__clang_major__ >= 3)) | ||
172 | #if __has_feature(cxx_attributes) | ||
173 | #define Z7_ATTR_NORETURN [[noreturn]] | ||
174 | #else | ||
175 | #define Z7_ATTR_NORETURN __attribute__((noreturn)) | ||
176 | #endif | ||
177 | #elif (defined(_MSC_VER) && (_MSC_VER >= 1900)) | ||
178 | #define Z7_ATTR_NORETURN [[noreturn]] | ||
179 | #else | ||
180 | #define Z7_ATTR_NORETURN | ||
181 | #endif | ||
182 | |||
183 | |||
184 | // final in "GCC 4.7.0" | ||
185 | // In C++98 and C++03 code the alternative spelling __final can be used instead (this is a GCC extension.) | ||
186 | |||
187 | #if defined (__cplusplus) && __cplusplus >= 201103L \ | ||
188 | || defined(_MSC_VER) && _MSC_VER >= 1800 \ | ||
189 | || defined(__clang__) && __clang_major__ >= 4 \ | ||
190 | /* || defined(__GNUC__) && __GNUC__ >= 9 */ | ||
191 | #define Z7_final final | ||
192 | #if defined(__clang__) && __cplusplus < 201103L | ||
193 | #pragma GCC diagnostic ignored "-Wc++11-extensions" | ||
194 | #endif | ||
195 | #elif defined (__cplusplus) && __cplusplus >= 199711L \ | ||
196 | && defined(__GNUC__) && __GNUC__ >= 4 && !defined(__clang__) | ||
197 | #define Z7_final __final | ||
198 | #else | ||
199 | #define Z7_final | ||
200 | #if defined(__clang__) && __clang_major__ >= 4 \ | ||
201 | || defined(__GNUC__) && __GNUC__ >= 4 | ||
202 | #pragma GCC diagnostic ignored "-Wnon-virtual-dtor" | ||
203 | #pragma GCC diagnostic ignored "-Wdelete-non-virtual-dtor" | ||
204 | #endif | ||
205 | #endif | ||
206 | |||
207 | #define Z7_class_final(c) class c Z7_final | ||
208 | |||
209 | |||
210 | #if defined (__cplusplus) && __cplusplus >= 201103L \ | ||
211 | || (defined(_MSC_VER) && _MSC_VER >= 1800) | ||
212 | #define Z7_CPP_IS_SUPPORTED_default | ||
213 | #define Z7_eq_delete = delete | ||
214 | // #define Z7_DECL_DEFAULT_COPY_CONSTRUCTOR_IF_SUPPORTED(c) c(const c& k) = default; | ||
215 | #else | ||
216 | #define Z7_eq_delete | ||
217 | // #define Z7_DECL_DEFAULT_COPY_CONSTRUCTOR_IF_SUPPORTED(c) | ||
218 | #endif | ||
219 | |||
220 | |||
221 | #if defined(__cplusplus) && (__cplusplus >= 201103L) \ | ||
222 | || defined(_MSC_VER) && (_MSC_VER >= 1400) /* && (_MSC_VER != 1600) */ \ | ||
223 | || defined(__clang__) && __clang_major__ >= 4 | ||
224 | #if defined(_MSC_VER) && (_MSC_VER == 1600) /* && (_MSC_VER != 1600) */ | ||
225 | #pragma warning(disable : 4481) // nonstandard extension used: override specifier 'override' | ||
226 | #define Z7_DESTRUCTOR_override | ||
227 | #else | ||
228 | #define Z7_DESTRUCTOR_override override | ||
229 | #endif | ||
230 | #define Z7_override override | ||
231 | #else | ||
232 | #define Z7_override | ||
233 | #define Z7_DESTRUCTOR_override | ||
234 | #endif | ||
235 | |||
236 | |||
237 | |||
238 | #define Z7_CLASS_NO_COPY(cls) \ | ||
239 | private: \ | ||
240 | cls(const cls &) Z7_eq_delete; \ | ||
241 | cls &operator=(const cls &) Z7_eq_delete; | ||
242 | |||
243 | class CUncopyable | ||
244 | { | ||
245 | protected: | ||
246 | CUncopyable() {} // allow constructor | ||
247 | // ~CUncopyable() {} | ||
248 | Z7_CLASS_NO_COPY(CUncopyable) | ||
249 | }; | ||
250 | |||
251 | #define MY_UNCOPYABLE :private CUncopyable | ||
252 | // #define MY_UNCOPYABLE | ||
253 | |||
254 | |||
255 | // typedef void (*Z7_void_Function)(void); | ||
256 | |||
257 | #if defined(__clang__) || defined(__GNUC__) | ||
258 | #define Z7_CAST_FUNC(t, e) reinterpret_cast<t>(reinterpret_cast<Z7_void_Function>(e)) | ||
259 | #else | ||
260 | #define Z7_CAST_FUNC(t, e) reinterpret_cast<t>(reinterpret_cast<void*>(e)) | ||
261 | // #define Z7_CAST_FUNC(t, e) reinterpret_cast<t>(e) | ||
262 | #endif | ||
263 | |||
264 | #define Z7_GET_PROC_ADDRESS(func_type, hmodule, func_name) \ | ||
265 | Z7_CAST_FUNC(func_type, GetProcAddress(hmodule, func_name)) | ||
266 | |||
267 | // || defined(__clang__) | ||
268 | // || defined(__GNUC__) | ||
269 | |||
270 | #if defined(_MSC_VER) && (_MSC_VER >= 1400) | ||
271 | #define Z7_DECLSPEC_NOVTABLE __declspec(novtable) | ||
272 | #else | ||
273 | #define Z7_DECLSPEC_NOVTABLE | ||
274 | #endif | ||
275 | |||
276 | #ifdef __clang__ | ||
277 | #define Z7_PURE_INTERFACES_BEGIN \ | ||
278 | _Pragma("GCC diagnostic push") \ | ||
279 | _Pragma("GCC diagnostic ignored \"-Wnon-virtual-dtor\"") | ||
280 | _Pragma("GCC diagnostic ignored \"-Wweak-vtables\"") | ||
281 | #define Z7_PURE_INTERFACES_END \ | ||
282 | _Pragma("GCC diagnostic pop") | ||
283 | #else | ||
284 | #define Z7_PURE_INTERFACES_BEGIN | ||
285 | #define Z7_PURE_INTERFACES_END | ||
286 | #endif | ||
287 | |||
288 | // NewHandler.h and NewHandler.cpp redefine operator new() to throw exceptions, if compiled with old MSVC compilers | ||
289 | #include "NewHandler.h" | ||
290 | |||
291 | /* | ||
292 | // #define ARRAY_SIZE(a) (sizeof(a) / sizeof((a)[0])) | ||
293 | #ifndef ARRAY_SIZE | ||
294 | #define ARRAY_SIZE(a) Z7_ARRAY_SIZE(a) | ||
295 | #endif | ||
296 | */ | ||
297 | |||
298 | #endif // ZIP7_INC_COMMON0_H | ||
299 | |||
300 | |||
301 | |||
302 | // #define Z7_REDEFINE_NULL | ||
303 | |||
304 | #if defined(Z7_REDEFINE_NULL) /* && (!defined(__clang__) || defined(_MSC_VER)) */ | ||
305 | |||
306 | // NULL is defined in <stddef.h> | ||
307 | #include <stddef.h> | ||
308 | #undef NULL | ||
309 | |||
310 | #ifdef __cplusplus | ||
311 | #if defined (__cplusplus) && __cplusplus >= 201103L \ | ||
312 | || (defined(_MSC_VER) && _MSC_VER >= 1800) | ||
313 | #define NULL nullptr | ||
314 | #else | ||
315 | #define NULL 0 | ||
316 | #endif | ||
317 | #else | ||
318 | #define NULL ((void *)0) | ||
319 | #endif | ||
320 | |||
321 | #else // Z7_REDEFINE_NULL | ||
322 | |||
323 | #if defined(__clang__) && __clang_major__ >= 5 | ||
324 | #pragma GCC diagnostic ignored "-Wzero-as-null-pointer-constant" | ||
325 | #endif | ||
326 | |||
327 | #endif // Z7_REDEFINE_NULL | ||
328 | |||
329 | // for precompiler: | ||
330 | // #include "MyWindows.h" | ||
diff --git a/CPP/Common/CrcReg.cpp b/CPP/Common/CrcReg.cpp index 6cda892..cd5d3da 100644 --- a/CPP/Common/CrcReg.cpp +++ b/CPP/Common/CrcReg.cpp | |||
@@ -11,14 +11,6 @@ | |||
11 | 11 | ||
12 | EXTERN_C_BEGIN | 12 | EXTERN_C_BEGIN |
13 | 13 | ||
14 | // UInt32 Z7_FASTCALL CrcUpdateT1(UInt32 v, const void *data, size_t size, const UInt32 *table); | ||
15 | |||
16 | extern CRC_FUNC g_CrcUpdate; | ||
17 | // extern CRC_FUNC g_CrcUpdateT4; | ||
18 | extern CRC_FUNC g_CrcUpdateT8; | ||
19 | extern CRC_FUNC g_CrcUpdateT0_32; | ||
20 | extern CRC_FUNC g_CrcUpdateT0_64; | ||
21 | |||
22 | EXTERN_C_END | 14 | EXTERN_C_END |
23 | 15 | ||
24 | Z7_CLASS_IMP_COM_2( | 16 | Z7_CLASS_IMP_COM_2( |
@@ -27,7 +19,7 @@ Z7_CLASS_IMP_COM_2( | |||
27 | , ICompressSetCoderProperties | 19 | , ICompressSetCoderProperties |
28 | ) | 20 | ) |
29 | UInt32 _crc; | 21 | UInt32 _crc; |
30 | CRC_FUNC _updateFunc; | 22 | Z7_CRC_UPDATE_FUNC _updateFunc; |
31 | 23 | ||
32 | Z7_CLASS_NO_COPY(CCrcHasher) | 24 | Z7_CLASS_NO_COPY(CCrcHasher) |
33 | 25 | ||
@@ -40,17 +32,10 @@ public: | |||
40 | 32 | ||
41 | bool CCrcHasher::SetFunctions(UInt32 tSize) | 33 | bool CCrcHasher::SetFunctions(UInt32 tSize) |
42 | { | 34 | { |
43 | CRC_FUNC f = NULL; | 35 | const Z7_CRC_UPDATE_FUNC f = z7_GetFunc_CrcUpdate(tSize); |
44 | if (tSize == 0) f = g_CrcUpdate; | ||
45 | // else if (tSize == 1) f = CrcUpdateT1; | ||
46 | // else if (tSize == 4) f = g_CrcUpdateT4; | ||
47 | else if (tSize == 8) f = g_CrcUpdateT8; | ||
48 | else if (tSize == 32) f = g_CrcUpdateT0_32; | ||
49 | else if (tSize == 64) f = g_CrcUpdateT0_64; | ||
50 | |||
51 | if (!f) | 36 | if (!f) |
52 | { | 37 | { |
53 | _updateFunc = g_CrcUpdate; | 38 | _updateFunc = CrcUpdate; |
54 | return false; | 39 | return false; |
55 | } | 40 | } |
56 | _updateFunc = f; | 41 | _updateFunc = f; |
@@ -80,7 +65,7 @@ Z7_COM7F_IMF2(void, CCrcHasher::Init()) | |||
80 | 65 | ||
81 | Z7_COM7F_IMF2(void, CCrcHasher::Update(const void *data, UInt32 size)) | 66 | Z7_COM7F_IMF2(void, CCrcHasher::Update(const void *data, UInt32 size)) |
82 | { | 67 | { |
83 | _crc = _updateFunc(_crc, data, size, g_CrcTable); | 68 | _crc = _updateFunc(_crc, data, size); |
84 | } | 69 | } |
85 | 70 | ||
86 | Z7_COM7F_IMF2(void, CCrcHasher::Final(Byte *digest)) | 71 | Z7_COM7F_IMF2(void, CCrcHasher::Final(Byte *digest)) |
diff --git a/CPP/Common/DynamicBuffer.h b/CPP/Common/DynamicBuffer.h index 714be4a..b03d371 100644 --- a/CPP/Common/DynamicBuffer.h +++ b/CPP/Common/DynamicBuffer.h | |||
@@ -5,7 +5,7 @@ | |||
5 | 5 | ||
6 | #include <string.h> | 6 | #include <string.h> |
7 | 7 | ||
8 | #include "Common.h" | 8 | #include "MyTypes.h" |
9 | 9 | ||
10 | template <class T> class CDynamicBuffer | 10 | template <class T> class CDynamicBuffer |
11 | { | 11 | { |
@@ -43,6 +43,14 @@ public: | |||
43 | operator const T *() const { return _items; } | 43 | operator const T *() const { return _items; } |
44 | ~CDynamicBuffer() { delete []_items; } | 44 | ~CDynamicBuffer() { delete []_items; } |
45 | 45 | ||
46 | void Free() | ||
47 | { | ||
48 | delete []_items; | ||
49 | _items = NULL; | ||
50 | _size = 0; | ||
51 | _pos = 0; | ||
52 | } | ||
53 | |||
46 | T *GetCurPtrAndGrow(size_t addSize) | 54 | T *GetCurPtrAndGrow(size_t addSize) |
47 | { | 55 | { |
48 | size_t rem = _size - _pos; | 56 | size_t rem = _size - _pos; |
@@ -63,6 +71,6 @@ public: | |||
63 | // void Empty() { _pos = 0; } | 71 | // void Empty() { _pos = 0; } |
64 | }; | 72 | }; |
65 | 73 | ||
66 | typedef CDynamicBuffer<unsigned char> CByteDynamicBuffer; | 74 | typedef CDynamicBuffer<Byte> CByteDynamicBuffer; |
67 | 75 | ||
68 | #endif | 76 | #endif |
diff --git a/CPP/Common/IntToString.cpp b/CPP/Common/IntToString.cpp index 21b0680..0a7cb3b 100644 --- a/CPP/Common/IntToString.cpp +++ b/CPP/Common/IntToString.cpp | |||
@@ -7,10 +7,19 @@ | |||
7 | #include "IntToString.h" | 7 | #include "IntToString.h" |
8 | 8 | ||
9 | #define CONVERT_INT_TO_STR(charType, tempSize) \ | 9 | #define CONVERT_INT_TO_STR(charType, tempSize) \ |
10 | unsigned char temp[tempSize]; unsigned i = 0; \ | 10 | if (val < 10) \ |
11 | while (val >= 10) { temp[i++] = (unsigned char)('0' + (unsigned)(val % 10)); val /= 10; } \ | 11 | *s++ = (charType)('0' + (unsigned)val); \ |
12 | *s++ = (charType)('0' + (unsigned)val); \ | 12 | else { \ |
13 | while (i != 0) { i--; *s++ = (charType)temp[i]; } \ | 13 | Byte temp[tempSize]; \ |
14 | size_t i = 0; \ | ||
15 | do { \ | ||
16 | temp[++i] = (Byte)('0' + (unsigned)(val % 10)); \ | ||
17 | val /= 10; } \ | ||
18 | while (val >= 10); \ | ||
19 | *s++ = (charType)('0' + (unsigned)val); \ | ||
20 | do { *s++ = (charType)temp[i]; } \ | ||
21 | while (--i); \ | ||
22 | } \ | ||
14 | *s = 0; \ | 23 | *s = 0; \ |
15 | return s; | 24 | return s; |
16 | 25 | ||
@@ -22,88 +31,109 @@ char * ConvertUInt32ToString(UInt32 val, char *s) throw() | |||
22 | char * ConvertUInt64ToString(UInt64 val, char *s) throw() | 31 | char * ConvertUInt64ToString(UInt64 val, char *s) throw() |
23 | { | 32 | { |
24 | if (val <= (UInt32)0xFFFFFFFF) | 33 | if (val <= (UInt32)0xFFFFFFFF) |
25 | { | ||
26 | return ConvertUInt32ToString((UInt32)val, s); | 34 | return ConvertUInt32ToString((UInt32)val, s); |
27 | } | ||
28 | CONVERT_INT_TO_STR(char, 24) | 35 | CONVERT_INT_TO_STR(char, 24) |
29 | } | 36 | } |
30 | 37 | ||
31 | void ConvertUInt64ToOct(UInt64 val, char *s) throw() | 38 | wchar_t * ConvertUInt32ToString(UInt32 val, wchar_t *s) throw() |
32 | { | 39 | { |
33 | UInt64 v = val; | 40 | CONVERT_INT_TO_STR(wchar_t, 16) |
34 | unsigned i; | 41 | } |
35 | for (i = 1;; i++) | 42 | |
43 | wchar_t * ConvertUInt64ToString(UInt64 val, wchar_t *s) throw() | ||
44 | { | ||
45 | if (val <= (UInt32)0xFFFFFFFF) | ||
46 | return ConvertUInt32ToString((UInt32)val, s); | ||
47 | CONVERT_INT_TO_STR(wchar_t, 24) | ||
48 | } | ||
49 | |||
50 | void ConvertInt64ToString(Int64 val, char *s) throw() | ||
51 | { | ||
52 | if (val < 0) | ||
36 | { | 53 | { |
37 | v >>= 3; | 54 | *s++ = '-'; |
38 | if (v == 0) | 55 | val = -val; |
39 | break; | ||
40 | } | 56 | } |
41 | s[i] = 0; | 57 | ConvertUInt64ToString((UInt64)val, s); |
42 | do | 58 | } |
59 | |||
60 | void ConvertInt64ToString(Int64 val, wchar_t *s) throw() | ||
61 | { | ||
62 | if (val < 0) | ||
43 | { | 63 | { |
44 | unsigned t = (unsigned)(val & 0x7); | 64 | *s++ = L'-'; |
45 | val >>= 3; | 65 | val = -val; |
46 | s[--i] = (char)('0' + t); | ||
47 | } | 66 | } |
48 | while (i); | 67 | ConvertUInt64ToString((UInt64)val, s); |
49 | } | 68 | } |
50 | 69 | ||
51 | 70 | ||
52 | #define GET_HEX_CHAR(t) ((char)(((t < 10) ? ('0' + t) : ('A' + (t - 10))))) | 71 | void ConvertUInt64ToOct(UInt64 val, char *s) throw() |
53 | 72 | { | |
54 | static inline char GetHexChar(unsigned t) { return GET_HEX_CHAR(t); } | 73 | { |
74 | UInt64 v = val; | ||
75 | do | ||
76 | s++; | ||
77 | while (v >>= 3); | ||
78 | } | ||
79 | *s = 0; | ||
80 | do | ||
81 | { | ||
82 | const unsigned t = (unsigned)val & 7; | ||
83 | *--s = (char)('0' + t); | ||
84 | } | ||
85 | while (val >>= 3); | ||
86 | } | ||
55 | 87 | ||
88 | MY_ALIGN(16) const char k_Hex_Upper[16] = | ||
89 | { '0','1','2','3','4','5','6','7','8','9','A','B','C','D','E','F' }; | ||
90 | MY_ALIGN(16) const char k_Hex_Lower[16] = | ||
91 | { '0','1','2','3','4','5','6','7','8','9','a','b','c','d','e','f' }; | ||
56 | 92 | ||
57 | void ConvertUInt32ToHex(UInt32 val, char *s) throw() | 93 | void ConvertUInt32ToHex(UInt32 val, char *s) throw() |
58 | { | 94 | { |
59 | UInt32 v = val; | ||
60 | unsigned i; | ||
61 | for (i = 1;; i++) | ||
62 | { | 95 | { |
63 | v >>= 4; | 96 | UInt32 v = val; |
64 | if (v == 0) | 97 | do |
65 | break; | 98 | s++; |
99 | while (v >>= 4); | ||
66 | } | 100 | } |
67 | s[i] = 0; | 101 | *s = 0; |
68 | do | 102 | do |
69 | { | 103 | { |
70 | unsigned t = (unsigned)(val & 0xF); | 104 | const unsigned t = (unsigned)val & 0xF; |
71 | val >>= 4; | 105 | *--s = GET_HEX_CHAR_UPPER(t); |
72 | s[--i] = GET_HEX_CHAR(t); | ||
73 | } | 106 | } |
74 | while (i); | 107 | while (val >>= 4); |
75 | } | 108 | } |
76 | 109 | ||
77 | |||
78 | void ConvertUInt64ToHex(UInt64 val, char *s) throw() | 110 | void ConvertUInt64ToHex(UInt64 val, char *s) throw() |
79 | { | 111 | { |
80 | UInt64 v = val; | ||
81 | unsigned i; | ||
82 | for (i = 1;; i++) | ||
83 | { | 112 | { |
84 | v >>= 4; | 113 | UInt64 v = val; |
85 | if (v == 0) | 114 | do |
86 | break; | 115 | s++; |
116 | while (v >>= 4); | ||
87 | } | 117 | } |
88 | s[i] = 0; | 118 | *s = 0; |
89 | do | 119 | do |
90 | { | 120 | { |
91 | unsigned t = (unsigned)(val & 0xF); | 121 | const unsigned t = (unsigned)val & 0xF; |
92 | val >>= 4; | 122 | *--s = GET_HEX_CHAR_UPPER(t); |
93 | s[--i] = GET_HEX_CHAR(t); | ||
94 | } | 123 | } |
95 | while (i); | 124 | while (val >>= 4); |
96 | } | 125 | } |
97 | 126 | ||
98 | void ConvertUInt32ToHex8Digits(UInt32 val, char *s) throw() | 127 | void ConvertUInt32ToHex8Digits(UInt32 val, char *s) throw() |
99 | { | 128 | { |
100 | s[8] = 0; | 129 | s[8] = 0; |
101 | for (int i = 7; i >= 0; i--) | 130 | int i = 7; |
131 | do | ||
102 | { | 132 | { |
103 | unsigned t = val & 0xF; | 133 | { const unsigned t = (unsigned)val & 0xF; s[i--] = GET_HEX_CHAR_UPPER(t); } |
104 | val >>= 4; | 134 | { const unsigned t = (Byte)val >> 4; val >>= 8; s[i--] = GET_HEX_CHAR_UPPER(t); } |
105 | s[i] = GET_HEX_CHAR(t); | ||
106 | } | 135 | } |
136 | while (i >= 0); | ||
107 | } | 137 | } |
108 | 138 | ||
109 | /* | 139 | /* |
@@ -112,81 +142,74 @@ void ConvertUInt32ToHex8Digits(UInt32 val, wchar_t *s) | |||
112 | s[8] = 0; | 142 | s[8] = 0; |
113 | for (int i = 7; i >= 0; i--) | 143 | for (int i = 7; i >= 0; i--) |
114 | { | 144 | { |
115 | unsigned t = val & 0xF; | 145 | const unsigned t = (unsigned)val & 0xF; |
116 | val >>= 4; | 146 | val >>= 4; |
117 | s[i] = (wchar_t)(((t < 10) ? ('0' + t) : ('A' + (t - 10)))); | 147 | s[i] = GET_HEX_CHAR(t); |
118 | } | 148 | } |
119 | } | 149 | } |
120 | */ | 150 | */ |
121 | 151 | ||
122 | wchar_t * ConvertUInt32ToString(UInt32 val, wchar_t *s) throw() | ||
123 | { | ||
124 | CONVERT_INT_TO_STR(wchar_t, 16) | ||
125 | } | ||
126 | |||
127 | wchar_t * ConvertUInt64ToString(UInt64 val, wchar_t *s) throw() | ||
128 | { | ||
129 | if (val <= (UInt32)0xFFFFFFFF) | ||
130 | { | ||
131 | return ConvertUInt32ToString((UInt32)val, s); | ||
132 | } | ||
133 | CONVERT_INT_TO_STR(wchar_t, 24) | ||
134 | } | ||
135 | 152 | ||
136 | void ConvertInt64ToString(Int64 val, char *s) throw() | 153 | MY_ALIGN(16) static const Byte k_Guid_Pos[] = |
137 | { | 154 | { 6,4,2,0, 11,9, 16,14, 19,21, 24,26,28,30,32,34 }; |
138 | if (val < 0) | ||
139 | { | ||
140 | *s++ = '-'; | ||
141 | val = -val; | ||
142 | } | ||
143 | ConvertUInt64ToString((UInt64)val, s); | ||
144 | } | ||
145 | 155 | ||
146 | void ConvertInt64ToString(Int64 val, wchar_t *s) throw() | 156 | char *RawLeGuidToString(const Byte *g, char *s) throw() |
147 | { | 157 | { |
148 | if (val < 0) | 158 | s[ 8] = '-'; |
159 | s[13] = '-'; | ||
160 | s[18] = '-'; | ||
161 | s[23] = '-'; | ||
162 | s[36] = 0; | ||
163 | for (unsigned i = 0; i < 16; i++) | ||
149 | { | 164 | { |
150 | *s++ = L'-'; | 165 | char *s2 = s + k_Guid_Pos[i]; |
151 | val = -val; | 166 | const unsigned v = g[i]; |
167 | s2[0] = GET_HEX_CHAR_UPPER(v >> 4); | ||
168 | s2[1] = GET_HEX_CHAR_UPPER(v & 0xF); | ||
152 | } | 169 | } |
153 | ConvertUInt64ToString((UInt64)val, s); | 170 | return s + 36; |
154 | } | 171 | } |
155 | 172 | ||
156 | 173 | char *RawLeGuidToString_Braced(const Byte *g, char *s) throw() | |
157 | static void ConvertByteToHex2Digits(unsigned v, char *s) throw() | ||
158 | { | 174 | { |
159 | s[0] = GetHexChar(v >> 4); | 175 | *s++ = '{'; |
160 | s[1] = GetHexChar(v & 0xF); | 176 | s = RawLeGuidToString(g, s); |
177 | *s++ = '}'; | ||
178 | *s = 0; | ||
179 | return s; | ||
161 | } | 180 | } |
162 | 181 | ||
163 | static void ConvertUInt16ToHex4Digits(UInt32 val, char *s) throw() | ||
164 | { | ||
165 | ConvertByteToHex2Digits(val >> 8, s); | ||
166 | ConvertByteToHex2Digits(val & 0xFF, s + 2); | ||
167 | } | ||
168 | 182 | ||
169 | char *RawLeGuidToString(const Byte *g, char *s) throw() | 183 | void ConvertDataToHex_Lower(char *dest, const Byte *src, size_t size) throw() |
170 | { | 184 | { |
171 | ConvertUInt32ToHex8Digits(GetUi32(g ), s); s += 8; *s++ = '-'; | 185 | if (size) |
172 | ConvertUInt16ToHex4Digits(GetUi16(g + 4), s); s += 4; *s++ = '-'; | ||
173 | ConvertUInt16ToHex4Digits(GetUi16(g + 6), s); s += 4; *s++ = '-'; | ||
174 | for (unsigned i = 0; i < 8; i++) | ||
175 | { | 186 | { |
176 | if (i == 2) | 187 | const Byte *lim = src + size; |
177 | *s++ = '-'; | 188 | do |
178 | ConvertByteToHex2Digits(g[8 + i], s); | 189 | { |
179 | s += 2; | 190 | const unsigned b = *src++; |
191 | dest[0] = GET_HEX_CHAR_LOWER(b >> 4); | ||
192 | dest[1] = GET_HEX_CHAR_LOWER(b & 0xF); | ||
193 | dest += 2; | ||
194 | } | ||
195 | while (src != lim); | ||
180 | } | 196 | } |
181 | *s = 0; | 197 | *dest = 0; |
182 | return s; | ||
183 | } | 198 | } |
184 | 199 | ||
185 | char *RawLeGuidToString_Braced(const Byte *g, char *s) throw() | 200 | void ConvertDataToHex_Upper(char *dest, const Byte *src, size_t size) throw() |
186 | { | 201 | { |
187 | *s++ = '{'; | 202 | if (size) |
188 | s = RawLeGuidToString(g, s); | 203 | { |
189 | *s++ = '}'; | 204 | const Byte *lim = src + size; |
190 | *s = 0; | 205 | do |
191 | return s; | 206 | { |
207 | const unsigned b = *src++; | ||
208 | dest[0] = GET_HEX_CHAR_UPPER(b >> 4); | ||
209 | dest[1] = GET_HEX_CHAR_UPPER(b & 0xF); | ||
210 | dest += 2; | ||
211 | } | ||
212 | while (src != lim); | ||
213 | } | ||
214 | *dest = 0; | ||
192 | } | 215 | } |
diff --git a/CPP/Common/IntToString.h b/CPP/Common/IntToString.h index f4fc662..2f096d6 100644 --- a/CPP/Common/IntToString.h +++ b/CPP/Common/IntToString.h | |||
@@ -12,19 +12,43 @@ char * ConvertUInt64ToString(UInt64 value, char *s) throw(); | |||
12 | 12 | ||
13 | wchar_t * ConvertUInt32ToString(UInt32 value, wchar_t *s) throw(); | 13 | wchar_t * ConvertUInt32ToString(UInt32 value, wchar_t *s) throw(); |
14 | wchar_t * ConvertUInt64ToString(UInt64 value, wchar_t *s) throw(); | 14 | wchar_t * ConvertUInt64ToString(UInt64 value, wchar_t *s) throw(); |
15 | void ConvertInt64ToString(Int64 value, char *s) throw(); | ||
16 | void ConvertInt64ToString(Int64 value, wchar_t *s) throw(); | ||
15 | 17 | ||
16 | void ConvertUInt64ToOct(UInt64 value, char *s) throw(); | 18 | void ConvertUInt64ToOct(UInt64 value, char *s) throw(); |
17 | 19 | ||
20 | extern const char k_Hex_Upper[16]; | ||
21 | extern const char k_Hex_Lower[16]; | ||
22 | |||
23 | #define GET_HEX_CHAR_UPPER(t) (k_Hex_Upper[t]) | ||
24 | #define GET_HEX_CHAR_LOWER(t) (k_Hex_Lower[t]) | ||
25 | /* | ||
26 | // #define GET_HEX_CHAR_UPPER(t) ((char)(((t < 10) ? ('0' + t) : ('A' + (t - 10))))) | ||
27 | static inline unsigned GetHex_Lower(unsigned v) | ||
28 | { | ||
29 | const unsigned v0 = v + '0'; | ||
30 | v += 'a' - 10; | ||
31 | if (v < 'a') | ||
32 | v = v0; | ||
33 | return v; | ||
34 | } | ||
35 | static inline char GetHex_Upper(unsigned v) | ||
36 | { | ||
37 | return (char)((v < 10) ? ('0' + v) : ('A' + (v - 10))); | ||
38 | } | ||
39 | */ | ||
40 | |||
41 | |||
18 | void ConvertUInt32ToHex(UInt32 value, char *s) throw(); | 42 | void ConvertUInt32ToHex(UInt32 value, char *s) throw(); |
19 | void ConvertUInt64ToHex(UInt64 value, char *s) throw(); | 43 | void ConvertUInt64ToHex(UInt64 value, char *s) throw(); |
20 | void ConvertUInt32ToHex8Digits(UInt32 value, char *s) throw(); | 44 | void ConvertUInt32ToHex8Digits(UInt32 value, char *s) throw(); |
21 | // void ConvertUInt32ToHex8Digits(UInt32 value, wchar_t *s) throw(); | 45 | // void ConvertUInt32ToHex8Digits(UInt32 value, wchar_t *s) throw(); |
22 | 46 | ||
23 | void ConvertInt64ToString(Int64 value, char *s) throw(); | ||
24 | void ConvertInt64ToString(Int64 value, wchar_t *s) throw(); | ||
25 | |||
26 | // use RawLeGuid only for RAW bytes that contain stored GUID as Little-endian. | 47 | // use RawLeGuid only for RAW bytes that contain stored GUID as Little-endian. |
27 | char *RawLeGuidToString(const Byte *guid, char *s) throw(); | 48 | char *RawLeGuidToString(const Byte *guid, char *s) throw(); |
28 | char *RawLeGuidToString_Braced(const Byte *guid, char *s) throw(); | 49 | char *RawLeGuidToString_Braced(const Byte *guid, char *s) throw(); |
29 | 50 | ||
51 | void ConvertDataToHex_Lower(char *dest, const Byte *src, size_t size) throw(); | ||
52 | void ConvertDataToHex_Upper(char *dest, const Byte *src, size_t size) throw(); | ||
53 | |||
30 | #endif | 54 | #endif |
diff --git a/CPP/Common/ListFileUtils.cpp b/CPP/Common/ListFileUtils.cpp index e43dbc9..714b275 100644 --- a/CPP/Common/ListFileUtils.cpp +++ b/CPP/Common/ListFileUtils.cpp | |||
@@ -76,26 +76,26 @@ bool ReadNamesFromListFile2(CFSTR fileName, UStringVector &strings, UINT codePag | |||
76 | return false; | 76 | return false; |
77 | 77 | ||
78 | file.Close(); | 78 | file.Close(); |
79 | const unsigned num = (unsigned)fileSize / 2; | 79 | const size_t num = (size_t)fileSize / 2; |
80 | wchar_t *p = u.GetBuf(num); | 80 | wchar_t *p = u.GetBuf((unsigned)num); |
81 | if (codePage == Z7_WIN_CP_UTF16) | 81 | if (codePage == Z7_WIN_CP_UTF16) |
82 | for (unsigned i = 0; i < num; i++) | 82 | for (size_t i = 0; i < num; i++) |
83 | { | 83 | { |
84 | wchar_t c = GetUi16(buf + (size_t)i * 2); | 84 | const wchar_t c = GetUi16(buf.ConstData() + (size_t)i * 2); |
85 | if (c == 0) | 85 | if (c == 0) |
86 | return false; | 86 | return false; |
87 | p[i] = c; | 87 | p[i] = c; |
88 | } | 88 | } |
89 | else | 89 | else |
90 | for (unsigned i = 0; i < num; i++) | 90 | for (size_t i = 0; i < num; i++) |
91 | { | 91 | { |
92 | wchar_t c = (wchar_t)GetBe16(buf + (size_t)i * 2); | 92 | const wchar_t c = (wchar_t)GetBe16(buf.ConstData() + (size_t)i * 2); |
93 | if (c == 0) | 93 | if (c == 0) |
94 | return false; | 94 | return false; |
95 | p[i] = c; | 95 | p[i] = c; |
96 | } | 96 | } |
97 | p[num] = 0; | 97 | p[num] = 0; |
98 | u.ReleaseBuf_SetLen(num); | 98 | u.ReleaseBuf_SetLen((unsigned)num); |
99 | } | 99 | } |
100 | else | 100 | else |
101 | { | 101 | { |
diff --git a/CPP/Common/MyBuffer.h b/CPP/Common/MyBuffer.h index bc829f4..80f0205 100644 --- a/CPP/Common/MyBuffer.h +++ b/CPP/Common/MyBuffer.h | |||
@@ -51,6 +51,12 @@ public: | |||
51 | 51 | ||
52 | operator T *() { return _items; } | 52 | operator T *() { return _items; } |
53 | operator const T *() const { return _items; } | 53 | operator const T *() const { return _items; } |
54 | const T* ConstData() const { return _items; } | ||
55 | T* NonConstData() const { return _items; } | ||
56 | T* NonConstData() { return _items; } | ||
57 | // const T* Data() const { return _items; } | ||
58 | // T* Data() { return _items; } | ||
59 | |||
54 | size_t Size() const { return _size; } | 60 | size_t Size() const { return _size; } |
55 | 61 | ||
56 | void Alloc(size_t size) | 62 | void Alloc(size_t size) |
@@ -140,15 +146,15 @@ bool operator!=(const CBuffer<T>& b1, const CBuffer<T>& b2) | |||
140 | 146 | ||
141 | // typedef CBuffer<char> CCharBuffer; | 147 | // typedef CBuffer<char> CCharBuffer; |
142 | // typedef CBuffer<wchar_t> CWCharBuffer; | 148 | // typedef CBuffer<wchar_t> CWCharBuffer; |
143 | typedef CBuffer<unsigned char> CByteBuffer; | 149 | typedef CBuffer<Byte> CByteBuffer; |
144 | 150 | ||
145 | 151 | ||
146 | class CByteBuffer_Wipe: public CByteBuffer | 152 | class CByteBuffer_Wipe: public CByteBuffer |
147 | { | 153 | { |
148 | Z7_CLASS_NO_COPY(CByteBuffer_Wipe) | 154 | Z7_CLASS_NO_COPY(CByteBuffer_Wipe) |
149 | public: | 155 | public: |
150 | // CByteBuffer_Wipe(): CBuffer<unsigned char>() {} | 156 | // CByteBuffer_Wipe(): CBuffer<Byte>() {} |
151 | CByteBuffer_Wipe(size_t size): CBuffer<unsigned char>(size) {} | 157 | CByteBuffer_Wipe(size_t size): CBuffer<Byte>(size) {} |
152 | ~CByteBuffer_Wipe() { Wipe(); } | 158 | ~CByteBuffer_Wipe() { Wipe(); } |
153 | }; | 159 | }; |
154 | 160 | ||
@@ -181,6 +187,11 @@ public: | |||
181 | 187 | ||
182 | operator T *() { return _items; } | 188 | operator T *() { return _items; } |
183 | operator const T *() const { return _items; } | 189 | operator const T *() const { return _items; } |
190 | const T* ConstData() const { return _items; } | ||
191 | T* NonConstData() const { return _items; } | ||
192 | T* NonConstData() { return _items; } | ||
193 | // const T* Data() const { return _items; } | ||
194 | // T* Data() { return _items; } | ||
184 | 195 | ||
185 | void Alloc(size_t newSize) | 196 | void Alloc(size_t newSize) |
186 | { | 197 | { |
@@ -191,7 +202,7 @@ public: | |||
191 | } | 202 | } |
192 | }; | 203 | }; |
193 | 204 | ||
194 | typedef CObjArray<unsigned char> CByteArr; | 205 | typedef CObjArray<Byte> CByteArr; |
195 | typedef CObjArray<bool> CBoolArr; | 206 | typedef CObjArray<bool> CBoolArr; |
196 | typedef CObjArray<int> CIntArr; | 207 | typedef CObjArray<int> CIntArr; |
197 | typedef CObjArray<unsigned> CUIntArr; | 208 | typedef CObjArray<unsigned> CUIntArr; |
diff --git a/CPP/Common/MyBuffer2.h b/CPP/Common/MyBuffer2.h index 23394f8..1ec8ffb 100644 --- a/CPP/Common/MyBuffer2.h +++ b/CPP/Common/MyBuffer2.h | |||
@@ -65,13 +65,13 @@ class CAlignedBuffer1 | |||
65 | public: | 65 | public: |
66 | ~CAlignedBuffer1() | 66 | ~CAlignedBuffer1() |
67 | { | 67 | { |
68 | ISzAlloc_Free(&g_AlignedAlloc, _data); | 68 | z7_AlignedFree(_data); |
69 | } | 69 | } |
70 | 70 | ||
71 | CAlignedBuffer1(size_t size) | 71 | CAlignedBuffer1(size_t size) |
72 | { | 72 | { |
73 | _data = NULL; | 73 | _data = NULL; |
74 | _data = (Byte *)ISzAlloc_Alloc(&g_AlignedAlloc, size); | 74 | _data = (Byte *)z7_AlignedAlloc(size); |
75 | if (!_data) | 75 | if (!_data) |
76 | throw 1; | 76 | throw 1; |
77 | } | 77 | } |
@@ -92,21 +92,23 @@ public: | |||
92 | CAlignedBuffer(): _data(NULL), _size(0) {} | 92 | CAlignedBuffer(): _data(NULL), _size(0) {} |
93 | ~CAlignedBuffer() | 93 | ~CAlignedBuffer() |
94 | { | 94 | { |
95 | ISzAlloc_Free(&g_AlignedAlloc, _data); | 95 | z7_AlignedFree(_data); |
96 | } | 96 | } |
97 | 97 | ||
98 | /* | ||
98 | CAlignedBuffer(size_t size): _size(0) | 99 | CAlignedBuffer(size_t size): _size(0) |
99 | { | 100 | { |
100 | _data = NULL; | 101 | _data = NULL; |
101 | _data = (Byte *)ISzAlloc_Alloc(&g_AlignedAlloc, size); | 102 | _data = (Byte *)z7_AlignedAlloc(size); |
102 | if (!_data) | 103 | if (!_data) |
103 | throw 1; | 104 | throw 1; |
104 | _size = size; | 105 | _size = size; |
105 | } | 106 | } |
107 | */ | ||
106 | 108 | ||
107 | void Free() | 109 | void Free() |
108 | { | 110 | { |
109 | ISzAlloc_Free(&g_AlignedAlloc, _data); | 111 | z7_AlignedFree(_data); |
110 | _data = NULL; | 112 | _data = NULL; |
111 | _size = 0; | 113 | _size = 0; |
112 | } | 114 | } |
@@ -120,10 +122,10 @@ public: | |||
120 | { | 122 | { |
121 | if (!_data || size != _size) | 123 | if (!_data || size != _size) |
122 | { | 124 | { |
123 | ISzAlloc_Free(&g_AlignedAlloc, _data); | 125 | z7_AlignedFree(_data); |
124 | _size = 0; | 126 | _size = 0; |
125 | _data = NULL; | 127 | _data = NULL; |
126 | _data = (Byte *)ISzAlloc_Alloc(&g_AlignedAlloc, size); | 128 | _data = (Byte *)z7_AlignedAlloc(size); |
127 | if (_data) | 129 | if (_data) |
128 | _size = size; | 130 | _size = size; |
129 | } | 131 | } |
@@ -133,10 +135,29 @@ public: | |||
133 | { | 135 | { |
134 | if (!_data || size > _size) | 136 | if (!_data || size > _size) |
135 | { | 137 | { |
136 | ISzAlloc_Free(&g_AlignedAlloc, _data); | 138 | z7_AlignedFree(_data); |
137 | _size = 0; | 139 | _size = 0; |
138 | _data = NULL; | 140 | _data = NULL; |
139 | _data = (Byte *)ISzAlloc_Alloc(&g_AlignedAlloc, size); | 141 | _data = (Byte *)z7_AlignedAlloc(size); |
142 | if (_data) | ||
143 | _size = size; | ||
144 | } | ||
145 | } | ||
146 | |||
147 | // (size <= size_max) | ||
148 | void AllocAtLeast_max(size_t size, size_t size_max) | ||
149 | { | ||
150 | if (!_data || size > _size) | ||
151 | { | ||
152 | z7_AlignedFree(_data); | ||
153 | _size = 0; | ||
154 | _data = NULL; | ||
155 | if (size_max < size) size_max = size; // optional check | ||
156 | const size_t delta = size / 2; | ||
157 | size += delta; | ||
158 | if (size < delta || size > size_max) | ||
159 | size = size_max; | ||
160 | _data = (Byte *)z7_AlignedAlloc(size); | ||
140 | if (_data) | 161 | if (_data) |
141 | _size = size; | 162 | _size = size; |
142 | } | 163 | } |
diff --git a/CPP/Common/MyCom.h b/CPP/Common/MyCom.h index 65c4330..a3cc3c8 100644 --- a/CPP/Common/MyCom.h +++ b/CPP/Common/MyCom.h | |||
@@ -17,6 +17,7 @@ public: | |||
17 | ~CMyComPtr() { if (_p) _p->Release(); } | 17 | ~CMyComPtr() { if (_p) _p->Release(); } |
18 | void Release() { if (_p) { _p->Release(); _p = NULL; } } | 18 | void Release() { if (_p) { _p->Release(); _p = NULL; } } |
19 | operator T*() const { return (T*)_p; } | 19 | operator T*() const { return (T*)_p; } |
20 | T* Interface() const { return (T*)_p; } | ||
20 | // T& operator*() const { return *_p; } | 21 | // T& operator*() const { return *_p; } |
21 | T** operator&() { return &_p; } | 22 | T** operator&() { return &_p; } |
22 | T* operator->() const { return _p; } | 23 | T* operator->() const { return _p; } |
@@ -68,6 +69,112 @@ public: | |||
68 | } | 69 | } |
69 | }; | 70 | }; |
70 | 71 | ||
72 | |||
73 | template <class iface, class cls> | ||
74 | class CMyComPtr2 | ||
75 | { | ||
76 | cls* _p; | ||
77 | |||
78 | CMyComPtr2(const CMyComPtr2<iface, cls>& lp); | ||
79 | CMyComPtr2(cls* p); | ||
80 | CMyComPtr2(iface* p); | ||
81 | iface* operator=(const CMyComPtr2<iface, cls>& lp); | ||
82 | iface* operator=(cls* p); | ||
83 | iface* operator=(iface* p); | ||
84 | public: | ||
85 | CMyComPtr2(): _p(NULL) {} | ||
86 | ~CMyComPtr2() | ||
87 | { | ||
88 | if (_p) | ||
89 | { | ||
90 | iface *ip = _p; | ||
91 | ip->Release(); | ||
92 | } | ||
93 | } | ||
94 | // void Release() { if (_p) { (iface *)_p->Release(); _p = NULL; } } | ||
95 | cls* operator->() const { return _p; } | ||
96 | cls* ClsPtr() const { return _p; } | ||
97 | operator iface*() const | ||
98 | { | ||
99 | iface *ip = _p; | ||
100 | return ip; | ||
101 | } | ||
102 | iface* Interface() const | ||
103 | { | ||
104 | iface *ip = _p; | ||
105 | return ip; | ||
106 | } | ||
107 | // operator bool() const { return _p != NULL; } | ||
108 | bool IsDefined() const { return _p != NULL; } | ||
109 | void Create_if_Empty() | ||
110 | { | ||
111 | if (!_p) | ||
112 | { | ||
113 | _p = new cls; | ||
114 | iface *ip = _p; | ||
115 | ip->AddRef(); | ||
116 | } | ||
117 | } | ||
118 | iface* Detach() | ||
119 | { | ||
120 | iface *ip = _p; | ||
121 | _p = NULL; | ||
122 | return ip; | ||
123 | } | ||
124 | void SetFromCls(cls *src) | ||
125 | { | ||
126 | if (src) | ||
127 | { | ||
128 | iface *ip = src; | ||
129 | ip->AddRef(); | ||
130 | } | ||
131 | if (_p) | ||
132 | { | ||
133 | iface *ip = _p; | ||
134 | ip->Release(); | ||
135 | } | ||
136 | _p = src; | ||
137 | } | ||
138 | }; | ||
139 | |||
140 | |||
141 | template <class iface, class cls> | ||
142 | class CMyComPtr2_Create | ||
143 | { | ||
144 | cls* _p; | ||
145 | |||
146 | CMyComPtr2_Create(const CMyComPtr2_Create<iface, cls>& lp); | ||
147 | CMyComPtr2_Create(cls* p); | ||
148 | CMyComPtr2_Create(iface* p); | ||
149 | iface* operator=(const CMyComPtr2_Create<iface, cls>& lp); | ||
150 | iface* operator=(cls* p); | ||
151 | iface* operator=(iface* p); | ||
152 | public: | ||
153 | CMyComPtr2_Create(): _p(new cls) | ||
154 | { | ||
155 | iface *ip = _p; | ||
156 | ip->AddRef(); | ||
157 | } | ||
158 | ~CMyComPtr2_Create() | ||
159 | { | ||
160 | iface *ip = _p; | ||
161 | ip->Release(); | ||
162 | } | ||
163 | cls* operator->() const { return _p; } | ||
164 | cls* ClsPtr() const { return _p; } | ||
165 | operator iface*() const | ||
166 | { | ||
167 | iface *ip = _p; | ||
168 | return ip; | ||
169 | } | ||
170 | iface* Interface() const | ||
171 | { | ||
172 | iface *ip = _p; | ||
173 | return ip; | ||
174 | } | ||
175 | }; | ||
176 | |||
177 | |||
71 | #define Z7_DECL_CMyComPtr_QI_FROM(i, v, unk) \ | 178 | #define Z7_DECL_CMyComPtr_QI_FROM(i, v, unk) \ |
72 | CMyComPtr<i> v; (unk)->QueryInterface(IID_ ## i, (void **)&v); | 179 | CMyComPtr<i> v; (unk)->QueryInterface(IID_ ## i, (void **)&v); |
73 | 180 | ||
@@ -234,16 +341,56 @@ protected: | |||
234 | Z7_COM_QI_ENTRY_UNKNOWN(i) \ | 341 | Z7_COM_QI_ENTRY_UNKNOWN(i) \ |
235 | Z7_COM_QI_ENTRY(i) | 342 | Z7_COM_QI_ENTRY(i) |
236 | 343 | ||
237 | #define Z7_COM_QI_END \ | 344 | |
345 | #define Z7_COM_ADDREF_RELEASE_MT \ | ||
346 | private: \ | ||
347 | STDMETHOD_(ULONG, AddRef)() Z7_override Z7_final \ | ||
348 | { return (ULONG)InterlockedIncrement((LONG *)&_m_RefCount); } \ | ||
349 | STDMETHOD_(ULONG, Release)() Z7_override Z7_final \ | ||
350 | { const LONG v = InterlockedDecrement((LONG *)&_m_RefCount); \ | ||
351 | if (v != 0) return (ULONG)v; \ | ||
352 | delete this; return 0; } | ||
353 | |||
354 | #define Z7_COM_QI_END_MT \ | ||
238 | else return E_NOINTERFACE; \ | 355 | else return E_NOINTERFACE; \ |
239 | ++_m_RefCount; /* AddRef(); */ return S_OK; } | 356 | InterlockedIncrement((LONG *)&_m_RefCount); /* AddRef(); */ return S_OK; } |
357 | |||
358 | // you can define Z7_COM_USE_ATOMIC, | ||
359 | // if you want to call Release() from different threads (for example, for .NET code) | ||
360 | // #define Z7_COM_USE_ATOMIC | ||
361 | |||
362 | #if defined(Z7_COM_USE_ATOMIC) && !defined(Z7_ST) | ||
363 | |||
364 | #ifndef _WIN32 | ||
365 | #if 0 | ||
366 | #include "../../C/Threads.h" | ||
367 | #else | ||
368 | EXTERN_C_BEGIN | ||
369 | LONG InterlockedIncrement(LONG volatile *addend); | ||
370 | LONG InterlockedDecrement(LONG volatile *addend); | ||
371 | EXTERN_C_END | ||
372 | #endif | ||
373 | #endif // _WIN32 | ||
374 | |||
375 | #define Z7_COM_ADDREF_RELEASE Z7_COM_ADDREF_RELEASE_MT | ||
376 | #define Z7_COM_QI_END Z7_COM_QI_END_MT | ||
377 | |||
378 | #else // !Z7_COM_USE_ATOMIC | ||
240 | 379 | ||
241 | #define Z7_COM_ADDREF_RELEASE \ | 380 | #define Z7_COM_ADDREF_RELEASE \ |
242 | private: \ | 381 | private: \ |
243 | STDMETHOD_(ULONG, AddRef)() throw() Z7_override Z7_final \ | 382 | STDMETHOD_(ULONG, AddRef)() throw() Z7_override Z7_final \ |
244 | { return ++_m_RefCount; } \ | 383 | { return ++_m_RefCount; } \ |
245 | STDMETHOD_(ULONG, Release)() throw() Z7_override Z7_final \ | 384 | STDMETHOD_(ULONG, Release)() throw() Z7_override Z7_final \ |
246 | { if (--_m_RefCount != 0) return _m_RefCount; delete this; return 0; } \ | 385 | { if (--_m_RefCount != 0) return _m_RefCount; \ |
386 | delete this; return 0; } | ||
387 | |||
388 | #define Z7_COM_QI_END \ | ||
389 | else return E_NOINTERFACE; \ | ||
390 | ++_m_RefCount; /* AddRef(); */ return S_OK; } | ||
391 | |||
392 | #endif // !Z7_COM_USE_ATOMIC | ||
393 | |||
247 | 394 | ||
248 | #define Z7_COM_UNKNOWN_IMP_SPEC(i) \ | 395 | #define Z7_COM_UNKNOWN_IMP_SPEC(i) \ |
249 | Z7_COM_QI_BEGIN \ | 396 | Z7_COM_QI_BEGIN \ |
diff --git a/CPP/Common/MyGuidDef.h b/CPP/Common/MyGuidDef.h index ab9993b..3aa5266 100644 --- a/CPP/Common/MyGuidDef.h +++ b/CPP/Common/MyGuidDef.h | |||
@@ -13,7 +13,7 @@ typedef struct { | |||
13 | UInt32 Data1; | 13 | UInt32 Data1; |
14 | UInt16 Data2; | 14 | UInt16 Data2; |
15 | UInt16 Data3; | 15 | UInt16 Data3; |
16 | unsigned char Data4[8]; | 16 | Byte Data4[8]; |
17 | } GUID; | 17 | } GUID; |
18 | 18 | ||
19 | #ifdef __cplusplus | 19 | #ifdef __cplusplus |
@@ -32,7 +32,7 @@ typedef GUID CLSID; | |||
32 | inline int operator==(REFGUID g1, REFGUID g2) | 32 | inline int operator==(REFGUID g1, REFGUID g2) |
33 | { | 33 | { |
34 | for (unsigned i = 0; i < sizeof(g1); i++) | 34 | for (unsigned i = 0; i < sizeof(g1); i++) |
35 | if (((const unsigned char *)&g1)[i] != ((const unsigned char *)&g2)[i]) | 35 | if (((const Byte *)&g1)[i] != ((const Byte *)&g2)[i]) |
36 | return 0; | 36 | return 0; |
37 | return 1; | 37 | return 1; |
38 | } | 38 | } |
diff --git a/CPP/Common/MyMap.cpp b/CPP/Common/MyMap.cpp index 0a200f0..d130aec 100644 --- a/CPP/Common/MyMap.cpp +++ b/CPP/Common/MyMap.cpp | |||
@@ -103,7 +103,7 @@ bool CMap32::Set(UInt32 key, UInt32 value) | |||
103 | n.IsLeaf[newBit] = 1; | 103 | n.IsLeaf[newBit] = 1; |
104 | n.IsLeaf[1 - newBit] = 0; | 104 | n.IsLeaf[1 - newBit] = 0; |
105 | n.Keys[newBit] = key; | 105 | n.Keys[newBit] = key; |
106 | n.Keys[1 - newBit] = Nodes.Size(); | 106 | n.Keys[1 - newBit] = (UInt32)Nodes.Size(); |
107 | Nodes.Add(e2); | 107 | Nodes.Add(e2); |
108 | return false; | 108 | return false; |
109 | } | 109 | } |
@@ -130,7 +130,7 @@ bool CMap32::Set(UInt32 key, UInt32 value) | |||
130 | e2.Len = (UInt16)(bitPos - (1 + i)); | 130 | e2.Len = (UInt16)(bitPos - (1 + i)); |
131 | 131 | ||
132 | n.IsLeaf[bit] = 0; | 132 | n.IsLeaf[bit] = 0; |
133 | n.Keys[bit] = Nodes.Size(); | 133 | n.Keys[bit] = (UInt32)Nodes.Size(); |
134 | 134 | ||
135 | Nodes.Add(e2); | 135 | Nodes.Add(e2); |
136 | return false; | 136 | return false; |
diff --git a/CPP/Common/MyString.cpp b/CPP/Common/MyString.cpp index 51c1c3b..b5f7e52 100644 --- a/CPP/Common/MyString.cpp +++ b/CPP/Common/MyString.cpp | |||
@@ -62,7 +62,7 @@ void MyStringUpper_Ascii(char *s) throw() | |||
62 | { | 62 | { |
63 | for (;;) | 63 | for (;;) |
64 | { | 64 | { |
65 | char c = *s; | 65 | const char c = *s; |
66 | if (c == 0) | 66 | if (c == 0) |
67 | return; | 67 | return; |
68 | *s++ = MyCharUpper_Ascii(c); | 68 | *s++ = MyCharUpper_Ascii(c); |
@@ -73,7 +73,7 @@ void MyStringUpper_Ascii(wchar_t *s) throw() | |||
73 | { | 73 | { |
74 | for (;;) | 74 | for (;;) |
75 | { | 75 | { |
76 | wchar_t c = *s; | 76 | const wchar_t c = *s; |
77 | if (c == 0) | 77 | if (c == 0) |
78 | return; | 78 | return; |
79 | *s++ = MyCharUpper_Ascii(c); | 79 | *s++ = MyCharUpper_Ascii(c); |
@@ -85,7 +85,7 @@ void MyStringLower_Ascii(char *s) throw() | |||
85 | { | 85 | { |
86 | for (;;) | 86 | for (;;) |
87 | { | 87 | { |
88 | char c = *s; | 88 | const char c = *s; |
89 | if (c == 0) | 89 | if (c == 0) |
90 | return; | 90 | return; |
91 | *s++ = MyCharLower_Ascii(c); | 91 | *s++ = MyCharLower_Ascii(c); |
@@ -96,7 +96,7 @@ void MyStringLower_Ascii(wchar_t *s) throw() | |||
96 | { | 96 | { |
97 | for (;;) | 97 | for (;;) |
98 | { | 98 | { |
99 | wchar_t c = *s; | 99 | const wchar_t c = *s; |
100 | if (c == 0) | 100 | if (c == 0) |
101 | return; | 101 | return; |
102 | *s++ = MyCharLower_Ascii(c); | 102 | *s++ = MyCharLower_Ascii(c); |
@@ -190,8 +190,8 @@ bool IsString1PrefixedByString2(const char *s1, const char *s2) throw() | |||
190 | { | 190 | { |
191 | for (;;) | 191 | for (;;) |
192 | { | 192 | { |
193 | const unsigned char c2 = (unsigned char)*s2++; if (c2 == 0) return true; | 193 | const char c2 = *s2++; if (c2 == 0) return true; |
194 | const unsigned char c1 = (unsigned char)*s1++; if (c1 != c2) return false; | 194 | const char c1 = *s1++; if (c1 != c2) return false; |
195 | } | 195 | } |
196 | } | 196 | } |
197 | 197 | ||
@@ -402,6 +402,7 @@ void AString::InsertSpace(unsigned &index, unsigned size) | |||
402 | } | 402 | } |
403 | 403 | ||
404 | #define k_Alloc_Len_Limit (0x40000000 - 2) | 404 | #define k_Alloc_Len_Limit (0x40000000 - 2) |
405 | // #define k_Alloc_Len_Limit (((unsigned)1 << (sizeof(unsigned) * 8 - 2)) - 2) | ||
405 | 406 | ||
406 | void AString::ReAlloc(unsigned newLimit) | 407 | void AString::ReAlloc(unsigned newLimit) |
407 | { | 408 | { |
@@ -413,9 +414,14 @@ void AString::ReAlloc(unsigned newLimit) | |||
413 | _limit = newLimit; | 414 | _limit = newLimit; |
414 | } | 415 | } |
415 | 416 | ||
417 | #define THROW_STRING_ALLOC_EXCEPTION { throw 20130220; } | ||
418 | |||
419 | #define CHECK_STRING_ALLOC_LEN(len) \ | ||
420 | { if ((len) > k_Alloc_Len_Limit) THROW_STRING_ALLOC_EXCEPTION } | ||
421 | |||
416 | void AString::ReAlloc2(unsigned newLimit) | 422 | void AString::ReAlloc2(unsigned newLimit) |
417 | { | 423 | { |
418 | if (newLimit > k_Alloc_Len_Limit) throw 20130220; | 424 | CHECK_STRING_ALLOC_LEN(newLimit) |
419 | // MY_STRING_REALLOC(_chars, char, (size_t)newLimit + 1, 0); | 425 | // MY_STRING_REALLOC(_chars, char, (size_t)newLimit + 1, 0); |
420 | char *newBuf = MY_STRING_NEW_char((size_t)newLimit + 1); | 426 | char *newBuf = MY_STRING_NEW_char((size_t)newLimit + 1); |
421 | newBuf[0] = 0; | 427 | newBuf[0] = 0; |
@@ -433,6 +439,7 @@ void AString::SetStartLen(unsigned len) | |||
433 | _limit = len; | 439 | _limit = len; |
434 | } | 440 | } |
435 | 441 | ||
442 | Z7_NO_INLINE | ||
436 | void AString::Grow_1() | 443 | void AString::Grow_1() |
437 | { | 444 | { |
438 | unsigned next = _len; | 445 | unsigned next = _len; |
@@ -443,7 +450,7 @@ void AString::Grow_1() | |||
443 | if (next < _len || next > k_Alloc_Len_Limit) | 450 | if (next < _len || next > k_Alloc_Len_Limit) |
444 | next = k_Alloc_Len_Limit; | 451 | next = k_Alloc_Len_Limit; |
445 | if (next <= _len) | 452 | if (next <= _len) |
446 | throw 20130220; | 453 | THROW_STRING_ALLOC_EXCEPTION |
447 | ReAlloc(next); | 454 | ReAlloc(next); |
448 | // Grow(1); | 455 | // Grow(1); |
449 | } | 456 | } |
@@ -461,7 +468,7 @@ void AString::Grow(unsigned n) | |||
461 | if (next < _len || next > k_Alloc_Len_Limit) | 468 | if (next < _len || next > k_Alloc_Len_Limit) |
462 | next = k_Alloc_Len_Limit; | 469 | next = k_Alloc_Len_Limit; |
463 | if (next <= _len || next - _len < n) | 470 | if (next <= _len || next - _len < n) |
464 | throw 20130220; | 471 | THROW_STRING_ALLOC_EXCEPTION |
465 | ReAlloc(next); | 472 | ReAlloc(next); |
466 | } | 473 | } |
467 | 474 | ||
@@ -638,12 +645,14 @@ void AString::SetFromBstr_if_Ascii(BSTR s) | |||
638 | } | 645 | } |
639 | */ | 646 | */ |
640 | 647 | ||
648 | void AString::Add_Char(char c) { operator+=(c); } | ||
641 | void AString::Add_Space() { operator+=(' '); } | 649 | void AString::Add_Space() { operator+=(' '); } |
642 | void AString::Add_Space_if_NotEmpty() { if (!IsEmpty()) Add_Space(); } | 650 | void AString::Add_Space_if_NotEmpty() { if (!IsEmpty()) Add_Space(); } |
643 | void AString::Add_LF() { operator+=('\n'); } | 651 | void AString::Add_LF() { operator+=('\n'); } |
644 | void AString::Add_Slash() { operator+=('/'); } | 652 | void AString::Add_Slash() { operator+=('/'); } |
645 | void AString::Add_Dot() { operator+=('.'); } | 653 | void AString::Add_Dot() { operator+=('.'); } |
646 | void AString::Add_Minus() { operator+=('-'); } | 654 | void AString::Add_Minus() { operator+=('-'); } |
655 | void AString::Add_Colon() { operator+=(':'); } | ||
647 | 656 | ||
648 | AString &AString::operator+=(const char *s) | 657 | AString &AString::operator+=(const char *s) |
649 | { | 658 | { |
@@ -696,6 +705,7 @@ void AString::SetFrom(const char *s, unsigned len) // no check | |||
696 | { | 705 | { |
697 | if (len > _limit) | 706 | if (len > _limit) |
698 | { | 707 | { |
708 | CHECK_STRING_ALLOC_LEN(len) | ||
699 | char *newBuf = MY_STRING_NEW_char((size_t)len + 1); | 709 | char *newBuf = MY_STRING_NEW_char((size_t)len + 1); |
700 | MY_STRING_DELETE(_chars) | 710 | MY_STRING_DELETE(_chars) |
701 | _chars = newBuf; | 711 | _chars = newBuf; |
@@ -707,6 +717,12 @@ void AString::SetFrom(const char *s, unsigned len) // no check | |||
707 | _len = len; | 717 | _len = len; |
708 | } | 718 | } |
709 | 719 | ||
720 | void AString::SetFrom_Chars_SizeT(const char *s, size_t len) | ||
721 | { | ||
722 | CHECK_STRING_ALLOC_LEN(len) | ||
723 | SetFrom(s, (unsigned)len); | ||
724 | } | ||
725 | |||
710 | void AString::SetFrom_CalcLen(const char *s, unsigned len) // no check | 726 | void AString::SetFrom_CalcLen(const char *s, unsigned len) // no check |
711 | { | 727 | { |
712 | unsigned i; | 728 | unsigned i; |
@@ -906,8 +922,8 @@ void AString::Replace(const AString &oldString, const AString &newString) | |||
906 | return; // 0; | 922 | return; // 0; |
907 | if (oldString == newString) | 923 | if (oldString == newString) |
908 | return; // 0; | 924 | return; // 0; |
909 | unsigned oldLen = oldString.Len(); | 925 | const unsigned oldLen = oldString.Len(); |
910 | unsigned newLen = newString.Len(); | 926 | const unsigned newLen = newString.Len(); |
911 | // unsigned number = 0; | 927 | // unsigned number = 0; |
912 | int pos = 0; | 928 | int pos = 0; |
913 | while ((unsigned)pos < _len) | 929 | while ((unsigned)pos < _len) |
@@ -1011,7 +1027,7 @@ void UString::ReAlloc(unsigned newLimit) | |||
1011 | 1027 | ||
1012 | void UString::ReAlloc2(unsigned newLimit) | 1028 | void UString::ReAlloc2(unsigned newLimit) |
1013 | { | 1029 | { |
1014 | if (newLimit > k_Alloc_Len_Limit) throw 20130221; | 1030 | CHECK_STRING_ALLOC_LEN(newLimit) |
1015 | // MY_STRING_REALLOC(_chars, wchar_t, newLimit + 1, 0); | 1031 | // MY_STRING_REALLOC(_chars, wchar_t, newLimit + 1, 0); |
1016 | wchar_t *newBuf = MY_STRING_NEW_wchar_t((size_t)newLimit + 1); | 1032 | wchar_t *newBuf = MY_STRING_NEW_wchar_t((size_t)newLimit + 1); |
1017 | newBuf[0] = 0; | 1033 | newBuf[0] = 0; |
@@ -1029,6 +1045,7 @@ void UString::SetStartLen(unsigned len) | |||
1029 | _limit = len; | 1045 | _limit = len; |
1030 | } | 1046 | } |
1031 | 1047 | ||
1048 | Z7_NO_INLINE | ||
1032 | void UString::Grow_1() | 1049 | void UString::Grow_1() |
1033 | { | 1050 | { |
1034 | unsigned next = _len; | 1051 | unsigned next = _len; |
@@ -1039,7 +1056,7 @@ void UString::Grow_1() | |||
1039 | if (next < _len || next > k_Alloc_Len_Limit) | 1056 | if (next < _len || next > k_Alloc_Len_Limit) |
1040 | next = k_Alloc_Len_Limit; | 1057 | next = k_Alloc_Len_Limit; |
1041 | if (next <= _len) | 1058 | if (next <= _len) |
1042 | throw 20130220; | 1059 | THROW_STRING_ALLOC_EXCEPTION |
1043 | ReAlloc(next); | 1060 | ReAlloc(next); |
1044 | } | 1061 | } |
1045 | 1062 | ||
@@ -1056,7 +1073,7 @@ void UString::Grow(unsigned n) | |||
1056 | if (next < _len || next > k_Alloc_Len_Limit) | 1073 | if (next < _len || next > k_Alloc_Len_Limit) |
1057 | next = k_Alloc_Len_Limit; | 1074 | next = k_Alloc_Len_Limit; |
1058 | if (next <= _len || next - _len < n) | 1075 | if (next <= _len || next - _len < n) |
1059 | throw 20130220; | 1076 | THROW_STRING_ALLOC_EXCEPTION |
1060 | ReAlloc(next - 1); | 1077 | ReAlloc(next - 1); |
1061 | } | 1078 | } |
1062 | 1079 | ||
@@ -1214,6 +1231,7 @@ void UString::SetFrom(const wchar_t *s, unsigned len) // no check | |||
1214 | { | 1231 | { |
1215 | if (len > _limit) | 1232 | if (len > _limit) |
1216 | { | 1233 | { |
1234 | CHECK_STRING_ALLOC_LEN(len) | ||
1217 | wchar_t *newBuf = MY_STRING_NEW_wchar_t((size_t)len + 1); | 1235 | wchar_t *newBuf = MY_STRING_NEW_wchar_t((size_t)len + 1); |
1218 | MY_STRING_DELETE(_chars) | 1236 | MY_STRING_DELETE(_chars) |
1219 | _chars = newBuf; | 1237 | _chars = newBuf; |
@@ -1238,7 +1256,7 @@ void UString::SetFromBstr(LPCOLESTR s) | |||
1238 | if (c >= 0xd800 && c < 0xdc00 && i + 1 != len) | 1256 | if (c >= 0xd800 && c < 0xdc00 && i + 1 != len) |
1239 | { | 1257 | { |
1240 | wchar_t c2 = s[i]; | 1258 | wchar_t c2 = s[i]; |
1241 | if (c2 >= 0xdc00 && c2 < 0x10000) | 1259 | if (c2 >= 0xdc00 && c2 < 0xe000) |
1242 | { | 1260 | { |
1243 | c = 0x10000 + ((c & 0x3ff) << 10) + (c2 & 0x3ff); | 1261 | c = 0x10000 + ((c & 0x3ff) << 10) + (c2 & 0x3ff); |
1244 | i++; | 1262 | i++; |
@@ -1269,7 +1287,7 @@ void UString::SetFromBstr(LPCOLESTR s) | |||
1269 | if (c >= 0xd800 && c < 0xdc00 && i + 1 != len) | 1287 | if (c >= 0xd800 && c < 0xdc00 && i + 1 != len) |
1270 | { | 1288 | { |
1271 | wchar_t c2 = *s; | 1289 | wchar_t c2 = *s; |
1272 | if (c2 >= 0xdc00 && c2 < 0x10000) | 1290 | if (c2 >= 0xdc00 && c2 < 0xe000) |
1273 | { | 1291 | { |
1274 | s++; | 1292 | s++; |
1275 | c = 0x10000 + ((c & 0x3ff) << 10) + (c2 & 0x3ff); | 1293 | c = 0x10000 + ((c & 0x3ff) << 10) + (c2 & 0x3ff); |
@@ -1305,21 +1323,15 @@ UString &UString::operator=(const char *s) | |||
1305 | return *this; | 1323 | return *this; |
1306 | } | 1324 | } |
1307 | 1325 | ||
1326 | void UString::Add_Char(char c) { operator+=((wchar_t)(unsigned char)c); } | ||
1327 | // void UString::Add_WChar(wchar_t c) { operator+=(c); } | ||
1308 | void UString::Add_Dot() { operator+=(L'.'); } | 1328 | void UString::Add_Dot() { operator+=(L'.'); } |
1309 | void UString::Add_Space() { operator+=(L' '); } | 1329 | void UString::Add_Space() { operator+=(L' '); } |
1330 | void UString::Add_Minus() { operator+=(L'-'); } | ||
1331 | void UString::Add_Colon() { operator+=(L':'); } | ||
1332 | void UString::Add_LF() { operator+=(L'\n'); } | ||
1310 | void UString::Add_Space_if_NotEmpty() { if (!IsEmpty()) Add_Space(); } | 1333 | void UString::Add_Space_if_NotEmpty() { if (!IsEmpty()) Add_Space(); } |
1311 | 1334 | ||
1312 | void UString::Add_LF() | ||
1313 | { | ||
1314 | if (_limit == _len) | ||
1315 | Grow_1(); | ||
1316 | unsigned len = _len; | ||
1317 | wchar_t *chars = _chars; | ||
1318 | chars[len++] = L'\n'; | ||
1319 | chars[len] = 0; | ||
1320 | _len = len; | ||
1321 | } | ||
1322 | |||
1323 | UString &UString::operator+=(const wchar_t *s) | 1335 | UString &UString::operator+=(const wchar_t *s) |
1324 | { | 1336 | { |
1325 | unsigned len = MyStringLen(s); | 1337 | unsigned len = MyStringLen(s); |
@@ -1597,7 +1609,7 @@ void UString::DeleteFrontal(unsigned num) throw() | |||
1597 | void UString2::ReAlloc2(unsigned newLimit) | 1609 | void UString2::ReAlloc2(unsigned newLimit) |
1598 | { | 1610 | { |
1599 | // wrong (_len) is allowed after this function | 1611 | // wrong (_len) is allowed after this function |
1600 | if (newLimit > k_Alloc_Len_Limit) throw 20130221; | 1612 | CHECK_STRING_ALLOC_LEN(newLimit) |
1601 | // MY_STRING_REALLOC(_chars, wchar_t, newLimit + 1, 0); | 1613 | // MY_STRING_REALLOC(_chars, wchar_t, newLimit + 1, 0); |
1602 | if (_chars) | 1614 | if (_chars) |
1603 | { | 1615 | { |
@@ -1805,7 +1817,7 @@ bool CStringFinder::FindWord_In_LowCaseAsciiList_NoCase(const char *p, const wch | |||
1805 | break; | 1817 | break; |
1806 | if (c <= 0x20 || c > 0x7f) | 1818 | if (c <= 0x20 || c > 0x7f) |
1807 | return false; | 1819 | return false; |
1808 | _temp += (char)MyCharLower_Ascii((char)c); | 1820 | _temp.Add_Char((char)MyCharLower_Ascii((char)c)); |
1809 | } | 1821 | } |
1810 | 1822 | ||
1811 | while (*p != 0) | 1823 | while (*p != 0) |
diff --git a/CPP/Common/MyString.h b/CPP/Common/MyString.h index e5ce18a..ba9914e 100644 --- a/CPP/Common/MyString.h +++ b/CPP/Common/MyString.h | |||
@@ -281,6 +281,8 @@ class AString | |||
281 | void ReAlloc(unsigned newLimit); | 281 | void ReAlloc(unsigned newLimit); |
282 | void ReAlloc2(unsigned newLimit); | 282 | void ReAlloc2(unsigned newLimit); |
283 | void SetStartLen(unsigned len); | 283 | void SetStartLen(unsigned len); |
284 | |||
285 | Z7_NO_INLINE | ||
284 | void Grow_1(); | 286 | void Grow_1(); |
285 | void Grow(unsigned n); | 287 | void Grow(unsigned n); |
286 | 288 | ||
@@ -373,6 +375,8 @@ public: | |||
373 | void SetFromWStr_if_Ascii(const wchar_t *s); | 375 | void SetFromWStr_if_Ascii(const wchar_t *s); |
374 | // void SetFromBstr_if_Ascii(BSTR s); | 376 | // void SetFromBstr_if_Ascii(BSTR s); |
375 | 377 | ||
378 | // private: | ||
379 | Z7_FORCE_INLINE | ||
376 | AString &operator+=(char c) | 380 | AString &operator+=(char c) |
377 | { | 381 | { |
378 | if (_limit == _len) | 382 | if (_limit == _len) |
@@ -384,14 +388,16 @@ public: | |||
384 | _len = len; | 388 | _len = len; |
385 | return *this; | 389 | return *this; |
386 | } | 390 | } |
387 | 391 | public: | |
388 | void Add_Space(); | 392 | void Add_Space(); |
389 | void Add_Space_if_NotEmpty(); | 393 | void Add_Space_if_NotEmpty(); |
390 | void Add_OptSpaced(const char *s); | 394 | void Add_OptSpaced(const char *s); |
395 | void Add_Char(char c); | ||
391 | void Add_LF(); | 396 | void Add_LF(); |
392 | void Add_Slash(); | 397 | void Add_Slash(); |
393 | void Add_Dot(); | 398 | void Add_Dot(); |
394 | void Add_Minus(); | 399 | void Add_Minus(); |
400 | void Add_Colon(); | ||
395 | void Add_PathSepar() { operator+=(CHAR_PATH_SEPARATOR); } | 401 | void Add_PathSepar() { operator+=(CHAR_PATH_SEPARATOR); } |
396 | 402 | ||
397 | AString &operator+=(const char *s); | 403 | AString &operator+=(const char *s); |
@@ -402,6 +408,7 @@ public: | |||
402 | 408 | ||
403 | void AddFrom(const char *s, unsigned len); // no check | 409 | void AddFrom(const char *s, unsigned len); // no check |
404 | void SetFrom(const char *s, unsigned len); // no check | 410 | void SetFrom(const char *s, unsigned len); // no check |
411 | void SetFrom_Chars_SizeT(const char* s, size_t len); // no check | ||
405 | void SetFrom(const char* s, int len) // no check | 412 | void SetFrom(const char* s, int len) // no check |
406 | { | 413 | { |
407 | SetFrom(s, (unsigned)len); // no check | 414 | SetFrom(s, (unsigned)len); // no check |
@@ -668,6 +675,8 @@ public: | |||
668 | UString &operator=(const char *s); | 675 | UString &operator=(const char *s); |
669 | UString &operator=(const AString &s) { return operator=(s.Ptr()); } | 676 | UString &operator=(const AString &s) { return operator=(s.Ptr()); } |
670 | 677 | ||
678 | // private: | ||
679 | Z7_FORCE_INLINE | ||
671 | UString &operator+=(wchar_t c) | 680 | UString &operator+=(wchar_t c) |
672 | { | 681 | { |
673 | if (_limit == _len) | 682 | if (_limit == _len) |
@@ -680,12 +689,17 @@ public: | |||
680 | return *this; | 689 | return *this; |
681 | } | 690 | } |
682 | 691 | ||
683 | UString &operator+=(char c) { return (*this)+=((wchar_t)(unsigned char)c); } | 692 | private: |
684 | 693 | UString &operator+=(char c); // { return (*this)+=((wchar_t)(unsigned char)c); } | |
694 | public: | ||
695 | void Add_Char(char c); | ||
696 | // void Add_WChar(wchar_t c); | ||
685 | void Add_Space(); | 697 | void Add_Space(); |
686 | void Add_Space_if_NotEmpty(); | 698 | void Add_Space_if_NotEmpty(); |
687 | void Add_LF(); | 699 | void Add_LF(); |
688 | void Add_Dot(); | 700 | void Add_Dot(); |
701 | void Add_Minus(); | ||
702 | void Add_Colon(); | ||
689 | void Add_PathSepar() { operator+=(WCHAR_PATH_SEPARATOR); } | 703 | void Add_PathSepar() { operator+=(WCHAR_PATH_SEPARATOR); } |
690 | 704 | ||
691 | UString &operator+=(const wchar_t *s); | 705 | UString &operator+=(const wchar_t *s); |
diff --git a/CPP/Common/MyTypes.h b/CPP/Common/MyTypes.h index 8f44f67..eadc9a4 100644 --- a/CPP/Common/MyTypes.h +++ b/CPP/Common/MyTypes.h | |||
@@ -3,10 +3,11 @@ | |||
3 | #ifndef ZIP7_INC_COMMON_MY_TYPES_H | 3 | #ifndef ZIP7_INC_COMMON_MY_TYPES_H |
4 | #define ZIP7_INC_COMMON_MY_TYPES_H | 4 | #define ZIP7_INC_COMMON_MY_TYPES_H |
5 | 5 | ||
6 | #include "Common0.h" | ||
6 | #include "../../C/7zTypes.h" | 7 | #include "../../C/7zTypes.h" |
7 | #include "Common.h" | ||
8 | 8 | ||
9 | typedef int HRes; | 9 | // typedef int HRes; |
10 | // typedef HRESULT HRes; | ||
10 | 11 | ||
11 | struct CBoolPair | 12 | struct CBoolPair |
12 | { | 13 | { |
diff --git a/CPP/Common/MyVector.h b/CPP/Common/MyVector.h index 9ee7105..a772785 100644 --- a/CPP/Common/MyVector.h +++ b/CPP/Common/MyVector.h | |||
@@ -258,7 +258,7 @@ public: | |||
258 | { | 258 | { |
259 | if (index != 0) | 259 | if (index != 0) |
260 | { | 260 | { |
261 | T temp = _items[index]; | 261 | const T temp = _items[index]; |
262 | memmove(_items + 1, _items, (size_t)index * sizeof(T)); | 262 | memmove(_items + 1, _items, (size_t)index * sizeof(T)); |
263 | _items[0] = temp; | 263 | _items[0] = temp; |
264 | } | 264 | } |
@@ -268,15 +268,29 @@ public: | |||
268 | 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]; } | 269 | const T& operator[](int index) const { return _items[(unsigned)index]; } |
270 | T& operator[](int index) { return _items[(unsigned)index]; } | 270 | T& operator[](int index) { return _items[(unsigned)index]; } |
271 | |||
272 | const T* ConstData() const { return _items; } | ||
273 | T* NonConstData() const { return _items; } | ||
274 | T* NonConstData() { return _items; } | ||
275 | |||
276 | const T* Data() const { return _items; } | ||
277 | T* Data() { return _items; } | ||
278 | |||
279 | const T& FrontItem() const { return _items[0]; } | ||
280 | T& FrontItem() { return _items[0]; } | ||
281 | /* | ||
282 | const T Front() const { return _items[0]; } | ||
283 | T Front() { return _items[0]; } | ||
271 | const T& Front() const { return _items[0]; } | 284 | const T& Front() const { return _items[0]; } |
272 | T& Front() { return _items[0]; } | 285 | T& Front() { return _items[0]; } |
286 | */ | ||
273 | const T& Back() const { return _items[(size_t)_size - 1]; } | 287 | const T& Back() const { return _items[(size_t)_size - 1]; } |
274 | T& Back() { return _items[(size_t)_size - 1]; } | 288 | T& Back() { return _items[(size_t)_size - 1]; } |
275 | 289 | ||
276 | /* | 290 | /* |
277 | void Swap(unsigned i, unsigned j) | 291 | void Swap(unsigned i, unsigned j) |
278 | { | 292 | { |
279 | T temp = _items[i]; | 293 | const T temp = _items[i]; |
280 | _items[i] = _items[j]; | 294 | _items[i] = _items[j]; |
281 | _items[j] = temp; | 295 | _items[j] = temp; |
282 | } | 296 | } |
@@ -368,7 +382,7 @@ public: | |||
368 | 382 | ||
369 | static void SortRefDown(T* p, unsigned k, unsigned size, int (*compare)(const T*, const T*, void *), void *param) | 383 | static void SortRefDown(T* p, unsigned k, unsigned size, int (*compare)(const T*, const T*, void *), void *param) |
370 | { | 384 | { |
371 | T temp = p[k]; | 385 | const T temp = p[k]; |
372 | for (;;) | 386 | for (;;) |
373 | { | 387 | { |
374 | unsigned s = (k << 1); | 388 | unsigned s = (k << 1); |
@@ -389,16 +403,16 @@ public: | |||
389 | unsigned size = _size; | 403 | unsigned size = _size; |
390 | if (size <= 1) | 404 | if (size <= 1) |
391 | return; | 405 | return; |
392 | T* p = (&Front()) - 1; | 406 | T* p = _items - 1; |
393 | { | 407 | { |
394 | unsigned i = size >> 1; | 408 | unsigned i = size >> 1; |
395 | do | 409 | do |
396 | SortRefDown(p, i, size, compare, param); | 410 | SortRefDown(p, i, size, compare, param); |
397 | while (--i != 0); | 411 | while (--i); |
398 | } | 412 | } |
399 | do | 413 | do |
400 | { | 414 | { |
401 | T temp = p[size]; | 415 | const T temp = p[size]; |
402 | p[size--] = p[1]; | 416 | p[size--] = p[1]; |
403 | p[1] = temp; | 417 | p[1] = temp; |
404 | SortRefDown(p, 1, size, compare, param); | 418 | SortRefDown(p, 1, size, compare, param); |
@@ -408,7 +422,7 @@ public: | |||
408 | 422 | ||
409 | static void SortRefDown2(T* p, unsigned k, unsigned size) | 423 | static void SortRefDown2(T* p, unsigned k, unsigned size) |
410 | { | 424 | { |
411 | T temp = p[k]; | 425 | const T temp = p[k]; |
412 | for (;;) | 426 | for (;;) |
413 | { | 427 | { |
414 | unsigned s = (k << 1); | 428 | unsigned s = (k << 1); |
@@ -429,16 +443,16 @@ public: | |||
429 | unsigned size = _size; | 443 | unsigned size = _size; |
430 | if (size <= 1) | 444 | if (size <= 1) |
431 | return; | 445 | return; |
432 | T* p = (&Front()) - 1; | 446 | T* p = _items - 1; |
433 | { | 447 | { |
434 | unsigned i = size >> 1; | 448 | unsigned i = size >> 1; |
435 | do | 449 | do |
436 | SortRefDown2(p, i, size); | 450 | SortRefDown2(p, i, size); |
437 | while (--i != 0); | 451 | while (--i); |
438 | } | 452 | } |
439 | do | 453 | do |
440 | { | 454 | { |
441 | T temp = p[size]; | 455 | const T temp = p[size]; |
442 | p[size--] = p[1]; | 456 | p[size--] = p[1]; |
443 | p[1] = temp; | 457 | p[1] = temp; |
444 | SortRefDown2(p, 1, size); | 458 | SortRefDown2(p, 1, size); |
diff --git a/CPP/Common/MyWindows.cpp b/CPP/Common/MyWindows.cpp index ae284eb..a1dfbef 100644 --- a/CPP/Common/MyWindows.cpp +++ b/CPP/Common/MyWindows.cpp | |||
@@ -88,21 +88,21 @@ BSTR SysAllocString(const OLECHAR *s) | |||
88 | void SysFreeString(BSTR bstr) | 88 | void SysFreeString(BSTR bstr) |
89 | { | 89 | { |
90 | if (bstr) | 90 | if (bstr) |
91 | FreeForBSTR((CBstrSizeType *)bstr - 1); | 91 | FreeForBSTR((CBstrSizeType *)(void *)bstr - 1); |
92 | } | 92 | } |
93 | 93 | ||
94 | UINT SysStringByteLen(BSTR bstr) | 94 | UINT SysStringByteLen(BSTR bstr) |
95 | { | 95 | { |
96 | if (!bstr) | 96 | if (!bstr) |
97 | return 0; | 97 | return 0; |
98 | return *((CBstrSizeType *)bstr - 1); | 98 | return *((CBstrSizeType *)(void *)bstr - 1); |
99 | } | 99 | } |
100 | 100 | ||
101 | UINT SysStringLen(BSTR bstr) | 101 | UINT SysStringLen(BSTR bstr) |
102 | { | 102 | { |
103 | if (!bstr) | 103 | if (!bstr) |
104 | return 0; | 104 | return 0; |
105 | return *((CBstrSizeType *)bstr - 1) / (UINT)sizeof(OLECHAR); | 105 | return *((CBstrSizeType *)(void *)bstr - 1) / (UINT)sizeof(OLECHAR); |
106 | } | 106 | } |
107 | 107 | ||
108 | 108 | ||
diff --git a/CPP/Common/MyWindows.h b/CPP/Common/MyWindows.h index a76e14b..da5370b 100644 --- a/CPP/Common/MyWindows.h +++ b/CPP/Common/MyWindows.h | |||
@@ -66,8 +66,8 @@ typedef int BOOL; | |||
66 | typedef Int64 LONGLONG; | 66 | typedef Int64 LONGLONG; |
67 | typedef UInt64 ULONGLONG; | 67 | typedef UInt64 ULONGLONG; |
68 | 68 | ||
69 | typedef struct _LARGE_INTEGER { LONGLONG QuadPart; } LARGE_INTEGER; | 69 | typedef struct { LONGLONG QuadPart; } LARGE_INTEGER; |
70 | typedef struct _ULARGE_INTEGER { ULONGLONG QuadPart; } ULARGE_INTEGER; | 70 | typedef struct { ULONGLONG QuadPart; } ULARGE_INTEGER; |
71 | 71 | ||
72 | typedef const CHAR *LPCSTR; | 72 | typedef const CHAR *LPCSTR; |
73 | typedef CHAR TCHAR; | 73 | typedef CHAR TCHAR; |
@@ -79,7 +79,7 @@ typedef OLECHAR *BSTR; | |||
79 | typedef const OLECHAR *LPCOLESTR; | 79 | typedef const OLECHAR *LPCOLESTR; |
80 | typedef OLECHAR *LPOLESTR; | 80 | typedef OLECHAR *LPOLESTR; |
81 | 81 | ||
82 | typedef struct _FILETIME | 82 | typedef struct |
83 | { | 83 | { |
84 | DWORD dwLowDateTime; | 84 | DWORD dwLowDateTime; |
85 | DWORD dwHighDateTime; | 85 | DWORD dwHighDateTime; |
@@ -292,7 +292,7 @@ typedef enum tagSTREAM_SEEK | |||
292 | 292 | ||
293 | 293 | ||
294 | 294 | ||
295 | typedef struct _SYSTEMTIME | 295 | typedef struct |
296 | { | 296 | { |
297 | WORD wYear; | 297 | WORD wYear; |
298 | WORD wMonth; | 298 | WORD wMonth; |
@@ -312,12 +312,13 @@ BOOL WINAPI FileTimeToSystemTime(const FILETIME *fileTime, SYSTEMTIME *systemTim | |||
312 | DWORD GetTickCount(); | 312 | DWORD GetTickCount(); |
313 | 313 | ||
314 | 314 | ||
315 | /* | ||
315 | #define CREATE_NEW 1 | 316 | #define CREATE_NEW 1 |
316 | #define CREATE_ALWAYS 2 | 317 | #define CREATE_ALWAYS 2 |
317 | #define OPEN_EXISTING 3 | 318 | #define OPEN_EXISTING 3 |
318 | #define OPEN_ALWAYS 4 | 319 | #define OPEN_ALWAYS 4 |
319 | #define TRUNCATE_EXISTING 5 | 320 | #define TRUNCATE_EXISTING 5 |
320 | 321 | */ | |
321 | 322 | ||
322 | #endif // _WIN32 | 323 | #endif // _WIN32 |
323 | 324 | ||
diff --git a/CPP/Common/MyXml.cpp b/CPP/Common/MyXml.cpp index a879d34..cc891fc 100644 --- a/CPP/Common/MyXml.cpp +++ b/CPP/Common/MyXml.cpp | |||
@@ -3,6 +3,7 @@ | |||
3 | #include "StdAfx.h" | 3 | #include "StdAfx.h" |
4 | 4 | ||
5 | #include "MyXml.h" | 5 | #include "MyXml.h" |
6 | #include "StringToInt.h" | ||
6 | 7 | ||
7 | static bool IsValidChar(char c) | 8 | static bool IsValidChar(char c) |
8 | { | 9 | { |
@@ -30,7 +31,7 @@ int CXmlItem::FindProp(const char *propName) const throw() | |||
30 | 31 | ||
31 | AString CXmlItem::GetPropVal(const char *propName) const | 32 | AString CXmlItem::GetPropVal(const char *propName) const |
32 | { | 33 | { |
33 | int index = FindProp(propName); | 34 | const int index = FindProp(propName); |
34 | if (index >= 0) | 35 | if (index >= 0) |
35 | return Props[(unsigned)index].Value; | 36 | return Props[(unsigned)index].Value; |
36 | return AString(); | 37 | return AString(); |
@@ -49,6 +50,17 @@ int CXmlItem::FindSubTag(const char *tag) const throw() | |||
49 | return -1; | 50 | return -1; |
50 | } | 51 | } |
51 | 52 | ||
53 | const CXmlItem *CXmlItem::FindSubTag_GetPtr(const char *tag) const throw() | ||
54 | { | ||
55 | FOR_VECTOR (i, SubItems) | ||
56 | { | ||
57 | const CXmlItem *p = &SubItems[i]; | ||
58 | if (p->IsTagged(tag)) | ||
59 | return p; | ||
60 | } | ||
61 | return NULL; | ||
62 | } | ||
63 | |||
52 | AString CXmlItem::GetSubString() const | 64 | AString CXmlItem::GetSubString() const |
53 | { | 65 | { |
54 | if (SubItems.Size() == 1) | 66 | if (SubItems.Size() == 1) |
@@ -73,9 +85,9 @@ const AString * CXmlItem::GetSubStringPtr() const throw() | |||
73 | 85 | ||
74 | AString CXmlItem::GetSubStringForTag(const char *tag) const | 86 | AString CXmlItem::GetSubStringForTag(const char *tag) const |
75 | { | 87 | { |
76 | int index = FindSubTag(tag); | 88 | const CXmlItem *item = FindSubTag_GetPtr(tag); |
77 | if (index >= 0) | 89 | if (item) |
78 | return SubItems[(unsigned)index].GetSubString(); | 90 | return item->GetSubString(); |
79 | return AString(); | 91 | return AString(); |
80 | } | 92 | } |
81 | 93 | ||
@@ -92,11 +104,14 @@ const char * CXmlItem::ParseItem(const char *s, int numAllowedLevels) | |||
92 | } | 104 | } |
93 | if (*s == 0) | 105 | if (*s == 0) |
94 | return NULL; | 106 | return NULL; |
95 | if (s != beg) | ||
96 | { | 107 | { |
97 | IsTag = false; | 108 | const size_t num = (size_t)(s - beg); |
98 | Name.SetFrom(beg, (unsigned)(s - beg)); | 109 | if (num) |
99 | return s; | 110 | { |
111 | IsTag = false; | ||
112 | Name.SetFrom_Chars_SizeT(beg, num); | ||
113 | return s; | ||
114 | } | ||
100 | } | 115 | } |
101 | 116 | ||
102 | IsTag = true; | 117 | IsTag = true; |
@@ -110,7 +125,7 @@ const char * CXmlItem::ParseItem(const char *s, int numAllowedLevels) | |||
110 | break; | 125 | break; |
111 | if (s == beg || *s == 0) | 126 | if (s == beg || *s == 0) |
112 | return NULL; | 127 | return NULL; |
113 | Name.SetFrom(beg, (unsigned)(s - beg)); | 128 | Name.SetFrom_Chars_SizeT(beg, (size_t)(s - beg)); |
114 | 129 | ||
115 | for (;;) | 130 | for (;;) |
116 | { | 131 | { |
@@ -142,11 +157,12 @@ const char * CXmlItem::ParseItem(const char *s, int numAllowedLevels) | |||
142 | } | 157 | } |
143 | 158 | ||
144 | s += 2; | 159 | s += 2; |
145 | unsigned len = Name.Len(); | 160 | const unsigned len = Name.Len(); |
161 | const char *name = Name.Ptr(); | ||
146 | for (unsigned i = 0; i < len; i++) | 162 | for (unsigned i = 0; i < len; i++) |
147 | if (s[i] != Name[i]) | 163 | if (*s++ != *name++) |
148 | return NULL; | 164 | return NULL; |
149 | s += len; | 165 | // s += len; |
150 | if (s[0] != '>') | 166 | if (s[0] != '>') |
151 | return NULL; | 167 | return NULL; |
152 | return s + 1; | 168 | return s + 1; |
@@ -166,7 +182,7 @@ const char * CXmlItem::ParseItem(const char *s, int numAllowedLevels) | |||
166 | } | 182 | } |
167 | if (s == beg) | 183 | if (s == beg) |
168 | return NULL; | 184 | return NULL; |
169 | prop.Name.SetFrom(beg, (unsigned)(s - beg)); | 185 | prop.Name.SetFrom_Chars_SizeT(beg, (size_t)(s - beg)); |
170 | 186 | ||
171 | SKIP_SPACES(s) | 187 | SKIP_SPACES(s) |
172 | if (*s != '=') | 188 | if (*s != '=') |
@@ -187,7 +203,7 @@ const char * CXmlItem::ParseItem(const char *s, int numAllowedLevels) | |||
187 | break; | 203 | break; |
188 | s++; | 204 | s++; |
189 | } | 205 | } |
190 | prop.Value.SetFrom(beg, (unsigned)(s - beg)); | 206 | prop.Value.SetFrom_Chars_SizeT(beg, (size_t)(s - beg)); |
191 | s++; | 207 | s++; |
192 | } | 208 | } |
193 | } | 209 | } |
@@ -258,3 +274,76 @@ void CXml::AppendTo(AString &s) const | |||
258 | Root.AppendTo(s); | 274 | Root.AppendTo(s); |
259 | } | 275 | } |
260 | */ | 276 | */ |
277 | |||
278 | |||
279 | void z7_xml_DecodeString(AString &temp) | ||
280 | { | ||
281 | char * const beg = temp.GetBuf(); | ||
282 | char *dest = beg; | ||
283 | const char *p = beg; | ||
284 | for (;;) | ||
285 | { | ||
286 | char c = *p++; | ||
287 | if (c == 0) | ||
288 | break; | ||
289 | if (c == '&') | ||
290 | { | ||
291 | if (p[0] == '#') | ||
292 | { | ||
293 | const char *end; | ||
294 | const UInt32 number = ConvertStringToUInt32(p + 1, &end); | ||
295 | if (*end == ';' && number != 0 && number <= 127) | ||
296 | { | ||
297 | p = end + 1; | ||
298 | c = (char)number; | ||
299 | } | ||
300 | } | ||
301 | else if ( | ||
302 | p[0] == 'a' && | ||
303 | p[1] == 'm' && | ||
304 | p[2] == 'p' && | ||
305 | p[3] == ';') | ||
306 | { | ||
307 | p += 4; | ||
308 | } | ||
309 | else if ( | ||
310 | p[0] == 'l' && | ||
311 | p[1] == 't' && | ||
312 | p[2] == ';') | ||
313 | { | ||
314 | p += 3; | ||
315 | c = '<'; | ||
316 | } | ||
317 | else if ( | ||
318 | p[0] == 'g' && | ||
319 | p[1] == 't' && | ||
320 | p[2] == ';') | ||
321 | { | ||
322 | p += 3; | ||
323 | c = '>'; | ||
324 | } | ||
325 | else if ( | ||
326 | p[0] == 'a' && | ||
327 | p[1] == 'p' && | ||
328 | p[2] == 'o' && | ||
329 | p[3] == 's' && | ||
330 | p[4] == ';') | ||
331 | { | ||
332 | p += 5; | ||
333 | c = '\''; | ||
334 | } | ||
335 | else if ( | ||
336 | p[0] == 'q' && | ||
337 | p[1] == 'u' && | ||
338 | p[2] == 'o' && | ||
339 | p[3] == 't' && | ||
340 | p[4] == ';') | ||
341 | { | ||
342 | p += 5; | ||
343 | c = '\"'; | ||
344 | } | ||
345 | } | ||
346 | *dest++ = c; | ||
347 | } | ||
348 | temp.ReleaseBuf_SetEnd((unsigned)(dest - beg)); | ||
349 | } | ||
diff --git a/CPP/Common/MyXml.h b/CPP/Common/MyXml.h index 5362602..b22d7e4 100644 --- a/CPP/Common/MyXml.h +++ b/CPP/Common/MyXml.h | |||
@@ -27,8 +27,8 @@ public: | |||
27 | AString GetSubString() const; | 27 | AString GetSubString() const; |
28 | const AString * GetSubStringPtr() const throw(); | 28 | const AString * GetSubStringPtr() const throw(); |
29 | int FindSubTag(const char *tag) const throw(); | 29 | int FindSubTag(const char *tag) const throw(); |
30 | const CXmlItem *FindSubTag_GetPtr(const char *tag) const throw(); | ||
30 | AString GetSubStringForTag(const char *tag) const; | 31 | AString GetSubStringForTag(const char *tag) const; |
31 | |||
32 | void AppendTo(AString &s) const; | 32 | void AppendTo(AString &s) const; |
33 | }; | 33 | }; |
34 | 34 | ||
@@ -40,4 +40,6 @@ struct CXml | |||
40 | // void AppendTo(AString &s) const; | 40 | // void AppendTo(AString &s) const; |
41 | }; | 41 | }; |
42 | 42 | ||
43 | void z7_xml_DecodeString(AString &s); | ||
44 | |||
43 | #endif | 45 | #endif |
diff --git a/CPP/Common/NewHandler.cpp b/CPP/Common/NewHandler.cpp index c95833e..173b8eb 100644 --- a/CPP/Common/NewHandler.cpp +++ b/CPP/Common/NewHandler.cpp | |||
@@ -65,6 +65,13 @@ operator new(size_t size) | |||
65 | return p; | 65 | return p; |
66 | } | 66 | } |
67 | 67 | ||
68 | |||
69 | #if defined(_MSC_VER) && _MSC_VER == 1600 | ||
70 | // vs2010 has no throw() by default ? | ||
71 | #pragma warning(push) | ||
72 | #pragma warning(disable : 4986) // 'operator delete': exception specification does not match previous declaration | ||
73 | #endif | ||
74 | |||
68 | void | 75 | void |
69 | #ifdef _MSC_VER | 76 | #ifdef _MSC_VER |
70 | __cdecl | 77 | __cdecl |
@@ -76,6 +83,27 @@ operator delete(void *p) throw() | |||
76 | ::free(p); | 83 | ::free(p); |
77 | } | 84 | } |
78 | 85 | ||
86 | /* we define operator delete(void *p, size_t n) because | ||
87 | vs2022 compiler uses delete(void *p, size_t n), and | ||
88 | we want to mix files from different compilers: | ||
89 | - old vc6 linker | ||
90 | - old vc6 complier | ||
91 | - new vs2022 complier | ||
92 | */ | ||
93 | void | ||
94 | #ifdef _MSC_VER | ||
95 | __cdecl | ||
96 | #endif | ||
97 | operator delete(void *p, size_t n) throw() | ||
98 | { | ||
99 | UNUSED_VAR(n) | ||
100 | ::free(p); | ||
101 | } | ||
102 | |||
103 | #if defined(_MSC_VER) && _MSC_VER == 1600 | ||
104 | #pragma warning(pop) | ||
105 | #endif | ||
106 | |||
79 | /* | 107 | /* |
80 | void * | 108 | void * |
81 | #ifdef _MSC_VER | 109 | #ifdef _MSC_VER |
@@ -205,11 +233,9 @@ operator delete(void *p) throw() | |||
205 | a[i] = 0; | 233 | a[i] = 0; |
206 | */ | 234 | */ |
207 | HeapFree(GetProcessHeap(), 0, p); | 235 | HeapFree(GetProcessHeap(), 0, p); |
208 | if (numAllocs == 0) | 236 | // if (numAllocs == 0) numAllocs = numAllocs; // ERROR |
209 | numAllocs = numAllocs; // ERROR | ||
210 | numAllocs--; | 237 | numAllocs--; |
211 | if (numAllocs == 0) | 238 | // if (numAllocs == 0) numAllocs = numAllocs; // OK: all objects were deleted |
212 | numAllocs = numAllocs; // OK: all objects were deleted | ||
213 | printf("Free %d\n", numAllocs); | 239 | printf("Free %d\n", numAllocs); |
214 | LeaveCriticalSection(&cs); | 240 | LeaveCriticalSection(&cs); |
215 | #else | 241 | #else |
@@ -219,6 +245,22 @@ operator delete(void *p) throw() | |||
219 | #endif | 245 | #endif |
220 | } | 246 | } |
221 | 247 | ||
248 | void | ||
249 | #ifdef _MSC_VER | ||
250 | __cdecl | ||
251 | #endif | ||
252 | operator delete(void *p, size_t n) throw(); | ||
253 | void | ||
254 | #ifdef _MSC_VER | ||
255 | __cdecl | ||
256 | #endif | ||
257 | operator delete(void *p, size_t n) throw() | ||
258 | { | ||
259 | UNUSED_VAR(n) | ||
260 | printf("delete_WITH_SIZE=%u, ptr = %p\n", (unsigned)n, p); | ||
261 | operator delete(p); | ||
262 | } | ||
263 | |||
222 | /* | 264 | /* |
223 | void * | 265 | void * |
224 | #ifdef _MSC_VER | 266 | #ifdef _MSC_VER |
diff --git a/CPP/Common/NewHandler.h b/CPP/Common/NewHandler.h index 50f6d0a..5ba64b7 100644 --- a/CPP/Common/NewHandler.h +++ b/CPP/Common/NewHandler.h | |||
@@ -65,12 +65,35 @@ __cdecl | |||
65 | #endif | 65 | #endif |
66 | operator new(size_t size); | 66 | operator new(size_t size); |
67 | 67 | ||
68 | /* | ||
69 | #if 0 && defined(_MSC_VER) && _MSC_VER == 1600 | ||
70 | #define Z7_OPERATOR_DELETE_SPEC_THROW0 | ||
71 | #else | ||
72 | #define Z7_OPERATOR_DELETE_SPEC_THROW0 throw() | ||
73 | #endif | ||
74 | */ | ||
75 | #if defined(_MSC_VER) && _MSC_VER == 1600 | ||
76 | #pragma warning(push) | ||
77 | #pragma warning(disable : 4986) // 'operator delete': exception specification does not match previous declaration | ||
78 | #endif | ||
79 | |||
68 | void | 80 | void |
69 | #ifdef _MSC_VER | 81 | #ifdef _MSC_VER |
70 | __cdecl | 82 | __cdecl |
71 | #endif | 83 | #endif |
72 | operator delete(void *p) throw(); | 84 | operator delete(void *p) throw(); |
73 | 85 | ||
86 | void | ||
87 | #ifdef _MSC_VER | ||
88 | __cdecl | ||
89 | #endif | ||
90 | operator delete(void *p, size_t n) throw(); | ||
91 | |||
92 | #if defined(_MSC_VER) && _MSC_VER == 1600 | ||
93 | #pragma warning(pop) | ||
94 | #endif | ||
95 | |||
96 | |||
74 | #else | 97 | #else |
75 | 98 | ||
76 | #include <new> | 99 | #include <new> |
diff --git a/CPP/Common/Random.cpp b/CPP/Common/Random.cpp index fbdb8c9..6ef9f1a 100644 --- a/CPP/Common/Random.cpp +++ b/CPP/Common/Random.cpp | |||
@@ -12,11 +12,11 @@ | |||
12 | 12 | ||
13 | #include "Random.h" | 13 | #include "Random.h" |
14 | 14 | ||
15 | void CRandom::Init(unsigned int seed) { srand(seed); } | 15 | void CRandom::Init(unsigned seed) { srand(seed); } |
16 | 16 | ||
17 | void CRandom::Init() | 17 | void CRandom::Init() |
18 | { | 18 | { |
19 | Init((unsigned int) | 19 | Init((unsigned) |
20 | #ifdef _WIN32 | 20 | #ifdef _WIN32 |
21 | GetTickCount() | 21 | GetTickCount() |
22 | #else | 22 | #else |
diff --git a/CPP/Common/Random.h b/CPP/Common/Random.h index 283869e..3fbb416 100644 --- a/CPP/Common/Random.h +++ b/CPP/Common/Random.h | |||
@@ -7,7 +7,7 @@ class CRandom | |||
7 | { | 7 | { |
8 | public: | 8 | public: |
9 | void Init(); | 9 | void Init(); |
10 | void Init(unsigned int seed); | 10 | void Init(unsigned seed); |
11 | int Generate() const; | 11 | int Generate() const; |
12 | }; | 12 | }; |
13 | 13 | ||
diff --git a/CPP/Common/StdInStream.cpp b/CPP/Common/StdInStream.cpp index 7b209f1..944be34 100644 --- a/CPP/Common/StdInStream.cpp +++ b/CPP/Common/StdInStream.cpp | |||
@@ -48,15 +48,15 @@ bool CStdInStream::ScanAStringUntilNewLine(AString &s) | |||
48 | s.Empty(); | 48 | s.Empty(); |
49 | for (;;) | 49 | for (;;) |
50 | { | 50 | { |
51 | int intChar = GetChar(); | 51 | const int intChar = GetChar(); |
52 | if (intChar == EOF) | 52 | if (intChar == EOF) |
53 | return true; | 53 | return true; |
54 | char c = (char)intChar; | 54 | const char c = (char)intChar; |
55 | if (c == 0) | 55 | if (c == 0) |
56 | return false; | 56 | return false; |
57 | if (c == '\n') | 57 | if (c == '\n') |
58 | return true; | 58 | return true; |
59 | s += c; | 59 | s.Add_Char(c); |
60 | } | 60 | } |
61 | } | 61 | } |
62 | 62 | ||
@@ -64,14 +64,14 @@ bool CStdInStream::ScanUStringUntilNewLine(UString &dest) | |||
64 | { | 64 | { |
65 | dest.Empty(); | 65 | dest.Empty(); |
66 | AString s; | 66 | AString s; |
67 | bool res = ScanAStringUntilNewLine(s); | 67 | const bool res = ScanAStringUntilNewLine(s); |
68 | int codePage = CodePage; | 68 | int codePage = CodePage; |
69 | if (codePage == -1) | 69 | if (codePage == -1) |
70 | codePage = CP_OEMCP; | 70 | codePage = CP_OEMCP; |
71 | if (codePage == CP_UTF8) | 71 | if ((unsigned)codePage == CP_UTF8) |
72 | ConvertUTF8ToUnicode(s, dest); | 72 | ConvertUTF8ToUnicode(s, dest); |
73 | else | 73 | else |
74 | MultiByteToUnicodeString2(dest, s, (UINT)codePage); | 74 | MultiByteToUnicodeString2(dest, s, (UINT)(unsigned)codePage); |
75 | return res; | 75 | return res; |
76 | } | 76 | } |
77 | 77 | ||
diff --git a/CPP/Common/StdOutStream.cpp b/CPP/Common/StdOutStream.cpp index cfa5fde..ba179d9 100644 --- a/CPP/Common/StdOutStream.cpp +++ b/CPP/Common/StdOutStream.cpp | |||
@@ -66,70 +66,158 @@ void CStdOutStream::Convert_UString_to_AString(const UString &src, AString &dest | |||
66 | int codePage = CodePage; | 66 | int codePage = CodePage; |
67 | if (codePage == -1) | 67 | if (codePage == -1) |
68 | codePage = CP_OEMCP; | 68 | codePage = CP_OEMCP; |
69 | if (codePage == CP_UTF8) | 69 | if ((unsigned)codePage == CP_UTF8) |
70 | ConvertUnicodeToUTF8(src, dest); | 70 | ConvertUnicodeToUTF8(src, dest); |
71 | else | 71 | else |
72 | UnicodeStringToMultiByte2(dest, src, (UINT)codePage); | 72 | UnicodeStringToMultiByte2(dest, src, (UINT)(unsigned)codePage); |
73 | } | 73 | } |
74 | 74 | ||
75 | 75 | ||
76 | static const wchar_t kReplaceChar = '_'; | 76 | static const wchar_t kReplaceChar = '_'; |
77 | 77 | ||
78 | /* | ||
78 | void CStdOutStream::Normalize_UString_LF_Allowed(UString &s) | 79 | void CStdOutStream::Normalize_UString_LF_Allowed(UString &s) |
79 | { | 80 | { |
80 | unsigned len = s.Len(); | 81 | if (!IsTerminalMode) |
82 | return; | ||
83 | |||
84 | const unsigned len = s.Len(); | ||
81 | wchar_t *d = s.GetBuf(); | 85 | wchar_t *d = s.GetBuf(); |
82 | 86 | ||
83 | if (IsTerminalMode) | ||
84 | for (unsigned i = 0; i < len; i++) | 87 | for (unsigned i = 0; i < len; i++) |
85 | { | 88 | { |
86 | wchar_t c = d[i]; | 89 | const wchar_t c = d[i]; |
87 | if (c <= 13 && c >= 7 && c != '\n') | 90 | if (c == 0x1b || (c <= 13 && c >= 7 && c != '\n')) |
88 | d[i] = kReplaceChar; | 91 | d[i] = kReplaceChar; |
89 | } | 92 | } |
90 | } | 93 | } |
94 | */ | ||
91 | 95 | ||
92 | void CStdOutStream::Normalize_UString(UString &s) | 96 | void CStdOutStream::Normalize_UString(UString &s) |
93 | { | 97 | { |
94 | unsigned len = s.Len(); | 98 | const unsigned len = s.Len(); |
95 | wchar_t *d = s.GetBuf(); | 99 | wchar_t *d = s.GetBuf(); |
96 | 100 | ||
97 | if (IsTerminalMode) | 101 | if (IsTerminalMode) |
98 | for (unsigned i = 0; i < len; i++) | 102 | for (unsigned i = 0; i < len; i++) |
99 | { | 103 | { |
100 | wchar_t c = d[i]; | 104 | const wchar_t c = d[i]; |
101 | if (c <= 13 && c >= 7) | 105 | if ((c <= 13 && c >= 7) || c == 0x1b) |
102 | d[i] = kReplaceChar; | 106 | d[i] = kReplaceChar; |
103 | } | 107 | } |
104 | else | 108 | else |
105 | for (unsigned i = 0; i < len; i++) | 109 | for (unsigned i = 0; i < len; i++) |
106 | { | 110 | { |
107 | wchar_t c = d[i]; | 111 | const wchar_t c = d[i]; |
108 | if (c == '\n') | 112 | if (c == '\n') |
109 | d[i] = kReplaceChar; | 113 | d[i] = kReplaceChar; |
110 | } | 114 | } |
111 | } | 115 | } |
112 | 116 | ||
113 | void CStdOutStream::NormalizePrint_UString(const UString &s, UString &tempU, AString &tempA) | 117 | void CStdOutStream::Normalize_UString_Path(UString &s) |
118 | { | ||
119 | if (ListPathSeparatorSlash.Def) | ||
120 | { | ||
121 | #ifdef _WIN32 | ||
122 | if (ListPathSeparatorSlash.Val) | ||
123 | s.Replace(L'\\', L'/'); | ||
124 | #else | ||
125 | if (!ListPathSeparatorSlash.Val) | ||
126 | s.Replace(L'/', L'\\'); | ||
127 | #endif | ||
128 | } | ||
129 | Normalize_UString(s); | ||
130 | } | ||
131 | |||
132 | |||
133 | /* | ||
134 | void CStdOutStream::Normalize_UString(UString &src) | ||
135 | { | ||
136 | const wchar_t *s = src.Ptr(); | ||
137 | const unsigned len = src.Len(); | ||
138 | unsigned i; | ||
139 | for (i = 0; i < len; i++) | ||
140 | { | ||
141 | const wchar_t c = s[i]; | ||
142 | #if 0 && !defined(_WIN32) | ||
143 | if (c == '\\') // IsTerminalMode && | ||
144 | break; | ||
145 | #endif | ||
146 | if ((unsigned)c < 0x20) | ||
147 | break; | ||
148 | } | ||
149 | if (i == len) | ||
150 | return; | ||
151 | |||
152 | UString temp; | ||
153 | for (i = 0; i < len; i++) | ||
154 | { | ||
155 | wchar_t c = s[i]; | ||
156 | #if 0 && !defined(_WIN32) | ||
157 | if (c == '\\') | ||
158 | temp += (wchar_t)L'\\'; | ||
159 | else | ||
160 | #endif | ||
161 | if ((unsigned)c < 0x20) | ||
162 | { | ||
163 | if (c == '\n' | ||
164 | || (IsTerminalMode && (c == 0x1b || (c <= 13 && c >= 7)))) | ||
165 | { | ||
166 | #if 1 || defined(_WIN32) | ||
167 | c = (wchar_t)kReplaceChar; | ||
168 | #else | ||
169 | temp += (wchar_t)L'\\'; | ||
170 | if (c == '\n') c = L'n'; | ||
171 | else if (c == '\r') c = L'r'; | ||
172 | else if (c == '\a') c = L'a'; | ||
173 | else if (c == '\b') c = L'b'; | ||
174 | else if (c == '\t') c = L't'; | ||
175 | else if (c == '\v') c = L'v'; | ||
176 | else if (c == '\f') c = L'f'; | ||
177 | else | ||
178 | { | ||
179 | temp += (wchar_t)(L'0' + (unsigned)c / 64); | ||
180 | temp += (wchar_t)(L'0' + (unsigned)c / 8 % 8); | ||
181 | c = (wchar_t)(L'0' + (unsigned)c % 8); | ||
182 | } | ||
183 | #endif | ||
184 | } | ||
185 | } | ||
186 | temp += c; | ||
187 | } | ||
188 | src = temp; | ||
189 | } | ||
190 | */ | ||
191 | |||
192 | void CStdOutStream::NormalizePrint_UString_Path(const UString &s, UString &tempU, AString &tempA) | ||
114 | { | 193 | { |
115 | tempU = s; | 194 | tempU = s; |
116 | Normalize_UString(tempU); | 195 | Normalize_UString_Path(tempU); |
117 | PrintUString(tempU, tempA); | 196 | PrintUString(tempU, tempA); |
118 | } | 197 | } |
119 | 198 | ||
120 | void CStdOutStream::NormalizePrint_UString(const UString &s) | 199 | void CStdOutStream::NormalizePrint_UString_Path(const UString &s) |
121 | { | 200 | { |
122 | NormalizePrint_wstr(s); | 201 | UString tempU; |
202 | AString tempA; | ||
203 | NormalizePrint_UString_Path(s, tempU, tempA); | ||
123 | } | 204 | } |
124 | 205 | ||
125 | void CStdOutStream::NormalizePrint_wstr(const wchar_t *s) | 206 | void CStdOutStream::NormalizePrint_wstr_Path(const wchar_t *s) |
126 | { | 207 | { |
127 | UString tempU = s; | 208 | UString tempU = s; |
128 | Normalize_UString(tempU); | 209 | Normalize_UString_Path(tempU); |
129 | AString tempA; | 210 | AString tempA; |
130 | PrintUString(tempU, tempA); | 211 | PrintUString(tempU, tempA); |
131 | } | 212 | } |
132 | 213 | ||
214 | void CStdOutStream::NormalizePrint_UString(const UString &s) | ||
215 | { | ||
216 | UString tempU = s; | ||
217 | Normalize_UString(tempU); | ||
218 | AString tempA; | ||
219 | PrintUString(tempU, tempA); | ||
220 | } | ||
133 | 221 | ||
134 | CStdOutStream & CStdOutStream::operator<<(Int32 number) throw() | 222 | CStdOutStream & CStdOutStream::operator<<(Int32 number) throw() |
135 | { | 223 | { |
diff --git a/CPP/Common/StdOutStream.h b/CPP/Common/StdOutStream.h index bd15d7c..846b0db 100644 --- a/CPP/Common/StdOutStream.h +++ b/CPP/Common/StdOutStream.h | |||
@@ -14,6 +14,7 @@ class CStdOutStream | |||
14 | // bool _streamIsOpen; | 14 | // bool _streamIsOpen; |
15 | public: | 15 | public: |
16 | bool IsTerminalMode; | 16 | bool IsTerminalMode; |
17 | CBoolPair ListPathSeparatorSlash; | ||
17 | int CodePage; | 18 | int CodePage; |
18 | 19 | ||
19 | CStdOutStream(FILE *stream = NULL): | 20 | CStdOutStream(FILE *stream = NULL): |
@@ -21,7 +22,14 @@ public: | |||
21 | // _streamIsOpen(false), | 22 | // _streamIsOpen(false), |
22 | IsTerminalMode(false), | 23 | IsTerminalMode(false), |
23 | CodePage(-1) | 24 | CodePage(-1) |
24 | {} | 25 | { |
26 | ListPathSeparatorSlash.Val = | ||
27 | #ifdef _WIN32 | ||
28 | false; | ||
29 | #else | ||
30 | true; | ||
31 | #endif | ||
32 | } | ||
25 | 33 | ||
26 | // ~CStdOutStream() { Close(); } | 34 | // ~CStdOutStream() { Close(); } |
27 | 35 | ||
@@ -62,12 +70,13 @@ public: | |||
62 | void PrintUString(const UString &s, AString &temp); | 70 | void PrintUString(const UString &s, AString &temp); |
63 | void Convert_UString_to_AString(const UString &src, AString &dest); | 71 | void Convert_UString_to_AString(const UString &src, AString &dest); |
64 | 72 | ||
65 | void Normalize_UString_LF_Allowed(UString &s); | ||
66 | void Normalize_UString(UString &s); | 73 | void Normalize_UString(UString &s); |
74 | void Normalize_UString_Path(UString &s); | ||
67 | 75 | ||
68 | void NormalizePrint_UString(const UString &s, UString &tempU, AString &tempA); | 76 | void NormalizePrint_UString_Path(const UString &s, UString &tempU, AString &tempA); |
77 | void NormalizePrint_UString_Path(const UString &s); | ||
69 | void NormalizePrint_UString(const UString &s); | 78 | void NormalizePrint_UString(const UString &s); |
70 | void NormalizePrint_wstr(const wchar_t *s); | 79 | void NormalizePrint_wstr_Path(const wchar_t *s); |
71 | }; | 80 | }; |
72 | 81 | ||
73 | CStdOutStream & endl(CStdOutStream & outStream) throw(); | 82 | CStdOutStream & endl(CStdOutStream & outStream) throw(); |
diff --git a/CPP/Common/StringConvert.cpp b/CPP/Common/StringConvert.cpp index f25396a..79ff9e0 100644 --- a/CPP/Common/StringConvert.cpp +++ b/CPP/Common/StringConvert.cpp | |||
@@ -267,8 +267,10 @@ void MultiByteToUnicodeString2(UString &dest, const AString &src, UINT codePage) | |||
267 | 267 | ||
268 | if (codePage == CP_UTF8 || g_ForceToUTF8) | 268 | if (codePage == CP_UTF8 || g_ForceToUTF8) |
269 | { | 269 | { |
270 | #if 1 | ||
270 | ConvertUTF8ToUnicode(src, dest); | 271 | ConvertUTF8ToUnicode(src, dest); |
271 | return; | 272 | return; |
273 | #endif | ||
272 | } | 274 | } |
273 | 275 | ||
274 | const size_t limit = ((size_t)src.Len() + 1) * 2; | 276 | const size_t limit = ((size_t)src.Len() + 1) * 2; |
@@ -278,48 +280,47 @@ void MultiByteToUnicodeString2(UString &dest, const AString &src, UINT codePage) | |||
278 | { | 280 | { |
279 | dest.ReleaseBuf_SetEnd((unsigned)len); | 281 | dest.ReleaseBuf_SetEnd((unsigned)len); |
280 | 282 | ||
281 | #if WCHAR_MAX > 0xffff | 283 | #if WCHAR_MAX > 0xffff |
282 | d = dest.GetBuf(); | 284 | d = dest.GetBuf(); |
283 | for (size_t i = 0;; i++) | 285 | for (size_t i = 0;; i++) |
284 | { | 286 | { |
285 | // wchar_t c = dest[i]; | ||
286 | wchar_t c = d[i]; | 287 | wchar_t c = d[i]; |
288 | // printf("\ni=%2d c = %4x\n", (unsigned)i, (unsigned)c); | ||
287 | if (c == 0) | 289 | if (c == 0) |
288 | break; | 290 | break; |
289 | if (c >= 0x10000 && c < 0x110000) | 291 | if (c >= 0x10000 && c < 0x110000) |
290 | { | 292 | { |
291 | /* | 293 | UString tempString = d + i; |
292 | c -= 0x10000; | 294 | const wchar_t *t = tempString.Ptr(); |
293 | unsigned c0 = 0xd800 + ((c >> 10) & 0x3FF); | ||
294 | dest.ReplaceOneCharAtPos(i, c0); | ||
295 | i++; | ||
296 | c = 0xdc00 + (c & 0x3FF); | ||
297 | dest.Insert_wchar_t(i, c); | ||
298 | */ | ||
299 | UString temp = d + i; | ||
300 | 295 | ||
301 | for (size_t t = 0;; t++) | 296 | for (;;) |
302 | { | 297 | { |
303 | wchar_t w = temp[t]; | 298 | wchar_t w = *t++; |
299 | // printf("\nchar=%x\n", w); | ||
304 | if (w == 0) | 300 | if (w == 0) |
305 | break; | 301 | break; |
306 | if (i == limit) | 302 | if (i == limit) |
307 | break; // unexpected error | 303 | break; // unexpected error |
308 | if (w >= 0x10000 && w < 0x110000) | 304 | if (w >= 0x10000 && w < 0x110000) |
309 | { | 305 | { |
306 | #if 1 | ||
310 | if (i + 1 == limit) | 307 | if (i + 1 == limit) |
311 | break; // unexpected error | 308 | break; // unexpected error |
312 | w -= 0x10000; | 309 | w -= 0x10000; |
313 | d[i++] = (unsigned)0xd800 + (((unsigned)w >> 10) & 0x3FF); | 310 | d[i++] = (unsigned)0xd800 + (((unsigned)w >> 10) & 0x3ff); |
314 | w = 0xdc00 + (w & 0x3FF); | 311 | w = 0xdc00 + (w & 0x3ff); |
312 | #else | ||
313 | // w = '_'; // for debug | ||
314 | #endif | ||
315 | } | 315 | } |
316 | d[i++] = w; | 316 | d[i++] = w; |
317 | } | 317 | } |
318 | dest.ReleaseBuf_SetEnd((unsigned)i); | 318 | dest.ReleaseBuf_SetEnd((unsigned)i); |
319 | break; | ||
319 | } | 320 | } |
320 | } | 321 | } |
321 | 322 | ||
322 | #endif | 323 | #endif |
323 | 324 | ||
324 | /* | 325 | /* |
325 | printf("\nMultiByteToUnicodeString2 (%d) %s\n", (int)src.Len(), src.Ptr()); | 326 | printf("\nMultiByteToUnicodeString2 (%d) %s\n", (int)src.Len(), src.Ptr()); |
@@ -395,34 +396,39 @@ static void UnicodeStringToMultiByte2(AString &dest, const UString &src2, UINT c | |||
395 | // if (codePage == 1234567) // for debug purposes | 396 | // if (codePage == 1234567) // for debug purposes |
396 | if (codePage == CP_UTF8 || g_ForceToUTF8) | 397 | if (codePage == CP_UTF8 || g_ForceToUTF8) |
397 | { | 398 | { |
399 | #if 1 | ||
398 | defaultCharWasUsed = false; | 400 | defaultCharWasUsed = false; |
399 | ConvertUnicodeToUTF8(src2, dest); | 401 | ConvertUnicodeToUTF8(src2, dest); |
400 | return; | 402 | return; |
403 | #endif | ||
401 | } | 404 | } |
402 | 405 | ||
403 | UString src = src2; | 406 | UString src = src2; |
404 | #if WCHAR_MAX > 0xffff | 407 | #if WCHAR_MAX > 0xffff |
405 | { | 408 | { |
406 | src.Empty(); | 409 | src.Empty(); |
407 | for (unsigned i = 0; i < src2.Len();) | 410 | for (unsigned i = 0; i < src2.Len();) |
408 | { | 411 | { |
409 | wchar_t c = src2[i]; | 412 | wchar_t c = src2[i++]; |
410 | if (c >= 0xd800 && c < 0xdc00 && i + 1 != src2.Len()) | 413 | if (c >= 0xd800 && c < 0xdc00 && i != src2.Len()) |
411 | { | 414 | { |
412 | const wchar_t c2 = src2[i + 1]; | 415 | const wchar_t c2 = src2[i]; |
413 | if (c2 >= 0xdc00 && c2 < 0x10000) | 416 | if (c2 >= 0xdc00 && c2 < 0xe000) |
414 | { | 417 | { |
418 | #if 1 | ||
415 | // printf("\nSurragate [%d]: %4x %4x -> ", i, (int)c, (int)c2); | 419 | // printf("\nSurragate [%d]: %4x %4x -> ", i, (int)c, (int)c2); |
416 | c = 0x10000 + ((c & 0x3ff) << 10) + (c2 & 0x3ff); | 420 | c = 0x10000 + ((c & 0x3ff) << 10) + (c2 & 0x3ff); |
417 | // printf("%4x\n", (int)c); | 421 | // printf("%4x\n", (int)c); |
418 | i++; | 422 | i++; |
423 | #else | ||
424 | // c = '_'; // for debug | ||
425 | #endif | ||
419 | } | 426 | } |
420 | } | 427 | } |
421 | src += c; | 428 | src += c; |
422 | i++; | ||
423 | } | 429 | } |
424 | } | 430 | } |
425 | #endif | 431 | #endif |
426 | 432 | ||
427 | dest.Empty(); | 433 | dest.Empty(); |
428 | defaultCharWasUsed = false; | 434 | defaultCharWasUsed = false; |
diff --git a/CPP/Common/StringToInt.cpp b/CPP/Common/StringToInt.cpp index bc4926e..ba8a81b 100644 --- a/CPP/Common/StringToInt.cpp +++ b/CPP/Common/StringToInt.cpp | |||
@@ -2,57 +2,63 @@ | |||
2 | 2 | ||
3 | #include "StdAfx.h" | 3 | #include "StdAfx.h" |
4 | 4 | ||
5 | #include <limits.h> | ||
6 | #if defined(_MSC_VER) && (_MSC_VER >= 1600) | ||
7 | #include <stdint.h> // for WCHAR_MAX in vs2022 | ||
8 | #endif | ||
9 | |||
5 | #include "StringToInt.h" | 10 | #include "StringToInt.h" |
6 | 11 | ||
7 | static const UInt32 k_UInt32_max = 0xFFFFFFFF; | 12 | static const UInt32 k_UInt32_max = 0xFFFFFFFF; |
8 | static const UInt64 k_UInt64_max = UINT64_CONST(0xFFFFFFFFFFFFFFFF); | 13 | static const UInt64 k_UInt64_max = UINT64_CONST(0xFFFFFFFFFFFFFFFF); |
9 | // static const UInt64 k_UInt64_max = (UInt64)(Int64)-1; | 14 | // static const UInt64 k_UInt64_max = (UInt64)(Int64)-1; |
10 | 15 | ||
16 | #define DIGIT_TO_VALUE(charTypeUnsigned, digit) ((unsigned)(charTypeUnsigned)digit - '0') | ||
17 | // #define DIGIT_TO_VALUE(charTypeUnsigned, digit) ((unsigned)digit - '0') | ||
18 | // #define DIGIT_TO_VALUE(charTypeUnsigned, digit) ((unsigned)(digit - '0')) | ||
19 | |||
11 | #define CONVERT_STRING_TO_UINT_FUNC(uintType, charType, charTypeUnsigned) \ | 20 | #define CONVERT_STRING_TO_UINT_FUNC(uintType, charType, charTypeUnsigned) \ |
12 | uintType ConvertStringTo ## uintType(const charType *s, const charType **end) throw() { \ | 21 | uintType ConvertStringTo ## uintType(const charType *s, const charType **end) throw() { \ |
22 | if (end) *end = s; \ | ||
23 | uintType res = 0; \ | ||
24 | for (;; s++) { \ | ||
25 | const unsigned v = DIGIT_TO_VALUE(charTypeUnsigned, *s); \ | ||
26 | if (v > 9) { if (end) *end = s; return res; } \ | ||
27 | if (res > (k_ ## uintType ## _max) / 10) return 0; \ | ||
28 | res *= 10; \ | ||
29 | if (res > (k_ ## uintType ## _max) - v) return 0; \ | ||
30 | res += v; }} | ||
31 | |||
32 | // arm-linux-gnueabi GCC compilers give (WCHAR_MAX > UINT_MAX) by some unknown reason | ||
33 | // so we don't use this branch | ||
34 | #if 0 && WCHAR_MAX > UINT_MAX | ||
35 | /* | ||
36 | if (sizeof(wchar_t) > sizeof(unsigned) | ||
37 | we must use CONVERT_STRING_TO_UINT_FUNC_SLOW | ||
38 | But we just stop compiling instead. | ||
39 | We need some real cases to test this code. | ||
40 | */ | ||
41 | #error Stop_Compiling_WCHAR_MAX_IS_LARGER_THAN_UINT_MAX | ||
42 | #define CONVERT_STRING_TO_UINT_FUNC_SLOW(uintType, charType, charTypeUnsigned) \ | ||
43 | uintType ConvertStringTo ## uintType(const charType *s, const charType **end) throw() { \ | ||
13 | if (end) *end = s; \ | 44 | if (end) *end = s; \ |
14 | uintType res = 0; \ | 45 | uintType res = 0; \ |
15 | for (;; s++) { \ | 46 | for (;; s++) { \ |
16 | charTypeUnsigned c = (charTypeUnsigned)*s; \ | 47 | const charTypeUnsigned c = (charTypeUnsigned)*s; \ |
17 | if (c < '0' || c > '9') { if (end) *end = s; return res; } \ | 48 | if (c < '0' || c > '9') { if (end) *end = s; return res; } \ |
18 | if (res > (k_ ## uintType ## _max) / 10) return 0; \ | 49 | if (res > (k_ ## uintType ## _max) / 10) return 0; \ |
19 | res *= 10; \ | 50 | res *= 10; \ |
20 | unsigned v = (unsigned)(c - '0'); \ | 51 | const unsigned v = (unsigned)(c - '0'); \ |
21 | if (res > (k_ ## uintType ## _max) - v) return 0; \ | 52 | if (res > (k_ ## uintType ## _max) - v) return 0; \ |
22 | res += v; }} | 53 | res += v; }} |
54 | #endif | ||
55 | |||
23 | 56 | ||
24 | CONVERT_STRING_TO_UINT_FUNC(UInt32, char, Byte) | 57 | CONVERT_STRING_TO_UINT_FUNC(UInt32, char, Byte) |
25 | CONVERT_STRING_TO_UINT_FUNC(UInt32, wchar_t, wchar_t) | 58 | CONVERT_STRING_TO_UINT_FUNC(UInt32, wchar_t, wchar_t) |
26 | CONVERT_STRING_TO_UINT_FUNC(UInt64, char, Byte) | 59 | CONVERT_STRING_TO_UINT_FUNC(UInt64, char, Byte) |
27 | CONVERT_STRING_TO_UINT_FUNC(UInt64, wchar_t, wchar_t) | 60 | CONVERT_STRING_TO_UINT_FUNC(UInt64, wchar_t, wchar_t) |
28 | 61 | ||
29 | /* | ||
30 | Int32 ConvertStringToInt32(const char *s, const char **end) throw() | ||
31 | { | ||
32 | if (end) | ||
33 | *end = s; | ||
34 | const char *s2 = s; | ||
35 | if (*s == '-') | ||
36 | s2++; | ||
37 | if (*s2 == 0) | ||
38 | return 0; | ||
39 | const char *end2; | ||
40 | UInt32 res = ConvertStringToUInt32(s2, &end2); | ||
41 | if (*s == '-') | ||
42 | { | ||
43 | if (res > ((UInt32)1 << (32 - 1))) | ||
44 | return 0; | ||
45 | } | ||
46 | else if ((res & ((UInt32)1 << (32 - 1))) != 0) | ||
47 | return 0; | ||
48 | if (end) | ||
49 | *end = end2; | ||
50 | if (*s == '-') | ||
51 | return -(Int32)res; | ||
52 | return (Int32)res; | ||
53 | } | ||
54 | */ | ||
55 | |||
56 | Int32 ConvertStringToInt32(const wchar_t *s, const wchar_t **end) throw() | 62 | Int32 ConvertStringToInt32(const wchar_t *s, const wchar_t **end) throw() |
57 | { | 63 | { |
58 | if (end) | 64 | if (end) |
@@ -60,112 +66,89 @@ Int32 ConvertStringToInt32(const wchar_t *s, const wchar_t **end) throw() | |||
60 | const wchar_t *s2 = s; | 66 | const wchar_t *s2 = s; |
61 | if (*s == '-') | 67 | if (*s == '-') |
62 | s2++; | 68 | s2++; |
63 | if (*s2 == 0) | ||
64 | return 0; | ||
65 | const wchar_t *end2; | 69 | const wchar_t *end2; |
66 | UInt32 res = ConvertStringToUInt32(s2, &end2); | 70 | UInt32 res = ConvertStringToUInt32(s2, &end2); |
67 | if (*s == '-') | 71 | if (s2 == end2) |
72 | return 0; | ||
73 | if (s != s2) | ||
68 | { | 74 | { |
69 | if (res > ((UInt32)1 << (32 - 1))) | 75 | if (res > (UInt32)1 << (32 - 1)) |
76 | return 0; | ||
77 | res = 0 - res; | ||
78 | } | ||
79 | else | ||
80 | { | ||
81 | if (res & (UInt32)1 << (32 - 1)) | ||
70 | return 0; | 82 | return 0; |
71 | } | 83 | } |
72 | else if ((res & ((UInt32)1 << (32 - 1))) != 0) | ||
73 | return 0; | ||
74 | if (end) | 84 | if (end) |
75 | *end = end2; | 85 | *end = end2; |
76 | if (*s == '-') | ||
77 | return -(Int32)res; | ||
78 | return (Int32)res; | 86 | return (Int32)res; |
79 | } | 87 | } |
80 | 88 | ||
81 | UInt32 ConvertOctStringToUInt32(const char *s, const char **end) throw() | 89 | |
82 | { | 90 | #define CONVERT_OCT_STRING_TO_UINT_FUNC(uintType) \ |
83 | if (end) | 91 | uintType ConvertOctStringTo ## uintType(const char *s, const char **end) throw() \ |
84 | *end = s; | 92 | { \ |
85 | UInt32 res = 0; | 93 | if (end) *end = s; \ |
86 | for (;; s++) | 94 | uintType res = 0; \ |
87 | { | 95 | for (;; s++) { \ |
88 | unsigned c = (unsigned char)*s; | 96 | const unsigned c = (unsigned)(Byte)*s - '0'; \ |
89 | if (c < '0' || c > '7') | 97 | if (c > 7) { \ |
90 | { | 98 | if (end) \ |
91 | if (end) | 99 | *end = s; \ |
92 | *end = s; | 100 | return res; \ |
93 | return res; | 101 | } \ |
94 | } | 102 | if (res & (uintType)7 << (sizeof(uintType) * 8 - 3)) \ |
95 | if ((res & (UInt32)7 << (32 - 3)) != 0) | 103 | return 0; \ |
96 | return 0; | 104 | res <<= 3; \ |
97 | res <<= 3; | 105 | res |= c; \ |
98 | res |= (unsigned)(c - '0'); | 106 | } \ |
99 | } | ||
100 | } | 107 | } |
101 | 108 | ||
102 | UInt64 ConvertOctStringToUInt64(const char *s, const char **end) throw() | 109 | CONVERT_OCT_STRING_TO_UINT_FUNC(UInt32) |
103 | { | 110 | CONVERT_OCT_STRING_TO_UINT_FUNC(UInt64) |
104 | if (end) | 111 | |
105 | *end = s; | 112 | |
106 | UInt64 res = 0; | 113 | #define CONVERT_HEX_STRING_TO_UINT_FUNC(uintType) \ |
107 | for (;; s++) | 114 | uintType ConvertHexStringTo ## uintType(const char *s, const char **end) throw() \ |
108 | { | 115 | { \ |
109 | unsigned c = (unsigned char)*s; | 116 | if (end) *end = s; \ |
110 | if (c < '0' || c > '7') | 117 | uintType res = 0; \ |
111 | { | 118 | for (;; s++) { \ |
112 | if (end) | 119 | unsigned c = (unsigned)(Byte)*s; \ |
113 | *end = s; | 120 | Z7_PARSE_HEX_DIGIT(c, { if (end) *end = s; return res; }) \ |
114 | return res; | 121 | if (res & (uintType)0xF << (sizeof(uintType) * 8 - 4)) \ |
115 | } | 122 | return 0; \ |
116 | if ((res & (UInt64)7 << (64 - 3)) != 0) | 123 | res <<= 4; \ |
117 | return 0; | 124 | res |= c; \ |
118 | res <<= 3; | 125 | } \ |
119 | res |= (unsigned)(c - '0'); | ||
120 | } | ||
121 | } | 126 | } |
122 | 127 | ||
123 | UInt32 ConvertHexStringToUInt32(const char *s, const char **end) throw() | 128 | CONVERT_HEX_STRING_TO_UINT_FUNC(UInt32) |
129 | CONVERT_HEX_STRING_TO_UINT_FUNC(UInt64) | ||
130 | |||
131 | const char *FindNonHexChar(const char *s) throw() | ||
124 | { | 132 | { |
125 | if (end) | 133 | for (;;) |
126 | *end = s; | ||
127 | UInt32 res = 0; | ||
128 | for (;; s++) | ||
129 | { | 134 | { |
130 | unsigned c = (Byte)*s; | 135 | unsigned c = (Byte)*s++; // pointer can go 1 byte after end |
131 | unsigned v; | 136 | c -= '0'; |
132 | if (c >= '0' && c <= '9') v = (c - '0'); | 137 | if (c <= 9) |
133 | else if (c >= 'A' && c <= 'F') v = 10 + (c - 'A'); | 138 | continue; |
134 | else if (c >= 'a' && c <= 'f') v = 10 + (c - 'a'); | 139 | c -= 'A' - '0'; |
135 | else | 140 | c &= ~0x20u; |
136 | { | 141 | if (c > 5) |
137 | if (end) | 142 | return s - 1; |
138 | *end = s; | ||
139 | return res; | ||
140 | } | ||
141 | if ((res & (UInt32)0xF << (32 - 4)) != 0) | ||
142 | return 0; | ||
143 | res <<= 4; | ||
144 | res |= v; | ||
145 | } | 143 | } |
146 | } | 144 | } |
147 | 145 | ||
148 | UInt64 ConvertHexStringToUInt64(const char *s, const char **end) throw() | 146 | Byte *ParseHexString(const char *s, Byte *dest) throw() |
149 | { | 147 | { |
150 | if (end) | 148 | for (;;) |
151 | *end = s; | ||
152 | UInt64 res = 0; | ||
153 | for (;; s++) | ||
154 | { | 149 | { |
155 | unsigned c = (Byte)*s; | 150 | unsigned v0 = (Byte)s[0]; Z7_PARSE_HEX_DIGIT(v0, return dest;) |
156 | unsigned v; | 151 | unsigned v1 = (Byte)s[1]; s += 2; Z7_PARSE_HEX_DIGIT(v1, return dest;) |
157 | if (c >= '0' && c <= '9') v = (c - '0'); | 152 | *dest++ = (Byte)(v1 | (v0 << 4)); |
158 | else if (c >= 'A' && c <= 'F') v = 10 + (c - 'A'); | ||
159 | else if (c >= 'a' && c <= 'f') v = 10 + (c - 'a'); | ||
160 | else | ||
161 | { | ||
162 | if (end) | ||
163 | *end = s; | ||
164 | return res; | ||
165 | } | ||
166 | if ((res & (UInt64)0xF << (64 - 4)) != 0) | ||
167 | return 0; | ||
168 | res <<= 4; | ||
169 | res |= v; | ||
170 | } | 153 | } |
171 | } | 154 | } |
diff --git a/CPP/Common/StringToInt.h b/CPP/Common/StringToInt.h index c9dce7d..31ab274 100644 --- a/CPP/Common/StringToInt.h +++ b/CPP/Common/StringToInt.h | |||
@@ -19,4 +19,20 @@ UInt64 ConvertOctStringToUInt64(const char *s, const char **end) throw(); | |||
19 | UInt32 ConvertHexStringToUInt32(const char *s, const char **end) throw(); | 19 | UInt32 ConvertHexStringToUInt32(const char *s, const char **end) throw(); |
20 | UInt64 ConvertHexStringToUInt64(const char *s, const char **end) throw(); | 20 | UInt64 ConvertHexStringToUInt64(const char *s, const char **end) throw(); |
21 | 21 | ||
22 | #define Z7_PARSE_HEX_DIGIT(c, err_op) \ | ||
23 | { c -= '0'; \ | ||
24 | if (c > 9) { \ | ||
25 | c -= 'A' - '0'; \ | ||
26 | c &= ~0x20u; \ | ||
27 | if (c > 5) { err_op } \ | ||
28 | c += 10; \ | ||
29 | } \ | ||
30 | } | ||
31 | |||
32 | const char *FindNonHexChar(const char *s) throw(); | ||
33 | |||
34 | // in: (dest != NULL) | ||
35 | // returns: pointer in dest array after last written byte | ||
36 | Byte *ParseHexString(const char *s, Byte *dest) throw(); | ||
37 | |||
22 | #endif | 38 | #endif |
diff --git a/CPP/Common/TextConfig.cpp b/CPP/Common/TextConfig.cpp index d3e561c..5714e46 100644 --- a/CPP/Common/TextConfig.cpp +++ b/CPP/Common/TextConfig.cpp | |||
@@ -90,15 +90,14 @@ bool GetTextConfig(const AString &s, CObjectVector<CTextConfigPair> &pairs) | |||
90 | c = s[pos++]; | 90 | c = s[pos++]; |
91 | switch (c) | 91 | switch (c) |
92 | { | 92 | { |
93 | case 'n': message += '\n'; break; | 93 | case 'n': c = '\n'; break; |
94 | case 't': message += '\t'; break; | 94 | case 't': c = '\t'; break; |
95 | case '\\': message += '\\'; break; | 95 | case '\\': break; |
96 | case '\"': message += '\"'; break; | 96 | case '\"': break; |
97 | default: message += '\\'; message += c; break; | 97 | default: message += '\\'; break; |
98 | } | 98 | } |
99 | } | 99 | } |
100 | else | 100 | message += c; |
101 | message += c; | ||
102 | } | 101 | } |
103 | if (!ConvertUTF8ToUnicode(message, pair.String)) | 102 | if (!ConvertUTF8ToUnicode(message, pair.String)) |
104 | return false; | 103 | return false; |
diff --git a/CPP/Common/UTFConvert.cpp b/CPP/Common/UTFConvert.cpp index fb166b7..509de76 100644 --- a/CPP/Common/UTFConvert.cpp +++ b/CPP/Common/UTFConvert.cpp | |||
@@ -135,7 +135,7 @@ we can place 128 ESCAPE chars to | |||
135 | #endif | 135 | #endif |
136 | 136 | ||
137 | #define IS_SURROGATE_POINT(v) (((v) & (UInt32)0xfffff800) == 0xd800) | 137 | #define IS_SURROGATE_POINT(v) (((v) & (UInt32)0xfffff800) == 0xd800) |
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 UTF_ERROR_UTF8_CHECK \ | 141 | #define UTF_ERROR_UTF8_CHECK \ |
@@ -168,14 +168,14 @@ 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) |
172 | UTF_ERROR_UTF8_CHECK | 172 | UTF_ERROR_UTF8_CHECK |
173 | 173 | ||
174 | unsigned numBytes; | 174 | unsigned numBytes; |
175 | |||
176 | UInt32 val = c; | 175 | UInt32 val = c; |
177 | MY_UTF8_HEAD_PARSE2(1) | 176 | MY_UTF8_HEAD_PARSE2(1) |
178 | else MY_UTF8_HEAD_PARSE2(2) | 177 | else MY_UTF8_HEAD_PARSE2(2) |
178 | else MY_UTF8_HEAD_PARSE2(3) | ||
179 | else MY_UTF8_HEAD_PARSE2(4) | 179 | else MY_UTF8_HEAD_PARSE2(4) |
180 | else MY_UTF8_HEAD_PARSE2(5) | 180 | else MY_UTF8_HEAD_PARSE2(5) |
181 | else | 181 | else |
@@ -768,7 +768,7 @@ void Convert_UTF16_To_UTF32(const UString &src, UString &dest) | |||
768 | if (c >= 0xd800 && c < 0xdc00 && i < src.Len()) | 768 | if (c >= 0xd800 && c < 0xdc00 && i < src.Len()) |
769 | { | 769 | { |
770 | const wchar_t c2 = src[i]; | 770 | const wchar_t c2 = src[i]; |
771 | if (c2 >= 0xdc00 && c2 < 0x10000) | 771 | if (c2 >= 0xdc00 && c2 < 0xe000) |
772 | { | 772 | { |
773 | // printf("\nSurragate [%d]: %4x %4x -> ", i, (int)c, (int)c2); | 773 | // printf("\nSurragate [%d]: %4x %4x -> ", i, (int)c, (int)c2); |
774 | c = 0x10000 + ((c & 0x3ff) << 10) + (c2 & 0x3ff); | 774 | c = 0x10000 + ((c & 0x3ff) << 10) + (c2 & 0x3ff); |
diff --git a/CPP/Common/Xxh64Reg.cpp b/CPP/Common/Xxh64Reg.cpp new file mode 100644 index 0000000..8abd15e --- /dev/null +++ b/CPP/Common/Xxh64Reg.cpp | |||
@@ -0,0 +1,97 @@ | |||
1 | // Xxh64Reg.cpp | ||
2 | |||
3 | #include "StdAfx.h" | ||
4 | |||
5 | #include "../../C/Xxh64.h" | ||
6 | #include "../../C/CpuArch.h" | ||
7 | |||
8 | // #define Z7_USE_HHX64_ORIGINAL | ||
9 | #ifdef Z7_USE_HHX64_ORIGINAL | ||
10 | #ifdef __clang__ | ||
11 | #include "../../C/zstd7z/7z_zstd_cmpl.h" | ||
12 | #pragma GCC diagnostic ignored "-Wlanguage-extension-token" | ||
13 | #endif | ||
14 | #define XXH_STATIC_LINKING_ONLY | ||
15 | #include "../../C/zstd7z/common/xxhash.h" | ||
16 | #endif | ||
17 | |||
18 | #include "../Common/MyCom.h" | ||
19 | |||
20 | #include "../7zip/Common/RegisterCodec.h" | ||
21 | |||
22 | Z7_CLASS_IMP_COM_1( | ||
23 | CXxh64Hasher | ||
24 | , IHasher | ||
25 | ) | ||
26 | CXxh64 _state; | ||
27 | public: | ||
28 | Byte _mtDummy[1 << 7]; // it's public to eliminate clang warning: unused private field | ||
29 | CXxh64Hasher() { Init(); } | ||
30 | }; | ||
31 | |||
32 | Z7_COM7F_IMF2(void, CXxh64Hasher::Init()) | ||
33 | { | ||
34 | Xxh64_Init(&_state); | ||
35 | } | ||
36 | |||
37 | Z7_COM7F_IMF2(void, CXxh64Hasher::Update(const void *data, UInt32 size)) | ||
38 | { | ||
39 | #if 1 | ||
40 | Xxh64_Update(&_state, data, size); | ||
41 | #else // for debug: | ||
42 | for (;;) | ||
43 | { | ||
44 | if (size == 0) | ||
45 | return; | ||
46 | UInt32 size2 = (size * 0x85EBCA87) % size / 8; | ||
47 | if (size2 == 0) | ||
48 | size2 = 1; | ||
49 | Xxh64_Update(&_state, data, size2); | ||
50 | data = (const void *)((const Byte *)data + size2); | ||
51 | size -= size2; | ||
52 | } | ||
53 | #endif | ||
54 | } | ||
55 | |||
56 | Z7_COM7F_IMF2(void, CXxh64Hasher::Final(Byte *digest)) | ||
57 | { | ||
58 | const UInt64 val = Xxh64_Digest(&_state); | ||
59 | SetUi64(digest, val) | ||
60 | } | ||
61 | |||
62 | REGISTER_HASHER(CXxh64Hasher, 0x211, "XXH64", 8) | ||
63 | |||
64 | |||
65 | |||
66 | #ifdef Z7_USE_HHX64_ORIGINAL | ||
67 | namespace NOriginal | ||
68 | { | ||
69 | Z7_CLASS_IMP_COM_1( | ||
70 | CXxh64Hasher | ||
71 | , IHasher | ||
72 | ) | ||
73 | XXH64_state_t _state; | ||
74 | public: | ||
75 | Byte _mtDummy[1 << 7]; // it's public to eliminate clang warning: unused private field | ||
76 | CXxh64Hasher() { Init(); } | ||
77 | }; | ||
78 | |||
79 | Z7_COM7F_IMF2(void, CXxh64Hasher::Init()) | ||
80 | { | ||
81 | XXH64_reset(&_state, 0); | ||
82 | } | ||
83 | |||
84 | Z7_COM7F_IMF2(void, CXxh64Hasher::Update(const void *data, UInt32 size)) | ||
85 | { | ||
86 | XXH64_update(&_state, data, size); | ||
87 | } | ||
88 | |||
89 | Z7_COM7F_IMF2(void, CXxh64Hasher::Final(Byte *digest)) | ||
90 | { | ||
91 | const UInt64 val = XXH64_digest(&_state); | ||
92 | SetUi64(digest, val) | ||
93 | } | ||
94 | |||
95 | REGISTER_HASHER(CXxh64Hasher, 0x212, "XXH64a", 8) | ||
96 | } | ||
97 | #endif | ||