Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/kornelski/7z.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorIgor Pavlov <ipavlov@users.sourceforge.net>2008-05-05 04:00:00 +0400
committerKornel LesiƄski <kornel@geekhood.net>2016-05-28 02:15:55 +0300
commit3901bf0ab88106a5b031cba7bc18d60cdebf7eef (patch)
tree808a2489abed822223b118b64e0553db80af6087
parentbd1fa36322ac27f5715433b388742893d6524516 (diff)
4.58 beta
-rwxr-xr-xC/7zBuf.c36
-rwxr-xr-xC/7zBuf.h21
-rwxr-xr-xC/7zCrc.c5
-rwxr-xr-xC/7zCrc.h5
-rwxr-xr-xC/7zCrcT8.c5
-rwxr-xr-xC/Aes.c (renamed from C/Crypto/Aes.c)93
-rwxr-xr-xC/Aes.h48
-rwxr-xr-xC/Alloc.c5
-rwxr-xr-xC/Alloc.h5
-rwxr-xr-xC/Archive/7z/7z.dsp (renamed from C/Archive/7z/7z_C.dsp)72
-rwxr-xr-xC/Archive/7z/7z.dsw (renamed from CPP/7zip/Archive/7z/7z.dsw)2
-rwxr-xr-xC/Archive/7z/7zAlloc.c19
-rwxr-xr-xC/Archive/7z/7zAlloc.h19
-rwxr-xr-xC/Archive/7z/7zBuffer.c29
-rwxr-xr-xC/Archive/7z/7zBuffer.h19
-rwxr-xr-xC/Archive/7z/7zDecode.c280
-rwxr-xr-xC/Archive/7z/7zDecode.h16
-rwxr-xr-xC/Archive/7z/7zExtract.c77
-rwxr-xr-xC/Archive/7z/7zExtract.h10
-rwxr-xr-xC/Archive/7z/7zHeader.c6
-rwxr-xr-xC/Archive/7z/7zHeader.h5
-rwxr-xr-xC/Archive/7z/7zIn.c547
-rwxr-xr-xC/Archive/7z/7zIn.h70
-rwxr-xr-xC/Archive/7z/7zItem.c154
-rwxr-xr-xC/Archive/7z/7zItem.h86
-rwxr-xr-xC/Archive/7z/7zMain.c112
-rwxr-xr-xC/Archive/7z/7zMethodID.c10
-rwxr-xr-xC/Archive/7z/7zMethodID.h10
-rwxr-xr-xC/Archive/7z/makefile60
-rwxr-xr-xC/Archive/7z/makefile.gcc23
-rwxr-xr-xC/Bcj2.c (renamed from C/Compress/Branch/BranchX86_2.c)57
-rwxr-xr-xC/Bcj2.h (renamed from C/Compress/Branch/BranchX86_2.h)20
-rwxr-xr-xC/Bra.c135
-rwxr-xr-xC/Bra.h62
-rwxr-xr-xC/Bra86.c (renamed from C/Compress/Branch/BranchX86.c)27
-rwxr-xr-xC/BraIA64.c (renamed from C/Compress/Branch/BranchIA64.c)29
-rwxr-xr-xC/BwtSort.c (renamed from CPP/7zip/Compress/BWT/BlockSort.cpp)162
-rwxr-xr-xC/BwtSort.h (renamed from CPP/7zip/Compress/BWT/BlockSort.h)15
-rwxr-xr-xC/Compress/Branch/BranchARM.c26
-rwxr-xr-xC/Compress/Branch/BranchARM.h10
-rwxr-xr-xC/Compress/Branch/BranchARMThumb.c35
-rwxr-xr-xC/Compress/Branch/BranchARMThumb.h10
-rwxr-xr-xC/Compress/Branch/BranchIA64.h10
-rwxr-xr-xC/Compress/Branch/BranchPPC.c36
-rwxr-xr-xC/Compress/Branch/BranchPPC.h10
-rwxr-xr-xC/Compress/Branch/BranchSPARC.c36
-rwxr-xr-xC/Compress/Branch/BranchSPARC.h10
-rwxr-xr-xC/Compress/Branch/BranchTypes.h51
-rwxr-xr-xC/Compress/Branch/BranchX86.h12
-rwxr-xr-xC/Compress/Lzma/LzmaDecode.c584
-rwxr-xr-xC/Compress/Lzma/LzmaDecode.h113
-rwxr-xr-xC/Compress/Lzma/LzmaDecodeSize.c712
-rwxr-xr-xC/Compress/Lzma/LzmaStateDecode.c521
-rwxr-xr-xC/Compress/Lzma/LzmaStateDecode.h96
-rwxr-xr-xC/Compress/Lzma/LzmaStateTest.c195
-rwxr-xr-xC/Compress/Lzma/LzmaTest.c342
-rwxr-xr-xC/Compress/Lzma/LzmaTypes.h45
-rwxr-xr-xC/CpuArch.h32
-rwxr-xr-xC/Crypto/Aes.h40
-rwxr-xr-xC/HuffEnc.c (renamed from C/Compress/Huffman/HuffmanEncode.c)12
-rwxr-xr-xC/HuffEnc.h (renamed from C/Compress/Huffman/HuffmanEncode.h)11
-rwxr-xr-xC/IStream.h19
-rwxr-xr-xC/LzFind.c (renamed from C/Compress/Lz/MatchFinder.c)85
-rwxr-xr-xC/LzFind.h (renamed from C/Compress/Lz/MatchFinder.h)22
-rwxr-xr-xC/LzFindMt.c (renamed from C/Compress/Lz/MatchFinderMt.c)95
-rwxr-xr-xC/LzFindMt.h (renamed from C/Compress/Lz/MatchFinderMt.h)18
-rwxr-xr-xC/LzHash.h (renamed from C/Compress/Lz/LzHash.h)33
-rwxr-xr-xC/LzmaDec.c1014
-rwxr-xr-xC/LzmaDec.h232
-rwxr-xr-xC/LzmaEnc.c2332
-rwxr-xr-xC/LzmaEnc.h74
-rwxr-xr-xC/LzmaLib.c46
-rwxr-xr-xC/LzmaLib.h135
-rwxr-xr-xC/LzmaLib/LzmaLib.def4
-rwxr-xr-xC/LzmaLib/LzmaLib.dsp (renamed from CPP/7zip/Compress/Copy/Copy.dsp)104
-rwxr-xr-xC/LzmaLib/LzmaLib.dsw (renamed from CPP/7zip/Compress/BZip2/BZip2.dsw)2
-rwxr-xr-xC/LzmaLib/LzmaLibExports.c14
-rwxr-xr-xC/LzmaLib/makefile37
-rwxr-xr-xC/LzmaLib/resource.rc4
-rwxr-xr-xC/LzmaUtil/Lzma86Dec.c61
-rwxr-xr-xC/LzmaUtil/Lzma86Dec.h45
-rwxr-xr-xC/LzmaUtil/Lzma86Enc.c113
-rwxr-xr-xC/LzmaUtil/Lzma86Enc.h72
-rwxr-xr-xC/LzmaUtil/LzmaUtil.c311
-rwxr-xr-xC/LzmaUtil/LzmaUtil.dsp152
-rwxr-xr-xC/LzmaUtil/LzmaUtil.dsw (renamed from C/Archive/7z/7z_C.dsw)2
-rwxr-xr-xC/LzmaUtil/makefile27
-rwxr-xr-xC/LzmaUtil/makefile.gcc36
-rwxr-xr-xC/RotateDefs.h (renamed from CPP/7zip/Crypto/Hash/RotateDefs.h)7
-rwxr-xr-xC/Sha256.c (renamed from CPP/7zip/Crypto/Hash/Sha256.cpp)160
-rwxr-xr-xC/Sha256.h24
-rwxr-xr-xC/Sort.c5
-rwxr-xr-xC/Sort.h9
-rwxr-xr-xC/Threads.c71
-rwxr-xr-xC/Threads.h43
-rwxr-xr-xC/Types.h152
-rwxr-xr-xCPP/7zip/Archive/7z/7z.dsp644
-rwxr-xr-xCPP/7zip/Archive/7z/7zIn.cpp14
-rwxr-xr-xCPP/7zip/Archive/7z/7zProperties.cpp9
-rwxr-xr-xCPP/7zip/Archive/7z/makefile111
-rwxr-xr-xCPP/7zip/Archive/7z/resource.rc5
-rwxr-xr-xCPP/7zip/Archive/ArchiveExports.cpp4
-rwxr-xr-xCPP/7zip/Archive/Arj/ArjIn.cpp8
-rwxr-xr-xCPP/7zip/Archive/BZip2/BZip2Handler.cpp11
-rwxr-xr-xCPP/7zip/Archive/Cab/CabBlockInStream.cpp20
-rwxr-xr-xCPP/7zip/Archive/Chm/ChmHandler.cpp2
-rwxr-xr-xCPP/7zip/Archive/Com/ComHandler.cpp8
-rwxr-xr-xCPP/7zip/Archive/Com/ComIn.cpp22
-rwxr-xr-xCPP/7zip/Archive/Common/CoderMixer2MT.cpp6
-rwxr-xr-xCPP/7zip/Archive/Common/CoderMixerMT.cpp6
-rwxr-xr-xCPP/7zip/Archive/Common/HandlerOut.cpp32
-rwxr-xr-xCPP/7zip/Archive/Common/ParseProperties.cpp7
-rwxr-xr-xCPP/7zip/Archive/Cpio/CpioIn.cpp7
-rwxr-xr-xCPP/7zip/Archive/Deb/DebIn.cpp21
-rwxr-xr-xCPP/7zip/Archive/Deb/DebIn.h1
-rwxr-xr-xCPP/7zip/Archive/GZip/GZipIn.cpp7
-rwxr-xr-xCPP/7zip/Archive/GZip/GZipOut.cpp6
-rwxr-xr-xCPP/7zip/Archive/Iso/IsoIn.cpp14
-rwxr-xr-xCPP/7zip/Archive/Iso/IsoIn.h1
-rwxr-xr-xCPP/7zip/Archive/Iso/IsoItem.h4
-rwxr-xr-xCPP/7zip/Archive/Lzh/LzhIn.cpp4
-rwxr-xr-xCPP/7zip/Archive/Lzma/LzmaArcRegister.cpp14
-rwxr-xr-xCPP/7zip/Archive/Lzma/LzmaFiltersDecode.cpp86
-rwxr-xr-xCPP/7zip/Archive/Lzma/LzmaFiltersDecode.h26
-rwxr-xr-xCPP/7zip/Archive/Lzma/LzmaHandler.cpp243
-rwxr-xr-xCPP/7zip/Archive/Lzma/LzmaHandler.h69
-rwxr-xr-xCPP/7zip/Archive/Lzma/LzmaIn.cpp56
-rwxr-xr-xCPP/7zip/Archive/Lzma/LzmaIn.h16
-rwxr-xr-xCPP/7zip/Archive/Lzma/LzmaItem.h27
-rwxr-xr-xCPP/7zip/Archive/Lzma/StdAfx.h8
-rwxr-xr-xCPP/7zip/Archive/Lzma/lzma.icobin0 -> 3638 bytes
-rwxr-xr-xCPP/7zip/Archive/Nsis/NsisDecode.cpp4
-rwxr-xr-xCPP/7zip/Archive/Nsis/NsisDecode.h2
-rwxr-xr-xCPP/7zip/Archive/Nsis/NsisHandler.cpp32
-rwxr-xr-xCPP/7zip/Archive/Nsis/NsisIn.cpp232
-rwxr-xr-xCPP/7zip/Archive/Nsis/NsisIn.h53
-rwxr-xr-xCPP/7zip/Archive/RPM/RpmHandler.cpp30
-rwxr-xr-xCPP/7zip/Archive/RPM/RpmHandler.h1
-rwxr-xr-xCPP/7zip/Archive/RPM/RpmIn.cpp10
-rwxr-xr-xCPP/7zip/Archive/RPM/RpmRegister.cpp2
-rwxr-xr-xCPP/7zip/Archive/Rar/RarHandler.cpp13
-rwxr-xr-xCPP/7zip/Archive/Rar/RarIn.cpp21
-rwxr-xr-xCPP/7zip/Archive/Rar/RarIn.h2
-rwxr-xr-xCPP/7zip/Archive/Tar/TarHeader.h9
-rwxr-xr-xCPP/7zip/Archive/Tar/TarIn.cpp23
-rwxr-xr-xCPP/7zip/Archive/Tar/TarIn.h2
-rwxr-xr-xCPP/7zip/Archive/Tar/TarItem.h16
-rwxr-xr-xCPP/7zip/Archive/Tar/TarOut.cpp6
-rwxr-xr-xCPP/7zip/Archive/Wim/WimHandler.cpp4
-rwxr-xr-xCPP/7zip/Archive/Wim/WimIn.cpp81
-rwxr-xr-xCPP/7zip/Archive/Z/ZHandler.cpp5
-rwxr-xr-xCPP/7zip/Archive/Zip/ZipAddCommon.cpp2
-rwxr-xr-xCPP/7zip/Archive/Zip/ZipHandler.cpp64
-rwxr-xr-xCPP/7zip/Archive/Zip/ZipHandler.h7
-rwxr-xr-xCPP/7zip/Archive/Zip/ZipHandlerOut.cpp171
-rwxr-xr-xCPP/7zip/Archive/Zip/ZipHeader.h18
-rwxr-xr-xCPP/7zip/Archive/Zip/ZipIn.cpp12
-rwxr-xr-xCPP/7zip/Archive/Zip/ZipItem.cpp34
-rwxr-xr-xCPP/7zip/Archive/Zip/ZipItem.h48
-rwxr-xr-xCPP/7zip/Archive/Zip/ZipOut.cpp17
-rwxr-xr-xCPP/7zip/Archive/Zip/ZipUpdate.cpp14
-rwxr-xr-xCPP/7zip/Archive/Zip/ZipUpdate.h8
-rwxr-xr-xCPP/7zip/Bundles/Alone/Alone.dsp458
-rwxr-xr-xCPP/7zip/Bundles/Alone/makefile60
-rwxr-xr-xCPP/7zip/Bundles/Alone7z/Alone.dsp1453
-rwxr-xr-xCPP/7zip/Bundles/Alone7z/Alone.dsw29
-rwxr-xr-xCPP/7zip/Bundles/Alone7z/makefile62
-rwxr-xr-xCPP/7zip/Bundles/Format7z/makefile44
-rwxr-xr-xCPP/7zip/Bundles/Format7zExtract/makefile35
-rwxr-xr-xCPP/7zip/Bundles/Format7zExtractR/makefile31
-rwxr-xr-xCPP/7zip/Bundles/Format7zF/Format7z.dsp393
-rwxr-xr-xCPP/7zip/Bundles/Format7zF/makefile61
-rwxr-xr-xCPP/7zip/Bundles/Format7zF/resource.rc3
-rwxr-xr-xCPP/7zip/Bundles/Format7zR/makefile45
-rwxr-xr-xCPP/7zip/Bundles/SFXCon/SFXCon.dsp46
-rwxr-xr-xCPP/7zip/Bundles/SFXCon/makefile24
-rwxr-xr-xCPP/7zip/Bundles/SFXSetup/SFXSetup.dsp25
-rwxr-xr-xCPP/7zip/Bundles/SFXSetup/makefile12
-rwxr-xr-xCPP/7zip/Bundles/SFXWin/Main.cpp2
-rwxr-xr-xCPP/7zip/Bundles/SFXWin/SFXWin.dsp46
-rwxr-xr-xCPP/7zip/Bundles/SFXWin/makefile24
-rwxr-xr-xCPP/7zip/Common/FileStreams.cpp2
-rwxr-xr-xCPP/7zip/Common/FilterCoder.cpp26
-rwxr-xr-xCPP/7zip/Common/InOutTempBuffer.cpp4
-rwxr-xr-xCPP/7zip/Common/MemBlocks.cpp7
-rwxr-xr-xCPP/7zip/Common/StreamObjects.cpp34
-rwxr-xr-xCPP/7zip/Common/StreamUtils.cpp44
-rwxr-xr-xCPP/7zip/Common/StreamUtils.h6
-rwxr-xr-xCPP/7zip/Common/VirtThread.cpp2
-rwxr-xr-xCPP/7zip/Common/VirtThread.h2
-rwxr-xr-xCPP/7zip/Compress/Arj/ArjDecoder1.cpp4
-rwxr-xr-xCPP/7zip/Compress/Arj/ArjDecoder1.h8
-rwxr-xr-xCPP/7zip/Compress/Arj/ArjDecoder2.cpp4
-rwxr-xr-xCPP/7zip/Compress/Arj/ArjDecoder2.h7
-rwxr-xr-xCPP/7zip/Compress/BZip2/BZip2.dsp316
-rwxr-xr-xCPP/7zip/Compress/BZip2/BZip2Decoder.cpp30
-rwxr-xr-xCPP/7zip/Compress/BZip2/BZip2Decoder.h12
-rwxr-xr-xCPP/7zip/Compress/BZip2/BZip2Encoder.cpp38
-rwxr-xr-xCPP/7zip/Compress/BZip2/BZip2Encoder.h10
-rwxr-xr-xCPP/7zip/Compress/BZip2/makefile58
-rwxr-xr-xCPP/7zip/Compress/BZip2/resource.rc3
-rwxr-xr-xCPP/7zip/Compress/Branch/ARM.cpp19
-rwxr-xr-xCPP/7zip/Compress/Branch/ARM.h10
-rwxr-xr-xCPP/7zip/Compress/Branch/ARMThumb.cpp20
-rwxr-xr-xCPP/7zip/Compress/Branch/ARMThumb.h10
-rwxr-xr-xCPP/7zip/Compress/Branch/Branch.dsp433
-rwxr-xr-xCPP/7zip/Compress/Branch/Branch.dsw29
-rwxr-xr-xCPP/7zip/Compress/Branch/BranchMisc.cpp39
-rwxr-xr-xCPP/7zip/Compress/Branch/BranchMisc.h14
-rwxr-xr-xCPP/7zip/Compress/Branch/BranchRegister.cpp20
-rwxr-xr-xCPP/7zip/Compress/Branch/IA64.cpp19
-rwxr-xr-xCPP/7zip/Compress/Branch/IA64.h10
-rwxr-xr-xCPP/7zip/Compress/Branch/PPC.cpp19
-rwxr-xr-xCPP/7zip/Compress/Branch/PPC.h10
-rwxr-xr-xCPP/7zip/Compress/Branch/SPARC.cpp19
-rwxr-xr-xCPP/7zip/Compress/Branch/SPARC.h10
-rwxr-xr-xCPP/7zip/Compress/Branch/makefile63
-rwxr-xr-xCPP/7zip/Compress/Branch/resource.rc3
-rwxr-xr-xCPP/7zip/Compress/Branch/x86.h2
-rwxr-xr-xCPP/7zip/Compress/ByteSwap/ByteSwap.dsp133
-rwxr-xr-xCPP/7zip/Compress/ByteSwap/ByteSwap.dsw29
-rwxr-xr-xCPP/7zip/Compress/ByteSwap/makefile25
-rwxr-xr-xCPP/7zip/Compress/ByteSwap/resource.rc3
-rwxr-xr-xCPP/7zip/Compress/CodecExports.cpp4
-rwxr-xr-xCPP/7zip/Compress/Copy/Copy.dsw29
-rwxr-xr-xCPP/7zip/Compress/Copy/CopyCoder.cpp2
-rwxr-xr-xCPP/7zip/Compress/Copy/makefile37
-rwxr-xr-xCPP/7zip/Compress/Copy/resource.rc3
-rwxr-xr-xCPP/7zip/Compress/Deflate/Deflate.dsp350
-rwxr-xr-xCPP/7zip/Compress/Deflate/Deflate.dsw29
-rwxr-xr-xCPP/7zip/Compress/Deflate/DeflateEncoder.cpp64
-rwxr-xr-xCPP/7zip/Compress/Deflate/DeflateEncoder.h4
-rwxr-xr-xCPP/7zip/Compress/Deflate/makefile63
-rwxr-xr-xCPP/7zip/Compress/Deflate/resource.rc3
-rwxr-xr-xCPP/7zip/Compress/Huffman/HuffmanDecoder.h3
-rwxr-xr-xCPP/7zip/Compress/LZMA/LZMA.dsp367
-rwxr-xr-xCPP/7zip/Compress/LZMA/LZMA.dsw29
-rwxr-xr-xCPP/7zip/Compress/LZMA/LZMA.h82
-rwxr-xr-xCPP/7zip/Compress/LZMA/LZMADecoder.cpp426
-rwxr-xr-xCPP/7zip/Compress/LZMA/LZMADecoder.h208
-rwxr-xr-xCPP/7zip/Compress/LZMA/LZMAEncoder.cpp1512
-rwxr-xr-xCPP/7zip/Compress/LZMA/LZMAEncoder.h415
-rwxr-xr-xCPP/7zip/Compress/LZMA/makefile70
-rwxr-xr-xCPP/7zip/Compress/LZMA/resource.rc3
-rwxr-xr-xCPP/7zip/Compress/LZMA_Alone/AloneLZMA.dsp76
-rwxr-xr-xCPP/7zip/Compress/LZMA_Alone/LzmaAlone.cpp72
-rwxr-xr-xCPP/7zip/Compress/LZMA_Alone/LzmaBench.cpp10
-rwxr-xr-xCPP/7zip/Compress/LZMA_Alone/LzmaRam.cpp226
-rwxr-xr-xCPP/7zip/Compress/LZMA_Alone/LzmaRam.h46
-rwxr-xr-xCPP/7zip/Compress/LZMA_Alone/LzmaRamDecode.c78
-rwxr-xr-xCPP/7zip/Compress/LZMA_Alone/LzmaRamDecode.h55
-rwxr-xr-xCPP/7zip/Compress/LZMA_Alone/makefile85
-rwxr-xr-xCPP/7zip/Compress/LZMA_Alone/makefile.gcc44
-rwxr-xr-xCPP/7zip/Compress/Lzx/LzxDecoder.cpp12
-rwxr-xr-xCPP/7zip/Compress/Lzx/LzxDecoder.h8
-rwxr-xr-xCPP/7zip/Compress/PPMD/PPMD.dsp242
-rwxr-xr-xCPP/7zip/Compress/PPMD/PPMD.dsw29
-rwxr-xr-xCPP/7zip/Compress/PPMD/PPMDEncoder.cpp2
-rwxr-xr-xCPP/7zip/Compress/PPMD/makefile43
-rwxr-xr-xCPP/7zip/Compress/PPMD/resource.rc3
-rwxr-xr-xCPP/7zip/Compress/RangeCoder/RangeCoder.h7
-rwxr-xr-xCPP/7zip/Compress/RangeCoder/RangeCoderBit.cpp72
-rwxr-xr-xCPP/7zip/Compress/RangeCoder/RangeCoderBit.h19
-rwxr-xr-xCPP/7zip/Compress/RangeCoder/RangeCoderBitTree.h4
-rwxr-xr-xCPP/7zip/Compress/Rar/Rar29.dsp8
-rwxr-xr-xCPP/7zip/Compress/Rar/Rar2Decoder.cpp14
-rwxr-xr-xCPP/7zip/Compress/Rar/Rar2Decoder.h8
-rwxr-xr-xCPP/7zip/Compress/Rar/Rar3Decoder.cpp6
-rwxr-xr-xCPP/7zip/Compress/Rar/Rar3Vm.h46
-rwxr-xr-xCPP/7zip/Compress/Rar/makefile2
-rwxr-xr-xCPP/7zip/Crypto/7zAES/7zAES.cpp29
-rwxr-xr-xCPP/7zip/Crypto/AES/MyAES.cpp12
-rwxr-xr-xCPP/7zip/Crypto/AES/MyAES.h2
-rwxr-xr-xCPP/7zip/Crypto/Hash/Sha1.cpp5
-rwxr-xr-xCPP/7zip/Crypto/Hash/Sha256.h30
-rwxr-xr-xCPP/7zip/Crypto/RarAES/RarAES.cpp6
-rwxr-xr-xCPP/7zip/Crypto/RarAES/RarAES.h2
-rwxr-xr-xCPP/7zip/Crypto/WzAES/WzAES.cpp37
-rwxr-xr-xCPP/7zip/Crypto/WzAES/WzAES.h2
-rwxr-xr-xCPP/7zip/Crypto/Zip/ZipCipher.cpp11
-rwxr-xr-xCPP/7zip/ICoder.h1
-rwxr-xr-xCPP/7zip/MyVersion.h12
-rwxr-xr-xCPP/7zip/PropID.h1
-rwxr-xr-xCPP/7zip/UI/Agent/AgentOut.cpp7
-rwxr-xr-xCPP/7zip/UI/Agent/AgentProxy.cpp13
-rwxr-xr-xCPP/7zip/UI/Client7z/Client7z.cpp8
-rwxr-xr-xCPP/7zip/UI/Common/ArchiveExtractCallback.h2
-rwxr-xr-xCPP/7zip/UI/Common/DirItem.h13
-rwxr-xr-xCPP/7zip/UI/Common/LoadCodecs.cpp10
-rwxr-xr-xCPP/7zip/UI/Common/LoadCodecs.h8
-rwxr-xr-xCPP/7zip/UI/Common/OpenArchive.cpp25
-rwxr-xr-xCPP/7zip/UI/Common/SetProperties.cpp18
-rwxr-xr-xCPP/7zip/UI/Common/Update.cpp51
-rwxr-xr-xCPP/7zip/UI/Common/UpdatePair.cpp24
-rwxr-xr-xCPP/7zip/UI/Console/List.cpp11
-rwxr-xr-xCPP/7zip/UI/Console/Main.cpp4
-rwxr-xr-xCPP/7zip/UI/Console/MainAr.cpp6
-rwxr-xr-xCPP/7zip/UI/Console/UpdateCallbackConsole.cpp2
-rwxr-xr-xCPP/7zip/UI/Explorer/ContextMenu.cpp2
-rwxr-xr-xCPP/7zip/UI/Far/ExtractEngine.cpp4
-rwxr-xr-xCPP/7zip/UI/Far/Plugin.cpp15
-rwxr-xr-xCPP/7zip/UI/FileManager/App.cpp19
-rwxr-xr-xCPP/7zip/UI/FileManager/ExtractCallback.cpp4
-rwxr-xr-xCPP/7zip/UI/FileManager/FM.cpp34
-rwxr-xr-xCPP/7zip/UI/FileManager/Panel.cpp2
-rwxr-xr-xCPP/7zip/UI/FileManager/PanelItemOpen.cpp7
-rwxr-xr-xCPP/7zip/UI/FileManager/PanelListNotify.cpp95
-rwxr-xr-xCPP/7zip/UI/FileManager/ProgressDialog2.rc2
-rwxr-xr-xCPP/7zip/UI/GUI/CompressDialog.cpp19
-rwxr-xr-xCPP/Build.mak17
-rwxr-xr-xCPP/Common/CRC.cpp6
-rwxr-xr-xCPP/Common/ListFileUtils.cpp1
-rwxr-xr-xCPP/Common/StringConvert.cpp28
-rwxr-xr-xCPP/Common/StringConvert.h2
-rwxr-xr-xCPP/Common/Types.h50
-rwxr-xr-xCPP/Windows/PropVariantConversions.cpp5
-rwxr-xr-xCPP/Windows/Synchronization.h40
-rwxr-xr-xCPP/Windows/Thread.h6
-rwxr-xr-xDOC/7zC.txt86
-rwxr-xr-xDOC/7zFormat.txt21
-rwxr-xr-xDOC/7zip.nsi8
-rwxr-xr-xDOC/7zip.wxs6
-rwxr-xr-xDOC/Methods.txt16
-rwxr-xr-xDOC/history.txt646
-rwxr-xr-xDOC/lzma.txt577
-rwxr-xr-xDOC/readme.txt6
326 files changed, 10231 insertions, 14501 deletions
diff --git a/C/7zBuf.c b/C/7zBuf.c
new file mode 100755
index 00000000..14e7f4e2
--- /dev/null
+++ b/C/7zBuf.c
@@ -0,0 +1,36 @@
+/* 7zBuf.c -- Byte Buffer
+2008-03-28
+Igor Pavlov
+Public domain */
+
+#include "7zBuf.h"
+
+void Buf_Init(CBuf *p)
+{
+ p->data = 0;
+ p->size = 0;
+}
+
+int Buf_Create(CBuf *p, size_t size, ISzAlloc *alloc)
+{
+ p->size = 0;
+ if (size == 0)
+ {
+ p->data = 0;
+ return 1;
+ }
+ p->data = (Byte *)alloc->Alloc(alloc, size);
+ if (p->data != 0)
+ {
+ p->size = size;
+ return 1;
+ }
+ return 0;
+}
+
+void Buf_Free(CBuf *p, ISzAlloc *alloc)
+{
+ alloc->Free(alloc, p->data);
+ p->data = 0;
+ p->size = 0;
+}
diff --git a/C/7zBuf.h b/C/7zBuf.h
new file mode 100755
index 00000000..d827aa86
--- /dev/null
+++ b/C/7zBuf.h
@@ -0,0 +1,21 @@
+/* 7zBuf.h -- Byte Buffer
+2008-05-01
+Igor Pavlov
+Public domain */
+
+#ifndef __7Z_BUF_H
+#define __7Z_BUF_H
+
+#include "Types.h"
+
+typedef struct
+{
+ Byte *data;
+ size_t size;
+} CBuf;
+
+void Buf_Init(CBuf *p);
+int Buf_Create(CBuf *p, size_t size, ISzAlloc *alloc);
+void Buf_Free(CBuf *p, ISzAlloc *alloc);
+
+#endif
diff --git a/C/7zCrc.c b/C/7zCrc.c
index 1436b993..acc309a4 100755
--- a/C/7zCrc.c
+++ b/C/7zCrc.c
@@ -1,4 +1,7 @@
-/* 7zCrc.c */
+/* 7zCrc.c -- CRC32 calculation
+2008-03-13
+Igor Pavlov
+Public domain */
#include "7zCrc.h"
diff --git a/C/7zCrc.h b/C/7zCrc.h
index 6cb10161..00dc29ce 100755
--- a/C/7zCrc.h
+++ b/C/7zCrc.h
@@ -1,4 +1,7 @@
-/* 7zCrc.h */
+/* 7zCrc.h -- CRC32 calculation
+2008-03-13
+Igor Pavlov
+Public domain */
#ifndef __7Z_CRC_H
#define __7Z_CRC_H
diff --git a/C/7zCrcT8.c b/C/7zCrcT8.c
index 83aa95f7..cd80e262 100755
--- a/C/7zCrcT8.c
+++ b/C/7zCrcT8.c
@@ -1,4 +1,7 @@
-/* 7zCrcT8.c */
+/* 7zCrcT8.c -- CRC32 calculation with 8 tables
+2008-03-19
+Igor Pavlov
+Public domain */
#include "7zCrc.h"
diff --git a/C/Crypto/Aes.c b/C/Aes.c
index 205edbc8..6e2b7bf0 100755
--- a/C/Crypto/Aes.c
+++ b/C/Aes.c
@@ -1,10 +1,13 @@
-/* Aes.h */
+/* Aes.c -- AES encryption / decryption
+2008-03-26
+Igor Pavlov
+Public domain */
#include "Aes.h"
-#include "../CpuArch.h"
+#include "CpuArch.h"
-UInt32 T[256 * 4];
-Byte Sbox[256] = {
+static UInt32 T[256 * 4];
+static Byte Sbox[256] = {
0x63, 0x7c, 0x77, 0x7b, 0xf2, 0x6b, 0x6f, 0xc5, 0x30, 0x01, 0x67, 0x2b, 0xfe, 0xd7, 0xab, 0x76,
0xca, 0x82, 0xc9, 0x7d, 0xfa, 0x59, 0x47, 0xf0, 0xad, 0xd4, 0xa2, 0xaf, 0x9c, 0xa4, 0x72, 0xc0,
0xb7, 0xfd, 0x93, 0x26, 0x36, 0x3f, 0xf7, 0xcc, 0x34, 0xa5, 0xe5, 0xf1, 0x71, 0xd8, 0x31, 0x15,
@@ -22,10 +25,10 @@ Byte Sbox[256] = {
0xe1, 0xf8, 0x98, 0x11, 0x69, 0xd9, 0x8e, 0x94, 0x9b, 0x1e, 0x87, 0xe9, 0xce, 0x55, 0x28, 0xdf,
0x8c, 0xa1, 0x89, 0x0d, 0xbf, 0xe6, 0x42, 0x68, 0x41, 0x99, 0x2d, 0x0f, 0xb0, 0x54, 0xbb, 0x16};
-UInt32 D[256 * 4];
-Byte InvS[256];
+static UInt32 D[256 * 4];
+static Byte InvS[256];
-Byte Rcon[11] = { 0x00, 0x01, 0x02, 0x04, 0x08, 0x10, 0x20, 0x40, 0x80, 0x1b, 0x36 };
+static Byte Rcon[11] = { 0x00, 0x01, 0x02, 0x04, 0x08, 0x10, 0x20, 0x40, 0x80, 0x1b, 0x36 };
#define xtime(x) ((((x) << 1) ^ (((x) & 0x80) != 0 ? 0x1B : 0)) & 0xFF)
@@ -36,7 +39,7 @@ Byte Rcon[11] = { 0x00, 0x01, 0x02, 0x04, 0x08, 0x10, 0x20, 0x40, 0x80, 0x1b, 0x
#define gb2(x) (((x) >> (16)) & 0xFF)
#define gb3(x) (((x) >> (24)) & 0xFF)
-void MY_FAST_CALL AesGenTables(void)
+void AesGenTables(void)
{
unsigned i;
for (i = 0; i < 256; i++)
@@ -101,7 +104,7 @@ void MY_FAST_CALL AesGenTables(void)
#define FD(i, x) InvS[gb ## x(m[(i - x) & 3])]
#define FD4(i) dest[i] = Ui32(FD(i, 0), FD(i, 1), FD(i, 2), FD(i, 3)) ^ w[i];
-void MY_FAST_CALL AesSetKeyEncode(CAes *p, const Byte *key, unsigned keySize)
+void Aes_SetKeyEncode(CAes *p, const Byte *key, unsigned keySize)
{
unsigned i, wSize;
UInt32 *w;
@@ -126,11 +129,11 @@ void MY_FAST_CALL AesSetKeyEncode(CAes *p, const Byte *key, unsigned keySize)
}
}
-void MY_FAST_CALL AesSetKeyDecode(CAes *p, const Byte *key, unsigned keySize)
+void Aes_SetKeyDecode(CAes *p, const Byte *key, unsigned keySize)
{
unsigned i, num;
UInt32 *w;
- AesSetKeyEncode(p, key, keySize);
+ Aes_SetKeyEncode(p, key, keySize);
num = p->numRounds2 * 8 - 4;
w = p->rkey + 4;
for (i = 0; i < num; i++)
@@ -144,7 +147,7 @@ void MY_FAST_CALL AesSetKeyDecode(CAes *p, const Byte *key, unsigned keySize)
}
}
-void MY_FAST_CALL AesEncode32(const UInt32 *src, UInt32 *dest, const UInt32 *w, unsigned numRounds2)
+static void AesEncode32(UInt32 *dest, const UInt32 *src, const UInt32 *w, unsigned numRounds2)
{
UInt32 s[4];
UInt32 m[4];
@@ -165,7 +168,7 @@ void MY_FAST_CALL AesEncode32(const UInt32 *src, UInt32 *dest, const UInt32 *w,
FT4(0); FT4(1); FT4(2); FT4(3);
}
-void MY_FAST_CALL AesDecode32(const UInt32 *src, UInt32 *dest, const UInt32 *w, unsigned numRounds2)
+static void AesDecode32(UInt32 *dest, const UInt32 *src, const UInt32 *w, unsigned numRounds2)
{
UInt32 s[4];
UInt32 m[4];
@@ -185,26 +188,26 @@ void MY_FAST_CALL AesDecode32(const UInt32 *src, UInt32 *dest, const UInt32 *w,
FD4(0); FD4(1); FD4(2); FD4(3);
}
-#ifdef LITTLE_ENDIAN_UNALIGN
-#define GetUi32(p) (*(const UInt32 *)(p))
-#define SetUi32(p, d) *(UInt32 *)(p) = d;
-#else
-#define GetUi32(p) ((p)[0] | ((UInt32)(p)[1] << 8) | ((UInt32)(p)[2] << 16) | ((UInt32)(p)[3] << 24))
-#define SetUi32(p, d) { UInt32 x = (d); (p)[0] = (Byte)x; (p)[1] = (Byte)(x >> 8); \
- (p)[2] = (Byte)(x >> 16); (p)[3] = (Byte)(x >> 24); }
-#endif
+void Aes_Encode32(const CAes *p, UInt32 *dest, const UInt32 *src)
+{
+ AesEncode32(dest, src, p->rkey, p->numRounds2);
+}
+void Aes_Decode32(const CAes *p, UInt32 *dest, const UInt32 *src)
+{
+ AesDecode32(dest, src, p->rkey, p->numRounds2);
+}
-void MY_FAST_CALL AesCbcInit(CAesCbc *cbc, const Byte *iv)
+void AesCbc_Init(CAesCbc *p, const Byte *iv)
{
unsigned i;
for (i = 0; i < 4; i++)
- cbc->prev[i] = GetUi32(iv + i * 4);
+ p->prev[i] = GetUi32(iv + i * 4);
}
-UInt32 MY_FAST_CALL AesCbcEncode(CAesCbc *cbc, Byte *data, UInt32 size)
+SizeT AesCbc_Encode(CAesCbc *p, Byte *data, SizeT size)
{
- UInt32 i;
+ SizeT i;
if (size == 0)
return 0;
if (size < AES_BLOCK_SIZE)
@@ -212,24 +215,24 @@ UInt32 MY_FAST_CALL AesCbcEncode(CAesCbc *cbc, Byte *data, UInt32 size)
size -= AES_BLOCK_SIZE;
for (i = 0; i <= size; i += AES_BLOCK_SIZE, data += AES_BLOCK_SIZE)
{
- cbc->prev[0] ^= GetUi32(data);
- cbc->prev[1] ^= GetUi32(data + 4);
- cbc->prev[2] ^= GetUi32(data + 8);
- cbc->prev[3] ^= GetUi32(data + 12);
+ p->prev[0] ^= GetUi32(data);
+ p->prev[1] ^= GetUi32(data + 4);
+ p->prev[2] ^= GetUi32(data + 8);
+ p->prev[3] ^= GetUi32(data + 12);
- AesEncode32(cbc->prev, cbc->prev, cbc->aes.rkey, cbc->aes.numRounds2);
+ AesEncode32(p->prev, p->prev, p->aes.rkey, p->aes.numRounds2);
- SetUi32(data, cbc->prev[0]);
- SetUi32(data + 4, cbc->prev[1]);
- SetUi32(data + 8, cbc->prev[2]);
- SetUi32(data + 12, cbc->prev[3]);
+ SetUi32(data, p->prev[0]);
+ SetUi32(data + 4, p->prev[1]);
+ SetUi32(data + 8, p->prev[2]);
+ SetUi32(data + 12, p->prev[3]);
}
return i;
}
-UInt32 MY_FAST_CALL AesCbcDecode(CAesCbc *cbc, Byte *data, UInt32 size)
+SizeT AesCbc_Decode(CAesCbc *p, Byte *data, SizeT size)
{
- UInt32 i;
+ SizeT i;
UInt32 in[4], out[4];
if (size == 0)
return 0;
@@ -243,17 +246,17 @@ UInt32 MY_FAST_CALL AesCbcDecode(CAesCbc *cbc, Byte *data, UInt32 size)
in[2] = GetUi32(data + 8);
in[3] = GetUi32(data + 12);
- AesDecode32(in, out, cbc->aes.rkey, cbc->aes.numRounds2);
+ AesDecode32(out, in, p->aes.rkey, p->aes.numRounds2);
- SetUi32(data, cbc->prev[0] ^ out[0]);
- SetUi32(data + 4, cbc->prev[1] ^ out[1]);
- SetUi32(data + 8, cbc->prev[2] ^ out[2]);
- SetUi32(data + 12, cbc->prev[3] ^ out[3]);
+ SetUi32(data, p->prev[0] ^ out[0]);
+ SetUi32(data + 4, p->prev[1] ^ out[1]);
+ SetUi32(data + 8, p->prev[2] ^ out[2]);
+ SetUi32(data + 12, p->prev[3] ^ out[3]);
- cbc->prev[0] = in[0];
- cbc->prev[1] = in[1];
- cbc->prev[2] = in[2];
- cbc->prev[3] = in[3];
+ p->prev[0] = in[0];
+ p->prev[1] = in[1];
+ p->prev[2] = in[2];
+ p->prev[3] = in[3];
}
return i;
}
diff --git a/C/Aes.h b/C/Aes.h
new file mode 100755
index 00000000..d5779788
--- /dev/null
+++ b/C/Aes.h
@@ -0,0 +1,48 @@
+/* Aes.h -- AES encryption / decryption
+2008-03-26
+Igor Pavlov
+Public domain */
+
+#ifndef __AES_H
+#define __AES_H
+
+#include "Types.h"
+
+#define AES_BLOCK_SIZE 16
+
+typedef struct
+{
+ unsigned numRounds2; /* = numRounds / 2 */
+ UInt32 rkey[(14 + 1) * 4];
+} CAes;
+
+/* Call AesGenTables one time before other AES functions */
+void AesGenTables(void);
+
+/* keySize = 16 or 24 or 32 (bytes) */
+void Aes_SetKeyEncode(CAes *p, const Byte *key, unsigned keySize);
+void Aes_SetKeyDecode(CAes *p, const Byte *key, unsigned keySize);
+
+/* Aes_Encode32 and Aes_Decode32 functions work with little-endian words.
+ src and dest are pointers to 4 UInt32 words.
+ arc and dest can point to same block */
+void Aes_Encode32(const CAes *p, UInt32 *dest, const UInt32 *src);
+void Aes_Decode32(const CAes *p, UInt32 *dest, const UInt32 *src);
+
+typedef struct
+{
+ UInt32 prev[4];
+ CAes aes;
+} CAesCbc;
+
+void AesCbc_Init(CAesCbc *p, const Byte *iv); /* iv size is AES_BLOCK_SIZE */
+
+/* AesCbc_Encode and AesCbc_Decode:
+ if (res <= size): Filter have converted res bytes
+ if (res > size): Filter have not converted anything. And it needs at
+ least res = AES_BLOCK_SIZE bytes to convert one block */
+
+SizeT AesCbc_Encode(CAesCbc *p, Byte *data, SizeT size);
+SizeT AesCbc_Decode(CAesCbc *p, Byte *data, SizeT size);
+
+#endif
diff --git a/C/Alloc.c b/C/Alloc.c
index 7b5af420..c8418047 100755
--- a/C/Alloc.c
+++ b/C/Alloc.c
@@ -1,4 +1,7 @@
-/* Alloc.c */
+/* Alloc.c -- Memory allocation functions
+2008-03-13
+Igor Pavlov
+Public domain */
#ifdef _WIN32
#include <windows.h>
diff --git a/C/Alloc.h b/C/Alloc.h
index d748cb18..ff0669ca 100755
--- a/C/Alloc.h
+++ b/C/Alloc.h
@@ -1,4 +1,7 @@
-/* Alloc.h */
+/* Alloc.h -- Memory allocation functions
+2008-03-13
+Igor Pavlov
+Public domain */
#ifndef __COMMON_ALLOC_H
#define __COMMON_ALLOC_H
diff --git a/C/Archive/7z/7z_C.dsp b/C/Archive/7z/7z.dsp
index 9a040ad1..a0246af9 100755
--- a/C/Archive/7z/7z_C.dsp
+++ b/C/Archive/7z/7z.dsp
@@ -1,24 +1,24 @@
-# Microsoft Developer Studio Project File - Name="7z_C" - Package Owner=<4>
+# Microsoft Developer Studio Project File - Name="7z" - Package Owner=<4>
# Microsoft Developer Studio Generated Build File, Format Version 6.00
# ** DO NOT EDIT **
# TARGTYPE "Win32 (x86) Console Application" 0x0103
-CFG=7z_C - Win32 Debug
+CFG=7z - Win32 Debug
!MESSAGE This is not a valid makefile. To build this project using NMAKE,
!MESSAGE use the Export Makefile command and run
!MESSAGE
-!MESSAGE NMAKE /f "7z_C.mak".
+!MESSAGE NMAKE /f "7z.mak".
!MESSAGE
!MESSAGE You can specify a configuration when running NMAKE
!MESSAGE by defining the macro CFG on the command line. For example:
!MESSAGE
-!MESSAGE NMAKE /f "7z_C.mak" CFG="7z_C - Win32 Debug"
+!MESSAGE NMAKE /f "7z.mak" CFG="7z - Win32 Debug"
!MESSAGE
!MESSAGE Possible choices for configuration are:
!MESSAGE
-!MESSAGE "7z_C - Win32 Release" (based on "Win32 (x86) Console Application")
-!MESSAGE "7z_C - Win32 Debug" (based on "Win32 (x86) Console Application")
+!MESSAGE "7z - Win32 Release" (based on "Win32 (x86) Console Application")
+!MESSAGE "7z - Win32 Debug" (based on "Win32 (x86) Console Application")
!MESSAGE
# Begin Project
@@ -28,7 +28,7 @@ CFG=7z_C - Win32 Debug
CPP=cl.exe
RSC=rc.exe
-!IF "$(CFG)" == "7z_C - Win32 Release"
+!IF "$(CFG)" == "7z - Win32 Release"
# PROP BASE Use_MFC 0
# PROP BASE Use_Debug_Libraries 0
@@ -42,7 +42,7 @@ RSC=rc.exe
# PROP Ignore_Export_Lib 0
# PROP Target_Dir ""
# ADD BASE CPP /nologo /W3 /GX /O2 /D "WIN32" /D "NDEBUG" /D "_CONSOLE" /D "_MBCS" /YX /FD /c
-# ADD CPP /nologo /MD /W4 /GX /O2 /D "NDEBUG" /D "WIN32" /D "_CONSOLE" /D "_MBCS" /D "_LZMA_PROB32" /D "_LZMA_IN_CB" /YX /FD /c
+# ADD CPP /nologo /MD /W3 /GX /O2 /D "NDEBUG" /D "WIN32" /D "_CONSOLE" /D "_MBCS" /YX /FD /c
# ADD BASE RSC /l 0x419 /d "NDEBUG"
# ADD RSC /l 0x419 /d "NDEBUG"
BSC32=bscmake.exe
@@ -53,7 +53,7 @@ LINK32=link.exe
# ADD LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /machine:I386 /out:"Release/7zDec.exe" /opt:NOWIN98
# SUBTRACT LINK32 /pdb:none
-!ELSEIF "$(CFG)" == "7z_C - Win32 Debug"
+!ELSEIF "$(CFG)" == "7z - Win32 Debug"
# PROP BASE Use_MFC 0
# PROP BASE Use_Debug_Libraries 1
@@ -67,7 +67,7 @@ LINK32=link.exe
# PROP Ignore_Export_Lib 0
# PROP Target_Dir ""
# ADD BASE CPP /nologo /W3 /Gm /GX /ZI /Od /D "WIN32" /D "_DEBUG" /D "_CONSOLE" /D "_MBCS" /YX /FD /GZ /c
-# ADD CPP /nologo /W4 /Gm /GX /ZI /Od /D "_DEBUG" /D "WIN32" /D "_CONSOLE" /D "_MBCS" /D "_LZMA_PROB32" /D "_LZMA_IN_CB" /YX /FD /GZ /c
+# ADD CPP /nologo /W4 /Gm /GX /ZI /Od /D "_DEBUG" /D "WIN32" /D "_CONSOLE" /D "_MBCS" /YX /FD /GZ /c
# ADD BASE RSC /l 0x419 /d "_DEBUG"
# ADD RSC /l 0x419 /d "_DEBUG"
BSC32=bscmake.exe
@@ -81,29 +81,21 @@ LINK32=link.exe
# Begin Target
-# Name "7z_C - Win32 Release"
-# Name "7z_C - Win32 Debug"
-# Begin Group "LZMA"
+# Name "7z - Win32 Release"
+# Name "7z - Win32 Debug"
+# Begin Group "Common"
# PROP Default_Filter ""
# Begin Source File
-SOURCE=..\..\Compress\Lzma\LzmaDecode.c
+SOURCE=..\..\7zBuf.c
# End Source File
# Begin Source File
-SOURCE=..\..\Compress\Lzma\LzmaDecode.h
+SOURCE=..\..\7zBuf.h
# End Source File
# Begin Source File
-SOURCE=..\..\Compress\Lzma\LzmaTypes.h
-# End Source File
-# End Group
-# Begin Group "Common"
-
-# PROP Default_Filter ""
-# Begin Source File
-
SOURCE=..\..\7zCrc.c
# End Source File
# Begin Source File
@@ -112,31 +104,31 @@ SOURCE=..\..\7zCrc.h
# End Source File
# Begin Source File
-SOURCE=..\..\Types.h
+SOURCE=..\..\Bcj2.c
# End Source File
-# End Group
-# Begin Group "Branch"
+# Begin Source File
-# PROP Default_Filter ""
+SOURCE=..\..\Bcj2.h
+# End Source File
# Begin Source File
-SOURCE=..\..\Compress\Branch\BranchTypes.h
+SOURCE=..\..\Bra.h
# End Source File
# Begin Source File
-SOURCE=..\..\Compress\Branch\BranchX86.c
+SOURCE=..\..\Bra86.c
# End Source File
# Begin Source File
-SOURCE=..\..\Compress\Branch\BranchX86.h
+SOURCE=..\..\LzmaDec.c
# End Source File
# Begin Source File
-SOURCE=..\..\Compress\Branch\BranchX86_2.c
+SOURCE=..\..\LzmaDec.h
# End Source File
# Begin Source File
-SOURCE=..\..\Compress\Branch\BranchX86_2.h
+SOURCE=..\..\Types.h
# End Source File
# End Group
# Begin Source File
@@ -149,14 +141,6 @@ SOURCE=.\7zAlloc.h
# End Source File
# Begin Source File
-SOURCE=.\7zBuffer.c
-# End Source File
-# Begin Source File
-
-SOURCE=.\7zBuffer.h
-# End Source File
-# Begin Source File
-
SOURCE=.\7zDecode.c
# End Source File
# Begin Source File
@@ -199,13 +183,5 @@ SOURCE=.\7zItem.h
SOURCE=.\7zMain.c
# End Source File
-# Begin Source File
-
-SOURCE=.\7zMethodID.c
-# End Source File
-# Begin Source File
-
-SOURCE=.\7zMethodID.h
-# End Source File
# End Target
# End Project
diff --git a/CPP/7zip/Archive/7z/7z.dsw b/C/Archive/7z/7z.dsw
index 702a86c7..848d13cb 100755
--- a/CPP/7zip/Archive/7z/7z.dsw
+++ b/C/Archive/7z/7z.dsw
@@ -3,7 +3,7 @@ Microsoft Developer Studio Workspace File, Format Version 6.00
###############################################################################
-Project: "7z"=".\7z.dsp" - Package Owner=<4>
+Project: "7z"=.\7z.dsp - Package Owner=<4>
Package=<5>
{{{
diff --git a/C/Archive/7z/7zAlloc.c b/C/Archive/7z/7zAlloc.c
index 21bb30c7..1b48a258 100755
--- a/C/Archive/7z/7zAlloc.c
+++ b/C/Archive/7z/7zAlloc.c
@@ -1,4 +1,7 @@
-/* 7zAlloc.c */
+/* 7zAlloc.c -- Allocation functions
+2008-03-28
+Igor Pavlov
+Public domain */
#include <stdlib.h>
#include "7zAlloc.h"
@@ -11,13 +14,16 @@
#ifdef _WIN32
#include <windows.h>
#endif
+
#include <stdio.h>
int g_allocCount = 0;
int g_allocCountTemp = 0;
+
#endif
-void *SzAlloc(size_t size)
+void *SzAlloc(void *p, size_t size)
{
+ p = p;
if (size == 0)
return 0;
#ifdef _SZ_ALLOC_DEBUG
@@ -27,8 +33,9 @@ void *SzAlloc(size_t size)
return malloc(size);
}
-void SzFree(void *address)
+void SzFree(void *p, void *address)
{
+ p = p;
#ifdef _SZ_ALLOC_DEBUG
if (address != 0)
{
@@ -39,8 +46,9 @@ void SzFree(void *address)
free(address);
}
-void *SzAllocTemp(size_t size)
+void *SzAllocTemp(void *p, size_t size)
{
+ p = p;
if (size == 0)
return 0;
#ifdef _SZ_ALLOC_DEBUG
@@ -53,8 +61,9 @@ void *SzAllocTemp(size_t size)
return malloc(size);
}
-void SzFreeTemp(void *address)
+void SzFreeTemp(void *p, void *address)
{
+ p = p;
#ifdef _SZ_ALLOC_DEBUG
if (address != 0)
{
diff --git a/C/Archive/7z/7zAlloc.h b/C/Archive/7z/7zAlloc.h
index 4ca4170c..714ecf15 100755
--- a/C/Archive/7z/7zAlloc.h
+++ b/C/Archive/7z/7zAlloc.h
@@ -1,20 +1,17 @@
-/* 7zAlloc.h */
+/* 7zAlloc.h -- Allocation functions
+2008-03-28
+Igor Pavlov
+Public domain */
#ifndef __7Z_ALLOC_H
#define __7Z_ALLOC_H
#include <stddef.h>
-typedef struct _ISzAlloc
-{
- void *(*Alloc)(size_t size);
- void (*Free)(void *address); /* address can be 0 */
-} ISzAlloc;
+void *SzAlloc(void *p, size_t size);
+void SzFree(void *p, void *address);
-void *SzAlloc(size_t size);
-void SzFree(void *address);
-
-void *SzAllocTemp(size_t size);
-void SzFreeTemp(void *address);
+void *SzAllocTemp(void *p, size_t size);
+void SzFreeTemp(void *p, void *address);
#endif
diff --git a/C/Archive/7z/7zBuffer.c b/C/Archive/7z/7zBuffer.c
deleted file mode 100755
index 3c4b71e8..00000000
--- a/C/Archive/7z/7zBuffer.c
+++ /dev/null
@@ -1,29 +0,0 @@
-/* 7zBuffer.c */
-
-#include "7zBuffer.h"
-#include "7zAlloc.h"
-
-void SzByteBufferInit(CSzByteBuffer *buffer)
-{
- buffer->Capacity = 0;
- buffer->Items = 0;
-}
-
-int SzByteBufferCreate(CSzByteBuffer *buffer, size_t newCapacity, void * (*allocFunc)(size_t size))
-{
- buffer->Capacity = newCapacity;
- if (newCapacity == 0)
- {
- buffer->Items = 0;
- return 1;
- }
- buffer->Items = (Byte *)allocFunc(newCapacity);
- return (buffer->Items != 0);
-}
-
-void SzByteBufferFree(CSzByteBuffer *buffer, void (*freeFunc)(void *))
-{
- freeFunc(buffer->Items);
- buffer->Items = 0;
- buffer->Capacity = 0;
-}
diff --git a/C/Archive/7z/7zBuffer.h b/C/Archive/7z/7zBuffer.h
deleted file mode 100755
index 05c6d748..00000000
--- a/C/Archive/7z/7zBuffer.h
+++ /dev/null
@@ -1,19 +0,0 @@
-/* 7zBuffer.h */
-
-#ifndef __7Z_BUFFER_H
-#define __7Z_BUFFER_H
-
-#include <stddef.h>
-#include "../../Types.h"
-
-typedef struct _CSzByteBuffer
-{
- size_t Capacity;
- Byte *Items;
-}CSzByteBuffer;
-
-void SzByteBufferInit(CSzByteBuffer *buffer);
-int SzByteBufferCreate(CSzByteBuffer *buffer, size_t newCapacity, void * (*allocFunc)(size_t size));
-void SzByteBufferFree(CSzByteBuffer *buffer, void (*freeFunc)(void *));
-
-#endif
diff --git a/C/Archive/7z/7zDecode.c b/C/Archive/7z/7zDecode.c
index aea893da..02a3c008 100755
--- a/C/Archive/7z/7zDecode.c
+++ b/C/Archive/7z/7zDecode.c
@@ -1,153 +1,114 @@
-/* 7zDecode.c */
+/* 7zDecode.c Decoding from 7z folder
+2008-04-09
+Igor Pavlov
+Copyright (c) 1999-2008 Igor Pavlov
+Read 7zDecode.h for license options */
-#include <memory.h>
+#include <string.h>
#include "7zDecode.h"
-#ifdef _SZ_ONE_DIRECTORY
-#include "LzmaDecode.h"
-#else
-#include "../../Compress/Lzma/LzmaDecode.h"
-#include "../../Compress/Branch/BranchX86.h"
-#include "../../Compress/Branch/BranchX86_2.h"
-#endif
+#include "../../LzmaDec.h"
+#include "../../Bra.h"
+#include "../../Bcj2.h"
#define k_Copy 0
#define k_LZMA 0x30101
#define k_BCJ 0x03030103
#define k_BCJ2 0x0303011B
+/*
#ifdef _LZMA_IN_CB
+*/
-typedef struct _CLzmaInCallbackImp
+static SRes SzDecodeLzma(CSzCoderInfo *coder, CFileSize inSize, ISzInStream *inStream,
+ Byte *outBuffer, size_t outSize, ISzAlloc *allocMain)
{
- ILzmaInCallback InCallback;
- ISzInStream *InStream;
- CFileSize Size;
-} CLzmaInCallbackImp;
+ CLzmaDec state;
+ int res = SZ_OK;
+ size_t _inSize;
+ Byte *inBuf = NULL;
-int LzmaReadImp(void *object, const unsigned char **buffer, SizeT *size)
-{
- CLzmaInCallbackImp *cb = (CLzmaInCallbackImp *)object;
- size_t processedSize;
- SZ_RESULT res;
- size_t curSize = (1 << 20);
- if (curSize > cb->Size)
- curSize = (size_t)cb->Size;
- *size = 0;
- res = cb->InStream->Read((void *)cb->InStream, (void **)buffer, curSize, &processedSize);
- *size = (SizeT)processedSize;
- if (processedSize > curSize)
- return (int)SZE_FAIL;
- cb->Size -= processedSize;
- if (res == SZ_OK)
- return 0;
- return (int)res;
-}
+ LzmaDec_Construct(&state);
+ RINOK(LzmaDec_AllocateProbs(&state, coder->Props.data, (unsigned)coder->Props.size, allocMain));
+ state.dic = outBuffer;
+ state.dicBufSize = outSize;
+ LzmaDec_Init(&state);
-#endif
+ _inSize = 0;
-SZ_RESULT SzDecodeLzma(CCoderInfo *coder, CFileSize inSize,
- #ifdef _LZMA_IN_CB
- ISzInStream *inStream,
- #else
- const Byte *inBuffer,
- #endif
- Byte *outBuffer, size_t outSize, ISzAlloc *allocMain)
-{
- #ifdef _LZMA_IN_CB
- CLzmaInCallbackImp lzmaCallback;
- #else
- SizeT inProcessed;
- #endif
-
- CLzmaDecoderState state; /* it's about 24-80 bytes structure, if int is 32-bit */
- int result;
- SizeT outSizeProcessedLoc;
-
- #ifdef _LZMA_IN_CB
- lzmaCallback.Size = inSize;
- lzmaCallback.InStream = inStream;
- lzmaCallback.InCallback.Read = LzmaReadImp;
- #endif
-
- if (LzmaDecodeProperties(&state.Properties, coder->Properties.Items,
- (unsigned)coder->Properties.Capacity) != LZMA_RESULT_OK)
- return SZE_FAIL;
-
- state.Probs = (CProb *)allocMain->Alloc(LzmaGetNumProbs(&state.Properties) * sizeof(CProb));
- if (state.Probs == 0)
- return SZE_OUTOFMEMORY;
-
- #ifdef _LZMA_OUT_READ
- if (state.Properties.DictionarySize == 0)
- state.Dictionary = 0;
- else
+ for (;;)
{
- state.Dictionary = (unsigned char *)allocMain->Alloc(state.Properties.DictionarySize);
- if (state.Dictionary == 0)
+ if (_inSize == 0)
{
- allocMain->Free(state.Probs);
- return SZE_OUTOFMEMORY;
+ _inSize = (1 << 18);
+ if (_inSize > inSize)
+ _inSize = (size_t)(inSize);
+ res = inStream->Read((void *)inStream, (void **)&inBuf, &_inSize);
+ if (res != SZ_OK)
+ break;
+ inSize -= _inSize;
}
- }
- LzmaDecoderInit(&state);
- #endif
-
- result = LzmaDecode(&state,
- #ifdef _LZMA_IN_CB
- &lzmaCallback.InCallback,
- #else
- inBuffer, (SizeT)inSize, &inProcessed,
- #endif
- outBuffer, (SizeT)outSize, &outSizeProcessedLoc);
- allocMain->Free(state.Probs);
- #ifdef _LZMA_OUT_READ
- allocMain->Free(state.Dictionary);
- #endif
- if (result == LZMA_RESULT_DATA_ERROR)
- return SZE_DATA_ERROR;
- if (result != LZMA_RESULT_OK)
- return SZE_FAIL;
- return (outSizeProcessedLoc == outSize) ? SZ_OK : SZE_DATA_ERROR;
+
+ {
+ SizeT inProcessed = _inSize, dicPos = state.dicPos;
+ ELzmaStatus status;
+ res = LzmaDec_DecodeToDic(&state, outSize, inBuf, &inProcessed, LZMA_FINISH_END, &status);
+ _inSize -= inProcessed;
+ inBuf = (Byte *)inBuf + inProcessed;
+ if (res != SZ_OK)
+ break;
+ if (state.dicPos == state.dicBufSize || (inProcessed == 0 && dicPos == state.dicPos))
+ {
+ if (state.dicBufSize != outSize || _inSize != 0 ||
+ (status != LZMA_STATUS_FINISHED_WITH_MARK &&
+ status != LZMA_STATUS_MAYBE_FINISHED_WITHOUT_MARK))
+ res = SZ_ERROR_DATA;
+ break;
+ }
+ }
+ }
+
+ LzmaDec_FreeProbs(&state, allocMain);
+
+ return res;
}
-#ifdef _LZMA_IN_CB
-SZ_RESULT SzDecodeCopy(CFileSize inSize, ISzInStream *inStream, Byte *outBuffer)
+static SRes SzDecodeCopy(CFileSize inSize, ISzInStream *inStream, Byte *outBuffer)
{
while (inSize > 0)
{
void *inBuffer;
- size_t processedSize, curSize = (1 << 18);
+ size_t curSize = (1 << 18);
if (curSize > inSize)
curSize = (size_t)(inSize);
- RINOK(inStream->Read((void *)inStream, (void **)&inBuffer, curSize, &processedSize));
- if (processedSize == 0)
- return SZE_DATA_ERROR;
- if (processedSize > curSize)
- return SZE_FAIL;
- memcpy(outBuffer, inBuffer, processedSize);
- outBuffer += processedSize;
- inSize -= processedSize;
+ RINOK(inStream->Read((void *)inStream, (void **)&inBuffer, &curSize));
+ if (curSize == 0)
+ return SZ_ERROR_INPUT_EOF;
+ memcpy(outBuffer, inBuffer, curSize);
+ outBuffer += curSize;
+ inSize -= curSize;
}
return SZ_OK;
}
+/*
#endif
+*/
#define IS_UNSUPPORTED_METHOD(m) ((m) != k_Copy && (m) != k_LZMA)
#define IS_UNSUPPORTED_CODER(c) (IS_UNSUPPORTED_METHOD(c.MethodID) || c.NumInStreams != 1 || c.NumOutStreams != 1)
#define IS_NO_BCJ(c) (c.MethodID != k_BCJ || c.NumInStreams != 1 || c.NumOutStreams != 1)
#define IS_NO_BCJ2(c) (c.MethodID != k_BCJ2 || c.NumInStreams != 4 || c.NumOutStreams != 1)
-SZ_RESULT CheckSupportedFolder(const CFolder *f)
+SRes CheckSupportedFolder(const CSzFolder *f)
{
if (f->NumCoders < 1 || f->NumCoders > 4)
- return SZE_NOTIMPL;
+ return SZ_ERROR_UNSUPPORTED;
if (IS_UNSUPPORTED_CODER(f->Coders[0]))
- return SZE_NOTIMPL;
+ return SZ_ERROR_UNSUPPORTED;
if (f->NumCoders == 1)
{
if (f->NumPackStreams != 1 || f->PackStreams[0] != 0 || f->NumBindPairs != 0)
- return SZE_NOTIMPL;
+ return SZ_ERROR_UNSUPPORTED;
return SZ_OK;
}
if (f->NumCoders == 2)
@@ -156,7 +117,7 @@ SZ_RESULT CheckSupportedFolder(const CFolder *f)
f->NumPackStreams != 1 || f->PackStreams[0] != 0 ||
f->NumBindPairs != 1 ||
f->BindPairs[0].InIndex != 1 || f->BindPairs[0].OutIndex != 0)
- return SZE_NOTIMPL;
+ return SZ_ERROR_UNSUPPORTED;
return SZ_OK;
}
if (f->NumCoders == 4)
@@ -164,7 +125,7 @@ SZ_RESULT CheckSupportedFolder(const CFolder *f)
if (IS_UNSUPPORTED_CODER(f->Coders[1]) ||
IS_UNSUPPORTED_CODER(f->Coders[2]) ||
IS_NO_BCJ2(f->Coders[3]))
- return SZE_NOTIMPL;
+ return SZ_ERROR_UNSUPPORTED;
if (f->NumPackStreams != 4 ||
f->PackStreams[0] != 2 ||
f->PackStreams[1] != 6 ||
@@ -174,10 +135,10 @@ SZ_RESULT CheckSupportedFolder(const CFolder *f)
f->BindPairs[0].InIndex != 5 || f->BindPairs[0].OutIndex != 0 ||
f->BindPairs[1].InIndex != 4 || f->BindPairs[1].OutIndex != 1 ||
f->BindPairs[2].InIndex != 3 || f->BindPairs[2].OutIndex != 2)
- return SZE_NOTIMPL;
+ return SZ_ERROR_UNSUPPORTED;
return SZ_OK;
}
- return SZE_NOTIMPL;
+ return SZ_ERROR_UNSUPPORTED;
}
CFileSize GetSum(const CFileSize *values, UInt32 index)
@@ -189,12 +150,16 @@ CFileSize GetSum(const CFileSize *values, UInt32 index)
return sum;
}
-SZ_RESULT SzDecode2(const CFileSize *packSizes, const CFolder *folder,
+SRes SzDecode2(const CFileSize *packSizes, const CSzFolder *folder,
+ /*
#ifdef _LZMA_IN_CB
+ */
ISzInStream *inStream, CFileSize startPos,
+ /*
#else
const Byte *inBuffer,
#endif
+ */
Byte *outBuffer, size_t outSize, ISzAlloc *allocMain,
Byte *tempBuf[])
{
@@ -207,7 +172,7 @@ SZ_RESULT SzDecode2(const CFileSize *packSizes, const CFolder *folder,
for (ci = 0; ci < folder->NumCoders; ci++)
{
- CCoderInfo *coder = &folder->Coders[ci];
+ CSzCoderInfo *coder = &folder->Coders[ci];
if (coder->MethodID == k_Copy || coder->MethodID == k_LZMA)
{
@@ -226,57 +191,74 @@ SZ_RESULT SzDecode2(const CFileSize *packSizes, const CFolder *folder,
Byte *temp;
outSizeCur = (size_t)unpackSize;
if (outSizeCur != unpackSize)
- return SZE_OUTOFMEMORY;
- temp = (Byte *)allocMain->Alloc(outSizeCur);
+ return SZ_ERROR_MEM;
+ temp = (Byte *)IAlloc_Alloc(allocMain, outSizeCur);
if (temp == 0 && outSizeCur != 0)
- return SZE_OUTOFMEMORY;
+ return SZ_ERROR_MEM;
outBufCur = tempBuf[1 - ci] = temp;
tempSizes[1 - ci] = outSizeCur;
}
else if (ci == 2)
{
- if (unpackSize > outSize)
- return SZE_OUTOFMEMORY;
+ if (unpackSize > outSize) // check it
+ return SZ_ERROR_PARAM; // check it
tempBuf3 = outBufCur = outBuffer + (outSize - (size_t)unpackSize);
tempSize3 = outSizeCur = (size_t)unpackSize;
}
else
- return SZE_NOTIMPL;
+ return SZ_ERROR_UNSUPPORTED;
}
offset = GetSum(packSizes, si);
inSize = packSizes[si];
+ /*
#ifdef _LZMA_IN_CB
- RINOK(inStream->Seek(inStream, startPos + offset));
+ */
+ RINOK(inStream->Seek(inStream, startPos + offset, SZ_SEEK_SET));
+ /*
#endif
+ */
if (coder->MethodID == k_Copy)
{
- if (inSize != outSizeCur)
- return SZE_DATA_ERROR;
+ if (inSize != outSizeCur) // check it
+ return SZ_ERROR_DATA;
+ /*
#ifdef _LZMA_IN_CB
+ */
RINOK(SzDecodeCopy(inSize, inStream, outBufCur));
+ /*
#else
memcpy(outBufCur, inBuffer + (size_t)offset, (size_t)inSize);
#endif
+ */
}
else
{
- SZ_RESULT res = SzDecodeLzma(coder, inSize,
- #ifdef _LZMA_IN_CB
+ /*
+ #ifdef _LZMA_IN_CB
+ */
+ SRes res = SzDecodeLzma(coder, inSize,
inStream,
- #else
- inBuffer + (size_t)offset,
- #endif
outBufCur, outSizeCur, allocMain);
- RINOK(res)
+ /*
+ #else
+ SizeT lzmaOutSizeT = outSizeCur;
+ SizeT lzmaInSizeT = (SizeT)inSize;
+ SRes res = LzmaDecode(outBufCur, &lzmaOutSizeT,
+ inBuffer + (size_t)offset, &lzmaInSizeT,
+ coder->Props.Items, (unsigned)coder->Props.size, LZMA_FINISH_BYTE, allocMain);
+ #endif
+ */
+
+ RINOK(res);
}
}
else if (coder->MethodID == k_BCJ)
{
UInt32 state;
if (ci != 1)
- return SZE_NOTIMPL;
+ return SZ_ERROR_UNSUPPORTED;
x86_Convert_Init(state);
x86_Convert(outBuffer, outSize, 0, &state, 0);
}
@@ -284,58 +266,74 @@ SZ_RESULT SzDecode2(const CFileSize *packSizes, const CFolder *folder,
{
CFileSize offset = GetSum(packSizes, 1);
CFileSize s3Size = packSizes[1];
- SZ_RESULT res;
+ SRes res;
if (ci != 3)
- return SZE_NOTIMPL;
+ return SZ_ERROR_UNSUPPORTED;
+ /*
#ifdef _LZMA_IN_CB
- RINOK(inStream->Seek(inStream, startPos + offset));
+ */
+ RINOK(inStream->Seek(inStream, startPos + offset, SZ_SEEK_SET));
tempSizes[2] = (size_t)s3Size;
if (tempSizes[2] != s3Size)
- return SZE_OUTOFMEMORY;
- tempBuf[2] = (Byte *)allocMain->Alloc(tempSizes[2]);
+ return SZ_ERROR_MEM;
+ tempBuf[2] = (Byte *)IAlloc_Alloc(allocMain, tempSizes[2]);
if (tempBuf[2] == 0 && tempSizes[2] != 0)
- return SZE_OUTOFMEMORY;
+ return SZ_ERROR_MEM;
res = SzDecodeCopy(s3Size, inStream, tempBuf[2]);
RINOK(res)
+ /*
#endif
+ */
- res = x86_2_Decode(
+ res = Bcj2_Decode(
tempBuf3, tempSize3,
tempBuf[0], tempSizes[0],
tempBuf[1], tempSizes[1],
+ /*
#ifdef _LZMA_IN_CB
+ */
tempBuf[2], tempSizes[2],
+ /*
#else
inBuffer + (size_t)offset, (size_t)s3Size,
#endif
+ */
outBuffer, outSize);
RINOK(res)
}
else
- return SZE_NOTIMPL;
+ return SZ_ERROR_UNSUPPORTED;
}
return SZ_OK;
}
-SZ_RESULT SzDecode(const CFileSize *packSizes, const CFolder *folder,
+SRes SzDecode(const CFileSize *packSizes, const CSzFolder *folder,
+ /*
#ifdef _LZMA_IN_CB
+ */
ISzInStream *inStream, CFileSize startPos,
+ /*
#else
const Byte *inBuffer,
#endif
+ */
Byte *outBuffer, size_t outSize, ISzAlloc *allocMain)
{
Byte *tempBuf[3] = { 0, 0, 0};
int i;
- SZ_RESULT res = SzDecode2(packSizes, folder,
+ SRes res = SzDecode2(packSizes, folder,
+ /*
#ifdef _LZMA_IN_CB
+ */
inStream, startPos,
+ /*
#else
inBuffer,
#endif
+ */
outBuffer, outSize, allocMain, tempBuf);
for (i = 0; i < 3; i++)
- allocMain->Free(tempBuf[i]);
+ IAlloc_Free(allocMain, tempBuf[i]);
return res;
}
diff --git a/C/Archive/7z/7zDecode.h b/C/Archive/7z/7zDecode.h
index 175896ef..5b0996d7 100755
--- a/C/Archive/7z/7zDecode.h
+++ b/C/Archive/7z/7zDecode.h
@@ -1,20 +1,26 @@
-/* 7zDecode.h */
+/* 7zDecode.h -- Decoding from 7z folder
+2008-04-09
+Igor Pavlov
+Copyright (c) 1999-2008 Igor Pavlov
+Read 7zItem.h for license options */
#ifndef __7Z_DECODE_H
#define __7Z_DECODE_H
#include "7zItem.h"
-#include "7zAlloc.h"
-#ifdef _LZMA_IN_CB
+
#include "7zIn.h"
-#endif
-SZ_RESULT SzDecode(const CFileSize *packSizes, const CFolder *folder,
+SRes SzDecode(const CFileSize *packSizes, const CSzFolder *folder,
+ /*
#ifdef _LZMA_IN_CB
+ */
ISzInStream *stream, CFileSize startPos,
+ /*
#else
const Byte *inBuffer,
#endif
+ */
Byte *outBuffer, size_t outSize, ISzAlloc *allocMain);
#endif
diff --git a/C/Archive/7z/7zExtract.c b/C/Archive/7z/7zExtract.c
index 1760a3ce..40b592aa 100755
--- a/C/Archive/7z/7zExtract.c
+++ b/C/Archive/7z/7zExtract.c
@@ -1,12 +1,16 @@
-/* 7zExtract.c */
+/* 7zExtract.c -- Extracting from 7z archive
+2008-04-09
+Igor Pavlov
+Copyright (c) 1999-2008 Igor Pavlov
+Read 7zExtract.h for license options */
#include "7zExtract.h"
#include "7zDecode.h"
#include "../../7zCrc.h"
-SZ_RESULT SzExtract(
+SRes SzAr_Extract(
+ const CSzArEx *p,
ISzInStream *inStream,
- CArchiveDatabaseEx *db,
UInt32 fileIndex,
UInt32 *blockIndex,
Byte **outBuffer,
@@ -16,13 +20,13 @@ SZ_RESULT SzExtract(
ISzAlloc *allocMain,
ISzAlloc *allocTemp)
{
- UInt32 folderIndex = db->FileIndexToFolderIndexMap[fileIndex];
- SZ_RESULT res = SZ_OK;
+ UInt32 folderIndex = p->FileIndexToFolderIndexMap[fileIndex];
+ SRes res = SZ_OK;
*offset = 0;
*outSizeProcessed = 0;
if (folderIndex == (UInt32)-1)
{
- allocMain->Free(*outBuffer);
+ IAlloc_Free(allocMain, *outBuffer);
*blockIndex = folderIndex;
*outBuffer = 0;
*outBufferSize = 0;
@@ -31,87 +35,60 @@ SZ_RESULT SzExtract(
if (*outBuffer == 0 || *blockIndex != folderIndex)
{
- CFolder *folder = db->Database.Folders + folderIndex;
- CFileSize unPackSizeSpec = SzFolderGetUnPackSize(folder);
+ CSzFolder *folder = p->db.Folders + folderIndex;
+ CFileSize unPackSizeSpec = SzFolder_GetUnPackSize(folder);
size_t unPackSize = (size_t)unPackSizeSpec;
- CFileSize startOffset = SzArDbGetFolderStreamPos(db, folderIndex, 0);
- #ifndef _LZMA_IN_CB
- Byte *inBuffer = 0;
- size_t processedSize;
- CFileSize packSizeSpec;
- size_t packSize;
- RINOK(SzArDbGetFolderFullPackSize(db, folderIndex, &packSizeSpec));
- packSize = (size_t)packSizeSpec;
- if (packSize != packSizeSpec)
- return SZE_OUTOFMEMORY;
- #endif
+ CFileSize startOffset = SzArEx_GetFolderStreamPos(p, folderIndex, 0);
+
if (unPackSize != unPackSizeSpec)
- return SZE_OUTOFMEMORY;
+ return SZ_ERROR_MEM;
*blockIndex = folderIndex;
- allocMain->Free(*outBuffer);
+ IAlloc_Free(allocMain, *outBuffer);
*outBuffer = 0;
- RINOK(inStream->Seek(inStream, startOffset));
+ RINOK(inStream->Seek(inStream, startOffset, SZ_SEEK_SET));
- #ifndef _LZMA_IN_CB
- if (packSize != 0)
- {
- inBuffer = (Byte *)allocTemp->Alloc(packSize);
- if (inBuffer == 0)
- return SZE_OUTOFMEMORY;
- }
- res = inStream->Read(inStream, inBuffer, packSize, &processedSize);
- if (res == SZ_OK && processedSize != packSize)
- res = SZE_FAIL;
- #endif
if (res == SZ_OK)
{
*outBufferSize = unPackSize;
if (unPackSize != 0)
{
- *outBuffer = (Byte *)allocMain->Alloc(unPackSize);
+ *outBuffer = (Byte *)IAlloc_Alloc(allocMain, unPackSize);
if (*outBuffer == 0)
- res = SZE_OUTOFMEMORY;
+ res = SZ_ERROR_MEM;
}
if (res == SZ_OK)
{
- res = SzDecode(db->Database.PackSizes +
- db->FolderStartPackStreamIndex[folderIndex], folder,
- #ifdef _LZMA_IN_CB
+ res = SzDecode(p->db.PackSizes +
+ p->FolderStartPackStreamIndex[folderIndex], folder,
inStream, startOffset,
- #else
- inBuffer,
- #endif
*outBuffer, unPackSize, allocTemp);
if (res == SZ_OK)
{
if (folder->UnPackCRCDefined)
{
if (CrcCalc(*outBuffer, unPackSize) != folder->UnPackCRC)
- res = SZE_CRC_ERROR;
+ res = SZ_ERROR_CRC;
}
}
}
}
- #ifndef _LZMA_IN_CB
- allocTemp->Free(inBuffer);
- #endif
}
if (res == SZ_OK)
{
UInt32 i;
- CFileItem *fileItem = db->Database.Files + fileIndex;
+ CSzFileItem *fileItem = p->db.Files + fileIndex;
*offset = 0;
- for(i = db->FolderStartFileIndex[folderIndex]; i < fileIndex; i++)
- *offset += (UInt32)db->Database.Files[i].Size;
+ for(i = p->FolderStartFileIndex[folderIndex]; i < fileIndex; i++)
+ *offset += (UInt32)p->db.Files[i].Size;
*outSizeProcessed = (size_t)fileItem->Size;
if (*offset + *outSizeProcessed > *outBufferSize)
- return SZE_FAIL;
+ return SZ_ERROR_FAIL;
{
if (fileItem->IsFileCRCDefined)
{
if (CrcCalc(*outBuffer + *offset, *outSizeProcessed) != fileItem->FileCRC)
- res = SZE_CRC_ERROR;
+ res = SZ_ERROR_CRC;
}
}
}
diff --git a/C/Archive/7z/7zExtract.h b/C/Archive/7z/7zExtract.h
index e9a4fb4e..cd0e4f03 100755
--- a/C/Archive/7z/7zExtract.h
+++ b/C/Archive/7z/7zExtract.h
@@ -1,4 +1,8 @@
-/* 7zExtract.h */
+/* 7zExtract.h -- Extracting from 7z archive
+2008-04-09
+Igor Pavlov
+Copyright (c) 1999-2008 Igor Pavlov
+Read 7zItem.h for license options */
#ifndef __7Z_EXTRACT_H
#define __7Z_EXTRACT_H
@@ -25,9 +29,9 @@
Free *outBuffer and set *outBuffer to 0, if you want to flush cache.
*/
-SZ_RESULT SzExtract(
+SRes SzAr_Extract(
+ const CSzArEx *db,
ISzInStream *inStream,
- CArchiveDatabaseEx *db,
UInt32 fileIndex, /* index of file */
UInt32 *blockIndex, /* index of solid block */
Byte **outBuffer, /* pointer to pointer to output buffer (allocated with allocMain) */
diff --git a/C/Archive/7z/7zHeader.c b/C/Archive/7z/7zHeader.c
index 3be4bc27..3edb8d00 100755
--- a/C/Archive/7z/7zHeader.c
+++ b/C/Archive/7z/7zHeader.c
@@ -1,4 +1,8 @@
-/* 7zHeader.c */
+/* 7zHeader.c -- 7z Headers
+2008-04-09
+Igor Pavlov
+Copyright (c) 1999-2008 Igor Pavlov
+Read 7zHeader.h for license options */
#include "7zHeader.h"
diff --git a/C/Archive/7z/7zHeader.h b/C/Archive/7z/7zHeader.h
index 3e67cf57..9cd3e3dc 100755
--- a/C/Archive/7z/7zHeader.h
+++ b/C/Archive/7z/7zHeader.h
@@ -1,4 +1,7 @@
-/* 7zHeader.h */
+/* 7zHeader.h -- 7z Headers
+2008-03-17
+Copyright (c) 1999-2008 Igor Pavlov
+Read LzmaDec.h for license options */
#ifndef __7Z_HEADER_H
#define __7Z_HEADER_H
diff --git a/C/Archive/7z/7zIn.c b/C/Archive/7z/7zIn.c
index ac25dbc7..b99a6ac7 100755
--- a/C/Archive/7z/7zIn.c
+++ b/C/Archive/7z/7zIn.c
@@ -1,28 +1,32 @@
-/* 7zIn.c */
+/* 7zIn.c -- 7z Input functions
+2008-04-09
+Igor Pavlov
+Copyright (c) 1999-2008 Igor Pavlov
+Read 7zIn.h for license options */
#include "7zIn.h"
#include "7zDecode.h"
#include "../../7zCrc.h"
-#define RINOM(x) { if((x) == 0) return SZE_OUTOFMEMORY; }
+#define RINOM(x) { if((x) == 0) return SZ_ERROR_MEM; }
-void SzArDbExInit(CArchiveDatabaseEx *db)
+void SzArEx_Init(CSzArEx *p)
{
- SzArchiveDatabaseInit(&db->Database);
- db->FolderStartPackStreamIndex = 0;
- db->PackStreamStartPositions = 0;
- db->FolderStartFileIndex = 0;
- db->FileIndexToFolderIndexMap = 0;
+ SzAr_Init(&p->db);
+ p->FolderStartPackStreamIndex = 0;
+ p->PackStreamStartPositions = 0;
+ p->FolderStartFileIndex = 0;
+ p->FileIndexToFolderIndexMap = 0;
}
-void SzArDbExFree(CArchiveDatabaseEx *db, void (*freeFunc)(void *))
+void SzArEx_Free(CSzArEx *p, ISzAlloc *alloc)
{
- freeFunc(db->FolderStartPackStreamIndex);
- freeFunc(db->PackStreamStartPositions);
- freeFunc(db->FolderStartFileIndex);
- freeFunc(db->FileIndexToFolderIndexMap);
- SzArchiveDatabaseFree(&db->Database, freeFunc);
- SzArDbExInit(db);
+ IAlloc_Free(alloc, p->FolderStartPackStreamIndex);
+ IAlloc_Free(alloc, p->PackStreamStartPositions);
+ IAlloc_Free(alloc, p->FolderStartFileIndex);
+ IAlloc_Free(alloc, p->FileIndexToFolderIndexMap);
+ SzAr_Free(&p->db, alloc);
+ SzArEx_Init(p);
}
/*
@@ -36,7 +40,7 @@ CFileSize GetFilePackSize(int fileIndex) const
int folderIndex = FileIndexToFolderIndexMap[fileIndex];
if (folderIndex >= 0)
{
- const CFolder &folderInfo = Folders[folderIndex];
+ const CSzFolder &folderInfo = Folders[folderIndex];
if (FolderStartFileIndex[folderIndex] == fileIndex)
return GetFolderFullPackSize(folderIndex);
}
@@ -44,41 +48,41 @@ CFileSize GetFilePackSize(int fileIndex) const
}
*/
-#define MY_ALLOC(T, p, size, allocFunc) { if ((size) == 0) p = 0; else \
- if ((p = (T *)allocFunc((size) * sizeof(T))) == 0) return SZE_OUTOFMEMORY; }
+#define MY_ALLOC(T, p, size, alloc) { if ((size) == 0) p = 0; else \
+ if ((p = (T *)IAlloc_Alloc(alloc, (size) * sizeof(T))) == 0) return SZ_ERROR_MEM; }
-SZ_RESULT SzArDbExFill(CArchiveDatabaseEx *db, void * (*allocFunc)(size_t size))
+static SRes SzArEx_Fill(CSzArEx *p, ISzAlloc *alloc)
{
UInt32 startPos = 0;
CFileSize startPosSize = 0;
UInt32 i;
UInt32 folderIndex = 0;
UInt32 indexInFolder = 0;
- MY_ALLOC(UInt32, db->FolderStartPackStreamIndex, db->Database.NumFolders, allocFunc);
- for(i = 0; i < db->Database.NumFolders; i++)
+ MY_ALLOC(UInt32, p->FolderStartPackStreamIndex, p->db.NumFolders, alloc);
+ for (i = 0; i < p->db.NumFolders; i++)
{
- db->FolderStartPackStreamIndex[i] = startPos;
- startPos += db->Database.Folders[i].NumPackStreams;
+ p->FolderStartPackStreamIndex[i] = startPos;
+ startPos += p->db.Folders[i].NumPackStreams;
}
- MY_ALLOC(CFileSize, db->PackStreamStartPositions, db->Database.NumPackStreams, allocFunc);
+ MY_ALLOC(CFileSize, p->PackStreamStartPositions, p->db.NumPackStreams, alloc);
- for(i = 0; i < db->Database.NumPackStreams; i++)
+ for (i = 0; i < p->db.NumPackStreams; i++)
{
- db->PackStreamStartPositions[i] = startPosSize;
- startPosSize += db->Database.PackSizes[i];
+ p->PackStreamStartPositions[i] = startPosSize;
+ startPosSize += p->db.PackSizes[i];
}
- MY_ALLOC(UInt32, db->FolderStartFileIndex, db->Database.NumFolders, allocFunc);
- MY_ALLOC(UInt32, db->FileIndexToFolderIndexMap, db->Database.NumFiles, allocFunc);
+ MY_ALLOC(UInt32, p->FolderStartFileIndex, p->db.NumFolders, alloc);
+ MY_ALLOC(UInt32, p->FileIndexToFolderIndexMap, p->db.NumFiles, alloc);
- for (i = 0; i < db->Database.NumFiles; i++)
+ for (i = 0; i < p->db.NumFiles; i++)
{
- CFileItem *file = db->Database.Files + i;
+ CSzFileItem *file = p->db.Files + i;
int emptyStream = !file->HasStream;
if (emptyStream && indexInFolder == 0)
{
- db->FileIndexToFolderIndexMap[i] = (UInt32)-1;
+ p->FileIndexToFolderIndexMap[i] = (UInt32)-1;
continue;
}
if (indexInFolder == 0)
@@ -89,19 +93,19 @@ SZ_RESULT SzArDbExFill(CArchiveDatabaseEx *db, void * (*allocFunc)(size_t size))
*/
for (;;)
{
- if (folderIndex >= db->Database.NumFolders)
- return SZE_ARCHIVE_ERROR;
- db->FolderStartFileIndex[folderIndex] = i;
- if (db->Database.Folders[folderIndex].NumUnPackStreams != 0)
+ if (folderIndex >= p->db.NumFolders)
+ return SZ_ERROR_ARCHIVE;
+ p->FolderStartFileIndex[folderIndex] = i;
+ if (p->db.Folders[folderIndex].NumUnPackStreams != 0)
break;
folderIndex++;
}
}
- db->FileIndexToFolderIndexMap[i] = folderIndex;
+ p->FileIndexToFolderIndexMap[i] = folderIndex;
if (emptyStream)
continue;
indexInFolder++;
- if (indexInFolder >= db->Database.Folders[folderIndex].NumUnPackStreams)
+ if (indexInFolder >= p->db.Folders[folderIndex].NumUnPackStreams)
{
folderIndex++;
indexInFolder = 0;
@@ -111,23 +115,23 @@ SZ_RESULT SzArDbExFill(CArchiveDatabaseEx *db, void * (*allocFunc)(size_t size))
}
-CFileSize SzArDbGetFolderStreamPos(CArchiveDatabaseEx *db, UInt32 folderIndex, UInt32 indexInFolder)
+CFileSize SzArEx_GetFolderStreamPos(const CSzArEx *p, UInt32 folderIndex, UInt32 indexInFolder)
{
- return db->ArchiveInfo.DataStartPosition +
- db->PackStreamStartPositions[db->FolderStartPackStreamIndex[folderIndex] + indexInFolder];
+ return p->ArchiveInfo.DataStartPosition +
+ p->PackStreamStartPositions[p->FolderStartPackStreamIndex[folderIndex] + indexInFolder];
}
-int SzArDbGetFolderFullPackSize(CArchiveDatabaseEx *db, UInt32 folderIndex, CFileSize *resSize)
+int SzArEx_GetFolderFullPackSize(const CSzArEx *p, UInt32 folderIndex, CFileSize *resSize)
{
- UInt32 packStreamIndex = db->FolderStartPackStreamIndex[folderIndex];
- CFolder *folder = db->Database.Folders + folderIndex;
+ UInt32 packStreamIndex = p->FolderStartPackStreamIndex[folderIndex];
+ CSzFolder *folder = p->db.Folders + folderIndex;
CFileSize size = 0;
UInt32 i;
for (i = 0; i < folder->NumPackStreams; i++)
{
- CFileSize t = size + db->Database.PackSizes[packStreamIndex + i];
- if (t < size)
- return SZE_FAIL;
+ CFileSize t = size + p->db.PackSizes[packStreamIndex + i];
+ if (t < size) // check it
+ return SZ_ERROR_FAIL;
size = t;
}
*resSize = size;
@@ -136,8 +140,8 @@ int SzArDbGetFolderFullPackSize(CArchiveDatabaseEx *db, UInt32 folderIndex, CFil
/*
-SZ_RESULT SzReadTime(const CObjectVector<CSzByteBuffer> &dataVector,
- CObjectVector<CFileItem> &files, UInt64 type)
+SRes SzReadTime(const CObjectVector<CBuf> &dataVector,
+ CObjectVector<CSzFileItem> &files, UInt64 type)
{
CBoolVector boolVector;
RINOK(ReadBoolVector2(files.Size(), boolVector))
@@ -145,9 +149,9 @@ SZ_RESULT SzReadTime(const CObjectVector<CSzByteBuffer> &dataVector,
CStreamSwitch streamSwitch;
RINOK(streamSwitch.Set(this, &dataVector));
- for(int i = 0; i < files.Size(); i++)
+ for (int i = 0; i < files.Size(); i++)
{
- CFileItem &file = files[i];
+ CSzFileItem &file = files[i];
CArchiveFileTime fileTime;
bool defined = boolVector[i];
if (defined)
@@ -181,40 +185,31 @@ SZ_RESULT SzReadTime(const CObjectVector<CSzByteBuffer> &dataVector,
}
*/
-SZ_RESULT SafeReadDirect(ISzInStream *inStream, Byte *data, size_t size)
+static SRes SafeReadDirect(ISzInStream *inStream, Byte *data, size_t size)
{
- #ifdef _LZMA_IN_CB
while (size > 0)
{
void *inBufferSpec;
- size_t processedSize;
+ size_t processedSize = size;
const Byte *inBuffer;
- RINOK(inStream->Read(inStream, (void **)&inBufferSpec, size, &processedSize));
+ RINOK(inStream->Read(inStream, (void **)&inBufferSpec, &processedSize));
inBuffer = (const Byte *)inBufferSpec;
- if (processedSize == 0 || processedSize > size)
- return SZE_FAIL;
+ if (processedSize == 0)
+ return SZ_ERROR_INPUT_EOF;
size -= processedSize;
do
- {
*data++ = *inBuffer++;
- }
while (--processedSize != 0);
}
- #else
- size_t processedSize;
- RINOK(inStream->Read(inStream, data, size, &processedSize));
- if (processedSize != size)
- return SZE_FAIL;
- #endif
return SZ_OK;
}
-SZ_RESULT SafeReadDirectByte(ISzInStream *inStream, Byte *data)
+static SRes SafeReadDirectByte(ISzInStream *inStream, Byte *data)
{
return SafeReadDirect(inStream, data, 1);
}
-SZ_RESULT SafeReadDirectUInt32(ISzInStream *inStream, UInt32 *value, UInt32 *crc)
+static SRes SafeReadDirectUInt32(ISzInStream *inStream, UInt32 *value, UInt32 *crc)
{
int i;
*value = 0;
@@ -228,7 +223,7 @@ SZ_RESULT SafeReadDirectUInt32(ISzInStream *inStream, UInt32 *value, UInt32 *crc
return SZ_OK;
}
-SZ_RESULT SafeReadDirectUInt64(ISzInStream *inStream, UInt64 *value, UInt32 *crc)
+static SRes SafeReadDirectUInt64(ISzInStream *inStream, UInt64 *value, UInt32 *crc)
{
int i;
*value = 0;
@@ -242,7 +237,7 @@ SZ_RESULT SafeReadDirectUInt64(ISzInStream *inStream, UInt64 *value, UInt32 *crc
return SZ_OK;
}
-int TestSignatureCandidate(Byte *testBytes)
+static int TestSignatureCandidate(Byte *testBytes)
{
size_t i;
for (i = 0; i < k7zSignatureSize; i++)
@@ -257,16 +252,16 @@ typedef struct _CSzState
size_t Size;
}CSzData;
-SZ_RESULT SzReadByte(CSzData *sd, Byte *b)
+static SRes SzReadByte(CSzData *sd, Byte *b)
{
if (sd->Size == 0)
- return SZE_ARCHIVE_ERROR;
+ return SZ_ERROR_ARCHIVE;
sd->Size--;
*b = *sd->Data++;
return SZ_OK;
}
-SZ_RESULT SzReadBytes(CSzData *sd, Byte *data, size_t size)
+static SRes SzReadBytes(CSzData *sd, Byte *data, size_t size)
{
size_t i;
for (i = 0; i < size; i++)
@@ -276,7 +271,7 @@ SZ_RESULT SzReadBytes(CSzData *sd, Byte *data, size_t size)
return SZ_OK;
}
-SZ_RESULT SzReadUInt32(CSzData *sd, UInt32 *value)
+static SRes SzReadUInt32(CSzData *sd, UInt32 *value)
{
int i;
*value = 0;
@@ -289,7 +284,7 @@ SZ_RESULT SzReadUInt32(CSzData *sd, UInt32 *value)
return SZ_OK;
}
-SZ_RESULT SzReadNumber(CSzData *sd, UInt64 *value)
+static SRes SzReadNumber(CSzData *sd, UInt64 *value)
{
Byte firstByte;
Byte mask = 0x80;
@@ -312,7 +307,7 @@ SZ_RESULT SzReadNumber(CSzData *sd, UInt64 *value)
return SZ_OK;
}
-SZ_RESULT SzReadSize(CSzData *sd, CFileSize *value)
+static SRes SzReadSize(CSzData *sd, CFileSize *value)
{
UInt64 value64;
RINOK(SzReadNumber(sd, &value64));
@@ -320,40 +315,40 @@ SZ_RESULT SzReadSize(CSzData *sd, CFileSize *value)
return SZ_OK;
}
-SZ_RESULT SzReadNumber32(CSzData *sd, UInt32 *value)
+static SRes SzReadNumber32(CSzData *sd, UInt32 *value)
{
UInt64 value64;
RINOK(SzReadNumber(sd, &value64));
if (value64 >= 0x80000000)
- return SZE_NOTIMPL;
+ return SZ_ERROR_UNSUPPORTED;
if (value64 >= ((UInt64)(1) << ((sizeof(size_t) - 1) * 8 + 2)))
- return SZE_NOTIMPL;
+ return SZ_ERROR_UNSUPPORTED;
*value = (UInt32)value64;
return SZ_OK;
}
-SZ_RESULT SzReadID(CSzData *sd, UInt64 *value)
+static SRes SzReadID(CSzData *sd, UInt64 *value)
{
return SzReadNumber(sd, value);
}
-SZ_RESULT SzSkeepDataSize(CSzData *sd, UInt64 size)
+static SRes SzSkeepDataSize(CSzData *sd, UInt64 size)
{
if (size > sd->Size)
- return SZE_ARCHIVE_ERROR;
+ return SZ_ERROR_ARCHIVE;
sd->Size -= (size_t)size;
sd->Data += (size_t)size;
return SZ_OK;
}
-SZ_RESULT SzSkeepData(CSzData *sd)
+static SRes SzSkeepData(CSzData *sd)
{
UInt64 size;
RINOK(SzReadNumber(sd, &size));
return SzSkeepDataSize(sd, size);
}
-SZ_RESULT SzReadArchiveProperties(CSzData *sd)
+static SRes SzReadArchiveProperties(CSzData *sd)
{
for (;;)
{
@@ -366,7 +361,7 @@ SZ_RESULT SzReadArchiveProperties(CSzData *sd)
return SZ_OK;
}
-SZ_RESULT SzWaitAttribute(CSzData *sd, UInt64 attribute)
+static SRes SzWaitAttribute(CSzData *sd, UInt64 attribute)
{
for (;;)
{
@@ -375,17 +370,17 @@ SZ_RESULT SzWaitAttribute(CSzData *sd, UInt64 attribute)
if (type == attribute)
return SZ_OK;
if (type == k7zIdEnd)
- return SZE_ARCHIVE_ERROR;
+ return SZ_ERROR_ARCHIVE;
RINOK(SzSkeepData(sd));
}
}
-SZ_RESULT SzReadBoolVector(CSzData *sd, size_t numItems, Byte **v, void * (*allocFunc)(size_t size))
+static SRes SzReadBoolVector(CSzData *sd, size_t numItems, Byte **v, ISzAlloc *alloc)
{
Byte b = 0;
Byte mask = 0;
size_t i;
- MY_ALLOC(Byte, *v, numItems, allocFunc);
+ MY_ALLOC(Byte, *v, numItems, alloc);
for (i = 0; i < numItems; i++)
{
if (mask == 0)
@@ -399,30 +394,30 @@ SZ_RESULT SzReadBoolVector(CSzData *sd, size_t numItems, Byte **v, void * (*allo
return SZ_OK;
}
-SZ_RESULT SzReadBoolVector2(CSzData *sd, size_t numItems, Byte **v, void * (*allocFunc)(size_t size))
+static SRes SzReadBoolVector2(CSzData *sd, size_t numItems, Byte **v, ISzAlloc *alloc)
{
Byte allAreDefined;
size_t i;
RINOK(SzReadByte(sd, &allAreDefined));
if (allAreDefined == 0)
- return SzReadBoolVector(sd, numItems, v, allocFunc);
- MY_ALLOC(Byte, *v, numItems, allocFunc);
- for(i = 0; i < numItems; i++)
+ return SzReadBoolVector(sd, numItems, v, alloc);
+ MY_ALLOC(Byte, *v, numItems, alloc);
+ for (i = 0; i < numItems; i++)
(*v)[i] = 1;
return SZ_OK;
}
-SZ_RESULT SzReadHashDigests(
+static SRes SzReadHashDigests(
CSzData *sd,
size_t numItems,
Byte **digestsDefined,
UInt32 **digests,
- void * (*allocFunc)(size_t size))
+ ISzAlloc *alloc)
{
size_t i;
- RINOK(SzReadBoolVector2(sd, numItems, digestsDefined, allocFunc));
- MY_ALLOC(UInt32, *digests, numItems, allocFunc);
- for(i = 0; i < numItems; i++)
+ RINOK(SzReadBoolVector2(sd, numItems, digestsDefined, alloc));
+ MY_ALLOC(UInt32, *digests, numItems, alloc);
+ for (i = 0; i < numItems; i++)
if ((*digestsDefined)[i])
{
RINOK(SzReadUInt32(sd, (*digests) + i));
@@ -430,14 +425,14 @@ SZ_RESULT SzReadHashDigests(
return SZ_OK;
}
-SZ_RESULT SzReadPackInfo(
+static SRes SzReadPackInfo(
CSzData *sd,
CFileSize *dataOffset,
UInt32 *numPackStreams,
CFileSize **packSizes,
Byte **packCRCsDefined,
UInt32 **packCRCs,
- void * (*allocFunc)(size_t size))
+ ISzAlloc *alloc)
{
UInt32 i;
RINOK(SzReadSize(sd, dataOffset));
@@ -445,9 +440,9 @@ SZ_RESULT SzReadPackInfo(
RINOK(SzWaitAttribute(sd, k7zIdSize));
- MY_ALLOC(CFileSize, *packSizes, (size_t)*numPackStreams, allocFunc);
+ MY_ALLOC(CFileSize, *packSizes, (size_t)*numPackStreams, alloc);
- for(i = 0; i < *numPackStreams; i++)
+ for (i = 0; i < *numPackStreams; i++)
{
RINOK(SzReadSize(sd, (*packSizes) + i));
}
@@ -460,16 +455,16 @@ SZ_RESULT SzReadPackInfo(
break;
if (type == k7zIdCRC)
{
- RINOK(SzReadHashDigests(sd, (size_t)*numPackStreams, packCRCsDefined, packCRCs, allocFunc));
+ RINOK(SzReadHashDigests(sd, (size_t)*numPackStreams, packCRCsDefined, packCRCs, alloc));
continue;
}
RINOK(SzSkeepData(sd));
}
if (*packCRCsDefined == 0)
{
- MY_ALLOC(Byte, *packCRCsDefined, (size_t)*numPackStreams, allocFunc);
- MY_ALLOC(UInt32, *packCRCs, (size_t)*numPackStreams, allocFunc);
- for(i = 0; i < *numPackStreams; i++)
+ MY_ALLOC(Byte, *packCRCsDefined, (size_t)*numPackStreams, alloc);
+ MY_ALLOC(UInt32, *packCRCs, (size_t)*numPackStreams, alloc);
+ for (i = 0; i < *numPackStreams; i++)
{
(*packCRCsDefined)[i] = 0;
(*packCRCs)[i] = 0;
@@ -478,14 +473,14 @@ SZ_RESULT SzReadPackInfo(
return SZ_OK;
}
-SZ_RESULT SzReadSwitch(CSzData *sd)
+static SRes SzReadSwitch(CSzData *sd)
{
Byte external;
RINOK(SzReadByte(sd, &external));
- return (external == 0) ? SZ_OK: SZE_ARCHIVE_ERROR;
+ return (external == 0) ? SZ_OK: SZ_ERROR_UNSUPPORTED;
}
-SZ_RESULT SzGetNextFolderItem(CSzData *sd, CFolder *folder, void * (*allocFunc)(size_t size))
+static SRes SzGetNextFolderItem(CSzData *sd, CSzFolder *folder, ISzAlloc *alloc)
{
UInt32 numCoders;
UInt32 numBindPairs;
@@ -496,15 +491,15 @@ SZ_RESULT SzGetNextFolderItem(CSzData *sd, CFolder *folder, void * (*allocFunc)(
RINOK(SzReadNumber32(sd, &numCoders));
folder->NumCoders = numCoders;
- MY_ALLOC(CCoderInfo, folder->Coders, (size_t)numCoders, allocFunc);
+ MY_ALLOC(CSzCoderInfo, folder->Coders, (size_t)numCoders, alloc);
for (i = 0; i < numCoders; i++)
- SzCoderInfoInit(folder->Coders + i);
+ SzCoderInfo_Init(folder->Coders + i);
for (i = 0; i < numCoders; i++)
{
Byte mainByte;
- CCoderInfo *coder = folder->Coders + i;
+ CSzCoderInfo *coder = folder->Coders + i;
{
unsigned idSize, j;
Byte longID[15];
@@ -512,7 +507,7 @@ SZ_RESULT SzGetNextFolderItem(CSzData *sd, CFolder *folder, void * (*allocFunc)(
idSize = (unsigned)(mainByte & 0xF);
RINOK(SzReadBytes(sd, longID, idSize));
if (idSize > sizeof(coder->MethodID))
- return SZE_NOTIMPL;
+ return SZ_ERROR_UNSUPPORTED;
coder->MethodID = 0;
for (j = 0; j < idSize; j++)
coder->MethodID |= (CMethodID)longID[idSize - 1 - j] << (8 * j);
@@ -531,9 +526,9 @@ SZ_RESULT SzGetNextFolderItem(CSzData *sd, CFolder *folder, void * (*allocFunc)(
{
UInt64 propertiesSize = 0;
RINOK(SzReadNumber(sd, &propertiesSize));
- if (!SzByteBufferCreate(&coder->Properties, (size_t)propertiesSize, allocFunc))
- return SZE_OUTOFMEMORY;
- RINOK(SzReadBytes(sd, coder->Properties.Items, (size_t)propertiesSize));
+ if (!Buf_Create(&coder->Props, (size_t)propertiesSize, alloc))
+ return SZ_ERROR_MEM;
+ RINOK(SzReadBytes(sd, coder->Props.data, (size_t)propertiesSize));
}
}
while ((mainByte & 0x80) != 0)
@@ -561,7 +556,7 @@ SZ_RESULT SzGetNextFolderItem(CSzData *sd, CFolder *folder, void * (*allocFunc)(
folder->NumBindPairs = numBindPairs;
- MY_ALLOC(CBindPair, folder->BindPairs, (size_t)numBindPairs, allocFunc);
+ MY_ALLOC(CBindPair, folder->BindPairs, (size_t)numBindPairs, alloc);
for (i = 0; i < numBindPairs; i++)
{
@@ -573,32 +568,32 @@ SZ_RESULT SzGetNextFolderItem(CSzData *sd, CFolder *folder, void * (*allocFunc)(
numPackedStreams = numInStreams - (UInt32)numBindPairs;
folder->NumPackStreams = numPackedStreams;
- MY_ALLOC(UInt32, folder->PackStreams, (size_t)numPackedStreams, allocFunc);
+ MY_ALLOC(UInt32, folder->PackStreams, (size_t)numPackedStreams, alloc);
if (numPackedStreams == 1)
{
UInt32 j;
UInt32 pi = 0;
for (j = 0; j < numInStreams; j++)
- if (SzFolderFindBindPairForInStream(folder, j) < 0)
+ if (SzFolder_FindBindPairForInStream(folder, j) < 0)
{
folder->PackStreams[pi++] = j;
break;
}
}
else
- for(i = 0; i < numPackedStreams; i++)
+ for (i = 0; i < numPackedStreams; i++)
{
RINOK(SzReadNumber32(sd, folder->PackStreams + i));
}
return SZ_OK;
}
-SZ_RESULT SzReadUnPackInfo(
+static SRes SzReadUnPackInfo(
CSzData *sd,
UInt32 *numFolders,
- CFolder **folders, /* for allocFunc */
- void * (*allocFunc)(size_t size),
+ CSzFolder **folders, /* for alloc */
+ ISzAlloc *alloc,
ISzAlloc *allocTemp)
{
UInt32 i;
@@ -607,28 +602,28 @@ SZ_RESULT SzReadUnPackInfo(
{
RINOK(SzReadSwitch(sd));
- MY_ALLOC(CFolder, *folders, (size_t)*numFolders, allocFunc);
+ MY_ALLOC(CSzFolder, *folders, (size_t)*numFolders, alloc);
- for(i = 0; i < *numFolders; i++)
- SzFolderInit((*folders) + i);
+ for (i = 0; i < *numFolders; i++)
+ SzFolder_Init((*folders) + i);
- for(i = 0; i < *numFolders; i++)
+ for (i = 0; i < *numFolders; i++)
{
- RINOK(SzGetNextFolderItem(sd, (*folders) + i, allocFunc));
+ RINOK(SzGetNextFolderItem(sd, (*folders) + i, alloc));
}
}
RINOK(SzWaitAttribute(sd, k7zIdCodersUnPackSize));
- for(i = 0; i < *numFolders; i++)
+ for (i = 0; i < *numFolders; i++)
{
UInt32 j;
- CFolder *folder = (*folders) + i;
- UInt32 numOutStreams = SzFolderGetNumOutStreams(folder);
+ CSzFolder *folder = (*folders) + i;
+ UInt32 numOutStreams = SzFolder_GetNumOutStreams(folder);
- MY_ALLOC(CFileSize, folder->UnPackSizes, (size_t)numOutStreams, allocFunc);
+ MY_ALLOC(CFileSize, folder->UnPackSizes, (size_t)numOutStreams, alloc);
- for(j = 0; j < numOutStreams; j++)
+ for (j = 0; j < numOutStreams; j++)
{
RINOK(SzReadSize(sd, folder->UnPackSizes + j));
}
@@ -642,21 +637,21 @@ SZ_RESULT SzReadUnPackInfo(
return SZ_OK;
if (type == k7zIdCRC)
{
- SZ_RESULT res;
+ SRes res;
Byte *crcsDefined = 0;
UInt32 *crcs = 0;
- res = SzReadHashDigests(sd, *numFolders, &crcsDefined, &crcs, allocTemp->Alloc);
+ res = SzReadHashDigests(sd, *numFolders, &crcsDefined, &crcs, allocTemp);
if (res == SZ_OK)
{
- for(i = 0; i < *numFolders; i++)
+ for (i = 0; i < *numFolders; i++)
{
- CFolder *folder = (*folders) + i;
+ CSzFolder *folder = (*folders) + i;
folder->UnPackCRCDefined = crcsDefined[i];
folder->UnPackCRC = crcs[i];
}
}
- allocTemp->Free(crcs);
- allocTemp->Free(crcsDefined);
+ IAlloc_Free(allocTemp, crcs);
+ IAlloc_Free(allocTemp, crcsDefined);
RINOK(res);
continue;
}
@@ -664,10 +659,10 @@ SZ_RESULT SzReadUnPackInfo(
}
}
-SZ_RESULT SzReadSubStreamsInfo(
+static SRes SzReadSubStreamsInfo(
CSzData *sd,
UInt32 numFolders,
- CFolder *folders,
+ CSzFolder *folders,
UInt32 *numUnPackStreams,
CFileSize **unPackSizes,
Byte **digestsDefined,
@@ -679,7 +674,7 @@ SZ_RESULT SzReadSubStreamsInfo(
UInt32 si = 0;
UInt32 numDigests = 0;
- for(i = 0; i < numFolders; i++)
+ for (i = 0; i < numFolders; i++)
folders[i].NumUnPackStreams = 1;
*numUnPackStreams = numFolders;
@@ -689,7 +684,7 @@ SZ_RESULT SzReadSubStreamsInfo(
if (type == k7zIdNumUnPackStream)
{
*numUnPackStreams = 0;
- for(i = 0; i < numFolders; i++)
+ for (i = 0; i < numFolders; i++)
{
UInt32 numStreams;
RINOK(SzReadNumber32(sd, &numStreams));
@@ -713,15 +708,15 @@ SZ_RESULT SzReadSubStreamsInfo(
}
else
{
- *unPackSizes = (CFileSize *)allocTemp->Alloc((size_t)*numUnPackStreams * sizeof(CFileSize));
+ *unPackSizes = (CFileSize *)IAlloc_Alloc(allocTemp, (size_t)*numUnPackStreams * sizeof(CFileSize));
RINOM(*unPackSizes);
- *digestsDefined = (Byte *)allocTemp->Alloc((size_t)*numUnPackStreams * sizeof(Byte));
+ *digestsDefined = (Byte *)IAlloc_Alloc(allocTemp, (size_t)*numUnPackStreams * sizeof(Byte));
RINOM(*digestsDefined);
- *digests = (UInt32 *)allocTemp->Alloc((size_t)*numUnPackStreams * sizeof(UInt32));
+ *digests = (UInt32 *)IAlloc_Alloc(allocTemp, (size_t)*numUnPackStreams * sizeof(UInt32));
RINOM(*digests);
}
- for(i = 0; i < numFolders; i++)
+ for (i = 0; i < numFolders; i++)
{
/*
v3.13 incorrectly worked with empty folders
@@ -740,21 +735,21 @@ SZ_RESULT SzReadSubStreamsInfo(
(*unPackSizes)[si++] = size;
sum += size;
}
- (*unPackSizes)[si++] = SzFolderGetUnPackSize(folders + i) - sum;
+ (*unPackSizes)[si++] = SzFolder_GetUnPackSize(folders + i) - sum;
}
if (type == k7zIdSize)
{
RINOK(SzReadID(sd, &type));
}
- for(i = 0; i < *numUnPackStreams; i++)
+ for (i = 0; i < *numUnPackStreams; i++)
{
(*digestsDefined)[i] = 0;
(*digests)[i] = 0;
}
- for(i = 0; i < numFolders; i++)
+ for (i = 0; i < numFolders; i++)
{
UInt32 numSubstreams = folders[i].NumUnPackStreams;
if (numSubstreams != 1 || !folders[i].UnPackCRCDefined)
@@ -770,12 +765,12 @@ SZ_RESULT SzReadSubStreamsInfo(
int digestIndex = 0;
Byte *digestsDefined2 = 0;
UInt32 *digests2 = 0;
- SZ_RESULT res = SzReadHashDigests(sd, numDigests, &digestsDefined2, &digests2, allocTemp->Alloc);
+ SRes res = SzReadHashDigests(sd, numDigests, &digestsDefined2, &digests2, allocTemp);
if (res == SZ_OK)
{
for (i = 0; i < numFolders; i++)
{
- CFolder *folder = folders + i;
+ CSzFolder *folder = folders + i;
UInt32 numSubstreams = folder->NumUnPackStreams;
if (numSubstreams == 1 && folder->UnPackCRCDefined)
{
@@ -795,8 +790,8 @@ SZ_RESULT SzReadSubStreamsInfo(
}
}
}
- allocTemp->Free(digestsDefined2);
- allocTemp->Free(digests2);
+ IAlloc_Free(allocTemp, digestsDefined2);
+ IAlloc_Free(allocTemp, digests2);
RINOK(res);
}
else if (type == k7zIdEnd)
@@ -810,15 +805,15 @@ SZ_RESULT SzReadSubStreamsInfo(
}
-SZ_RESULT SzReadStreamsInfo(
+static SRes SzReadStreamsInfo(
CSzData *sd,
CFileSize *dataOffset,
- CArchiveDatabase *db,
+ CSzAr *p,
UInt32 *numUnPackStreams,
CFileSize **unPackSizes, /* allocTemp */
Byte **digestsDefined, /* allocTemp */
UInt32 **digests, /* allocTemp */
- void * (*allocFunc)(size_t size),
+ ISzAlloc *alloc,
ISzAlloc *allocTemp)
{
for (;;)
@@ -826,45 +821,44 @@ SZ_RESULT SzReadStreamsInfo(
UInt64 type;
RINOK(SzReadID(sd, &type));
if ((UInt64)(int)type != type)
- return SZE_FAIL;
+ return SZ_ERROR_UNSUPPORTED;
switch((int)type)
{
case k7zIdEnd:
return SZ_OK;
case k7zIdPackInfo:
{
- RINOK(SzReadPackInfo(sd, dataOffset, &db->NumPackStreams,
- &db->PackSizes, &db->PackCRCsDefined, &db->PackCRCs, allocFunc));
+ RINOK(SzReadPackInfo(sd, dataOffset, &p->NumPackStreams,
+ &p->PackSizes, &p->PackCRCsDefined, &p->PackCRCs, alloc));
break;
}
case k7zIdUnPackInfo:
{
- RINOK(SzReadUnPackInfo(sd, &db->NumFolders, &db->Folders, allocFunc, allocTemp));
+ RINOK(SzReadUnPackInfo(sd, &p->NumFolders, &p->Folders, alloc, allocTemp));
break;
}
case k7zIdSubStreamsInfo:
{
- RINOK(SzReadSubStreamsInfo(sd, db->NumFolders, db->Folders,
+ RINOK(SzReadSubStreamsInfo(sd, p->NumFolders, p->Folders,
numUnPackStreams, unPackSizes, digestsDefined, digests, allocTemp));
break;
}
default:
- return SZE_FAIL;
+ return SZ_ERROR_UNSUPPORTED;
}
}
}
Byte kUtf8Limits[5] = { 0xC0, 0xE0, 0xF0, 0xF8, 0xFC };
-SZ_RESULT SzReadFileNames(CSzData *sd, UInt32 numFiles, CFileItem *files,
- void * (*allocFunc)(size_t size))
+static SRes SzReadFileNames(CSzData *sd, UInt32 numFiles, CSzFileItem *files, ISzAlloc *alloc)
{
UInt32 i;
- for(i = 0; i < numFiles; i++)
+ for (i = 0; i < numFiles; i++)
{
UInt32 len = 0;
UInt32 pos = 0;
- CFileItem *file = files + i;
+ CSzFileItem *file = files + i;
while(pos + 2 <= sd->Size)
{
int numAdds;
@@ -879,13 +873,13 @@ SZ_RESULT SzReadFileNames(CSzData *sd, UInt32 numFiles, CFileItem *files,
{
UInt32 c2;
if (value >= 0xDC00)
- return SZE_ARCHIVE_ERROR;
+ return SZ_ERROR_ARCHIVE;
if (pos + 2 > sd->Size)
- return SZE_ARCHIVE_ERROR;
+ return SZ_ERROR_ARCHIVE;
c2 = (UInt32)(sd->Data[pos] | (((UInt32)sd->Data[pos + 1]) << 8));
pos += 2;
if (c2 < 0xDC00 || c2 >= 0xE000)
- return SZE_ARCHIVE_ERROR;
+ return SZ_ERROR_ARCHIVE;
value = ((value - 0xD800) << 10) | (c2 - 0xDC00);
}
for (numAdds = 1; numAdds < 5; numAdds++)
@@ -894,7 +888,7 @@ SZ_RESULT SzReadFileNames(CSzData *sd, UInt32 numFiles, CFileItem *files,
len += numAdds;
}
- MY_ALLOC(char, file->Name, (size_t)len, allocFunc);
+ MY_ALLOC(char, file->Name, (size_t)len, alloc);
len = 0;
while(2 <= sd->Size)
@@ -932,9 +926,9 @@ SZ_RESULT SzReadFileNames(CSzData *sd, UInt32 numFiles, CFileItem *files,
return SZ_OK;
}
-SZ_RESULT SzReadHeader2(
+static SRes SzReadHeader2(
+ CSzArEx *p, /* allocMain */
CSzData *sd,
- CArchiveDatabaseEx *db, /* allocMain */
CFileSize **unPackSizes, /* allocTemp */
Byte **digestsDefined, /* allocTemp */
UInt32 **digests, /* allocTemp */
@@ -947,7 +941,7 @@ SZ_RESULT SzReadHeader2(
UInt64 type;
UInt32 numUnPackStreams = 0;
UInt32 numFiles = 0;
- CFileItem *files = 0;
+ CSzFileItem *files = 0;
UInt32 numEmptyStreams = 0;
UInt32 i;
@@ -963,29 +957,29 @@ SZ_RESULT SzReadHeader2(
if (type == k7zIdMainStreamsInfo)
{
RINOK(SzReadStreamsInfo(sd,
- &db->ArchiveInfo.DataStartPosition,
- &db->Database,
+ &p->ArchiveInfo.DataStartPosition,
+ &p->db,
&numUnPackStreams,
unPackSizes,
digestsDefined,
- digests, allocMain->Alloc, allocTemp));
- db->ArchiveInfo.DataStartPosition += db->ArchiveInfo.StartPositionAfterHeader;
+ digests, allocMain, allocTemp));
+ p->ArchiveInfo.DataStartPosition += p->ArchiveInfo.StartPositionAfterHeader;
RINOK(SzReadID(sd, &type));
}
if (type == k7zIdEnd)
return SZ_OK;
if (type != k7zIdFilesInfo)
- return SZE_ARCHIVE_ERROR;
+ return SZ_ERROR_ARCHIVE;
RINOK(SzReadNumber32(sd, &numFiles));
- db->Database.NumFiles = numFiles;
+ p->db.NumFiles = numFiles;
- MY_ALLOC(CFileItem, files, (size_t)numFiles, allocMain->Alloc);
+ MY_ALLOC(CSzFileItem, files, (size_t)numFiles, allocMain);
- db->Database.Files = files;
- for(i = 0; i < numFiles; i++)
- SzFileInit(files + i);
+ p->db.Files = files;
+ for (i = 0; i < numFiles; i++)
+ SzFile_Init(files + i);
for (;;)
{
@@ -1006,12 +1000,12 @@ SZ_RESULT SzReadHeader2(
case k7zIdName:
{
RINOK(SzReadSwitch(sd));
- RINOK(SzReadFileNames(sd, numFiles, files, allocMain->Alloc))
+ RINOK(SzReadFileNames(sd, numFiles, files, allocMain))
break;
}
case k7zIdEmptyStream:
{
- RINOK(SzReadBoolVector(sd, numFiles, emptyStreamVector, allocTemp->Alloc));
+ RINOK(SzReadBoolVector(sd, numFiles, emptyStreamVector, allocTemp));
numEmptyStreams = 0;
for (i = 0; i < numFiles; i++)
if ((*emptyStreamVector)[i])
@@ -1020,16 +1014,16 @@ SZ_RESULT SzReadHeader2(
}
case k7zIdEmptyFile:
{
- RINOK(SzReadBoolVector(sd, numEmptyStreams, emptyFileVector, allocTemp->Alloc));
+ RINOK(SzReadBoolVector(sd, numEmptyStreams, emptyFileVector, allocTemp));
break;
}
case k7zIdLastWriteTime:
{
- RINOK(SzReadBoolVector2(sd, numFiles, lwtVector, allocTemp->Alloc));
+ RINOK(SzReadBoolVector2(sd, numFiles, lwtVector, allocTemp));
RINOK(SzReadSwitch(sd));
for (i = 0; i < numFiles; i++)
{
- CFileItem *f = &files[i];
+ CSzFileItem *f = &files[i];
Byte defined = (*lwtVector)[i];
f->IsLastWriteTimeDefined = defined;
f->LastWriteTime.Low = f->LastWriteTime.High = 0;
@@ -1051,9 +1045,9 @@ SZ_RESULT SzReadHeader2(
{
UInt32 emptyFileIndex = 0;
UInt32 sizeIndex = 0;
- for(i = 0; i < numFiles; i++)
+ for (i = 0; i < numFiles; i++)
{
- CFileItem *file = files + i;
+ CSzFileItem *file = files + i;
file->IsAnti = 0;
if (*emptyStreamVector == 0)
file->HasStream = 1;
@@ -1079,12 +1073,12 @@ SZ_RESULT SzReadHeader2(
}
}
}
- return SzArDbExFill(db, allocMain->Alloc);
+ return SzArEx_Fill(p, allocMain);
}
-SZ_RESULT SzReadHeader(
+static SRes SzReadHeader(
+ CSzArEx *p,
CSzData *sd,
- CArchiveDatabaseEx *db,
ISzAlloc *allocMain,
ISzAlloc *allocTemp)
{
@@ -1094,118 +1088,89 @@ SZ_RESULT SzReadHeader(
Byte *emptyStreamVector = 0;
Byte *emptyFileVector = 0;
Byte *lwtVector = 0;
- SZ_RESULT res = SzReadHeader2(sd, db,
+ SRes res = SzReadHeader2(p, sd,
&unPackSizes, &digestsDefined, &digests,
&emptyStreamVector, &emptyFileVector, &lwtVector,
allocMain, allocTemp);
- allocTemp->Free(unPackSizes);
- allocTemp->Free(digestsDefined);
- allocTemp->Free(digests);
- allocTemp->Free(emptyStreamVector);
- allocTemp->Free(emptyFileVector);
- allocTemp->Free(lwtVector);
+ IAlloc_Free(allocTemp, unPackSizes);
+ IAlloc_Free(allocTemp, digestsDefined);
+ IAlloc_Free(allocTemp, digests);
+ IAlloc_Free(allocTemp, emptyStreamVector);
+ IAlloc_Free(allocTemp, emptyFileVector);
+ IAlloc_Free(allocTemp, lwtVector);
return res;
}
-SZ_RESULT SzReadAndDecodePackedStreams2(
+static SRes SzReadAndDecodePackedStreams2(
ISzInStream *inStream,
CSzData *sd,
- CSzByteBuffer *outBuffer,
+ CBuf *outBuffer,
CFileSize baseOffset,
- CArchiveDatabase *db,
+ CSzAr *p,
CFileSize **unPackSizes,
Byte **digestsDefined,
UInt32 **digests,
- #ifndef _LZMA_IN_CB
- Byte **inBuffer,
- #endif
ISzAlloc *allocTemp)
{
UInt32 numUnPackStreams = 0;
CFileSize dataStartPos;
- CFolder *folder;
- #ifndef _LZMA_IN_CB
- CFileSize packSize = 0;
- UInt32 i = 0;
- #endif
+ CSzFolder *folder;
CFileSize unPackSize;
- SZ_RESULT res;
+ SRes res;
- RINOK(SzReadStreamsInfo(sd, &dataStartPos, db,
+ RINOK(SzReadStreamsInfo(sd, &dataStartPos, p,
&numUnPackStreams, unPackSizes, digestsDefined, digests,
- allocTemp->Alloc, allocTemp));
+ allocTemp, allocTemp));
dataStartPos += baseOffset;
- if (db->NumFolders != 1)
- return SZE_ARCHIVE_ERROR;
+ if (p->NumFolders != 1)
+ return SZ_ERROR_ARCHIVE;
- folder = db->Folders;
- unPackSize = SzFolderGetUnPackSize(folder);
+ folder = p->Folders;
+ unPackSize = SzFolder_GetUnPackSize(folder);
- RINOK(inStream->Seek(inStream, dataStartPos));
-
- #ifndef _LZMA_IN_CB
- for (i = 0; i < db->NumPackStreams; i++)
- packSize += db->PackSizes[i];
+ RINOK(inStream->Seek(inStream, dataStartPos, SZ_SEEK_SET));
- MY_ALLOC(Byte, *inBuffer, (size_t)packSize, allocTemp->Alloc);
-
- RINOK(SafeReadDirect(inStream, *inBuffer, (size_t)packSize));
- #endif
-
- if (!SzByteBufferCreate(outBuffer, (size_t)unPackSize, allocTemp->Alloc))
- return SZE_OUTOFMEMORY;
+ if (!Buf_Create(outBuffer, (size_t)unPackSize, allocTemp))
+ return SZ_ERROR_MEM;
- res = SzDecode(db->PackSizes, folder,
- #ifdef _LZMA_IN_CB
+ res = SzDecode(p->PackSizes, folder,
inStream, dataStartPos,
- #else
- *inBuffer,
- #endif
- outBuffer->Items, (size_t)unPackSize, allocTemp);
- RINOK(res)
+ outBuffer->data, (size_t)unPackSize, allocTemp);
+ RINOK(res);
if (folder->UnPackCRCDefined)
- if (CrcCalc(outBuffer->Items, (size_t)unPackSize) != folder->UnPackCRC)
- return SZE_FAIL;
+ if (CrcCalc(outBuffer->data, (size_t)unPackSize) != folder->UnPackCRC)
+ return SZ_ERROR_CRC;
return SZ_OK;
}
-SZ_RESULT SzReadAndDecodePackedStreams(
+static SRes SzReadAndDecodePackedStreams(
ISzInStream *inStream,
CSzData *sd,
- CSzByteBuffer *outBuffer,
+ CBuf *outBuffer,
CFileSize baseOffset,
ISzAlloc *allocTemp)
{
- CArchiveDatabase db;
+ CSzAr p;
CFileSize *unPackSizes = 0;
Byte *digestsDefined = 0;
UInt32 *digests = 0;
- #ifndef _LZMA_IN_CB
- Byte *inBuffer = 0;
- #endif
- SZ_RESULT res;
- SzArchiveDatabaseInit(&db);
+ SRes res;
+ SzAr_Init(&p);
res = SzReadAndDecodePackedStreams2(inStream, sd, outBuffer, baseOffset,
- &db, &unPackSizes, &digestsDefined, &digests,
- #ifndef _LZMA_IN_CB
- &inBuffer,
- #endif
+ &p, &unPackSizes, &digestsDefined, &digests,
allocTemp);
- SzArchiveDatabaseFree(&db, allocTemp->Free);
- allocTemp->Free(unPackSizes);
- allocTemp->Free(digestsDefined);
- allocTemp->Free(digests);
- #ifndef _LZMA_IN_CB
- allocTemp->Free(inBuffer);
- #endif
+ SzAr_Free(&p, allocTemp);
+ IAlloc_Free(allocTemp, unPackSizes);
+ IAlloc_Free(allocTemp, digestsDefined);
+ IAlloc_Free(allocTemp, digests);
return res;
}
-SZ_RESULT SzArchiveOpen2(
+static SRes SzArEx_Open2(
+ CSzArEx *p,
ISzInStream *inStream,
- CArchiveDatabaseEx *db,
ISzAlloc *allocMain,
ISzAlloc *allocTemp)
{
@@ -1217,22 +1182,23 @@ SZ_RESULT SzArchiveOpen2(
UInt32 nextHeaderCRC;
UInt32 crc = 0;
CFileSize pos = 0;
- CSzByteBuffer buffer;
+ CBuf buffer;
CSzData sd;
- SZ_RESULT res;
+ SRes res;
- RINOK(SafeReadDirect(inStream, signature, k7zSignatureSize));
+ if (SafeReadDirect(inStream, signature, k7zSignatureSize) != SZ_OK)
+ return SZ_ERROR_NO_ARCHIVE;
if (!TestSignatureCandidate(signature))
- return SZE_ARCHIVE_ERROR;
+ return SZ_ERROR_NO_ARCHIVE;
/*
- db.Clear();
- db.ArchiveInfo.StartPosition = _arhiveBeginStreamPosition;
+ p.Clear();
+ p.ArchiveInfo.StartPosition = _arhiveBeginStreamPosition;
*/
RINOK(SafeReadDirectByte(inStream, &version));
if (version != k7zMajorVersion)
- return SZE_ARCHIVE_ERROR;
+ return SZ_ERROR_UNSUPPORTED;
RINOK(SafeReadDirectByte(inStream, &version));
RINOK(SafeReadDirectUInt32(inStream, &crcFromArchive, &crc));
@@ -1243,72 +1209,69 @@ SZ_RESULT SzArchiveOpen2(
RINOK(SafeReadDirectUInt32(inStream, &nextHeaderCRC, &crc));
pos = k7zStartHeaderSize;
- db->ArchiveInfo.StartPositionAfterHeader = pos;
+ p->ArchiveInfo.StartPositionAfterHeader = pos;
if (CRC_GET_DIGEST(crc) != crcFromArchive)
- return SZE_ARCHIVE_ERROR;
+ return SZ_ERROR_CRC;
if (nextHeaderSize == 0)
return SZ_OK;
- RINOK(inStream->Seek(inStream, (CFileSize)(pos + nextHeaderOffset)));
+ RINOK(inStream->Seek(inStream, (CFileSize)(pos + nextHeaderOffset), SZ_SEEK_SET));
- if (!SzByteBufferCreate(&buffer, (size_t)nextHeaderSize, allocTemp->Alloc))
- return SZE_OUTOFMEMORY;
+ if (!Buf_Create(&buffer, (size_t)nextHeaderSize, allocTemp))
+ return SZ_ERROR_MEM;
- res = SafeReadDirect(inStream, buffer.Items, (size_t)nextHeaderSize);
+ res = SafeReadDirect(inStream, buffer.data, (size_t)nextHeaderSize);
if (res == SZ_OK)
{
- res = SZE_ARCHIVE_ERROR;
- if (CrcCalc(buffer.Items, (UInt32)nextHeaderSize) == nextHeaderCRC)
+ res = SZ_ERROR_ARCHIVE;
+ if (CrcCalc(buffer.data, (size_t)nextHeaderSize) == nextHeaderCRC)
{
for (;;)
{
UInt64 type;
- sd.Data = buffer.Items;
- sd.Size = buffer.Capacity;
+ sd.Data = buffer.data;
+ sd.Size = buffer.size;
res = SzReadID(&sd, &type);
if (res != SZ_OK)
break;
if (type == k7zIdHeader)
{
- res = SzReadHeader(&sd, db, allocMain, allocTemp);
+ res = SzReadHeader(p, &sd, allocMain, allocTemp);
break;
}
if (type != k7zIdEncodedHeader)
{
- res = SZE_ARCHIVE_ERROR;
+ res = SZ_ERROR_UNSUPPORTED;
break;
}
{
- CSzByteBuffer outBuffer;
+ CBuf outBuffer;
+ Buf_Init(&outBuffer);
res = SzReadAndDecodePackedStreams(inStream, &sd, &outBuffer,
- db->ArchiveInfo.StartPositionAfterHeader,
+ p->ArchiveInfo.StartPositionAfterHeader,
allocTemp);
if (res != SZ_OK)
{
- SzByteBufferFree(&outBuffer, allocTemp->Free);
+ Buf_Free(&outBuffer, allocTemp);
break;
}
- SzByteBufferFree(&buffer, allocTemp->Free);
- buffer.Items = outBuffer.Items;
- buffer.Capacity = outBuffer.Capacity;
+ Buf_Free(&buffer, allocTemp);
+ buffer.data = outBuffer.data;
+ buffer.size = outBuffer.size;
}
}
}
}
- SzByteBufferFree(&buffer, allocTemp->Free);
+ Buf_Free(&buffer, allocTemp);
return res;
}
-SZ_RESULT SzArchiveOpen(
- ISzInStream *inStream,
- CArchiveDatabaseEx *db,
- ISzAlloc *allocMain,
- ISzAlloc *allocTemp)
+SRes SzArEx_Open(CSzArEx *p, ISzInStream *inStream, ISzAlloc *allocMain, ISzAlloc *allocTemp)
{
- SZ_RESULT res = SzArchiveOpen2(inStream, db, allocMain, allocTemp);
+ SRes res = SzArEx_Open2(p, inStream, allocMain, allocTemp);
if (res != SZ_OK)
- SzArDbExFree(db, allocMain->Free);
+ SzArEx_Free(p, allocMain);
return res;
}
diff --git a/C/Archive/7z/7zIn.h b/C/Archive/7z/7zIn.h
index 0b4ca08d..811bbb66 100755
--- a/C/Archive/7z/7zIn.h
+++ b/C/Archive/7z/7zIn.h
@@ -1,55 +1,63 @@
-/* 7zIn.h */
+/* 7zIn.h -- 7z Input functions
+2008-05-05
+Igor Pavlov
+Copyright (c) 1999-2008 Igor Pavlov
+Read 7zItem.h for license options */
#ifndef __7Z_IN_H
#define __7Z_IN_H
#include "7zHeader.h"
#include "7zItem.h"
-#include "7zAlloc.h"
-
-typedef struct _CInArchiveInfo
+
+typedef struct
{
CFileSize StartPositionAfterHeader;
CFileSize DataStartPosition;
-}CInArchiveInfo;
+} CInArchiveInfo;
-typedef struct _CArchiveDatabaseEx
+typedef struct
{
- CArchiveDatabase Database;
+ CSzAr db;
CInArchiveInfo ArchiveInfo;
UInt32 *FolderStartPackStreamIndex;
CFileSize *PackStreamStartPositions;
UInt32 *FolderStartFileIndex;
UInt32 *FileIndexToFolderIndexMap;
-}CArchiveDatabaseEx;
+} CSzArEx;
-void SzArDbExInit(CArchiveDatabaseEx *db);
-void SzArDbExFree(CArchiveDatabaseEx *db, void (*freeFunc)(void *));
-CFileSize SzArDbGetFolderStreamPos(CArchiveDatabaseEx *db, UInt32 folderIndex, UInt32 indexInFolder);
-int SzArDbGetFolderFullPackSize(CArchiveDatabaseEx *db, UInt32 folderIndex, CFileSize *resSize);
+void SzArEx_Init(CSzArEx *p);
+void SzArEx_Free(CSzArEx *p, ISzAlloc *alloc);
+CFileSize SzArEx_GetFolderStreamPos(const CSzArEx *p, UInt32 folderIndex, UInt32 indexInFolder);
+int SzArEx_GetFolderFullPackSize(const CSzArEx *p, UInt32 folderIndex, CFileSize *resSize);
-typedef struct _ISzInStream
+typedef enum
{
- #ifdef _LZMA_IN_CB
- SZ_RESULT (*Read)(
- void *object, /* pointer to ISzInStream itself */
- void **buffer, /* out: pointer to buffer with data */
- size_t maxRequiredSize, /* max required size to read */
- size_t *processedSize); /* real processed size.
- processedSize can be less than maxRequiredSize.
- If processedSize == 0, then there are no more
- bytes in stream. */
- #else
- SZ_RESULT (*Read)(void *object, void *buffer, size_t size, size_t *processedSize);
- #endif
- SZ_RESULT (*Seek)(void *object, CFileSize pos);
+ SZ_SEEK_SET = 0,
+ SZ_SEEK_CUR = 1,
+ SZ_SEEK_END = 2
+} ESzSeek;
+
+typedef struct
+{
+ SRes (*Read)(void *object, void **buf, size_t *size);
+ /* if (input(*size) != 0 && output(*size) == 0) means end_of_stream.
+ (output(*size) < input(*size)) is allowed */
+ SRes (*Seek)(void *object, CFileSize pos, ESzSeek origin);
} ISzInStream;
-int SzArchiveOpen(
- ISzInStream *inStream,
- CArchiveDatabaseEx *db,
- ISzAlloc *allocMain,
- ISzAlloc *allocTemp);
+/*
+Errors:
+SZ_ERROR_NO_ARCHIVE
+SZ_ERROR_ARCHIVE
+SZ_ERROR_UNSUPPORTED
+SZ_ERROR_MEM
+SZ_ERROR_CRC
+SZ_ERROR_INPUT_EOF
+SZ_ERROR_FAIL
+*/
+
+SRes SzArEx_Open(CSzArEx *p, ISzInStream *inStream, ISzAlloc *allocMain, ISzAlloc *allocTemp);
#endif
diff --git a/C/Archive/7z/7zItem.c b/C/Archive/7z/7zItem.c
index a88afe9a..7a5ad427 100755
--- a/C/Archive/7z/7zItem.c
+++ b/C/Archive/7z/7zItem.c
@@ -1,134 +1,130 @@
-/* 7zItem.c */
+/* 7zItem.c -- 7z Items
+2008-04-09
+Igor Pavlov
+Copyright (c) 1999-2008 Igor Pavlov
+Read 7zItem.h for license options */
#include "7zItem.h"
-#include "7zAlloc.h"
-void SzCoderInfoInit(CCoderInfo *coder)
+void SzCoderInfo_Init(CSzCoderInfo *p)
{
- SzByteBufferInit(&coder->Properties);
+ Buf_Init(&p->Props);
}
-void SzCoderInfoFree(CCoderInfo *coder, void (*freeFunc)(void *p))
+void SzCoderInfo_Free(CSzCoderInfo *p, ISzAlloc *alloc)
{
- SzByteBufferFree(&coder->Properties, freeFunc);
- SzCoderInfoInit(coder);
+ Buf_Free(&p->Props, alloc);
+ SzCoderInfo_Init(p);
}
-void SzFolderInit(CFolder *folder)
+void SzFolder_Init(CSzFolder *p)
{
- folder->NumCoders = 0;
- folder->Coders = 0;
- folder->NumBindPairs = 0;
- folder->BindPairs = 0;
- folder->NumPackStreams = 0;
- folder->PackStreams = 0;
- folder->UnPackSizes = 0;
- folder->UnPackCRCDefined = 0;
- folder->UnPackCRC = 0;
- folder->NumUnPackStreams = 0;
+ p->Coders = 0;
+ p->BindPairs = 0;
+ p->PackStreams = 0;
+ p->UnPackSizes = 0;
+ p->NumCoders = 0;
+ p->NumBindPairs = 0;
+ p->NumPackStreams = 0;
+ p->UnPackCRCDefined = 0;
+ p->UnPackCRC = 0;
+ p->NumUnPackStreams = 0;
}
-void SzFolderFree(CFolder *folder, void (*freeFunc)(void *p))
+void SzFolder_Free(CSzFolder *p, ISzAlloc *alloc)
{
UInt32 i;
- for (i = 0; i < folder->NumCoders; i++)
- SzCoderInfoFree(&folder->Coders[i], freeFunc);
- freeFunc(folder->Coders);
- freeFunc(folder->BindPairs);
- freeFunc(folder->PackStreams);
- freeFunc(folder->UnPackSizes);
- SzFolderInit(folder);
+ if (p->Coders)
+ for (i = 0; i < p->NumCoders; i++)
+ SzCoderInfo_Free(&p->Coders[i], alloc);
+ IAlloc_Free(alloc, p->Coders);
+ IAlloc_Free(alloc, p->BindPairs);
+ IAlloc_Free(alloc, p->PackStreams);
+ IAlloc_Free(alloc, p->UnPackSizes);
+ SzFolder_Init(p);
}
-UInt32 SzFolderGetNumOutStreams(CFolder *folder)
+UInt32 SzFolder_GetNumOutStreams(CSzFolder *p)
{
UInt32 result = 0;
UInt32 i;
- for (i = 0; i < folder->NumCoders; i++)
- result += folder->Coders[i].NumOutStreams;
+ for (i = 0; i < p->NumCoders; i++)
+ result += p->Coders[i].NumOutStreams;
return result;
}
-int SzFolderFindBindPairForInStream(CFolder *folder, UInt32 inStreamIndex)
+int SzFolder_FindBindPairForInStream(CSzFolder *p, UInt32 inStreamIndex)
{
UInt32 i;
- for(i = 0; i < folder->NumBindPairs; i++)
- if (folder->BindPairs[i].InIndex == inStreamIndex)
+ for (i = 0; i < p->NumBindPairs; i++)
+ if (p->BindPairs[i].InIndex == inStreamIndex)
return i;
return -1;
}
-int SzFolderFindBindPairForOutStream(CFolder *folder, UInt32 outStreamIndex)
+int SzFolder_FindBindPairForOutStream(CSzFolder *p, UInt32 outStreamIndex)
{
UInt32 i;
- for(i = 0; i < folder->NumBindPairs; i++)
- if (folder->BindPairs[i].OutIndex == outStreamIndex)
+ for (i = 0; i < p->NumBindPairs; i++)
+ if (p->BindPairs[i].OutIndex == outStreamIndex)
return i;
return -1;
}
-CFileSize SzFolderGetUnPackSize(CFolder *folder)
+CFileSize SzFolder_GetUnPackSize(CSzFolder *p)
{
- int i = (int)SzFolderGetNumOutStreams(folder);
+ int i = (int)SzFolder_GetNumOutStreams(p);
if (i == 0)
return 0;
for (i--; i >= 0; i--)
- if (SzFolderFindBindPairForOutStream(folder, i) < 0)
- return folder->UnPackSizes[i];
+ if (SzFolder_FindBindPairForOutStream(p, i) < 0)
+ return p->UnPackSizes[i];
/* throw 1; */
return 0;
}
-/*
-int FindPackStreamArrayIndex(int inStreamIndex) const
+void SzFile_Init(CSzFileItem *p)
{
- for(int i = 0; i < PackStreams.Size(); i++)
- if (PackStreams[i] == inStreamIndex)
- return i;
- return -1;
-}
-*/
-
-void SzFileInit(CFileItem *fileItem)
-{
- fileItem->IsFileCRCDefined = 0;
- fileItem->HasStream = 1;
- fileItem->IsDirectory = 0;
- fileItem->IsAnti = 0;
- fileItem->IsLastWriteTimeDefined = 0;
- fileItem->Name = 0;
+ p->IsFileCRCDefined = 0;
+ p->HasStream = 1;
+ p->IsDirectory = 0;
+ p->IsAnti = 0;
+ p->IsLastWriteTimeDefined = 0;
+ p->Name = 0;
}
-void SzFileFree(CFileItem *fileItem, void (*freeFunc)(void *p))
+static void SzFile_Free(CSzFileItem *p, ISzAlloc *alloc)
{
- freeFunc(fileItem->Name);
- SzFileInit(fileItem);
+ IAlloc_Free(alloc, p->Name);
+ SzFile_Init(p);
}
-void SzArchiveDatabaseInit(CArchiveDatabase *db)
+void SzAr_Init(CSzAr *p)
{
- db->NumPackStreams = 0;
- db->PackSizes = 0;
- db->PackCRCsDefined = 0;
- db->PackCRCs = 0;
- db->NumFolders = 0;
- db->Folders = 0;
- db->NumFiles = 0;
- db->Files = 0;
+ p->PackSizes = 0;
+ p->PackCRCsDefined = 0;
+ p->PackCRCs = 0;
+ p->Folders = 0;
+ p->Files = 0;
+ p->NumPackStreams = 0;
+ p->NumFolders = 0;
+ p->NumFiles = 0;
}
-void SzArchiveDatabaseFree(CArchiveDatabase *db, void (*freeFunc)(void *))
+void SzAr_Free(CSzAr *p, ISzAlloc *alloc)
{
UInt32 i;
- for (i = 0; i < db->NumFolders; i++)
- SzFolderFree(&db->Folders[i], freeFunc);
- for (i = 0; i < db->NumFiles; i++)
- SzFileFree(&db->Files[i], freeFunc);
- freeFunc(db->PackSizes);
- freeFunc(db->PackCRCsDefined);
- freeFunc(db->PackCRCs);
- freeFunc(db->Folders);
- freeFunc(db->Files);
- SzArchiveDatabaseInit(db);
+ if (p->Folders)
+ for (i = 0; i < p->NumFolders; i++)
+ SzFolder_Free(&p->Folders[i], alloc);
+ if (p->Files)
+ for (i = 0; i < p->NumFiles; i++)
+ SzFile_Free(&p->Files[i], alloc);
+ IAlloc_Free(alloc, p->PackSizes);
+ IAlloc_Free(alloc, p->PackCRCsDefined);
+ IAlloc_Free(alloc, p->PackCRCs);
+ IAlloc_Free(alloc, p->Folders);
+ IAlloc_Free(alloc, p->Files);
+ SzAr_Init(p);
}
diff --git a/C/Archive/7z/7zItem.h b/C/Archive/7z/7zItem.h
index 05567bff..074a3a99 100755
--- a/C/Archive/7z/7zItem.h
+++ b/C/Archive/7z/7zItem.h
@@ -1,66 +1,79 @@
-/* 7zItem.h */
+/* 7zItem.h -- 7z Items
+2008-05-01
+Igor Pavlov
+Copyright (c) 1999-2008 Igor Pavlov
+Read LzmaDec.h for license options */
#ifndef __7Z_ITEM_H
#define __7Z_ITEM_H
-#include "7zMethodID.h"
-#include "7zHeader.h"
-#include "7zBuffer.h"
+#include "../../7zBuf.h"
-typedef struct _CCoderInfo
+/* #define _SZ_FILE_SIZE_32 */
+/* You can define _SZ_FILE_SIZE_32, if you don't need support for files larger than 4 GB*/
+
+#ifdef _SZ_FILE_SIZE_32
+typedef UInt32 CFileSize;
+#else
+typedef UInt64 CFileSize;
+#endif
+
+typedef UInt64 CMethodID;
+
+typedef struct
{
UInt32 NumInStreams;
UInt32 NumOutStreams;
CMethodID MethodID;
- CSzByteBuffer Properties;
-}CCoderInfo;
+ CBuf Props;
+} CSzCoderInfo;
-void SzCoderInfoInit(CCoderInfo *coder);
-void SzCoderInfoFree(CCoderInfo *coder, void (*freeFunc)(void *p));
+void SzCoderInfo_Init(CSzCoderInfo *p);
+void SzCoderInfo_Free(CSzCoderInfo *p, ISzAlloc *alloc);
-typedef struct _CBindPair
+typedef struct
{
UInt32 InIndex;
UInt32 OutIndex;
-}CBindPair;
+} CBindPair;
-typedef struct _CFolder
+typedef struct
{
- UInt32 NumCoders;
- CCoderInfo *Coders;
- UInt32 NumBindPairs;
+ CSzCoderInfo *Coders;
CBindPair *BindPairs;
- UInt32 NumPackStreams;
UInt32 *PackStreams;
CFileSize *UnPackSizes;
+ UInt32 NumCoders;
+ UInt32 NumBindPairs;
+ UInt32 NumPackStreams;
int UnPackCRCDefined;
UInt32 UnPackCRC;
UInt32 NumUnPackStreams;
-}CFolder;
+} CSzFolder;
-void SzFolderInit(CFolder *folder);
-CFileSize SzFolderGetUnPackSize(CFolder *folder);
-int SzFolderFindBindPairForInStream(CFolder *folder, UInt32 inStreamIndex);
-UInt32 SzFolderGetNumOutStreams(CFolder *folder);
-CFileSize SzFolderGetUnPackSize(CFolder *folder);
+void SzFolder_Init(CSzFolder *p);
+CFileSize SzFolder_GetUnPackSize(CSzFolder *p);
+int SzFolder_FindBindPairForInStream(CSzFolder *p, UInt32 inStreamIndex);
+UInt32 SzFolder_GetNumOutStreams(CSzFolder *p);
+CFileSize SzFolder_GetUnPackSize(CSzFolder *p);
-typedef struct _CArchiveFileTime
+typedef struct
{
UInt32 Low;
UInt32 High;
-} CArchiveFileTime;
+} CNtfsFileTime;
-typedef struct _CFileItem
+typedef struct
{
- CArchiveFileTime LastWriteTime;
+ CNtfsFileTime LastWriteTime;
/*
CFileSize StartPos;
UInt32 Attributes;
*/
CFileSize Size;
- UInt32 FileCRC;
char *Name;
+ UInt32 FileCRC;
Byte IsFileCRCDefined;
Byte HasStream;
@@ -72,24 +85,23 @@ typedef struct _CFileItem
int IsLastWriteTimeDefined;
int IsStartPosDefined;
*/
-}CFileItem;
+} CSzFileItem;
-void SzFileInit(CFileItem *fileItem);
+void SzFile_Init(CSzFileItem *p);
-typedef struct _CArchiveDatabase
+typedef struct
{
- UInt32 NumPackStreams;
CFileSize *PackSizes;
Byte *PackCRCsDefined;
UInt32 *PackCRCs;
+ CSzFolder *Folders;
+ CSzFileItem *Files;
+ UInt32 NumPackStreams;
UInt32 NumFolders;
- CFolder *Folders;
UInt32 NumFiles;
- CFileItem *Files;
-}CArchiveDatabase;
-
-void SzArchiveDatabaseInit(CArchiveDatabase *db);
-void SzArchiveDatabaseFree(CArchiveDatabase *db, void (*freeFunc)(void *));
+} CSzAr;
+void SzAr_Init(CSzAr *p);
+void SzAr_Free(CSzAr *p, ISzAlloc *alloc);
#endif
diff --git a/C/Archive/7z/7zMain.c b/C/Archive/7z/7zMain.c
index 0deef893..62f50689 100755
--- a/C/Archive/7z/7zMain.c
+++ b/C/Archive/7z/7zMain.c
@@ -1,8 +1,7 @@
-/*
-7zMain.c
-Test application for 7z Decoder
-LZMA SDK 4.43 Copyright (c) 1999-2006 Igor Pavlov (2006-06-04)
-*/
+/* 7zMain.c - Test application for 7z Decoder
+2008-04-09
+Igor Pavlov
+Public domain */
#include <stdio.h>
#include <stdlib.h>
@@ -18,6 +17,7 @@ LZMA SDK 4.43 Copyright (c) 1999-2006 Igor Pavlov (2006-06-04)
#include "7zIn.h"
#include "7zExtract.h"
+#include "7zAlloc.h"
#include "../../7zCrc.h"
@@ -48,7 +48,7 @@ void ConvertNumberToString(CFileSize value, char *s)
#define PERIOD_100 (PERIOD_4 * 25 - 1)
#define PERIOD_400 (PERIOD_100 * 4 + 1)
-void ConvertFileTimeToString(CArchiveFileTime *ft, char *s)
+void ConvertFileTimeToString(CNtfsFileTime *ft, char *s)
{
unsigned year, mon, day, hour, min, sec;
UInt64 v64 = ft->Low | ((UInt64)ft->High << 32);
@@ -177,61 +177,59 @@ typedef struct _CFileInStream
MY_FILE_HANDLE File;
} CFileInStream;
-#ifdef _LZMA_IN_CB
#define kBufferSize (1 << 12)
Byte g_Buffer[kBufferSize];
-SZ_RESULT SzFileReadImp(void *object, void **buffer, size_t maxRequiredSize, size_t *processedSize)
+SRes SzFileReadImp(void *object, void **buffer, size_t *size)
{
CFileInStream *s = (CFileInStream *)object;
- size_t processedSizeLoc;
- if (maxRequiredSize > kBufferSize)
- maxRequiredSize = kBufferSize;
- processedSizeLoc = MyReadFile(s->File, g_Buffer, maxRequiredSize);
+ if (*size > kBufferSize)
+ *size = kBufferSize;
+ *size = MyReadFile(s->File, g_Buffer, *size);
*buffer = g_Buffer;
- if (processedSize != 0)
- *processedSize = processedSizeLoc;
return SZ_OK;
}
-#else
-
-SZ_RESULT SzFileReadImp(void *object, void *buffer, size_t size, size_t *processedSize)
-{
- CFileInStream *s = (CFileInStream *)object;
- size_t processedSizeLoc = MyReadFile(s->File, buffer, size);
- if (processedSize != 0)
- *processedSize = processedSizeLoc;
- return SZ_OK;
-}
-
-#endif
-
-SZ_RESULT SzFileSeekImp(void *object, CFileSize pos)
+SRes SzFileSeekImp(void *object, CFileSize pos, ESzSeek origin)
{
CFileInStream *s = (CFileInStream *)object;
#ifdef USE_WINDOWS_FUNCTIONS
{
LARGE_INTEGER value;
+ DWORD moveMethod;
value.LowPart = (DWORD)pos;
value.HighPart = (LONG)((UInt64)pos >> 32);
#ifdef _SZ_FILE_SIZE_32
/* VC 6.0 has bug with >> 32 shifts. */
value.HighPart = 0;
#endif
- value.LowPart = SetFilePointer(s->File, value.LowPart, &value.HighPart, FILE_BEGIN);
+ switch (origin)
+ {
+ case SZ_SEEK_SET: moveMethod = FILE_BEGIN; break;
+ case SZ_SEEK_CUR: moveMethod = FILE_CURRENT; break;
+ case SZ_SEEK_END: moveMethod = FILE_END; break;
+ default: return SZ_ERROR_PARAM;
+ }
+ value.LowPart = SetFilePointer(s->File, value.LowPart, &value.HighPart, moveMethod);
if (value.LowPart == 0xFFFFFFFF)
- if(GetLastError() != NO_ERROR)
- return SZE_FAIL;
+ if (GetLastError() != NO_ERROR)
+ return SZ_ERROR_FAIL;
return SZ_OK;
}
#else
- int res = fseek(s->File, (long)pos, SEEK_SET);
- if (res == 0)
- return SZ_OK;
- return SZE_FAIL;
+ int moveMethod;
+ int res;
+ switch (origin)
+ {
+ case SZ_SEEK_SET: moveMethod = SEEK_SET; break;
+ case SZ_SEEK_CUR: moveMethod = SEEK_CUR; break;
+ case SZ_SEEK_END: moveMethod = SEEK_END; break;
+ default: return SZ_ERROR_PARAM;
+ }
+ res = fseek(s->File, (long)pos, moveMethod );
+ return (res == 0) ? SZ_OK : SZ_ERROR_FAIL;
#endif
}
@@ -240,15 +238,15 @@ void PrintError(char *sz)
printf("\nERROR: %s\n", sz);
}
-int main(int numargs, char *args[])
+int MY_CDECL main(int numargs, char *args[])
{
CFileInStream archiveStream;
- CArchiveDatabaseEx db;
- SZ_RESULT res;
+ CSzArEx db;
+ SRes res;
ISzAlloc allocImp;
ISzAlloc allocTempImp;
- printf("\n7z ANSI-C Decoder 4.48 Copyright (c) 1999-2007 Igor Pavlov 2007-06-21\n");
+ printf("\n7z ANSI-C Decoder 4.58 Copyright (c) 1999-2008 Igor Pavlov 2008-04-09\n");
if (numargs == 1)
{
printf(
@@ -267,7 +265,7 @@ int main(int numargs, char *args[])
archiveStream.File =
#ifdef USE_WINDOWS_FUNCTIONS
- CreateFile(args[2], GENERIC_READ, FILE_SHARE_READ,
+ CreateFileA(args[2], GENERIC_READ, FILE_SHARE_READ,
NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL);
if (archiveStream.File == INVALID_HANDLE_VALUE)
#else
@@ -290,8 +288,8 @@ int main(int numargs, char *args[])
CrcGenerateTable();
- SzArDbExInit(&db);
- res = SzArchiveOpen(&archiveStream.InStream, &db, &allocImp, &allocTempImp);
+ SzArEx_Init(&db);
+ res = SzArEx_Open(&db, &archiveStream.InStream, &allocImp, &allocTempImp);
if (res == SZ_OK)
{
char *command = args[1];
@@ -308,9 +306,9 @@ int main(int numargs, char *args[])
if (listCommand)
{
UInt32 i;
- for (i = 0; i < db.Database.NumFiles; i++)
+ for (i = 0; i < db.db.NumFiles; i++)
{
- CFileItem *f = db.Database.Files + i;
+ CSzFileItem *f = db.db.Files + i;
char s[32], t[32];
ConvertNumberToString(f->Size, s);
if (f->IsLastWriteTimeDefined)
@@ -334,11 +332,11 @@ int main(int numargs, char *args[])
size_t outBufferSize = 0; /* it can have any value before first call (if outBuffer = 0) */
printf("\n");
- for (i = 0; i < db.Database.NumFiles; i++)
+ for (i = 0; i < db.db.NumFiles; i++)
{
size_t offset;
size_t outSizeProcessed;
- CFileItem *f = db.Database.Files + i;
+ CSzFileItem *f = db.db.Files + i;
if (f->IsDirectory)
printf("Directory ");
else
@@ -351,7 +349,7 @@ int main(int numargs, char *args[])
printf("\n");
continue;
}
- res = SzExtract(&archiveStream.InStream, &db, i,
+ res = SzAr_Extract(&db, &archiveStream.InStream, i,
&blockIndex, &outBuffer, &outBufferSize,
&offset, &outSizeProcessed,
&allocImp, &allocTempImp);
@@ -372,7 +370,7 @@ int main(int numargs, char *args[])
outputHandle =
#ifdef USE_WINDOWS_FUNCTIONS
- CreateFile(fileName, GENERIC_WRITE, FILE_SHARE_READ,
+ CreateFileA(fileName, GENERIC_WRITE, FILE_SHARE_READ,
NULL, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL);
if (outputHandle == INVALID_HANDLE_VALUE)
#else
@@ -381,34 +379,34 @@ int main(int numargs, char *args[])
#endif
{
PrintError("can not open output file");
- res = SZE_FAIL;
+ res = SZ_ERROR_FAIL;
break;
}
processedSize = MyWriteFile(outputHandle, outBuffer + offset, outSizeProcessed);
if (processedSize != outSizeProcessed)
{
PrintError("can not write output file");
- res = SZE_FAIL;
+ res = SZ_ERROR_FAIL;
break;
}
if (MyCloseFile(outputHandle))
{
PrintError("can not close output file");
- res = SZE_FAIL;
+ res = SZ_ERROR_FAIL;
break;
}
}
printf("\n");
}
- allocImp.Free(outBuffer);
+ IAlloc_Free(&allocImp, outBuffer);
}
else
{
PrintError("incorrect command");
- res = SZE_FAIL;
+ res = SZ_ERROR_FAIL;
}
}
- SzArDbExFree(&db, allocImp.Free);
+ SzArEx_Free(&db, &allocImp);
MyCloseFile(archiveStream.File);
if (res == SZ_OK)
@@ -416,11 +414,11 @@ int main(int numargs, char *args[])
printf("\nEverything is Ok\n");
return 0;
}
- if (res == (SZ_RESULT)SZE_NOTIMPL)
+ if (res == SZ_ERROR_UNSUPPORTED)
PrintError("decoder doesn't support this archive");
- else if (res == (SZ_RESULT)SZE_OUTOFMEMORY)
+ else if (res == SZ_ERROR_MEM)
PrintError("can not allocate memory");
- else if (res == (SZ_RESULT)SZE_CRC_ERROR)
+ else if (res == SZ_ERROR_CRC)
PrintError("CRC error");
else
printf("\nERROR #%d\n", res);
diff --git a/C/Archive/7z/7zMethodID.c b/C/Archive/7z/7zMethodID.c
deleted file mode 100755
index a7e825de..00000000
--- a/C/Archive/7z/7zMethodID.c
+++ /dev/null
@@ -1,10 +0,0 @@
-/* 7zMethodID.c */
-
-#include "7zMethodID.h"
-
-/*
-int AreMethodsEqual(CMethodID *a1, CMethodID *a2)
-{
- return (*a1 == *a2) ? 1 : 0;
-}
-*/
diff --git a/C/Archive/7z/7zMethodID.h b/C/Archive/7z/7zMethodID.h
deleted file mode 100755
index 57f22a50..00000000
--- a/C/Archive/7z/7zMethodID.h
+++ /dev/null
@@ -1,10 +0,0 @@
-/* 7zMethodID.h */
-
-#ifndef __7Z_METHOD_ID_H
-#define __7Z_METHOD_ID_H
-
-#include "../../Types.h"
-
-typedef UInt64 CMethodID;
-
-#endif
diff --git a/C/Archive/7z/makefile b/C/Archive/7z/makefile
index 6ea3119a..76fdec01 100755
--- a/C/Archive/7z/makefile
+++ b/C/Archive/7z/makefile
@@ -1,74 +1,30 @@
-PROG = 7zDec.exe
-
-!IFDEF CPU
-LIBS = $(LIBS) bufferoverflowU.lib
-CFLAGS = $(CFLAGS) -GS- -Zc:forScope -WX -GS- -Gy -W4
-!ENDIF
-
-!IFNDEF O
-!IFDEF CPU
-O=$(CPU)
-!ELSE
-O=O
-!ENDIF
-!ENDIF
-
-CFLAGS = $(CFLAGS) -nologo -c -Fo$O/ -D_LZMA_IN_CB
-CFLAGS_O1 = $(CFLAGS) -O1
-CFLAGS_O2 = $(CFLAGS) -O2
-
-LFLAGS = $(LFLAGS) -nologo -OPT:NOWIN98 -OPT:REF
+MY_STATIC_LINK=1
-PROGPATH = $O\$(PROG)
-
-COMPL_O1 = $(CPP) $(CFLAGS_O1) $**
-COMPL_O2 = $(CPP) $(CFLAGS_O2) $**
-COMPL = $(CPP) $(CFLAGS_O1) $**
+PROG = 7zDec.exe
C_OBJS = \
+ $O\7zBuf.obj \
$O\7zCrc.obj \
-
+ $O\LzmaDec.obj \
+ $O\Bra86.obj \
+ $O\Bcj2.obj \
7Z_OBJS = \
$O\7zAlloc.obj \
- $O\7zBuffer.obj \
$O\7zDecode.obj \
$O\7zExtract.obj \
$O\7zHeader.obj \
$O\7zIn.obj \
$O\7zItem.obj \
$O\7zMain.obj \
- $O\7zMethodID.obj \
OBJS = \
$(7Z_OBJS) \
- $O\LzmaDecode.obj \
- $O\BranchX86.obj \
- $O\BranchX86_2.obj \
$(C_OBJS) \
-all: $(PROGPATH)
-
-clean:
- -del /Q $(PROGPATH) $O\*.exe $O\*.dll $O\*.obj $O\*.lib $O\*.exp $O\*.res $O\*.pch
-
-$O:
- if not exist "$O" mkdir "$O"
-
-$(PROGPATH): $O $(OBJS)
- link $(LFLAGS) -out:$(PROGPATH) $(OBJS) $(LIBS)
-
+!include "../../../CPP/Build.mak"
$(7Z_OBJS): $(*B).c
- $(COMPL)
-$O\LzmaDecode.obj: ../../Compress/Lzma/$(*B).c
- $(COMPL_O2)
-
-$O\BranchX86.obj: ../../Compress/Branch/$(*B).c
- $(COMPL_O2)
-
-$O\BranchX86_2.obj: ../../Compress/Branch/$(*B).c
- $(COMPL_O2)
-
+ $(COMPL_O1)
$(C_OBJS): ../../$(*B).c
$(COMPL_O2)
diff --git a/C/Archive/7z/makefile.gcc b/C/Archive/7z/makefile.gcc
index 664ac252..796412a1 100755
--- a/C/Archive/7z/makefile.gcc
+++ b/C/Archive/7z/makefile.gcc
@@ -2,9 +2,9 @@ PROG = 7zDec
CXX = g++
LIB =
RM = rm -f
-CFLAGS = -c -O2 -Wall -D_LZMA_IN_CB
+CFLAGS = -c -O2 -Wall
-OBJS = 7zAlloc.o 7zBuffer.o 7zCrc.o 7zDecode.o 7zExtract.o 7zHeader.o 7zIn.o 7zItem.o 7zMain.o 7zMethodID.o LzmaDecode.o BranchX86.o BranchX86_2.o
+OBJS = 7zAlloc.o 7zBuf.o 7zCrc.o 7zDecode.o 7zExtract.o 7zHeader.o 7zIn.o 7zItem.o 7zMain.o LzmaDec.o Bra86.o Bcj2.o
all: $(PROG)
@@ -14,8 +14,8 @@ $(PROG): $(OBJS)
7zAlloc.o: 7zAlloc.c
$(CXX) $(CFLAGS) 7zAlloc.c
-7zBuffer.o: 7zBuffer.c
- $(CXX) $(CFLAGS) 7zBuffer.c
+7zBuf.o: ../../7zBuf.c
+ $(CXX) $(CFLAGS) ../../7zBuf.c
7zCrc.o: ../../7zCrc.c
$(CXX) $(CFLAGS) ../../7zCrc.c
@@ -38,17 +38,14 @@ $(PROG): $(OBJS)
7zMain.o: 7zMain.c
$(CXX) $(CFLAGS) 7zMain.c
-7zMethodID.o: 7zMethodID.c
- $(CXX) $(CFLAGS) 7zMethodID.c
+LzmaDec.o: ../../LzmaDec.c
+ $(CXX) $(CFLAGS) ../../LzmaDec.c
-LzmaDecode.o: ../../Compress/Lzma/LzmaDecode.c
- $(CXX) $(CFLAGS) ../../Compress/Lzma/LzmaDecode.c
+Bra86.o: ../../Bra86.c
+ $(CXX) $(CFLAGS) ../../Bra86.c
-BranchX86.o: ../../Compress/Branch/BranchX86.c
- $(CXX) $(CFLAGS) ../../Compress/Branch/BranchX86.c
-
-BranchX86_2.o: ../../Compress/Branch/BranchX86_2.c
- $(CXX) $(CFLAGS) ../../Compress/Branch/BranchX86_2.c
+Bcj2.o: ../../Bcj2.c
+ $(CXX) $(CFLAGS) ../../Bcj2.c
clean:
-$(RM) $(PROG) $(OBJS)
diff --git a/C/Compress/Branch/BranchX86_2.c b/C/Bcj2.c
index 241789a5..3a1d82fe 100755
--- a/C/Compress/Branch/BranchX86_2.c
+++ b/C/Bcj2.c
@@ -1,8 +1,11 @@
-// BranchX86_2.c
+/* Bcj2.c -- Converter for x86 code (BCJ2)
+2008-04-11
+Copyright (c) 1999-2008 Igor Pavlov
+Read Bra.h for license options */
-#include "BranchX86_2.h"
+#include "Bcj2.h"
-#include "../../Alloc.h"
+#include "Alloc.h"
#ifdef _LZMA_PROB32
#define CProb UInt32
@@ -20,24 +23,18 @@
#define kBitModelTotal (1 << kNumBitModelTotalBits)
#define kNumMoveBits 5
-#define RC_READ_BYTE (*Buffer++)
+#define RC_READ_BYTE (*buffer++)
+#define RC_TEST { if (buffer == bufferLim) return SZ_ERROR_DATA; }
+#define RC_INIT2 code = 0; range = 0xFFFFFFFF; \
+ { int i; for(i = 0; i < 5; i++) { RC_TEST; code = (code << 8) | RC_READ_BYTE; }}
-#define RC_INIT2 Code = 0; Range = 0xFFFFFFFF; \
- { int i; for(i = 0; i < 5; i++) { RC_TEST; Code = (Code << 8) | RC_READ_BYTE; }}
+#define NORMALIZE if (range < kTopValue) { RC_TEST; range <<= 8; code = (code << 8) | RC_READ_BYTE; }
-#define RC_TEST { if (Buffer == BufferLim) return BCJ2_RESULT_DATA_ERROR; }
+#define IF_BIT_0(p) ttt = *(p); bound = (range >> kNumBitModelTotalBits) * ttt; if (code < bound)
+#define UPDATE_0(p) range = bound; *(p) = (CProb)(ttt + ((kBitModelTotal - ttt) >> kNumMoveBits)); NORMALIZE;
+#define UPDATE_1(p) range -= bound; code -= bound; *(p) = (CProb)(ttt - (ttt >> kNumMoveBits)); NORMALIZE;
-#define RC_INIT(buffer, bufferSize) Buffer = buffer; BufferLim = buffer + bufferSize; RC_INIT2
-
-#define RC_NORMALIZE if (Range < kTopValue) { RC_TEST; Range <<= 8; Code = (Code << 8) | RC_READ_BYTE; }
-
-#define IfBit0(p) RC_NORMALIZE; bound = (Range >> kNumBitModelTotalBits) * *(p); if (Code < bound)
-#define UpdateBit0(p) Range = bound; *(p) += (kBitModelTotal - *(p)) >> kNumMoveBits;
-#define UpdateBit1(p) Range -= bound; Code -= bound; *(p) -= (*(p)) >> kNumMoveBits;
-// #define UpdateBit0(p) Range = bound; *(p) = (CProb)(*(p) + ((kBitModelTotal - *(p)) >> kNumMoveBits));
-// #define UpdateBit1(p) Range -= bound; Code -= bound; *(p) = (CProb)(*(p) - (*(p) >> kNumMoveBits));
-
-int x86_2_Decode(
+int Bcj2_Decode(
const Byte *buf0, SizeT size0,
const Byte *buf1, SizeT size1,
const Byte *buf2, SizeT size2,
@@ -47,23 +44,27 @@ int x86_2_Decode(
CProb p[256 + 2];
SizeT inPos = 0, outPos = 0;
- const Byte *Buffer, *BufferLim;
- UInt32 Range, Code;
+ const Byte *buffer, *bufferLim;
+ UInt32 range, code;
Byte prevByte = 0;
unsigned int i;
for (i = 0; i < sizeof(p) / sizeof(p[0]); i++)
p[i] = kBitModelTotal >> 1;
- RC_INIT(buf3, size3);
+
+ buffer = buf3;
+ bufferLim = buffer + size3;
+ RC_INIT2
if (outSize == 0)
- return BCJ2_RESULT_OK;
+ return SZ_OK;
for (;;)
{
Byte b;
CProb *prob;
UInt32 bound;
+ UInt32 ttt;
SizeT limit = size0 - inPos;
if (outSize - outPos < limit)
@@ -91,21 +92,21 @@ int x86_2_Decode(
else
prob = p + 257;
- IfBit0(prob)
+ IF_BIT_0(prob)
{
- UpdateBit0(prob)
+ UPDATE_0(prob)
prevByte = b;
}
else
{
UInt32 dest;
const Byte *v;
- UpdateBit1(prob)
+ UPDATE_1(prob)
if (b == 0xE8)
{
v = buf1;
if (size1 < 4)
- return BCJ2_RESULT_DATA_ERROR;
+ return SZ_ERROR_DATA;
buf1 += 4;
size1 -= 4;
}
@@ -113,7 +114,7 @@ int x86_2_Decode(
{
v = buf2;
if (size2 < 4)
- return BCJ2_RESULT_DATA_ERROR;
+ return SZ_ERROR_DATA;
buf2 += 4;
size2 -= 4;
}
@@ -131,5 +132,5 @@ int x86_2_Decode(
outBuf[outPos++] = prevByte = (Byte)(dest >> 24);
}
}
- return (outPos == outSize) ? BCJ2_RESULT_OK : BCJ2_RESULT_DATA_ERROR;
+ return (outPos == outSize) ? SZ_OK : SZ_ERROR_DATA;
}
diff --git a/C/Compress/Branch/BranchX86_2.h b/C/Bcj2.h
index 4d861fa3..9dd81b5c 100755
--- a/C/Compress/Branch/BranchX86_2.h
+++ b/C/Bcj2.h
@@ -1,12 +1,12 @@
-// BranchX86_2.h
+/* Bcj2.h -- Converter for x86 code (BCJ2)
+2008-04-11
+Copyright (c) 1999-2008 Igor Pavlov
+Read Bra.h for license options */
-#ifndef __BRANCHX86_2_H
-#define __BRANCHX86_2_H
+#ifndef __BCJ2_H
+#define __BCJ2_H
-#include "BranchTypes.h"
-
-#define BCJ2_RESULT_OK 0
-#define BCJ2_RESULT_DATA_ERROR 1
+#include "Types.h"
/*
Conditions:
@@ -16,9 +16,13 @@ Conditions:
If buf0 overlaps outBuf, there are two required conditions:
1) (buf0 >= outBuf)
2) (buf0 + size0 >= outBuf + FullOutputSize).
+
+Returns:
+ SZ_OK
+ SZ_ERROR_DATA - Data error
*/
-int x86_2_Decode(
+int Bcj2_Decode(
const Byte *buf0, SizeT size0,
const Byte *buf1, SizeT size1,
const Byte *buf2, SizeT size2,
diff --git a/C/Bra.c b/C/Bra.c
new file mode 100755
index 00000000..5683cb34
--- /dev/null
+++ b/C/Bra.c
@@ -0,0 +1,135 @@
+/* Bra.c -- converters for RISC code
+2008-03-19
+Copyright (c) 1999-2008 Igor Pavlov
+Read Bra.h for license options */
+
+#include "Bra.h"
+
+SizeT ARM_Convert(Byte *data, SizeT size, UInt32 ip, int encoding)
+{
+ SizeT i;
+ if (size < 4)
+ return 0;
+ size -= 4;
+ ip += 8;
+ for (i = 0; i <= size; i += 4)
+ {
+ if (data[i + 3] == 0xEB)
+ {
+ UInt32 dest;
+ UInt32 src = ((UInt32)data[i + 2] << 16) | ((UInt32)data[i + 1] << 8) | (data[i + 0]);
+ src <<= 2;
+ if (encoding)
+ dest = ip + (UInt32)i + src;
+ else
+ dest = src - (ip + (UInt32)i);
+ dest >>= 2;
+ data[i + 2] = (Byte)(dest >> 16);
+ data[i + 1] = (Byte)(dest >> 8);
+ data[i + 0] = (Byte)dest;
+ }
+ }
+ return i;
+}
+
+SizeT ARMT_Convert(Byte *data, SizeT size, UInt32 ip, int encoding)
+{
+ SizeT i;
+ if (size < 4)
+ return 0;
+ size -= 4;
+ ip += 4;
+ for (i = 0; i <= size; i += 2)
+ {
+ if ((data[i + 1] & 0xF8) == 0xF0 &&
+ (data[i + 3] & 0xF8) == 0xF8)
+ {
+ UInt32 dest;
+ UInt32 src =
+ (((UInt32)data[i + 1] & 0x7) << 19) |
+ ((UInt32)data[i + 0] << 11) |
+ (((UInt32)data[i + 3] & 0x7) << 8) |
+ (data[i + 2]);
+
+ src <<= 1;
+ if (encoding)
+ dest = ip + (UInt32)i + src;
+ else
+ dest = src - (ip + (UInt32)i);
+ dest >>= 1;
+
+ data[i + 1] = (Byte)(0xF0 | ((dest >> 19) & 0x7));
+ data[i + 0] = (Byte)(dest >> 11);
+ data[i + 3] = (Byte)(0xF8 | ((dest >> 8) & 0x7));
+ data[i + 2] = (Byte)dest;
+ i += 2;
+ }
+ }
+ return i;
+}
+
+SizeT PPC_Convert(Byte *data, SizeT size, UInt32 ip, int encoding)
+{
+ SizeT i;
+ if (size < 4)
+ return 0;
+ size -= 4;
+ for (i = 0; i <= size; i += 4)
+ {
+ if ((data[i] >> 2) == 0x12 && (data[i + 3] & 3) == 1)
+ {
+ UInt32 src = ((UInt32)(data[i + 0] & 3) << 24) |
+ ((UInt32)data[i + 1] << 16) |
+ ((UInt32)data[i + 2] << 8) |
+ ((UInt32)data[i + 3] & (~3));
+
+ UInt32 dest;
+ if (encoding)
+ dest = ip + (UInt32)i + src;
+ else
+ dest = src - (ip + (UInt32)i);
+ data[i + 0] = (Byte)(0x48 | ((dest >> 24) & 0x3));
+ data[i + 1] = (Byte)(dest >> 16);
+ data[i + 2] = (Byte)(dest >> 8);
+ data[i + 3] &= 0x3;
+ data[i + 3] |= dest;
+ }
+ }
+ return i;
+}
+
+SizeT SPARC_Convert(Byte *data, SizeT size, UInt32 ip, int encoding)
+{
+ UInt32 i;
+ if (size < 4)
+ return 0;
+ size -= 4;
+ for (i = 0; i <= size; i += 4)
+ {
+ if (data[i] == 0x40 && (data[i + 1] & 0xC0) == 0x00 ||
+ data[i] == 0x7F && (data[i + 1] & 0xC0) == 0xC0)
+ {
+ UInt32 src =
+ ((UInt32)data[i + 0] << 24) |
+ ((UInt32)data[i + 1] << 16) |
+ ((UInt32)data[i + 2] << 8) |
+ ((UInt32)data[i + 3]);
+ UInt32 dest;
+
+ src <<= 2;
+ if (encoding)
+ dest = ip + i + src;
+ else
+ dest = src - (ip + i);
+ dest >>= 2;
+
+ dest = (((0 - ((dest >> 22) & 1)) << 22) & 0x3FFFFFFF) | (dest & 0x3FFFFF) | 0x40000000;
+
+ data[i + 0] = (Byte)(dest >> 24);
+ data[i + 1] = (Byte)(dest >> 16);
+ data[i + 2] = (Byte)(dest >> 8);
+ data[i + 3] = (Byte)dest;
+ }
+ }
+ return i;
+}
diff --git a/C/Bra.h b/C/Bra.h
new file mode 100755
index 00000000..66800535
--- /dev/null
+++ b/C/Bra.h
@@ -0,0 +1,62 @@
+/* Bra.h -- Branch converters for executables
+2008-03-19
+Copyright (c) 1999-2008 Igor Pavlov
+Read LzmaDec.h for license options */
+
+#ifndef __BRA_H
+#define __BRA_H
+
+#include "Types.h"
+
+/*
+These functions convert relative addresses to absolute addresses
+in CALL instructions to increase the compression ratio.
+
+ In:
+ data - data buffer
+ size - size of data
+ ip - current virtual Instruction Pinter (IP) value
+ state - state variable for x86 converter
+ encoding - 0 (for decoding), 1 (for encoding)
+
+ Out:
+ state - state variable for x86 converter
+
+ Returns:
+ The number of processed bytes. If you call these functions with multiple calls,
+ you must start next call with first byte after block of processed bytes.
+
+ Type Endian Alignment LookAhead
+
+ x86 little 1 4
+ ARMT little 2 2
+ ARM little 4 0
+ PPC big 4 0
+ SPARC big 4 0
+ IA64 little 16 0
+
+ size must be >= Alignment + LookAhead, if it's not last block.
+ If (size < Alignment + LookAhead), converter returns 0.
+
+ Example:
+
+ UInt32 ip = 0;
+ for()
+ {
+ // size must be >= Alignment + LookAhead, if it's not last block
+ SizeT processed = Convert(data, size, ip, 1);
+ data += processed;
+ size -= processed;
+ ip += processed;
+ }
+*/
+
+#define x86_Convert_Init(state) { state = 0; }
+SizeT x86_Convert(Byte *data, SizeT size, UInt32 ip, UInt32 *state, int encoding);
+SizeT ARM_Convert(Byte *data, SizeT size, UInt32 ip, int encoding);
+SizeT ARMT_Convert(Byte *data, SizeT size, UInt32 ip, int encoding);
+SizeT PPC_Convert(Byte *data, SizeT size, UInt32 ip, int encoding);
+SizeT SPARC_Convert(Byte *data, SizeT size, UInt32 ip, int encoding);
+SizeT IA64_Convert(Byte *data, SizeT size, UInt32 ip, int encoding);
+
+#endif
diff --git a/C/Compress/Branch/BranchX86.c b/C/Bra86.c
index fd1d334e..62a1705b 100755
--- a/C/Compress/Branch/BranchX86.c
+++ b/C/Bra86.c
@@ -1,29 +1,32 @@
-/* BranchX86.c */
+/* Bra86.c -- converter for x86 code (BCJ)
+2008-03-19
+Copyright (c) 1999-2008 Igor Pavlov
+Read Bra.h for license options */
-#include "BranchX86.h"
+#include "Bra.h"
#define Test86MSByte(b) ((b) == 0 || (b) == 0xFF)
const Byte kMaskToAllowedStatus[8] = {1, 1, 1, 0, 1, 0, 0, 0};
const Byte kMaskToBitNumber[8] = {0, 1, 2, 2, 3, 3, 3, 3};
-SizeT x86_Convert(Byte *buffer, SizeT endPos, UInt32 nowPos, UInt32 *prevMaskMix, int encoding)
+SizeT x86_Convert(Byte *data, SizeT size, UInt32 ip, UInt32 *state, int encoding)
{
SizeT bufferPos = 0, prevPosT;
- UInt32 prevMask = *prevMaskMix & 0x7;
- if (endPos < 5)
+ UInt32 prevMask = *state & 0x7;
+ if (size < 5)
return 0;
- nowPos += 5;
+ ip += 5;
prevPosT = (SizeT)0 - 1;
for(;;)
{
- Byte *p = buffer + bufferPos;
- Byte *limit = buffer + endPos - 4;
+ Byte *p = data + bufferPos;
+ Byte *limit = data + size - 4;
for (; p < limit; p++)
if ((*p & 0xFE) == 0xE8)
break;
- bufferPos = (SizeT)(p - buffer);
+ bufferPos = (SizeT)(p - data);
if (p >= limit)
break;
prevPosT = bufferPos - prevPosT;
@@ -55,9 +58,9 @@ SizeT x86_Convert(Byte *buffer, SizeT endPos, UInt32 nowPos, UInt32 *prevMaskMix
Byte b;
int index;
if (encoding)
- dest = (nowPos + (UInt32)bufferPos) + src;
+ dest = (ip + (UInt32)bufferPos) + src;
else
- dest = src - (nowPos + (UInt32)bufferPos);
+ dest = src - (ip + (UInt32)bufferPos);
if (prevMask == 0)
break;
index = kMaskToBitNumber[prevMask] * 8;
@@ -79,6 +82,6 @@ SizeT x86_Convert(Byte *buffer, SizeT endPos, UInt32 nowPos, UInt32 *prevMaskMix
}
}
prevPosT = bufferPos - prevPosT;
- *prevMaskMix = ((prevPosT > 3) ? 0 : ((prevMask << ((int)prevPosT - 1)) & 0x7));
+ *state = ((prevPosT > 3) ? 0 : ((prevMask << ((int)prevPosT - 1)) & 0x7));
return bufferPos;
}
diff --git a/C/Compress/Branch/BranchIA64.c b/C/BraIA64.c
index 009086b1..8e02cdea 100755
--- a/C/Compress/Branch/BranchIA64.c
+++ b/C/BraIA64.c
@@ -1,8 +1,11 @@
-/* BranchIA64.c */
+/* BraIA64.c -- converter for IA-64 code
+2008-03-19
+Copyright (c) 1999-2008 Igor Pavlov
+Read Bra.h for license options */
-#include "BranchIA64.h"
+#include "Bra.h"
-const Byte kBranchTable[32] =
+static const Byte kBranchTable[32] =
{
0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0,
@@ -10,10 +13,13 @@ const Byte kBranchTable[32] =
4, 4, 0, 0, 4, 4, 0, 0
};
-UInt32 IA64_Convert(Byte *data, UInt32 size, UInt32 nowPos, int encoding)
+SizeT IA64_Convert(Byte *data, SizeT size, UInt32 ip, int encoding)
{
- UInt32 i;
- for (i = 0; i + 16 <= size; i += 16)
+ SizeT i;
+ if (size < 16)
+ return 0;
+ size -= 16;
+ for (i = 0; i <= size; i += 16)
{
UInt32 instrTemplate = data[i] & 0x1F;
UInt32 mask = kBranchTable[instrTemplate];
@@ -30,13 +36,10 @@ UInt32 IA64_Convert(Byte *data, UInt32 size, UInt32 nowPos, int encoding)
bitRes = bitPos & 0x7;
instruction = 0;
for (j = 0; j < 6; j++)
- instruction += (UInt64)(data[i + j + bytePos]) << (8 * j);
+ instruction += (UInt64)data[i + j + bytePos] << (8 * j);
instNorm = instruction >> bitRes;
- if (((instNorm >> 37) & 0xF) == 0x5
- && ((instNorm >> 9) & 0x7) == 0
- /* && (instNorm & 0x3F)== 0 */
- )
+ if (((instNorm >> 37) & 0xF) == 0x5 && ((instNorm >> 9) & 0x7) == 0)
{
UInt32 src = (UInt32)((instNorm >> 13) & 0xFFFFF);
UInt32 dest;
@@ -45,9 +48,9 @@ UInt32 IA64_Convert(Byte *data, UInt32 size, UInt32 nowPos, int encoding)
src <<= 4;
if (encoding)
- dest = nowPos + i + src;
+ dest = ip + (UInt32)i + src;
else
- dest = src - (nowPos + i);
+ dest = src - (ip + (UInt32)i);
dest >>= 4;
diff --git a/CPP/7zip/Compress/BWT/BlockSort.cpp b/C/BwtSort.c
index 283d8302..507046ad 100755
--- a/CPP/7zip/Compress/BWT/BlockSort.cpp
+++ b/C/BwtSort.c
@@ -1,56 +1,46 @@
-// BlockSort.cpp
+/* BwtSort.c -- BWT block sorting
+2008-03-26
+Igor Pavlov
+Public domain */
-#include "StdAfx.h"
+#include "BwtSort.h"
+#include "Sort.h"
-#include "BlockSort.h"
+/* #define BLOCK_SORT_USE_HEAP_SORT */
-extern "C"
-{
- #include "../../../../C/Sort.h"
-}
-
-// use BLOCK_SORT_EXTERNAL_FLAGS if blockSize > 1M
-// #define BLOCK_SORT_USE_HEAP_SORT
-
-#if _MSC_VER >= 1300
- #define NO_INLINE __declspec(noinline) __fastcall
-#else
-#ifdef _MSC_VER
- #define NO_INLINE __fastcall
-#else
- #define NO_INLINE
-#endif
-#endif
+#define NO_INLINE MY_FAST_CALL
-// Don't change it !!
-static const int kNumHashBytes = 2;
-static const UInt32 kNumHashValues = 1 << (kNumHashBytes * 8);
+/* Don't change it !!! */
+#define kNumHashBytes 2
+#define kNumHashValues (1 << (kNumHashBytes * 8))
-static const int kNumRefBitsMax = 12; // must be < (kNumHashBytes * 8) = 16
+/* kNumRefBitsMax must be < (kNumHashBytes * 8) = 16 */
+#define kNumRefBitsMax 12
#define BS_TEMP_SIZE kNumHashValues
#ifdef BLOCK_SORT_EXTERNAL_FLAGS
-static const int kNumFlagsBits = 5; // 32 Flags in UInt32 word
-static const UInt32 kNumFlagsInWord = (1 << kNumFlagsBits);
-static const UInt32 kFlagsMask = kNumFlagsInWord - 1;
-static const UInt32 kAllFlags = 0xFFFFFFFF;
+/* 32 Flags in UInt32 word */
+#define kNumFlagsBits 5
+#define kNumFlagsInWord (1 << kNumFlagsBits)
+#define kFlagsMask (kNumFlagsInWord - 1)
+#define kAllFlags 0xFFFFFFFF
#else
-const int kNumBitsMax = 20;
-const UInt32 kIndexMask = (1 << kNumBitsMax) - 1;
-const int kNumExtraBits = 32 - kNumBitsMax;
-const int kNumExtra0Bits = kNumExtraBits - 2;
-const UInt32 kNumExtra0Mask = (1 << kNumExtra0Bits) - 1;
+#define kNumBitsMax 20
+#define kIndexMask ((1 << kNumBitsMax) - 1)
+#define kNumExtraBits (32 - kNumBitsMax)
+#define kNumExtra0Bits (kNumExtraBits - 2)
+#define kNumExtra0Mask ((1 << kNumExtra0Bits) - 1)
#define SetFinishedGroupSize(p, size) \
{ *(p) |= ((((size) - 1) & kNumExtra0Mask) << kNumBitsMax); \
if ((size) > (1 << kNumExtra0Bits)) { \
*(p) |= 0x40000000; *((p) + 1) |= ((((size) - 1)>> kNumExtra0Bits) << kNumBitsMax); } } \
-inline void SetGroupSize(UInt32 *p, UInt32 size)
+static void SetGroupSize(UInt32 *p, UInt32 size)
{
if (--size == 0)
return;
@@ -64,9 +54,11 @@ inline void SetGroupSize(UInt32 *p, UInt32 size)
#endif
-// SortGroup - is recursive Range-Sort function with HeapSort optimization for small blocks
-// "range" is not real range. It's only for optimization.
-// returns: 1 - if there are groups, 0 - no more groups
+/*
+SortGroup - is recursive Range-Sort function with HeapSort optimization for small blocks
+ "range" is not real range. It's only for optimization.
+returns: 1 - if there are groups, 0 - no more groups
+*/
UInt32 NO_INLINE SortGroup(UInt32 BlockSize, UInt32 NumSortedBytes, UInt32 groupOffset, UInt32 groupSize, int NumRefBits, UInt32 *Indices
#ifndef BLOCK_SORT_USE_HEAP_SORT
@@ -75,6 +67,7 @@ UInt32 NO_INLINE SortGroup(UInt32 BlockSize, UInt32 NumSortedBytes, UInt32 group
)
{
UInt32 *ind2 = Indices + groupOffset;
+ UInt32 *Groups;
if (groupSize <= 1)
{
/*
@@ -84,7 +77,7 @@ UInt32 NO_INLINE SortGroup(UInt32 BlockSize, UInt32 NumSortedBytes, UInt32 group
*/
return 0;
}
- UInt32 *Groups = Indices + BlockSize + BS_TEMP_SIZE;
+ Groups = Indices + BlockSize + BS_TEMP_SIZE;
if (groupSize <= ((UInt32)1 << NumRefBits)
#ifndef BLOCK_SORT_USE_HEAP_SORT
&& groupSize <= range
@@ -93,6 +86,7 @@ UInt32 NO_INLINE SortGroup(UInt32 BlockSize, UInt32 NumSortedBytes, UInt32 group
{
UInt32 *temp = Indices + BlockSize;
UInt32 j;
+ UInt32 mask, thereAreGroups, group, cg;
{
UInt32 gPrev;
UInt32 gRes = 0;
@@ -106,8 +100,9 @@ UInt32 NO_INLINE SortGroup(UInt32 BlockSize, UInt32 NumSortedBytes, UInt32 group
for (j = 1; j < groupSize; j++)
{
UInt32 sp = ind2[j] + NumSortedBytes;
+ UInt32 g;
if (sp >= BlockSize) sp -= BlockSize;
- UInt32 g = Groups[sp];
+ g = Groups[sp];
temp[j] = (g << NumRefBits) | j;
gRes |= (gPrev ^ g);
}
@@ -121,13 +116,14 @@ UInt32 NO_INLINE SortGroup(UInt32 BlockSize, UInt32 NumSortedBytes, UInt32 group
}
HeapSort(temp, groupSize);
- const UInt32 mask = ((1 << NumRefBits) - 1);
- UInt32 thereAreGroups = 0;
+ mask = ((1 << NumRefBits) - 1);
+ thereAreGroups = 0;
- UInt32 group = groupOffset;
- UInt32 cg = (temp[0] >> NumRefBits);
+ group = groupOffset;
+ cg = (temp[0] >> NumRefBits);
temp[0] = ind2[temp[0] & mask];
+ {
#ifdef BLOCK_SORT_EXTERNAL_FLAGS
UInt32 *Flags = Groups + BlockSize;
#else
@@ -145,8 +141,10 @@ UInt32 NO_INLINE SortGroup(UInt32 BlockSize, UInt32 NumSortedBytes, UInt32 group
group = groupOffset + j;
#ifdef BLOCK_SORT_EXTERNAL_FLAGS
+ {
UInt32 t = group - 1;
Flags[t >> kNumFlagsBits] &= ~(1 << (t & kFlagsMask));
+ }
#else
SetGroupSize(temp + prevGroupStart, j - prevGroupStart);
prevGroupStart = j;
@@ -154,25 +152,28 @@ UInt32 NO_INLINE SortGroup(UInt32 BlockSize, UInt32 NumSortedBytes, UInt32 group
}
else
thereAreGroups = 1;
+ {
UInt32 ind = ind2[val & mask];
temp[j] = ind;
Groups[ind] = group;
+ }
}
#ifndef BLOCK_SORT_EXTERNAL_FLAGS
SetGroupSize(temp + prevGroupStart, j - prevGroupStart);
#endif
+ }
for (j = 0; j < groupSize; j++)
ind2[j] = temp[j];
return thereAreGroups;
}
- // Check that all strings are in one group (cannot sort)
+ /* Check that all strings are in one group (cannot sort) */
{
+ UInt32 group, j;
UInt32 sp = ind2[0] + NumSortedBytes; if (sp >= BlockSize) sp -= BlockSize;
- UInt32 group = Groups[sp];
- UInt32 j;
+ group = Groups[sp];
for (j = 1; j < groupSize; j++)
{
sp = ind2[j] + NumSortedBytes; if (sp >= BlockSize) sp -= BlockSize;
@@ -189,12 +190,13 @@ UInt32 NO_INLINE SortGroup(UInt32 BlockSize, UInt32 NumSortedBytes, UInt32 group
}
#ifndef BLOCK_SORT_USE_HEAP_SORT
- //--------------------------------------
- // Range Sort
+ {
+ /* ---------- Range Sort ---------- */
UInt32 i;
UInt32 mid;
for (;;)
{
+ UInt32 j;
if (range <= 1)
{
#ifndef BLOCK_SORT_EXTERNAL_FLAGS
@@ -203,7 +205,7 @@ UInt32 NO_INLINE SortGroup(UInt32 BlockSize, UInt32 NumSortedBytes, UInt32 group
return 1;
}
mid = left + ((range + 1) >> 1);
- UInt32 j = groupSize;
+ j = groupSize;
i = 0;
do
{
@@ -243,16 +245,22 @@ UInt32 NO_INLINE SortGroup(UInt32 BlockSize, UInt32 NumSortedBytes, UInt32 group
}
#endif
- for (UInt32 j = i; j < groupSize; j++)
- Groups[ind2[j]] = groupOffset + i;
+ {
+ UInt32 j;
+ for (j = i; j < groupSize; j++)
+ Groups[ind2[j]] = groupOffset + i;
+ }
+ {
UInt32 res = SortGroup(BlockSize, NumSortedBytes, groupOffset, i, NumRefBits, Indices, left, mid - left);
return res | SortGroup(BlockSize, NumSortedBytes, groupOffset + i, groupSize - i, NumRefBits, Indices, mid, range - (mid - left));
+ }
+
+ }
#else
- //--------------------------------------
- // Heap Sort
+ /* ---------- Heap Sort ---------- */
{
UInt32 j;
@@ -264,7 +272,8 @@ UInt32 NO_INLINE SortGroup(UInt32 BlockSize, UInt32 NumSortedBytes, UInt32 group
HeapSortRef(ind2, Groups, groupSize);
- // Write Flags
+ /* Write Flags */
+ {
UInt32 sp = ind2[0];
UInt32 group = Groups[sp];
@@ -281,8 +290,10 @@ UInt32 NO_INLINE SortGroup(UInt32 BlockSize, UInt32 NumSortedBytes, UInt32 group
{
group = Groups[sp];
#ifdef BLOCK_SORT_EXTERNAL_FLAGS
+ {
UInt32 t = groupOffset + j - 1;
Flags[t >> kNumFlagsBits] &= ~(1 << (t & kFlagsMask));
+ }
#else
SetGroupSize(ind2 + prevGroupStart, j - prevGroupStart);
prevGroupStart = j;
@@ -293,8 +304,9 @@ UInt32 NO_INLINE SortGroup(UInt32 BlockSize, UInt32 NumSortedBytes, UInt32 group
#ifndef BLOCK_SORT_EXTERNAL_FLAGS
SetGroupSize(ind2 + prevGroupStart, j - prevGroupStart);
#endif
-
- // Write new Groups values and Check that there are groups
+ }
+ {
+ /* Write new Groups values and Check that there are groups */
UInt32 thereAreGroups = 0;
for (j = 0; j < groupSize; j++)
{
@@ -317,6 +329,7 @@ UInt32 NO_INLINE SortGroup(UInt32 BlockSize, UInt32 NumSortedBytes, UInt32 group
thereAreGroups = 1;
}
#else
+ UInt32 *Flags = Groups + BlockSize;
for (;;)
{
UInt32 sp = ind2[j]; if (sp < NumSortedBytes) sp += BlockSize; sp -= NumSortedBytes;
@@ -330,26 +343,31 @@ UInt32 NO_INLINE SortGroup(UInt32 BlockSize, UInt32 NumSortedBytes, UInt32 group
#endif
}
return thereAreGroups;
+ }
}
#endif
}
-// conditions: blockSize > 0
+/* conditions: blockSize > 0 */
UInt32 BlockSort(UInt32 *Indices, const Byte *data, UInt32 blockSize)
{
UInt32 *counters = Indices + blockSize;
UInt32 i;
+ UInt32 *Groups;
+ #ifdef BLOCK_SORT_EXTERNAL_FLAGS
+ UInt32 *Flags;
+ #endif
- // Radix-Sort for 2 bytes
+ /* Radix-Sort for 2 bytes */
for (i = 0; i < kNumHashValues; i++)
counters[i] = 0;
for (i = 0; i < blockSize - 1; i++)
counters[((UInt32)data[i] << 8) | data[i + 1]]++;
counters[((UInt32)data[i] << 8) | data[0]]++;
- UInt32 *Groups = counters + BS_TEMP_SIZE;
+ Groups = counters + BS_TEMP_SIZE;
#ifdef BLOCK_SORT_EXTERNAL_FLAGS
- UInt32 *Flags = Groups + blockSize;
+ Flags = Groups + blockSize;
{
UInt32 numWords = (blockSize + kFlagsMask) >> kNumFlagsBits;
for (i = 0; i < numWords; i++)
@@ -382,6 +400,7 @@ UInt32 BlockSort(UInt32 *Indices, const Byte *data, UInt32 blockSize)
Indices[counters[((UInt32)data[i] << 8) | data[0]]++] = i;
#ifndef BLOCK_SORT_EXTERNAL_FLAGS
+ {
UInt32 prev = 0;
for (i = 0; i < kNumHashValues; i++)
{
@@ -391,16 +410,19 @@ UInt32 BlockSort(UInt32 *Indices, const Byte *data, UInt32 blockSize)
SetGroupSize(Indices + prev, prevGroupSize);
prev = counters[i];
}
+ }
#endif
}
+ {
int NumRefBits;
+ UInt32 NumSortedBytes;
for (NumRefBits = 0; ((blockSize - 1) >> NumRefBits) != 0; NumRefBits++);
NumRefBits = 32 - NumRefBits;
if (NumRefBits > kNumRefBitsMax)
NumRefBits = kNumRefBitsMax;
- for (UInt32 NumSortedBytes = kNumHashBytes; ; NumSortedBytes <<= 1)
+ for (NumSortedBytes = kNumHashBytes; ; NumSortedBytes <<= 1)
{
#ifndef BLOCK_SORT_EXTERNAL_FLAGS
UInt32 finishedGroupSize = 0;
@@ -408,6 +430,7 @@ UInt32 BlockSort(UInt32 *Indices, const Byte *data, UInt32 blockSize)
UInt32 newLimit = 0;
for (i = 0; i < blockSize;)
{
+ UInt32 groupSize;
#ifdef BLOCK_SORT_EXTERNAL_FLAGS
if ((Flags[i >> kNumFlagsBits] & (1 << (i & kFlagsMask))) == 0)
@@ -415,7 +438,6 @@ UInt32 BlockSort(UInt32 *Indices, const Byte *data, UInt32 blockSize)
i++;
continue;
}
- UInt32 groupSize;
for(groupSize = 1;
(Flags[(i + groupSize) >> kNumFlagsBits] & (1 << ((i + groupSize) & kFlagsMask))) != 0;
groupSize++);
@@ -424,8 +446,9 @@ UInt32 BlockSort(UInt32 *Indices, const Byte *data, UInt32 blockSize)
#else
- UInt32 groupSize = ((Indices[i] & ~0xC0000000) >> kNumBitsMax);
- bool finishedGroup = ((Indices[i] & 0x80000000) == 0);
+ groupSize = ((Indices[i] & ~0xC0000000) >> kNumBitsMax);
+ {
+ Bool finishedGroup = ((Indices[i] & 0x80000000) == 0);
if ((Indices[i] & 0x40000000) != 0)
{
groupSize += ((Indices[i + 1] >> kNumBitsMax) << kNumExtra0Bits);
@@ -438,23 +461,29 @@ UInt32 BlockSort(UInt32 *Indices, const Byte *data, UInt32 blockSize)
Indices[i - finishedGroupSize] &= kIndexMask;
if (finishedGroupSize > 1)
Indices[i - finishedGroupSize + 1] &= kIndexMask;
+ {
UInt32 newGroupSize = groupSize + finishedGroupSize;
SetFinishedGroupSize(Indices + i - finishedGroupSize, newGroupSize);
finishedGroupSize = newGroupSize;
+ }
i += groupSize;
continue;
}
finishedGroupSize = 0;
+ }
#endif
if (NumSortedBytes >= blockSize)
- for (UInt32 j = 0; j < groupSize; j++)
+ {
+ UInt32 j;
+ for (j = 0; j < groupSize; j++)
{
UInt32 t = (i + j);
- // Flags[t >> kNumFlagsBits] &= ~(1 << (t & kFlagsMask));
+ /* Flags[t >> kNumFlagsBits] &= ~(1 << (t & kFlagsMask)); */
Groups[Indices[t]] = t;
}
+ }
else
if (SortGroup(blockSize, NumSortedBytes, i, groupSize, NumRefBits, Indices
#ifndef BLOCK_SORT_USE_HEAP_SORT
@@ -467,6 +496,7 @@ UInt32 BlockSort(UInt32 *Indices, const Byte *data, UInt32 blockSize)
if (newLimit == 0)
break;
}
+ }
#ifndef BLOCK_SORT_EXTERNAL_FLAGS
for (i = 0; i < blockSize;)
{
diff --git a/CPP/7zip/Compress/BWT/BlockSort.h b/C/BwtSort.h
index def48a96..f373213e 100755
--- a/CPP/7zip/Compress/BWT/BlockSort.h
+++ b/C/BwtSort.h
@@ -1,12 +1,15 @@
-// BlockSort.h
+/* BwtSort.h -- BWT block sorting
+2008-03-26
+Igor Pavlov
+Public domain */
-#ifndef __BLOCKSORT_H
-#define __BLOCKSORT_H
+#ifndef __BWTSORT_H
+#define __BWTSORT_H
-#include "Common/Types.h"
+#include "Types.h"
-// use BLOCK_SORT_EXTERNAL_FLAGS if blockSize can be > 1M
-// #define BLOCK_SORT_EXTERNAL_FLAGS
+/* use BLOCK_SORT_EXTERNAL_FLAGS if blockSize can be > 1M */
+/* #define BLOCK_SORT_EXTERNAL_FLAGS */
#ifdef BLOCK_SORT_EXTERNAL_FLAGS
#define BLOCK_SORT_EXTERNAL_SIZE(blockSize) ((((blockSize) + 31) >> 5))
diff --git a/C/Compress/Branch/BranchARM.c b/C/Compress/Branch/BranchARM.c
deleted file mode 100755
index da7db261..00000000
--- a/C/Compress/Branch/BranchARM.c
+++ /dev/null
@@ -1,26 +0,0 @@
-/* BranchARM.c */
-
-#include "BranchARM.h"
-
-UInt32 ARM_Convert(Byte *data, UInt32 size, UInt32 nowPos, int encoding)
-{
- UInt32 i;
- for (i = 0; i + 4 <= size; i += 4)
- {
- if (data[i + 3] == 0xEB)
- {
- UInt32 dest;
- UInt32 src = (data[i + 2] << 16) | (data[i + 1] << 8) | (data[i + 0]);
- src <<= 2;
- if (encoding)
- dest = nowPos + i + 8 + src;
- else
- dest = src - (nowPos + i + 8);
- dest >>= 2;
- data[i + 2] = (Byte)(dest >> 16);
- data[i + 1] = (Byte)(dest >> 8);
- data[i + 0] = (Byte)dest;
- }
- }
- return i;
-}
diff --git a/C/Compress/Branch/BranchARM.h b/C/Compress/Branch/BranchARM.h
deleted file mode 100755
index 3b4d63e1..00000000
--- a/C/Compress/Branch/BranchARM.h
+++ /dev/null
@@ -1,10 +0,0 @@
-/* BranchARM.h */
-
-#ifndef __BRANCH_ARM_H
-#define __BRANCH_ARM_H
-
-#include "BranchTypes.h"
-
-UInt32 ARM_Convert(Byte *data, UInt32 size, UInt32 nowPos, int encoding);
-
-#endif
diff --git a/C/Compress/Branch/BranchARMThumb.c b/C/Compress/Branch/BranchARMThumb.c
deleted file mode 100755
index fa30e439..00000000
--- a/C/Compress/Branch/BranchARMThumb.c
+++ /dev/null
@@ -1,35 +0,0 @@
-/* BranchARMThumb.c */
-
-#include "BranchARMThumb.h"
-
-UInt32 ARMThumb_Convert(Byte *data, UInt32 size, UInt32 nowPos, int encoding)
-{
- UInt32 i;
- for (i = 0; i + 4 <= size; i += 2)
- {
- if ((data[i + 1] & 0xF8) == 0xF0 &&
- (data[i + 3] & 0xF8) == 0xF8)
- {
- UInt32 dest;
- UInt32 src =
- ((data[i + 1] & 0x7) << 19) |
- (data[i + 0] << 11) |
- ((data[i + 3] & 0x7) << 8) |
- (data[i + 2]);
-
- src <<= 1;
- if (encoding)
- dest = nowPos + i + 4 + src;
- else
- dest = src - (nowPos + i + 4);
- dest >>= 1;
-
- data[i + 1] = (Byte)(0xF0 | ((dest >> 19) & 0x7));
- data[i + 0] = (Byte)(dest >> 11);
- data[i + 3] = (Byte)(0xF8 | ((dest >> 8) & 0x7));
- data[i + 2] = (Byte)dest;
- i += 2;
- }
- }
- return i;
-}
diff --git a/C/Compress/Branch/BranchARMThumb.h b/C/Compress/Branch/BranchARMThumb.h
deleted file mode 100755
index 304699ce..00000000
--- a/C/Compress/Branch/BranchARMThumb.h
+++ /dev/null
@@ -1,10 +0,0 @@
-/* BranchARMThumb.h */
-
-#ifndef __BRANCH_ARM_THUMB_H
-#define __BRANCH_ARM_THUMB_H
-
-#include "BranchTypes.h"
-
-UInt32 ARMThumb_Convert(Byte *data, UInt32 size, UInt32 nowPos, int encoding);
-
-#endif
diff --git a/C/Compress/Branch/BranchIA64.h b/C/Compress/Branch/BranchIA64.h
deleted file mode 100755
index 8213cb50..00000000
--- a/C/Compress/Branch/BranchIA64.h
+++ /dev/null
@@ -1,10 +0,0 @@
-/* BranchIA64.h */
-
-#ifndef __BRANCH_IA64_H
-#define __BRANCH_IA64_H
-
-#include "BranchTypes.h"
-
-UInt32 IA64_Convert(Byte *data, UInt32 size, UInt32 nowPos, int encoding);
-
-#endif
diff --git a/C/Compress/Branch/BranchPPC.c b/C/Compress/Branch/BranchPPC.c
deleted file mode 100755
index b3e5703f..00000000
--- a/C/Compress/Branch/BranchPPC.c
+++ /dev/null
@@ -1,36 +0,0 @@
-/* BranchPPC.c */
-
-#include "BranchPPC.h"
-
-UInt32 PPC_B_Convert(Byte *data, UInt32 size, UInt32 nowPos, int encoding)
-{
- UInt32 i;
- for (i = 0; i + 4 <= size; i += 4)
- {
- /* PowerPC branch 6(48) 24(Offset) 1(Abs) 1(Link) */
- if ((data[i] >> 2) == 0x12 &&
- (
- (data[i + 3] & 3) == 1
- /* || (data[i+3] & 3) == 3 */
- )
- )
- {
- UInt32 src = ((data[i + 0] & 3) << 24) |
- (data[i + 1] << 16) |
- (data[i + 2] << 8) |
- (data[i + 3] & (~3));
-
- UInt32 dest;
- if (encoding)
- dest = nowPos + i + src;
- else
- dest = src - (nowPos + i);
- data[i + 0] = (Byte)(0x48 | ((dest >> 24) & 0x3));
- data[i + 1] = (Byte)(dest >> 16);
- data[i + 2] = (Byte)(dest >> 8);
- data[i + 3] &= 0x3;
- data[i + 3] |= dest;
- }
- }
- return i;
-}
diff --git a/C/Compress/Branch/BranchPPC.h b/C/Compress/Branch/BranchPPC.h
deleted file mode 100755
index 05e2a377..00000000
--- a/C/Compress/Branch/BranchPPC.h
+++ /dev/null
@@ -1,10 +0,0 @@
-/* BranchPPC.h */
-
-#ifndef __BRANCH_PPC_H
-#define __BRANCH_PPC_H
-
-#include "BranchTypes.h"
-
-UInt32 PPC_B_Convert(Byte *data, UInt32 size, UInt32 nowPos, int encoding);
-
-#endif
diff --git a/C/Compress/Branch/BranchSPARC.c b/C/Compress/Branch/BranchSPARC.c
deleted file mode 100755
index 79da2ea7..00000000
--- a/C/Compress/Branch/BranchSPARC.c
+++ /dev/null
@@ -1,36 +0,0 @@
-/* BranchSPARC.c */
-
-#include "BranchSPARC.h"
-
-UInt32 SPARC_Convert(Byte *data, UInt32 size, UInt32 nowPos, int encoding)
-{
- UInt32 i;
- for (i = 0; i + 4 <= size; i += 4)
- {
- if (data[i] == 0x40 && (data[i + 1] & 0xC0) == 0x00 ||
- data[i] == 0x7F && (data[i + 1] & 0xC0) == 0xC0)
- {
- UInt32 src =
- ((UInt32)data[i + 0] << 24) |
- ((UInt32)data[i + 1] << 16) |
- ((UInt32)data[i + 2] << 8) |
- ((UInt32)data[i + 3]);
- UInt32 dest;
-
- src <<= 2;
- if (encoding)
- dest = nowPos + i + src;
- else
- dest = src - (nowPos + i);
- dest >>= 2;
-
- dest = (((0 - ((dest >> 22) & 1)) << 22) & 0x3FFFFFFF) | (dest & 0x3FFFFF) | 0x40000000;
-
- data[i + 0] = (Byte)(dest >> 24);
- data[i + 1] = (Byte)(dest >> 16);
- data[i + 2] = (Byte)(dest >> 8);
- data[i + 3] = (Byte)dest;
- }
- }
- return i;
-}
diff --git a/C/Compress/Branch/BranchSPARC.h b/C/Compress/Branch/BranchSPARC.h
deleted file mode 100755
index f3f83206..00000000
--- a/C/Compress/Branch/BranchSPARC.h
+++ /dev/null
@@ -1,10 +0,0 @@
-/* BranchSPARC.h */
-
-#ifndef __BRANCH_SPARC_H
-#define __BRANCH_SPARC_H
-
-#include "BranchTypes.h"
-
-UInt32 SPARC_Convert(Byte *data, UInt32 size, UInt32 nowPos, int encoding);
-
-#endif
diff --git a/C/Compress/Branch/BranchTypes.h b/C/Compress/Branch/BranchTypes.h
deleted file mode 100755
index 1bed56a9..00000000
--- a/C/Compress/Branch/BranchTypes.h
+++ /dev/null
@@ -1,51 +0,0 @@
-/* BranchTypes.h */
-
-#ifndef __BRANCHTYPES_H
-#define __BRANCHTYPES_H
-
-#ifndef _7ZIP_BYTE_DEFINED
-#define _7ZIP_BYTE_DEFINED
-typedef unsigned char Byte;
-#endif
-
-#ifndef _7ZIP_UINT16_DEFINED
-#define _7ZIP_UINT16_DEFINED
-typedef unsigned short UInt16;
-#endif
-
-#ifndef _7ZIP_UINT32_DEFINED
-#define _7ZIP_UINT32_DEFINED
-#ifdef _LZMA_UINT32_IS_ULONG
-typedef unsigned long UInt32;
-#else
-typedef unsigned int UInt32;
-#endif
-#endif
-
-#ifndef _7ZIP_UINT64_DEFINED
-#define _7ZIP_UINT64_DEFINED
-#ifdef _SZ_NO_INT_64
-typedef unsigned long UInt64;
-#else
-#if defined(_MSC_VER) || defined(__BORLANDC__)
-typedef unsigned __int64 UInt64;
-#else
-typedef unsigned long long int UInt64;
-#endif
-#endif
-#endif
-
-/* #define _LZMA_NO_SYSTEM_SIZE_T */
-/* You can use it, if you don't want <stddef.h> */
-
-#ifndef _7ZIP_SIZET_DEFINED
-#define _7ZIP_SIZET_DEFINED
-#ifdef _LZMA_NO_SYSTEM_SIZE_T
-typedef UInt32 SizeT;
-#else
-#include <stddef.h>
-typedef size_t SizeT;
-#endif
-#endif
-
-#endif
diff --git a/C/Compress/Branch/BranchX86.h b/C/Compress/Branch/BranchX86.h
deleted file mode 100755
index 5dfd02a7..00000000
--- a/C/Compress/Branch/BranchX86.h
+++ /dev/null
@@ -1,12 +0,0 @@
-/* BranchX86.h */
-
-#ifndef __BRANCHX86_H
-#define __BRANCHX86_H
-
-#include "BranchTypes.h"
-
-#define x86_Convert_Init(state) { state = 0; }
-
-SizeT x86_Convert(Byte *buffer, SizeT endPos, UInt32 nowPos, UInt32 *state, int encoding);
-
-#endif
diff --git a/C/Compress/Lzma/LzmaDecode.c b/C/Compress/Lzma/LzmaDecode.c
deleted file mode 100755
index cb834537..00000000
--- a/C/Compress/Lzma/LzmaDecode.c
+++ /dev/null
@@ -1,584 +0,0 @@
-/*
- LzmaDecode.c
- LZMA Decoder (optimized for Speed version)
-
- LZMA SDK 4.40 Copyright (c) 1999-2006 Igor Pavlov (2006-05-01)
- http://www.7-zip.org/
-
- LZMA SDK is licensed under two licenses:
- 1) GNU Lesser General Public License (GNU LGPL)
- 2) Common Public License (CPL)
- It means that you can select one of these two licenses and
- follow rules of that license.
-
- SPECIAL EXCEPTION:
- Igor Pavlov, as the author of this Code, expressly permits you to
- statically or dynamically link your Code (or bind by name) to the
- interfaces of this file without subjecting your linked Code to the
- terms of the CPL or GNU LGPL. Any modifications or additions
- to this file, however, are subject to the LGPL or CPL terms.
-*/
-
-#include "LzmaDecode.h"
-
-#define kNumTopBits 24
-#define kTopValue ((UInt32)1 << kNumTopBits)
-
-#define kNumBitModelTotalBits 11
-#define kBitModelTotal (1 << kNumBitModelTotalBits)
-#define kNumMoveBits 5
-
-#define RC_READ_BYTE (*Buffer++)
-
-#define RC_INIT2 Code = 0; Range = 0xFFFFFFFF; \
- { int i; for(i = 0; i < 5; i++) { RC_TEST; Code = (Code << 8) | RC_READ_BYTE; }}
-
-#ifdef _LZMA_IN_CB
-
-#define RC_TEST { if (Buffer == BufferLim) \
- { SizeT size; int result = InCallback->Read(InCallback, &Buffer, &size); if (result != LZMA_RESULT_OK) return result; \
- BufferLim = Buffer + size; if (size == 0) return LZMA_RESULT_DATA_ERROR; }}
-
-#define RC_INIT Buffer = BufferLim = 0; RC_INIT2
-
-#else
-
-#define RC_TEST { if (Buffer == BufferLim) return LZMA_RESULT_DATA_ERROR; }
-
-#define RC_INIT(buffer, bufferSize) Buffer = buffer; BufferLim = buffer + bufferSize; RC_INIT2
-
-#endif
-
-#define RC_NORMALIZE if (Range < kTopValue) { RC_TEST; Range <<= 8; Code = (Code << 8) | RC_READ_BYTE; }
-
-#define IfBit0(p) RC_NORMALIZE; bound = (Range >> kNumBitModelTotalBits) * *(p); if (Code < bound)
-#define UpdateBit0(p) Range = bound; *(p) += (kBitModelTotal - *(p)) >> kNumMoveBits;
-#define UpdateBit1(p) Range -= bound; Code -= bound; *(p) -= (*(p)) >> kNumMoveBits;
-
-#define RC_GET_BIT2(p, mi, A0, A1) IfBit0(p) \
- { UpdateBit0(p); mi <<= 1; A0; } else \
- { UpdateBit1(p); mi = (mi + mi) + 1; A1; }
-
-#define RC_GET_BIT(p, mi) RC_GET_BIT2(p, mi, ; , ;)
-
-#define RangeDecoderBitTreeDecode(probs, numLevels, res) \
- { int i = numLevels; res = 1; \
- do { CProb *p = probs + res; RC_GET_BIT(p, res) } while(--i != 0); \
- res -= (1 << numLevels); }
-
-
-#define kNumPosBitsMax 4
-#define kNumPosStatesMax (1 << kNumPosBitsMax)
-
-#define kLenNumLowBits 3
-#define kLenNumLowSymbols (1 << kLenNumLowBits)
-#define kLenNumMidBits 3
-#define kLenNumMidSymbols (1 << kLenNumMidBits)
-#define kLenNumHighBits 8
-#define kLenNumHighSymbols (1 << kLenNumHighBits)
-
-#define LenChoice 0
-#define LenChoice2 (LenChoice + 1)
-#define LenLow (LenChoice2 + 1)
-#define LenMid (LenLow + (kNumPosStatesMax << kLenNumLowBits))
-#define LenHigh (LenMid + (kNumPosStatesMax << kLenNumMidBits))
-#define kNumLenProbs (LenHigh + kLenNumHighSymbols)
-
-
-#define kNumStates 12
-#define kNumLitStates 7
-
-#define kStartPosModelIndex 4
-#define kEndPosModelIndex 14
-#define kNumFullDistances (1 << (kEndPosModelIndex >> 1))
-
-#define kNumPosSlotBits 6
-#define kNumLenToPosStates 4
-
-#define kNumAlignBits 4
-#define kAlignTableSize (1 << kNumAlignBits)
-
-#define kMatchMinLen 2
-
-#define IsMatch 0
-#define IsRep (IsMatch + (kNumStates << kNumPosBitsMax))
-#define IsRepG0 (IsRep + kNumStates)
-#define IsRepG1 (IsRepG0 + kNumStates)
-#define IsRepG2 (IsRepG1 + kNumStates)
-#define IsRep0Long (IsRepG2 + kNumStates)
-#define PosSlot (IsRep0Long + (kNumStates << kNumPosBitsMax))
-#define SpecPos (PosSlot + (kNumLenToPosStates << kNumPosSlotBits))
-#define Align (SpecPos + kNumFullDistances - kEndPosModelIndex)
-#define LenCoder (Align + kAlignTableSize)
-#define RepLenCoder (LenCoder + kNumLenProbs)
-#define Literal (RepLenCoder + kNumLenProbs)
-
-#if Literal != LZMA_BASE_SIZE
-StopCompilingDueBUG
-#endif
-
-int LzmaDecodeProperties(CLzmaProperties *propsRes, const unsigned char *propsData, int size)
-{
- unsigned char prop0;
- if (size < LZMA_PROPERTIES_SIZE)
- return LZMA_RESULT_DATA_ERROR;
- prop0 = propsData[0];
- if (prop0 >= (9 * 5 * 5))
- return LZMA_RESULT_DATA_ERROR;
- {
- for (propsRes->pb = 0; prop0 >= (9 * 5); propsRes->pb++, prop0 -= (9 * 5));
- for (propsRes->lp = 0; prop0 >= 9; propsRes->lp++, prop0 -= 9);
- propsRes->lc = prop0;
- /*
- unsigned char remainder = (unsigned char)(prop0 / 9);
- propsRes->lc = prop0 % 9;
- propsRes->pb = remainder / 5;
- propsRes->lp = remainder % 5;
- */
- }
-
- #ifdef _LZMA_OUT_READ
- {
- int i;
- propsRes->DictionarySize = 0;
- for (i = 0; i < 4; i++)
- propsRes->DictionarySize += (UInt32)(propsData[1 + i]) << (i * 8);
- if (propsRes->DictionarySize == 0)
- propsRes->DictionarySize = 1;
- }
- #endif
- return LZMA_RESULT_OK;
-}
-
-#define kLzmaStreamWasFinishedId (-1)
-
-int LzmaDecode(CLzmaDecoderState *vs,
- #ifdef _LZMA_IN_CB
- ILzmaInCallback *InCallback,
- #else
- const unsigned char *inStream, SizeT inSize, SizeT *inSizeProcessed,
- #endif
- unsigned char *outStream, SizeT outSize, SizeT *outSizeProcessed)
-{
- CProb *p = vs->Probs;
- SizeT nowPos = 0;
- Byte previousByte = 0;
- UInt32 posStateMask = (1 << (vs->Properties.pb)) - 1;
- UInt32 literalPosMask = (1 << (vs->Properties.lp)) - 1;
- int lc = vs->Properties.lc;
-
- #ifdef _LZMA_OUT_READ
-
- UInt32 Range = vs->Range;
- UInt32 Code = vs->Code;
- #ifdef _LZMA_IN_CB
- const Byte *Buffer = vs->Buffer;
- const Byte *BufferLim = vs->BufferLim;
- #else
- const Byte *Buffer = inStream;
- const Byte *BufferLim = inStream + inSize;
- #endif
- int state = vs->State;
- UInt32 rep0 = vs->Reps[0], rep1 = vs->Reps[1], rep2 = vs->Reps[2], rep3 = vs->Reps[3];
- int len = vs->RemainLen;
- UInt32 globalPos = vs->GlobalPos;
- UInt32 distanceLimit = vs->DistanceLimit;
-
- Byte *dictionary = vs->Dictionary;
- UInt32 dictionarySize = vs->Properties.DictionarySize;
- UInt32 dictionaryPos = vs->DictionaryPos;
-
- Byte tempDictionary[4];
-
- #ifndef _LZMA_IN_CB
- *inSizeProcessed = 0;
- #endif
- *outSizeProcessed = 0;
- if (len == kLzmaStreamWasFinishedId)
- return LZMA_RESULT_OK;
-
- if (dictionarySize == 0)
- {
- dictionary = tempDictionary;
- dictionarySize = 1;
- tempDictionary[0] = vs->TempDictionary[0];
- }
-
- if (len == kLzmaNeedInitId)
- {
- {
- UInt32 numProbs = Literal + ((UInt32)LZMA_LIT_SIZE << (lc + vs->Properties.lp));
- UInt32 i;
- for (i = 0; i < numProbs; i++)
- p[i] = kBitModelTotal >> 1;
- rep0 = rep1 = rep2 = rep3 = 1;
- state = 0;
- globalPos = 0;
- distanceLimit = 0;
- dictionaryPos = 0;
- dictionary[dictionarySize - 1] = 0;
- #ifdef _LZMA_IN_CB
- RC_INIT;
- #else
- RC_INIT(inStream, inSize);
- #endif
- }
- len = 0;
- }
- while(len != 0 && nowPos < outSize)
- {
- UInt32 pos = dictionaryPos - rep0;
- if (pos >= dictionarySize)
- pos += dictionarySize;
- outStream[nowPos++] = dictionary[dictionaryPos] = dictionary[pos];
- if (++dictionaryPos == dictionarySize)
- dictionaryPos = 0;
- len--;
- }
- if (dictionaryPos == 0)
- previousByte = dictionary[dictionarySize - 1];
- else
- previousByte = dictionary[dictionaryPos - 1];
-
- #else /* if !_LZMA_OUT_READ */
-
- int state = 0;
- UInt32 rep0 = 1, rep1 = 1, rep2 = 1, rep3 = 1;
- int len = 0;
- const Byte *Buffer;
- const Byte *BufferLim;
- UInt32 Range;
- UInt32 Code;
-
- #ifndef _LZMA_IN_CB
- *inSizeProcessed = 0;
- #endif
- *outSizeProcessed = 0;
-
- {
- UInt32 i;
- UInt32 numProbs = Literal + ((UInt32)LZMA_LIT_SIZE << (lc + vs->Properties.lp));
- for (i = 0; i < numProbs; i++)
- p[i] = kBitModelTotal >> 1;
- }
-
- #ifdef _LZMA_IN_CB
- RC_INIT;
- #else
- RC_INIT(inStream, inSize);
- #endif
-
- #endif /* _LZMA_OUT_READ */
-
- while(nowPos < outSize)
- {
- CProb *prob;
- UInt32 bound;
- int posState = (int)(
- (nowPos
- #ifdef _LZMA_OUT_READ
- + globalPos
- #endif
- )
- & posStateMask);
-
- prob = p + IsMatch + (state << kNumPosBitsMax) + posState;
- IfBit0(prob)
- {
- int symbol = 1;
- UpdateBit0(prob)
- prob = p + Literal + (LZMA_LIT_SIZE *
- (((
- (nowPos
- #ifdef _LZMA_OUT_READ
- + globalPos
- #endif
- )
- & literalPosMask) << lc) + (previousByte >> (8 - lc))));
-
- if (state >= kNumLitStates)
- {
- int matchByte;
- #ifdef _LZMA_OUT_READ
- UInt32 pos = dictionaryPos - rep0;
- if (pos >= dictionarySize)
- pos += dictionarySize;
- matchByte = dictionary[pos];
- #else
- matchByte = outStream[nowPos - rep0];
- #endif
- do
- {
- int bit;
- CProb *probLit;
- matchByte <<= 1;
- bit = (matchByte & 0x100);
- probLit = prob + 0x100 + bit + symbol;
- RC_GET_BIT2(probLit, symbol, if (bit != 0) break, if (bit == 0) break)
- }
- while (symbol < 0x100);
- }
- while (symbol < 0x100)
- {
- CProb *probLit = prob + symbol;
- RC_GET_BIT(probLit, symbol)
- }
- previousByte = (Byte)symbol;
-
- outStream[nowPos++] = previousByte;
- #ifdef _LZMA_OUT_READ
- if (distanceLimit < dictionarySize)
- distanceLimit++;
-
- dictionary[dictionaryPos] = previousByte;
- if (++dictionaryPos == dictionarySize)
- dictionaryPos = 0;
- #endif
- if (state < 4) state = 0;
- else if (state < 10) state -= 3;
- else state -= 6;
- }
- else
- {
- UpdateBit1(prob);
- prob = p + IsRep + state;
- IfBit0(prob)
- {
- UpdateBit0(prob);
- rep3 = rep2;
- rep2 = rep1;
- rep1 = rep0;
- state = state < kNumLitStates ? 0 : 3;
- prob = p + LenCoder;
- }
- else
- {
- UpdateBit1(prob);
- prob = p + IsRepG0 + state;
- IfBit0(prob)
- {
- UpdateBit0(prob);
- prob = p + IsRep0Long + (state << kNumPosBitsMax) + posState;
- IfBit0(prob)
- {
- #ifdef _LZMA_OUT_READ
- UInt32 pos;
- #endif
- UpdateBit0(prob);
-
- #ifdef _LZMA_OUT_READ
- if (distanceLimit == 0)
- #else
- if (nowPos == 0)
- #endif
- return LZMA_RESULT_DATA_ERROR;
-
- state = state < kNumLitStates ? 9 : 11;
- #ifdef _LZMA_OUT_READ
- pos = dictionaryPos - rep0;
- if (pos >= dictionarySize)
- pos += dictionarySize;
- previousByte = dictionary[pos];
- dictionary[dictionaryPos] = previousByte;
- if (++dictionaryPos == dictionarySize)
- dictionaryPos = 0;
- #else
- previousByte = outStream[nowPos - rep0];
- #endif
- outStream[nowPos++] = previousByte;
- #ifdef _LZMA_OUT_READ
- if (distanceLimit < dictionarySize)
- distanceLimit++;
- #endif
-
- continue;
- }
- else
- {
- UpdateBit1(prob);
- }
- }
- else
- {
- UInt32 distance;
- UpdateBit1(prob);
- prob = p + IsRepG1 + state;
- IfBit0(prob)
- {
- UpdateBit0(prob);
- distance = rep1;
- }
- else
- {
- UpdateBit1(prob);
- prob = p + IsRepG2 + state;
- IfBit0(prob)
- {
- UpdateBit0(prob);
- distance = rep2;
- }
- else
- {
- UpdateBit1(prob);
- distance = rep3;
- rep3 = rep2;
- }
- rep2 = rep1;
- }
- rep1 = rep0;
- rep0 = distance;
- }
- state = state < kNumLitStates ? 8 : 11;
- prob = p + RepLenCoder;
- }
- {
- int numBits, offset;
- CProb *probLen = prob + LenChoice;
- IfBit0(probLen)
- {
- UpdateBit0(probLen);
- probLen = prob + LenLow + (posState << kLenNumLowBits);
- offset = 0;
- numBits = kLenNumLowBits;
- }
- else
- {
- UpdateBit1(probLen);
- probLen = prob + LenChoice2;
- IfBit0(probLen)
- {
- UpdateBit0(probLen);
- probLen = prob + LenMid + (posState << kLenNumMidBits);
- offset = kLenNumLowSymbols;
- numBits = kLenNumMidBits;
- }
- else
- {
- UpdateBit1(probLen);
- probLen = prob + LenHigh;
- offset = kLenNumLowSymbols + kLenNumMidSymbols;
- numBits = kLenNumHighBits;
- }
- }
- RangeDecoderBitTreeDecode(probLen, numBits, len);
- len += offset;
- }
-
- if (state < 4)
- {
- int posSlot;
- state += kNumLitStates;
- prob = p + PosSlot +
- ((len < kNumLenToPosStates ? len : kNumLenToPosStates - 1) <<
- kNumPosSlotBits);
- RangeDecoderBitTreeDecode(prob, kNumPosSlotBits, posSlot);
- if (posSlot >= kStartPosModelIndex)
- {
- int numDirectBits = ((posSlot >> 1) - 1);
- rep0 = (2 | ((UInt32)posSlot & 1));
- if (posSlot < kEndPosModelIndex)
- {
- rep0 <<= numDirectBits;
- prob = p + SpecPos + rep0 - posSlot - 1;
- }
- else
- {
- numDirectBits -= kNumAlignBits;
- do
- {
- RC_NORMALIZE
- Range >>= 1;
- rep0 <<= 1;
- if (Code >= Range)
- {
- Code -= Range;
- rep0 |= 1;
- }
- }
- while (--numDirectBits != 0);
- prob = p + Align;
- rep0 <<= kNumAlignBits;
- numDirectBits = kNumAlignBits;
- }
- {
- int i = 1;
- int mi = 1;
- do
- {
- CProb *prob3 = prob + mi;
- RC_GET_BIT2(prob3, mi, ; , rep0 |= i);
- i <<= 1;
- }
- while(--numDirectBits != 0);
- }
- }
- else
- rep0 = posSlot;
- if (++rep0 == (UInt32)(0))
- {
- /* it's for stream version */
- len = kLzmaStreamWasFinishedId;
- break;
- }
- }
-
- len += kMatchMinLen;
- #ifdef _LZMA_OUT_READ
- if (rep0 > distanceLimit)
- #else
- if (rep0 > nowPos)
- #endif
- return LZMA_RESULT_DATA_ERROR;
-
- #ifdef _LZMA_OUT_READ
- if (dictionarySize - distanceLimit > (UInt32)len)
- distanceLimit += len;
- else
- distanceLimit = dictionarySize;
- #endif
-
- do
- {
- #ifdef _LZMA_OUT_READ
- UInt32 pos = dictionaryPos - rep0;
- if (pos >= dictionarySize)
- pos += dictionarySize;
- previousByte = dictionary[pos];
- dictionary[dictionaryPos] = previousByte;
- if (++dictionaryPos == dictionarySize)
- dictionaryPos = 0;
- #else
- previousByte = outStream[nowPos - rep0];
- #endif
- len--;
- outStream[nowPos++] = previousByte;
- }
- while(len != 0 && nowPos < outSize);
- }
- }
- RC_NORMALIZE;
-
- #ifdef _LZMA_OUT_READ
- vs->Range = Range;
- vs->Code = Code;
- vs->DictionaryPos = dictionaryPos;
- vs->GlobalPos = globalPos + (UInt32)nowPos;
- vs->DistanceLimit = distanceLimit;
- vs->Reps[0] = rep0;
- vs->Reps[1] = rep1;
- vs->Reps[2] = rep2;
- vs->Reps[3] = rep3;
- vs->State = state;
- vs->RemainLen = len;
- vs->TempDictionary[0] = tempDictionary[0];
- #endif
-
- #ifdef _LZMA_IN_CB
- vs->Buffer = Buffer;
- vs->BufferLim = BufferLim;
- #else
- *inSizeProcessed = (SizeT)(Buffer - inStream);
- #endif
- *outSizeProcessed = nowPos;
- return LZMA_RESULT_OK;
-}
diff --git a/C/Compress/Lzma/LzmaDecode.h b/C/Compress/Lzma/LzmaDecode.h
deleted file mode 100755
index 2870eeb9..00000000
--- a/C/Compress/Lzma/LzmaDecode.h
+++ /dev/null
@@ -1,113 +0,0 @@
-/*
- LzmaDecode.h
- LZMA Decoder interface
-
- LZMA SDK 4.40 Copyright (c) 1999-2006 Igor Pavlov (2006-05-01)
- http://www.7-zip.org/
-
- LZMA SDK is licensed under two licenses:
- 1) GNU Lesser General Public License (GNU LGPL)
- 2) Common Public License (CPL)
- It means that you can select one of these two licenses and
- follow rules of that license.
-
- SPECIAL EXCEPTION:
- Igor Pavlov, as the author of this code, expressly permits you to
- statically or dynamically link your code (or bind by name) to the
- interfaces of this file without subjecting your linked code to the
- terms of the CPL or GNU LGPL. Any modifications or additions
- to this file, however, are subject to the LGPL or CPL terms.
-*/
-
-#ifndef __LZMADECODE_H
-#define __LZMADECODE_H
-
-#include "LzmaTypes.h"
-
-/* #define _LZMA_IN_CB */
-/* Use callback for input data */
-
-/* #define _LZMA_OUT_READ */
-/* Use read function for output data */
-
-/* #define _LZMA_PROB32 */
-/* It can increase speed on some 32-bit CPUs,
- but memory usage will be doubled in that case */
-
-/* #define _LZMA_LOC_OPT */
-/* Enable local speed optimizations inside code */
-
-#ifdef _LZMA_PROB32
-#define CProb UInt32
-#else
-#define CProb UInt16
-#endif
-
-#define LZMA_RESULT_OK 0
-#define LZMA_RESULT_DATA_ERROR 1
-
-#ifdef _LZMA_IN_CB
-typedef struct _ILzmaInCallback
-{
- int (*Read)(void *object, const unsigned char **buffer, SizeT *bufferSize);
-} ILzmaInCallback;
-#endif
-
-#define LZMA_BASE_SIZE 1846
-#define LZMA_LIT_SIZE 768
-
-#define LZMA_PROPERTIES_SIZE 5
-
-typedef struct _CLzmaProperties
-{
- int lc;
- int lp;
- int pb;
- #ifdef _LZMA_OUT_READ
- UInt32 DictionarySize;
- #endif
-}CLzmaProperties;
-
-int LzmaDecodeProperties(CLzmaProperties *propsRes, const unsigned char *propsData, int size);
-
-#define LzmaGetNumProbs(Properties) (LZMA_BASE_SIZE + (LZMA_LIT_SIZE << ((Properties)->lc + (Properties)->lp)))
-
-#define kLzmaNeedInitId (-2)
-
-typedef struct _CLzmaDecoderState
-{
- CLzmaProperties Properties;
- CProb *Probs;
-
- #ifdef _LZMA_IN_CB
- const unsigned char *Buffer;
- const unsigned char *BufferLim;
- #endif
-
- #ifdef _LZMA_OUT_READ
- unsigned char *Dictionary;
- UInt32 Range;
- UInt32 Code;
- UInt32 DictionaryPos;
- UInt32 GlobalPos;
- UInt32 DistanceLimit;
- UInt32 Reps[4];
- int State;
- int RemainLen;
- unsigned char TempDictionary[4];
- #endif
-} CLzmaDecoderState;
-
-#ifdef _LZMA_OUT_READ
-#define LzmaDecoderInit(vs) { (vs)->RemainLen = kLzmaNeedInitId; }
-#endif
-
-int LzmaDecode(CLzmaDecoderState *vs,
- #ifdef _LZMA_IN_CB
- ILzmaInCallback *inCallback,
- #else
- const unsigned char *inStream, SizeT inSize, SizeT *inSizeProcessed,
- #endif
- unsigned char *outStream, SizeT outSize, SizeT *outSizeProcessed);
-
-#endif
diff --git a/C/Compress/Lzma/LzmaDecodeSize.c b/C/Compress/Lzma/LzmaDecodeSize.c
deleted file mode 100755
index a3a5eb9d..00000000
--- a/C/Compress/Lzma/LzmaDecodeSize.c
+++ /dev/null
@@ -1,712 +0,0 @@
-/*
- LzmaDecodeSize.c
- LZMA Decoder (optimized for Size version)
-
- LZMA SDK 4.40 Copyright (c) 1999-2006 Igor Pavlov (2006-05-01)
- http://www.7-zip.org/
-
- LZMA SDK is licensed under two licenses:
- 1) GNU Lesser General Public License (GNU LGPL)
- 2) Common Public License (CPL)
- It means that you can select one of these two licenses and
- follow rules of that license.
-
- SPECIAL EXCEPTION:
- Igor Pavlov, as the author of this code, expressly permits you to
- statically or dynamically link your code (or bind by name) to the
- interfaces of this file without subjecting your linked code to the
- terms of the CPL or GNU LGPL. Any modifications or additions
- to this file, however, are subject to the LGPL or CPL terms.
-*/
-
-#include "LzmaDecode.h"
-
-#define kNumTopBits 24
-#define kTopValue ((UInt32)1 << kNumTopBits)
-
-#define kNumBitModelTotalBits 11
-#define kBitModelTotal (1 << kNumBitModelTotalBits)
-#define kNumMoveBits 5
-
-typedef struct _CRangeDecoder
-{
- const Byte *Buffer;
- const Byte *BufferLim;
- UInt32 Range;
- UInt32 Code;
- #ifdef _LZMA_IN_CB
- ILzmaInCallback *InCallback;
- int Result;
- #endif
- int ExtraBytes;
-} CRangeDecoder;
-
-Byte RangeDecoderReadByte(CRangeDecoder *rd)
-{
- if (rd->Buffer == rd->BufferLim)
- {
- #ifdef _LZMA_IN_CB
- SizeT size;
- rd->Result = rd->InCallback->Read(rd->InCallback, &rd->Buffer, &size);
- rd->BufferLim = rd->Buffer + size;
- if (size == 0)
- #endif
- {
- rd->ExtraBytes = 1;
- return 0xFF;
- }
- }
- return (*rd->Buffer++);
-}
-
-/* #define ReadByte (*rd->Buffer++) */
-#define ReadByte (RangeDecoderReadByte(rd))
-
-void RangeDecoderInit(CRangeDecoder *rd
- #ifndef _LZMA_IN_CB
- , const Byte *stream, SizeT bufferSize
- #endif
- )
-{
- int i;
- #ifdef _LZMA_IN_CB
- rd->Buffer = rd->BufferLim = 0;
- #else
- rd->Buffer = stream;
- rd->BufferLim = stream + bufferSize;
- #endif
- rd->ExtraBytes = 0;
- rd->Code = 0;
- rd->Range = (0xFFFFFFFF);
- for(i = 0; i < 5; i++)
- rd->Code = (rd->Code << 8) | ReadByte;
-}
-
-#define RC_INIT_VAR UInt32 range = rd->Range; UInt32 code = rd->Code;
-#define RC_FLUSH_VAR rd->Range = range; rd->Code = code;
-#define RC_NORMALIZE if (range < kTopValue) { range <<= 8; code = (code << 8) | ReadByte; }
-
-UInt32 RangeDecoderDecodeDirectBits(CRangeDecoder *rd, int numTotalBits)
-{
- RC_INIT_VAR
- UInt32 result = 0;
- int i;
- for (i = numTotalBits; i != 0; i--)
- {
- /* UInt32 t; */
- range >>= 1;
-
- result <<= 1;
- if (code >= range)
- {
- code -= range;
- result |= 1;
- }
- /*
- t = (code - range) >> 31;
- t &= 1;
- code -= range & (t - 1);
- result = (result + result) | (1 - t);
- */
- RC_NORMALIZE
- }
- RC_FLUSH_VAR
- return result;
-}
-
-int RangeDecoderBitDecode(CProb *prob, CRangeDecoder *rd)
-{
- UInt32 bound = (rd->Range >> kNumBitModelTotalBits) * *prob;
- if (rd->Code < bound)
- {
- rd->Range = bound;
- *prob += (kBitModelTotal - *prob) >> kNumMoveBits;
- if (rd->Range < kTopValue)
- {
- rd->Code = (rd->Code << 8) | ReadByte;
- rd->Range <<= 8;
- }
- return 0;
- }
- else
- {
- rd->Range -= bound;
- rd->Code -= bound;
- *prob -= (*prob) >> kNumMoveBits;
- if (rd->Range < kTopValue)
- {
- rd->Code = (rd->Code << 8) | ReadByte;
- rd->Range <<= 8;
- }
- return 1;
- }
-}
-
-#define RC_GET_BIT2(prob, mi, A0, A1) \
- UInt32 bound = (range >> kNumBitModelTotalBits) * *prob; \
- if (code < bound) \
- { A0; range = bound; *prob += (kBitModelTotal - *prob) >> kNumMoveBits; mi <<= 1; } \
- else \
- { A1; range -= bound; code -= bound; *prob -= (*prob) >> kNumMoveBits; mi = (mi + mi) + 1; } \
- RC_NORMALIZE
-
-#define RC_GET_BIT(prob, mi) RC_GET_BIT2(prob, mi, ; , ;)
-
-int RangeDecoderBitTreeDecode(CProb *probs, int numLevels, CRangeDecoder *rd)
-{
- int mi = 1;
- int i;
- #ifdef _LZMA_LOC_OPT
- RC_INIT_VAR
- #endif
- for(i = numLevels; i != 0; i--)
- {
- #ifdef _LZMA_LOC_OPT
- CProb *prob = probs + mi;
- RC_GET_BIT(prob, mi)
- #else
- mi = (mi + mi) + RangeDecoderBitDecode(probs + mi, rd);
- #endif
- }
- #ifdef _LZMA_LOC_OPT
- RC_FLUSH_VAR
- #endif
- return mi - (1 << numLevels);
-}
-
-int RangeDecoderReverseBitTreeDecode(CProb *probs, int numLevels, CRangeDecoder *rd)
-{
- int mi = 1;
- int i;
- int symbol = 0;
- #ifdef _LZMA_LOC_OPT
- RC_INIT_VAR
- #endif
- for(i = 0; i < numLevels; i++)
- {
- #ifdef _LZMA_LOC_OPT
- CProb *prob = probs + mi;
- RC_GET_BIT2(prob, mi, ; , symbol |= (1 << i))
- #else
- int bit = RangeDecoderBitDecode(probs + mi, rd);
- mi = mi + mi + bit;
- symbol |= (bit << i);
- #endif
- }
- #ifdef _LZMA_LOC_OPT
- RC_FLUSH_VAR
- #endif
- return symbol;
-}
-
-Byte LzmaLiteralDecode(CProb *probs, CRangeDecoder *rd)
-{
- int symbol = 1;
- #ifdef _LZMA_LOC_OPT
- RC_INIT_VAR
- #endif
- do
- {
- #ifdef _LZMA_LOC_OPT
- CProb *prob = probs + symbol;
- RC_GET_BIT(prob, symbol)
- #else
- symbol = (symbol + symbol) | RangeDecoderBitDecode(probs + symbol, rd);
- #endif
- }
- while (symbol < 0x100);
- #ifdef _LZMA_LOC_OPT
- RC_FLUSH_VAR
- #endif
- return symbol;
-}
-
-Byte LzmaLiteralDecodeMatch(CProb *probs, CRangeDecoder *rd, Byte matchByte)
-{
- int symbol = 1;
- #ifdef _LZMA_LOC_OPT
- RC_INIT_VAR
- #endif
- do
- {
- int bit;
- int matchBit = (matchByte >> 7) & 1;
- matchByte <<= 1;
- #ifdef _LZMA_LOC_OPT
- {
- CProb *prob = probs + 0x100 + (matchBit << 8) + symbol;
- RC_GET_BIT2(prob, symbol, bit = 0, bit = 1)
- }
- #else
- bit = RangeDecoderBitDecode(probs + 0x100 + (matchBit << 8) + symbol, rd);
- symbol = (symbol << 1) | bit;
- #endif
- if (matchBit != bit)
- {
- while (symbol < 0x100)
- {
- #ifdef _LZMA_LOC_OPT
- CProb *prob = probs + symbol;
- RC_GET_BIT(prob, symbol)
- #else
- symbol = (symbol + symbol) | RangeDecoderBitDecode(probs + symbol, rd);
- #endif
- }
- break;
- }
- }
- while (symbol < 0x100);
- #ifdef _LZMA_LOC_OPT
- RC_FLUSH_VAR
- #endif
- return symbol;
-}
-
-#define kNumPosBitsMax 4
-#define kNumPosStatesMax (1 << kNumPosBitsMax)
-
-#define kLenNumLowBits 3
-#define kLenNumLowSymbols (1 << kLenNumLowBits)
-#define kLenNumMidBits 3
-#define kLenNumMidSymbols (1 << kLenNumMidBits)
-#define kLenNumHighBits 8
-#define kLenNumHighSymbols (1 << kLenNumHighBits)
-
-#define LenChoice 0
-#define LenChoice2 (LenChoice + 1)
-#define LenLow (LenChoice2 + 1)
-#define LenMid (LenLow + (kNumPosStatesMax << kLenNumLowBits))
-#define LenHigh (LenMid + (kNumPosStatesMax << kLenNumMidBits))
-#define kNumLenProbs (LenHigh + kLenNumHighSymbols)
-
-int LzmaLenDecode(CProb *p, CRangeDecoder *rd, int posState)
-{
- if(RangeDecoderBitDecode(p + LenChoice, rd) == 0)
- return RangeDecoderBitTreeDecode(p + LenLow +
- (posState << kLenNumLowBits), kLenNumLowBits, rd);
- if(RangeDecoderBitDecode(p + LenChoice2, rd) == 0)
- return kLenNumLowSymbols + RangeDecoderBitTreeDecode(p + LenMid +
- (posState << kLenNumMidBits), kLenNumMidBits, rd);
- return kLenNumLowSymbols + kLenNumMidSymbols +
- RangeDecoderBitTreeDecode(p + LenHigh, kLenNumHighBits, rd);
-}
-
-#define kNumStates 12
-#define kNumLitStates 7
-
-#define kStartPosModelIndex 4
-#define kEndPosModelIndex 14
-#define kNumFullDistances (1 << (kEndPosModelIndex >> 1))
-
-#define kNumPosSlotBits 6
-#define kNumLenToPosStates 4
-
-#define kNumAlignBits 4
-#define kAlignTableSize (1 << kNumAlignBits)
-
-#define kMatchMinLen 2
-
-#define IsMatch 0
-#define IsRep (IsMatch + (kNumStates << kNumPosBitsMax))
-#define IsRepG0 (IsRep + kNumStates)
-#define IsRepG1 (IsRepG0 + kNumStates)
-#define IsRepG2 (IsRepG1 + kNumStates)
-#define IsRep0Long (IsRepG2 + kNumStates)
-#define PosSlot (IsRep0Long + (kNumStates << kNumPosBitsMax))
-#define SpecPos (PosSlot + (kNumLenToPosStates << kNumPosSlotBits))
-#define Align (SpecPos + kNumFullDistances - kEndPosModelIndex)
-#define LenCoder (Align + kAlignTableSize)
-#define RepLenCoder (LenCoder + kNumLenProbs)
-#define Literal (RepLenCoder + kNumLenProbs)
-
-#if Literal != LZMA_BASE_SIZE
-StopCompilingDueBUG
-#endif
-
-int LzmaDecodeProperties(CLzmaProperties *propsRes, const unsigned char *propsData, int size)
-{
- unsigned char prop0;
- if (size < LZMA_PROPERTIES_SIZE)
- return LZMA_RESULT_DATA_ERROR;
- prop0 = propsData[0];
- if (prop0 >= (9 * 5 * 5))
- return LZMA_RESULT_DATA_ERROR;
- {
- for (propsRes->pb = 0; prop0 >= (9 * 5); propsRes->pb++, prop0 -= (9 * 5));
- for (propsRes->lp = 0; prop0 >= 9; propsRes->lp++, prop0 -= 9);
- propsRes->lc = prop0;
- /*
- unsigned char remainder = (unsigned char)(prop0 / 9);
- propsRes->lc = prop0 % 9;
- propsRes->pb = remainder / 5;
- propsRes->lp = remainder % 5;
- */
- }
-
- #ifdef _LZMA_OUT_READ
- {
- int i;
- propsRes->DictionarySize = 0;
- for (i = 0; i < 4; i++)
- propsRes->DictionarySize += (UInt32)(propsData[1 + i]) << (i * 8);
- if (propsRes->DictionarySize == 0)
- propsRes->DictionarySize = 1;
- }
- #endif
- return LZMA_RESULT_OK;
-}
-
-#define kLzmaStreamWasFinishedId (-1)
-
-int LzmaDecode(CLzmaDecoderState *vs,
- #ifdef _LZMA_IN_CB
- ILzmaInCallback *InCallback,
- #else
- const unsigned char *inStream, SizeT inSize, SizeT *inSizeProcessed,
- #endif
- unsigned char *outStream, SizeT outSize, SizeT *outSizeProcessed)
-{
- CProb *p = vs->Probs;
- SizeT nowPos = 0;
- Byte previousByte = 0;
- UInt32 posStateMask = (1 << (vs->Properties.pb)) - 1;
- UInt32 literalPosMask = (1 << (vs->Properties.lp)) - 1;
- int lc = vs->Properties.lc;
- CRangeDecoder rd;
-
- #ifdef _LZMA_OUT_READ
-
- int state = vs->State;
- UInt32 rep0 = vs->Reps[0], rep1 = vs->Reps[1], rep2 = vs->Reps[2], rep3 = vs->Reps[3];
- int len = vs->RemainLen;
- UInt32 globalPos = vs->GlobalPos;
- UInt32 distanceLimit = vs->DistanceLimit;
-
- Byte *dictionary = vs->Dictionary;
- UInt32 dictionarySize = vs->Properties.DictionarySize;
- UInt32 dictionaryPos = vs->DictionaryPos;
-
- Byte tempDictionary[4];
-
- rd.Range = vs->Range;
- rd.Code = vs->Code;
- #ifdef _LZMA_IN_CB
- rd.InCallback = InCallback;
- rd.Buffer = vs->Buffer;
- rd.BufferLim = vs->BufferLim;
- #else
- rd.Buffer = inStream;
- rd.BufferLim = inStream + inSize;
- #endif
-
- #ifndef _LZMA_IN_CB
- *inSizeProcessed = 0;
- #endif
- *outSizeProcessed = 0;
- if (len == kLzmaStreamWasFinishedId)
- return LZMA_RESULT_OK;
-
- if (dictionarySize == 0)
- {
- dictionary = tempDictionary;
- dictionarySize = 1;
- tempDictionary[0] = vs->TempDictionary[0];
- }
-
- if (len == kLzmaNeedInitId)
- {
- {
- UInt32 numProbs = Literal + ((UInt32)LZMA_LIT_SIZE << (lc + vs->Properties.lp));
- UInt32 i;
- for (i = 0; i < numProbs; i++)
- p[i] = kBitModelTotal >> 1;
- rep0 = rep1 = rep2 = rep3 = 1;
- state = 0;
- globalPos = 0;
- distanceLimit = 0;
- dictionaryPos = 0;
- dictionary[dictionarySize - 1] = 0;
- RangeDecoderInit(&rd
- #ifndef _LZMA_IN_CB
- , inStream, inSize
- #endif
- );
- #ifdef _LZMA_IN_CB
- if (rd.Result != LZMA_RESULT_OK)
- return rd.Result;
- #endif
- if (rd.ExtraBytes != 0)
- return LZMA_RESULT_DATA_ERROR;
- }
- len = 0;
- }
- while(len != 0 && nowPos < outSize)
- {
- UInt32 pos = dictionaryPos - rep0;
- if (pos >= dictionarySize)
- pos += dictionarySize;
- outStream[nowPos++] = dictionary[dictionaryPos] = dictionary[pos];
- if (++dictionaryPos == dictionarySize)
- dictionaryPos = 0;
- len--;
- }
- if (dictionaryPos == 0)
- previousByte = dictionary[dictionarySize - 1];
- else
- previousByte = dictionary[dictionaryPos - 1];
-
- #ifdef _LZMA_IN_CB
- rd.Result = LZMA_RESULT_OK;
- #endif
- rd.ExtraBytes = 0;
-
- #else /* if !_LZMA_OUT_READ */
-
- int state = 0;
- UInt32 rep0 = 1, rep1 = 1, rep2 = 1, rep3 = 1;
- int len = 0;
-
- #ifndef _LZMA_IN_CB
- *inSizeProcessed = 0;
- #endif
- *outSizeProcessed = 0;
-
- {
- UInt32 i;
- UInt32 numProbs = Literal + ((UInt32)LZMA_LIT_SIZE << (lc + vs->Properties.lp));
- for (i = 0; i < numProbs; i++)
- p[i] = kBitModelTotal >> 1;
- }
-
- #ifdef _LZMA_IN_CB
- rd.InCallback = InCallback;
- #endif
- RangeDecoderInit(&rd
- #ifndef _LZMA_IN_CB
- , inStream, inSize
- #endif
- );
-
- #ifdef _LZMA_IN_CB
- if (rd.Result != LZMA_RESULT_OK)
- return rd.Result;
- #endif
- if (rd.ExtraBytes != 0)
- return LZMA_RESULT_DATA_ERROR;
-
- #endif /* _LZMA_OUT_READ */
-
-
- while(nowPos < outSize)
- {
- int posState = (int)(
- (nowPos
- #ifdef _LZMA_OUT_READ
- + globalPos
- #endif
- )
- & posStateMask);
- #ifdef _LZMA_IN_CB
- if (rd.Result != LZMA_RESULT_OK)
- return rd.Result;
- #endif
- if (rd.ExtraBytes != 0)
- return LZMA_RESULT_DATA_ERROR;
- if (RangeDecoderBitDecode(p + IsMatch + (state << kNumPosBitsMax) + posState, &rd) == 0)
- {
- CProb *probs = p + Literal + (LZMA_LIT_SIZE *
- (((
- (nowPos
- #ifdef _LZMA_OUT_READ
- + globalPos
- #endif
- )
- & literalPosMask) << lc) + (previousByte >> (8 - lc))));
-
- if (state >= kNumLitStates)
- {
- Byte matchByte;
- #ifdef _LZMA_OUT_READ
- UInt32 pos = dictionaryPos - rep0;
- if (pos >= dictionarySize)
- pos += dictionarySize;
- matchByte = dictionary[pos];
- #else
- matchByte = outStream[nowPos - rep0];
- #endif
- previousByte = LzmaLiteralDecodeMatch(probs, &rd, matchByte);
- }
- else
- previousByte = LzmaLiteralDecode(probs, &rd);
- outStream[nowPos++] = previousByte;
- #ifdef _LZMA_OUT_READ
- if (distanceLimit < dictionarySize)
- distanceLimit++;
-
- dictionary[dictionaryPos] = previousByte;
- if (++dictionaryPos == dictionarySize)
- dictionaryPos = 0;
- #endif
- if (state < 4) state = 0;
- else if (state < 10) state -= 3;
- else state -= 6;
- }
- else
- {
- if (RangeDecoderBitDecode(p + IsRep + state, &rd) == 1)
- {
- if (RangeDecoderBitDecode(p + IsRepG0 + state, &rd) == 0)
- {
- if (RangeDecoderBitDecode(p + IsRep0Long + (state << kNumPosBitsMax) + posState, &rd) == 0)
- {
- #ifdef _LZMA_OUT_READ
- UInt32 pos;
- #endif
-
- #ifdef _LZMA_OUT_READ
- if (distanceLimit == 0)
- #else
- if (nowPos == 0)
- #endif
- return LZMA_RESULT_DATA_ERROR;
-
- state = state < 7 ? 9 : 11;
- #ifdef _LZMA_OUT_READ
- pos = dictionaryPos - rep0;
- if (pos >= dictionarySize)
- pos += dictionarySize;
- previousByte = dictionary[pos];
- dictionary[dictionaryPos] = previousByte;
- if (++dictionaryPos == dictionarySize)
- dictionaryPos = 0;
- #else
- previousByte = outStream[nowPos - rep0];
- #endif
- outStream[nowPos++] = previousByte;
-
- #ifdef _LZMA_OUT_READ
- if (distanceLimit < dictionarySize)
- distanceLimit++;
- #endif
- continue;
- }
- }
- else
- {
- UInt32 distance;
- if(RangeDecoderBitDecode(p + IsRepG1 + state, &rd) == 0)
- distance = rep1;
- else
- {
- if(RangeDecoderBitDecode(p + IsRepG2 + state, &rd) == 0)
- distance = rep2;
- else
- {
- distance = rep3;
- rep3 = rep2;
- }
- rep2 = rep1;
- }
- rep1 = rep0;
- rep0 = distance;
- }
- len = LzmaLenDecode(p + RepLenCoder, &rd, posState);
- state = state < 7 ? 8 : 11;
- }
- else
- {
- int posSlot;
- rep3 = rep2;
- rep2 = rep1;
- rep1 = rep0;
- state = state < 7 ? 7 : 10;
- len = LzmaLenDecode(p + LenCoder, &rd, posState);
- posSlot = RangeDecoderBitTreeDecode(p + PosSlot +
- ((len < kNumLenToPosStates ? len : kNumLenToPosStates - 1) <<
- kNumPosSlotBits), kNumPosSlotBits, &rd);
- if (posSlot >= kStartPosModelIndex)
- {
- int numDirectBits = ((posSlot >> 1) - 1);
- rep0 = ((2 | ((UInt32)posSlot & 1)) << numDirectBits);
- if (posSlot < kEndPosModelIndex)
- {
- rep0 += RangeDecoderReverseBitTreeDecode(
- p + SpecPos + rep0 - posSlot - 1, numDirectBits, &rd);
- }
- else
- {
- rep0 += RangeDecoderDecodeDirectBits(&rd,
- numDirectBits - kNumAlignBits) << kNumAlignBits;
- rep0 += RangeDecoderReverseBitTreeDecode(p + Align, kNumAlignBits, &rd);
- }
- }
- else
- rep0 = posSlot;
- if (++rep0 == (UInt32)(0))
- {
- /* it's for stream version */
- len = kLzmaStreamWasFinishedId;
- break;
- }
- }
-
- len += kMatchMinLen;
- #ifdef _LZMA_OUT_READ
- if (rep0 > distanceLimit)
- #else
- if (rep0 > nowPos)
- #endif
- return LZMA_RESULT_DATA_ERROR;
-
- #ifdef _LZMA_OUT_READ
- if (dictionarySize - distanceLimit > (UInt32)len)
- distanceLimit += len;
- else
- distanceLimit = dictionarySize;
- #endif
-
- do
- {
- #ifdef _LZMA_OUT_READ
- UInt32 pos = dictionaryPos - rep0;
- if (pos >= dictionarySize)
- pos += dictionarySize;
- previousByte = dictionary[pos];
- dictionary[dictionaryPos] = previousByte;
- if (++dictionaryPos == dictionarySize)
- dictionaryPos = 0;
- #else
- previousByte = outStream[nowPos - rep0];
- #endif
- len--;
- outStream[nowPos++] = previousByte;
- }
- while(len != 0 && nowPos < outSize);
- }
- }
-
-
- #ifdef _LZMA_OUT_READ
- vs->Range = rd.Range;
- vs->Code = rd.Code;
- vs->DictionaryPos = dictionaryPos;
- vs->GlobalPos = globalPos + (UInt32)nowPos;
- vs->DistanceLimit = distanceLimit;
- vs->Reps[0] = rep0;
- vs->Reps[1] = rep1;
- vs->Reps[2] = rep2;
- vs->Reps[3] = rep3;
- vs->State = state;
- vs->RemainLen = len;
- vs->TempDictionary[0] = tempDictionary[0];
- #endif
-
- #ifdef _LZMA_IN_CB
- vs->Buffer = rd.Buffer;
- vs->BufferLim = rd.BufferLim;
- #else
- *inSizeProcessed = (SizeT)(rd.Buffer - inStream);
- #endif
- *outSizeProcessed = nowPos;
- return LZMA_RESULT_OK;
-}
diff --git a/C/Compress/Lzma/LzmaStateDecode.c b/C/Compress/Lzma/LzmaStateDecode.c
deleted file mode 100755
index 5dc8f0e2..00000000
--- a/C/Compress/Lzma/LzmaStateDecode.c
+++ /dev/null
@@ -1,521 +0,0 @@
-/*
- LzmaStateDecode.c
- LZMA Decoder (State version)
-
- LZMA SDK 4.40 Copyright (c) 1999-2006 Igor Pavlov (2006-05-01)
- http://www.7-zip.org/
-
- LZMA SDK is licensed under two licenses:
- 1) GNU Lesser General Public License (GNU LGPL)
- 2) Common Public License (CPL)
- It means that you can select one of these two licenses and
- follow rules of that license.
-
- SPECIAL EXCEPTION:
- Igor Pavlov, as the author of this Code, expressly permits you to
- statically or dynamically link your Code (or bind by name) to the
- interfaces of this file without subjecting your linked Code to the
- terms of the CPL or GNU LGPL. Any modifications or additions
- to this file, however, are subject to the LGPL or CPL terms.
-*/
-
-#include "LzmaStateDecode.h"
-
-#define kNumTopBits 24
-#define kTopValue ((UInt32)1 << kNumTopBits)
-
-#define kNumBitModelTotalBits 11
-#define kBitModelTotal (1 << kNumBitModelTotalBits)
-#define kNumMoveBits 5
-
-#define RC_READ_BYTE (*Buffer++)
-
-#define RC_INIT Code = 0; Range = 0xFFFFFFFF; \
- { int i; for(i = 0; i < 5; i++) { Code = (Code << 8) | RC_READ_BYTE; }}
-
-#define RC_NORMALIZE if (Range < kTopValue) { Range <<= 8; Code = (Code << 8) | RC_READ_BYTE; }
-
-#define IfBit0(p) RC_NORMALIZE; bound = (Range >> kNumBitModelTotalBits) * *(p); if (Code < bound)
-#define UpdateBit0(p) Range = bound; *(p) += (kBitModelTotal - *(p)) >> kNumMoveBits;
-#define UpdateBit1(p) Range -= bound; Code -= bound; *(p) -= (*(p)) >> kNumMoveBits;
-
-#define RC_GET_BIT2(p, mi, A0, A1) IfBit0(p) \
- { UpdateBit0(p); mi <<= 1; A0; } else \
- { UpdateBit1(p); mi = (mi + mi) + 1; A1; }
-
-#define RC_GET_BIT(p, mi) RC_GET_BIT2(p, mi, ; , ;)
-
-#define RangeDecoderBitTreeDecode(probs, numLevels, res) \
- { int i = numLevels; res = 1; \
- do { CProb *p = probs + res; RC_GET_BIT(p, res) } while(--i != 0); \
- res -= (1 << numLevels); }
-
-
-#define kNumPosBitsMax 4
-#define kNumPosStatesMax (1 << kNumPosBitsMax)
-
-#define kLenNumLowBits 3
-#define kLenNumLowSymbols (1 << kLenNumLowBits)
-#define kLenNumMidBits 3
-#define kLenNumMidSymbols (1 << kLenNumMidBits)
-#define kLenNumHighBits 8
-#define kLenNumHighSymbols (1 << kLenNumHighBits)
-
-#define LenChoice 0
-#define LenChoice2 (LenChoice + 1)
-#define LenLow (LenChoice2 + 1)
-#define LenMid (LenLow + (kNumPosStatesMax << kLenNumLowBits))
-#define LenHigh (LenMid + (kNumPosStatesMax << kLenNumMidBits))
-#define kNumLenProbs (LenHigh + kLenNumHighSymbols)
-
-
-#define kNumStates 12
-#define kNumLitStates 7
-
-#define kStartPosModelIndex 4
-#define kEndPosModelIndex 14
-#define kNumFullDistances (1 << (kEndPosModelIndex >> 1))
-
-#define kNumPosSlotBits 6
-#define kNumLenToPosStates 4
-
-#define kNumAlignBits 4
-#define kAlignTableSize (1 << kNumAlignBits)
-
-#define kMatchMinLen 2
-
-#define IsMatch 0
-#define IsRep (IsMatch + (kNumStates << kNumPosBitsMax))
-#define IsRepG0 (IsRep + kNumStates)
-#define IsRepG1 (IsRepG0 + kNumStates)
-#define IsRepG2 (IsRepG1 + kNumStates)
-#define IsRep0Long (IsRepG2 + kNumStates)
-#define PosSlot (IsRep0Long + (kNumStates << kNumPosBitsMax))
-#define SpecPos (PosSlot + (kNumLenToPosStates << kNumPosSlotBits))
-#define Align (SpecPos + kNumFullDistances - kEndPosModelIndex)
-#define LenCoder (Align + kAlignTableSize)
-#define RepLenCoder (LenCoder + kNumLenProbs)
-#define Literal (RepLenCoder + kNumLenProbs)
-
-#if Literal != LZMA_BASE_SIZE
-StopCompilingDueBUG
-#endif
-
-/* kRequiredInBufferSize = number of required input bytes for worst case:
- longest match with longest distance.
- kLzmaInBufferSize must be larger than kRequiredInBufferSize
- 23 bits = 2 (match select) + 10 (len) + 6 (distance) + 4(align) + 1 (RC_NORMALIZE)
-*/
-
-#define kRequiredInBufferSize ((23 * (kNumBitModelTotalBits - kNumMoveBits + 1) + 26 + 9) / 8)
-
-#define kLzmaStreamWasFinishedId (-1)
-
-int LzmaDecodeProperties(CLzmaProperties *propsRes, const unsigned char *propsData, int size)
-{
- unsigned char prop0;
- if (size < LZMA_PROPERTIES_SIZE)
- return LZMA_RESULT_DATA_ERROR;
- prop0 = propsData[0];
- if (prop0 >= (9 * 5 * 5))
- return LZMA_RESULT_DATA_ERROR;
- {
- for (propsRes->pb = 0; prop0 >= (9 * 5); propsRes->pb++, prop0 -= (9 * 5));
- for (propsRes->lp = 0; prop0 >= 9; propsRes->lp++, prop0 -= 9);
- propsRes->lc = prop0;
- /*
- unsigned char remainder = (unsigned char)(prop0 / 9);
- propsRes->lc = prop0 % 9;
- propsRes->pb = remainder / 5;
- propsRes->lp = remainder % 5;
- */
- }
-
- {
- int i;
- propsRes->DictionarySize = 0;
- for (i = 0; i < 4; i++)
- propsRes->DictionarySize += (UInt32)(propsData[1 + i]) << (i * 8);
- if (propsRes->DictionarySize == 0)
- propsRes->DictionarySize = 1;
- return LZMA_RESULT_OK;
- }
-}
-
-int LzmaDecode(
- CLzmaDecoderState *vs,
- const unsigned char *inStream, SizeT inSize, SizeT *inSizeProcessed,
- unsigned char *outStream, SizeT outSize, SizeT *outSizeProcessed,
- int finishDecoding)
-{
- UInt32 Range = vs->Range;
- UInt32 Code = vs->Code;
-
- unsigned char *Buffer = vs->Buffer;
- int BufferSize = vs->BufferSize; /* don't change it to unsigned int */
- CProb *p = vs->Probs;
-
- int state = vs->State;
- unsigned char previousByte;
- UInt32 rep0 = vs->Reps[0], rep1 = vs->Reps[1], rep2 = vs->Reps[2], rep3 = vs->Reps[3];
- SizeT nowPos = 0;
- UInt32 posStateMask = (1 << (vs->Properties.pb)) - 1;
- UInt32 literalPosMask = (1 << (vs->Properties.lp)) - 1;
- int lc = vs->Properties.lc;
- int len = vs->RemainLen;
- UInt32 globalPos = vs->GlobalPos;
- UInt32 distanceLimit = vs->DistanceLimit;
-
- unsigned char *dictionary = vs->Dictionary;
- UInt32 dictionarySize = vs->Properties.DictionarySize;
- UInt32 dictionaryPos = vs->DictionaryPos;
-
- unsigned char tempDictionary[4];
-
- (*inSizeProcessed) = 0;
- (*outSizeProcessed) = 0;
- if (len == kLzmaStreamWasFinishedId)
- return LZMA_RESULT_OK;
-
- if (dictionarySize == 0)
- {
- dictionary = tempDictionary;
- dictionarySize = 1;
- tempDictionary[0] = vs->TempDictionary[0];
- }
-
- if (len == kLzmaNeedInitId)
- {
- while (inSize > 0 && BufferSize < kLzmaInBufferSize)
- {
- Buffer[BufferSize++] = *inStream++;
- (*inSizeProcessed)++;
- inSize--;
- }
- if (BufferSize < 5)
- {
- vs->BufferSize = BufferSize;
- return finishDecoding ? LZMA_RESULT_DATA_ERROR : LZMA_RESULT_OK;
- }
- {
- UInt32 numProbs = Literal + ((UInt32)LZMA_LIT_SIZE << (lc + vs->Properties.lp));
- UInt32 i;
- for (i = 0; i < numProbs; i++)
- p[i] = kBitModelTotal >> 1;
- rep0 = rep1 = rep2 = rep3 = 1;
- state = 0;
- globalPos = 0;
- distanceLimit = 0;
- dictionaryPos = 0;
- dictionary[dictionarySize - 1] = 0;
- RC_INIT;
- }
- len = 0;
- }
- while(len != 0 && nowPos < outSize)
- {
- UInt32 pos = dictionaryPos - rep0;
- if (pos >= dictionarySize)
- pos += dictionarySize;
- outStream[nowPos++] = dictionary[dictionaryPos] = dictionary[pos];
- if (++dictionaryPos == dictionarySize)
- dictionaryPos = 0;
- len--;
- }
- if (dictionaryPos == 0)
- previousByte = dictionary[dictionarySize - 1];
- else
- previousByte = dictionary[dictionaryPos - 1];
-
- for (;;)
- {
- int bufferPos = (int)(Buffer - vs->Buffer);
- if (BufferSize - bufferPos < kRequiredInBufferSize)
- {
- int i;
- BufferSize -= bufferPos;
- if (BufferSize < 0)
- return LZMA_RESULT_DATA_ERROR;
- for (i = 0; i < BufferSize; i++)
- vs->Buffer[i] = Buffer[i];
- Buffer = vs->Buffer;
- while (inSize > 0 && BufferSize < kLzmaInBufferSize)
- {
- Buffer[BufferSize++] = *inStream++;
- (*inSizeProcessed)++;
- inSize--;
- }
- if (BufferSize < kRequiredInBufferSize && !finishDecoding)
- break;
- }
- if (nowPos >= outSize)
- break;
- {
- CProb *prob;
- UInt32 bound;
- int posState = (int)((nowPos + globalPos) & posStateMask);
-
- prob = p + IsMatch + (state << kNumPosBitsMax) + posState;
- IfBit0(prob)
- {
- int symbol = 1;
- UpdateBit0(prob)
- prob = p + Literal + (LZMA_LIT_SIZE *
- ((((nowPos + globalPos)& literalPosMask) << lc) + (previousByte >> (8 - lc))));
-
- if (state >= kNumLitStates)
- {
- int matchByte;
- UInt32 pos = dictionaryPos - rep0;
- if (pos >= dictionarySize)
- pos += dictionarySize;
- matchByte = dictionary[pos];
- do
- {
- int bit;
- CProb *probLit;
- matchByte <<= 1;
- bit = (matchByte & 0x100);
- probLit = prob + 0x100 + bit + symbol;
- RC_GET_BIT2(probLit, symbol, if (bit != 0) break, if (bit == 0) break)
- }
- while (symbol < 0x100);
- }
- while (symbol < 0x100)
- {
- CProb *probLit = prob + symbol;
- RC_GET_BIT(probLit, symbol)
- }
- previousByte = (unsigned char)symbol;
-
- outStream[nowPos++] = previousByte;
- if (distanceLimit < dictionarySize)
- distanceLimit++;
-
- dictionary[dictionaryPos] = previousByte;
- if (++dictionaryPos == dictionarySize)
- dictionaryPos = 0;
- if (state < 4) state = 0;
- else if (state < 10) state -= 3;
- else state -= 6;
- }
- else
- {
- UpdateBit1(prob);
- prob = p + IsRep + state;
- IfBit0(prob)
- {
- UpdateBit0(prob);
- rep3 = rep2;
- rep2 = rep1;
- rep1 = rep0;
- state = state < kNumLitStates ? 0 : 3;
- prob = p + LenCoder;
- }
- else
- {
- UpdateBit1(prob);
- prob = p + IsRepG0 + state;
- IfBit0(prob)
- {
- UpdateBit0(prob);
- prob = p + IsRep0Long + (state << kNumPosBitsMax) + posState;
- IfBit0(prob)
- {
- UInt32 pos;
- UpdateBit0(prob);
- if (distanceLimit == 0)
- return LZMA_RESULT_DATA_ERROR;
- if (distanceLimit < dictionarySize)
- distanceLimit++;
- state = state < kNumLitStates ? 9 : 11;
- pos = dictionaryPos - rep0;
- if (pos >= dictionarySize)
- pos += dictionarySize;
- previousByte = dictionary[pos];
- dictionary[dictionaryPos] = previousByte;
- if (++dictionaryPos == dictionarySize)
- dictionaryPos = 0;
- outStream[nowPos++] = previousByte;
- continue;
- }
- else
- {
- UpdateBit1(prob);
- }
- }
- else
- {
- UInt32 distance;
- UpdateBit1(prob);
- prob = p + IsRepG1 + state;
- IfBit0(prob)
- {
- UpdateBit0(prob);
- distance = rep1;
- }
- else
- {
- UpdateBit1(prob);
- prob = p + IsRepG2 + state;
- IfBit0(prob)
- {
- UpdateBit0(prob);
- distance = rep2;
- }
- else
- {
- UpdateBit1(prob);
- distance = rep3;
- rep3 = rep2;
- }
- rep2 = rep1;
- }
- rep1 = rep0;
- rep0 = distance;
- }
- state = state < kNumLitStates ? 8 : 11;
- prob = p + RepLenCoder;
- }
- {
- int numBits, offset;
- CProb *probLen = prob + LenChoice;
- IfBit0(probLen)
- {
- UpdateBit0(probLen);
- probLen = prob + LenLow + (posState << kLenNumLowBits);
- offset = 0;
- numBits = kLenNumLowBits;
- }
- else
- {
- UpdateBit1(probLen);
- probLen = prob + LenChoice2;
- IfBit0(probLen)
- {
- UpdateBit0(probLen);
- probLen = prob + LenMid + (posState << kLenNumMidBits);
- offset = kLenNumLowSymbols;
- numBits = kLenNumMidBits;
- }
- else
- {
- UpdateBit1(probLen);
- probLen = prob + LenHigh;
- offset = kLenNumLowSymbols + kLenNumMidSymbols;
- numBits = kLenNumHighBits;
- }
- }
- RangeDecoderBitTreeDecode(probLen, numBits, len);
- len += offset;
- }
-
- if (state < 4)
- {
- int posSlot;
- state += kNumLitStates;
- prob = p + PosSlot +
- ((len < kNumLenToPosStates ? len : kNumLenToPosStates - 1) <<
- kNumPosSlotBits);
- RangeDecoderBitTreeDecode(prob, kNumPosSlotBits, posSlot);
- if (posSlot >= kStartPosModelIndex)
- {
- int numDirectBits = ((posSlot >> 1) - 1);
- rep0 = (2 | ((UInt32)posSlot & 1));
- if (posSlot < kEndPosModelIndex)
- {
- rep0 <<= numDirectBits;
- prob = p + SpecPos + rep0 - posSlot - 1;
- }
- else
- {
- numDirectBits -= kNumAlignBits;
- do
- {
- RC_NORMALIZE
- Range >>= 1;
- rep0 <<= 1;
- if (Code >= Range)
- {
- Code -= Range;
- rep0 |= 1;
- }
- }
- while (--numDirectBits != 0);
- prob = p + Align;
- rep0 <<= kNumAlignBits;
- numDirectBits = kNumAlignBits;
- }
- {
- int i = 1;
- int mi = 1;
- do
- {
- CProb *prob3 = prob + mi;
- RC_GET_BIT2(prob3, mi, ; , rep0 |= i);
- i <<= 1;
- }
- while(--numDirectBits != 0);
- }
- }
- else
- rep0 = posSlot;
- if (++rep0 == (UInt32)(0))
- {
- /* it's for stream version */
- len = kLzmaStreamWasFinishedId;
- break;
- }
- }
-
- len += kMatchMinLen;
- if (rep0 > distanceLimit)
- return LZMA_RESULT_DATA_ERROR;
- if (dictionarySize - distanceLimit > (UInt32)len)
- distanceLimit += len;
- else
- distanceLimit = dictionarySize;
-
- do
- {
- UInt32 pos = dictionaryPos - rep0;
- if (pos >= dictionarySize)
- pos += dictionarySize;
- previousByte = dictionary[pos];
- dictionary[dictionaryPos] = previousByte;
- if (++dictionaryPos == dictionarySize)
- dictionaryPos = 0;
- len--;
- outStream[nowPos++] = previousByte;
- }
- while(len != 0 && nowPos < outSize);
- }
- }
- }
- RC_NORMALIZE;
-
- BufferSize -= (int)(Buffer - vs->Buffer);
- if (BufferSize < 0)
- return LZMA_RESULT_DATA_ERROR;
- {
- int i;
- for (i = 0; i < BufferSize; i++)
- vs->Buffer[i] = Buffer[i];
- }
- vs->BufferSize = BufferSize;
- vs->Range = Range;
- vs->Code = Code;
- vs->DictionaryPos = dictionaryPos;
- vs->GlobalPos = (UInt32)(globalPos + nowPos);
- vs->DistanceLimit = distanceLimit;
- vs->Reps[0] = rep0;
- vs->Reps[1] = rep1;
- vs->Reps[2] = rep2;
- vs->Reps[3] = rep3;
- vs->State = state;
- vs->RemainLen = len;
- vs->TempDictionary[0] = tempDictionary[0];
-
- (*outSizeProcessed) = nowPos;
- return LZMA_RESULT_OK;
-}
diff --git a/C/Compress/Lzma/LzmaStateDecode.h b/C/Compress/Lzma/LzmaStateDecode.h
deleted file mode 100755
index 26490d61..00000000
--- a/C/Compress/Lzma/LzmaStateDecode.h
+++ /dev/null
@@ -1,96 +0,0 @@
-/*
- LzmaStateDecode.h
- LZMA Decoder interface (State version)
-
- LZMA SDK 4.40 Copyright (c) 1999-2006 Igor Pavlov (2006-05-01)
- http://www.7-zip.org/
-
- LZMA SDK is licensed under two licenses:
- 1) GNU Lesser General Public License (GNU LGPL)
- 2) Common Public License (CPL)
- It means that you can select one of these two licenses and
- follow rules of that license.
-
- SPECIAL EXCEPTION:
- Igor Pavlov, as the author of this code, expressly permits you to
- statically or dynamically link your code (or bind by name) to the
- interfaces of this file without subjecting your linked code to the
- terms of the CPL or GNU LGPL. Any modifications or additions
- to this file, however, are subject to the LGPL or CPL terms.
-*/
-
-#ifndef __LZMASTATEDECODE_H
-#define __LZMASTATEDECODE_H
-
-#include "LzmaTypes.h"
-
-/* #define _LZMA_PROB32 */
-/* It can increase speed on some 32-bit CPUs,
- but memory usage will be doubled in that case */
-
-#ifdef _LZMA_PROB32
-#define CProb UInt32
-#else
-#define CProb UInt16
-#endif
-
-#define LZMA_RESULT_OK 0
-#define LZMA_RESULT_DATA_ERROR 1
-
-#define LZMA_BASE_SIZE 1846
-#define LZMA_LIT_SIZE 768
-
-#define LZMA_PROPERTIES_SIZE 5
-
-typedef struct _CLzmaProperties
-{
- int lc;
- int lp;
- int pb;
- UInt32 DictionarySize;
-}CLzmaProperties;
-
-int LzmaDecodeProperties(CLzmaProperties *propsRes, const unsigned char *propsData, int size);
-
-#define LzmaGetNumProbs(lzmaProps) (LZMA_BASE_SIZE + (LZMA_LIT_SIZE << ((lzmaProps)->lc + (lzmaProps)->lp)))
-
-#define kLzmaInBufferSize 64 /* don't change it. it must be larger than kRequiredInBufferSize */
-
-#define kLzmaNeedInitId (-2)
-
-typedef struct _CLzmaDecoderState
-{
- CLzmaProperties Properties;
- CProb *Probs;
- unsigned char *Dictionary;
-
- unsigned char Buffer[kLzmaInBufferSize];
- int BufferSize;
-
- UInt32 Range;
- UInt32 Code;
- UInt32 DictionaryPos;
- UInt32 GlobalPos;
- UInt32 DistanceLimit;
- UInt32 Reps[4];
- int State;
- int RemainLen; /* -2: decoder needs internal initialization
- -1: stream was finished,
- 0: ok
- > 0: need to write RemainLen bytes as match Reps[0],
- */
- unsigned char TempDictionary[4]; /* it's required when DictionarySize = 0 */
-} CLzmaDecoderState;
-
-#define LzmaDecoderInit(vs) { (vs)->RemainLen = kLzmaNeedInitId; (vs)->BufferSize = 0; }
-
-/* LzmaDecode: decoding from input stream to output stream.
- If finishDecoding != 0, then there are no more bytes in input stream
- after inStream[inSize - 1]. */
-
-int LzmaDecode(CLzmaDecoderState *vs,
- const unsigned char *inStream, SizeT inSize, SizeT *inSizeProcessed,
- unsigned char *outStream, SizeT outSize, SizeT *outSizeProcessed,
- int finishDecoding);
-
-#endif
diff --git a/C/Compress/Lzma/LzmaStateTest.c b/C/Compress/Lzma/LzmaStateTest.c
deleted file mode 100755
index 5df4e438..00000000
--- a/C/Compress/Lzma/LzmaStateTest.c
+++ /dev/null
@@ -1,195 +0,0 @@
-/*
-LzmaStateTest.c
-Test application for LZMA Decoder (State version)
-
-This file written and distributed to public domain by Igor Pavlov.
-This file is part of LZMA SDK 4.26 (2005-08-02)
-*/
-
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-
-#include "LzmaStateDecode.h"
-
-const char *kCantReadMessage = "Can not read input file";
-const char *kCantWriteMessage = "Can not write output file";
-const char *kCantAllocateMessage = "Can not allocate memory";
-
-#define kInBufferSize (1 << 15)
-#define kOutBufferSize (1 << 15)
-
-unsigned char g_InBuffer[kInBufferSize];
-unsigned char g_OutBuffer[kOutBufferSize];
-
-size_t MyReadFile(FILE *file, void *data, size_t size)
- { return fread(data, 1, size, file); }
-
-int MyReadFileAndCheck(FILE *file, void *data, size_t size)
- { return (MyReadFile(file, data, size) == size); }
-
-int PrintError(char *buffer, const char *message)
-{
- sprintf(buffer + strlen(buffer), "\nError: ");
- sprintf(buffer + strlen(buffer), message);
- return 1;
-}
-
-int main3(FILE *inFile, FILE *outFile, char *rs)
-{
- /* We use two 32-bit integers to construct 64-bit integer for file size.
- You can remove outSizeHigh, if you don't need >= 4GB supporting,
- or you can use UInt64 outSize, if your compiler supports 64-bit integers*/
- UInt32 outSize = 0;
- UInt32 outSizeHigh = 0;
-
- int waitEOS = 1;
- /* waitEOS = 1, if there is no uncompressed size in headers,
- so decoder will wait EOS (End of Stream Marker) in compressed stream */
-
- int i;
- int res = 0;
- CLzmaDecoderState state; /* it's about 140 bytes structure, if int is 32-bit */
- unsigned char properties[LZMA_PROPERTIES_SIZE];
- SizeT inAvail = 0;
- unsigned char *inBuffer = 0;
-
- if (sizeof(UInt32) < 4)
- return PrintError(rs, "LZMA decoder needs correct UInt32");
-
- /* Read LZMA properties for compressed stream */
-
- if (!MyReadFileAndCheck(inFile, properties, sizeof(properties)))
- return PrintError(rs, kCantReadMessage);
-
- /* Read uncompressed size */
-
- for (i = 0; i < 8; i++)
- {
- unsigned char b;
- if (!MyReadFileAndCheck(inFile, &b, 1))
- return PrintError(rs, kCantReadMessage);
- if (b != 0xFF)
- waitEOS = 0;
- if (i < 4)
- outSize += (UInt32)(b) << (i * 8);
- else
- outSizeHigh += (UInt32)(b) << ((i - 4) * 8);
- }
-
- /* Decode LZMA properties and allocate memory */
-
- if (LzmaDecodeProperties(&state.Properties, properties, LZMA_PROPERTIES_SIZE) != LZMA_RESULT_OK)
- return PrintError(rs, "Incorrect stream properties");
- state.Probs = (CProb *)malloc(LzmaGetNumProbs(&state.Properties) * sizeof(CProb));
- if (state.Probs == 0)
- return PrintError(rs, kCantAllocateMessage);
-
- if (state.Properties.DictionarySize == 0)
- state.Dictionary = 0;
- else
- {
- state.Dictionary = (unsigned char *)malloc(state.Properties.DictionarySize);
- if (state.Dictionary == 0)
- {
- free(state.Probs);
- return PrintError(rs, kCantAllocateMessage);
- }
- }
-
- /* Decompress */
-
- LzmaDecoderInit(&state);
-
- do
- {
- SizeT inProcessed, outProcessed;
- int finishDecoding;
- UInt32 outAvail = kOutBufferSize;
- if (!waitEOS && outSizeHigh == 0 && outAvail > outSize)
- outAvail = outSize;
- if (inAvail == 0)
- {
- inAvail = (SizeT)MyReadFile(inFile, g_InBuffer, kInBufferSize);
- inBuffer = g_InBuffer;
- }
- finishDecoding = (inAvail == 0);
- res = LzmaDecode(&state,
- inBuffer, inAvail, &inProcessed,
- g_OutBuffer, outAvail, &outProcessed,
- finishDecoding);
- if (res != 0)
- {
- sprintf(rs + strlen(rs), "\nDecoding error = %d\n", res);
- res = 1;
- break;
- }
- inAvail -= inProcessed;
- inBuffer += inProcessed;
-
- if (outFile != 0)
- if (fwrite(g_OutBuffer, 1, outProcessed, outFile) != outProcessed)
- {
- PrintError(rs, kCantWriteMessage);
- res = 1;
- break;
- }
-
- if (outSize < outProcessed)
- outSizeHigh--;
- outSize -= (UInt32)outProcessed;
- outSize &= 0xFFFFFFFF;
-
- if (outProcessed == 0 && finishDecoding)
- {
- if (!waitEOS && (outSize != 0 || outSizeHigh != 0))
- res = 1;
- break;
- }
- }
- while ((outSize != 0 && outSizeHigh == 0) || outSizeHigh != 0 || waitEOS);
-
- free(state.Dictionary);
- free(state.Probs);
- return res;
-}
-
-int main2(int numArgs, const char *args[], char *rs)
-{
- FILE *inFile = 0;
- FILE *outFile = 0;
- int res;
-
- sprintf(rs + strlen(rs), "\nLZMA Decoder 4.26 Copyright (c) 1999-2005 Igor Pavlov 2005-08-02\n");
- if (numArgs < 2 || numArgs > 3)
- {
- sprintf(rs + strlen(rs), "\nUsage: lzmadec file.lzma [outFile]\n");
- return 1;
- }
-
- inFile = fopen(args[1], "rb");
- if (inFile == 0)
- return PrintError(rs, "Can not open input file");
-
- if (numArgs > 2)
- {
- outFile = fopen(args[2], "wb+");
- if (outFile == 0)
- return PrintError(rs, "Can not open output file");
- }
-
- res = main3(inFile, outFile, rs);
-
- if (outFile != 0)
- fclose(outFile);
- fclose(inFile);
- return res;
-}
-
-int main(int numArgs, const char *args[])
-{
- char rs[800] = { 0 };
- int res = main2(numArgs, args, rs);
- printf(rs);
- return res;
-}
diff --git a/C/Compress/Lzma/LzmaTest.c b/C/Compress/Lzma/LzmaTest.c
deleted file mode 100755
index f95a753b..00000000
--- a/C/Compress/Lzma/LzmaTest.c
+++ /dev/null
@@ -1,342 +0,0 @@
-/*
-LzmaTest.c
-Test application for LZMA Decoder
-
-This file written and distributed to public domain by Igor Pavlov.
-This file is part of LZMA SDK 4.26 (2005-08-05)
-*/
-
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-
-#include "LzmaDecode.h"
-
-const char *kCantReadMessage = "Can not read input file";
-const char *kCantWriteMessage = "Can not write output file";
-const char *kCantAllocateMessage = "Can not allocate memory";
-
-size_t MyReadFile(FILE *file, void *data, size_t size)
-{
- if (size == 0)
- return 0;
- return fread(data, 1, size, file);
-}
-
-int MyReadFileAndCheck(FILE *file, void *data, size_t size)
- { return (MyReadFile(file, data, size) == size);}
-
-size_t MyWriteFile(FILE *file, const void *data, size_t size)
-{
- if (size == 0)
- return 0;
- return fwrite(data, 1, size, file);
-}
-
-int MyWriteFileAndCheck(FILE *file, const void *data, size_t size)
- { return (MyWriteFile(file, data, size) == size); }
-
-#ifdef _LZMA_IN_CB
-#define kInBufferSize (1 << 15)
-typedef struct _CBuffer
-{
- ILzmaInCallback InCallback;
- FILE *File;
- unsigned char Buffer[kInBufferSize];
-} CBuffer;
-
-int LzmaReadCompressed(void *object, const unsigned char **buffer, SizeT *size)
-{
- CBuffer *b = (CBuffer *)object;
- *buffer = b->Buffer;
- *size = (SizeT)MyReadFile(b->File, b->Buffer, kInBufferSize);
- return LZMA_RESULT_OK;
-}
-CBuffer g_InBuffer;
-
-#endif
-
-#ifdef _LZMA_OUT_READ
-#define kOutBufferSize (1 << 15)
-unsigned char g_OutBuffer[kOutBufferSize];
-#endif
-
-int PrintError(char *buffer, const char *message)
-{
- sprintf(buffer + strlen(buffer), "\nError: ");
- sprintf(buffer + strlen(buffer), message);
- return 1;
-}
-
-int main3(FILE *inFile, FILE *outFile, char *rs)
-{
- /* We use two 32-bit integers to construct 64-bit integer for file size.
- You can remove outSizeHigh, if you don't need >= 4GB supporting,
- or you can use UInt64 outSize, if your compiler supports 64-bit integers*/
- UInt32 outSize = 0;
- UInt32 outSizeHigh = 0;
- #ifndef _LZMA_OUT_READ
- SizeT outSizeFull;
- unsigned char *outStream;
- #endif
-
- int waitEOS = 1;
- /* waitEOS = 1, if there is no uncompressed size in headers,
- so decoder will wait EOS (End of Stream Marker) in compressed stream */
-
- #ifndef _LZMA_IN_CB
- SizeT compressedSize;
- unsigned char *inStream;
- #endif
-
- CLzmaDecoderState state; /* it's about 24-80 bytes structure, if int is 32-bit */
- unsigned char properties[LZMA_PROPERTIES_SIZE];
-
- int res;
-
- #ifdef _LZMA_IN_CB
- g_InBuffer.File = inFile;
- #endif
-
- if (sizeof(UInt32) < 4)
- return PrintError(rs, "LZMA decoder needs correct UInt32");
-
- #ifndef _LZMA_IN_CB
- {
- long length;
- fseek(inFile, 0, SEEK_END);
- length = ftell(inFile);
- fseek(inFile, 0, SEEK_SET);
- if ((long)(SizeT)length != length)
- return PrintError(rs, "Too big compressed stream");
- compressedSize = (SizeT)(length - (LZMA_PROPERTIES_SIZE + 8));
- }
- #endif
-
- /* Read LZMA properties for compressed stream */
-
- if (!MyReadFileAndCheck(inFile, properties, sizeof(properties)))
- return PrintError(rs, kCantReadMessage);
-
- /* Read uncompressed size */
-
- {
- int i;
- for (i = 0; i < 8; i++)
- {
- unsigned char b;
- if (!MyReadFileAndCheck(inFile, &b, 1))
- return PrintError(rs, kCantReadMessage);
- if (b != 0xFF)
- waitEOS = 0;
- if (i < 4)
- outSize += (UInt32)(b) << (i * 8);
- else
- outSizeHigh += (UInt32)(b) << ((i - 4) * 8);
- }
-
- #ifndef _LZMA_OUT_READ
- if (waitEOS)
- return PrintError(rs, "Stream with EOS marker is not supported");
- outSizeFull = (SizeT)outSize;
- if (sizeof(SizeT) >= 8)
- outSizeFull |= (((SizeT)outSizeHigh << 16) << 16);
- else if (outSizeHigh != 0 || (UInt32)(SizeT)outSize != outSize)
- return PrintError(rs, "Too big uncompressed stream");
- #endif
- }
-
- /* Decode LZMA properties and allocate memory */
-
- if (LzmaDecodeProperties(&state.Properties, properties, LZMA_PROPERTIES_SIZE) != LZMA_RESULT_OK)
- return PrintError(rs, "Incorrect stream properties");
- state.Probs = (CProb *)malloc(LzmaGetNumProbs(&state.Properties) * sizeof(CProb));
-
- #ifdef _LZMA_OUT_READ
- if (state.Properties.DictionarySize == 0)
- state.Dictionary = 0;
- else
- state.Dictionary = (unsigned char *)malloc(state.Properties.DictionarySize);
- #else
- if (outSizeFull == 0)
- outStream = 0;
- else
- outStream = (unsigned char *)malloc(outSizeFull);
- #endif
-
- #ifndef _LZMA_IN_CB
- if (compressedSize == 0)
- inStream = 0;
- else
- inStream = (unsigned char *)malloc(compressedSize);
- #endif
-
- if (state.Probs == 0
- #ifdef _LZMA_OUT_READ
- || (state.Dictionary == 0 && state.Properties.DictionarySize != 0)
- #else
- || (outStream == 0 && outSizeFull != 0)
- #endif
- #ifndef _LZMA_IN_CB
- || (inStream == 0 && compressedSize != 0)
- #endif
- )
- {
- free(state.Probs);
- #ifdef _LZMA_OUT_READ
- free(state.Dictionary);
- #else
- free(outStream);
- #endif
- #ifndef _LZMA_IN_CB
- free(inStream);
- #endif
- return PrintError(rs, kCantAllocateMessage);
- }
-
- /* Decompress */
-
- #ifdef _LZMA_IN_CB
- g_InBuffer.InCallback.Read = LzmaReadCompressed;
- #else
- if (!MyReadFileAndCheck(inFile, inStream, compressedSize))
- return PrintError(rs, kCantReadMessage);
- #endif
-
- #ifdef _LZMA_OUT_READ
- {
- #ifndef _LZMA_IN_CB
- SizeT inAvail = compressedSize;
- const unsigned char *inBuffer = inStream;
- #endif
- LzmaDecoderInit(&state);
- do
- {
- #ifndef _LZMA_IN_CB
- SizeT inProcessed;
- #endif
- SizeT outProcessed;
- SizeT outAvail = kOutBufferSize;
- if (!waitEOS && outSizeHigh == 0 && outAvail > outSize)
- outAvail = (SizeT)outSize;
- res = LzmaDecode(&state,
- #ifdef _LZMA_IN_CB
- &g_InBuffer.InCallback,
- #else
- inBuffer, inAvail, &inProcessed,
- #endif
- g_OutBuffer, outAvail, &outProcessed);
- if (res != 0)
- {
- sprintf(rs + strlen(rs), "\nDecoding error = %d\n", res);
- res = 1;
- break;
- }
- #ifndef _LZMA_IN_CB
- inAvail -= inProcessed;
- inBuffer += inProcessed;
- #endif
-
- if (outFile != 0)
- if (!MyWriteFileAndCheck(outFile, g_OutBuffer, (size_t)outProcessed))
- {
- PrintError(rs, kCantWriteMessage);
- res = 1;
- break;
- }
-
- if (outSize < outProcessed)
- outSizeHigh--;
- outSize -= (UInt32)outProcessed;
- outSize &= 0xFFFFFFFF;
-
- if (outProcessed == 0)
- {
- if (!waitEOS && (outSize != 0 || outSizeHigh != 0))
- res = 1;
- break;
- }
- }
- while ((outSize != 0 && outSizeHigh == 0) || outSizeHigh != 0 || waitEOS);
- }
-
- #else
- {
- #ifndef _LZMA_IN_CB
- SizeT inProcessed;
- #endif
- SizeT outProcessed;
- res = LzmaDecode(&state,
- #ifdef _LZMA_IN_CB
- &g_InBuffer.InCallback,
- #else
- inStream, compressedSize, &inProcessed,
- #endif
- outStream, outSizeFull, &outProcessed);
- if (res != 0)
- {
- sprintf(rs + strlen(rs), "\nDecoding error = %d\n", res);
- res = 1;
- }
- else if (outFile != 0)
- {
- if (!MyWriteFileAndCheck(outFile, outStream, (size_t)outProcessed))
- {
- PrintError(rs, kCantWriteMessage);
- res = 1;
- }
- }
- }
- #endif
-
- free(state.Probs);
- #ifdef _LZMA_OUT_READ
- free(state.Dictionary);
- #else
- free(outStream);
- #endif
- #ifndef _LZMA_IN_CB
- free(inStream);
- #endif
- return res;
-}
-
-int main2(int numArgs, const char *args[], char *rs)
-{
- FILE *inFile = 0;
- FILE *outFile = 0;
- int res;
-
- sprintf(rs + strlen(rs), "\nLZMA Decoder 4.26 Copyright (c) 1999-2005 Igor Pavlov 2005-08-05\n");
- if (numArgs < 2 || numArgs > 3)
- {
- sprintf(rs + strlen(rs), "\nUsage: lzmadec file.lzma [outFile]\n");
- return 1;
- }
-
- inFile = fopen(args[1], "rb");
- if (inFile == 0)
- return PrintError(rs, "Can not open input file");
-
- if (numArgs > 2)
- {
- outFile = fopen(args[2], "wb+");
- if (outFile == 0)
- return PrintError(rs, "Can not open output file");
- }
-
- res = main3(inFile, outFile, rs);
-
- if (outFile != 0)
- fclose(outFile);
- fclose(inFile);
- return res;
-}
-
-int main(int numArgs, const char *args[])
-{
- char rs[800] = { 0 };
- int res = main2(numArgs, args, rs);
- printf(rs);
- return res;
-}
diff --git a/C/Compress/Lzma/LzmaTypes.h b/C/Compress/Lzma/LzmaTypes.h
deleted file mode 100755
index 9c272907..00000000
--- a/C/Compress/Lzma/LzmaTypes.h
+++ /dev/null
@@ -1,45 +0,0 @@
-/*
-LzmaTypes.h
-
-Types for LZMA Decoder
-
-This file written and distributed to public domain by Igor Pavlov.
-This file is part of LZMA SDK 4.40 (2006-05-01)
-*/
-
-#ifndef __LZMATYPES_H
-#define __LZMATYPES_H
-
-#ifndef _7ZIP_BYTE_DEFINED
-#define _7ZIP_BYTE_DEFINED
-typedef unsigned char Byte;
-#endif
-
-#ifndef _7ZIP_UINT16_DEFINED
-#define _7ZIP_UINT16_DEFINED
-typedef unsigned short UInt16;
-#endif
-
-#ifndef _7ZIP_UINT32_DEFINED
-#define _7ZIP_UINT32_DEFINED
-#ifdef _LZMA_UINT32_IS_ULONG
-typedef unsigned long UInt32;
-#else
-typedef unsigned int UInt32;
-#endif
-#endif
-
-/* #define _LZMA_NO_SYSTEM_SIZE_T */
-/* You can use it, if you don't want <stddef.h> */
-
-#ifndef _7ZIP_SIZET_DEFINED
-#define _7ZIP_SIZET_DEFINED
-#ifdef _LZMA_NO_SYSTEM_SIZE_T
-typedef UInt32 SizeT;
-#else
-#include <stddef.h>
-typedef size_t SizeT;
-#endif
-#endif
-
-#endif
diff --git a/C/CpuArch.h b/C/CpuArch.h
index 26ce8b1d..2ec7081f 100755
--- a/C/CpuArch.h
+++ b/C/CpuArch.h
@@ -1,4 +1,7 @@
-/* CpuArch.h */
+/* CpuArch.h
+2008-03-26
+Igor Pavlov
+Public domain */
#ifndef __CPUARCH_H
#define __CPUARCH_H
@@ -15,4 +18,31 @@ about these properties of platform.
#define LITTLE_ENDIAN_UNALIGN
#endif
+#ifdef LITTLE_ENDIAN_UNALIGN
+
+#define GetUi16(p) (*(const UInt16 *)(p))
+#define GetUi32(p) (*(const UInt32 *)(p))
+#define GetUi64(p) (*(const UInt64 *)(p))
+#define SetUi32(p, d) *(UInt32 *)(p) = d;
+
+#else
+
+#define GetUi16(p) (((const Byte *)(p))[0] | \
+ ((UInt16)((const Byte *)(p))[1] << 8))
+
+#define GetUi32(p) (((const Byte *)(p))[0] | \
+ ((UInt32)((const Byte *)(p))[1] << 8 ) | \
+ ((UInt32)((const Byte *)(p))[2] << 16) | \
+ ((UInt32)((const Byte *)(p))[3] << 24))
+
+#define GetUi64(p) (GetUi32(p) | (UInt64)GetUi32(((const Byte *)(p)) + 4) << 32)
+
+#define SetUi32(p, d) { UInt32 _x_ = (d); \
+ ((Byte *)(p))[0] = (Byte)_x_; \
+ ((Byte *)(p))[1] = (Byte)(_x_ >> 8); \
+ ((Byte *)(p))[2] = (Byte)(_x_ >> 16); \
+ ((Byte *)(p))[3] = (Byte)(_x_ >> 24); }
+
+#endif
+
#endif
diff --git a/C/Crypto/Aes.h b/C/Crypto/Aes.h
deleted file mode 100755
index ab51a72c..00000000
--- a/C/Crypto/Aes.h
+++ /dev/null
@@ -1,40 +0,0 @@
-/* Aes.h */
-
-#ifndef __AES_H
-#define __AES_H
-
-#include "../Types.h"
-
-#define AES_BLOCK_SIZE 16
-
-typedef struct _CAes
-{
- unsigned numRounds2; /* = numRounds / 2 */
- UInt32 rkey[(14 + 1) * 4];
-} CAes;
-
-/* Call AesGenTables one time before other AES functions */
-void MY_FAST_CALL AesGenTables(void);
-
-/* keySize = 16 or 24 or 32 */
-void MY_FAST_CALL AesSetKeyEncode(CAes *p, const Byte *key, unsigned keySize);
-void MY_FAST_CALL AesSetKeyDecode(CAes *p, const Byte *key, unsigned keySize);
-
-/*
-AesEncode32 and AesDecode32 functions work with little-endian words.
-src and dest can contain same address
-*/
-void MY_FAST_CALL AesEncode32(const UInt32 *src, UInt32 *dest, const UInt32 *w, unsigned numRounds2);
-void MY_FAST_CALL AesDecode32(const UInt32 *src, UInt32 *dest, const UInt32 *w, unsigned numRounds2);
-
-typedef struct _CAesCbc
-{
- UInt32 prev[4];
- CAes aes;
-} CAesCbc;
-
-void MY_FAST_CALL AesCbcInit(CAesCbc *cbc, const Byte *iv); /* iv size is AES_BLOCK_SIZE */
-UInt32 MY_FAST_CALL AesCbcDecode(CAesCbc *cbc, Byte *data, UInt32 size);
-UInt32 MY_FAST_CALL AesCbcEncode(CAesCbc *cbc, Byte *data, UInt32 size);
-
-#endif
diff --git a/C/Compress/Huffman/HuffmanEncode.c b/C/HuffEnc.c
index f27607e6..65f5d27a 100755
--- a/C/Compress/Huffman/HuffmanEncode.c
+++ b/C/HuffEnc.c
@@ -1,7 +1,10 @@
-/* Compress/HuffmanEncode.c */
+/* HuffEnc.c -- functions for Huffman encoding
+2008-03-26
+Igor Pavlov
+Public domain */
-#include "HuffmanEncode.h"
-#include "../../Sort.h"
+#include "HuffEnc.h"
+#include "Sort.h"
#define kMaxLen 16
#define NUM_BITS 10
@@ -9,7 +12,6 @@
#define NUM_COUNTERS 64
-/* use BLOCK_SORT_EXTERNAL_FLAGS if blockSize > 1M */
#define HUFFMAN_SPEED_OPT
void Huffman_Generate(const UInt32 *freqs, UInt32 *p, Byte *lens, UInt32 numSymbols, UInt32 maxLen)
@@ -69,7 +71,7 @@ void Huffman_Generate(const UInt32 *freqs, UInt32 *p, Byte *lens, UInt32 numSymb
int maxCode = 1;
if (num == 1)
{
- maxCode = p[0] & MASK;
+ maxCode = (int)(p[0] & MASK);
if (maxCode == 0)
maxCode++;
}
diff --git a/C/Compress/Huffman/HuffmanEncode.h b/C/HuffEnc.h
index c8acc283..00dd9aca 100755
--- a/C/Compress/Huffman/HuffmanEncode.h
+++ b/C/HuffEnc.h
@@ -1,9 +1,12 @@
-/* Compress/HuffmanEncode.h */
+/* HuffEnc.h -- functions for Huffman encoding
+2008-03-26
+Igor Pavlov
+Public domain */
-#ifndef __COMPRESS_HUFFMANENCODE_H
-#define __COMPRESS_HUFFMANENCODE_H
+#ifndef __HUFFENC_H
+#define __HUFFENC_H
-#include "../../Types.h"
+#include "Types.h"
/*
Conditions:
diff --git a/C/IStream.h b/C/IStream.h
deleted file mode 100755
index 58218487..00000000
--- a/C/IStream.h
+++ /dev/null
@@ -1,19 +0,0 @@
-/* IStream.h */
-
-#ifndef __C_ISTREAM_H
-#define __C_ISTREAM_H
-
-#include "Types.h"
-
-typedef struct _ISeqInStream
-{
- HRes (*Read)(void *object, void *data, UInt32 size, UInt32 *processedSize);
-} ISeqInStream;
-
-typedef struct _ISzAlloc
-{
- void *(*Alloc)(size_t size);
- void (*Free)(void *address); /* address can be 0 */
-} ISzAlloc;
-
-#endif
diff --git a/C/Compress/Lz/MatchFinder.c b/C/LzFind.c
index 0f530fc1..831f0e47 100755
--- a/C/Compress/Lz/MatchFinder.c
+++ b/C/LzFind.c
@@ -1,13 +1,13 @@
-/* MatchFinder.c */
-/* Please call InitCrcTable before */
+/* LzFind.c -- Match finder for LZ algorithms
+2008-04-04
+Copyright (c) 1999-2008 Igor Pavlov
+Read LzFind.h for license options */
#include <string.h>
-#include "MatchFinder.h"
+#include "LzFind.h"
#include "LzHash.h"
-#include "../../7zCrc.h"
-
#define kEmptyHashValue 0
#define kMaxValForNormalize ((UInt32)0xFFFFFFFF)
#define kNormalizeStepMin (1 << 10) /* it must be power of 2 */
@@ -16,18 +16,18 @@
#define kStartMaxLen 3
-void LzInWindow_Free(CMatchFinder *p, ISzAlloc *alloc)
+static void LzInWindow_Free(CMatchFinder *p, ISzAlloc *alloc)
{
if (!p->directInput)
{
- alloc->Free(p->bufferBase);
+ alloc->Free(alloc, p->bufferBase);
p->bufferBase = 0;
}
}
/* keepSizeBefore + keepSizeAfter + keepSizeReserv must be < 4G) */
-int LzInWindow_Create(CMatchFinder *p, UInt32 keepSizeReserv, ISzAlloc *alloc)
+static int LzInWindow_Create(CMatchFinder *p, UInt32 keepSizeReserv, ISzAlloc *alloc)
{
UInt32 blockSize = p->keepSizeBefore + p->keepSizeAfter + keepSizeReserv;
if (p->directInput)
@@ -39,7 +39,7 @@ int LzInWindow_Create(CMatchFinder *p, UInt32 keepSizeReserv, ISzAlloc *alloc)
{
LzInWindow_Free(p, alloc);
p->blockSize = blockSize;
- p->bufferBase = (Byte *)alloc->Alloc(blockSize);
+ p->bufferBase = (Byte *)alloc->Alloc(alloc, (size_t)blockSize);
}
return (p->bufferBase != 0);
}
@@ -56,26 +56,25 @@ void MatchFinder_ReduceOffsets(CMatchFinder *p, UInt32 subValue)
p->streamPos -= subValue;
}
-void MatchFinder_ReadBlock(CMatchFinder *p)
+static void MatchFinder_ReadBlock(CMatchFinder *p)
{
if (p->streamEndWasReached || p->result != SZ_OK)
return;
for (;;)
{
Byte *dest = p->buffer + (p->streamPos - p->pos);
- UInt32 numReadBytes;
- UInt32 size = (UInt32)(p->bufferBase + p->blockSize - dest);
+ size_t size = (p->bufferBase + p->blockSize - dest);
if (size == 0)
return;
- p->result = p->stream->Read(p->stream, dest, size, &numReadBytes);
+ p->result = p->stream->Read(p->stream, dest, &size);
if (p->result != SZ_OK)
return;
- if (numReadBytes == 0)
+ if (size == 0)
{
p->streamEndWasReached = 1;
return;
}
- p->streamPos += numReadBytes;
+ p->streamPos += (UInt32)size;
if (p->streamPos - p->pos > p->keepSizeAfter)
return;
}
@@ -85,7 +84,7 @@ void MatchFinder_MoveBlock(CMatchFinder *p)
{
memmove(p->bufferBase,
p->buffer - p->keepSizeBefore,
- p->streamPos - p->pos + p->keepSizeBefore);
+ (size_t)(p->streamPos - p->pos + p->keepSizeBefore));
p->buffer = p->bufferBase + p->keepSizeBefore;
}
@@ -103,14 +102,14 @@ void MatchFinder_ReadIfRequired(CMatchFinder *p)
MatchFinder_ReadBlock(p);
}
-void MatchFinder_CheckAndMoveAndRead(CMatchFinder *p)
+static void MatchFinder_CheckAndMoveAndRead(CMatchFinder *p)
{
if (MatchFinder_NeedMove(p))
MatchFinder_MoveBlock(p);
MatchFinder_ReadBlock(p);
}
-void MatchFinder_SetDefaultSettings(CMatchFinder *p)
+static void MatchFinder_SetDefaultSettings(CMatchFinder *p)
{
p->cutValue = 32;
p->btMode = 1;
@@ -120,17 +119,29 @@ void MatchFinder_SetDefaultSettings(CMatchFinder *p)
p->bigHash = 0;
}
+#define kCrcPoly 0xEDB88320
+
void MatchFinder_Construct(CMatchFinder *p)
{
+ UInt32 i;
p->bufferBase = 0;
p->directInput = 0;
p->hash = 0;
MatchFinder_SetDefaultSettings(p);
+
+ for (i = 0; i < 256; i++)
+ {
+ UInt32 r = i;
+ int j;
+ for (j = 0; j < 8; j++)
+ r = (r >> 1) ^ (kCrcPoly & ~((r & 1) - 1));
+ p->crc[i] = r;
+ }
}
-void MatchFinder_FreeThisClassMemory(CMatchFinder *p, ISzAlloc *alloc)
+static void MatchFinder_FreeThisClassMemory(CMatchFinder *p, ISzAlloc *alloc)
{
- alloc->Free(p->hash);
+ alloc->Free(alloc, p->hash);
p->hash = 0;
}
@@ -140,12 +151,12 @@ void MatchFinder_Free(CMatchFinder *p, ISzAlloc *alloc)
LzInWindow_Free(p, alloc);
}
-CLzRef* AllocRefs(UInt32 num, ISzAlloc *alloc)
+static CLzRef* AllocRefs(UInt32 num, ISzAlloc *alloc)
{
size_t sizeInBytes = (size_t)num * sizeof(CLzRef);
if (sizeInBytes / sizeof(CLzRef) != num)
return 0;
- return (CLzRef *)alloc->Alloc(sizeInBytes);
+ return (CLzRef *)alloc->Alloc(alloc, sizeInBytes);
}
int MatchFinder_Create(CMatchFinder *p, UInt32 historySize,
@@ -224,7 +235,7 @@ int MatchFinder_Create(CMatchFinder *p, UInt32 historySize,
return 0;
}
-void MatchFinder_SetLimits(CMatchFinder *p)
+static void MatchFinder_SetLimits(CMatchFinder *p)
{
UInt32 limit = kMaxValForNormalize - p->pos;
UInt32 limit2 = p->cyclicBufferSize - p->cyclicBufferPos;
@@ -263,7 +274,7 @@ void MatchFinder_Init(CMatchFinder *p)
MatchFinder_SetLimits(p);
}
-UInt32 MatchFinder_GetSubValue(CMatchFinder *p)
+static UInt32 MatchFinder_GetSubValue(CMatchFinder *p)
{
return (p->pos - p->historySize - 1) & kNormalizeMask;
}
@@ -282,14 +293,14 @@ void MatchFinder_Normalize3(UInt32 subValue, CLzRef *items, UInt32 numItems)
}
}
-void MatchFinder_Normalize(CMatchFinder *p)
+static void MatchFinder_Normalize(CMatchFinder *p)
{
UInt32 subValue = MatchFinder_GetSubValue(p);
MatchFinder_Normalize3(subValue, p->hash, p->hashSizeSum + p->numSons);
MatchFinder_ReduceOffsets(p, subValue);
}
-void MatchFinder_CheckLimits(CMatchFinder *p)
+static void MatchFinder_CheckLimits(CMatchFinder *p)
{
if (p->pos == kMaxValForNormalize)
MatchFinder_Normalize(p);
@@ -300,7 +311,7 @@ void MatchFinder_CheckLimits(CMatchFinder *p)
MatchFinder_SetLimits(p);
}
-UInt32 * Hc_GetMatchesSpec(UInt32 lenLimit, UInt32 curMatch, UInt32 pos, const Byte *cur, CLzRef *son,
+static UInt32 * Hc_GetMatchesSpec(UInt32 lenLimit, UInt32 curMatch, UInt32 pos, const Byte *cur, CLzRef *son,
UInt32 _cyclicBufferPos, UInt32 _cyclicBufferSize, UInt32 cutValue,
UInt32 *distances, UInt32 maxLen)
{
@@ -386,7 +397,7 @@ UInt32 * GetMatchesSpec1(UInt32 lenLimit, UInt32 curMatch, UInt32 pos, const Byt
}
}
-void SkipMatchesSpec(UInt32 lenLimit, UInt32 curMatch, UInt32 pos, const Byte *cur, CLzRef *son,
+static void SkipMatchesSpec(UInt32 lenLimit, UInt32 curMatch, UInt32 pos, const Byte *cur, CLzRef *son,
UInt32 _cyclicBufferPos, UInt32 _cyclicBufferSize, UInt32 cutValue)
{
CLzRef *ptr0 = son + (_cyclicBufferPos << 1) + 1;
@@ -443,7 +454,7 @@ void SkipMatchesSpec(UInt32 lenLimit, UInt32 curMatch, UInt32 pos, const Byte *c
#define MOVE_POS_RET MOVE_POS return offset;
-void MatchFinder_MovePos(CMatchFinder *p) { MOVE_POS; }
+static void MatchFinder_MovePos(CMatchFinder *p) { MOVE_POS; }
#define GET_MATCHES_HEADER2(minLen, ret_op) \
UInt32 lenLimit; UInt32 hashValue; const Byte *cur; UInt32 curMatch; \
@@ -462,7 +473,7 @@ void MatchFinder_MovePos(CMatchFinder *p) { MOVE_POS; }
#define SKIP_FOOTER \
SkipMatchesSpec(lenLimit, curMatch, MF_PARAMS(p)); MOVE_POS;
-UInt32 Bt2_MatchFinder_GetMatches(CMatchFinder *p, UInt32 *distances)
+static UInt32 Bt2_MatchFinder_GetMatches(CMatchFinder *p, UInt32 *distances)
{
UInt32 offset;
GET_MATCHES_HEADER(2)
@@ -484,7 +495,7 @@ UInt32 Bt3Zip_MatchFinder_GetMatches(CMatchFinder *p, UInt32 *distances)
GET_MATCHES_FOOTER(offset, 2)
}
-UInt32 Bt3_MatchFinder_GetMatches(CMatchFinder *p, UInt32 *distances)
+static UInt32 Bt3_MatchFinder_GetMatches(CMatchFinder *p, UInt32 *distances)
{
UInt32 hash2Value, delta2, maxLen, offset;
GET_MATCHES_HEADER(3)
@@ -517,7 +528,7 @@ UInt32 Bt3_MatchFinder_GetMatches(CMatchFinder *p, UInt32 *distances)
GET_MATCHES_FOOTER(offset, maxLen)
}
-UInt32 Bt4_MatchFinder_GetMatches(CMatchFinder *p, UInt32 *distances)
+static UInt32 Bt4_MatchFinder_GetMatches(CMatchFinder *p, UInt32 *distances)
{
UInt32 hash2Value, hash3Value, delta2, delta3, maxLen, offset;
GET_MATCHES_HEADER(4)
@@ -564,7 +575,7 @@ UInt32 Bt4_MatchFinder_GetMatches(CMatchFinder *p, UInt32 *distances)
GET_MATCHES_FOOTER(offset, maxLen)
}
-UInt32 Hc4_MatchFinder_GetMatches(CMatchFinder *p, UInt32 *distances)
+static UInt32 Hc4_MatchFinder_GetMatches(CMatchFinder *p, UInt32 *distances)
{
UInt32 hash2Value, hash3Value, delta2, delta3, maxLen, offset;
GET_MATCHES_HEADER(4)
@@ -625,7 +636,7 @@ UInt32 Hc3Zip_MatchFinder_GetMatches(CMatchFinder *p, UInt32 *distances)
MOVE_POS_RET
}
-void Bt2_MatchFinder_Skip(CMatchFinder *p, UInt32 num)
+static void Bt2_MatchFinder_Skip(CMatchFinder *p, UInt32 num)
{
do
{
@@ -651,7 +662,7 @@ void Bt3Zip_MatchFinder_Skip(CMatchFinder *p, UInt32 num)
while (--num != 0);
}
-void Bt3_MatchFinder_Skip(CMatchFinder *p, UInt32 num)
+static void Bt3_MatchFinder_Skip(CMatchFinder *p, UInt32 num)
{
do
{
@@ -666,7 +677,7 @@ void Bt3_MatchFinder_Skip(CMatchFinder *p, UInt32 num)
while (--num != 0);
}
-void Bt4_MatchFinder_Skip(CMatchFinder *p, UInt32 num)
+static void Bt4_MatchFinder_Skip(CMatchFinder *p, UInt32 num)
{
do
{
@@ -682,7 +693,7 @@ void Bt4_MatchFinder_Skip(CMatchFinder *p, UInt32 num)
while (--num != 0);
}
-void Hc4_MatchFinder_Skip(CMatchFinder *p, UInt32 num)
+static void Hc4_MatchFinder_Skip(CMatchFinder *p, UInt32 num)
{
do
{
diff --git a/C/Compress/Lz/MatchFinder.h b/C/LzFind.h
index 74f52a8f..01b9f732 100755
--- a/C/Compress/Lz/MatchFinder.h
+++ b/C/LzFind.h
@@ -1,9 +1,19 @@
-/* MatchFinder.h */
+/* LzFind.h -- Match finder for LZ algorithms
+2008-04-04
+Copyright (c) 1999-2008 Igor Pavlov
+You can use any of the following license options:
+ 1) GNU Lesser General Public License (GNU LGPL)
+ 2) Common Public License (CPL)
+ 3) Common Development and Distribution License (CDDL) Version 1.0
+ 4) Igor Pavlov, as the author of this code, expressly permits you to
+ statically or dynamically link your code (or bind by name) to this file,
+ while you keep this file unmodified.
+*/
-#ifndef __MATCHFINDER_H
-#define __MATCHFINDER_H
+#ifndef __LZFIND_H
+#define __LZFIND_H
-#include "../../IStream.h"
+#include "Types.h"
typedef UInt32 CLzRef;
@@ -41,8 +51,8 @@ typedef struct _CMatchFinder
UInt32 fixedHashSize;
UInt32 hashSizeSum;
UInt32 numSons;
-
- HRes result;
+ SRes result;
+ UInt32 crc[256];
} CMatchFinder;
#define Inline_MatchFinder_GetPointerToCurrentPos(p) ((p)->buffer)
diff --git a/C/Compress/Lz/MatchFinderMt.c b/C/LzFindMt.c
index ea65a6e6..7ed2030a 100755
--- a/C/Compress/Lz/MatchFinderMt.c
+++ b/C/LzFindMt.c
@@ -1,21 +1,11 @@
-/* MatchFinderMt.c */
+/* LzFindMt.c -- multithreaded Match finder for LZ algorithms
+2008-04-11
+Copyright (c) 1999-2008 Igor Pavlov
+Read LzFind.h for license options */
-#ifdef _WIN32
-#define USE_ALLOCA
-#endif
-
-#ifdef USE_ALLOCA
-#ifdef _WIN32
-#include <malloc.h>
-#else
-#include <stdlib.h>
-#endif
-#endif
-
-#include "../../7zCrc.h"
#include "LzHash.h"
-#include "MatchFinderMt.h"
+#include "LzFindMt.h"
void MtSync_Construct(CMtSync *p)
{
@@ -107,52 +97,55 @@ void MtSync_Destruct(CMtSync *p)
p->wasCreated = False;
}
-HRes MtSync_Create2(CMtSync *p, unsigned (StdCall *startAddress)(void *), void *obj, UInt32 numBlocks)
+#define RINOK_THREAD(x) { if((x) != 0) return SZ_ERROR_THREAD; }
+
+static SRes MtSync_Create2(CMtSync *p, unsigned (MY_STD_CALL *startAddress)(void *), void *obj, UInt32 numBlocks)
{
if (p->wasCreated)
return SZ_OK;
- RINOK(CriticalSection_Init(&p->cs));
+ RINOK_THREAD(CriticalSection_Init(&p->cs));
p->csWasInitialized = True;
- RINOK(AutoResetEvent_CreateNotSignaled(&p->canStart));
- RINOK(AutoResetEvent_CreateNotSignaled(&p->wasStarted));
- RINOK(AutoResetEvent_CreateNotSignaled(&p->wasStopped));
+ RINOK_THREAD(AutoResetEvent_CreateNotSignaled(&p->canStart));
+ RINOK_THREAD(AutoResetEvent_CreateNotSignaled(&p->wasStarted));
+ RINOK_THREAD(AutoResetEvent_CreateNotSignaled(&p->wasStopped));
- RINOK(Semaphore_Create(&p->freeSemaphore, numBlocks, numBlocks));
- RINOK(Semaphore_Create(&p->filledSemaphore, 0, numBlocks));
+ RINOK_THREAD(Semaphore_Create(&p->freeSemaphore, numBlocks, numBlocks));
+ RINOK_THREAD(Semaphore_Create(&p->filledSemaphore, 0, numBlocks));
p->needStart = True;
- RINOK(Thread_Create(&p->thread, startAddress, obj));
+ RINOK_THREAD(Thread_Create(&p->thread, startAddress, obj));
p->wasCreated = True;
return SZ_OK;
}
-HRes MtSync_Create(CMtSync *p, unsigned (StdCall *startAddress)(void *), void *obj, UInt32 numBlocks)
+static SRes MtSync_Create(CMtSync *p, unsigned (MY_STD_CALL *startAddress)(void *), void *obj, UInt32 numBlocks)
{
- HRes res = MtSync_Create2(p, startAddress, obj, numBlocks);
+ SRes res = MtSync_Create2(p, startAddress, obj, numBlocks);
if (res != SZ_OK)
MtSync_Destruct(p);
return res;
}
-
void MtSync_Init(CMtSync *p) { p->needStart = True; }
#define kMtMaxValForNormalize 0xFFFFFFFF
-#define DEF_GetHeads(name, v) \
+#define DEF_GetHeads2(name, v, action) \
static void GetHeads ## name(const Byte *p, UInt32 pos, \
-UInt32 *hash, UInt32 hashMask, UInt32 *heads, UInt32 numHeads) { \
-for (; numHeads != 0; numHeads--) { \
+UInt32 *hash, UInt32 hashMask, UInt32 *heads, UInt32 numHeads, const UInt32 *crc) \
+{ action; for (; numHeads != 0; numHeads--) { \
const UInt32 value = (v); p++; *heads++ = pos - hash[value]; hash[value] = pos++; } }
-DEF_GetHeads(2, (p[0] | ((UInt32)p[1] << 8)) & hashMask)
-DEF_GetHeads(3, (g_CrcTable[p[0]] ^ p[1] ^ ((UInt32)p[2] << 8)) & hashMask)
-DEF_GetHeads(4, (g_CrcTable[p[0]] ^ p[1] ^ ((UInt32)p[2] << 8) ^ (g_CrcTable[p[3]] << 5)) & hashMask)
-DEF_GetHeads(4b, (g_CrcTable[p[0]] ^ p[1] ^ ((UInt32)p[2] << 8) ^ ((UInt32)p[3] << 16)) & hashMask)
-DEF_GetHeads(5, (g_CrcTable[p[0]] ^ p[1] ^ ((UInt32)p[2] << 8) ^ (g_CrcTable[p[3]] << 5) ^ (g_CrcTable[p[4]] << 3)) & hashMask)
+#define DEF_GetHeads(name, v) DEF_GetHeads2(name, v, ;)
+
+DEF_GetHeads2(2, (p[0] | ((UInt32)p[1] << 8)), hashMask = hashMask; crc = crc; )
+DEF_GetHeads(3, (crc[p[0]] ^ p[1] ^ ((UInt32)p[2] << 8)) & hashMask)
+DEF_GetHeads(4, (crc[p[0]] ^ p[1] ^ ((UInt32)p[2] << 8) ^ (crc[p[3]] << 5)) & hashMask)
+DEF_GetHeads(4b, (crc[p[0]] ^ p[1] ^ ((UInt32)p[2] << 8) ^ ((UInt32)p[3] << 16)) & hashMask)
+DEF_GetHeads(5, (crc[p[0]] ^ p[1] ^ ((UInt32)p[2] << 8) ^ (crc[p[3]] << 5) ^ (crc[p[4]] << 3)) & hashMask)
void HashThreadFunc(CMatchFinderMt *mt)
{
@@ -211,7 +204,7 @@ void HashThreadFunc(CMatchFinderMt *mt)
num = num - mf->numHashBytes + 1;
if (num > kMtHashBlockSize - 2)
num = kMtHashBlockSize - 2;
- mt->GetHeadsFunc(mf->buffer, mf->pos, mf->hash + mf->fixedHashSize, mf->hashMask, heads + 2, num);
+ mt->GetHeadsFunc(mf->buffer, mf->pos, mf->hash + mf->fixedHashSize, mf->hashMask, heads + 2, num, mf->crc);
heads[0] += num;
}
mf->pos += num;
@@ -238,13 +231,7 @@ void MatchFinderMt_GetNextBlock_Hash(CMatchFinderMt *p)
#ifdef MFMT_GM_INLINE
-#if _MSC_VER >= 1300
-#define NO_INLINE __declspec(noinline) __fastcall
-#else
-#ifdef _MSC_VER
-#define NO_INLINE __fastcall
-#endif
-#endif
+#define NO_INLINE MY_FAST_CALL
Int32 NO_INLINE GetMatchesSpecN(UInt32 lenLimit, UInt32 pos, const Byte *cur, CLzRef *son,
UInt32 _cyclicBufferPos, UInt32 _cyclicBufferSize, UInt32 _cutValue,
@@ -452,7 +439,7 @@ void MatchFinderMt_Construct(CMatchFinderMt *p)
void MatchFinderMt_FreeMem(CMatchFinderMt *p, ISzAlloc *alloc)
{
- alloc->Free(p->hashBuf);
+ alloc->Free(alloc, p->hashBuf);
p->hashBuf = 0;
}
@@ -466,34 +453,35 @@ void MatchFinderMt_Destruct(CMatchFinderMt *p, ISzAlloc *alloc)
#define kHashBufferSize (kMtHashBlockSize * kMtHashNumBlocks)
#define kBtBufferSize (kMtBtBlockSize * kMtBtNumBlocks)
-static unsigned StdCall HashThreadFunc2(void *p) { HashThreadFunc((CMatchFinderMt *)p); return 0; }
-static unsigned StdCall BtThreadFunc2(void *p)
+static unsigned MY_STD_CALL HashThreadFunc2(void *p) { HashThreadFunc((CMatchFinderMt *)p); return 0; }
+static unsigned MY_STD_CALL BtThreadFunc2(void *p)
{
- #ifdef USE_ALLOCA
- alloca(0x180);
- #endif
+ Byte allocaDummy[0x180];
+ int i = 0;
+ for (i = 0; i < 16; i++)
+ allocaDummy[i] = (Byte)i;
BtThreadFunc((CMatchFinderMt *)p);
return 0;
}
-HRes MatchFinderMt_Create(CMatchFinderMt *p, UInt32 historySize, UInt32 keepAddBufferBefore,
+SRes MatchFinderMt_Create(CMatchFinderMt *p, UInt32 historySize, UInt32 keepAddBufferBefore,
UInt32 matchMaxLen, UInt32 keepAddBufferAfter, ISzAlloc *alloc)
{
CMatchFinder *mf = p->MatchFinder;
p->historySize = historySize;
if (kMtBtBlockSize <= matchMaxLen * 4)
- return E_INVALIDARG;
+ return SZ_ERROR_PARAM;
if (p->hashBuf == 0)
{
- p->hashBuf = (UInt32 *)alloc->Alloc((kHashBufferSize + kBtBufferSize) * sizeof(UInt32));
+ p->hashBuf = (UInt32 *)alloc->Alloc(alloc, (kHashBufferSize + kBtBufferSize) * sizeof(UInt32));
if (p->hashBuf == 0)
- return SZE_OUTOFMEMORY;
+ return SZ_ERROR_MEM;
p->btBuf = p->hashBuf + kHashBufferSize;
}
keepAddBufferBefore += (kHashBufferSize + kBtBufferSize);
keepAddBufferAfter += kMtHashBlockSize;
if (!MatchFinder_Create(mf, historySize, keepAddBufferBefore, matchMaxLen, keepAddBufferAfter, alloc))
- return SZE_OUTOFMEMORY;
+ return SZ_ERROR_MEM;
RINOK(MtSync_Create(&p->hashSync, HashThreadFunc2, p, kMtHashNumBlocks));
RINOK(MtSync_Create(&p->btSync, BtThreadFunc2, p, kMtBtNumBlocks));
@@ -513,6 +501,7 @@ void MatchFinderMt_Init(CMatchFinderMt *p)
p->hash = mf->hash;
p->fixedHashSize = mf->fixedHashSize;
+ p->crc = mf->crc;
p->son = mf->son;
p->matchMaxLen = mf->matchMaxLen;
diff --git a/C/Compress/Lz/MatchFinderMt.h b/C/LzFindMt.h
index e718a09e..36343b4f 100755
--- a/C/Compress/Lz/MatchFinderMt.h
+++ b/C/LzFindMt.h
@@ -1,10 +1,13 @@
-/* MatchFinderMt.h */
+/* LzFindMt.h -- multithreaded Match finder for LZ algorithms
+2008-04-04
+Copyright (c) 1999-2008 Igor Pavlov
+Read LzFind.h for license options */
-#ifndef __MATCHFINDERMT_H
-#define __MATCHFINDERMT_H
+#ifndef __LZFINDMT_H
+#define __LZFINDMT_H
-#include "../../Threads.h"
-#include "MatchFinder.h"
+#include "Threads.h"
+#include "LzFind.h"
#define kMtHashBlockSize (1 << 13)
#define kMtHashNumBlocks (1 << 3)
@@ -39,7 +42,7 @@ typedef UInt32 * (*Mf_Mix_Matches)(void *p, UInt32 matchMinPos, UInt32 *distance
#define kMtCacheLineDummy 128
typedef void (*Mf_GetHeads)(const Byte *buffer, UInt32 pos,
- UInt32 *hash, UInt32 hashMask, UInt32 *heads, UInt32 numHeads);
+ UInt32 *hash, UInt32 hashMask, UInt32 *heads, UInt32 numHeads, const UInt32 *crc);
typedef struct _CMatchFinderMt
{
@@ -54,6 +57,7 @@ typedef struct _CMatchFinderMt
UInt32 *hash;
UInt32 fixedHashSize;
UInt32 historySize;
+ const UInt32 *crc;
Mf_Mix_Matches MixMatchesFunc;
@@ -87,7 +91,7 @@ typedef struct _CMatchFinderMt
void MatchFinderMt_Construct(CMatchFinderMt *p);
void MatchFinderMt_Destruct(CMatchFinderMt *p, ISzAlloc *alloc);
-HRes MatchFinderMt_Create(CMatchFinderMt *p, UInt32 historySize, UInt32 keepAddBufferBefore,
+SRes MatchFinderMt_Create(CMatchFinderMt *p, UInt32 historySize, UInt32 keepAddBufferBefore,
UInt32 matchMaxLen, UInt32 keepAddBufferAfter, ISzAlloc *alloc);
void MatchFinderMt_CreateVTable(CMatchFinderMt *p, IMatchFinder *vTable);
void MatchFinderMt_ReleaseStream(CMatchFinderMt *p);
diff --git a/C/Compress/Lz/LzHash.h b/C/LzHash.h
index 87c28365..9a7a2020 100755
--- a/C/Compress/Lz/LzHash.h
+++ b/C/LzHash.h
@@ -1,7 +1,10 @@
-/* LzHash.h */
+/* LzHash.h -- HASH functions for LZ algorithms
+2008-03-26
+Copyright (c) 1999-2008 Igor Pavlov
+Read LzFind.h for license options */
-#ifndef __C_LZHASH_H
-#define __C_LZHASH_H
+#ifndef __LZHASH_H
+#define __LZHASH_H
#define kHash2Size (1 << 10)
#define kHash3Size (1 << 16)
@@ -14,40 +17,40 @@
#define HASH2_CALC hashValue = cur[0] | ((UInt32)cur[1] << 8);
#define HASH3_CALC { \
- UInt32 temp = g_CrcTable[cur[0]] ^ cur[1]; \
+ UInt32 temp = p->crc[cur[0]] ^ cur[1]; \
hash2Value = temp & (kHash2Size - 1); \
hashValue = (temp ^ ((UInt32)cur[2] << 8)) & p->hashMask; }
#define HASH4_CALC { \
- UInt32 temp = g_CrcTable[cur[0]] ^ cur[1]; \
+ UInt32 temp = p->crc[cur[0]] ^ cur[1]; \
hash2Value = temp & (kHash2Size - 1); \
hash3Value = (temp ^ ((UInt32)cur[2] << 8)) & (kHash3Size - 1); \
- hashValue = (temp ^ ((UInt32)cur[2] << 8) ^ (g_CrcTable[cur[3]] << 5)) & p->hashMask; }
+ hashValue = (temp ^ ((UInt32)cur[2] << 8) ^ (p->crc[cur[3]] << 5)) & p->hashMask; }
#define HASH5_CALC { \
- UInt32 temp = g_CrcTable[cur[0]] ^ cur[1]; \
+ UInt32 temp = p->crc[cur[0]] ^ cur[1]; \
hash2Value = temp & (kHash2Size - 1); \
hash3Value = (temp ^ ((UInt32)cur[2] << 8)) & (kHash3Size - 1); \
- hash4Value = (temp ^ ((UInt32)cur[2] << 8) ^ (g_CrcTable[cur[3]] << 5)); \
- hashValue = (hash4Value ^ (g_CrcTable[cur[4]] << 3)) & p->hashMask; \
+ hash4Value = (temp ^ ((UInt32)cur[2] << 8) ^ (p->crc[cur[3]] << 5)); \
+ hashValue = (hash4Value ^ (p->crc[cur[4]] << 3)) & p->hashMask; \
hash4Value &= (kHash4Size - 1); }
-/* #define HASH_ZIP_CALC hashValue = ((cur[0] | ((UInt32)cur[1] << 8)) ^ g_CrcTable[cur[2]]) & 0xFFFF; */
-#define HASH_ZIP_CALC hashValue = ((cur[2] | ((UInt32)cur[0] << 8)) ^ g_CrcTable[cur[1]]) & 0xFFFF;
+/* #define HASH_ZIP_CALC hashValue = ((cur[0] | ((UInt32)cur[1] << 8)) ^ p->crc[cur[2]]) & 0xFFFF; */
+#define HASH_ZIP_CALC hashValue = ((cur[2] | ((UInt32)cur[0] << 8)) ^ p->crc[cur[1]]) & 0xFFFF;
#define MT_HASH2_CALC \
- hash2Value = (g_CrcTable[cur[0]] ^ cur[1]) & (kHash2Size - 1);
+ hash2Value = (p->crc[cur[0]] ^ cur[1]) & (kHash2Size - 1);
#define MT_HASH3_CALC { \
- UInt32 temp = g_CrcTable[cur[0]] ^ cur[1]; \
+ UInt32 temp = p->crc[cur[0]] ^ cur[1]; \
hash2Value = temp & (kHash2Size - 1); \
hash3Value = (temp ^ ((UInt32)cur[2] << 8)) & (kHash3Size - 1); }
#define MT_HASH4_CALC { \
- UInt32 temp = g_CrcTable[cur[0]] ^ cur[1]; \
+ UInt32 temp = p->crc[cur[0]] ^ cur[1]; \
hash2Value = temp & (kHash2Size - 1); \
hash3Value = (temp ^ ((UInt32)cur[2] << 8)) & (kHash3Size - 1); \
- hash4Value = (temp ^ ((UInt32)cur[2] << 8) ^ (g_CrcTable[cur[3]] << 5)) & (kHash4Size - 1); }
+ hash4Value = (temp ^ ((UInt32)cur[2] << 8) ^ (p->crc[cur[3]] << 5)) & (kHash4Size - 1); }
#endif
diff --git a/C/LzmaDec.c b/C/LzmaDec.c
new file mode 100755
index 00000000..37dd6c9d
--- /dev/null
+++ b/C/LzmaDec.c
@@ -0,0 +1,1014 @@
+/* LzmaDec.c -- LZMA Decoder
+2008-04-29
+Copyright (c) 1999-2008 Igor Pavlov
+Read LzmaDec.h for license options */
+
+#include "LzmaDec.h"
+
+#include <string.h>
+
+#define kNumTopBits 24
+#define kTopValue ((UInt32)1 << kNumTopBits)
+
+#define kNumBitModelTotalBits 11
+#define kBitModelTotal (1 << kNumBitModelTotalBits)
+#define kNumMoveBits 5
+
+#define RC_INIT_SIZE 5
+
+#define NORMALIZE if (range < kTopValue) { range <<= 8; code = (code << 8) | (*buf++); }
+
+#define IF_BIT_0(p) ttt = *(p); NORMALIZE; bound = (range >> kNumBitModelTotalBits) * ttt; if (code < bound)
+#define UPDATE_0(p) range = bound; *(p) = (CLzmaProb)(ttt + ((kBitModelTotal - ttt) >> kNumMoveBits));
+#define UPDATE_1(p) range -= bound; code -= bound; *(p) = (CLzmaProb)(ttt - (ttt >> kNumMoveBits));
+#define GET_BIT2(p, i, A0, A1) IF_BIT_0(p) \
+ { UPDATE_0(p); i = (i + i); A0; } else \
+ { UPDATE_1(p); i = (i + i) + 1; A1; }
+#define GET_BIT(p, i) GET_BIT2(p, i, ; , ;)
+
+#define TREE_GET_BIT(probs, i) { GET_BIT((probs + i), i); }
+#define TREE_DECODE(probs, limit, i) \
+ { i = 1; do { TREE_GET_BIT(probs, i); } while (i < limit); i -= limit; }
+
+/* #define _LZMA_SIZE_OPT */
+
+#ifdef _LZMA_SIZE_OPT
+#define TREE_6_DECODE(probs, i) TREE_DECODE(probs, (1 << 6), i)
+#else
+#define TREE_6_DECODE(probs, i) \
+ { i = 1; \
+ TREE_GET_BIT(probs, i); \
+ TREE_GET_BIT(probs, i); \
+ TREE_GET_BIT(probs, i); \
+ TREE_GET_BIT(probs, i); \
+ TREE_GET_BIT(probs, i); \
+ TREE_GET_BIT(probs, i); \
+ i -= 0x40; }
+#endif
+
+#define NORMALIZE_CHECK if (range < kTopValue) { if (buf >= bufLimit) return DUMMY_ERROR; range <<= 8; code = (code << 8) | (*buf++); }
+
+#define IF_BIT_0_CHECK(p) ttt = *(p); NORMALIZE_CHECK; bound = (range >> kNumBitModelTotalBits) * ttt; if (code < bound)
+#define UPDATE_0_CHECK range = bound;
+#define UPDATE_1_CHECK range -= bound; code -= bound;
+#define GET_BIT2_CHECK(p, i, A0, A1) IF_BIT_0_CHECK(p) \
+ { UPDATE_0_CHECK; i = (i + i); A0; } else \
+ { UPDATE_1_CHECK; i = (i + i) + 1; A1; }
+#define GET_BIT_CHECK(p, i) GET_BIT2_CHECK(p, i, ; , ;)
+#define TREE_DECODE_CHECK(probs, limit, i) \
+ { i = 1; do { GET_BIT_CHECK(probs + i, i) } while(i < limit); i -= limit; }
+
+
+#define kNumPosBitsMax 4
+#define kNumPosStatesMax (1 << kNumPosBitsMax)
+
+#define kLenNumLowBits 3
+#define kLenNumLowSymbols (1 << kLenNumLowBits)
+#define kLenNumMidBits 3
+#define kLenNumMidSymbols (1 << kLenNumMidBits)
+#define kLenNumHighBits 8
+#define kLenNumHighSymbols (1 << kLenNumHighBits)
+
+#define LenChoice 0
+#define LenChoice2 (LenChoice + 1)
+#define LenLow (LenChoice2 + 1)
+#define LenMid (LenLow + (kNumPosStatesMax << kLenNumLowBits))
+#define LenHigh (LenMid + (kNumPosStatesMax << kLenNumMidBits))
+#define kNumLenProbs (LenHigh + kLenNumHighSymbols)
+
+
+#define kNumStates 12
+#define kNumLitStates 7
+
+#define kStartPosModelIndex 4
+#define kEndPosModelIndex 14
+#define kNumFullDistances (1 << (kEndPosModelIndex >> 1))
+
+#define kNumPosSlotBits 6
+#define kNumLenToPosStates 4
+
+#define kNumAlignBits 4
+#define kAlignTableSize (1 << kNumAlignBits)
+
+#define kMatchMinLen 2
+#define kMatchSpecLenStart (kMatchMinLen + kLenNumLowSymbols + kLenNumMidSymbols + kLenNumHighSymbols)
+
+#define IsMatch 0
+#define IsRep (IsMatch + (kNumStates << kNumPosBitsMax))
+#define IsRepG0 (IsRep + kNumStates)
+#define IsRepG1 (IsRepG0 + kNumStates)
+#define IsRepG2 (IsRepG1 + kNumStates)
+#define IsRep0Long (IsRepG2 + kNumStates)
+#define PosSlot (IsRep0Long + (kNumStates << kNumPosBitsMax))
+#define SpecPos (PosSlot + (kNumLenToPosStates << kNumPosSlotBits))
+#define Align (SpecPos + kNumFullDistances - kEndPosModelIndex)
+#define LenCoder (Align + kAlignTableSize)
+#define RepLenCoder (LenCoder + kNumLenProbs)
+#define Literal (RepLenCoder + kNumLenProbs)
+
+#define LZMA_BASE_SIZE 1846
+#define LZMA_LIT_SIZE 768
+
+#define LzmaProps_GetNumProbs(p) ((UInt32)LZMA_BASE_SIZE + (LZMA_LIT_SIZE << ((p)->lc + (p)->lp)))
+
+#if Literal != LZMA_BASE_SIZE
+StopCompilingDueBUG
+#endif
+
+/*
+#define LZMA_STREAM_WAS_FINISHED_ID (-1)
+#define LZMA_SPEC_LEN_OFFSET (-3)
+*/
+
+Byte kLiteralNextStates[kNumStates * 2] =
+{
+ 0, 0, 0, 0, 1, 2, 3, 4, 5, 6, 4, 5,
+ 7, 7, 7, 7, 7, 7, 7, 10, 10, 10, 10, 10
+};
+
+#define LZMA_DIC_MIN (1 << 12)
+
+/* First LZMA-symbol is always decoded.
+And it decodes new LZMA-symbols while (buf < bufLimit), but "buf" is without last normalization
+Out:
+ Result:
+ 0 - OK
+ 1 - Error
+ p->remainLen:
+ < kMatchSpecLenStart : normal remain
+ = kMatchSpecLenStart : finished
+ = kMatchSpecLenStart + 1 : Flush marker
+ = kMatchSpecLenStart + 2 : State Init Marker
+*/
+
+static int MY_FAST_CALL LzmaDec_DecodeReal(CLzmaDec *p, SizeT limit, const Byte *bufLimit)
+{
+ CLzmaProb *probs = p->probs;
+
+ unsigned state = p->state;
+ UInt32 rep0 = p->reps[0], rep1 = p->reps[1], rep2 = p->reps[2], rep3 = p->reps[3];
+ unsigned pbMask = ((unsigned)1 << (p->prop.pb)) - 1;
+ unsigned lpMask = ((unsigned)1 << (p->prop.lp)) - 1;
+ unsigned lc = p->prop.lc;
+
+ Byte *dic = p->dic;
+ SizeT dicBufSize = p->dicBufSize;
+ SizeT dicPos = p->dicPos;
+
+ UInt32 processedPos = p->processedPos;
+ UInt32 checkDicSize = p->checkDicSize;
+ unsigned len = 0;
+
+ const Byte *buf = p->buf;
+ UInt32 range = p->range;
+ UInt32 code = p->code;
+
+ do
+ {
+ CLzmaProb *prob;
+ UInt32 bound;
+ unsigned ttt;
+ unsigned posState = processedPos & pbMask;
+
+ prob = probs + IsMatch + (state << kNumPosBitsMax) + posState;
+ IF_BIT_0(prob)
+ {
+ unsigned symbol;
+ UPDATE_0(prob);
+ prob = probs + Literal;
+ if (checkDicSize != 0 || processedPos != 0)
+ prob += (LZMA_LIT_SIZE * (((processedPos & lpMask) << lc) +
+ (dic[(dicPos == 0 ? dicBufSize : dicPos) - 1] >> (8 - lc))));
+
+ if (state < kNumLitStates)
+ {
+ symbol = 1;
+ do { GET_BIT(prob + symbol, symbol) } while (symbol < 0x100);
+ }
+ else
+ {
+ unsigned matchByte = p->dic[(dicPos - rep0) + ((dicPos < rep0) ? dicBufSize : 0)];
+ unsigned offs = 0x100;
+ symbol = 1;
+ do
+ {
+ unsigned bit;
+ CLzmaProb *probLit;
+ matchByte <<= 1;
+ bit = (matchByte & offs);
+ probLit = prob + offs + bit + symbol;
+ GET_BIT2(probLit, symbol, offs &= ~bit, offs &= bit)
+ }
+ while (symbol < 0x100);
+ }
+ dic[dicPos++] = (Byte)symbol;
+ processedPos++;
+
+ state = kLiteralNextStates[state];
+ /* if (state < 4) state = 0; else if (state < 10) state -= 3; else state -= 6; */
+ continue;
+ }
+ else
+ {
+ UPDATE_1(prob);
+ prob = probs + IsRep + state;
+ IF_BIT_0(prob)
+ {
+ UPDATE_0(prob);
+ state += kNumStates;
+ prob = probs + LenCoder;
+ }
+ else
+ {
+ UPDATE_1(prob);
+ if (checkDicSize == 0 && processedPos == 0)
+ return SZ_ERROR_DATA;
+ prob = probs + IsRepG0 + state;
+ IF_BIT_0(prob)
+ {
+ UPDATE_0(prob);
+ prob = probs + IsRep0Long + (state << kNumPosBitsMax) + posState;
+ IF_BIT_0(prob)
+ {
+ UPDATE_0(prob);
+ dic[dicPos] = dic[(dicPos - rep0) + ((dicPos < rep0) ? dicBufSize : 0)];
+ dicPos++;
+ processedPos++;
+ state = state < kNumLitStates ? 9 : 11;
+ continue;
+ }
+ UPDATE_1(prob);
+ }
+ else
+ {
+ UInt32 distance;
+ UPDATE_1(prob);
+ prob = probs + IsRepG1 + state;
+ IF_BIT_0(prob)
+ {
+ UPDATE_0(prob);
+ distance = rep1;
+ }
+ else
+ {
+ UPDATE_1(prob);
+ prob = probs + IsRepG2 + state;
+ IF_BIT_0(prob)
+ {
+ UPDATE_0(prob);
+ distance = rep2;
+ }
+ else
+ {
+ UPDATE_1(prob);
+ distance = rep3;
+ rep3 = rep2;
+ }
+ rep2 = rep1;
+ }
+ rep1 = rep0;
+ rep0 = distance;
+ }
+ state = state < kNumLitStates ? 8 : 11;
+ prob = probs + RepLenCoder;
+ }
+ {
+ unsigned limit, offset;
+ CLzmaProb *probLen = prob + LenChoice;
+ IF_BIT_0(probLen)
+ {
+ UPDATE_0(probLen);
+ probLen = prob + LenLow + (posState << kLenNumLowBits);
+ offset = 0;
+ limit = (1 << kLenNumLowBits);
+ }
+ else
+ {
+ UPDATE_1(probLen);
+ probLen = prob + LenChoice2;
+ IF_BIT_0(probLen)
+ {
+ UPDATE_0(probLen);
+ probLen = prob + LenMid + (posState << kLenNumMidBits);
+ offset = kLenNumLowSymbols;
+ limit = (1 << kLenNumMidBits);
+ }
+ else
+ {
+ UPDATE_1(probLen);
+ probLen = prob + LenHigh;
+ offset = kLenNumLowSymbols + kLenNumMidSymbols;
+ limit = (1 << kLenNumHighBits);
+ }
+ }
+ TREE_DECODE(probLen, limit, len);
+ len += offset;
+ }
+
+ if (state >= kNumStates)
+ {
+ UInt32 distance;
+ prob = probs + PosSlot +
+ ((len < kNumLenToPosStates ? len : kNumLenToPosStates - 1) << kNumPosSlotBits);
+ TREE_6_DECODE(prob, distance);
+ if (distance >= kStartPosModelIndex)
+ {
+ unsigned posSlot = (unsigned)distance;
+ int numDirectBits = (int)(((distance >> 1) - 1));
+ distance = (2 | (distance & 1));
+ if (posSlot < kEndPosModelIndex)
+ {
+ distance <<= numDirectBits;
+ prob = probs + SpecPos + distance - posSlot - 1;
+ {
+ UInt32 mask = 1;
+ unsigned i = 1;
+ do
+ {
+ GET_BIT2(prob + i, i, ; , distance |= mask);
+ mask <<= 1;
+ }
+ while(--numDirectBits != 0);
+ }
+ }
+ else
+ {
+ numDirectBits -= kNumAlignBits;
+ do
+ {
+ NORMALIZE
+ range >>= 1;
+
+ {
+ UInt32 t;
+ code -= range;
+ t = (0 - ((UInt32)code >> 31)); /* (UInt32)((Int32)code >> 31) */
+ distance = (distance << 1) + (t + 1);
+ code += range & t;
+ }
+ /*
+ distance <<= 1;
+ if (code >= range)
+ {
+ code -= range;
+ distance |= 1;
+ }
+ */
+ }
+ while (--numDirectBits != 0);
+ prob = probs + Align;
+ distance <<= kNumAlignBits;
+ {
+ unsigned i = 1;
+ GET_BIT2(prob + i, i, ; , distance |= 1);
+ GET_BIT2(prob + i, i, ; , distance |= 2);
+ GET_BIT2(prob + i, i, ; , distance |= 4);
+ GET_BIT2(prob + i, i, ; , distance |= 8);
+ }
+ if (distance == (UInt32)0xFFFFFFFF)
+ {
+ len += kMatchSpecLenStart;
+ state -= kNumStates;
+ break;
+ }
+ }
+ }
+ rep3 = rep2;
+ rep2 = rep1;
+ rep1 = rep0;
+ rep0 = distance + 1;
+ if (checkDicSize == 0)
+ {
+ if (distance >= processedPos)
+ return SZ_ERROR_DATA;
+ }
+ else if (distance >= checkDicSize)
+ return SZ_ERROR_DATA;
+ state = (state < kNumStates + kNumLitStates) ? kNumLitStates : kNumLitStates + 3;
+ /* state = kLiteralNextStates[state]; */
+ }
+
+ len += kMatchMinLen;
+
+ {
+ SizeT rem = limit - dicPos;
+ unsigned curLen = ((rem < len) ? (unsigned)rem : len);
+ SizeT pos = (dicPos - rep0) + ((dicPos < rep0) ? dicBufSize : 0);
+
+ processedPos += curLen;
+
+ len -= curLen;
+ if (pos + curLen <= dicBufSize)
+ {
+ Byte *dest = dic + dicPos;
+ ptrdiff_t src = (ptrdiff_t)pos - (ptrdiff_t)dicPos;
+ const Byte *lim = dest + curLen;
+ dicPos += curLen;
+ do
+ *(dest) = (Byte)*(dest + src);
+ while (++dest != lim);
+ }
+ else
+ {
+ do
+ {
+ dic[dicPos++] = dic[pos];
+ if (++pos == dicBufSize)
+ pos = 0;
+ }
+ while (--curLen != 0);
+ }
+ }
+ }
+ }
+ while (dicPos < limit && buf < bufLimit);
+ NORMALIZE;
+ p->buf = buf;
+ p->range = range;
+ p->code = code;
+ p->remainLen = len;
+ p->dicPos = dicPos;
+ p->processedPos = processedPos;
+ p->reps[0] = rep0;
+ p->reps[1] = rep1;
+ p->reps[2] = rep2;
+ p->reps[3] = rep3;
+ p->state = state;
+
+ return SZ_OK;
+}
+
+static void MY_FAST_CALL LzmaDec_WriteRem(CLzmaDec *p, SizeT limit)
+{
+ if (p->remainLen != 0 && p->remainLen < kMatchSpecLenStart)
+ {
+ Byte *dic = p->dic;
+ SizeT dicPos = p->dicPos;
+ SizeT dicBufSize = p->dicBufSize;
+ unsigned len = p->remainLen;
+ UInt32 rep0 = p->reps[0];
+ if (limit - dicPos < len)
+ len = (unsigned)(limit - dicPos);
+
+ if (p->checkDicSize == 0 && p->prop.dicSize - p->processedPos <= len)
+ p->checkDicSize = p->prop.dicSize;
+
+ p->processedPos += len;
+ p->remainLen -= len;
+ while (len-- != 0)
+ {
+ dic[dicPos] = dic[(dicPos - rep0) + ((dicPos < rep0) ? dicBufSize : 0)];
+ dicPos++;
+ }
+ p->dicPos = dicPos;
+ }
+}
+
+/* LzmaDec_DecodeReal2 decodes LZMA-symbols and sets p->needFlush and p->needInit, if required. */
+
+static int MY_FAST_CALL LzmaDec_DecodeReal2(CLzmaDec *p, SizeT limit, const Byte *bufLimit)
+{
+ do
+ {
+ SizeT limit2 = limit;
+ if (p->checkDicSize == 0)
+ {
+ UInt32 rem = p->prop.dicSize - p->processedPos;
+ if (limit - p->dicPos > rem)
+ limit2 = p->dicPos + rem;
+ }
+ RINOK(LzmaDec_DecodeReal(p, limit2, bufLimit));
+ if (p->processedPos >= p->prop.dicSize)
+ p->checkDicSize = p->prop.dicSize;
+ LzmaDec_WriteRem(p, limit);
+ }
+ while (p->dicPos < limit && p->buf < bufLimit && p->remainLen < kMatchSpecLenStart);
+
+ if (p->remainLen > kMatchSpecLenStart)
+ {
+ p->remainLen = kMatchSpecLenStart;
+ }
+ return 0;
+}
+
+typedef enum
+{
+ DUMMY_ERROR, /* unexpected end of input stream */
+ DUMMY_LIT,
+ DUMMY_MATCH,
+ DUMMY_REP
+} ELzmaDummy;
+
+static ELzmaDummy LzmaDec_TryDummy(const CLzmaDec *p, const Byte *buf, SizeT inSize)
+{
+ UInt32 range = p->range;
+ UInt32 code = p->code;
+ const Byte *bufLimit = buf + inSize;
+ CLzmaProb *probs = p->probs;
+ unsigned state = p->state;
+ ELzmaDummy res;
+
+ {
+ CLzmaProb *prob;
+ UInt32 bound;
+ unsigned ttt;
+ unsigned posState = (p->processedPos) & ((1 << p->prop.pb) - 1);
+
+ prob = probs + IsMatch + (state << kNumPosBitsMax) + posState;
+ IF_BIT_0_CHECK(prob)
+ {
+ UPDATE_0_CHECK
+
+ /* if (bufLimit - buf >= 7) return DUMMY_LIT; */
+
+ prob = probs + Literal;
+ if (p->checkDicSize != 0 || p->processedPos != 0)
+ prob += (LZMA_LIT_SIZE *
+ ((((p->processedPos) & ((1 << (p->prop.lp)) - 1)) << p->prop.lc) +
+ (p->dic[(p->dicPos == 0 ? p->dicBufSize : p->dicPos) - 1] >> (8 - p->prop.lc))));
+
+ if (state < kNumLitStates)
+ {
+ unsigned symbol = 1;
+ do { GET_BIT_CHECK(prob + symbol, symbol) } while (symbol < 0x100);
+ }
+ else
+ {
+ unsigned matchByte = p->dic[p->dicPos - p->reps[0] +
+ ((p->dicPos < p->reps[0]) ? p->dicBufSize : 0)];
+ unsigned offs = 0x100;
+ unsigned symbol = 1;
+ do
+ {
+ unsigned bit;
+ CLzmaProb *probLit;
+ matchByte <<= 1;
+ bit = (matchByte & offs);
+ probLit = prob + offs + bit + symbol;
+ GET_BIT2_CHECK(probLit, symbol, offs &= ~bit, offs &= bit)
+ }
+ while (symbol < 0x100);
+ }
+ res = DUMMY_LIT;
+ }
+ else
+ {
+ unsigned len;
+ UPDATE_1_CHECK;
+
+ prob = probs + IsRep + state;
+ IF_BIT_0_CHECK(prob)
+ {
+ UPDATE_0_CHECK;
+ state = 0;
+ prob = probs + LenCoder;
+ res = DUMMY_MATCH;
+ }
+ else
+ {
+ UPDATE_1_CHECK;
+ res = DUMMY_REP;
+ prob = probs + IsRepG0 + state;
+ IF_BIT_0_CHECK(prob)
+ {
+ UPDATE_0_CHECK;
+ prob = probs + IsRep0Long + (state << kNumPosBitsMax) + posState;
+ IF_BIT_0_CHECK(prob)
+ {
+ UPDATE_0_CHECK;
+ NORMALIZE_CHECK;
+ return DUMMY_REP;
+ }
+ else
+ {
+ UPDATE_1_CHECK;
+ }
+ }
+ else
+ {
+ UPDATE_1_CHECK;
+ prob = probs + IsRepG1 + state;
+ IF_BIT_0_CHECK(prob)
+ {
+ UPDATE_0_CHECK;
+ }
+ else
+ {
+ UPDATE_1_CHECK;
+ prob = probs + IsRepG2 + state;
+ IF_BIT_0_CHECK(prob)
+ {
+ UPDATE_0_CHECK;
+ }
+ else
+ {
+ UPDATE_1_CHECK;
+ }
+ }
+ }
+ state = kNumStates;
+ prob = probs + RepLenCoder;
+ }
+ {
+ unsigned limit, offset;
+ CLzmaProb *probLen = prob + LenChoice;
+ IF_BIT_0_CHECK(probLen)
+ {
+ UPDATE_0_CHECK;
+ probLen = prob + LenLow + (posState << kLenNumLowBits);
+ offset = 0;
+ limit = 1 << kLenNumLowBits;
+ }
+ else
+ {
+ UPDATE_1_CHECK;
+ probLen = prob + LenChoice2;
+ IF_BIT_0_CHECK(probLen)
+ {
+ UPDATE_0_CHECK;
+ probLen = prob + LenMid + (posState << kLenNumMidBits);
+ offset = kLenNumLowSymbols;
+ limit = 1 << kLenNumMidBits;
+ }
+ else
+ {
+ UPDATE_1_CHECK;
+ probLen = prob + LenHigh;
+ offset = kLenNumLowSymbols + kLenNumMidSymbols;
+ limit = 1 << kLenNumHighBits;
+ }
+ }
+ TREE_DECODE_CHECK(probLen, limit, len);
+ len += offset;
+ }
+
+ if (state < 4)
+ {
+ unsigned posSlot;
+ prob = probs + PosSlot +
+ ((len < kNumLenToPosStates ? len : kNumLenToPosStates - 1) <<
+ kNumPosSlotBits);
+ TREE_DECODE_CHECK(prob, 1 << kNumPosSlotBits, posSlot);
+ if (posSlot >= kStartPosModelIndex)
+ {
+ int numDirectBits = ((posSlot >> 1) - 1);
+
+ /* if (bufLimit - buf >= 8) return DUMMY_MATCH; */
+
+ if (posSlot < kEndPosModelIndex)
+ {
+ prob = probs + SpecPos + ((2 | (posSlot & 1)) << numDirectBits) - posSlot - 1;
+ }
+ else
+ {
+ numDirectBits -= kNumAlignBits;
+ do
+ {
+ NORMALIZE_CHECK
+ range >>= 1;
+ code -= range & (((code - range) >> 31) - 1);
+ /* if (code >= range) code -= range; */
+ }
+ while (--numDirectBits != 0);
+ prob = probs + Align;
+ numDirectBits = kNumAlignBits;
+ }
+ {
+ unsigned i = 1;
+ do
+ {
+ GET_BIT_CHECK(prob + i, i);
+ }
+ while(--numDirectBits != 0);
+ }
+ }
+ }
+ }
+ }
+ NORMALIZE_CHECK;
+ return res;
+}
+
+
+static void LzmaDec_InitRc(CLzmaDec *p, const Byte *data)
+{
+ p->code = ((UInt32)data[1] << 24) | ((UInt32)data[2] << 16) | ((UInt32)data[3] << 8) | ((UInt32)data[4]);
+ p->range = 0xFFFFFFFF;
+ p->needFlush = 0;
+}
+
+void LzmaDec_InitDicAndState(CLzmaDec *p, Bool initDic, Bool initState)
+{
+ p->needFlush = 1;
+ p->remainLen = 0;
+ p->tempBufSize = 0;
+
+ if (initDic)
+ {
+ p->processedPos = 0;
+ p->checkDicSize = 0;
+ p->needInitState = 1;
+ }
+ if (initState)
+ p->needInitState = 1;
+}
+
+void LzmaDec_Init(CLzmaDec *p)
+{
+ p->dicPos = 0;
+ LzmaDec_InitDicAndState(p, True, True);
+}
+
+static void LzmaDec_InitStateReal(CLzmaDec *p)
+{
+ UInt32 numProbs = Literal + ((UInt32)LZMA_LIT_SIZE << (p->prop.lc + p->prop.lp));
+ UInt32 i;
+ CLzmaProb *probs = p->probs;
+ for (i = 0; i < numProbs; i++)
+ probs[i] = kBitModelTotal >> 1;
+ p->reps[0] = p->reps[1] = p->reps[2] = p->reps[3] = 1;
+ p->state = 0;
+ p->needInitState = 0;
+}
+
+SRes LzmaDec_DecodeToDic(CLzmaDec *p, SizeT dicLimit, const Byte *src, SizeT *srcLen,
+ ELzmaFinishMode finishMode, ELzmaStatus *status)
+{
+ SizeT inSize = *srcLen;
+ (*srcLen) = 0;
+ LzmaDec_WriteRem(p, dicLimit);
+
+ *status = LZMA_STATUS_NOT_SPECIFIED;
+
+ while (p->remainLen != kMatchSpecLenStart)
+ {
+ int checkEndMarkNow;
+
+ if (p->needFlush != 0)
+ {
+ for (; inSize > 0 && p->tempBufSize < RC_INIT_SIZE; (*srcLen)++, inSize--)
+ p->tempBuf[p->tempBufSize++] = *src++;
+ if (p->tempBufSize < RC_INIT_SIZE)
+ {
+ *status = LZMA_STATUS_NEEDS_MORE_INPUT;
+ return SZ_OK;
+ }
+ if (p->tempBuf[0] != 0)
+ return SZ_ERROR_DATA;
+
+ LzmaDec_InitRc(p, p->tempBuf);
+ p->tempBufSize = 0;
+ }
+
+ checkEndMarkNow = 0;
+ if (p->dicPos >= dicLimit)
+ {
+ if (p->remainLen == 0 && p->code == 0)
+ {
+ *status = LZMA_STATUS_MAYBE_FINISHED_WITHOUT_MARK;
+ return SZ_OK;
+ }
+ if (finishMode == LZMA_FINISH_ANY)
+ {
+ *status = LZMA_STATUS_NOT_FINISHED;
+ return SZ_OK;
+ }
+ if (p->remainLen != 0)
+ {
+ *status = LZMA_STATUS_NOT_FINISHED;
+ return SZ_ERROR_DATA;
+ }
+ checkEndMarkNow = 1;
+ }
+
+ if (p->needInitState)
+ LzmaDec_InitStateReal(p);
+
+ if (p->tempBufSize == 0)
+ {
+ SizeT processed;
+ const Byte *bufLimit;
+ if (inSize < LZMA_REQUIRED_INPUT_MAX || checkEndMarkNow)
+ {
+ int dummyRes = LzmaDec_TryDummy(p, src, inSize);
+ if (dummyRes == DUMMY_ERROR)
+ {
+ memcpy(p->tempBuf, src, inSize);
+ p->tempBufSize = (unsigned)inSize;
+ (*srcLen) += inSize;
+ *status = LZMA_STATUS_NEEDS_MORE_INPUT;
+ return SZ_OK;
+ }
+ if (checkEndMarkNow && dummyRes != DUMMY_MATCH)
+ {
+ *status = LZMA_STATUS_NOT_FINISHED;
+ return SZ_ERROR_DATA;
+ }
+ bufLimit = src;
+ }
+ else
+ bufLimit = src + inSize - LZMA_REQUIRED_INPUT_MAX;
+ p->buf = src;
+ if (LzmaDec_DecodeReal2(p, dicLimit, bufLimit) != 0)
+ return SZ_ERROR_DATA;
+ processed = p->buf - src;
+ (*srcLen) += processed;
+ src += processed;
+ inSize -= processed;
+ }
+ else
+ {
+ unsigned rem = p->tempBufSize, lookAhead = 0;
+ while (rem < LZMA_REQUIRED_INPUT_MAX && lookAhead < inSize)
+ p->tempBuf[rem++] = src[lookAhead++];
+ p->tempBufSize = rem;
+ if (rem < LZMA_REQUIRED_INPUT_MAX || checkEndMarkNow)
+ {
+ int dummyRes = LzmaDec_TryDummy(p, p->tempBuf, rem);
+ if (dummyRes == DUMMY_ERROR)
+ {
+ (*srcLen) += lookAhead;
+ *status = LZMA_STATUS_NEEDS_MORE_INPUT;
+ return SZ_OK;
+ }
+ if (checkEndMarkNow && dummyRes != DUMMY_MATCH)
+ {
+ *status = LZMA_STATUS_NOT_FINISHED;
+ return SZ_ERROR_DATA;
+ }
+ }
+ p->buf = p->tempBuf;
+ if (LzmaDec_DecodeReal2(p, dicLimit, p->buf) != 0)
+ return SZ_ERROR_DATA;
+ lookAhead -= (rem - (unsigned)(p->buf - p->tempBuf));
+ (*srcLen) += lookAhead;
+ src += lookAhead;
+ inSize -= lookAhead;
+ p->tempBufSize = 0;
+ }
+ }
+ if (p->code == 0)
+ *status = LZMA_STATUS_FINISHED_WITH_MARK;
+ return (p->code == 0) ? SZ_OK : SZ_ERROR_DATA;
+}
+
+SRes LzmaDec_DecodeToBuf(CLzmaDec *p, Byte *dest, SizeT *destLen, const Byte *src, SizeT *srcLen, ELzmaFinishMode finishMode, ELzmaStatus *status)
+{
+ SizeT outSize = *destLen;
+ SizeT inSize = *srcLen;
+ *srcLen = *destLen = 0;
+ for (;;)
+ {
+ SizeT inSizeCur = inSize, outSizeCur, dicPos;
+ ELzmaFinishMode curFinishMode;
+ SRes res;
+ if (p->dicPos == p->dicBufSize)
+ p->dicPos = 0;
+ dicPos = p->dicPos;
+ if (outSize > p->dicBufSize - dicPos)
+ {
+ outSizeCur = p->dicBufSize;
+ curFinishMode = LZMA_FINISH_ANY;
+ }
+ else
+ {
+ outSizeCur = dicPos + outSize;
+ curFinishMode = finishMode;
+ }
+
+ res = LzmaDec_DecodeToDic(p, outSizeCur, src, &inSizeCur, curFinishMode, status);
+ src += inSizeCur;
+ inSize -= inSizeCur;
+ *srcLen += inSizeCur;
+ outSizeCur = p->dicPos - dicPos;
+ memcpy(dest, p->dic + dicPos, outSizeCur);
+ dest += outSizeCur;
+ outSize -= outSizeCur;
+ *destLen += outSizeCur;
+ if (res != 0)
+ return res;
+ if (outSizeCur == 0 || outSize == 0)
+ return SZ_OK;
+ }
+}
+
+void LzmaDec_FreeProbs(CLzmaDec *p, ISzAlloc *alloc)
+{
+ alloc->Free(alloc, p->probs);
+ p->probs = 0;
+}
+
+static void LzmaDec_FreeDict(CLzmaDec *p, ISzAlloc *alloc)
+{
+ alloc->Free(alloc, p->dic);
+ p->dic = 0;
+}
+
+void LzmaDec_Free(CLzmaDec *p, ISzAlloc *alloc)
+{
+ LzmaDec_FreeProbs(p, alloc);
+ LzmaDec_FreeDict(p, alloc);
+}
+
+SRes LzmaProps_Decode(CLzmaProps *p, const Byte *data, unsigned size)
+{
+ UInt32 dicSize;
+ Byte d;
+
+ if (size < LZMA_PROPS_SIZE)
+ return SZ_ERROR_UNSUPPORTED;
+ else
+ dicSize = data[1] | ((UInt32)data[2] << 8) | ((UInt32)data[3] << 16) | ((UInt32)data[4] << 24);
+
+ if (dicSize < LZMA_DIC_MIN)
+ dicSize = LZMA_DIC_MIN;
+ p->dicSize = dicSize;
+
+ d = data[0];
+ if (d >= (9 * 5 * 5))
+ return SZ_ERROR_UNSUPPORTED;
+
+ p->lc = d % 9;
+ d /= 9;
+ p->pb = d / 5;
+ p->lp = d % 5;
+
+ return SZ_OK;
+}
+
+static SRes LzmaDec_AllocateProbs2(CLzmaDec *p, const CLzmaProps *propNew, ISzAlloc *alloc)
+{
+ UInt32 numProbs = LzmaProps_GetNumProbs(propNew);
+ if (p->probs == 0 || numProbs != p->numProbs)
+ {
+ LzmaDec_FreeProbs(p, alloc);
+ p->probs = (CLzmaProb *)alloc->Alloc(alloc, numProbs * sizeof(CLzmaProb));
+ p->numProbs = numProbs;
+ if (p->probs == 0)
+ return SZ_ERROR_MEM;
+ }
+ return SZ_OK;
+}
+
+SRes LzmaDec_AllocateProbs(CLzmaDec *p, const Byte *props, unsigned propsSize, ISzAlloc *alloc)
+{
+ CLzmaProps propNew;
+ RINOK(LzmaProps_Decode(&propNew, props, propsSize));
+ RINOK(LzmaDec_AllocateProbs2(p, &propNew, alloc));
+ p->prop = propNew;
+ return SZ_OK;
+}
+
+SRes LzmaDec_Allocate(CLzmaDec *p, const Byte *props, unsigned propsSize, ISzAlloc *alloc)
+{
+ CLzmaProps propNew;
+ SizeT dicBufSize;
+ RINOK(LzmaProps_Decode(&propNew, props, propsSize));
+ RINOK(LzmaDec_AllocateProbs2(p, &propNew, alloc));
+ dicBufSize = propNew.dicSize;
+ if (p->dic == 0 || dicBufSize != p->dicBufSize)
+ {
+ LzmaDec_FreeDict(p, alloc);
+ p->dic = (Byte *)alloc->Alloc(alloc, dicBufSize);
+ if (p->dic == 0)
+ {
+ LzmaDec_FreeProbs(p, alloc);
+ return SZ_ERROR_MEM;
+ }
+ }
+ p->dicBufSize = dicBufSize;
+ p->prop = propNew;
+ return SZ_OK;
+}
+
+SRes LzmaDecode(Byte *dest, SizeT *destLen, const Byte *src, SizeT *srcLen,
+ const Byte *propData, unsigned propSize, ELzmaFinishMode finishMode,
+ ELzmaStatus *status, ISzAlloc *alloc)
+{
+ CLzmaDec p;
+ SRes res;
+ SizeT inSize = *srcLen;
+ SizeT outSize = *destLen;
+ *srcLen = *destLen = 0;
+ if (inSize < RC_INIT_SIZE)
+ return SZ_ERROR_INPUT_EOF;
+
+ LzmaDec_Construct(&p);
+ res = LzmaDec_AllocateProbs(&p, propData, propSize, alloc);
+ if (res != 0)
+ return res;
+ p.dic = dest;
+ p.dicBufSize = outSize;
+
+ LzmaDec_Init(&p);
+
+ *srcLen = inSize;
+ res = LzmaDec_DecodeToDic(&p, outSize, src, srcLen, finishMode, status);
+
+ if (res == SZ_OK && *status == LZMA_STATUS_NEEDS_MORE_INPUT)
+ res = SZ_ERROR_INPUT_EOF;
+
+ (*destLen) = p.dicPos;
+ LzmaDec_FreeProbs(&p, alloc);
+ return res;
+}
diff --git a/C/LzmaDec.h b/C/LzmaDec.h
new file mode 100755
index 00000000..9610f0ec
--- /dev/null
+++ b/C/LzmaDec.h
@@ -0,0 +1,232 @@
+/* LzmaDec.h -- LZMA Decoder
+2008-04-29
+Copyright (c) 1999-2008 Igor Pavlov
+You can use any of the following license options:
+ 1) GNU Lesser General Public License (GNU LGPL)
+ 2) Common Public License (CPL)
+ 3) Common Development and Distribution License (CDDL) Version 1.0
+ 4) Igor Pavlov, as the author of this code, expressly permits you to
+ statically or dynamically link your code (or bind by name) to this file,
+ while you keep this file unmodified.
+*/
+
+#ifndef __LZMADEC_H
+#define __LZMADEC_H
+
+#include "Types.h"
+
+/* #define _LZMA_PROB32 */
+/* _LZMA_PROB32 can increase the speed on some CPUs,
+ but memory usage for CLzmaDec::probs will be doubled in that case */
+
+#ifdef _LZMA_PROB32
+#define CLzmaProb UInt32
+#else
+#define CLzmaProb UInt16
+#endif
+
+
+/* ---------- LZMA Properties ---------- */
+
+#define LZMA_PROPS_SIZE 5
+
+typedef struct _CLzmaProps
+{
+ unsigned lc, lp, pb;
+ UInt32 dicSize;
+} CLzmaProps;
+
+/* LzmaProps_Decode - decodes properties
+Returns:
+ SZ_OK
+ SZ_ERROR_UNSUPPORTED - Unsupported properties
+*/
+
+SRes LzmaProps_Decode(CLzmaProps *p, const Byte *data, unsigned size);
+
+
+/* ---------- LZMA Decoder state ---------- */
+
+/* LZMA_REQUIRED_INPUT_MAX = number of required input bytes for worst case.
+ Num bits = log2((2^11 / 31) ^ 22) + 26 < 134 + 26 = 160; */
+
+#define LZMA_REQUIRED_INPUT_MAX 20
+
+typedef struct
+{
+ CLzmaProps prop;
+ CLzmaProb *probs;
+ Byte *dic;
+ const Byte *buf;
+ UInt32 range, code;
+ SizeT dicPos;
+ SizeT dicBufSize;
+ UInt32 processedPos;
+ UInt32 checkDicSize;
+ unsigned state;
+ UInt32 reps[4];
+ unsigned remainLen;
+ int needFlush;
+ int needInitState;
+ UInt32 numProbs;
+ unsigned tempBufSize;
+ Byte tempBuf[LZMA_REQUIRED_INPUT_MAX];
+} CLzmaDec;
+
+#define LzmaDec_Construct(p) { (p)->dic = 0; (p)->probs = 0; }
+
+void LzmaDec_Init(CLzmaDec *p);
+
+/* There are two types of LZMA streams:
+ 0) Stream with end mark. That end mark adds about 6 bytes to compressed size.
+ 1) Stream without end mark. You must know exact uncompressed size to decompress such stream. */
+
+typedef enum
+{
+ LZMA_FINISH_ANY, /* finish at any point */
+ LZMA_FINISH_END /* block must be finished at the end */
+} ELzmaFinishMode;
+
+/* ELzmaFinishMode has meaning only if the decoding reaches output limit !!!
+
+ You must use LZMA_FINISH_END, when you know that current output buffer
+ covers last bytes of block. In other cases you must use LZMA_FINISH_ANY.
+
+ If LZMA decoder sees end marker before reaching output limit, it returns SZ_OK,
+ and output value of destLen will be less than output buffer size limit.
+ You can check status result also.
+
+ You can use multiple checks to test data integrity after full decompression:
+ 1) Check Result and "status" variable.
+ 2) Check that output(destLen) = uncompressedSize, if you know real uncompressedSize.
+ 3) Check that output(srcLen) = compressedSize, if you know real compressedSize.
+ You must use correct finish mode in that case. */
+
+typedef enum
+{
+ LZMA_STATUS_NOT_SPECIFIED, /* use main error code instead */
+ LZMA_STATUS_FINISHED_WITH_MARK, /* stream was finished with end mark. */
+ LZMA_STATUS_NOT_FINISHED, /* stream was not finished */
+ LZMA_STATUS_NEEDS_MORE_INPUT, /* you must provide more input bytes */
+ LZMA_STATUS_MAYBE_FINISHED_WITHOUT_MARK /* there is probability that stream was finished without end mark */
+} ELzmaStatus;
+
+/* ELzmaStatus is used only as output value for function call */
+
+
+/* ---------- Interfaces ---------- */
+
+/* There are 3 levels of interfaces:
+ 1) Dictionary Interface
+ 2) Buffer Interface
+ 3) One Call Interface
+ You can select any of these interfaces, but don't mix functions from different
+ groups for same object. */
+
+
+/* There are two variants to allocate state for Dictionary Interface:
+ 1) LzmaDec_Allocate / LzmaDec_Free
+ 2) LzmaDec_AllocateProbs / LzmaDec_FreeProbs
+ You can use variant 2, if you set dictionary buffer manually.
+ For Buffer Interface you must always use variant 1.
+
+LzmaDec_Allocate* can return:
+ SZ_OK
+ SZ_ERROR_MEM - Memory allocation error
+ SZ_ERROR_UNSUPPORTED - Unsupported properties
+*/
+
+SRes LzmaDec_AllocateProbs(CLzmaDec *p, const Byte *props, unsigned propsSize, ISzAlloc *alloc);
+void LzmaDec_FreeProbs(CLzmaDec *p, ISzAlloc *alloc);
+
+SRes LzmaDec_Allocate(CLzmaDec *state, const Byte *prop, unsigned propsSize, ISzAlloc *alloc);
+void LzmaDec_Free(CLzmaDec *state, ISzAlloc *alloc);
+
+/* ---------- Dictionary Interface ---------- */
+
+/* You can use it, if you want to eliminate the overhead for data copying from
+ dictionary to some other external buffer.
+ You must work with CLzmaDec variables directly in this interface.
+
+ STEPS:
+ LzmaDec_Constr()
+ LzmaDec_Allocate()
+ for (each new stream)
+ {
+ LzmaDec_Init()
+ while (it needs more decompression)
+ {
+ LzmaDec_DecodeToDic()
+ use data from CLzmaDec::dic and update CLzmaDec::dicPos
+ }
+ }
+ LzmaDec_Free()
+*/
+
+/* LzmaDec_DecodeToDic
+
+ The decoding to internal dictionary buffer (CLzmaDec::dic).
+ You must manually update CLzmaDec::dicPos, if it reaches CLzmaDec::dicBufSize !!!
+
+finishMode:
+ It has meaning only if the decoding reaches output limit (dicLimit).
+ LZMA_FINISH_ANY - Decode just dicLimit bytes.
+ LZMA_FINISH_END - Stream must be finished after dicLimit.
+
+Returns:
+ SZ_OK
+ status:
+ LZMA_STATUS_FINISHED_WITH_MARK
+ LZMA_STATUS_NOT_FINISHED
+ LZMA_STATUS_NEEDS_MORE_INPUT
+ LZMA_STATUS_MAYBE_FINISHED_WITHOUT_MARK
+ SZ_ERROR_DATA - Data error
+*/
+
+SRes LzmaDec_DecodeToDic(CLzmaDec *p, SizeT dicLimit,
+ const Byte *src, SizeT *srcLen, ELzmaFinishMode finishMode, ELzmaStatus *status);
+
+
+/* ---------- Buffer Interface ---------- */
+
+/* It's zlib-like interface.
+ See LzmaDec_DecodeToDic description for information about STEPS and return results,
+ but you must use LzmaDec_DecodeToBuf instead of LzmaDec_DecodeToDic and you don't need
+ to work with CLzmaDec variables manually.
+
+finishMode:
+ It has meaning only if the decoding reaches output limit (*destLen).
+ LZMA_FINISH_ANY - Decode just destLen bytes.
+ LZMA_FINISH_END - Stream must be finished after (*destLen).
+*/
+
+SRes LzmaDec_DecodeToBuf(CLzmaDec *p, Byte *dest, SizeT *destLen,
+ const Byte *src, SizeT *srcLen, ELzmaFinishMode finishMode, ELzmaStatus *status);
+
+
+/* ---------- One Call Interface ---------- */
+
+/* LzmaDecode
+
+finishMode:
+ It has meaning only if the decoding reaches output limit (*destLen).
+ LZMA_FINISH_ANY - Decode just destLen bytes.
+ LZMA_FINISH_END - Stream must be finished after (*destLen).
+
+Returns:
+ SZ_OK
+ status:
+ LZMA_STATUS_FINISHED_WITH_MARK
+ LZMA_STATUS_NOT_FINISHED
+ LZMA_STATUS_MAYBE_FINISHED_WITHOUT_MARK
+ SZ_ERROR_DATA - Data error
+ SZ_ERROR_MEM - Memory allocation error
+ SZ_ERROR_UNSUPPORTED - Unsupported properties
+ SZ_ERROR_INPUT_EOF - It needs more bytes in input buffer (src).
+*/
+
+SRes LzmaDecode(Byte *dest, SizeT *destLen, const Byte *src, SizeT *srcLen,
+ const Byte *propData, unsigned propSize, ELzmaFinishMode finishMode,
+ ELzmaStatus *status, ISzAlloc *alloc);
+
+#endif
diff --git a/C/LzmaEnc.c b/C/LzmaEnc.c
new file mode 100755
index 00000000..402e2742
--- /dev/null
+++ b/C/LzmaEnc.c
@@ -0,0 +1,2332 @@
+/* LzmaEnc.c -- LZMA Encoder
+2008-04-28
+Copyright (c) 1999-2008 Igor Pavlov
+Read LzmaEnc.h for license options */
+
+#include <stdio.h>
+#include <string.h>
+
+#include "LzmaEnc.h"
+
+#include "LzFind.h"
+#ifdef COMPRESS_MF_MT
+#include "LzFindMt.h"
+#endif
+
+/* #define SHOW_STAT */
+/* #define SHOW_STAT2 */
+
+#ifdef SHOW_STAT
+static int ttt = 0;
+#endif
+
+#define kBlockSizeMax ((1 << LZMA_NUM_BLOCK_SIZE_BITS) - 1)
+
+#define kBlockSize (9 << 10)
+#define kUnpackBlockSize (1 << 18)
+#define kMatchArraySize (1 << 21)
+#define kMatchRecordMaxSize ((LZMA_MATCH_LEN_MAX * 2 + 3) * LZMA_MATCH_LEN_MAX)
+
+#define kNumMaxDirectBits (31)
+
+#define kNumTopBits 24
+#define kTopValue ((UInt32)1 << kNumTopBits)
+
+#define kNumBitModelTotalBits 11
+#define kBitModelTotal (1 << kNumBitModelTotalBits)
+#define kNumMoveBits 5
+#define kProbInitValue (kBitModelTotal >> 1)
+
+#define kNumMoveReducingBits 4
+#define kNumBitPriceShiftBits 4
+#define kBitPrice (1 << kNumBitPriceShiftBits)
+
+void LzmaEncProps_Init(CLzmaEncProps *p)
+{
+ p->level = 5;
+ p->dictSize = p->mc = 0;
+ p->lc = p->lp = p->pb = p->algo = p->fb = p->btMode = p->numHashBytes = p->numThreads = -1;
+ p->writeEndMark = 0;
+}
+
+void LzmaEncProps_Normalize(CLzmaEncProps *p)
+{
+ int level = p->level;
+ if (level < 0) level = 5;
+ p->level = level;
+ if (p->dictSize == 0) p->dictSize = (level <= 5 ? (1 << (level * 2 + 14)) : (level == 6 ? (1 << 25) : (1 << 26)));
+ if (p->lc < 0) p->lc = 3;
+ if (p->lp < 0) p->lp = 0;
+ if (p->pb < 0) p->pb = 2;
+ if (p->algo < 0) p->algo = (level < 5 ? 0 : 1);
+ if (p->fb < 0) p->fb = (level < 7 ? 32 : 64);
+ if (p->btMode < 0) p->btMode = (p->algo == 0 ? 0 : 1);
+ if (p->numHashBytes < 0) p->numHashBytes = 4;
+ if (p->mc == 0) p->mc = (16 + (p->fb >> 1)) >> (p->btMode ? 0 : 1);
+ if (p->numThreads < 0) p->numThreads = ((p->btMode && p->algo) ? 2 : 1);
+}
+
+UInt32 LzmaEncProps_GetDictSize(const CLzmaEncProps *props2)
+{
+ CLzmaEncProps props = *props2;
+ LzmaEncProps_Normalize(&props);
+ return props.dictSize;
+}
+
+/* #define LZMA_LOG_BSR */
+/* Define it for Intel's CPU */
+
+
+#ifdef LZMA_LOG_BSR
+
+#define kDicLogSizeMaxCompress 30
+
+#define BSR2_RET(pos, res) { unsigned long i; _BitScanReverse(&i, (pos)); res = (i + i) + ((pos >> (i - 1)) & 1); }
+
+UInt32 GetPosSlot1(UInt32 pos)
+{
+ UInt32 res;
+ BSR2_RET(pos, res);
+ return res;
+}
+#define GetPosSlot2(pos, res) { BSR2_RET(pos, res); }
+#define GetPosSlot(pos, res) { if (pos < 2) res = pos; else BSR2_RET(pos, res); }
+
+#else
+
+#define kNumLogBits (9 + (int)sizeof(size_t) / 2)
+#define kDicLogSizeMaxCompress ((kNumLogBits - 1) * 2 + 7)
+
+void LzmaEnc_FastPosInit(Byte *g_FastPos)
+{
+ int c = 2, slotFast;
+ g_FastPos[0] = 0;
+ g_FastPos[1] = 1;
+
+ for (slotFast = 2; slotFast < kNumLogBits * 2; slotFast++)
+ {
+ UInt32 k = (1 << ((slotFast >> 1) - 1));
+ UInt32 j;
+ for (j = 0; j < k; j++, c++)
+ g_FastPos[c] = (Byte)slotFast;
+ }
+}
+
+#define BSR2_RET(pos, res) { UInt32 i = 6 + ((kNumLogBits - 1) & \
+ (0 - (((((UInt32)1 << (kNumLogBits + 6)) - 1) - pos) >> 31))); \
+ res = p->g_FastPos[pos >> i] + (i * 2); }
+/*
+#define BSR2_RET(pos, res) { res = (pos < (1 << (kNumLogBits + 6))) ? \
+ p->g_FastPos[pos >> 6] + 12 : \
+ p->g_FastPos[pos >> (6 + kNumLogBits - 1)] + (6 + (kNumLogBits - 1)) * 2; }
+*/
+
+#define GetPosSlot1(pos) p->g_FastPos[pos]
+#define GetPosSlot2(pos, res) { BSR2_RET(pos, res); }
+#define GetPosSlot(pos, res) { if (pos < kNumFullDistances) res = p->g_FastPos[pos]; else BSR2_RET(pos, res); }
+
+#endif
+
+
+#define LZMA_NUM_REPS 4
+
+typedef unsigned CState;
+
+typedef struct _COptimal
+{
+ UInt32 price;
+
+ CState state;
+ int prev1IsChar;
+ int prev2;
+
+ UInt32 posPrev2;
+ UInt32 backPrev2;
+
+ UInt32 posPrev;
+ UInt32 backPrev;
+ UInt32 backs[LZMA_NUM_REPS];
+} COptimal;
+
+#define kNumOpts (1 << 12)
+
+#define kNumLenToPosStates 4
+#define kNumPosSlotBits 6
+#define kDicLogSizeMin 0
+#define kDicLogSizeMax 32
+#define kDistTableSizeMax (kDicLogSizeMax * 2)
+
+
+#define kNumAlignBits 4
+#define kAlignTableSize (1 << kNumAlignBits)
+#define kAlignMask (kAlignTableSize - 1)
+
+#define kStartPosModelIndex 4
+#define kEndPosModelIndex 14
+#define kNumPosModels (kEndPosModelIndex - kStartPosModelIndex)
+
+#define kNumFullDistances (1 << (kEndPosModelIndex / 2))
+
+#ifdef _LZMA_PROB32
+#define CLzmaProb UInt32
+#else
+#define CLzmaProb UInt16
+#endif
+
+#define LZMA_PB_MAX 4
+#define LZMA_LC_MAX 8
+#define LZMA_LP_MAX 4
+
+#define LZMA_NUM_PB_STATES_MAX (1 << LZMA_PB_MAX)
+
+
+#define kLenNumLowBits 3
+#define kLenNumLowSymbols (1 << kLenNumLowBits)
+#define kLenNumMidBits 3
+#define kLenNumMidSymbols (1 << kLenNumMidBits)
+#define kLenNumHighBits 8
+#define kLenNumHighSymbols (1 << kLenNumHighBits)
+
+#define kLenNumSymbolsTotal (kLenNumLowSymbols + kLenNumMidSymbols + kLenNumHighSymbols)
+
+#define LZMA_MATCH_LEN_MIN 2
+#define LZMA_MATCH_LEN_MAX (LZMA_MATCH_LEN_MIN + kLenNumSymbolsTotal - 1)
+
+#define kNumStates 12
+
+typedef struct
+{
+ CLzmaProb choice;
+ CLzmaProb choice2;
+ CLzmaProb low[LZMA_NUM_PB_STATES_MAX << kLenNumLowBits];
+ CLzmaProb mid[LZMA_NUM_PB_STATES_MAX << kLenNumMidBits];
+ CLzmaProb high[kLenNumHighSymbols];
+} CLenEnc;
+
+typedef struct
+{
+ CLenEnc p;
+ UInt32 prices[LZMA_NUM_PB_STATES_MAX][kLenNumSymbolsTotal];
+ UInt32 tableSize;
+ UInt32 counters[LZMA_NUM_PB_STATES_MAX];
+} CLenPriceEnc;
+
+typedef struct _CRangeEnc
+{
+ UInt32 range;
+ Byte cache;
+ UInt64 low;
+ UInt64 cacheSize;
+ Byte *buf;
+ Byte *bufLim;
+ Byte *bufBase;
+ ISeqOutStream *outStream;
+ UInt64 processed;
+ SRes res;
+} CRangeEnc;
+
+typedef struct _CSeqInStreamBuf
+{
+ ISeqInStream funcTable;
+ const Byte *data;
+ SizeT rem;
+} CSeqInStreamBuf;
+
+static SRes MyRead(void *pp, void *data, size_t *size)
+{
+ size_t curSize = *size;
+ CSeqInStreamBuf *p = (CSeqInStreamBuf *)pp;
+ if (p->rem < curSize)
+ curSize = p->rem;
+ memcpy(data, p->data, curSize);
+ p->rem -= curSize;
+ p->data += curSize;
+ *size = curSize;
+ return SZ_OK;
+}
+
+typedef struct
+{
+ CLzmaProb *litProbs;
+
+ CLzmaProb isMatch[kNumStates][LZMA_NUM_PB_STATES_MAX];
+ CLzmaProb isRep[kNumStates];
+ CLzmaProb isRepG0[kNumStates];
+ CLzmaProb isRepG1[kNumStates];
+ CLzmaProb isRepG2[kNumStates];
+ CLzmaProb isRep0Long[kNumStates][LZMA_NUM_PB_STATES_MAX];
+
+ CLzmaProb posSlotEncoder[kNumLenToPosStates][1 << kNumPosSlotBits];
+ CLzmaProb posEncoders[kNumFullDistances - kEndPosModelIndex];
+ CLzmaProb posAlignEncoder[1 << kNumAlignBits];
+
+ CLenPriceEnc lenEnc;
+ CLenPriceEnc repLenEnc;
+
+ UInt32 reps[LZMA_NUM_REPS];
+ UInt32 state;
+} CSaveState;
+
+typedef struct _CLzmaEnc
+{
+ IMatchFinder matchFinder;
+ void *matchFinderObj;
+
+ #ifdef COMPRESS_MF_MT
+ Bool mtMode;
+ CMatchFinderMt matchFinderMt;
+ #endif
+
+ CMatchFinder matchFinderBase;
+
+ #ifdef COMPRESS_MF_MT
+ Byte pad[128];
+ #endif
+
+ UInt32 optimumEndIndex;
+ UInt32 optimumCurrentIndex;
+
+ Bool longestMatchWasFound;
+ UInt32 longestMatchLength;
+ UInt32 numDistancePairs;
+
+ COptimal opt[kNumOpts];
+
+ #ifndef LZMA_LOG_BSR
+ Byte g_FastPos[1 << kNumLogBits];
+ #endif
+
+ UInt32 ProbPrices[kBitModelTotal >> kNumMoveReducingBits];
+ UInt32 matchDistances[LZMA_MATCH_LEN_MAX * 2 + 2 + 1];
+ UInt32 numFastBytes;
+ UInt32 additionalOffset;
+ UInt32 reps[LZMA_NUM_REPS];
+ UInt32 state;
+
+ UInt32 posSlotPrices[kNumLenToPosStates][kDistTableSizeMax];
+ UInt32 distancesPrices[kNumLenToPosStates][kNumFullDistances];
+ UInt32 alignPrices[kAlignTableSize];
+ UInt32 alignPriceCount;
+
+ UInt32 distTableSize;
+
+ unsigned lc, lp, pb;
+ unsigned lpMask, pbMask;
+
+ CLzmaProb *litProbs;
+
+ CLzmaProb isMatch[kNumStates][LZMA_NUM_PB_STATES_MAX];
+ CLzmaProb isRep[kNumStates];
+ CLzmaProb isRepG0[kNumStates];
+ CLzmaProb isRepG1[kNumStates];
+ CLzmaProb isRepG2[kNumStates];
+ CLzmaProb isRep0Long[kNumStates][LZMA_NUM_PB_STATES_MAX];
+
+ CLzmaProb posSlotEncoder[kNumLenToPosStates][1 << kNumPosSlotBits];
+ CLzmaProb posEncoders[kNumFullDistances - kEndPosModelIndex];
+ CLzmaProb posAlignEncoder[1 << kNumAlignBits];
+
+ CLenPriceEnc lenEnc;
+ CLenPriceEnc repLenEnc;
+
+ unsigned lclp;
+
+ Bool fastMode;
+
+ CRangeEnc rc;
+
+ Bool writeEndMark;
+ UInt64 nowPos64;
+ UInt32 matchPriceCount;
+ Bool finished;
+ Bool multiThread;
+
+ SRes result;
+ UInt32 dictSize;
+ UInt32 matchFinderCycles;
+
+ ISeqInStream *inStream;
+ CSeqInStreamBuf seqBufInStream;
+
+ CSaveState saveState;
+} CLzmaEnc;
+
+void LzmaEnc_SaveState(CLzmaEncHandle pp)
+{
+ CLzmaEnc *p = (CLzmaEnc *)pp;
+ CSaveState *dest = &p->saveState;
+ int i;
+ dest->lenEnc = p->lenEnc;
+ dest->repLenEnc = p->repLenEnc;
+ dest->state = p->state;
+
+ for (i = 0; i < kNumStates; i++)
+ {
+ memcpy(dest->isMatch[i], p->isMatch[i], sizeof(p->isMatch[i]));
+ memcpy(dest->isRep0Long[i], p->isRep0Long[i], sizeof(p->isRep0Long[i]));
+ }
+ for (i = 0; i < kNumLenToPosStates; i++)
+ memcpy(dest->posSlotEncoder[i], p->posSlotEncoder[i], sizeof(p->posSlotEncoder[i]));
+ memcpy(dest->isRep, p->isRep, sizeof(p->isRep));
+ memcpy(dest->isRepG0, p->isRepG0, sizeof(p->isRepG0));
+ memcpy(dest->isRepG1, p->isRepG1, sizeof(p->isRepG1));
+ memcpy(dest->isRepG2, p->isRepG2, sizeof(p->isRepG2));
+ memcpy(dest->posEncoders, p->posEncoders, sizeof(p->posEncoders));
+ memcpy(dest->posAlignEncoder, p->posAlignEncoder, sizeof(p->posAlignEncoder));
+ memcpy(dest->reps, p->reps, sizeof(p->reps));
+ memcpy(dest->litProbs, p->litProbs, (0x300 << p->lclp) * sizeof(CLzmaProb));
+}
+
+void LzmaEnc_RestoreState(CLzmaEncHandle pp)
+{
+ CLzmaEnc *dest = (CLzmaEnc *)pp;
+ const CSaveState *p = &dest->saveState;
+ int i;
+ dest->lenEnc = p->lenEnc;
+ dest->repLenEnc = p->repLenEnc;
+ dest->state = p->state;
+
+ for (i = 0; i < kNumStates; i++)
+ {
+ memcpy(dest->isMatch[i], p->isMatch[i], sizeof(p->isMatch[i]));
+ memcpy(dest->isRep0Long[i], p->isRep0Long[i], sizeof(p->isRep0Long[i]));
+ }
+ for (i = 0; i < kNumLenToPosStates; i++)
+ memcpy(dest->posSlotEncoder[i], p->posSlotEncoder[i], sizeof(p->posSlotEncoder[i]));
+ memcpy(dest->isRep, p->isRep, sizeof(p->isRep));
+ memcpy(dest->isRepG0, p->isRepG0, sizeof(p->isRepG0));
+ memcpy(dest->isRepG1, p->isRepG1, sizeof(p->isRepG1));
+ memcpy(dest->isRepG2, p->isRepG2, sizeof(p->isRepG2));
+ memcpy(dest->posEncoders, p->posEncoders, sizeof(p->posEncoders));
+ memcpy(dest->posAlignEncoder, p->posAlignEncoder, sizeof(p->posAlignEncoder));
+ memcpy(dest->reps, p->reps, sizeof(p->reps));
+ memcpy(dest->litProbs, p->litProbs, (0x300 << dest->lclp) * sizeof(CLzmaProb));
+}
+
+SRes LzmaEnc_SetProps(CLzmaEncHandle pp, const CLzmaEncProps *props2)
+{
+ CLzmaEnc *p = (CLzmaEnc *)pp;
+ CLzmaEncProps props = *props2;
+ LzmaEncProps_Normalize(&props);
+
+ if (props.lc > LZMA_LC_MAX || props.lp > LZMA_LP_MAX || props.pb > LZMA_PB_MAX ||
+ props.dictSize > (1 << kDicLogSizeMaxCompress) || props.dictSize > (1 << 30))
+ return SZ_ERROR_PARAM;
+ p->dictSize = props.dictSize;
+ p->matchFinderCycles = props.mc;
+ {
+ unsigned fb = props.fb;
+ if (fb < 5)
+ fb = 5;
+ if (fb > LZMA_MATCH_LEN_MAX)
+ fb = LZMA_MATCH_LEN_MAX;
+ p->numFastBytes = fb;
+ }
+ p->lc = props.lc;
+ p->lp = props.lp;
+ p->pb = props.pb;
+ p->fastMode = (props.algo == 0);
+ p->matchFinderBase.btMode = props.btMode;
+ {
+ UInt32 numHashBytes = 4;
+ if (props.btMode)
+ {
+ if (props.numHashBytes < 2)
+ numHashBytes = 2;
+ else if (props.numHashBytes < 4)
+ numHashBytes = props.numHashBytes;
+ }
+ p->matchFinderBase.numHashBytes = numHashBytes;
+ }
+
+ p->matchFinderBase.cutValue = props.mc;
+
+ p->writeEndMark = props.writeEndMark;
+
+ #ifdef COMPRESS_MF_MT
+ /*
+ if (newMultiThread != _multiThread)
+ {
+ ReleaseMatchFinder();
+ _multiThread = newMultiThread;
+ }
+ */
+ p->multiThread = (props.numThreads > 1);
+ #endif
+
+ return SZ_OK;
+}
+
+static const int kLiteralNextStates[kNumStates] = {0, 0, 0, 0, 1, 2, 3, 4, 5, 6, 4, 5};
+static const int kMatchNextStates[kNumStates] = {7, 7, 7, 7, 7, 7, 7, 10, 10, 10, 10, 10};
+static const int kRepNextStates[kNumStates] = {8, 8, 8, 8, 8, 8, 8, 11, 11, 11, 11, 11};
+static const int kShortRepNextStates[kNumStates]= {9, 9, 9, 9, 9, 9, 9, 11, 11, 11, 11, 11};
+
+/*
+ void UpdateChar() { Index = kLiteralNextStates[Index]; }
+ void UpdateMatch() { Index = kMatchNextStates[Index]; }
+ void UpdateRep() { Index = kRepNextStates[Index]; }
+ void UpdateShortRep() { Index = kShortRepNextStates[Index]; }
+*/
+
+#define IsCharState(s) ((s) < 7)
+
+
+#define GetLenToPosState(len) (((len) < kNumLenToPosStates + 1) ? (len) - 2 : kNumLenToPosStates - 1)
+
+#define kInfinityPrice (1 << 30)
+
+static void RangeEnc_Construct(CRangeEnc *p)
+{
+ p->outStream = 0;
+ p->bufBase = 0;
+}
+
+#define RangeEnc_GetProcessed(p) ((p)->processed + ((p)->buf - (p)->bufBase) + (p)->cacheSize)
+
+#define RC_BUF_SIZE (1 << 16)
+static int RangeEnc_Alloc(CRangeEnc *p, ISzAlloc *alloc)
+{
+ if (p->bufBase == 0)
+ {
+ p->bufBase = (Byte *)alloc->Alloc(alloc, RC_BUF_SIZE);
+ if (p->bufBase == 0)
+ return 0;
+ p->bufLim = p->bufBase + RC_BUF_SIZE;
+ }
+ return 1;
+}
+
+static void RangeEnc_Free(CRangeEnc *p, ISzAlloc *alloc)
+{
+ alloc->Free(alloc, p->bufBase);
+ p->bufBase = 0;
+}
+
+static void RangeEnc_Init(CRangeEnc *p)
+{
+ /* Stream.Init(); */
+ p->low = 0;
+ p->range = 0xFFFFFFFF;
+ p->cacheSize = 1;
+ p->cache = 0;
+
+ p->buf = p->bufBase;
+
+ p->processed = 0;
+ p->res = SZ_OK;
+}
+
+static void RangeEnc_FlushStream(CRangeEnc *p)
+{
+ size_t num;
+ if (p->res != SZ_OK)
+ return;
+ num = p->buf - p->bufBase;
+ if (num != p->outStream->Write(p->outStream, p->bufBase, num))
+ p->res = SZ_ERROR_WRITE;
+ p->processed += num;
+ p->buf = p->bufBase;
+}
+
+static void MY_FAST_CALL RangeEnc_ShiftLow(CRangeEnc *p)
+{
+ if ((UInt32)p->low < (UInt32)0xFF000000 || (int)(p->low >> 32) != 0)
+ {
+ Byte temp = p->cache;
+ do
+ {
+ Byte *buf = p->buf;
+ *buf++ = (Byte)(temp + (Byte)(p->low >> 32));
+ p->buf = buf;
+ if (buf == p->bufLim)
+ RangeEnc_FlushStream(p);
+ temp = 0xFF;
+ }
+ while (--p->cacheSize != 0);
+ p->cache = (Byte)((UInt32)p->low >> 24);
+ }
+ p->cacheSize++;
+ p->low = (UInt32)p->low << 8;
+}
+
+static void RangeEnc_FlushData(CRangeEnc *p)
+{
+ int i;
+ for (i = 0; i < 5; i++)
+ RangeEnc_ShiftLow(p);
+}
+
+static void RangeEnc_EncodeDirectBits(CRangeEnc *p, UInt32 value, int numBits)
+{
+ do
+ {
+ p->range >>= 1;
+ p->low += p->range & (0 - ((value >> --numBits) & 1));
+ if (p->range < kTopValue)
+ {
+ p->range <<= 8;
+ RangeEnc_ShiftLow(p);
+ }
+ }
+ while (numBits != 0);
+}
+
+static void RangeEnc_EncodeBit(CRangeEnc *p, CLzmaProb *prob, UInt32 symbol)
+{
+ UInt32 ttt = *prob;
+ UInt32 newBound = (p->range >> kNumBitModelTotalBits) * ttt;
+ if (symbol == 0)
+ {
+ p->range = newBound;
+ ttt += (kBitModelTotal - ttt) >> kNumMoveBits;
+ }
+ else
+ {
+ p->low += newBound;
+ p->range -= newBound;
+ ttt -= ttt >> kNumMoveBits;
+ }
+ *prob = (CLzmaProb)ttt;
+ if (p->range < kTopValue)
+ {
+ p->range <<= 8;
+ RangeEnc_ShiftLow(p);
+ }
+}
+
+static void LitEnc_Encode(CRangeEnc *p, CLzmaProb *probs, UInt32 symbol)
+{
+ symbol |= 0x100;
+ do
+ {
+ RangeEnc_EncodeBit(p, probs + (symbol >> 8), (symbol >> 7) & 1);
+ symbol <<= 1;
+ }
+ while (symbol < 0x10000);
+}
+
+static void LitEnc_EncodeMatched(CRangeEnc *p, CLzmaProb *probs, UInt32 symbol, UInt32 matchByte)
+{
+ UInt32 offs = 0x100;
+ symbol |= 0x100;
+ do
+ {
+ matchByte <<= 1;
+ RangeEnc_EncodeBit(p, probs + (offs + (matchByte & offs) + (symbol >> 8)), (symbol >> 7) & 1);
+ symbol <<= 1;
+ offs &= ~(matchByte ^ symbol);
+ }
+ while (symbol < 0x10000);
+}
+
+void LzmaEnc_InitPriceTables(UInt32 *ProbPrices)
+{
+ UInt32 i;
+ for (i = (1 << kNumMoveReducingBits) / 2; i < kBitModelTotal; i += (1 << kNumMoveReducingBits))
+ {
+ const int kCyclesBits = kNumBitPriceShiftBits;
+ UInt32 w = i;
+ UInt32 bitCount = 0;
+ int j;
+ for (j = 0; j < kCyclesBits; j++)
+ {
+ w = w * w;
+ bitCount <<= 1;
+ while (w >= ((UInt32)1 << 16))
+ {
+ w >>= 1;
+ bitCount++;
+ }
+ }
+ ProbPrices[i >> kNumMoveReducingBits] = ((kNumBitModelTotalBits << kCyclesBits) - 15 - bitCount);
+ }
+}
+
+
+#define GET_PRICE(prob, symbol) \
+ p->ProbPrices[((prob) ^ (((-(int)(symbol))) & (kBitModelTotal - 1))) >> kNumMoveReducingBits];
+
+#define GET_PRICEa(prob, symbol) \
+ ProbPrices[((prob) ^ ((-((int)(symbol))) & (kBitModelTotal - 1))) >> kNumMoveReducingBits];
+
+#define GET_PRICE_0(prob) p->ProbPrices[(prob) >> kNumMoveReducingBits]
+#define GET_PRICE_1(prob) p->ProbPrices[((prob) ^ (kBitModelTotal - 1)) >> kNumMoveReducingBits]
+
+#define GET_PRICE_0a(prob) ProbPrices[(prob) >> kNumMoveReducingBits]
+#define GET_PRICE_1a(prob) ProbPrices[((prob) ^ (kBitModelTotal - 1)) >> kNumMoveReducingBits]
+
+static UInt32 LitEnc_GetPrice(const CLzmaProb *probs, UInt32 symbol, UInt32 *ProbPrices)
+{
+ UInt32 price = 0;
+ symbol |= 0x100;
+ do
+ {
+ price += GET_PRICEa(probs[symbol >> 8], (symbol >> 7) & 1);
+ symbol <<= 1;
+ }
+ while (symbol < 0x10000);
+ return price;
+};
+
+static UInt32 LitEnc_GetPriceMatched(const CLzmaProb *probs, UInt32 symbol, UInt32 matchByte, UInt32 *ProbPrices)
+{
+ UInt32 price = 0;
+ UInt32 offs = 0x100;
+ symbol |= 0x100;
+ do
+ {
+ matchByte <<= 1;
+ price += GET_PRICEa(probs[offs + (matchByte & offs) + (symbol >> 8)], (symbol >> 7) & 1);
+ symbol <<= 1;
+ offs &= ~(matchByte ^ symbol);
+ }
+ while (symbol < 0x10000);
+ return price;
+};
+
+
+static void RcTree_Encode(CRangeEnc *rc, CLzmaProb *probs, int numBitLevels, UInt32 symbol)
+{
+ UInt32 m = 1;
+ int i;
+ for (i = numBitLevels; i != 0 ;)
+ {
+ UInt32 bit;
+ i--;
+ bit = (symbol >> i) & 1;
+ RangeEnc_EncodeBit(rc, probs + m, bit);
+ m = (m << 1) | bit;
+ }
+};
+
+static void RcTree_ReverseEncode(CRangeEnc *rc, CLzmaProb *probs, int numBitLevels, UInt32 symbol)
+{
+ UInt32 m = 1;
+ int i;
+ for (i = 0; i < numBitLevels; i++)
+ {
+ UInt32 bit = symbol & 1;
+ RangeEnc_EncodeBit(rc, probs + m, bit);
+ m = (m << 1) | bit;
+ symbol >>= 1;
+ }
+}
+
+static UInt32 RcTree_GetPrice(const CLzmaProb *probs, int numBitLevels, UInt32 symbol, UInt32 *ProbPrices)
+{
+ UInt32 price = 0;
+ symbol |= (1 << numBitLevels);
+ while (symbol != 1)
+ {
+ price += GET_PRICEa(probs[symbol >> 1], symbol & 1);
+ symbol >>= 1;
+ }
+ return price;
+}
+
+static UInt32 RcTree_ReverseGetPrice(const CLzmaProb *probs, int numBitLevels, UInt32 symbol, UInt32 *ProbPrices)
+{
+ UInt32 price = 0;
+ UInt32 m = 1;
+ int i;
+ for (i = numBitLevels; i != 0; i--)
+ {
+ UInt32 bit = symbol & 1;
+ symbol >>= 1;
+ price += GET_PRICEa(probs[m], bit);
+ m = (m << 1) | bit;
+ }
+ return price;
+}
+
+
+static void LenEnc_Init(CLenEnc *p)
+{
+ unsigned i;
+ p->choice = p->choice2 = kProbInitValue;
+ for (i = 0; i < (LZMA_NUM_PB_STATES_MAX << kLenNumLowBits); i++)
+ p->low[i] = kProbInitValue;
+ for (i = 0; i < (LZMA_NUM_PB_STATES_MAX << kLenNumMidBits); i++)
+ p->mid[i] = kProbInitValue;
+ for (i = 0; i < kLenNumHighSymbols; i++)
+ p->high[i] = kProbInitValue;
+}
+
+static void LenEnc_Encode(CLenEnc *p, CRangeEnc *rc, UInt32 symbol, UInt32 posState)
+{
+ if (symbol < kLenNumLowSymbols)
+ {
+ RangeEnc_EncodeBit(rc, &p->choice, 0);
+ RcTree_Encode(rc, p->low + (posState << kLenNumLowBits), kLenNumLowBits, symbol);
+ }
+ else
+ {
+ RangeEnc_EncodeBit(rc, &p->choice, 1);
+ if (symbol < kLenNumLowSymbols + kLenNumMidSymbols)
+ {
+ RangeEnc_EncodeBit(rc, &p->choice2, 0);
+ RcTree_Encode(rc, p->mid + (posState << kLenNumMidBits), kLenNumMidBits, symbol - kLenNumLowSymbols);
+ }
+ else
+ {
+ RangeEnc_EncodeBit(rc, &p->choice2, 1);
+ RcTree_Encode(rc, p->high, kLenNumHighBits, symbol - kLenNumLowSymbols - kLenNumMidSymbols);
+ }
+ }
+}
+
+static void LenEnc_SetPrices(CLenEnc *p, UInt32 posState, UInt32 numSymbols, UInt32 *prices, UInt32 *ProbPrices)
+{
+ UInt32 a0 = GET_PRICE_0a(p->choice);
+ UInt32 a1 = GET_PRICE_1a(p->choice);
+ UInt32 b0 = a1 + GET_PRICE_0a(p->choice2);
+ UInt32 b1 = a1 + GET_PRICE_1a(p->choice2);
+ UInt32 i = 0;
+ for (i = 0; i < kLenNumLowSymbols; i++)
+ {
+ if (i >= numSymbols)
+ return;
+ prices[i] = a0 + RcTree_GetPrice(p->low + (posState << kLenNumLowBits), kLenNumLowBits, i, ProbPrices);
+ }
+ for (; i < kLenNumLowSymbols + kLenNumMidSymbols; i++)
+ {
+ if (i >= numSymbols)
+ return;
+ prices[i] = b0 + RcTree_GetPrice(p->mid + (posState << kLenNumMidBits), kLenNumMidBits, i - kLenNumLowSymbols, ProbPrices);
+ }
+ for (; i < numSymbols; i++)
+ prices[i] = b1 + RcTree_GetPrice(p->high, kLenNumHighBits, i - kLenNumLowSymbols - kLenNumMidSymbols, ProbPrices);
+}
+
+static void MY_FAST_CALL LenPriceEnc_UpdateTable(CLenPriceEnc *p, UInt32 posState, UInt32 *ProbPrices)
+{
+ LenEnc_SetPrices(&p->p, posState, p->tableSize, p->prices[posState], ProbPrices);
+ p->counters[posState] = p->tableSize;
+}
+
+static void LenPriceEnc_UpdateTables(CLenPriceEnc *p, UInt32 numPosStates, UInt32 *ProbPrices)
+{
+ UInt32 posState;
+ for (posState = 0; posState < numPosStates; posState++)
+ LenPriceEnc_UpdateTable(p, posState, ProbPrices);
+}
+
+static void LenEnc_Encode2(CLenPriceEnc *p, CRangeEnc *rc, UInt32 symbol, UInt32 posState, Bool updatePrice, UInt32 *ProbPrices)
+{
+ LenEnc_Encode(&p->p, rc, symbol, posState);
+ if (updatePrice)
+ if (--p->counters[posState] == 0)
+ LenPriceEnc_UpdateTable(p, posState, ProbPrices);
+}
+
+
+
+
+static void MovePos(CLzmaEnc *p, UInt32 num)
+{
+ #ifdef SHOW_STAT
+ ttt += num;
+ printf("\n MovePos %d", num);
+ #endif
+ if (num != 0)
+ {
+ p->additionalOffset += num;
+ p->matchFinder.Skip(p->matchFinderObj, num);
+ }
+}
+
+static UInt32 ReadMatchDistances(CLzmaEnc *p, UInt32 *numDistancePairsRes)
+{
+ UInt32 lenRes = 0, numDistancePairs;
+ numDistancePairs = p->matchFinder.GetMatches(p->matchFinderObj, p->matchDistances);
+ #ifdef SHOW_STAT
+ printf("\n i = %d numPairs = %d ", ttt, numDistancePairs / 2);
+ if (ttt >= 61994)
+ ttt = ttt;
+
+ ttt++;
+ {
+ UInt32 i;
+ for (i = 0; i < numDistancePairs; i += 2)
+ printf("%2d %6d | ", p->matchDistances[i], p->matchDistances[i + 1]);
+ }
+ #endif
+ if (numDistancePairs > 0)
+ {
+ lenRes = p->matchDistances[numDistancePairs - 2];
+ if (lenRes == p->numFastBytes)
+ {
+ UInt32 numAvail = p->matchFinder.GetNumAvailableBytes(p->matchFinderObj) + 1;
+ const Byte *pby = p->matchFinder.GetPointerToCurrentPos(p->matchFinderObj) - 1;
+ UInt32 distance = p->matchDistances[numDistancePairs - 1] + 1;
+ if (numAvail > LZMA_MATCH_LEN_MAX)
+ numAvail = LZMA_MATCH_LEN_MAX;
+
+ {
+ const Byte *pby2 = pby - distance;
+ for (; lenRes < numAvail && pby[lenRes] == pby2[lenRes]; lenRes++);
+ }
+ }
+ }
+ p->additionalOffset++;
+ *numDistancePairsRes = numDistancePairs;
+ return lenRes;
+}
+
+
+#define MakeAsChar(p) (p)->backPrev = (UInt32)(-1); (p)->prev1IsChar = False;
+#define MakeAsShortRep(p) (p)->backPrev = 0; (p)->prev1IsChar = False;
+#define IsShortRep(p) ((p)->backPrev == 0)
+
+static UInt32 GetRepLen1Price(CLzmaEnc *p, UInt32 state, UInt32 posState)
+{
+ return
+ GET_PRICE_0(p->isRepG0[state]) +
+ GET_PRICE_0(p->isRep0Long[state][posState]);
+}
+
+static UInt32 GetPureRepPrice(CLzmaEnc *p, UInt32 repIndex, UInt32 state, UInt32 posState)
+{
+ UInt32 price;
+ if (repIndex == 0)
+ {
+ price = GET_PRICE_0(p->isRepG0[state]);
+ price += GET_PRICE_1(p->isRep0Long[state][posState]);
+ }
+ else
+ {
+ price = GET_PRICE_1(p->isRepG0[state]);
+ if (repIndex == 1)
+ price += GET_PRICE_0(p->isRepG1[state]);
+ else
+ {
+ price += GET_PRICE_1(p->isRepG1[state]);
+ price += GET_PRICE(p->isRepG2[state], repIndex - 2);
+ }
+ }
+ return price;
+}
+
+static UInt32 GetRepPrice(CLzmaEnc *p, UInt32 repIndex, UInt32 len, UInt32 state, UInt32 posState)
+{
+ return p->repLenEnc.prices[posState][len - LZMA_MATCH_LEN_MIN] +
+ GetPureRepPrice(p, repIndex, state, posState);
+}
+
+static UInt32 Backward(CLzmaEnc *p, UInt32 *backRes, UInt32 cur)
+{
+ UInt32 posMem = p->opt[cur].posPrev;
+ UInt32 backMem = p->opt[cur].backPrev;
+ p->optimumEndIndex = cur;
+ do
+ {
+ if (p->opt[cur].prev1IsChar)
+ {
+ MakeAsChar(&p->opt[posMem])
+ p->opt[posMem].posPrev = posMem - 1;
+ if (p->opt[cur].prev2)
+ {
+ p->opt[posMem - 1].prev1IsChar = False;
+ p->opt[posMem - 1].posPrev = p->opt[cur].posPrev2;
+ p->opt[posMem - 1].backPrev = p->opt[cur].backPrev2;
+ }
+ }
+ {
+ UInt32 posPrev = posMem;
+ UInt32 backCur = backMem;
+
+ backMem = p->opt[posPrev].backPrev;
+ posMem = p->opt[posPrev].posPrev;
+
+ p->opt[posPrev].backPrev = backCur;
+ p->opt[posPrev].posPrev = cur;
+ cur = posPrev;
+ }
+ }
+ while (cur != 0);
+ *backRes = p->opt[0].backPrev;
+ p->optimumCurrentIndex = p->opt[0].posPrev;
+ return p->optimumCurrentIndex;
+}
+
+#define LIT_PROBS(pos, prevByte) (p->litProbs + ((((pos) & p->lpMask) << p->lc) + ((prevByte) >> (8 - p->lc))) * 0x300)
+
+static UInt32 GetOptimum(CLzmaEnc *p, UInt32 position, UInt32 *backRes)
+{
+ UInt32 numAvailableBytes, lenMain, numDistancePairs;
+ const Byte *data;
+ UInt32 reps[LZMA_NUM_REPS];
+ UInt32 repLens[LZMA_NUM_REPS];
+ UInt32 repMaxIndex, i;
+ UInt32 *matchDistances;
+ Byte currentByte, matchByte;
+ UInt32 posState;
+ UInt32 matchPrice, repMatchPrice;
+ UInt32 lenEnd;
+ UInt32 len;
+ UInt32 normalMatchPrice;
+ UInt32 cur;
+ if (p->optimumEndIndex != p->optimumCurrentIndex)
+ {
+ const COptimal *opt = &p->opt[p->optimumCurrentIndex];
+ UInt32 lenRes = opt->posPrev - p->optimumCurrentIndex;
+ *backRes = opt->backPrev;
+ p->optimumCurrentIndex = opt->posPrev;
+ return lenRes;
+ }
+ p->optimumCurrentIndex = p->optimumEndIndex = 0;
+
+ numAvailableBytes = p->matchFinder.GetNumAvailableBytes(p->matchFinderObj);
+
+ if (!p->longestMatchWasFound)
+ {
+ lenMain = ReadMatchDistances(p, &numDistancePairs);
+ }
+ else
+ {
+ lenMain = p->longestMatchLength;
+ numDistancePairs = p->numDistancePairs;
+ p->longestMatchWasFound = False;
+ }
+
+ data = p->matchFinder.GetPointerToCurrentPos(p->matchFinderObj) - 1;
+ if (numAvailableBytes < 2)
+ {
+ *backRes = (UInt32)(-1);
+ return 1;
+ }
+ if (numAvailableBytes > LZMA_MATCH_LEN_MAX)
+ numAvailableBytes = LZMA_MATCH_LEN_MAX;
+
+ repMaxIndex = 0;
+ for (i = 0; i < LZMA_NUM_REPS; i++)
+ {
+ UInt32 lenTest;
+ const Byte *data2;
+ reps[i] = p->reps[i];
+ data2 = data - (reps[i] + 1);
+ if (data[0] != data2[0] || data[1] != data2[1])
+ {
+ repLens[i] = 0;
+ continue;
+ }
+ for (lenTest = 2; lenTest < numAvailableBytes && data[lenTest] == data2[lenTest]; lenTest++);
+ repLens[i] = lenTest;
+ if (lenTest > repLens[repMaxIndex])
+ repMaxIndex = i;
+ }
+ if (repLens[repMaxIndex] >= p->numFastBytes)
+ {
+ UInt32 lenRes;
+ *backRes = repMaxIndex;
+ lenRes = repLens[repMaxIndex];
+ MovePos(p, lenRes - 1);
+ return lenRes;
+ }
+
+ matchDistances = p->matchDistances;
+ if (lenMain >= p->numFastBytes)
+ {
+ *backRes = matchDistances[numDistancePairs - 1] + LZMA_NUM_REPS;
+ MovePos(p, lenMain - 1);
+ return lenMain;
+ }
+ currentByte = *data;
+ matchByte = *(data - (reps[0] + 1));
+
+ if (lenMain < 2 && currentByte != matchByte && repLens[repMaxIndex] < 2)
+ {
+ *backRes = (UInt32)-1;
+ return 1;
+ }
+
+ p->opt[0].state = (CState)p->state;
+
+ posState = (position & p->pbMask);
+
+ {
+ const CLzmaProb *probs = LIT_PROBS(position, *(data - 1));
+ p->opt[1].price = GET_PRICE_0(p->isMatch[p->state][posState]) +
+ (!IsCharState(p->state) ?
+ LitEnc_GetPriceMatched(probs, currentByte, matchByte, p->ProbPrices) :
+ LitEnc_GetPrice(probs, currentByte, p->ProbPrices));
+ }
+
+ MakeAsChar(&p->opt[1]);
+
+ matchPrice = GET_PRICE_1(p->isMatch[p->state][posState]);
+ repMatchPrice = matchPrice + GET_PRICE_1(p->isRep[p->state]);
+
+ if (matchByte == currentByte)
+ {
+ UInt32 shortRepPrice = repMatchPrice + GetRepLen1Price(p, p->state, posState);
+ if (shortRepPrice < p->opt[1].price)
+ {
+ p->opt[1].price = shortRepPrice;
+ MakeAsShortRep(&p->opt[1]);
+ }
+ }
+ lenEnd = ((lenMain >= repLens[repMaxIndex]) ? lenMain : repLens[repMaxIndex]);
+
+ if (lenEnd < 2)
+ {
+ *backRes = p->opt[1].backPrev;
+ return 1;
+ }
+
+ p->opt[1].posPrev = 0;
+ for (i = 0; i < LZMA_NUM_REPS; i++)
+ p->opt[0].backs[i] = reps[i];
+
+ len = lenEnd;
+ do
+ p->opt[len--].price = kInfinityPrice;
+ while (len >= 2);
+
+ for (i = 0; i < LZMA_NUM_REPS; i++)
+ {
+ UInt32 repLen = repLens[i];
+ UInt32 price;
+ if (repLen < 2)
+ continue;
+ price = repMatchPrice + GetPureRepPrice(p, i, p->state, posState);
+ do
+ {
+ UInt32 curAndLenPrice = price + p->repLenEnc.prices[posState][repLen - 2];
+ COptimal *opt = &p->opt[repLen];
+ if (curAndLenPrice < opt->price)
+ {
+ opt->price = curAndLenPrice;
+ opt->posPrev = 0;
+ opt->backPrev = i;
+ opt->prev1IsChar = False;
+ }
+ }
+ while (--repLen >= 2);
+ }
+
+ normalMatchPrice = matchPrice + GET_PRICE_0(p->isRep[p->state]);
+
+ len = ((repLens[0] >= 2) ? repLens[0] + 1 : 2);
+ if (len <= lenMain)
+ {
+ UInt32 offs = 0;
+ while (len > matchDistances[offs])
+ offs += 2;
+ for (; ; len++)
+ {
+ COptimal *opt;
+ UInt32 distance = matchDistances[offs + 1];
+
+ UInt32 curAndLenPrice = normalMatchPrice + p->lenEnc.prices[posState][len - LZMA_MATCH_LEN_MIN];
+ UInt32 lenToPosState = GetLenToPosState(len);
+ if (distance < kNumFullDistances)
+ curAndLenPrice += p->distancesPrices[lenToPosState][distance];
+ else
+ {
+ UInt32 slot;
+ GetPosSlot2(distance, slot);
+ curAndLenPrice += p->alignPrices[distance & kAlignMask] + p->posSlotPrices[lenToPosState][slot];
+ }
+ opt = &p->opt[len];
+ if (curAndLenPrice < opt->price)
+ {
+ opt->price = curAndLenPrice;
+ opt->posPrev = 0;
+ opt->backPrev = distance + LZMA_NUM_REPS;
+ opt->prev1IsChar = False;
+ }
+ if (len == matchDistances[offs])
+ {
+ offs += 2;
+ if (offs == numDistancePairs)
+ break;
+ }
+ }
+ }
+
+ cur = 0;
+
+ #ifdef SHOW_STAT2
+ if (position >= 0)
+ {
+ unsigned i;
+ printf("\n pos = %4X", position);
+ for (i = cur; i <= lenEnd; i++)
+ printf("\nprice[%4X] = %d", position - cur + i, p->opt[i].price);
+ }
+ #endif
+
+ for (;;)
+ {
+ UInt32 numAvailableBytesFull, newLen, numDistancePairs;
+ COptimal *curOpt;
+ UInt32 posPrev;
+ UInt32 state;
+ UInt32 curPrice;
+ Bool nextIsChar;
+ const Byte *data;
+ Byte currentByte, matchByte;
+ UInt32 posState;
+ UInt32 curAnd1Price;
+ COptimal *nextOpt;
+ UInt32 matchPrice, repMatchPrice;
+ UInt32 numAvailableBytes;
+ UInt32 startLen;
+
+ cur++;
+ if (cur == lenEnd)
+ return Backward(p, backRes, cur);
+
+ numAvailableBytesFull = p->matchFinder.GetNumAvailableBytes(p->matchFinderObj);
+ newLen = ReadMatchDistances(p, &numDistancePairs);
+ if (newLen >= p->numFastBytes)
+ {
+ p->numDistancePairs = numDistancePairs;
+ p->longestMatchLength = newLen;
+ p->longestMatchWasFound = True;
+ return Backward(p, backRes, cur);
+ }
+ position++;
+ curOpt = &p->opt[cur];
+ posPrev = curOpt->posPrev;
+ if (curOpt->prev1IsChar)
+ {
+ posPrev--;
+ if (curOpt->prev2)
+ {
+ state = p->opt[curOpt->posPrev2].state;
+ if (curOpt->backPrev2 < LZMA_NUM_REPS)
+ state = kRepNextStates[state];
+ else
+ state = kMatchNextStates[state];
+ }
+ else
+ state = p->opt[posPrev].state;
+ state = kLiteralNextStates[state];
+ }
+ else
+ state = p->opt[posPrev].state;
+ if (posPrev == cur - 1)
+ {
+ if (IsShortRep(curOpt))
+ state = kShortRepNextStates[state];
+ else
+ state = kLiteralNextStates[state];
+ }
+ else
+ {
+ UInt32 pos;
+ const COptimal *prevOpt;
+ if (curOpt->prev1IsChar && curOpt->prev2)
+ {
+ posPrev = curOpt->posPrev2;
+ pos = curOpt->backPrev2;
+ state = kRepNextStates[state];
+ }
+ else
+ {
+ pos = curOpt->backPrev;
+ if (pos < LZMA_NUM_REPS)
+ state = kRepNextStates[state];
+ else
+ state = kMatchNextStates[state];
+ }
+ prevOpt = &p->opt[posPrev];
+ if (pos < LZMA_NUM_REPS)
+ {
+ UInt32 i;
+ reps[0] = prevOpt->backs[pos];
+ for (i = 1; i <= pos; i++)
+ reps[i] = prevOpt->backs[i - 1];
+ for (; i < LZMA_NUM_REPS; i++)
+ reps[i] = prevOpt->backs[i];
+ }
+ else
+ {
+ UInt32 i;
+ reps[0] = (pos - LZMA_NUM_REPS);
+ for (i = 1; i < LZMA_NUM_REPS; i++)
+ reps[i] = prevOpt->backs[i - 1];
+ }
+ }
+ curOpt->state = (CState)state;
+
+ curOpt->backs[0] = reps[0];
+ curOpt->backs[1] = reps[1];
+ curOpt->backs[2] = reps[2];
+ curOpt->backs[3] = reps[3];
+
+ curPrice = curOpt->price;
+ nextIsChar = False;
+ data = p->matchFinder.GetPointerToCurrentPos(p->matchFinderObj) - 1;
+ currentByte = *data;
+ matchByte = *(data - (reps[0] + 1));
+
+ posState = (position & p->pbMask);
+
+ curAnd1Price = curPrice + GET_PRICE_0(p->isMatch[state][posState]);
+ {
+ const CLzmaProb *probs = LIT_PROBS(position, *(data - 1));
+ curAnd1Price +=
+ (!IsCharState(state) ?
+ LitEnc_GetPriceMatched(probs, currentByte, matchByte, p->ProbPrices) :
+ LitEnc_GetPrice(probs, currentByte, p->ProbPrices));
+ }
+
+ nextOpt = &p->opt[cur + 1];
+
+ if (curAnd1Price < nextOpt->price)
+ {
+ nextOpt->price = curAnd1Price;
+ nextOpt->posPrev = cur;
+ MakeAsChar(nextOpt);
+ nextIsChar = True;
+ }
+
+ matchPrice = curPrice + GET_PRICE_1(p->isMatch[state][posState]);
+ repMatchPrice = matchPrice + GET_PRICE_1(p->isRep[state]);
+
+ if (matchByte == currentByte && !(nextOpt->posPrev < cur && nextOpt->backPrev == 0))
+ {
+ UInt32 shortRepPrice = repMatchPrice + GetRepLen1Price(p, state, posState);
+ if (shortRepPrice <= nextOpt->price)
+ {
+ nextOpt->price = shortRepPrice;
+ nextOpt->posPrev = cur;
+ MakeAsShortRep(nextOpt);
+ nextIsChar = True;
+ }
+ }
+
+ {
+ UInt32 temp = kNumOpts - 1 - cur;
+ if (temp < numAvailableBytesFull)
+ numAvailableBytesFull = temp;
+ }
+ numAvailableBytes = numAvailableBytesFull;
+
+ if (numAvailableBytes < 2)
+ continue;
+ if (numAvailableBytes > p->numFastBytes)
+ numAvailableBytes = p->numFastBytes;
+ if (!nextIsChar && matchByte != currentByte) /* speed optimization */
+ {
+ /* try Literal + rep0 */
+ UInt32 temp;
+ UInt32 lenTest2;
+ const Byte *data2 = data - (reps[0] + 1);
+ UInt32 limit = p->numFastBytes + 1;
+ if (limit > numAvailableBytesFull)
+ limit = numAvailableBytesFull;
+
+ for (temp = 1; temp < limit && data[temp] == data2[temp]; temp++);
+ lenTest2 = temp - 1;
+ if (lenTest2 >= 2)
+ {
+ UInt32 state2 = kLiteralNextStates[state];
+ UInt32 posStateNext = (position + 1) & p->pbMask;
+ UInt32 nextRepMatchPrice = curAnd1Price +
+ GET_PRICE_1(p->isMatch[state2][posStateNext]) +
+ GET_PRICE_1(p->isRep[state2]);
+ /* for (; lenTest2 >= 2; lenTest2--) */
+ {
+ UInt32 curAndLenPrice;
+ COptimal *opt;
+ UInt32 offset = cur + 1 + lenTest2;
+ while (lenEnd < offset)
+ p->opt[++lenEnd].price = kInfinityPrice;
+ curAndLenPrice = nextRepMatchPrice + GetRepPrice(p, 0, lenTest2, state2, posStateNext);
+ opt = &p->opt[offset];
+ if (curAndLenPrice < opt->price)
+ {
+ opt->price = curAndLenPrice;
+ opt->posPrev = cur + 1;
+ opt->backPrev = 0;
+ opt->prev1IsChar = True;
+ opt->prev2 = False;
+ }
+ }
+ }
+ }
+
+ startLen = 2; /* speed optimization */
+ {
+ UInt32 repIndex;
+ for (repIndex = 0; repIndex < LZMA_NUM_REPS; repIndex++)
+ {
+ UInt32 lenTest;
+ UInt32 lenTestTemp;
+ UInt32 price;
+ const Byte *data2 = data - (reps[repIndex] + 1);
+ if (data[0] != data2[0] || data[1] != data2[1])
+ continue;
+ for (lenTest = 2; lenTest < numAvailableBytes && data[lenTest] == data2[lenTest]; lenTest++);
+ while (lenEnd < cur + lenTest)
+ p->opt[++lenEnd].price = kInfinityPrice;
+ lenTestTemp = lenTest;
+ price = repMatchPrice + GetPureRepPrice(p, repIndex, state, posState);
+ do
+ {
+ UInt32 curAndLenPrice = price + p->repLenEnc.prices[posState][lenTest - 2];
+ COptimal *opt = &p->opt[cur + lenTest];
+ if (curAndLenPrice < opt->price)
+ {
+ opt->price = curAndLenPrice;
+ opt->posPrev = cur;
+ opt->backPrev = repIndex;
+ opt->prev1IsChar = False;
+ }
+ }
+ while (--lenTest >= 2);
+ lenTest = lenTestTemp;
+
+ if (repIndex == 0)
+ startLen = lenTest + 1;
+
+ /* if (_maxMode) */
+ {
+ UInt32 lenTest2 = lenTest + 1;
+ UInt32 limit = lenTest2 + p->numFastBytes;
+ UInt32 nextRepMatchPrice;
+ if (limit > numAvailableBytesFull)
+ limit = numAvailableBytesFull;
+ for (; lenTest2 < limit && data[lenTest2] == data2[lenTest2]; lenTest2++);
+ lenTest2 -= lenTest + 1;
+ if (lenTest2 >= 2)
+ {
+ UInt32 state2 = kRepNextStates[state];
+ UInt32 posStateNext = (position + lenTest) & p->pbMask;
+ UInt32 curAndLenCharPrice =
+ price + p->repLenEnc.prices[posState][lenTest - 2] +
+ GET_PRICE_0(p->isMatch[state2][posStateNext]) +
+ LitEnc_GetPriceMatched(LIT_PROBS(position + lenTest, data[lenTest - 1]),
+ data[lenTest], data2[lenTest], p->ProbPrices);
+ state2 = kLiteralNextStates[state2];
+ posStateNext = (position + lenTest + 1) & p->pbMask;
+ nextRepMatchPrice = curAndLenCharPrice +
+ GET_PRICE_1(p->isMatch[state2][posStateNext]) +
+ GET_PRICE_1(p->isRep[state2]);
+
+ /* for (; lenTest2 >= 2; lenTest2--) */
+ {
+ UInt32 curAndLenPrice;
+ COptimal *opt;
+ UInt32 offset = cur + lenTest + 1 + lenTest2;
+ while (lenEnd < offset)
+ p->opt[++lenEnd].price = kInfinityPrice;
+ curAndLenPrice = nextRepMatchPrice + GetRepPrice(p, 0, lenTest2, state2, posStateNext);
+ opt = &p->opt[offset];
+ if (curAndLenPrice < opt->price)
+ {
+ opt->price = curAndLenPrice;
+ opt->posPrev = cur + lenTest + 1;
+ opt->backPrev = 0;
+ opt->prev1IsChar = True;
+ opt->prev2 = True;
+ opt->posPrev2 = cur;
+ opt->backPrev2 = repIndex;
+ }
+ }
+ }
+ }
+ }
+ }
+ /* for (UInt32 lenTest = 2; lenTest <= newLen; lenTest++) */
+ if (newLen > numAvailableBytes)
+ {
+ newLen = numAvailableBytes;
+ for (numDistancePairs = 0; newLen > matchDistances[numDistancePairs]; numDistancePairs += 2);
+ matchDistances[numDistancePairs] = newLen;
+ numDistancePairs += 2;
+ }
+ if (newLen >= startLen)
+ {
+ UInt32 normalMatchPrice = matchPrice + GET_PRICE_0(p->isRep[state]);
+ UInt32 offs, curBack, posSlot;
+ UInt32 lenTest;
+ while (lenEnd < cur + newLen)
+ p->opt[++lenEnd].price = kInfinityPrice;
+
+ offs = 0;
+ while (startLen > matchDistances[offs])
+ offs += 2;
+ curBack = matchDistances[offs + 1];
+ GetPosSlot2(curBack, posSlot);
+ for (lenTest = /*2*/ startLen; ; lenTest++)
+ {
+ UInt32 curAndLenPrice = normalMatchPrice + p->lenEnc.prices[posState][lenTest - LZMA_MATCH_LEN_MIN];
+ UInt32 lenToPosState = GetLenToPosState(lenTest);
+ COptimal *opt;
+ if (curBack < kNumFullDistances)
+ curAndLenPrice += p->distancesPrices[lenToPosState][curBack];
+ else
+ curAndLenPrice += p->posSlotPrices[lenToPosState][posSlot] + p->alignPrices[curBack & kAlignMask];
+
+ opt = &p->opt[cur + lenTest];
+ if (curAndLenPrice < opt->price)
+ {
+ opt->price = curAndLenPrice;
+ opt->posPrev = cur;
+ opt->backPrev = curBack + LZMA_NUM_REPS;
+ opt->prev1IsChar = False;
+ }
+
+ if (/*_maxMode && */lenTest == matchDistances[offs])
+ {
+ /* Try Match + Literal + Rep0 */
+ const Byte *data2 = data - (curBack + 1);
+ UInt32 lenTest2 = lenTest + 1;
+ UInt32 limit = lenTest2 + p->numFastBytes;
+ UInt32 nextRepMatchPrice;
+ if (limit > numAvailableBytesFull)
+ limit = numAvailableBytesFull;
+ for (; lenTest2 < limit && data[lenTest2] == data2[lenTest2]; lenTest2++);
+ lenTest2 -= lenTest + 1;
+ if (lenTest2 >= 2)
+ {
+ UInt32 state2 = kMatchNextStates[state];
+ UInt32 posStateNext = (position + lenTest) & p->pbMask;
+ UInt32 curAndLenCharPrice = curAndLenPrice +
+ GET_PRICE_0(p->isMatch[state2][posStateNext]) +
+ LitEnc_GetPriceMatched(LIT_PROBS(position + lenTest, data[lenTest - 1]),
+ data[lenTest], data2[lenTest], p->ProbPrices);
+ state2 = kLiteralNextStates[state2];
+ posStateNext = (posStateNext + 1) & p->pbMask;
+ nextRepMatchPrice = curAndLenCharPrice +
+ GET_PRICE_1(p->isMatch[state2][posStateNext]) +
+ GET_PRICE_1(p->isRep[state2]);
+
+ /* for (; lenTest2 >= 2; lenTest2--) */
+ {
+ UInt32 offset = cur + lenTest + 1 + lenTest2;
+ UInt32 curAndLenPrice;
+ COptimal *opt;
+ while (lenEnd < offset)
+ p->opt[++lenEnd].price = kInfinityPrice;
+ curAndLenPrice = nextRepMatchPrice + GetRepPrice(p, 0, lenTest2, state2, posStateNext);
+ opt = &p->opt[offset];
+ if (curAndLenPrice < opt->price)
+ {
+ opt->price = curAndLenPrice;
+ opt->posPrev = cur + lenTest + 1;
+ opt->backPrev = 0;
+ opt->prev1IsChar = True;
+ opt->prev2 = True;
+ opt->posPrev2 = cur;
+ opt->backPrev2 = curBack + LZMA_NUM_REPS;
+ }
+ }
+ }
+ offs += 2;
+ if (offs == numDistancePairs)
+ break;
+ curBack = matchDistances[offs + 1];
+ if (curBack >= kNumFullDistances)
+ GetPosSlot2(curBack, posSlot);
+ }
+ }
+ }
+ }
+}
+
+#define ChangePair(smallDist, bigDist) (((bigDist) >> 7) > (smallDist))
+
+static UInt32 GetOptimumFast(CLzmaEnc *p, UInt32 *backRes)
+{
+ UInt32 numAvailableBytes = p->matchFinder.GetNumAvailableBytes(p->matchFinderObj);
+ UInt32 lenMain, numDistancePairs;
+ const Byte *data;
+ UInt32 repLens[LZMA_NUM_REPS];
+ UInt32 repMaxIndex, i;
+ UInt32 *matchDistances;
+ UInt32 backMain;
+
+ if (!p->longestMatchWasFound)
+ {
+ lenMain = ReadMatchDistances(p, &numDistancePairs);
+ }
+ else
+ {
+ lenMain = p->longestMatchLength;
+ numDistancePairs = p->numDistancePairs;
+ p->longestMatchWasFound = False;
+ }
+
+ data = p->matchFinder.GetPointerToCurrentPos(p->matchFinderObj) - 1;
+ if (numAvailableBytes > LZMA_MATCH_LEN_MAX)
+ numAvailableBytes = LZMA_MATCH_LEN_MAX;
+ if (numAvailableBytes < 2)
+ {
+ *backRes = (UInt32)(-1);
+ return 1;
+ }
+
+ repMaxIndex = 0;
+
+ for (i = 0; i < LZMA_NUM_REPS; i++)
+ {
+ const Byte *data2 = data - (p->reps[i] + 1);
+ UInt32 len;
+ if (data[0] != data2[0] || data[1] != data2[1])
+ {
+ repLens[i] = 0;
+ continue;
+ }
+ for (len = 2; len < numAvailableBytes && data[len] == data2[len]; len++);
+ if (len >= p->numFastBytes)
+ {
+ *backRes = i;
+ MovePos(p, len - 1);
+ return len;
+ }
+ repLens[i] = len;
+ if (len > repLens[repMaxIndex])
+ repMaxIndex = i;
+ }
+ matchDistances = p->matchDistances;
+ if (lenMain >= p->numFastBytes)
+ {
+ *backRes = matchDistances[numDistancePairs - 1] + LZMA_NUM_REPS;
+ MovePos(p, lenMain - 1);
+ return lenMain;
+ }
+
+ backMain = 0; /* for GCC */
+ if (lenMain >= 2)
+ {
+ backMain = matchDistances[numDistancePairs - 1];
+ while (numDistancePairs > 2 && lenMain == matchDistances[numDistancePairs - 4] + 1)
+ {
+ if (!ChangePair(matchDistances[numDistancePairs - 3], backMain))
+ break;
+ numDistancePairs -= 2;
+ lenMain = matchDistances[numDistancePairs - 2];
+ backMain = matchDistances[numDistancePairs - 1];
+ }
+ if (lenMain == 2 && backMain >= 0x80)
+ lenMain = 1;
+ }
+
+ if (repLens[repMaxIndex] >= 2)
+ {
+ if (repLens[repMaxIndex] + 1 >= lenMain ||
+ (repLens[repMaxIndex] + 2 >= lenMain && (backMain > (1 << 9))) ||
+ (repLens[repMaxIndex] + 3 >= lenMain && (backMain > (1 << 15))))
+ {
+ UInt32 lenRes;
+ *backRes = repMaxIndex;
+ lenRes = repLens[repMaxIndex];
+ MovePos(p, lenRes - 1);
+ return lenRes;
+ }
+ }
+
+ if (lenMain >= 2 && numAvailableBytes > 2)
+ {
+ UInt32 i;
+ numAvailableBytes = p->matchFinder.GetNumAvailableBytes(p->matchFinderObj);
+ p->longestMatchLength = ReadMatchDistances(p, &p->numDistancePairs);
+ if (p->longestMatchLength >= 2)
+ {
+ UInt32 newDistance = matchDistances[p->numDistancePairs - 1];
+ if ((p->longestMatchLength >= lenMain && newDistance < backMain) ||
+ (p->longestMatchLength == lenMain + 1 && !ChangePair(backMain, newDistance)) ||
+ (p->longestMatchLength > lenMain + 1) ||
+ (p->longestMatchLength + 1 >= lenMain && lenMain >= 3 && ChangePair(newDistance, backMain)))
+ {
+ p->longestMatchWasFound = True;
+ *backRes = (UInt32)(-1);
+ return 1;
+ }
+ }
+ data = p->matchFinder.GetPointerToCurrentPos(p->matchFinderObj) - 1;
+ for (i = 0; i < LZMA_NUM_REPS; i++)
+ {
+ UInt32 len;
+ const Byte *data2 = data - (p->reps[i] + 1);
+ if (data[1] != data2[1] || data[2] != data2[2])
+ {
+ repLens[i] = 0;
+ continue;
+ }
+ for (len = 2; len < numAvailableBytes && data[len] == data2[len]; len++);
+ if (len + 1 >= lenMain)
+ {
+ p->longestMatchWasFound = True;
+ *backRes = (UInt32)(-1);
+ return 1;
+ }
+ }
+ *backRes = backMain + LZMA_NUM_REPS;
+ MovePos(p, lenMain - 2);
+ return lenMain;
+ }
+ *backRes = (UInt32)(-1);
+ return 1;
+}
+
+static void WriteEndMarker(CLzmaEnc *p, UInt32 posState)
+{
+ UInt32 len;
+ RangeEnc_EncodeBit(&p->rc, &p->isMatch[p->state][posState], 1);
+ RangeEnc_EncodeBit(&p->rc, &p->isRep[p->state], 0);
+ p->state = kMatchNextStates[p->state];
+ len = LZMA_MATCH_LEN_MIN;
+ LenEnc_Encode2(&p->lenEnc, &p->rc, len - LZMA_MATCH_LEN_MIN, posState, !p->fastMode, p->ProbPrices);
+ RcTree_Encode(&p->rc, p->posSlotEncoder[GetLenToPosState(len)], kNumPosSlotBits, (1 << kNumPosSlotBits) - 1);
+ RangeEnc_EncodeDirectBits(&p->rc, (((UInt32)1 << 30) - 1) >> kNumAlignBits, 30 - kNumAlignBits);
+ RcTree_ReverseEncode(&p->rc, p->posAlignEncoder, kNumAlignBits, kAlignMask);
+}
+
+static SRes CheckErrors(CLzmaEnc *p)
+{
+ if (p->result != SZ_OK)
+ return p->result;
+ if (p->rc.res != SZ_OK)
+ p->result = SZ_ERROR_WRITE;
+ if (p->matchFinderBase.result != SZ_OK)
+ p->result = SZ_ERROR_READ;
+ if (p->result != SZ_OK)
+ p->finished = True;
+ return p->result;
+}
+
+static SRes Flush(CLzmaEnc *p, UInt32 nowPos)
+{
+ /* ReleaseMFStream(); */
+ p->finished = True;
+ if (p->writeEndMark)
+ WriteEndMarker(p, nowPos & p->pbMask);
+ RangeEnc_FlushData(&p->rc);
+ RangeEnc_FlushStream(&p->rc);
+ return CheckErrors(p);
+}
+
+static void FillAlignPrices(CLzmaEnc *p)
+{
+ UInt32 i;
+ for (i = 0; i < kAlignTableSize; i++)
+ p->alignPrices[i] = RcTree_ReverseGetPrice(p->posAlignEncoder, kNumAlignBits, i, p->ProbPrices);
+ p->alignPriceCount = 0;
+}
+
+static void FillDistancesPrices(CLzmaEnc *p)
+{
+ UInt32 tempPrices[kNumFullDistances];
+ UInt32 i, lenToPosState;
+ for (i = kStartPosModelIndex; i < kNumFullDistances; i++)
+ {
+ UInt32 posSlot = GetPosSlot1(i);
+ UInt32 footerBits = ((posSlot >> 1) - 1);
+ UInt32 base = ((2 | (posSlot & 1)) << footerBits);
+ tempPrices[i] = RcTree_ReverseGetPrice(p->posEncoders + base - posSlot - 1, footerBits, i - base, p->ProbPrices);
+ }
+
+ for (lenToPosState = 0; lenToPosState < kNumLenToPosStates; lenToPosState++)
+ {
+ UInt32 posSlot;
+ const CLzmaProb *encoder = p->posSlotEncoder[lenToPosState];
+ UInt32 *posSlotPrices = p->posSlotPrices[lenToPosState];
+ for (posSlot = 0; posSlot < p->distTableSize; posSlot++)
+ posSlotPrices[posSlot] = RcTree_GetPrice(encoder, kNumPosSlotBits, posSlot, p->ProbPrices);
+ for (posSlot = kEndPosModelIndex; posSlot < p->distTableSize; posSlot++)
+ posSlotPrices[posSlot] += ((((posSlot >> 1) - 1) - kNumAlignBits) << kNumBitPriceShiftBits);
+
+ {
+ UInt32 *distancesPrices = p->distancesPrices[lenToPosState];
+ UInt32 i;
+ for (i = 0; i < kStartPosModelIndex; i++)
+ distancesPrices[i] = posSlotPrices[i];
+ for (; i < kNumFullDistances; i++)
+ distancesPrices[i] = posSlotPrices[GetPosSlot1(i)] + tempPrices[i];
+ }
+ }
+ p->matchPriceCount = 0;
+}
+
+void LzmaEnc_Construct(CLzmaEnc *p)
+{
+ RangeEnc_Construct(&p->rc);
+ MatchFinder_Construct(&p->matchFinderBase);
+ #ifdef COMPRESS_MF_MT
+ MatchFinderMt_Construct(&p->matchFinderMt);
+ p->matchFinderMt.MatchFinder = &p->matchFinderBase;
+ #endif
+
+ {
+ CLzmaEncProps props;
+ LzmaEncProps_Init(&props);
+ LzmaEnc_SetProps(p, &props);
+ }
+
+ #ifndef LZMA_LOG_BSR
+ LzmaEnc_FastPosInit(p->g_FastPos);
+ #endif
+
+ LzmaEnc_InitPriceTables(p->ProbPrices);
+ p->litProbs = 0;
+ p->saveState.litProbs = 0;
+}
+
+CLzmaEncHandle LzmaEnc_Create(ISzAlloc *alloc)
+{
+ void *p;
+ p = alloc->Alloc(alloc, sizeof(CLzmaEnc));
+ if (p != 0)
+ LzmaEnc_Construct((CLzmaEnc *)p);
+ return p;
+}
+
+void LzmaEnc_FreeLits(CLzmaEnc *p, ISzAlloc *alloc)
+{
+ alloc->Free(alloc, p->litProbs);
+ alloc->Free(alloc, p->saveState.litProbs);
+ p->litProbs = 0;
+ p->saveState.litProbs = 0;
+}
+
+void LzmaEnc_Destruct(CLzmaEnc *p, ISzAlloc *alloc, ISzAlloc *allocBig)
+{
+ #ifdef COMPRESS_MF_MT
+ MatchFinderMt_Destruct(&p->matchFinderMt, allocBig);
+ #endif
+ MatchFinder_Free(&p->matchFinderBase, allocBig);
+ LzmaEnc_FreeLits(p, alloc);
+ RangeEnc_Free(&p->rc, alloc);
+}
+
+void LzmaEnc_Destroy(CLzmaEncHandle p, ISzAlloc *alloc, ISzAlloc *allocBig)
+{
+ LzmaEnc_Destruct((CLzmaEnc *)p, alloc, allocBig);
+ alloc->Free(alloc, p);
+}
+
+static SRes LzmaEnc_CodeOneBlock(CLzmaEnc *p, Bool useLimits, UInt32 maxPackSize, UInt32 maxUnpackSize)
+{
+ UInt32 nowPos32, startPos32;
+ if (p->inStream != 0)
+ {
+ p->matchFinderBase.stream = p->inStream;
+ p->matchFinder.Init(p->matchFinderObj);
+ p->inStream = 0;
+ }
+
+ if (p->finished)
+ return p->result;
+ RINOK(CheckErrors(p));
+
+ nowPos32 = (UInt32)p->nowPos64;
+ startPos32 = nowPos32;
+
+ if (p->nowPos64 == 0)
+ {
+ UInt32 numDistancePairs;
+ Byte curByte;
+ if (p->matchFinder.GetNumAvailableBytes(p->matchFinderObj) == 0)
+ return Flush(p, nowPos32);
+ ReadMatchDistances(p, &numDistancePairs);
+ RangeEnc_EncodeBit(&p->rc, &p->isMatch[p->state][0], 0);
+ p->state = kLiteralNextStates[p->state];
+ curByte = p->matchFinder.GetIndexByte(p->matchFinderObj, 0 - p->additionalOffset);
+ LitEnc_Encode(&p->rc, p->litProbs, curByte);
+ p->additionalOffset--;
+ nowPos32++;
+ }
+
+ if (p->matchFinder.GetNumAvailableBytes(p->matchFinderObj) != 0)
+ for (;;)
+ {
+ UInt32 pos, len, posState;
+
+ if (p->fastMode)
+ len = GetOptimumFast(p, &pos);
+ else
+ len = GetOptimum(p, nowPos32, &pos);
+
+ #ifdef SHOW_STAT2
+ printf("\n pos = %4X, len = %d pos = %d", nowPos32, len, pos);
+ #endif
+
+ posState = nowPos32 & p->pbMask;
+ if (len == 1 && pos == 0xFFFFFFFF)
+ {
+ Byte curByte;
+ CLzmaProb *probs;
+ const Byte *data;
+
+ RangeEnc_EncodeBit(&p->rc, &p->isMatch[p->state][posState], 0);
+ data = p->matchFinder.GetPointerToCurrentPos(p->matchFinderObj) - p->additionalOffset;
+ curByte = *data;
+ probs = LIT_PROBS(nowPos32, *(data - 1));
+ if (IsCharState(p->state))
+ LitEnc_Encode(&p->rc, probs, curByte);
+ else
+ LitEnc_EncodeMatched(&p->rc, probs, curByte, *(data - p->reps[0] - 1));
+ p->state = kLiteralNextStates[p->state];
+ }
+ else
+ {
+ RangeEnc_EncodeBit(&p->rc, &p->isMatch[p->state][posState], 1);
+ if (pos < LZMA_NUM_REPS)
+ {
+ RangeEnc_EncodeBit(&p->rc, &p->isRep[p->state], 1);
+ if (pos == 0)
+ {
+ RangeEnc_EncodeBit(&p->rc, &p->isRepG0[p->state], 0);
+ RangeEnc_EncodeBit(&p->rc, &p->isRep0Long[p->state][posState], ((len == 1) ? 0 : 1));
+ }
+ else
+ {
+ UInt32 distance = p->reps[pos];
+ RangeEnc_EncodeBit(&p->rc, &p->isRepG0[p->state], 1);
+ if (pos == 1)
+ RangeEnc_EncodeBit(&p->rc, &p->isRepG1[p->state], 0);
+ else
+ {
+ RangeEnc_EncodeBit(&p->rc, &p->isRepG1[p->state], 1);
+ RangeEnc_EncodeBit(&p->rc, &p->isRepG2[p->state], pos - 2);
+ if (pos == 3)
+ p->reps[3] = p->reps[2];
+ p->reps[2] = p->reps[1];
+ }
+ p->reps[1] = p->reps[0];
+ p->reps[0] = distance;
+ }
+ if (len == 1)
+ p->state = kShortRepNextStates[p->state];
+ else
+ {
+ LenEnc_Encode2(&p->repLenEnc, &p->rc, len - LZMA_MATCH_LEN_MIN, posState, !p->fastMode, p->ProbPrices);
+ p->state = kRepNextStates[p->state];
+ }
+ }
+ else
+ {
+ UInt32 posSlot;
+ RangeEnc_EncodeBit(&p->rc, &p->isRep[p->state], 0);
+ p->state = kMatchNextStates[p->state];
+ LenEnc_Encode2(&p->lenEnc, &p->rc, len - LZMA_MATCH_LEN_MIN, posState, !p->fastMode, p->ProbPrices);
+ pos -= LZMA_NUM_REPS;
+ GetPosSlot(pos, posSlot);
+ RcTree_Encode(&p->rc, p->posSlotEncoder[GetLenToPosState(len)], kNumPosSlotBits, posSlot);
+
+ if (posSlot >= kStartPosModelIndex)
+ {
+ UInt32 footerBits = ((posSlot >> 1) - 1);
+ UInt32 base = ((2 | (posSlot & 1)) << footerBits);
+ UInt32 posReduced = pos - base;
+
+ if (posSlot < kEndPosModelIndex)
+ RcTree_ReverseEncode(&p->rc, p->posEncoders + base - posSlot - 1, footerBits, posReduced);
+ else
+ {
+ RangeEnc_EncodeDirectBits(&p->rc, posReduced >> kNumAlignBits, footerBits - kNumAlignBits);
+ RcTree_ReverseEncode(&p->rc, p->posAlignEncoder, kNumAlignBits, posReduced & kAlignMask);
+ p->alignPriceCount++;
+ }
+ }
+ p->reps[3] = p->reps[2];
+ p->reps[2] = p->reps[1];
+ p->reps[1] = p->reps[0];
+ p->reps[0] = pos;
+ p->matchPriceCount++;
+ }
+ }
+ p->additionalOffset -= len;
+ nowPos32 += len;
+ if (p->additionalOffset == 0)
+ {
+ UInt32 processed;
+ if (!p->fastMode)
+ {
+ if (p->matchPriceCount >= (1 << 7))
+ FillDistancesPrices(p);
+ if (p->alignPriceCount >= kAlignTableSize)
+ FillAlignPrices(p);
+ }
+ if (p->matchFinder.GetNumAvailableBytes(p->matchFinderObj) == 0)
+ break;
+ processed = nowPos32 - startPos32;
+ if (useLimits)
+ {
+ if (processed + kNumOpts + 300 >= maxUnpackSize ||
+ RangeEnc_GetProcessed(&p->rc) + kNumOpts * 2 >= maxPackSize)
+ break;
+ }
+ else if (processed >= (1 << 15))
+ {
+ p->nowPos64 += nowPos32 - startPos32;
+ return CheckErrors(p);
+ }
+ }
+ }
+ p->nowPos64 += nowPos32 - startPos32;
+ return Flush(p, nowPos32);
+}
+
+#define kBigHashDicLimit ((UInt32)1 << 24)
+
+static SRes LzmaEnc_Alloc(CLzmaEnc *p, UInt32 keepWindowSize, ISzAlloc *alloc, ISzAlloc *allocBig)
+{
+ UInt32 beforeSize = kNumOpts;
+ Bool btMode;
+ if (!RangeEnc_Alloc(&p->rc, alloc))
+ return SZ_ERROR_MEM;
+ btMode = (p->matchFinderBase.btMode != 0);
+ #ifdef COMPRESS_MF_MT
+ p->mtMode = (p->multiThread && !p->fastMode && btMode);
+ #endif
+
+ {
+ unsigned lclp = p->lc + p->lp;
+ if (p->litProbs == 0 || p->saveState.litProbs == 0 || p->lclp != lclp)
+ {
+ LzmaEnc_FreeLits(p, alloc);
+ p->litProbs = (CLzmaProb *)alloc->Alloc(alloc, (0x300 << lclp) * sizeof(CLzmaProb));
+ p->saveState.litProbs = (CLzmaProb *)alloc->Alloc(alloc, (0x300 << lclp) * sizeof(CLzmaProb));
+ if (p->litProbs == 0 || p->saveState.litProbs == 0)
+ {
+ LzmaEnc_FreeLits(p, alloc);
+ return SZ_ERROR_MEM;
+ }
+ p->lclp = lclp;
+ }
+ }
+
+ p->matchFinderBase.bigHash = (p->dictSize > kBigHashDicLimit);
+
+ if (beforeSize + p->dictSize < keepWindowSize)
+ beforeSize = keepWindowSize - p->dictSize;
+
+ #ifdef COMPRESS_MF_MT
+ if (p->mtMode)
+ {
+ RINOK(MatchFinderMt_Create(&p->matchFinderMt, p->dictSize, beforeSize, p->numFastBytes, LZMA_MATCH_LEN_MAX, allocBig));
+ p->matchFinderObj = &p->matchFinderMt;
+ MatchFinderMt_CreateVTable(&p->matchFinderMt, &p->matchFinder);
+ }
+ else
+ #endif
+ {
+ if (!MatchFinder_Create(&p->matchFinderBase, p->dictSize, beforeSize, p->numFastBytes, LZMA_MATCH_LEN_MAX, allocBig))
+ return SZ_ERROR_MEM;
+ p->matchFinderObj = &p->matchFinderBase;
+ MatchFinder_CreateVTable(&p->matchFinderBase, &p->matchFinder);
+ }
+ return SZ_OK;
+}
+
+void LzmaEnc_Init(CLzmaEnc *p)
+{
+ UInt32 i;
+ p->state = 0;
+ for(i = 0 ; i < LZMA_NUM_REPS; i++)
+ p->reps[i] = 0;
+
+ RangeEnc_Init(&p->rc);
+
+
+ for (i = 0; i < kNumStates; i++)
+ {
+ UInt32 j;
+ for (j = 0; j < LZMA_NUM_PB_STATES_MAX; j++)
+ {
+ p->isMatch[i][j] = kProbInitValue;
+ p->isRep0Long[i][j] = kProbInitValue;
+ }
+ p->isRep[i] = kProbInitValue;
+ p->isRepG0[i] = kProbInitValue;
+ p->isRepG1[i] = kProbInitValue;
+ p->isRepG2[i] = kProbInitValue;
+ }
+
+ {
+ UInt32 num = 0x300 << (p->lp + p->lc);
+ for (i = 0; i < num; i++)
+ p->litProbs[i] = kProbInitValue;
+ }
+
+ {
+ for (i = 0; i < kNumLenToPosStates; i++)
+ {
+ CLzmaProb *probs = p->posSlotEncoder[i];
+ UInt32 j;
+ for (j = 0; j < (1 << kNumPosSlotBits); j++)
+ probs[j] = kProbInitValue;
+ }
+ }
+ {
+ for(i = 0; i < kNumFullDistances - kEndPosModelIndex; i++)
+ p->posEncoders[i] = kProbInitValue;
+ }
+
+ LenEnc_Init(&p->lenEnc.p);
+ LenEnc_Init(&p->repLenEnc.p);
+
+ for (i = 0; i < (1 << kNumAlignBits); i++)
+ p->posAlignEncoder[i] = kProbInitValue;
+
+ p->longestMatchWasFound = False;
+ p->optimumEndIndex = 0;
+ p->optimumCurrentIndex = 0;
+ p->additionalOffset = 0;
+
+ p->pbMask = (1 << p->pb) - 1;
+ p->lpMask = (1 << p->lp) - 1;
+}
+
+void LzmaEnc_InitPrices(CLzmaEnc *p)
+{
+ if (!p->fastMode)
+ {
+ FillDistancesPrices(p);
+ FillAlignPrices(p);
+ }
+
+ p->lenEnc.tableSize =
+ p->repLenEnc.tableSize =
+ p->numFastBytes + 1 - LZMA_MATCH_LEN_MIN;
+ LenPriceEnc_UpdateTables(&p->lenEnc, 1 << p->pb, p->ProbPrices);
+ LenPriceEnc_UpdateTables(&p->repLenEnc, 1 << p->pb, p->ProbPrices);
+}
+
+static SRes LzmaEnc_AllocAndInit(CLzmaEnc *p, UInt32 keepWindowSize, ISzAlloc *alloc, ISzAlloc *allocBig)
+{
+ UInt32 i;
+ for (i = 0; i < (UInt32)kDicLogSizeMaxCompress; i++)
+ if (p->dictSize <= ((UInt32)1 << i))
+ break;
+ p->distTableSize = i * 2;
+
+ p->finished = False;
+ p->result = SZ_OK;
+ RINOK(LzmaEnc_Alloc(p, keepWindowSize, alloc, allocBig));
+ LzmaEnc_Init(p);
+ LzmaEnc_InitPrices(p);
+ p->nowPos64 = 0;
+ return SZ_OK;
+}
+
+static SRes LzmaEnc_Prepare(CLzmaEncHandle pp, ISeqInStream *inStream, ISeqOutStream *outStream,
+ ISzAlloc *alloc, ISzAlloc *allocBig)
+{
+ CLzmaEnc *p = (CLzmaEnc *)pp;
+ p->inStream = inStream;
+ p->rc.outStream = outStream;
+ return LzmaEnc_AllocAndInit(p, 0, alloc, allocBig);
+}
+
+SRes LzmaEnc_PrepareForLzma2(CLzmaEncHandle pp,
+ ISeqInStream *inStream, UInt32 keepWindowSize,
+ ISzAlloc *alloc, ISzAlloc *allocBig)
+{
+ CLzmaEnc *p = (CLzmaEnc *)pp;
+ p->inStream = inStream;
+ return LzmaEnc_AllocAndInit(p, keepWindowSize, alloc, allocBig);
+}
+
+static void LzmaEnc_SetInputBuf(CLzmaEnc *p, const Byte *src, SizeT srcLen)
+{
+ p->seqBufInStream.funcTable.Read = MyRead;
+ p->seqBufInStream.data = src;
+ p->seqBufInStream.rem = srcLen;
+}
+
+SRes LzmaEnc_MemPrepare(CLzmaEncHandle pp, const Byte *src, SizeT srcLen,
+ UInt32 keepWindowSize, ISzAlloc *alloc, ISzAlloc *allocBig)
+{
+ CLzmaEnc *p = (CLzmaEnc *)pp;
+ LzmaEnc_SetInputBuf(p, src, srcLen);
+ p->inStream = &p->seqBufInStream.funcTable;
+ return LzmaEnc_AllocAndInit(p, keepWindowSize, alloc, allocBig);
+}
+
+void LzmaEnc_Finish(CLzmaEncHandle pp)
+{
+ #ifdef COMPRESS_MF_MT
+ CLzmaEnc *p = (CLzmaEnc *)pp;
+ if (p->mtMode)
+ MatchFinderMt_ReleaseStream(&p->matchFinderMt);
+ #endif
+}
+
+typedef struct _CSeqOutStreamBuf
+{
+ ISeqOutStream funcTable;
+ Byte *data;
+ SizeT rem;
+ Bool overflow;
+} CSeqOutStreamBuf;
+
+static size_t MyWrite(void *pp, const void *data, size_t size)
+{
+ CSeqOutStreamBuf *p = (CSeqOutStreamBuf *)pp;
+ if (p->rem < size)
+ {
+ size = p->rem;
+ p->overflow = True;
+ }
+ memcpy(p->data, data, size);
+ p->rem -= size;
+ p->data += size;
+ return size;
+}
+
+
+UInt32 LzmaEnc_GetNumAvailableBytes(CLzmaEncHandle pp)
+{
+ const CLzmaEnc *p = (CLzmaEnc *)pp;
+ return p->matchFinder.GetNumAvailableBytes(p->matchFinderObj);
+}
+
+const Byte *LzmaEnc_GetCurBuf(CLzmaEncHandle pp)
+{
+ const CLzmaEnc *p = (CLzmaEnc *)pp;
+ return p->matchFinder.GetPointerToCurrentPos(p->matchFinderObj) - p->additionalOffset;
+}
+
+SRes LzmaEnc_CodeOneMemBlock(CLzmaEncHandle pp, Bool reInit,
+ Byte *dest, size_t *destLen, UInt32 desiredPackSize, UInt32 *unpackSize)
+{
+ CLzmaEnc *p = (CLzmaEnc *)pp;
+ UInt64 nowPos64;
+ SRes res;
+ CSeqOutStreamBuf outStream;
+
+ outStream.funcTable.Write = MyWrite;
+ outStream.data = dest;
+ outStream.rem = *destLen;
+ outStream.overflow = False;
+
+ p->writeEndMark = False;
+ p->finished = False;
+ p->result = SZ_OK;
+
+ if (reInit)
+ LzmaEnc_Init(p);
+ LzmaEnc_InitPrices(p);
+ nowPos64 = p->nowPos64;
+ RangeEnc_Init(&p->rc);
+ p->rc.outStream = &outStream.funcTable;
+
+ res = LzmaEnc_CodeOneBlock(pp, True, desiredPackSize, *unpackSize);
+
+ *unpackSize = (UInt32)(p->nowPos64 - nowPos64);
+ *destLen -= outStream.rem;
+ if (outStream.overflow)
+ return SZ_ERROR_OUTPUT_EOF;
+
+ return res;
+}
+
+SRes LzmaEnc_Encode(CLzmaEncHandle pp, ISeqOutStream *outStream, ISeqInStream *inStream, ICompressProgress *progress,
+ ISzAlloc *alloc, ISzAlloc *allocBig)
+{
+ CLzmaEnc *p = (CLzmaEnc *)pp;
+ SRes res = SZ_OK;
+
+ #ifdef COMPRESS_MF_MT
+ Byte allocaDummy[0x300];
+ int i = 0;
+ for (i = 0; i < 16; i++)
+ allocaDummy[i] = (Byte)i;
+ #endif
+
+ RINOK(LzmaEnc_Prepare(pp, inStream, outStream, alloc, allocBig));
+
+ for (;;)
+ {
+ res = LzmaEnc_CodeOneBlock(pp, False, 0, 0);
+ if (res != SZ_OK || p->finished != 0)
+ break;
+ if (progress != 0)
+ {
+ res = progress->Progress(progress, p->nowPos64, RangeEnc_GetProcessed(&p->rc));
+ if (res != SZ_OK)
+ {
+ res = SZ_ERROR_PROGRESS;
+ break;
+ }
+ }
+ }
+ LzmaEnc_Finish(pp);
+ return res;
+}
+
+SRes LzmaEnc_WriteProperties(CLzmaEncHandle pp, Byte *props, SizeT *size)
+{
+ CLzmaEnc *p = (CLzmaEnc *)pp;
+ int i;
+ UInt32 dictSize = p->dictSize;
+ if (*size < LZMA_PROPS_SIZE)
+ return SZ_ERROR_PARAM;
+ *size = LZMA_PROPS_SIZE;
+ props[0] = (Byte)((p->pb * 5 + p->lp) * 9 + p->lc);
+
+ for (i = 11; i <= 30; i++)
+ {
+ if (dictSize <= ((UInt32)2 << i))
+ {
+ dictSize = (2 << i);
+ break;
+ }
+ if (dictSize <= ((UInt32)3 << i))
+ {
+ dictSize = (3 << i);
+ break;
+ }
+ }
+
+ for (i = 0; i < 4; i++)
+ props[1 + i] = (Byte)(dictSize >> (8 * i));
+ return SZ_OK;
+}
+
+SRes LzmaEnc_MemEncode(CLzmaEncHandle pp, Byte *dest, SizeT *destLen, const Byte *src, SizeT srcLen,
+ int writeEndMark, ICompressProgress *progress, ISzAlloc *alloc, ISzAlloc *allocBig)
+{
+ SRes res;
+ CLzmaEnc *p = (CLzmaEnc *)pp;
+
+ CSeqOutStreamBuf outStream;
+
+ LzmaEnc_SetInputBuf(p, src, srcLen);
+
+ outStream.funcTable.Write = MyWrite;
+ outStream.data = dest;
+ outStream.rem = *destLen;
+ outStream.overflow = False;
+
+ p->writeEndMark = writeEndMark;
+ res = LzmaEnc_Encode(pp, &outStream.funcTable, &p->seqBufInStream.funcTable,
+ progress, alloc, allocBig);
+
+ *destLen -= outStream.rem;
+ if (outStream.overflow)
+ return SZ_ERROR_OUTPUT_EOF;
+ return res;
+}
+
+SRes LzmaEncode(Byte *dest, SizeT *destLen, const Byte *src, SizeT srcLen,
+ const CLzmaEncProps *props, Byte *propsEncoded, SizeT *propsSize, int writeEndMark,
+ ICompressProgress *progress, ISzAlloc *alloc, ISzAlloc *allocBig)
+{
+ CLzmaEnc *p = (CLzmaEnc *)LzmaEnc_Create(alloc);
+ SRes res;
+ if (p == 0)
+ return SZ_ERROR_MEM;
+
+ res = LzmaEnc_SetProps(p, props);
+ if (res == SZ_OK)
+ {
+ res = LzmaEnc_WriteProperties(p, propsEncoded, propsSize);
+ if (res == SZ_OK)
+ res = LzmaEnc_MemEncode(p, dest, destLen, src, srcLen,
+ writeEndMark, progress, alloc, allocBig);
+ }
+
+ LzmaEnc_Destroy(p, alloc, allocBig);
+ return res;
+}
diff --git a/C/LzmaEnc.h b/C/LzmaEnc.h
new file mode 100755
index 00000000..949f40f4
--- /dev/null
+++ b/C/LzmaEnc.h
@@ -0,0 +1,74 @@
+/* LzmaEnc.h -- LZMA Encoder
+2008-04-27
+Copyright (c) 1999-2008 Igor Pavlov
+Read LzFind.h for license options */
+
+#ifndef __LZMAENC_H
+#define __LZMAENC_H
+
+#include "Types.h"
+
+#define LZMA_PROPS_SIZE 5
+
+typedef struct _CLzmaEncProps
+{
+ int level; /* 0 <= level <= 9 */
+ UInt32 dictSize; /* (1 << 12) <= dictSize <= (1 << 27) for 32-bit version
+ (1 << 12) <= dictSize <= (1 << 30) for 64-bit version
+ default = (1 << 24) */
+ int lc; /* 0 <= lc <= 8, default = 3 */
+ int lp; /* 0 <= lp <= 4, default = 0 */
+ int pb; /* 0 <= pb <= 4, default = 2 */
+ int algo; /* 0 - fast, 1 - normal, default = 1 */
+ int fb; /* 5 <= fb <= 273, default = 32 */
+ int btMode; /* 0 - hashChain Mode, 1 - binTree mode - normal, default = 1 */
+ int numHashBytes; /* 2, 3 or 4, default = 4 */
+ UInt32 mc; /* 1 <= mc <= (1 << 30), default = 32 */
+ unsigned writeEndMark; /* 0 - do not write EOPM, 1 - write EOPM, default = 0 */
+ int numThreads; /* 1 or 2, default = 2 */
+} CLzmaEncProps;
+
+void LzmaEncProps_Init(CLzmaEncProps *p);
+void LzmaEncProps_Normalize(CLzmaEncProps *p);
+UInt32 LzmaEncProps_GetDictSize(const CLzmaEncProps *props2);
+
+
+/* ---------- CLzmaEncHandle Interface ---------- */
+
+/* LzmaEnc_* functions can return the following exit codes:
+Returns:
+ SZ_OK - OK
+ SZ_ERROR_MEM - Memory allocation error
+ SZ_ERROR_PARAM - Incorrect paramater in props
+ SZ_ERROR_WRITE - Write callback error.
+ SZ_ERROR_PROGRESS - some break from progress callback
+ SZ_ERROR_THREAD - errors in multithreading functions (only for Mt version)
+*/
+
+typedef void * CLzmaEncHandle;
+
+CLzmaEncHandle LzmaEnc_Create(ISzAlloc *alloc);
+void LzmaEnc_Destroy(CLzmaEncHandle p, ISzAlloc *alloc, ISzAlloc *allocBig);
+SRes LzmaEnc_SetProps(CLzmaEncHandle p, const CLzmaEncProps *props);
+SRes LzmaEnc_WriteProperties(CLzmaEncHandle p, Byte *properties, SizeT *size);
+SRes LzmaEnc_Encode(CLzmaEncHandle p, ISeqOutStream *outStream, ISeqInStream *inStream,
+ ICompressProgress *progress, ISzAlloc *alloc, ISzAlloc *allocBig);
+SRes LzmaEnc_MemEncode(CLzmaEncHandle p, Byte *dest, SizeT *destLen, const Byte *src, SizeT srcLen,
+ int writeEndMark, ICompressProgress *progress, ISzAlloc *alloc, ISzAlloc *allocBig);
+
+/* ---------- One Call Interface ---------- */
+
+/* LzmaEncode
+Return code:
+ SZ_OK - OK
+ SZ_ERROR_MEM - Memory allocation error
+ SZ_ERROR_PARAM - Incorrect paramater
+ SZ_ERROR_OUTPUT_EOF - output buffer overflow
+ SZ_ERROR_THREAD - errors in multithreading functions (only for Mt version)
+*/
+
+SRes LzmaEncode(Byte *dest, SizeT *destLen, const Byte *src, SizeT srcLen,
+ const CLzmaEncProps *props, Byte *propsEncoded, SizeT *propsSize, int writeEndMark,
+ ICompressProgress *progress, ISzAlloc *alloc, ISzAlloc *allocBig);
+
+#endif
diff --git a/C/LzmaLib.c b/C/LzmaLib.c
new file mode 100755
index 00000000..32b0a459
--- /dev/null
+++ b/C/LzmaLib.c
@@ -0,0 +1,46 @@
+/* LzmaLib.c -- LZMA library wrapper
+2008-04-07
+Igor Pavlov
+Public domain */
+
+#include "LzmaEnc.h"
+#include "LzmaDec.h"
+#include "Alloc.h"
+#include "LzmaLib.h"
+
+static void *SzAlloc(void *p, size_t size) { p = p; return MyAlloc(size); }
+static void SzFree(void *p, void *address) { p = p; MyFree(address); }
+static ISzAlloc g_Alloc = { SzAlloc, SzFree };
+
+MY_STDAPI LzmaCompress(unsigned char *dest, size_t *destLen, const unsigned char *src, size_t srcLen,
+ unsigned char *outProps, size_t *outPropsSize,
+ int level, /* 0 <= level <= 9, default = 5 */
+ unsigned dictSize, /* use (1 << N) or (3 << N). 4 KB < dictSize <= 128 MB */
+ int lc, /* 0 <= lc <= 8, default = 3 */
+ int lp, /* 0 <= lp <= 4, default = 0 */
+ int pb, /* 0 <= pb <= 4, default = 2 */
+ int fb, /* 5 <= fb <= 273, default = 32 */
+ int numThreads /* 1 or 2, default = 2 */
+)
+{
+ CLzmaEncProps props;
+ LzmaEncProps_Init(&props);
+ props.level = level;
+ props.dictSize = dictSize;
+ props.lc = lc;
+ props.lp = lp;
+ props.pb = pb;
+ props.fb = fb;
+ props.numThreads = numThreads;
+
+ return LzmaEncode(dest, destLen, src, srcLen, &props, outProps, outPropsSize, 0,
+ NULL, &g_Alloc, &g_Alloc);
+}
+
+
+MY_STDAPI LzmaUncompress(unsigned char *dest, size_t *destLen, const unsigned char *src, size_t *srcLen,
+ const unsigned char *props, size_t propsSize)
+{
+ ELzmaStatus status;
+ return LzmaDecode(dest, destLen, src, srcLen, props, (unsigned)propsSize, LZMA_FINISH_ANY, &status, &g_Alloc);
+}
diff --git a/C/LzmaLib.h b/C/LzmaLib.h
new file mode 100755
index 00000000..ac7f90f8
--- /dev/null
+++ b/C/LzmaLib.h
@@ -0,0 +1,135 @@
+/* LzmaLib.h -- LZMA library interface
+2008-04-11
+Igor Pavlov
+Public domain */
+
+#ifndef __LZMALIB_H
+#define __LZMALIB_H
+
+#include "Types.h"
+
+#ifdef __cplusplus
+ #define MY_EXTERN_C extern "C"
+#else
+ #define MY_EXTERN_C extern
+#endif
+
+#define MY_STDAPI MY_EXTERN_C int MY_STD_CALL
+
+#define LZMA_PROPS_SIZE 5
+
+/*
+RAM requirements for LZMA:
+ for compression: (dictSize * 11.5 + 6 MB) + state_size
+ for decompression: dictSize + state_size
+ state_size = (4 + (1.5 << (lc + lp))) KB
+ by default (lc=3, lp=0), state_size = 16 KB.
+
+LZMA properties (5 bytes) format
+ Offset Size Description
+ 0 1 lc, lp and pb in encoded form.
+ 1 4 dictSize (little endian).
+*/
+
+/*
+LzmaCompress
+------------
+
+outPropsSize -
+ In: the pointer to the size of outProps buffer; *outPropsSize = LZMA_PROPS_SIZE = 5.
+ Out: the pointer to the size of written properties in outProps buffer; *outPropsSize = LZMA_PROPS_SIZE = 5.
+
+ LZMA Encoder will use defult values for any parameter, if it is
+ -1 for any from: level, loc, lp, pb, fb, numThreads
+ 0 for dictSize
+
+level - compression level: 0 <= level <= 9;
+
+ level dictSize algo fb
+ 0: 16 KB 0 32
+ 1: 64 KB 0 32
+ 2: 256 KB 0 32
+ 3: 1 MB 0 32
+ 4: 4 MB 0 32
+ 5: 16 MB 1 32
+ 6: 32 MB 1 32
+ 7+: 64 MB 1 64
+
+ The default value for "level" is 5.
+
+ algo = 0 means fast method
+ algo = 1 means normal method
+
+dictSize - The dictionary size in bytes. The maximum value is
+ 128 MB = (1 << 27) bytes for 32-bit version
+ 1 GB = (1 << 30) bytes for 64-bit version
+ The default value is 16 MB = (1 << 24) bytes.
+ It's recommended to use the dictionary that is larger than 4 KB and
+ that can be calculated as (1 << N) or (3 << N) sizes.
+
+lc - The number of literal context bits (high bits of previous literal).
+ It can be in the range from 0 to 8. The default value is 3.
+ Sometimes lc=4 gives the gain for big files.
+
+lp - The number of literal pos bits (low bits of current position for literals).
+ It can be in the range from 0 to 4. The default value is 0.
+ The lp switch is intended for periodical data when the period is equal to 2^lp.
+ For example, for 32-bit (4 bytes) periodical data you can use lp=2. Often it's
+ better to set lc=0, if you change lp switch.
+
+pb - The number of pos bits (low bits of current position).
+ It can be in the range from 0 to 4. The default value is 2.
+ The pb switch is intended for periodical data when the period is equal 2^pb.
+
+fb - Word size (the number of fast bytes).
+ It can be in the range from 5 to 273. The default value is 32.
+ Usually, a big number gives a little bit better compression ratio and
+ slower compression process.
+
+numThreads - The number of thereads. 1 or 2. The default value is 2.
+ Fast mode (algo = 0) can use only 1 thread.
+
+Out:
+ destLen - processed output size
+Returns:
+ SZ_OK - OK
+ SZ_ERROR_MEM - Memory allocation error
+ SZ_ERROR_PARAM - Incorrect paramater
+ SZ_ERROR_OUTPUT_EOF - output buffer overflow
+ SZ_ERROR_THREAD - errors in multithreading functions (only for Mt version)
+*/
+
+MY_STDAPI LzmaCompress(unsigned char *dest, size_t *destLen, const unsigned char *src, size_t srcLen,
+ unsigned char *outProps, size_t *outPropsSize, /* *outPropsSize must be = 5 */
+ int level, /* 0 <= level <= 9, default = 5 */
+ unsigned dictSize, /* default = (1 << 24) */
+ int lc, /* 0 <= lc <= 8, default = 3 */
+ int lp, /* 0 <= lp <= 4, default = 0 */
+ int pb, /* 0 <= pb <= 4, default = 2 */
+ int fb, /* 5 <= fb <= 273, default = 32 */
+ int numThreads /* 1 or 2, default = 2 */
+ );
+
+/*
+LzmaUncompress
+--------------
+In:
+ dest - output data
+ destLen - output data size
+ src - input data
+ srcLen - input data size
+Out:
+ destLen - processed output size
+ srcLen - processed input size
+Returns:
+ SZ_OK - OK
+ SZ_ERROR_DATA - Data error
+ SZ_ERROR_MEM - Memory allocation arror
+ SZ_ERROR_UNSUPPORTED - Unsupported properties
+ SZ_ERROR_INPUT_EOF - it needs more bytes in input buffer (src)
+*/
+
+MY_STDAPI LzmaUncompress(unsigned char *dest, size_t *destLen, const unsigned char *src, SizeT *srcLen,
+ const unsigned char *props, size_t propsSize);
+
+#endif
diff --git a/C/LzmaLib/LzmaLib.def b/C/LzmaLib/LzmaLib.def
new file mode 100755
index 00000000..8bc6add9
--- /dev/null
+++ b/C/LzmaLib/LzmaLib.def
@@ -0,0 +1,4 @@
+EXPORTS
+ LzmaCompress
+ LzmaUncompress
+
diff --git a/CPP/7zip/Compress/Copy/Copy.dsp b/C/LzmaLib/LzmaLib.dsp
index efbc5e31..3ba6d254 100755
--- a/CPP/7zip/Compress/Copy/Copy.dsp
+++ b/C/LzmaLib/LzmaLib.dsp
@@ -1,24 +1,24 @@
-# Microsoft Developer Studio Project File - Name="Copy" - Package Owner=<4>
+# Microsoft Developer Studio Project File - Name="LzmaLib" - Package Owner=<4>
# Microsoft Developer Studio Generated Build File, Format Version 6.00
# ** DO NOT EDIT **
# TARGTYPE "Win32 (x86) Dynamic-Link Library" 0x0102
-CFG=Copy - Win32 Debug
+CFG=LzmaLib - Win32 Debug
!MESSAGE This is not a valid makefile. To build this project using NMAKE,
!MESSAGE use the Export Makefile command and run
!MESSAGE
-!MESSAGE NMAKE /f "Copy.mak".
+!MESSAGE NMAKE /f "LzmaLib.mak".
!MESSAGE
!MESSAGE You can specify a configuration when running NMAKE
!MESSAGE by defining the macro CFG on the command line. For example:
!MESSAGE
-!MESSAGE NMAKE /f "Copy.mak" CFG="Copy - Win32 Debug"
+!MESSAGE NMAKE /f "LzmaLib.mak" CFG="LzmaLib - Win32 Debug"
!MESSAGE
!MESSAGE Possible choices for configuration are:
!MESSAGE
-!MESSAGE "Copy - Win32 Release" (based on "Win32 (x86) Dynamic-Link Library")
-!MESSAGE "Copy - Win32 Debug" (based on "Win32 (x86) Dynamic-Link Library")
+!MESSAGE "LzmaLib - Win32 Release" (based on "Win32 (x86) Dynamic-Link Library")
+!MESSAGE "LzmaLib - Win32 Debug" (based on "Win32 (x86) Dynamic-Link Library")
!MESSAGE
# Begin Project
@@ -29,7 +29,7 @@ CPP=cl.exe
MTL=midl.exe
RSC=rc.exe
-!IF "$(CFG)" == "Copy - Win32 Release"
+!IF "$(CFG)" == "LzmaLib - Win32 Release"
# PROP BASE Use_MFC 0
# PROP BASE Use_Debug_Libraries 0
@@ -40,23 +40,24 @@ RSC=rc.exe
# PROP Use_Debug_Libraries 0
# PROP Output_Dir "Release"
# PROP Intermediate_Dir "Release"
-# PROP Ignore_Export_Lib 1
+# PROP Ignore_Export_Lib 0
# PROP Target_Dir ""
-# ADD BASE CPP /nologo /MT /W3 /GX /O2 /D "WIN32" /D "NDEBUG" /D "_WINDOWS" /D "_MBCS" /D "_USRDLL" /D "COPY_EXPORTS" /YX /FD /c
-# ADD CPP /nologo /Gz /MD /W3 /GX /O1 /D "WIN32" /D "NDEBUG" /D "_WINDOWS" /D "_MBCS" /D "_USRDLL" /D "COPY_EXPORTS" /Yu"StdAfx.h" /FD /c
+# ADD BASE CPP /nologo /MT /W3 /GX /O2 /D "WIN32" /D "NDEBUG" /D "_WINDOWS" /D "_MBCS" /D "_USRDLL" /D "LZMALIB_EXPORTS" /YX /FD /c
+# ADD CPP /nologo /Gr /MT /W3 /O2 /D "NDEBUG" /D "WIN32" /D "_WINDOWS" /D "_MBCS" /D "_USRDLL" /D "LZMALIB_EXPORTS" /D "COMPRESS_MF_MT" /FD /c
+# SUBTRACT CPP /YX
# ADD BASE MTL /nologo /D "NDEBUG" /mktyplib203 /win32
# ADD MTL /nologo /D "NDEBUG" /mktyplib203 /win32
# ADD BASE RSC /l 0x419 /d "NDEBUG"
-# ADD RSC /l 0x409 /d "NDEBUG"
+# ADD RSC /l 0x419 /d "NDEBUG"
BSC32=bscmake.exe
# ADD BASE BSC32 /nologo
# ADD BSC32 /nologo
LINK32=link.exe
# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /dll /machine:I386
-# ADD LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /dll /machine:I386 /out:"C:\Program Files\7-zip\Codecs\Copy.dll" /opt:NOWIN98
+# ADD LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /dll /machine:I386 /out:"C:\Util\LZMA.dll" /opt:NOWIN98
# SUBTRACT LINK32 /pdb:none
-!ELSEIF "$(CFG)" == "Copy - Win32 Debug"
+!ELSEIF "$(CFG)" == "LzmaLib - Win32 Debug"
# PROP BASE Use_MFC 0
# PROP BASE Use_Debug_Libraries 1
@@ -67,92 +68,111 @@ LINK32=link.exe
# PROP Use_Debug_Libraries 1
# PROP Output_Dir "Debug"
# PROP Intermediate_Dir "Debug"
-# PROP Ignore_Export_Lib 1
+# PROP Ignore_Export_Lib 0
# PROP Target_Dir ""
-# ADD BASE CPP /nologo /MTd /W3 /Gm /GX /ZI /Od /D "WIN32" /D "_DEBUG" /D "_WINDOWS" /D "_MBCS" /D "_USRDLL" /D "COPY_EXPORTS" /YX /FD /GZ /c
-# ADD CPP /nologo /Gz /MTd /W3 /Gm /GX /ZI /Od /D "WIN32" /D "_DEBUG" /D "_WINDOWS" /D "_MBCS" /D "_USRDLL" /D "COPY_EXPORTS" /Yu"StdAfx.h" /FD /GZ /c
+# ADD BASE CPP /nologo /MTd /W3 /Gm /GX /ZI /Od /D "WIN32" /D "_DEBUG" /D "_WINDOWS" /D "_MBCS" /D "_USRDLL" /D "LZMALIB_EXPORTS" /YX /FD /GZ /c
+# ADD CPP /nologo /MTd /W3 /Gm /ZI /Od /D "_DEBUG" /D "WIN32" /D "_WINDOWS" /D "_MBCS" /D "_USRDLL" /D "LZMALIB_EXPORTS" /D "COMPRESS_MF_MT" /FD /GZ /c
+# SUBTRACT CPP /YX
# ADD BASE MTL /nologo /D "_DEBUG" /mktyplib203 /win32
# ADD MTL /nologo /D "_DEBUG" /mktyplib203 /win32
# ADD BASE RSC /l 0x419 /d "_DEBUG"
-# ADD RSC /l 0x409 /d "_DEBUG"
+# ADD RSC /l 0x419 /d "_DEBUG"
BSC32=bscmake.exe
# ADD BASE BSC32 /nologo
# ADD BSC32 /nologo
LINK32=link.exe
# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /dll /debug /machine:I386 /pdbtype:sept
-# ADD LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /dll /debug /machine:I386 /out:"C:\Program Files\7-zip\Codecs\Copy.dll" /pdbtype:sept
+# ADD LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /dll /debug /machine:I386 /out:"C:\Util\LZMA.dll" /pdbtype:sept
!ENDIF
# Begin Target
-# Name "Copy - Win32 Release"
-# Name "Copy - Win32 Debug"
+# Name "LzmaLib - Win32 Release"
+# Name "LzmaLib - Win32 Debug"
# Begin Group "Spec"
# PROP Default_Filter ""
# Begin Source File
-SOURCE=..\Codec.def
+SOURCE=.\LzmaLib.def
# End Source File
# Begin Source File
-SOURCE=..\CodecExports.cpp
+SOURCE=.\LzmaLibExports.c
# End Source File
+# End Group
# Begin Source File
-SOURCE=..\DllExports.cpp
+SOURCE=..\Alloc.c
# End Source File
# Begin Source File
-SOURCE=.\resource.rc
+SOURCE=..\Alloc.h
# End Source File
# Begin Source File
-SOURCE=.\StdAfx.cpp
-# ADD CPP /Yc"StdAfx.h"
+SOURCE=..\IStream.h
# End Source File
# Begin Source File
-SOURCE=.\StdAfx.h
+SOURCE=..\LzFind.c
# End Source File
-# End Group
-# Begin Group "7-Zip Common"
+# Begin Source File
-# PROP Default_Filter ""
+SOURCE=..\LzFind.h
+# End Source File
# Begin Source File
-SOURCE=..\..\Common\StreamUtils.cpp
+SOURCE=..\LzFindMt.c
# End Source File
# Begin Source File
-SOURCE=..\..\Common\StreamUtils.h
+SOURCE=..\LzFindMt.h
# End Source File
-# End Group
-# Begin Group "Ń"
+# Begin Source File
-# PROP Default_Filter ""
+SOURCE=..\LzHash.h
+# End Source File
# Begin Source File
-SOURCE=..\..\..\..\C\Alloc.c
-# SUBTRACT CPP /YX /Yc /Yu
+SOURCE=..\LzmaDec.c
# End Source File
# Begin Source File
-SOURCE=..\..\..\..\C\Alloc.h
+SOURCE=..\LzmaDec.h
+# End Source File
+# Begin Source File
+
+SOURCE=..\LzmaEnc.c
+# End Source File
+# Begin Source File
+
+SOURCE=..\LzmaEnc.h
+# End Source File
+# Begin Source File
+
+SOURCE=..\LzmaLib.c
+# End Source File
+# Begin Source File
+
+SOURCE=..\LzmaLib.h
+# End Source File
+# Begin Source File
+
+SOURCE=.\resource.rc
# End Source File
-# End Group
# Begin Source File
-SOURCE=.\CopyCoder.cpp
+SOURCE=..\Threads.c
# End Source File
# Begin Source File
-SOURCE=.\CopyCoder.h
+SOURCE=..\Threads.h
# End Source File
# Begin Source File
-SOURCE=.\CopyRegister.cpp
+SOURCE=..\Types.h
# End Source File
# End Target
# End Project
diff --git a/CPP/7zip/Compress/BZip2/BZip2.dsw b/C/LzmaLib/LzmaLib.dsw
index 697e5095..6faf3336 100755
--- a/CPP/7zip/Compress/BZip2/BZip2.dsw
+++ b/C/LzmaLib/LzmaLib.dsw
@@ -3,7 +3,7 @@ Microsoft Developer Studio Workspace File, Format Version 6.00
###############################################################################
-Project: "BZip2"=.\BZip2.dsp - Package Owner=<4>
+Project: "LzmaLib"=.\LzmaLib.dsp - Package Owner=<4>
Package=<5>
{{{
diff --git a/C/LzmaLib/LzmaLibExports.c b/C/LzmaLib/LzmaLibExports.c
new file mode 100755
index 00000000..cc90cc0b
--- /dev/null
+++ b/C/LzmaLib/LzmaLibExports.c
@@ -0,0 +1,14 @@
+/* LzmaLibExports.c -- LZMA library DLL Entry point
+2008-03-26
+Igor Pavlov
+Public domain */
+
+#include <windows.h>
+
+BOOL WINAPI DllMain(HINSTANCE hInstance, DWORD dwReason, LPVOID lpReserved)
+{
+ hInstance = hInstance;
+ dwReason = dwReason;
+ lpReserved = lpReserved;
+ return TRUE;
+}
diff --git a/C/LzmaLib/makefile b/C/LzmaLib/makefile
new file mode 100755
index 00000000..01c86cb3
--- /dev/null
+++ b/C/LzmaLib/makefile
@@ -0,0 +1,37 @@
+MY_STATIC_LINK=1
+SLIB = sLZMA.lib
+PROG = LZMA.dll
+SLIBPATH = $O\$(SLIB)
+
+DEF_FILE = LzmaLib.def
+CFLAGS = $(CFLAGS) \
+ -DCOMPRESS_MF_MT \
+
+LIBS = $(LIBS) oleaut32.lib
+
+LIB_OBJS = \
+ $O\LzmaLibExports.obj \
+
+C_OBJS = \
+ $O\Alloc.obj \
+ $O\LzFind.obj \
+ $O\LzFindMt.obj \
+ $O\LzmaDec.obj \
+ $O\LzmaEnc.obj \
+ $O\LzmaLib.obj \
+ $O\Threads.obj \
+
+OBJS = \
+ $(LIB_OBJS) \
+ $(C_OBJS) \
+ $O\resource.res
+
+!include "../../CPP/Build.mak"
+
+$(SLIBPATH): $O $(OBJS)
+ lib -out:$(SLIBPATH) $(OBJS) $(LIBS)
+
+$(LIB_OBJS): $(*B).c
+ $(COMPL_O2)
+$(C_OBJS): ../$(*B).c
+ $(COMPL_O2)
diff --git a/C/LzmaLib/resource.rc b/C/LzmaLib/resource.rc
new file mode 100755
index 00000000..1e489161
--- /dev/null
+++ b/C/LzmaLib/resource.rc
@@ -0,0 +1,4 @@
+#include "../../CPP/7zip/MyVersionInfo.rc"
+
+MY_VERSION_INFO_DLL("LZMA library", "LZMA")
+
diff --git a/C/LzmaUtil/Lzma86Dec.c b/C/LzmaUtil/Lzma86Dec.c
new file mode 100755
index 00000000..b801dd1c
--- /dev/null
+++ b/C/LzmaUtil/Lzma86Dec.c
@@ -0,0 +1,61 @@
+/* Lzma86Dec.c -- LZMA + x86 (BCJ) Filter Decoder
+2008-04-07
+Igor Pavlov
+Public domain */
+
+#include "Lzma86Dec.h"
+
+#include "../Alloc.h"
+#include "../Bra.h"
+#include "../LzmaDec.h"
+
+#define LZMA86_SIZE_OFFSET (1 + LZMA_PROPS_SIZE)
+#define LZMA86_HEADER_SIZE (LZMA86_SIZE_OFFSET + 8)
+
+static void *SzAlloc(void *p, size_t size) { p = p; return MyAlloc(size); }
+static void SzFree(void *p, void *address) { p = p; MyFree(address); }
+static ISzAlloc g_Alloc = { SzAlloc, SzFree };
+
+SRes Lzma86_GetUnpackSize(const Byte *src, SizeT srcLen, UInt64 *unpackSize)
+{
+ unsigned i;
+ if (srcLen < LZMA86_HEADER_SIZE)
+ return SZ_ERROR_INPUT_EOF;
+ *unpackSize = 0;
+ for (i = 0; i < sizeof(UInt64); i++)
+ *unpackSize += ((UInt64)src[LZMA86_SIZE_OFFSET + i]) << (8 * i);
+ return SZ_OK;
+}
+
+SRes Lzma86_Decode(Byte *dest, SizeT *destLen, const Byte *src, SizeT *srcLen)
+{
+ SRes res;
+ int useFilter;
+ SizeT inSizePure;
+ ELzmaStatus status;
+
+ if (*srcLen < LZMA86_HEADER_SIZE)
+ return SZ_ERROR_INPUT_EOF;
+
+ useFilter = src[0];
+
+ if (useFilter > 1)
+ {
+ *destLen = 0;
+ return SZ_ERROR_UNSUPPORTED;
+ }
+
+ inSizePure = *srcLen - LZMA86_HEADER_SIZE;
+ res = LzmaDecode(dest, destLen, src + LZMA86_HEADER_SIZE, &inSizePure,
+ src + 1, LZMA_PROPS_SIZE, LZMA_FINISH_ANY, &status, &g_Alloc);
+ *srcLen = inSizePure + LZMA86_HEADER_SIZE;
+ if (res != SZ_OK)
+ return res;
+ if (useFilter == 1)
+ {
+ UInt32 x86State;
+ x86_Convert_Init(x86State);
+ x86_Convert(dest, *destLen, 0, &x86State, 0);
+ }
+ return SZ_OK;
+}
diff --git a/C/LzmaUtil/Lzma86Dec.h b/C/LzmaUtil/Lzma86Dec.h
new file mode 100755
index 00000000..702a37ba
--- /dev/null
+++ b/C/LzmaUtil/Lzma86Dec.h
@@ -0,0 +1,45 @@
+/* Lzma86Dec.h -- LZMA + x86 (BCJ) Filter Decoder
+2008-04-07
+Igor Pavlov
+Public domain */
+
+#ifndef __LZMA86DEC_H
+#define __LZMA86DEC_H
+
+#include "../Types.h"
+
+/*
+Lzma86_GetUnpackSize:
+ In:
+ src - input data
+ srcLen - input data size
+ Out:
+ unpackSize - size of uncompressed stream
+ Return code:
+ SZ_OK - OK
+ SZ_ERROR_INPUT_EOF - Error in headers
+*/
+
+SRes Lzma86_GetUnpackSize(const Byte *src, SizeT srcLen, UInt64 *unpackSize);
+
+/*
+Lzma86_Decode:
+ In:
+ dest - output data
+ destLen - output data size
+ src - input data
+ srcLen - input data size
+ Out:
+ destLen - processed output size
+ srcLen - processed input size
+ Return code:
+ SZ_OK - OK
+ SZ_ERROR_DATA - Data error
+ SZ_ERROR_MEM - Memory allocation error
+ SZ_ERROR_UNSUPPORTED - unsupported file
+ SZ_ERROR_INPUT_EOF - it needs more bytes in input buffer
+*/
+
+SRes Lzma86_Decode(Byte *dest, SizeT *destLen, const Byte *src, SizeT *srcLen);
+
+#endif
diff --git a/C/LzmaUtil/Lzma86Enc.c b/C/LzmaUtil/Lzma86Enc.c
new file mode 100755
index 00000000..f058e38f
--- /dev/null
+++ b/C/LzmaUtil/Lzma86Enc.c
@@ -0,0 +1,113 @@
+/* Lzma86Enc.c -- LZMA + x86 (BCJ) Filter Encoder
+2008-04-07
+Igor Pavlov
+Public domain */
+
+#include <string.h>
+
+#include "Lzma86Enc.h"
+
+#include "../Alloc.h"
+#include "../Bra.h"
+#include "../LzmaEnc.h"
+
+#define SZE_OUT_OVERFLOW SZE_DATA_ERROR
+
+static void *SzAlloc(void *p, size_t size) { p = p; return MyAlloc(size); }
+static void SzFree(void *p, void *address) { p = p; MyFree(address); }
+static ISzAlloc g_Alloc = { SzAlloc, SzFree };
+
+#define LZMA86_SIZE_OFFSET (1 + LZMA_PROPS_SIZE)
+#define LZMA86_HEADER_SIZE (LZMA86_SIZE_OFFSET + 8)
+
+int Lzma86_Encode(Byte *dest, size_t *destLen, const Byte *src, size_t srcLen,
+ int level, UInt32 dictSize, int filterMode)
+{
+ size_t outSize2 = *destLen;
+ Byte *filteredStream;
+ Bool useFilter;
+ int mainResult = SZ_ERROR_OUTPUT_EOF;
+ CLzmaEncProps props;
+ LzmaEncProps_Init(&props);
+ props.level = level;
+ props.dictSize = dictSize;
+
+ *destLen = 0;
+ if (outSize2 < LZMA86_HEADER_SIZE)
+ return SZ_ERROR_OUTPUT_EOF;
+
+ {
+ int i;
+ UInt64 t = srcLen;
+ for (i = 0; i < 8; i++, t >>= 8)
+ dest[LZMA86_SIZE_OFFSET + i] = (Byte)t;
+ }
+
+ filteredStream = 0;
+ useFilter = (filterMode != SZ_FILTER_NO);
+ if (useFilter)
+ {
+ if (srcLen != 0)
+ {
+ filteredStream = (Byte *)MyAlloc(srcLen);
+ if (filteredStream == 0)
+ return SZ_ERROR_MEM;
+ memcpy(filteredStream, src, srcLen);
+ }
+ {
+ UInt32 x86State;
+ x86_Convert_Init(x86State);
+ x86_Convert(filteredStream, srcLen, 0, &x86State, 1);
+ }
+ }
+
+ {
+ size_t minSize = 0;
+ Bool bestIsFiltered = False;
+
+ /* passes for SZ_FILTER_AUTO:
+ 0 - BCJ + LZMA
+ 1 - LZMA
+ 2 - BCJ + LZMA agaian, if pass 0 (BCJ + LZMA) is better.
+ */
+ int numPasses = (filterMode == SZ_FILTER_AUTO) ? 3 : 1;
+
+ int i;
+ for (i = 0; i < numPasses; i++)
+ {
+ size_t outSizeProcessed = outSize2 - LZMA86_HEADER_SIZE;
+ size_t outPropsSize = 5;
+ SRes curRes;
+ Bool curModeIsFiltered = (numPasses > 1 && i == numPasses - 1);
+ if (curModeIsFiltered && !bestIsFiltered)
+ break;
+ if (useFilter && i == 0)
+ curModeIsFiltered = True;
+
+ curRes = LzmaEncode(dest + LZMA86_HEADER_SIZE, &outSizeProcessed,
+ curModeIsFiltered ? filteredStream : src, srcLen,
+ &props, dest + 1, &outPropsSize, 0,
+ NULL, &g_Alloc, &g_Alloc);
+
+ if (curRes != SZ_ERROR_OUTPUT_EOF)
+ {
+ if (curRes != SZ_OK)
+ {
+ mainResult = curRes;
+ break;
+ }
+ if (outSizeProcessed <= minSize || mainResult != SZ_OK)
+ {
+ minSize = outSizeProcessed;
+ bestIsFiltered = curModeIsFiltered;
+ mainResult = SZ_OK;
+ }
+ }
+ }
+ dest[0] = (bestIsFiltered ? 1 : 0);
+ *destLen = LZMA86_HEADER_SIZE + minSize;
+ }
+ if (useFilter)
+ MyFree(filteredStream);
+ return mainResult;
+}
diff --git a/C/LzmaUtil/Lzma86Enc.h b/C/LzmaUtil/Lzma86Enc.h
new file mode 100755
index 00000000..03258782
--- /dev/null
+++ b/C/LzmaUtil/Lzma86Enc.h
@@ -0,0 +1,72 @@
+/* Lzma86Enc.h -- LZMA + x86 (BCJ) Filter Encoder
+2008-04-07
+Igor Pavlov
+Public domain */
+
+#ifndef __LZMA86ENC_H
+#define __LZMA86ENC_H
+
+#include "../Types.h"
+
+/*
+It's an example for LZMA + x86 Filter use.
+You can use .lzma86 extension, if you write that stream to file.
+.lzma86 header adds one additional byte to standard .lzma header.
+.lzma86 header (14 bytes):
+ Offset Size Description
+ 0 1 = 0 - no filter,
+ = 1 - x86 filter
+ 1 1 lc, lp and pb in encoded form
+ 2 4 dictSize (little endian)
+ 6 8 uncompressed size (little endian)
+
+
+Lzma86_Encode
+-------------
+level - compression level: 0 <= level <= 9, the default value for "level" is 5.
+
+
+dictSize - The dictionary size in bytes. The maximum value is
+ 128 MB = (1 << 27) bytes for 32-bit version
+ 1 GB = (1 << 30) bytes for 64-bit version
+ The default value is 16 MB = (1 << 24) bytes, for level = 5.
+ It's recommended to use the dictionary that is larger than 4 KB and
+ that can be calculated as (1 << N) or (3 << N) sizes.
+ For better compression ratio dictSize must be >= inSize.
+
+filterMode:
+ SZ_FILTER_NO - no Filter
+ SZ_FILTER_YES - x86 Filter
+ SZ_FILTER_AUTO - it tries both alternatives to select best.
+ Encoder will use 2 or 3 passes:
+ 2 passes when FILTER_NO provides better compression.
+ 3 passes when FILTER_YES provides better compression.
+
+Lzma86Encode allocates Data with MyAlloc functions.
+RAM Requirements for compressing:
+ RamSize = dictionarySize * 11.5 + 6MB + FilterBlockSize
+ filterMode FilterBlockSize
+ SZ_FILTER_NO 0
+ SZ_FILTER_YES inSize
+ SZ_FILTER_AUTO inSize
+
+
+Return code:
+ SZ_OK - OK
+ SZ_ERROR_MEM - Memory allocation error
+ SZ_ERROR_PARAM - Incorrect paramater
+ SZ_ERROR_OUTPUT_EOF - output buffer overflow
+ SZ_ERROR_THREAD - errors in multithreading functions (only for Mt version)
+*/
+
+enum ESzFilterMode
+{
+ SZ_FILTER_NO,
+ SZ_FILTER_YES,
+ SZ_FILTER_AUTO
+};
+
+SRes Lzma86_Encode(Byte *dest, size_t *destLen, const Byte *src, size_t srcLen,
+ int level, UInt32 dictSize, int filterMode);
+
+#endif
diff --git a/C/LzmaUtil/LzmaUtil.c b/C/LzmaUtil/LzmaUtil.c
new file mode 100755
index 00000000..a7f3bdff
--- /dev/null
+++ b/C/LzmaUtil/LzmaUtil.c
@@ -0,0 +1,311 @@
+/* LzmaUtil.c -- Test application for LZMA compression
+2008-04-29
+Igor Pavlov
+public domain */
+
+#define _CRT_SECURE_NO_WARNINGS
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+
+#include "../LzmaDec.h"
+#include "../LzmaEnc.h"
+#include "../Alloc.h"
+
+const char *kCantReadMessage = "Can not read input file";
+const char *kCantWriteMessage = "Can not write output file";
+const char *kCantAllocateMessage = "Can not allocate memory";
+const char *kDataErrorMessage = "Data error";
+
+static void *SzAlloc(void *p, size_t size) { p = p; return MyAlloc(size); }
+static void SzFree(void *p, void *address) { p = p; MyFree(address); }
+static ISzAlloc g_Alloc = { SzAlloc, SzFree };
+
+#define kInBufferSize (1 << 15)
+#define kOutBufferSize (1 << 15)
+
+unsigned char g_InBuffer[kInBufferSize];
+unsigned char g_OutBuffer[kOutBufferSize];
+
+size_t MyReadFile(FILE *file, void *data, size_t size)
+ { return fread(data, 1, size, file); }
+
+int MyReadFileAndCheck(FILE *file, void *data, size_t size)
+ { return (MyReadFile(file, data, size) == size); }
+
+size_t MyWriteFile(FILE *file, const void *data, size_t size)
+{
+ if (size == 0)
+ return 0;
+ return fwrite(data, 1, size, file);
+}
+
+int MyWriteFileAndCheck(FILE *file, const void *data, size_t size)
+ { return (MyWriteFile(file, data, size) == size); }
+
+long MyGetFileLength(FILE *file)
+{
+ long length;
+ fseek(file, 0, SEEK_END);
+ length = ftell(file);
+ fseek(file, 0, SEEK_SET);
+ return length;
+}
+
+void PrintHelp(char *buffer)
+{
+ strcat(buffer, "\nLZMA Utility 4.58 Copyright (c) 1999-2008 Igor Pavlov 2008-04-11\n"
+ "\nUsage: lzma <e|d> inputFile outputFile\n"
+ " e: encode file\n"
+ " d: decode file\n");
+}
+
+int PrintError(char *buffer, const char *message)
+{
+ strcat(buffer, "\nError: ");
+ strcat(buffer, message);
+ strcat(buffer, "\n");
+ return 1;
+}
+
+int PrintErrorNumber(char *buffer, SRes val)
+{
+ sprintf(buffer + strlen(buffer), "\nError code: %x\n", (unsigned)val);
+ return 1;
+}
+
+int PrintUserError(char *buffer)
+{
+ return PrintError(buffer, "Incorrect command");
+}
+
+#define IN_BUF_SIZE (1 << 16)
+#define OUT_BUF_SIZE (1 << 16)
+
+static int Decode(FILE *inFile, FILE *outFile, char *rs)
+{
+ UInt64 unpackSize;
+ int thereIsSize; /* = 1, if there is uncompressed size in headers */
+ int i;
+ int res = 0;
+
+ CLzmaDec state;
+
+ /* header: 5 bytes of LZMA properties and 8 bytes of uncompressed size */
+ unsigned char header[LZMA_PROPS_SIZE + 8];
+
+ /* Read and parse header */
+
+ if (!MyReadFileAndCheck(inFile, header, sizeof(header)))
+ return PrintError(rs, kCantReadMessage);
+
+ unpackSize = 0;
+ thereIsSize = 0;
+ for (i = 0; i < 8; i++)
+ {
+ unsigned char b = header[LZMA_PROPS_SIZE + i];
+ if (b != 0xFF)
+ thereIsSize = 1;
+ unpackSize += (UInt64)b << (i * 8);
+ }
+
+ LzmaDec_Construct(&state);
+ res = LzmaDec_Allocate(&state, header, LZMA_PROPS_SIZE, &g_Alloc);
+ if (res != SZ_OK)
+ return res;
+ {
+ Byte inBuf[IN_BUF_SIZE];
+ Byte outBuf[OUT_BUF_SIZE];
+ size_t inPos = 0, inSize = 0, outPos = 0;
+ LzmaDec_Init(&state);
+ for (;;)
+ {
+ if (inPos == inSize)
+ {
+ inSize = MyReadFile(inFile, inBuf, IN_BUF_SIZE);
+ inPos = 0;
+ }
+ {
+ SizeT inProcessed = inSize - inPos;
+ SizeT outProcessed = OUT_BUF_SIZE - outPos;
+ ELzmaFinishMode finishMode = LZMA_FINISH_ANY;
+ ELzmaStatus status;
+ if (thereIsSize && outProcessed > unpackSize)
+ {
+ outProcessed = (SizeT)unpackSize;
+ finishMode = LZMA_FINISH_END;
+ }
+
+ res = LzmaDec_DecodeToBuf(&state, outBuf + outPos, &outProcessed,
+ inBuf + inPos, &inProcessed, finishMode, &status);
+ inPos += (UInt32)inProcessed;
+ outPos += outProcessed;
+ unpackSize -= outProcessed;
+
+ if (outFile != 0)
+ MyWriteFile(outFile, outBuf, outPos);
+ outPos = 0;
+
+ if (res != SZ_OK || thereIsSize && unpackSize == 0)
+ break;
+
+ if (inProcessed == 0 && outProcessed == 0)
+ {
+ if (thereIsSize || status != LZMA_STATUS_FINISHED_WITH_MARK)
+ res = SZ_ERROR_DATA;
+ break;
+ }
+ }
+ }
+ }
+
+ LzmaDec_Free(&state, &g_Alloc);
+ return res;
+}
+
+typedef struct _CFileSeqInStream
+{
+ ISeqInStream funcTable;
+ FILE *file;
+} CFileSeqInStream;
+
+static SRes MyRead(void *p, void *buf, size_t *size)
+{
+ if (*size == 0)
+ return SZ_OK;
+ *size = MyReadFile(((CFileSeqInStream*)p)->file, buf, *size);
+ /*
+ if (*size == 0)
+ return SZE_FAIL;
+ */
+ return SZ_OK;
+}
+
+typedef struct _CFileSeqOutStream
+{
+ ISeqOutStream funcTable;
+ FILE *file;
+} CFileSeqOutStream;
+
+static size_t MyWrite(void *pp, const void *buf, size_t size)
+{
+ return MyWriteFile(((CFileSeqOutStream *)pp)->file, buf, size);
+}
+
+static SRes Encode(FILE *inFile, FILE *outFile, char *rs)
+{
+ CLzmaEncHandle enc;
+ SRes res;
+ CFileSeqInStream inStream;
+ CFileSeqOutStream outStream;
+ CLzmaEncProps props;
+
+ enc = LzmaEnc_Create(&g_Alloc);
+ if (enc == 0)
+ return SZ_ERROR_MEM;
+
+ inStream.funcTable.Read = MyRead;
+ inStream.file = inFile;
+ outStream.funcTable.Write = MyWrite;
+ outStream.file = outFile;
+
+ LzmaEncProps_Init(&props);
+ res = LzmaEnc_SetProps(enc, &props);
+
+ if (res == SZ_OK)
+ {
+ Byte header[LZMA_PROPS_SIZE + 8];
+ size_t headerSize = LZMA_PROPS_SIZE;
+ UInt64 fileSize;
+ int i;
+
+ res = LzmaEnc_WriteProperties(enc, header, &headerSize);
+ fileSize = MyGetFileLength(inFile);
+ for (i = 0; i < 8; i++)
+ header[headerSize++] = (Byte)(fileSize >> (8 * i));
+ if (!MyWriteFileAndCheck(outFile, header, headerSize))
+ return PrintError(rs, "writing error");
+
+ if (res == SZ_OK)
+ res = LzmaEnc_Encode(enc, &outStream.funcTable, &inStream.funcTable,
+ NULL, &g_Alloc, &g_Alloc);
+ }
+ LzmaEnc_Destroy(enc, &g_Alloc, &g_Alloc);
+ return res;
+}
+
+int main2(int numArgs, const char *args[], char *rs)
+{
+ FILE *inFile = 0;
+ FILE *outFile = 0;
+ char c;
+ int res;
+ int encodeMode;
+
+ if (numArgs == 1)
+ {
+ PrintHelp(rs);
+ return 0;
+ }
+
+ if (numArgs < 3 || numArgs > 4 || strlen(args[1]) != 1)
+ return PrintUserError(rs);
+
+ c = args[1][0];
+ encodeMode = (c == 'e' || c == 'E');
+ if (!encodeMode && c != 'd' && c != 'D')
+ return PrintUserError(rs);
+
+ {
+ size_t t4 = sizeof(UInt32);
+ size_t t8 = sizeof(UInt64);
+ if (t4 != 4 || t8 != 8)
+ return PrintError(rs, "LZMA UTil needs correct UInt32 and UInt64");
+ }
+
+ inFile = fopen(args[2], "rb");
+ if (inFile == 0)
+ return PrintError(rs, "Can not open input file");
+
+ if (numArgs > 3)
+ {
+ outFile = fopen(args[3], "wb+");
+ if (outFile == 0)
+ return PrintError(rs, "Can not open output file");
+ }
+ else if (encodeMode)
+ PrintUserError(rs);
+
+ if (encodeMode)
+ {
+ res = Encode(inFile, outFile, rs);
+ }
+ else
+ {
+ res = Decode(inFile, outFile, rs);
+ }
+
+ if (outFile != 0)
+ fclose(outFile);
+ fclose(inFile);
+
+ if (res != SZ_OK)
+ {
+ if (res == SZ_ERROR_MEM)
+ return PrintError(rs, kCantAllocateMessage);
+ else if (res == SZ_ERROR_DATA)
+ return PrintError(rs, kDataErrorMessage);
+ else
+ return PrintErrorNumber(rs, res);
+ }
+ return 0;
+}
+
+int MY_CDECL main(int numArgs, const char *args[])
+{
+ char rs[800] = { 0 };
+ int res = main2(numArgs, args, rs);
+ printf(rs);
+ return res;
+}
diff --git a/C/LzmaUtil/LzmaUtil.dsp b/C/LzmaUtil/LzmaUtil.dsp
new file mode 100755
index 00000000..77c03edd
--- /dev/null
+++ b/C/LzmaUtil/LzmaUtil.dsp
@@ -0,0 +1,152 @@
+# Microsoft Developer Studio Project File - Name="LzmaUtil" - Package Owner=<4>
+# Microsoft Developer Studio Generated Build File, Format Version 6.00
+# ** DO NOT EDIT **
+
+# TARGTYPE "Win32 (x86) Console Application" 0x0103
+
+CFG=LzmaUtil - Win32 Debug
+!MESSAGE This is not a valid makefile. To build this project using NMAKE,
+!MESSAGE use the Export Makefile command and run
+!MESSAGE
+!MESSAGE NMAKE /f "LzmaUtil.mak".
+!MESSAGE
+!MESSAGE You can specify a configuration when running NMAKE
+!MESSAGE by defining the macro CFG on the command line. For example:
+!MESSAGE
+!MESSAGE NMAKE /f "LzmaUtil.mak" CFG="LzmaUtil - Win32 Debug"
+!MESSAGE
+!MESSAGE Possible choices for configuration are:
+!MESSAGE
+!MESSAGE "LzmaUtil - Win32 Release" (based on "Win32 (x86) Console Application")
+!MESSAGE "LzmaUtil - Win32 Debug" (based on "Win32 (x86) Console Application")
+!MESSAGE
+
+# Begin Project
+# PROP AllowPerConfigDependencies 0
+# PROP Scc_ProjName ""
+# PROP Scc_LocalPath ""
+CPP=cl.exe
+RSC=rc.exe
+
+!IF "$(CFG)" == "LzmaUtil - Win32 Release"
+
+# PROP BASE Use_MFC 0
+# PROP BASE Use_Debug_Libraries 0
+# PROP BASE Output_Dir "Release"
+# PROP BASE Intermediate_Dir "Release"
+# PROP BASE Target_Dir ""
+# PROP Use_MFC 0
+# PROP Use_Debug_Libraries 0
+# PROP Output_Dir "Release"
+# PROP Intermediate_Dir "Release"
+# PROP Ignore_Export_Lib 0
+# PROP Target_Dir ""
+# ADD BASE CPP /nologo /W3 /GX /O2 /D "WIN32" /D "NDEBUG" /D "_CONSOLE" /D "_MBCS" /YX /FD /c
+# ADD CPP /nologo /MT /W3 /O2 /D "WIN32" /D "NDEBUG" /D "_CONSOLE" /D "_MBCS" /FD /c
+# SUBTRACT CPP /YX
+# ADD BASE RSC /l 0x419 /d "NDEBUG"
+# ADD RSC /l 0x419 /d "NDEBUG"
+BSC32=bscmake.exe
+# ADD BASE BSC32 /nologo
+# ADD BSC32 /nologo
+LINK32=link.exe
+# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /machine:I386
+# ADD LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /machine:I386 /out:"c:\util\lzmac.exe"
+
+!ELSEIF "$(CFG)" == "LzmaUtil - Win32 Debug"
+
+# PROP BASE Use_MFC 0
+# PROP BASE Use_Debug_Libraries 1
+# PROP BASE Output_Dir "Debug"
+# PROP BASE Intermediate_Dir "Debug"
+# PROP BASE Target_Dir ""
+# PROP Use_MFC 0
+# PROP Use_Debug_Libraries 1
+# PROP Output_Dir "Debug"
+# PROP Intermediate_Dir "Debug"
+# PROP Ignore_Export_Lib 0
+# PROP Target_Dir ""
+# ADD BASE CPP /nologo /W3 /Gm /GX /ZI /Od /D "WIN32" /D "_DEBUG" /D "_CONSOLE" /D "_MBCS" /YX /FD /GZ /c
+# ADD CPP /nologo /MTd /W3 /Gm /ZI /Od /D "WIN32" /D "_DEBUG" /D "_CONSOLE" /D "_MBCS" /FD /GZ /c
+# SUBTRACT CPP /YX
+# ADD BASE RSC /l 0x419 /d "_DEBUG"
+# ADD RSC /l 0x419 /d "_DEBUG"
+BSC32=bscmake.exe
+# ADD BASE BSC32 /nologo
+# ADD BSC32 /nologo
+LINK32=link.exe
+# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /debug /machine:I386 /pdbtype:sept
+# ADD LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /debug /machine:I386 /out:"c:\util\lzmac.exe" /pdbtype:sept
+
+!ENDIF
+
+# Begin Target
+
+# Name "LzmaUtil - Win32 Release"
+# Name "LzmaUtil - Win32 Debug"
+# Begin Source File
+
+SOURCE=..\Alloc.c
+# End Source File
+# Begin Source File
+
+SOURCE=..\Alloc.h
+# End Source File
+# Begin Source File
+
+SOURCE=..\CpuArch.h
+# End Source File
+# Begin Source File
+
+SOURCE=..\LzFind.c
+# End Source File
+# Begin Source File
+
+SOURCE=..\LzFind.h
+# End Source File
+# Begin Source File
+
+SOURCE=..\LzFindMt.c
+# End Source File
+# Begin Source File
+
+SOURCE=..\LzFindMt.h
+# End Source File
+# Begin Source File
+
+SOURCE=..\LzHash.h
+# End Source File
+# Begin Source File
+
+SOURCE=..\LzmaDec.c
+# End Source File
+# Begin Source File
+
+SOURCE=..\LzmaDec.h
+# End Source File
+# Begin Source File
+
+SOURCE=..\LzmaEnc.c
+# End Source File
+# Begin Source File
+
+SOURCE=..\LzmaEnc.h
+# End Source File
+# Begin Source File
+
+SOURCE=.\LzmaUtil.c
+# End Source File
+# Begin Source File
+
+SOURCE=..\Threads.c
+# End Source File
+# Begin Source File
+
+SOURCE=..\Threads.h
+# End Source File
+# Begin Source File
+
+SOURCE=..\Types.h
+# End Source File
+# End Target
+# End Project
diff --git a/C/Archive/7z/7z_C.dsw b/C/LzmaUtil/LzmaUtil.dsw
index 6fd39621..c52eaf6d 100755
--- a/C/Archive/7z/7z_C.dsw
+++ b/C/LzmaUtil/LzmaUtil.dsw
@@ -3,7 +3,7 @@ Microsoft Developer Studio Workspace File, Format Version 6.00
###############################################################################
-Project: "7z_C"=.\7z_C.dsp - Package Owner=<4>
+Project: "LzmaUtil"=.\LzmaUtil.dsp - Package Owner=<4>
Package=<5>
{{{
diff --git a/C/LzmaUtil/makefile b/C/LzmaUtil/makefile
new file mode 100755
index 00000000..11cada4e
--- /dev/null
+++ b/C/LzmaUtil/makefile
@@ -0,0 +1,27 @@
+MY_STATIC_LINK=1
+PROG = LZMAc.exe
+
+CFLAGS = $(CFLAGS) \
+ -DCOMPRESS_MF_MT \
+
+LIB_OBJS = \
+ $O\LzmaUtil.obj \
+
+C_OBJS = \
+ $O\Alloc.obj \
+ $O\LzFind.obj \
+ $O\LzFindMt.obj \
+ $O\LzmaDec.obj \
+ $O\LzmaEnc.obj \
+ $O\Threads.obj \
+
+OBJS = \
+ $(LIB_OBJS) \
+ $(C_OBJS) \
+
+!include "../../CPP/Build.mak"
+
+$(LIB_OBJS): $(*B).c
+ $(COMPL_O2)
+$(C_OBJS): ../$(*B).c
+ $(COMPL_O2)
diff --git a/C/LzmaUtil/makefile.gcc b/C/LzmaUtil/makefile.gcc
new file mode 100755
index 00000000..bfcdc3c3
--- /dev/null
+++ b/C/LzmaUtil/makefile.gcc
@@ -0,0 +1,36 @@
+PROG = lzma
+CXX = g++
+LIB =
+RM = rm -f
+CFLAGS = -c -O2 -Wall
+
+OBJS = \
+ LzmaUtil.o \
+ Alloc.o \
+ LzFind.o \
+ LzmaDec.o \
+ LzmaEnc.o \
+
+
+all: $(PROG)
+
+$(PROG): $(OBJS)
+ $(CXX) -o $(PROG) $(LDFLAGS) $(OBJS) $(LIB) $(LIB2)
+
+LzmaUtil.o: LzmaUtil.c
+ $(CXX) $(CFLAGS) LzmaUtil.c
+
+Alloc.o: ../Alloc.c
+ $(CXX) $(CFLAGS) ../Alloc.c
+
+LzFind.o: ../LzFind.c
+ $(CXX) $(CFLAGS) ../LzFind.c
+
+LzmaDec.o: ../LzmaDec.c
+ $(CXX) $(CFLAGS) ../LzmaDec.c
+
+LzmaEnc.o: ../LzmaEnc.c
+ $(CXX) $(CFLAGS) ../LzmaEnc.c
+
+clean:
+ -$(RM) $(PROG) $(OBJS)
diff --git a/CPP/7zip/Crypto/Hash/RotateDefs.h b/C/RotateDefs.h
index 832e7357..cd666271 100755
--- a/CPP/7zip/Crypto/Hash/RotateDefs.h
+++ b/C/RotateDefs.h
@@ -1,11 +1,14 @@
-// RotateDefs.h
+/* RotateDefs.h -- Rotate functions
+2008-03-24
+Igor Pavlov
+Public domain */
#ifndef __ROTATEDEFS_H
#define __ROTATEDEFS_H
#ifdef _MSC_VER
-#include <stddef.h>
+#include <stdlib.h>
#define rotlFixed(x, n) _rotl((x), (n))
#define rotrFixed(x, n) _rotr((x), (n))
diff --git a/CPP/7zip/Crypto/Hash/Sha256.cpp b/C/Sha256.c
index db236058..f052c0ec 100755
--- a/CPP/7zip/Crypto/Hash/Sha256.cpp
+++ b/C/Sha256.c
@@ -1,30 +1,27 @@
-// Crypto/Sha256.cpp
-// This code is based on code from Wei Dai's Crypto++ library.
-
-#include "StdAfx.h"
+/* Crypto/Sha256.c -- SHA-256 Hash function
+2008-03-24
+This code is based on public domain code from Wei Dai's Crypto++ library.
+Igor Pavlov
+Public domain */
#include "Sha256.h"
#include "RotateDefs.h"
-namespace NCrypto {
-namespace NSha256 {
-
-// define it for speed optimization
-// #define _SHA256_UNROLL
-// #define _SHA256_UNROLL2
+/* define it for speed optimization */
+/* #define _SHA256_UNROLL */
+/* #define _SHA256_UNROLL2 */
-void CContext::Init()
+void Sha256_Init(CSha256 *p)
{
- _state[0] = 0x6a09e667;
- _state[1] = 0xbb67ae85;
- _state[2] = 0x3c6ef372;
- _state[3] = 0xa54ff53a;
- _state[4] = 0x510e527f;
- _state[5] = 0x9b05688c;
- _state[6] = 0x1f83d9ab;
- _state[7] = 0x5be0cd19;
-
- _count = 0;
+ p->state[0] = 0x6a09e667;
+ p->state[1] = 0xbb67ae85;
+ p->state[2] = 0x3c6ef372;
+ p->state[3] = 0xa54ff53a;
+ p->state[4] = 0x510e527f;
+ p->state[5] = 0x9b05688c;
+ p->state[6] = 0x1f83d9ab;
+ p->state[7] = 0x5be0cd19;
+ p->count = 0;
}
#define S0(x) (rotrFixed(x, 2) ^ rotrFixed(x,13) ^ rotrFixed(x, 22))
@@ -76,11 +73,29 @@ void CContext::Init()
#endif
+const UInt32 K[64] = {
+ 0x428a2f98, 0x71374491, 0xb5c0fbcf, 0xe9b5dba5,
+ 0x3956c25b, 0x59f111f1, 0x923f82a4, 0xab1c5ed5,
+ 0xd807aa98, 0x12835b01, 0x243185be, 0x550c7dc3,
+ 0x72be5d74, 0x80deb1fe, 0x9bdc06a7, 0xc19bf174,
+ 0xe49b69c1, 0xefbe4786, 0x0fc19dc6, 0x240ca1cc,
+ 0x2de92c6f, 0x4a7484aa, 0x5cb0a9dc, 0x76f988da,
+ 0x983e5152, 0xa831c66d, 0xb00327c8, 0xbf597fc7,
+ 0xc6e00bf3, 0xd5a79147, 0x06ca6351, 0x14292967,
+ 0x27b70a85, 0x2e1b2138, 0x4d2c6dfc, 0x53380d13,
+ 0x650a7354, 0x766a0abb, 0x81c2c92e, 0x92722c85,
+ 0xa2bfe8a1, 0xa81a664b, 0xc24b8b70, 0xc76c51a3,
+ 0xd192e819, 0xd6990624, 0xf40e3585, 0x106aa070,
+ 0x19a4c116, 0x1e376c08, 0x2748774c, 0x34b0bcb5,
+ 0x391c0cb3, 0x4ed8aa4a, 0x5b9cca4f, 0x682e6ff3,
+ 0x748f82ee, 0x78a5636f, 0x84c87814, 0x8cc70208,
+ 0x90befffa, 0xa4506ceb, 0xbef9a3f7, 0xc67178f2
+};
-void CContext::Transform(UInt32 *state, const UInt32 *data)
+static void Sha256_Transform(UInt32 *state, const UInt32 *data)
{
UInt32 W[16];
-
+ unsigned j;
#ifdef _SHA256_UNROLL2
UInt32 a,b,c,d,e,f,g,h;
a = state[0];
@@ -93,16 +108,17 @@ void CContext::Transform(UInt32 *state, const UInt32 *data)
h = state[7];
#else
UInt32 T[8];
- for (int s = 0; s < 8; s++)
- T[s] = state[s];
+ for (j = 0; j < 8; j++)
+ T[j] = state[j];
#endif
- for (unsigned int j = 0; j < 64; j += 16)
+ for (j = 0; j < 64; j += 16)
{
#if defined(_SHA256_UNROLL) || defined(_SHA256_UNROLL2)
RX_8(0); RX_8(8);
#else
- for (unsigned int i = 0; i < 16; i++) { R(i); }
+ unsigned i;
+ for (i = 0; i < 16; i++) { R(i); }
#endif
}
@@ -116,95 +132,75 @@ void CContext::Transform(UInt32 *state, const UInt32 *data)
state[6] += g;
state[7] += h;
#else
- for (int i = 0; i < 8; i++)
- state[i] += T[i];
+ for (j = 0; j < 8; j++)
+ state[j] += T[j];
#endif
- // Wipe variables
- // memset(W, 0, sizeof(W));
- // memset(T, 0, sizeof(T));
+ /* Wipe variables */
+ /* memset(W, 0, sizeof(W)); */
+ /* memset(T, 0, sizeof(T)); */
}
-const UInt32 CContext::K[64] = {
- 0x428a2f98, 0x71374491, 0xb5c0fbcf, 0xe9b5dba5,
- 0x3956c25b, 0x59f111f1, 0x923f82a4, 0xab1c5ed5,
- 0xd807aa98, 0x12835b01, 0x243185be, 0x550c7dc3,
- 0x72be5d74, 0x80deb1fe, 0x9bdc06a7, 0xc19bf174,
- 0xe49b69c1, 0xefbe4786, 0x0fc19dc6, 0x240ca1cc,
- 0x2de92c6f, 0x4a7484aa, 0x5cb0a9dc, 0x76f988da,
- 0x983e5152, 0xa831c66d, 0xb00327c8, 0xbf597fc7,
- 0xc6e00bf3, 0xd5a79147, 0x06ca6351, 0x14292967,
- 0x27b70a85, 0x2e1b2138, 0x4d2c6dfc, 0x53380d13,
- 0x650a7354, 0x766a0abb, 0x81c2c92e, 0x92722c85,
- 0xa2bfe8a1, 0xa81a664b, 0xc24b8b70, 0xc76c51a3,
- 0xd192e819, 0xd6990624, 0xf40e3585, 0x106aa070,
- 0x19a4c116, 0x1e376c08, 0x2748774c, 0x34b0bcb5,
- 0x391c0cb3, 0x4ed8aa4a, 0x5b9cca4f, 0x682e6ff3,
- 0x748f82ee, 0x78a5636f, 0x84c87814, 0x8cc70208,
- 0x90befffa, 0xa4506ceb, 0xbef9a3f7, 0xc67178f2
-};
-
#undef S0
#undef S1
#undef s0
#undef s1
-void CContext::WriteByteBlock()
+static void Sha256_WriteByteBlock(CSha256 *p)
{
UInt32 data32[16];
- for (int i = 0; i < 16; i++)
- {
- data32[i] = (UInt32(_buffer[i * 4]) << 24) +
- (UInt32(_buffer[i * 4 + 1]) << 16) +
- (UInt32(_buffer[i * 4 + 2]) << 8) +
- UInt32(_buffer[i * 4 + 3]);
- }
- Transform(_state, data32);
+ unsigned i;
+ for (i = 0; i < 16; i++)
+ data32[i] =
+ ((UInt32)(p->buffer[i * 4 ]) << 24) +
+ ((UInt32)(p->buffer[i * 4 + 1]) << 16) +
+ ((UInt32)(p->buffer[i * 4 + 2]) << 8) +
+ ((UInt32)(p->buffer[i * 4 + 3]));
+ Sha256_Transform(p->state, data32);
}
-void CContext::Update(const Byte *data, size_t size)
+void Sha256_Update(CSha256 *p, const Byte *data, size_t size)
{
- UInt32 curBufferPos = (UInt32)_count & 0x3F;
+ UInt32 curBufferPos = (UInt32)p->count & 0x3F;
while (size > 0)
{
- _buffer[curBufferPos++] = *data++;
- _count++;
+ p->buffer[curBufferPos++] = *data++;
+ p->count++;
size--;
if (curBufferPos == 64)
{
curBufferPos = 0;
- WriteByteBlock();
+ Sha256_WriteByteBlock(p);
}
}
}
-void CContext::Final(Byte *digest)
+void Sha256_Final(CSha256 *p, Byte *digest)
{
- UInt64 lenInBits = (_count << 3);
- UInt32 curBufferPos = (UInt32)_count & 0x3F;
- _buffer[curBufferPos++] = 0x80;
+ UInt64 lenInBits = (p->count << 3);
+ UInt32 curBufferPos = (UInt32)p->count & 0x3F;
+ unsigned i;
+ p->buffer[curBufferPos++] = 0x80;
while (curBufferPos != (64 - 8))
{
curBufferPos &= 0x3F;
if (curBufferPos == 0)
- WriteByteBlock();
- _buffer[curBufferPos++] = 0;
+ Sha256_WriteByteBlock(p);
+ p->buffer[curBufferPos++] = 0;
}
- for (int i = 0; i < 8; i++)
+ for (i = 0; i < 8; i++)
{
- _buffer[curBufferPos++] = (Byte)(lenInBits >> 56);
+ p->buffer[curBufferPos++] = (Byte)(lenInBits >> 56);
lenInBits <<= 8;
}
- WriteByteBlock();
+ Sha256_WriteByteBlock(p);
- for (int j = 0; j < 8; j++)
+ for (i = 0; i < 8; i++)
{
- *digest++ = (Byte)(_state[j] >> 24);
- *digest++ = (Byte)(_state[j] >> 16);
- *digest++ = (Byte)(_state[j] >> 8);
- *digest++ = (Byte)(_state[j]);
+ *digest++ = (Byte)(p->state[i] >> 24);
+ *digest++ = (Byte)(p->state[i] >> 16);
+ *digest++ = (Byte)(p->state[i] >> 8);
+ *digest++ = (Byte)(p->state[i]);
}
- Init();
+ Sha256_Init(p);
}
-
-}}
diff --git a/C/Sha256.h b/C/Sha256.h
new file mode 100755
index 00000000..37d6b059
--- /dev/null
+++ b/C/Sha256.h
@@ -0,0 +1,24 @@
+/* Crypto/Sha256.h -- SHA-256 Hash function
+2008-03-24
+Igor Pavlov
+Public domain */
+
+#ifndef __CRYPTO_SHA256_H
+#define __CRYPTO_SHA256_H
+
+#include "Types.h"
+
+#define SHA256_DIGEST_SIZE 32
+
+typedef struct
+{
+ UInt32 state[8];
+ UInt64 count;
+ Byte buffer[64];
+} CSha256;
+
+void Sha256_Init(CSha256 *p);
+void Sha256_Update(CSha256 *p, const Byte *data, size_t size);
+void Sha256_Final(CSha256 *p, Byte *digest);
+
+#endif
diff --git a/C/Sort.c b/C/Sort.c
index b30cd6ab..15e4c6e3 100755
--- a/C/Sort.c
+++ b/C/Sort.c
@@ -1,4 +1,7 @@
-/* Sort.c */
+/* Sort.c -- Sort functions
+2008-03-13
+Igor Pavlov
+Public domain */
#include "Sort.h"
diff --git a/C/Sort.h b/C/Sort.h
index 896243c1..37242749 100755
--- a/C/Sort.h
+++ b/C/Sort.h
@@ -1,7 +1,10 @@
-/* Sort.h */
+/* Sort.h -- Sort functions
+2008-03-19
+Igor Pavlov
+Public domain */
-#ifndef __7Z_Sort_H
-#define __7Z_Sort_H
+#ifndef __7Z_SORT_H
+#define __7Z_SORT_H
#include "Types.h"
diff --git a/C/Threads.c b/C/Threads.c
index def48175..237f3f90 100755
--- a/C/Threads.c
+++ b/C/Threads.c
@@ -1,98 +1,101 @@
-/* Threads.c */
+/* Threads.c -- multithreading library
+2008-04-04
+Igor Pavlov
+Public domain */
#include "Threads.h"
#include <process.h>
-HRes GetError()
+static WRes GetError()
{
DWORD res = GetLastError();
- return (res) ? (HRes)(res) : SZE_FAIL;
+ return (res) ? (WRes)(res) : 1;
}
-HRes BoolToHRes(int v) { return v ? SZ_OK : GetError(); }
-HRes BOOLToHRes(BOOL v) { return v ? SZ_OK : GetError(); }
+WRes HandleToWRes(HANDLE h) { return (h != 0) ? 0 : GetError(); }
+WRes BOOLToWRes(BOOL v) { return v ? 0 : GetError(); }
-HRes MyCloseHandle(HANDLE *h)
+static WRes MyCloseHandle(HANDLE *h)
{
if (*h != NULL)
if (!CloseHandle(*h))
return GetError();
*h = NULL;
- return SZ_OK;
+ return 0;
}
-HRes Thread_Create(CThread *thread, THREAD_FUNC_RET_TYPE (THREAD_FUNC_CALL_TYPE *startAddress)(void *), LPVOID parameter)
+WRes Thread_Create(CThread *thread, THREAD_FUNC_RET_TYPE (THREAD_FUNC_CALL_TYPE *startAddress)(void *), LPVOID parameter)
{
unsigned threadId; /* Windows Me/98/95: threadId parameter may not be NULL in _beginthreadex/CreateThread functions */
thread->handle =
/* CreateThread(0, 0, startAddress, parameter, 0, &threadId); */
(HANDLE)_beginthreadex(NULL, 0, startAddress, parameter, 0, &threadId);
/* maybe we must use errno here, but probably GetLastError() is also OK. */
- return BoolToHRes(thread->handle != 0);
+ return HandleToWRes(thread->handle);
}
-HRes WaitObject(HANDLE h)
+WRes WaitObject(HANDLE h)
{
- return (HRes)WaitForSingleObject(h, INFINITE);
+ return (WRes)WaitForSingleObject(h, INFINITE);
}
-HRes Thread_Wait(CThread *thread)
+WRes Thread_Wait(CThread *thread)
{
if (thread->handle == NULL)
return 1;
return WaitObject(thread->handle);
}
-HRes Thread_Close(CThread *thread)
+WRes Thread_Close(CThread *thread)
{
return MyCloseHandle(&thread->handle);
}
-HRes Event_Create(CEvent *p, BOOL manualReset, int initialSignaled)
+WRes Event_Create(CEvent *p, BOOL manualReset, int initialSignaled)
{
p->handle = CreateEvent(NULL, manualReset, (initialSignaled ? TRUE : FALSE), NULL);
- return BoolToHRes(p->handle != 0);
+ return HandleToWRes(p->handle);
}
-HRes ManualResetEvent_Create(CManualResetEvent *p, int initialSignaled)
+WRes ManualResetEvent_Create(CManualResetEvent *p, int initialSignaled)
{ return Event_Create(p, TRUE, initialSignaled); }
-HRes ManualResetEvent_CreateNotSignaled(CManualResetEvent *p)
+WRes ManualResetEvent_CreateNotSignaled(CManualResetEvent *p)
{ return ManualResetEvent_Create(p, 0); }
-HRes AutoResetEvent_Create(CAutoResetEvent *p, int initialSignaled)
+WRes AutoResetEvent_Create(CAutoResetEvent *p, int initialSignaled)
{ return Event_Create(p, FALSE, initialSignaled); }
-HRes AutoResetEvent_CreateNotSignaled(CAutoResetEvent *p)
+WRes AutoResetEvent_CreateNotSignaled(CAutoResetEvent *p)
{ return AutoResetEvent_Create(p, 0); }
-HRes Event_Set(CEvent *p) { return BOOLToHRes(SetEvent(p->handle)); }
-HRes Event_Reset(CEvent *p) { return BOOLToHRes(ResetEvent(p->handle)); }
-HRes Event_Wait(CEvent *p) { return WaitObject(p->handle); }
-HRes Event_Close(CEvent *p) { return MyCloseHandle(&p->handle); }
+WRes Event_Set(CEvent *p) { return BOOLToWRes(SetEvent(p->handle)); }
+WRes Event_Reset(CEvent *p) { return BOOLToWRes(ResetEvent(p->handle)); }
+WRes Event_Wait(CEvent *p) { return WaitObject(p->handle); }
+WRes Event_Close(CEvent *p) { return MyCloseHandle(&p->handle); }
-HRes Semaphore_Create(CSemaphore *p, UInt32 initiallyCount, UInt32 maxCount)
+WRes Semaphore_Create(CSemaphore *p, UInt32 initiallyCount, UInt32 maxCount)
{
p->handle = CreateSemaphore(NULL, (LONG)initiallyCount, (LONG)maxCount, NULL);
- return BoolToHRes(p->handle != 0);
+ return HandleToWRes(p->handle);
}
-HRes Semaphore_Release(CSemaphore *p, LONG releaseCount, LONG *previousCount)
+WRes Semaphore_Release(CSemaphore *p, LONG releaseCount, LONG *previousCount)
{
- return BOOLToHRes(ReleaseSemaphore(p->handle, releaseCount, previousCount));
+ return BOOLToWRes(ReleaseSemaphore(p->handle, releaseCount, previousCount));
}
-HRes Semaphore_ReleaseN(CSemaphore *p, UInt32 releaseCount)
+WRes Semaphore_ReleaseN(CSemaphore *p, UInt32 releaseCount)
{
return Semaphore_Release(p, (LONG)releaseCount, NULL);
}
-HRes Semaphore_Release1(CSemaphore *p)
+WRes Semaphore_Release1(CSemaphore *p)
{
return Semaphore_ReleaseN(p, 1);
}
-HRes Semaphore_Wait(CSemaphore *p) { return WaitObject(p->handle); }
-HRes Semaphore_Close(CSemaphore *p) { return MyCloseHandle(&p->handle); }
+WRes Semaphore_Wait(CSemaphore *p) { return WaitObject(p->handle); }
+WRes Semaphore_Close(CSemaphore *p) { return MyCloseHandle(&p->handle); }
-HRes CriticalSection_Init(CCriticalSection *p)
+WRes CriticalSection_Init(CCriticalSection *p)
{
/* InitializeCriticalSection can raise only STATUS_NO_MEMORY exception */
__try
@@ -100,7 +103,7 @@ HRes CriticalSection_Init(CCriticalSection *p)
InitializeCriticalSection(p);
/* InitializeCriticalSectionAndSpinCount(p, 0); */
}
- __except (EXCEPTION_EXECUTE_HANDLER) { return SZE_OUTOFMEMORY; }
- return SZ_OK;
+ __except (EXCEPTION_EXECUTE_HANDLER) { return 1; }
+ return 0;
}
diff --git a/C/Threads.h b/C/Threads.h
index c024dcc6..03bea106 100755
--- a/C/Threads.h
+++ b/C/Threads.h
@@ -1,4 +1,7 @@
-/* Threads.h */
+/* Threads.h -- multithreading library
+2008-04-11
+Igor Pavlov
+Public domain */
#ifndef __7Z_THRESDS_H
#define __7Z_THRESDS_H
@@ -16,12 +19,14 @@ typedef struct _CThread
#define Thread_WasCreated(thread) ((thread)->handle != NULL)
typedef unsigned THREAD_FUNC_RET_TYPE;
-#define THREAD_FUNC_CALL_TYPE StdCall
+#define THREAD_FUNC_CALL_TYPE MY_STD_CALL
#define THREAD_FUNC_DECL THREAD_FUNC_RET_TYPE THREAD_FUNC_CALL_TYPE
-HRes Thread_Create(CThread *thread, THREAD_FUNC_RET_TYPE (THREAD_FUNC_CALL_TYPE *startAddress)(void *), LPVOID parameter);
-HRes Thread_Wait(CThread *thread);
-HRes Thread_Close(CThread *thread);
+typedef DWORD WRes;
+
+WRes Thread_Create(CThread *thread, THREAD_FUNC_RET_TYPE (THREAD_FUNC_CALL_TYPE *startAddress)(void *), LPVOID parameter);
+WRes Thread_Wait(CThread *thread);
+WRes Thread_Close(CThread *thread);
typedef struct _CEvent
{
@@ -34,14 +39,14 @@ typedef CEvent CManualResetEvent;
#define Event_Construct(event) (event)->handle = NULL
#define Event_IsCreated(event) ((event)->handle != NULL)
-HRes ManualResetEvent_Create(CManualResetEvent *event, int initialSignaled);
-HRes ManualResetEvent_CreateNotSignaled(CManualResetEvent *event);
-HRes AutoResetEvent_Create(CAutoResetEvent *event, int initialSignaled);
-HRes AutoResetEvent_CreateNotSignaled(CAutoResetEvent *event);
-HRes Event_Set(CEvent *event);
-HRes Event_Reset(CEvent *event);
-HRes Event_Wait(CEvent *event);
-HRes Event_Close(CEvent *event);
+WRes ManualResetEvent_Create(CManualResetEvent *event, int initialSignaled);
+WRes ManualResetEvent_CreateNotSignaled(CManualResetEvent *event);
+WRes AutoResetEvent_Create(CAutoResetEvent *event, int initialSignaled);
+WRes AutoResetEvent_CreateNotSignaled(CAutoResetEvent *event);
+WRes Event_Set(CEvent *event);
+WRes Event_Reset(CEvent *event);
+WRes Event_Wait(CEvent *event);
+WRes Event_Close(CEvent *event);
typedef struct _CSemaphore
@@ -51,16 +56,16 @@ typedef struct _CSemaphore
#define Semaphore_Construct(p) (p)->handle = NULL
-HRes Semaphore_Create(CSemaphore *p, UInt32 initiallyCount, UInt32 maxCount);
-HRes Semaphore_ReleaseN(CSemaphore *p, UInt32 num);
-HRes Semaphore_Release1(CSemaphore *p);
-HRes Semaphore_Wait(CSemaphore *p);
-HRes Semaphore_Close(CSemaphore *p);
+WRes Semaphore_Create(CSemaphore *p, UInt32 initiallyCount, UInt32 maxCount);
+WRes Semaphore_ReleaseN(CSemaphore *p, UInt32 num);
+WRes Semaphore_Release1(CSemaphore *p);
+WRes Semaphore_Wait(CSemaphore *p);
+WRes Semaphore_Close(CSemaphore *p);
typedef CRITICAL_SECTION CCriticalSection;
-HRes CriticalSection_Init(CCriticalSection *p);
+WRes CriticalSection_Init(CCriticalSection *p);
#define CriticalSection_Delete(p) DeleteCriticalSection(p)
#define CriticalSection_Enter(p) EnterCriticalSection(p)
#define CriticalSection_Leave(p) LeaveCriticalSection(p)
diff --git a/C/Types.h b/C/Types.h
index 368cc314..956e2721 100755
--- a/C/Types.h
+++ b/C/Types.h
@@ -1,100 +1,130 @@
-/* 7zTypes.h */
+/* Types.h -- Basic types
+2008-04-11
+Igor Pavlov
+Public domain */
+
+#ifndef __7Z_TYPES_H
+#define __7Z_TYPES_H
+
+#define SZ_OK 0
+
+#define SZ_ERROR_DATA 1
+#define SZ_ERROR_MEM 2
+#define SZ_ERROR_CRC 3
+#define SZ_ERROR_UNSUPPORTED 4
+#define SZ_ERROR_PARAM 5
+#define SZ_ERROR_INPUT_EOF 6
+#define SZ_ERROR_OUTPUT_EOF 7
+#define SZ_ERROR_READ 8
+#define SZ_ERROR_WRITE 9
+#define SZ_ERROR_PROGRESS 10
+#define SZ_ERROR_FAIL 11
+#define SZ_ERROR_THREAD 12
+
+#define SZ_ERROR_ARCHIVE 16
+#define SZ_ERROR_NO_ARCHIVE 17
+
+typedef int SRes;
-#ifndef __C_TYPES_H
-#define __C_TYPES_H
+#ifndef RINOK
+#define RINOK(x) { int __result__ = (x); if (__result__ != 0) return __result__; }
+#endif
-#ifndef _7ZIP_BYTE_DEFINED
-#define _7ZIP_BYTE_DEFINED
typedef unsigned char Byte;
-#endif
-
-#ifndef _7ZIP_UINT16_DEFINED
-#define _7ZIP_UINT16_DEFINED
+typedef short Int16;
typedef unsigned short UInt16;
-#endif
-#ifndef _7ZIP_UINT32_DEFINED
-#define _7ZIP_UINT32_DEFINED
#ifdef _LZMA_UINT32_IS_ULONG
-typedef unsigned long UInt32;
-#else
-typedef unsigned int UInt32;
-#endif
-#endif
-
-#ifndef _7ZIP_INT32_DEFINED
-#define _7ZIP_INT32_DEFINED
-#ifdef _LZMA_INT32_IS_ULONG
typedef long Int32;
+typedef unsigned long UInt32;
#else
typedef int Int32;
+typedef unsigned int UInt32;
#endif
-#endif
/* #define _SZ_NO_INT_64 */
-/* define it your compiler doesn't support long long int */
+/* define it if your compiler doesn't support 64-bit integers */
-#ifndef _7ZIP_UINT64_DEFINED
-#define _7ZIP_UINT64_DEFINED
#ifdef _SZ_NO_INT_64
+
+typedef long Int64;
typedef unsigned long UInt64;
+
#else
+
#if defined(_MSC_VER) || defined(__BORLANDC__)
+typedef __int64 Int64;
typedef unsigned __int64 UInt64;
#else
+typedef long long int Int64;
typedef unsigned long long int UInt64;
#endif
-#endif
-#endif
-
-/* #define _SZ_FILE_SIZE_32 */
-/* You can define _SZ_FILE_SIZE_32, if you don't need support for files larger than 4 GB*/
-
-#ifndef CFileSize
-#ifdef _SZ_FILE_SIZE_32
-typedef UInt32 CFileSize;
-#else
-typedef UInt64 CFileSize;
#endif
-#endif
-
-#define SZ_RESULT int
-
-typedef int HRes;
-#define RES_OK (0)
-
-#define SZ_OK (0)
-#define SZE_DATA_ERROR (1)
-#define SZE_CRC_ERROR (3)
-#define SZE_ARCHIVE_ERROR (6)
-
-#define SZE_OUTOFMEMORY (0x8007000EL)
-#define SZE_NOTIMPL (0x80004001L)
-#define SZE_FAIL (0x80004005L)
-#define SZE_INVALIDARG (0x80070057L)
-
-#ifndef RINOK
-#define RINOK(x) { HRes __result_ = (x); if(__result_ != 0) return __result_; }
+#ifdef _LZMA_NO_SYSTEM_SIZE_T
+typedef UInt32 SizeT;
+#else
+#include <stddef.h>
+typedef size_t SizeT;
#endif
typedef int Bool;
#define True 1
#define False 0
+
#ifdef _MSC_VER
-#define StdCall __stdcall
+
+#if _MSC_VER >= 1300
+#define MY_NO_INLINE __declspec(noinline)
#else
-#define StdCall
+#define MY_NO_INLINE
#endif
-#if _MSC_VER >= 1300
-#define MY_FAST_CALL __declspec(noinline) __fastcall
-#elif defined( _MSC_VER)
-#define MY_FAST_CALL __fastcall
+#define MY_CDECL __cdecl
+#define MY_STD_CALL __stdcall
+#define MY_FAST_CALL MY_NO_INLINE __fastcall
+
#else
+
+#define MY_CDECL
+#define MY_STD_CALL
#define MY_FAST_CALL
+
#endif
+
+/* The following interfaces use first parameter as pointer to structure */
+
+typedef struct
+{
+ SRes (*Read)(void *p, void *buf, size_t *size);
+ /* if (input(*size) != 0 && output(*size) == 0) means end_of_stream.
+ (output(*size) < input(*size)) is allowed */
+} ISeqInStream;
+
+typedef struct
+{
+ size_t (*Write)(void *p, const void *buf, size_t size);
+ /* Returns: result - the number of actually written bytes.
+ (result < size) means error */
+} ISeqOutStream;
+
+typedef struct
+{
+ SRes (*Progress)(void *p, UInt64 inSize, UInt64 outSize);
+ /* Returns: result. (result != SZ_OK) means break.
+ Value (UInt64)(Int64)-1 for size means unknown value. */
+} ICompressProgress;
+
+typedef struct
+{
+ void *(*Alloc)(void *p, size_t size);
+ void (*Free)(void *p, void *address); /* address can be 0 */
+} ISzAlloc;
+
+#define IAlloc_Alloc(p, size) (p)->Alloc((p), size)
+#define IAlloc_Free(p, a) (p)->Free((p), a)
+
#endif
diff --git a/CPP/7zip/Archive/7z/7z.dsp b/CPP/7zip/Archive/7z/7z.dsp
deleted file mode 100755
index fc4c3698..00000000
--- a/CPP/7zip/Archive/7z/7z.dsp
+++ /dev/null
@@ -1,644 +0,0 @@
-# Microsoft Developer Studio Project File - Name="7z" - Package Owner=<4>
-# Microsoft Developer Studio Generated Build File, Format Version 6.00
-# ** DO NOT EDIT **
-
-# TARGTYPE "Win32 (x86) Dynamic-Link Library" 0x0102
-
-CFG=7z - Win32 Debug
-!MESSAGE This is not a valid makefile. To build this project using NMAKE,
-!MESSAGE use the Export Makefile command and run
-!MESSAGE
-!MESSAGE NMAKE /f "7z.mak".
-!MESSAGE
-!MESSAGE You can specify a configuration when running NMAKE
-!MESSAGE by defining the macro CFG on the command line. For example:
-!MESSAGE
-!MESSAGE NMAKE /f "7z.mak" CFG="7z - Win32 Debug"
-!MESSAGE
-!MESSAGE Possible choices for configuration are:
-!MESSAGE
-!MESSAGE "7z - Win32 Release" (based on "Win32 (x86) Dynamic-Link Library")
-!MESSAGE "7z - Win32 Debug" (based on "Win32 (x86) Dynamic-Link Library")
-!MESSAGE
-
-# Begin Project
-# PROP AllowPerConfigDependencies 0
-# PROP Scc_ProjName ""
-# PROP Scc_LocalPath ""
-CPP=cl.exe
-MTL=midl.exe
-RSC=rc.exe
-
-!IF "$(CFG)" == "7z - Win32 Release"
-
-# PROP BASE Use_MFC 0
-# PROP BASE Use_Debug_Libraries 0
-# PROP BASE Output_Dir "Release"
-# PROP BASE Intermediate_Dir "Release"
-# PROP BASE Target_Dir ""
-# PROP Use_MFC 0
-# PROP Use_Debug_Libraries 0
-# PROP Output_Dir "Release"
-# PROP Intermediate_Dir "Release"
-# PROP Ignore_Export_Lib 1
-# PROP Target_Dir ""
-# ADD BASE CPP /nologo /MT /W3 /GX /O2 /D "WIN32" /D "NDEBUG" /D "_WINDOWS" /D "_MBCS" /D "_USRDLL" /D "MY7Z_EXPORTS" /YX /FD /c
-# ADD CPP /nologo /Gz /MD /W3 /GX /O1 /I "..\..\..\\" /D "NDEBUG" /D "WIN32" /D "_WINDOWS" /D "_MBCS" /D "_USRDLL" /D "MY7Z_EXPORTS" /D "COMPRESS_MT" /D "EXTERNAL_CODECS" /Yu"StdAfx.h" /FD /c
-# ADD BASE MTL /nologo /D "NDEBUG" /mktyplib203 /win32
-# ADD MTL /nologo /D "NDEBUG" /mktyplib203 /win32
-# ADD BASE RSC /l 0x419 /d "NDEBUG"
-# ADD RSC /l 0x409 /d "NDEBUG"
-BSC32=bscmake.exe
-# ADD BASE BSC32 /nologo
-# ADD BSC32 /nologo
-LINK32=link.exe
-# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /dll /machine:I386
-# ADD LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /dll /machine:I386 /out:"C:\Program Files\7-zip\Formats\7z.dll" /opt:NOWIN98
-# SUBTRACT LINK32 /pdb:none
-
-!ELSEIF "$(CFG)" == "7z - Win32 Debug"
-
-# PROP BASE Use_MFC 0
-# PROP BASE Use_Debug_Libraries 1
-# PROP BASE Output_Dir "Debug"
-# PROP BASE Intermediate_Dir "Debug"
-# PROP BASE Target_Dir ""
-# PROP Use_MFC 0
-# PROP Use_Debug_Libraries 1
-# PROP Output_Dir "Debug"
-# PROP Intermediate_Dir "Debug"
-# PROP Ignore_Export_Lib 1
-# PROP Target_Dir ""
-# ADD BASE CPP /nologo /MTd /W3 /Gm /GX /ZI /Od /D "WIN32" /D "_DEBUG" /D "_WINDOWS" /D "_MBCS" /D "_USRDLL" /D "MY7Z_EXPORTS" /YX /FD /GZ /c
-# ADD CPP /nologo /Gz /MTd /W3 /Gm /GX /ZI /Od /I "..\..\..\\" /D "_DEBUG" /D "WIN32" /D "_WINDOWS" /D "_MBCS" /D "_USRDLL" /D "MY7Z_EXPORTS" /D "COMPRESS_MT" /D "EXTERNAL_CODECS" /Yu"StdAfx.h" /FD /GZ /c
-# ADD BASE MTL /nologo /D "_DEBUG" /mktyplib203 /win32
-# ADD MTL /nologo /D "_DEBUG" /mktyplib203 /win32
-# ADD BASE RSC /l 0x419 /d "_DEBUG"
-# ADD RSC /l 0x409 /d "_DEBUG"
-BSC32=bscmake.exe
-# ADD BASE BSC32 /nologo
-# ADD BSC32 /nologo
-LINK32=link.exe
-# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /dll /debug /machine:I386 /pdbtype:sept
-# ADD LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /dll /debug /machine:I386 /out:"C:\Program Files\7-zip\Formats\7z.dll" /pdbtype:sept
-
-!ENDIF
-
-# Begin Target
-
-# Name "7z - Win32 Release"
-# Name "7z - Win32 Debug"
-# Begin Group "Spec"
-
-# PROP Default_Filter ""
-# Begin Source File
-
-SOURCE=..\Archive.def
-# End Source File
-# Begin Source File
-
-SOURCE=..\ArchiveExports.cpp
-# End Source File
-# Begin Source File
-
-SOURCE=..\DllExports.cpp
-# End Source File
-# Begin Source File
-
-SOURCE=.\resource.rc
-# End Source File
-# Begin Source File
-
-SOURCE=.\StdAfx.cpp
-# ADD CPP /Yc"StdAfx.h"
-# End Source File
-# Begin Source File
-
-SOURCE=.\StdAfx.h
-# End Source File
-# End Group
-# Begin Group "Engine"
-
-# PROP Default_Filter ""
-# Begin Source File
-
-SOURCE=.\7zCompressionMode.cpp
-# End Source File
-# Begin Source File
-
-SOURCE=.\7zCompressionMode.h
-# End Source File
-# Begin Source File
-
-SOURCE=.\7zDecode.cpp
-# End Source File
-# Begin Source File
-
-SOURCE=.\7zDecode.h
-# End Source File
-# Begin Source File
-
-SOURCE=.\7zEncode.cpp
-# End Source File
-# Begin Source File
-
-SOURCE=.\7zEncode.h
-# End Source File
-# Begin Source File
-
-SOURCE=.\7zExtract.cpp
-# End Source File
-# Begin Source File
-
-SOURCE=.\7zFolderInStream.cpp
-# End Source File
-# Begin Source File
-
-SOURCE=.\7zFolderInStream.h
-# End Source File
-# Begin Source File
-
-SOURCE=.\7zFolderOutStream.cpp
-# End Source File
-# Begin Source File
-
-SOURCE=.\7zFolderOutStream.h
-# End Source File
-# Begin Source File
-
-SOURCE=.\7zHandler.cpp
-# End Source File
-# Begin Source File
-
-SOURCE=.\7zHandler.h
-# End Source File
-# Begin Source File
-
-SOURCE=.\7zHandlerOut.cpp
-# End Source File
-# Begin Source File
-
-SOURCE=.\7zHeader.cpp
-# End Source File
-# Begin Source File
-
-SOURCE=.\7zHeader.h
-# End Source File
-# Begin Source File
-
-SOURCE=.\7zIn.cpp
-# End Source File
-# Begin Source File
-
-SOURCE=.\7zIn.h
-# End Source File
-# Begin Source File
-
-SOURCE=.\7zItem.h
-# End Source File
-# Begin Source File
-
-SOURCE=.\7zOut.cpp
-# End Source File
-# Begin Source File
-
-SOURCE=.\7zOut.h
-# End Source File
-# Begin Source File
-
-SOURCE=.\7zProperties.cpp
-# End Source File
-# Begin Source File
-
-SOURCE=.\7zProperties.h
-# End Source File
-# Begin Source File
-
-SOURCE=.\7zRegister.cpp
-# End Source File
-# Begin Source File
-
-SOURCE=.\7zSpecStream.cpp
-# End Source File
-# Begin Source File
-
-SOURCE=.\7zSpecStream.h
-# End Source File
-# Begin Source File
-
-SOURCE=.\7zUpdate.cpp
-# End Source File
-# Begin Source File
-
-SOURCE=.\7zUpdate.h
-# End Source File
-# End Group
-# Begin Group "Interface"
-
-# PROP Default_Filter ""
-# Begin Source File
-
-SOURCE=..\IArchive.h
-# End Source File
-# Begin Source File
-
-SOURCE=..\..\ICoder.h
-# End Source File
-# Begin Source File
-
-SOURCE=..\..\IMyUnknown.h
-# End Source File
-# Begin Source File
-
-SOURCE=..\..\IPassword.h
-# End Source File
-# Begin Source File
-
-SOURCE=..\..\IProgress.h
-# End Source File
-# Begin Source File
-
-SOURCE=..\..\IStream.h
-# End Source File
-# Begin Source File
-
-SOURCE=..\..\PropID.h
-# End Source File
-# End Group
-# Begin Group "Common"
-
-# PROP Default_Filter ""
-# Begin Source File
-
-SOURCE=..\..\..\Common\Buffer.h
-# End Source File
-# Begin Source File
-
-SOURCE=..\..\..\Common\CRC.cpp
-# End Source File
-# Begin Source File
-
-SOURCE=..\..\..\Common\DynamicBuffer.h
-# End Source File
-# Begin Source File
-
-SOURCE=..\..\..\Common\IntToString.cpp
-# End Source File
-# Begin Source File
-
-SOURCE=..\..\..\Common\IntToString.h
-# End Source File
-# Begin Source File
-
-SOURCE=..\..\..\Common\MyString.cpp
-# End Source File
-# Begin Source File
-
-SOURCE=..\..\..\Common\MyString.h
-# End Source File
-# Begin Source File
-
-SOURCE=..\..\..\Common\MyVector.cpp
-# End Source File
-# Begin Source File
-
-SOURCE=..\..\..\Common\MyVector.h
-# End Source File
-# Begin Source File
-
-SOURCE=..\..\..\Common\NewHandler.cpp
-# End Source File
-# Begin Source File
-
-SOURCE=..\..\..\Common\NewHandler.h
-# End Source File
-# Begin Source File
-
-SOURCE=..\..\..\Common\StringConvert.cpp
-# End Source File
-# Begin Source File
-
-SOURCE=..\..\..\Common\StringConvert.h
-# End Source File
-# Begin Source File
-
-SOURCE=..\..\..\Common\StringToInt.cpp
-# End Source File
-# Begin Source File
-
-SOURCE=..\..\..\Common\StringToInt.h
-# End Source File
-# End Group
-# Begin Group "Archive Common"
-
-# PROP Default_Filter ""
-# Begin Source File
-
-SOURCE=..\Common\CoderMixer2.cpp
-# End Source File
-# Begin Source File
-
-SOURCE=..\Common\CoderMixer2.h
-# End Source File
-# Begin Source File
-
-SOURCE=..\Common\CoderMixer2MT.cpp
-# End Source File
-# Begin Source File
-
-SOURCE=..\Common\CoderMixer2MT.h
-# End Source File
-# Begin Source File
-
-SOURCE=..\Common\CrossThreadProgress.cpp
-# End Source File
-# Begin Source File
-
-SOURCE=..\Common\CrossThreadProgress.h
-# End Source File
-# Begin Source File
-
-SOURCE=..\Common\HandlerOut.cpp
-# End Source File
-# Begin Source File
-
-SOURCE=..\Common\HandlerOut.h
-# End Source File
-# Begin Source File
-
-SOURCE=..\Common\InStreamWithCRC.cpp
-# End Source File
-# Begin Source File
-
-SOURCE=..\Common\InStreamWithCRC.h
-# End Source File
-# Begin Source File
-
-SOURCE=..\Common\ItemNameUtils.cpp
-# End Source File
-# Begin Source File
-
-SOURCE=..\Common\ItemNameUtils.h
-# End Source File
-# Begin Source File
-
-SOURCE=..\Common\MultiStream.cpp
-# End Source File
-# Begin Source File
-
-SOURCE=..\Common\MultiStream.h
-# End Source File
-# Begin Source File
-
-SOURCE=..\Common\OutStreamWithCRC.cpp
-# End Source File
-# Begin Source File
-
-SOURCE=..\Common\OutStreamWithCRC.h
-# End Source File
-# Begin Source File
-
-SOURCE=..\Common\ParseProperties.cpp
-# End Source File
-# Begin Source File
-
-SOURCE=..\Common\ParseProperties.h
-# End Source File
-# End Group
-# Begin Group "7-Zip Common"
-
-# PROP Default_Filter ""
-# Begin Source File
-
-SOURCE=..\..\Common\CreateCoder.cpp
-# End Source File
-# Begin Source File
-
-SOURCE=..\..\Common\CreateCoder.h
-# End Source File
-# Begin Source File
-
-SOURCE=..\..\Common\FilterCoder.cpp
-# End Source File
-# Begin Source File
-
-SOURCE=..\..\Common\FilterCoder.h
-# End Source File
-# Begin Source File
-
-SOURCE=..\..\Common\InOutTempBuffer.cpp
-# End Source File
-# Begin Source File
-
-SOURCE=..\..\Common\InOutTempBuffer.h
-# End Source File
-# Begin Source File
-
-SOURCE=..\..\Common\LimitedStreams.cpp
-# End Source File
-# Begin Source File
-
-SOURCE=..\..\Common\LimitedStreams.h
-# End Source File
-# Begin Source File
-
-SOURCE=..\..\Common\LockedStream.cpp
-# End Source File
-# Begin Source File
-
-SOURCE=..\..\Common\LockedStream.h
-# End Source File
-# Begin Source File
-
-SOURCE=..\..\Common\MethodId.cpp
-# End Source File
-# Begin Source File
-
-SOURCE=..\..\Common\MethodId.h
-# End Source File
-# Begin Source File
-
-SOURCE=..\..\Common\MethodProps.cpp
-# End Source File
-# Begin Source File
-
-SOURCE=..\..\Common\MethodProps.h
-# End Source File
-# Begin Source File
-
-SOURCE=..\..\Common\OutBuffer.cpp
-# End Source File
-# Begin Source File
-
-SOURCE=..\..\Common\OutBuffer.h
-# End Source File
-# Begin Source File
-
-SOURCE=..\..\Common\ProgressUtils.cpp
-# End Source File
-# Begin Source File
-
-SOURCE=..\..\Common\ProgressUtils.h
-# End Source File
-# Begin Source File
-
-SOURCE=..\..\Common\RegisterArc.h
-# End Source File
-# Begin Source File
-
-SOURCE=..\..\Common\RegisterCodec.h
-# End Source File
-# Begin Source File
-
-SOURCE=..\..\Common\StreamBinder.cpp
-# End Source File
-# Begin Source File
-
-SOURCE=..\..\Common\StreamBinder.h
-# End Source File
-# Begin Source File
-
-SOURCE=..\..\Common\StreamObjects.cpp
-# End Source File
-# Begin Source File
-
-SOURCE=..\..\Common\StreamObjects.h
-# End Source File
-# Begin Source File
-
-SOURCE=..\..\Common\StreamUtils.cpp
-# End Source File
-# Begin Source File
-
-SOURCE=..\..\Common\StreamUtils.h
-# End Source File
-# Begin Source File
-
-SOURCE=..\..\Common\VirtThread.cpp
-# End Source File
-# Begin Source File
-
-SOURCE=..\..\Common\VirtThread.h
-# End Source File
-# End Group
-# Begin Group "Windows"
-
-# PROP Default_Filter ""
-# Begin Source File
-
-SOURCE=..\..\..\Windows\DLL.cpp
-# End Source File
-# Begin Source File
-
-SOURCE=..\..\..\Windows\DLL.h
-# End Source File
-# Begin Source File
-
-SOURCE=..\..\..\Windows\FileDir.cpp
-# End Source File
-# Begin Source File
-
-SOURCE=..\..\..\Windows\FileDir.h
-# End Source File
-# Begin Source File
-
-SOURCE=..\..\..\Windows\FileFind.cpp
-# End Source File
-# Begin Source File
-
-SOURCE=..\..\..\Windows\FileFind.h
-# End Source File
-# Begin Source File
-
-SOURCE=..\..\..\Windows\FileIO.cpp
-# End Source File
-# Begin Source File
-
-SOURCE=..\..\..\Windows\FileIO.h
-# End Source File
-# Begin Source File
-
-SOURCE=..\..\..\Windows\FileName.h
-# End Source File
-# Begin Source File
-
-SOURCE=..\..\..\Windows\Handle.h
-# End Source File
-# Begin Source File
-
-SOURCE=..\..\..\Windows\PropVariant.cpp
-# End Source File
-# Begin Source File
-
-SOURCE=..\..\..\Windows\PropVariant.h
-# End Source File
-# Begin Source File
-
-SOURCE=..\..\..\Windows\Synchronization.cpp
-# End Source File
-# Begin Source File
-
-SOURCE=..\..\..\Windows\Synchronization.h
-# End Source File
-# Begin Source File
-
-SOURCE=..\..\..\Windows\System.cpp
-# End Source File
-# Begin Source File
-
-SOURCE=..\..\..\Windows\System.h
-# End Source File
-# Begin Source File
-
-SOURCE=..\..\..\Windows\Thread.h
-# End Source File
-# End Group
-# Begin Group "Compress"
-
-# PROP Default_Filter ""
-# Begin Source File
-
-SOURCE=..\..\Compress\Copy\CopyCoder.cpp
-# End Source File
-# Begin Source File
-
-SOURCE=..\..\Compress\Copy\CopyCoder.h
-# End Source File
-# End Group
-# Begin Group "C"
-
-# PROP Default_Filter ""
-# Begin Source File
-
-SOURCE=..\..\..\..\C\7zCrc.c
-# SUBTRACT CPP /YX /Yc /Yu
-# End Source File
-# Begin Source File
-
-SOURCE=..\..\..\..\C\7zCrc.h
-# End Source File
-# Begin Source File
-
-SOURCE=..\..\..\..\C\Alloc.c
-# SUBTRACT CPP /YX /Yc /Yu
-# End Source File
-# Begin Source File
-
-SOURCE=..\..\..\..\C\Alloc.h
-# End Source File
-# Begin Source File
-
-SOURCE=..\..\..\..\C\Threads.c
-# SUBTRACT CPP /YX /Yc /Yu
-# End Source File
-# Begin Source File
-
-SOURCE=..\..\..\..\C\Threads.h
-# End Source File
-# End Group
-# Begin Source File
-
-SOURCE=.\7z.ico
-# End Source File
-# End Target
-# End Project
diff --git a/CPP/7zip/Archive/7z/7zIn.cpp b/CPP/7zip/Archive/7z/7zIn.cpp
index a4292545..f892e0cd 100755
--- a/CPP/7zip/Archive/7z/7zIn.cpp
+++ b/CPP/7zip/Archive/7z/7zIn.cpp
@@ -9,6 +9,7 @@
extern "C"
{
#include "../../../../C/7zCrc.h"
+#include "../../../../C/CpuArch.h"
}
// define FORMAT_7Z_RECOVERY if you want to recover multivolume archives with empty StartHeader
@@ -96,11 +97,7 @@ void CStreamSwitch::Set(CInArchive *archive, const CObjectVector<CByteBuffer> *d
}
}
-#if defined(_M_IX86) || defined(_M_X64) || defined(_M_AMD64) || defined(__i386__) || defined(__x86_64__)
-#define SZ_LITTLE_ENDIAN_UNALIGN
-#endif
-
-#ifdef SZ_LITTLE_ENDIAN_UNALIGN
+#ifdef LITTLE_ENDIAN_UNALIGN
static inline UInt16 GetUInt16FromMem(const Byte *p) { return *(const UInt16 *)p; }
static inline UInt32 GetUInt32FromMem(const Byte *p) { return *(const UInt32 *)p; }
static inline UInt64 GetUInt64FromMem(const Byte *p) { return *(const UInt64 *)p; }
@@ -220,10 +217,8 @@ static inline bool TestSignatureCandidate(const Byte *p)
HRESULT CInArchive::FindAndReadSignature(IInStream *stream, const UInt64 *searchHeaderSizeLimit)
{
- UInt32 processedSize;
- RINOK(ReadStream(stream, _header, kHeaderSize, &processedSize));
- if (processedSize != kHeaderSize)
- return S_FALSE;
+ RINOK(ReadStream_FALSE(stream, _header, kHeaderSize));
+
if (TestSignatureCandidate(_header))
return S_OK;
@@ -240,6 +235,7 @@ HRESULT CInArchive::FindAndReadSignature(IInStream *stream, const UInt64 *search
if (curTestPos - _arhiveBeginStreamPosition > *searchHeaderSizeLimit)
break;
UInt32 numReadBytes = kBufferSize - numPrevBytes;
+ UInt32 processedSize;
RINOK(stream->Read(buffer + numPrevBytes, numReadBytes, &processedSize));
UInt32 numBytesInBuffer = numPrevBytes + processedSize;
if (numBytesInBuffer < kHeaderSize)
diff --git a/CPP/7zip/Archive/7z/7zProperties.cpp b/CPP/7zip/Archive/7z/7zProperties.cpp
index 3452a030..f5b5ba98 100755
--- a/CPP/7zip/Archive/7z/7zProperties.cpp
+++ b/CPP/7zip/Archive/7z/7zProperties.cpp
@@ -40,8 +40,9 @@ CPropMap kPropMap[] =
{ NID::kCRC, NULL, kpidCRC, VT_UI4},
{ NID::kAnti, NULL, kpidIsAnti, VT_BOOL},
- // { 97, NULL, kpidSolid, VT_BOOL},
+
#ifndef _SFX
+ { 97, NULL, kpidEncrypted, VT_BOOL},
{ 98, NULL, kpidMethod, VT_BSTR},
{ 99, NULL, kpidBlock, VT_UI4}
#endif
@@ -119,6 +120,7 @@ void CHandler::FillPopIDs()
_fileInfoPopIDs += fileInfoPopIDs;
#ifndef _SFX
+ _fileInfoPopIDs.Add(97);
_fileInfoPopIDs.Add(98);
_fileInfoPopIDs.Add(99);
#endif
@@ -144,10 +146,9 @@ STDMETHODIMP CHandler::GetNumberOfProperties(UInt32 *numProperties)
return S_OK;
}
-STDMETHODIMP CHandler::GetPropertyInfo(UInt32 index,
- BSTR *name, PROPID *propID, VARTYPE *varType)
+STDMETHODIMP CHandler::GetPropertyInfo(UInt32 index, BSTR *name, PROPID *propID, VARTYPE *varType)
{
- if((int)index >= _fileInfoPopIDs.Size())
+ if ((int)index >= _fileInfoPopIDs.Size())
return E_INVALIDARG;
int indexInMap = FindPropInMap(_fileInfoPopIDs[index]);
if (indexInMap == -1)
diff --git a/CPP/7zip/Archive/7z/makefile b/CPP/7zip/Archive/7z/makefile
deleted file mode 100755
index 1a72da0e..00000000
--- a/CPP/7zip/Archive/7z/makefile
+++ /dev/null
@@ -1,111 +0,0 @@
-PROG = 7z.dll
-DEF_FILE = ../Archive.def
-CFLAGS = $(CFLAGS) -I ../../../ \
- -DCOMPRESS_MT \
- -DEXTERNAL_CODECS \
-
-LIBS = $(LIBS) oleaut32.lib user32.lib
-
-AR_OBJS = \
- $O\ArchiveExports.obj \
- $O\DllExports.obj \
-
-7Z_OBJS = \
- $O\7zCompressionMode.obj \
- $O\7zDecode.obj \
- $O\7zEncode.obj \
- $O\7zExtract.obj \
- $O\7zFolderInStream.obj \
- $O\7zFolderOutStream.obj \
- $O\7zHandler.obj \
- $O\7zHandlerOut.obj \
- $O\7zHeader.obj \
- $O\7zIn.obj \
- $O\7zOut.obj \
- $O\7zProperties.obj \
- $O\7zSpecStream.obj \
- $O\7zUpdate.obj \
- $O\7zRegister.obj \
-
-COMMON_OBJS = \
- $O\CRC.obj \
- $O\IntToString.obj \
- $O\NewHandler.obj \
- $O\MyString.obj \
- $O\StringConvert.obj \
- $O\StringToInt.obj \
- $O\MyVector.obj \
-
-WIN_OBJS = \
- $O\DLL.obj \
- $O\FileDir.obj \
- $O\FileFind.obj \
- $O\FileIO.obj \
- $O\PropVariant.obj \
- $O\Synchronization.obj \
- $O\System.obj \
-
-7ZIP_COMMON_OBJS = \
- $O\CreateCoder.obj \
- $O\InOutTempBuffer.obj \
- $O\FilterCoder.obj \
- $O\LimitedStreams.obj \
- $O\LockedStream.obj \
- $O\MethodId.obj \
- $O\MethodProps.obj \
- $O\OutBuffer.obj \
- $O\ProgressUtils.obj \
- $O\StreamBinder.obj \
- $O\StreamObjects.obj \
- $O\StreamUtils.obj \
- $O\VirtThread.obj \
-
-AR_COMMON_OBJS = \
- $O\CoderMixer2.obj \
- $O\CoderMixer2MT.obj \
- $O\CrossThreadProgress.obj \
- $O\HandlerOut.obj \
- $O\InStreamWithCRC.obj \
- $O\ItemNameUtils.obj \
- $O\MultiStream.obj \
- $O\OutStreamWithCRC.obj \
- $O\ParseProperties.obj \
-
-C_OBJS = \
- $O\Alloc.obj \
- $O\Threads.obj \
-
-!include "../../Crc2.mak"
-
-OBJS = \
- $O\StdAfx.obj \
- $(AR_OBJS) \
- $(7Z_OBJS) \
- $(COMMON_OBJS) \
- $(WIN_OBJS) \
- $(7ZIP_COMMON_OBJS) \
- $(AR_COMMON_OBJS) \
- $O\CopyCoder.obj \
- $(C_OBJS) \
- $(CRC_OBJS) \
- $O\resource.res
-
-!include "../../../Build.mak"
-
-$(AR_OBJS): ../$(*B).cpp
- $(COMPL)
-$(7Z_OBJS): $(*B).cpp
- $(COMPL)
-$(COMMON_OBJS): ../../../Common/$(*B).cpp
- $(COMPL)
-$(WIN_OBJS): ../../../Windows/$(*B).cpp
- $(COMPL)
-$(7ZIP_COMMON_OBJS): ../../Common/$(*B).cpp
- $(COMPL)
-$(AR_COMMON_OBJS): ../Common/$(*B).cpp
- $(COMPL)
-$O\CopyCoder.obj: ../../Compress/Copy/$(*B).cpp
- $(COMPL)
-$(C_OBJS): ../../../../C/$(*B).c
- $(COMPL_O2)
-!include "../../Crc.mak"
diff --git a/CPP/7zip/Archive/7z/resource.rc b/CPP/7zip/Archive/7z/resource.rc
deleted file mode 100755
index 8868173c..00000000
--- a/CPP/7zip/Archive/7z/resource.rc
+++ /dev/null
@@ -1,5 +0,0 @@
-#include "../../MyVersionInfo.rc"
-
-MY_VERSION_INFO_DLL("7z Plugin", "7z")
-
-101 ICON "7z.ico"
diff --git a/CPP/7zip/Archive/ArchiveExports.cpp b/CPP/7zip/Archive/ArchiveExports.cpp
index a60303a5..3c51a3f5 100755
--- a/CPP/7zip/Archive/ArchiveExports.cpp
+++ b/CPP/7zip/Archive/ArchiveExports.cpp
@@ -44,9 +44,9 @@ int FindFormatCalssId(const GUID *clsID)
if (cls != CLSID_CArchiveHandler)
return -1;
Byte id = CLS_ARC_ID_ITEM(*clsID);
- for (UInt32 i = 0; i < g_NumArcs; i++)
+ for (unsigned i = 0; i < g_NumArcs; i++)
if (g_Arcs[i]->ClassId == id)
- return i;
+ return (int)i;
return -1;
}
diff --git a/CPP/7zip/Archive/Arj/ArjIn.cpp b/CPP/7zip/Archive/Arj/ArjIn.cpp
index 146f4f09..cc7cde49 100755
--- a/CPP/7zip/Archive/Arj/ArjIn.cpp
+++ b/CPP/7zip/Archive/Arj/ArjIn.cpp
@@ -19,10 +19,10 @@ namespace NArj {
HRESULT CInArchive::ReadBytes(void *data, UInt32 size, UInt32 *processedSize)
{
- UInt32 realProcessedSize;
- HRESULT result = ReadStream(_stream, data, size, &realProcessedSize);
- if(processedSize != NULL)
- *processedSize = realProcessedSize;
+ size_t realProcessedSize = size;
+ HRESULT result = ReadStream(_stream, data, &realProcessedSize);
+ if (processedSize != NULL)
+ *processedSize = (UInt32)realProcessedSize;
IncreasePositionValue(realProcessedSize);
return result;
}
diff --git a/CPP/7zip/Archive/BZip2/BZip2Handler.cpp b/CPP/7zip/Archive/BZip2/BZip2Handler.cpp
index 0b790c68..c88c883f 100755
--- a/CPP/7zip/Archive/BZip2/BZip2Handler.cpp
+++ b/CPP/7zip/Archive/BZip2/BZip2Handler.cpp
@@ -56,10 +56,7 @@ STDMETHODIMP CHandler::Open(IInStream *stream,
RINOK(stream->Seek(0, STREAM_SEEK_CUR, &_streamStartPosition));
const int kSignatureSize = 3;
Byte buffer[kSignatureSize];
- UInt32 processedSize;
- RINOK(ReadStream(stream, buffer, kSignatureSize, &processedSize));
- if (processedSize != kSignatureSize)
- return S_FALSE;
+ RINOK(ReadStream_FALSE(stream, buffer, kSignatureSize));
if (buffer[0] != 'B' || buffer[1] != 'Z' || buffer[2] != 'h')
return S_FALSE;
@@ -166,9 +163,9 @@ STDMETHODIMP CHandler::Extract(const UInt32* indices, UInt32 numItems,
const int kSignatureSize = 3;
Byte buffer[kSignatureSize];
- UInt32 processedSize;
- RINOK(ReadStream(_stream, buffer, kSignatureSize, &processedSize));
- if (processedSize < kSignatureSize)
+ size_t processedSize = kSignatureSize;
+ RINOK(ReadStream(_stream, buffer, &processedSize));
+ if (processedSize != kSignatureSize)
{
if (firstItem)
return E_FAIL;
diff --git a/CPP/7zip/Archive/Cab/CabBlockInStream.cpp b/CPP/7zip/Archive/Cab/CabBlockInStream.cpp
index 570ce058..343ef821 100755
--- a/CPP/7zip/Archive/Cab/CabBlockInStream.cpp
+++ b/CPP/7zip/Archive/Cab/CabBlockInStream.cpp
@@ -116,19 +116,14 @@ HRESULT CCabBlockInStream::PreRead(UInt32 &packSize, UInt32 &unpackSize)
{
CTempCabInBuffer2 inBuffer;
inBuffer.Pos = 0;
- UInt32 processedSizeLoc;
- RINOK(ReadStream(_stream, inBuffer.Buffer, kDataBlockHeaderSize, &processedSizeLoc))
- if (processedSizeLoc != kDataBlockHeaderSize)
- return S_FALSE; // bad block
+ RINOK(ReadStream_FALSE(_stream, inBuffer.Buffer, kDataBlockHeaderSize))
UInt32 checkSum = inBuffer.ReadUInt32();
packSize = inBuffer.ReadUInt16();
unpackSize = inBuffer.ReadUInt16();
if (ReservedSize != 0)
{
- RINOK(ReadStream(_stream, _buffer, ReservedSize, &processedSizeLoc));
- if(ReservedSize != processedSizeLoc)
- return S_FALSE; // bad block;
+ RINOK(ReadStream_FALSE(_stream, _buffer, ReservedSize));
}
_pos = 0;
CCheckSum2 checkSumCalc;
@@ -139,9 +134,7 @@ HRESULT CCabBlockInStream::PreRead(UInt32 &packSize, UInt32 &unpackSize)
if (packSize < 2)
return S_FALSE; // bad block;
Byte sig[2];
- RINOK(ReadStream(_stream, sig, 2, &processedSizeLoc));
- if(processedSizeLoc != 2)
- return S_FALSE;
+ RINOK(ReadStream_FALSE(_stream, sig, 2));
if (sig[0] != 0x43 || sig[1] != 0x4B)
return S_FALSE;
packSize2 -= 2;
@@ -154,9 +147,10 @@ HRESULT CCabBlockInStream::PreRead(UInt32 &packSize, UInt32 &unpackSize)
UInt32 curSize = packSize2;
if (curSize != 0)
{
- RINOK(ReadStream(_stream, _buffer + _size, curSize, &processedSizeLoc));
- checkSumCalc.Update(_buffer + _size, processedSizeLoc);
- _size += processedSizeLoc;
+ size_t processedSizeLoc = curSize;
+ RINOK(ReadStream(_stream, _buffer + _size, &processedSizeLoc));
+ checkSumCalc.Update(_buffer + _size, (UInt32)processedSizeLoc);
+ _size += (UInt32)processedSizeLoc;
if (processedSizeLoc != curSize)
return S_FALSE;
}
diff --git a/CPP/7zip/Archive/Chm/ChmHandler.cpp b/CPP/7zip/Archive/Chm/ChmHandler.cpp
index d1499328..7f3b1837 100755
--- a/CPP/7zip/Archive/Chm/ChmHandler.cpp
+++ b/CPP/7zip/Archive/Chm/ChmHandler.cpp
@@ -473,7 +473,7 @@ STDMETHODIMP CHandler::Extract(const UInt32* indices, UInt32 numItems,
if (!testMode)
{
UInt32 size = m_Database.NewFormatString.Length();
- RINOK(WriteStream(realOutStream, (const char *)m_Database.NewFormatString, size, 0));
+ RINOK(WriteStream(realOutStream, (const char *)m_Database.NewFormatString, size));
}
RINOK(extractCallback->SetOperationResult(NArchive::NExtract::NOperationResult::kOK));
continue;
diff --git a/CPP/7zip/Archive/Com/ComHandler.cpp b/CPP/7zip/Archive/Com/ComHandler.cpp
index aa9bf859..2255c021 100755
--- a/CPP/7zip/Archive/Com/ComHandler.cpp
+++ b/CPP/7zip/Archive/Com/ComHandler.cpp
@@ -217,16 +217,14 @@ STDMETHODIMP CHandler::Extract(const UInt32* indices, UInt32 numItems,
size = (UInt32)rem;
RINOK(_stream->Seek(offset, STREAM_SEEK_SET, NULL));
- UInt32 realProcessedSize;
- RINOK(ReadStream(_stream, sect, size, &realProcessedSize));
+ size_t realProcessedSize = size;
+ RINOK(ReadStream(_stream, sect, &realProcessedSize));
if (realProcessedSize != size)
break;
if (realOutStream)
{
- RINOK(WriteStream(realOutStream, sect, size, &realProcessedSize));
- if (realProcessedSize != size)
- break;
+ RINOK(WriteStream(realOutStream, sect, size));
}
pos += size;
}
diff --git a/CPP/7zip/Archive/Com/ComIn.cpp b/CPP/7zip/Archive/Com/ComIn.cpp
index c3549609..b8dfdb81 100755
--- a/CPP/7zip/Archive/Com/ComIn.cpp
+++ b/CPP/7zip/Archive/Com/ComIn.cpp
@@ -7,6 +7,8 @@ extern "C"
#include "../../../../C/Alloc.h"
}
+#include "../../../../C/CpuArch.h"
+
#include "Common/MyCom.h"
#include "../../Common/StreamUtils.h"
#include "Common/IntToString.h"
@@ -19,22 +21,6 @@ namespace NCom{
static const UInt32 kSignatureSize = 8;
static const Byte kSignature[kSignatureSize] = { 0xD0, 0xCF, 0x11, 0xE0, 0xA1, 0xB1, 0x1A, 0xE1 };
-static HRESULT ReadBytes(ISequentialInStream *inStream, void *data, UInt32 size)
-{
- UInt32 realProcessedSize;
- RINOK(ReadStream(inStream, data, size, &realProcessedSize));
- return (realProcessedSize == size) ? S_OK : S_FALSE;
-}
-
-#ifdef LITTLE_ENDIAN_UNALIGN
-#define GetUi16(p) (*(const UInt16 *)(p))
-#define GetUi32(p) (*(const UInt32 *)(p))
-#else
-#define GetUi16(p) ((p)[0] | ((UInt16)(p)[1] << 8))
-#define GetUi32(p) ((p)[0] | ((UInt32)(p)[1] << 8) | ((UInt32)(p)[2] << 16) | ((UInt32)(p)[3] << 24))
-#endif
-
-
void CUInt32Buf::Free()
{
MyFree(_buf);
@@ -56,7 +42,7 @@ bool CUInt32Buf::Allocate(UInt32 numItems)
static HRESULT ReadSector(IInStream *inStream, Byte *buf, int sectorSizeBits, UInt32 sid)
{
RINOK(inStream->Seek((((UInt64)sid + 1) << sectorSizeBits), STREAM_SEEK_SET, NULL));
- return ReadBytes(inStream, buf, (UInt32)1 << sectorSizeBits);
+ return ReadStream_FALSE(inStream, buf, (UInt32)1 << sectorSizeBits);
}
static HRESULT ReadIDs(IInStream *inStream, Byte *buf, int sectorSizeBits, UInt32 sid, UInt32 *dest)
@@ -219,7 +205,7 @@ HRESULT OpenArchive(IInStream *inStream, CDatabase &db)
{
static const UInt32 kHeaderSize = 512;
Byte p[kHeaderSize];
- RINOK(ReadBytes(inStream, p, kHeaderSize));
+ RINOK(ReadStream_FALSE(inStream, p, kHeaderSize));
if (memcmp(p, kSignature, kSignatureSize) != 0)
return S_FALSE;
UInt16 majorVer = GetUi16(p + 0x1A);
diff --git a/CPP/7zip/Archive/Common/CoderMixer2MT.cpp b/CPP/7zip/Archive/Common/CoderMixer2MT.cpp
index 2ef1fa95..e1030976 100755
--- a/CPP/7zip/Archive/Common/CoderMixer2MT.cpp
+++ b/CPP/7zip/Archive/Common/CoderMixer2MT.cpp
@@ -208,14 +208,16 @@ STDMETHODIMP CCoderMixer2MT::Code(ISequentialInStream **inStreams,
RINOK(ReturnIfError(E_ABORT));
RINOK(ReturnIfError(E_OUTOFMEMORY));
- RINOK(ReturnIfError(S_FALSE));
for (i = 0; i < _coders.Size(); i++)
{
HRESULT result = _coders[i].Result;
- if (result != S_OK && result != E_FAIL)
+ if (result != S_OK && result != E_FAIL && result != S_FALSE)
return result;
}
+
+ RINOK(ReturnIfError(S_FALSE));
+
for (i = 0; i < _coders.Size(); i++)
{
HRESULT result = _coders[i].Result;
diff --git a/CPP/7zip/Archive/Common/CoderMixerMT.cpp b/CPP/7zip/Archive/Common/CoderMixerMT.cpp
index 6319c5da..85cf0a52 100755
--- a/CPP/7zip/Archive/Common/CoderMixerMT.cpp
+++ b/CPP/7zip/Archive/Common/CoderMixerMT.cpp
@@ -77,14 +77,16 @@ STDMETHODIMP CCoderMixerMT::Code(ISequentialInStream *inStream,
RINOK(ReturnIfError(E_ABORT));
RINOK(ReturnIfError(E_OUTOFMEMORY));
- RINOK(ReturnIfError(S_FALSE));
for (i = 0; i < _coders.Size(); i++)
{
HRESULT result = _coders[i].Result;
- if (result != S_OK && result != E_FAIL)
+ if (result != S_OK && result != E_FAIL && result != S_FALSE)
return result;
}
+
+ RINOK(ReturnIfError(S_FALSE));
+
for (i = 0; i < _coders.Size(); i++)
{
HRESULT result = _coders[i].Result;
diff --git a/CPP/7zip/Archive/Common/HandlerOut.cpp b/CPP/7zip/Archive/Common/HandlerOut.cpp
index 0dcf449e..082a484d 100755
--- a/CPP/7zip/Archive/Common/HandlerOut.cpp
+++ b/CPP/7zip/Archive/Common/HandlerOut.cpp
@@ -380,15 +380,6 @@ HRESULT COutHandler::SetParams(COneMethodInfo &oneMethodInfo, const UString &src
HRESULT COutHandler::SetSolidSettings(const UString &s)
{
- bool res;
- if (StringToBool(s, res))
- {
- if (res)
- InitSolid();
- else
- _numSolidFiles = 1;
- return S_OK;
- }
UString s2 = s;
s2.MakeUpper();
for (int i = 0; i < s2.Length();)
@@ -439,16 +430,27 @@ HRESULT COutHandler::SetSolidSettings(const UString &s)
HRESULT COutHandler::SetSolidSettings(const PROPVARIANT &value)
{
+ bool isSolid;
switch(value.vt)
{
case VT_EMPTY:
- InitSolid();
- return S_OK;
+ isSolid = true;
+ break;
+ case VT_BOOL:
+ isSolid = (value.boolVal != VARIANT_FALSE);
+ break;
case VT_BSTR:
+ if (StringToBool(value.bstrVal, isSolid))
+ break;
return SetSolidSettings(value.bstrVal);
default:
return E_INVALIDARG;
}
+ if (isSolid)
+ InitSolid();
+ else
+ _numSolidFiles = 1;
+ return S_OK;
}
void COutHandler::Init()
@@ -587,6 +589,14 @@ HRESULT COutHandler::SetProperty(const wchar_t *nameSpec, const PROPVARIANT &val
if (number <= mainDicMethodIndex)
mainDicSize = dicSize;
}
+ else if (realName.Left(1).CompareNoCase(L"B") == 0)
+ {
+ UInt32 blockSize;
+ RINOK(ParsePropDictionaryValue(realName.Mid(1), value, blockSize));
+ property.Id = NCoderPropID::kBlockSize;
+ property.Value = blockSize;
+ oneMethodInfo.Properties.Add(property);
+ }
else if (realName.Left(3).CompareNoCase(L"MEM") == 0)
{
UInt32 dicSize;
diff --git a/CPP/7zip/Archive/Common/ParseProperties.cpp b/CPP/7zip/Archive/Common/ParseProperties.cpp
index f0d4e29c..83d51241 100755
--- a/CPP/7zip/Archive/Common/ParseProperties.cpp
+++ b/CPP/7zip/Archive/Common/ParseProperties.cpp
@@ -99,12 +99,12 @@ HRESULT ParsePropDictionaryValue(const UString &name, const PROPVARIANT &prop, U
bool StringToBool(const UString &s, bool &res)
{
- if (s.IsEmpty() || s.CompareNoCase(L"ON") == 0)
+ if (s.IsEmpty() || s.CompareNoCase(L"ON") == 0 || s.Compare(L"+") == 0)
{
res = true;
return true;
}
- if (s.CompareNoCase(L"OFF") == 0)
+ if (s.CompareNoCase(L"OFF") == 0 || s.Compare(L"-") == 0)
{
res = false;
return true;
@@ -119,6 +119,9 @@ HRESULT SetBoolProperty(bool &dest, const PROPVARIANT &value)
case VT_EMPTY:
dest = true;
return S_OK;
+ case VT_BOOL:
+ dest = (value.boolVal != VARIANT_FALSE);
+ return S_OK;
/*
case VT_UI4:
dest = (value.ulVal != 0);
diff --git a/CPP/7zip/Archive/Cpio/CpioIn.cpp b/CPP/7zip/Archive/Cpio/CpioIn.cpp
index 91399362..4732a32e 100755
--- a/CPP/7zip/Archive/Cpio/CpioIn.cpp
+++ b/CPP/7zip/Archive/Cpio/CpioIn.cpp
@@ -16,7 +16,9 @@ namespace NCpio {
HRESULT CInArchive::ReadBytes(void *data, UInt32 size, UInt32 &processedSize)
{
- RINOK(ReadStream(m_Stream, data, size, &processedSize));
+ size_t realProcessedSize = size;
+ RINOK(ReadStream(m_Stream, data, &realProcessedSize));
+ processedSize = (UInt32)realProcessedSize;
m_Position += processedSize;
return S_OK;
}
@@ -240,8 +242,7 @@ HRESULT CInArchive::GetNextItem(bool &filled, CItemEx &item)
}
if (nameSize == 0 || nameSize >= (1 << 27))
return E_FAIL;
- RINOK(ReadBytes(item.Name.GetBuffer(nameSize),
- nameSize, processedSize));
+ RINOK(ReadBytes(item.Name.GetBuffer(nameSize), nameSize, processedSize));
if (processedSize != nameSize)
return E_FAIL;
item.Name.ReleaseBuffer();
diff --git a/CPP/7zip/Archive/Deb/DebIn.cpp b/CPP/7zip/Archive/Deb/DebIn.cpp
index c2221d12..41aaeb8a 100755
--- a/CPP/7zip/Archive/Deb/DebIn.cpp
+++ b/CPP/7zip/Archive/Deb/DebIn.cpp
@@ -15,22 +15,12 @@ namespace NDeb {
using namespace NHeader;
-HRESULT CInArchive::ReadBytes(void *data, UInt32 size, UInt32 &processedSize)
-{
- RINOK(ReadStream(m_Stream, data, size, &processedSize));
- m_Position += processedSize;
- return S_OK;
-}
-
HRESULT CInArchive::Open(IInStream *inStream)
{
RINOK(inStream->Seek(0, STREAM_SEEK_CUR, &m_Position));
char signature[kSignatureLen];
- UInt32 processedSize;
- RINOK(ReadStream(inStream, signature, kSignatureLen, &processedSize));
- m_Position += processedSize;
- if (processedSize != kSignatureLen)
- return S_FALSE;
+ RINOK(ReadStream_FALSE(inStream, signature, kSignatureLen));
+ m_Position += kSignatureLen;
if (memcmp(signature, kSignature, kSignatureLen) != 0)
return S_FALSE;
m_Stream = inStream;
@@ -100,10 +90,11 @@ HRESULT CInArchive::GetNextItemReal(bool &filled, CItemEx &item)
char header[NHeader::kHeaderSize];
const char *cur = header;
- UInt32 processedSize;
+ size_t processedSize = sizeof(header);
item.HeaderPosition = m_Position;
- RINOK(ReadBytes(header, sizeof(header), processedSize));
- if (processedSize < sizeof(header))
+ RINOK(ReadStream(m_Stream, header, &processedSize));
+ m_Position += processedSize;
+ if (processedSize != sizeof(header))
return S_OK;
char tempString[kNameSize + 1];
diff --git a/CPP/7zip/Archive/Deb/DebIn.h b/CPP/7zip/Archive/Deb/DebIn.h
index c1b72b6e..7d33fa59 100755
--- a/CPP/7zip/Archive/Deb/DebIn.h
+++ b/CPP/7zip/Archive/Deb/DebIn.h
@@ -15,7 +15,6 @@ class CInArchive
CMyComPtr<IInStream> m_Stream;
UInt64 m_Position;
- HRESULT ReadBytes(void *data, UInt32 size, UInt32 &processedSize);
HRESULT GetNextItemReal(bool &filled, CItemEx &itemInfo);
HRESULT Skeep(UInt64 numBytes);
public:
diff --git a/CPP/7zip/Archive/GZip/GZipIn.cpp b/CPP/7zip/Archive/GZip/GZipIn.cpp
index 44ed62f6..33b0ac47 100755
--- a/CPP/7zip/Archive/GZip/GZipIn.cpp
+++ b/CPP/7zip/Archive/GZip/GZipIn.cpp
@@ -20,11 +20,8 @@ namespace NGZip {
HRESULT CInArchive::ReadBytes(ISequentialInStream *inStream, void *data, UInt32 size)
{
- UInt32 realProcessedSize;
- RINOK(ReadStream(inStream, data, size, &realProcessedSize));
- m_Position += realProcessedSize;
- if(realProcessedSize != size)
- return S_FALSE;
+ RINOK(ReadStream_FALSE(inStream, data, size));
+ m_Position += size;
return S_OK;
}
diff --git a/CPP/7zip/Archive/GZip/GZipOut.cpp b/CPP/7zip/Archive/GZip/GZipOut.cpp
index af01c79f..3d0d4f7a 100755
--- a/CPP/7zip/Archive/GZip/GZipOut.cpp
+++ b/CPP/7zip/Archive/GZip/GZipOut.cpp
@@ -12,11 +12,7 @@ namespace NGZip {
HRESULT COutArchive::WriteBytes(const void *buffer, UInt32 size)
{
- UInt32 processedSize;
- RINOK(WriteStream(m_Stream, buffer, size, &processedSize));
- if(processedSize != size)
- return E_FAIL;
- return S_OK;
+ return WriteStream(m_Stream, buffer, size);
}
HRESULT COutArchive::WriteByte(Byte value)
diff --git a/CPP/7zip/Archive/Iso/IsoIn.cpp b/CPP/7zip/Archive/Iso/IsoIn.cpp
index 213b3014..f4896d37 100755
--- a/CPP/7zip/Archive/Iso/IsoIn.cpp
+++ b/CPP/7zip/Archive/Iso/IsoIn.cpp
@@ -12,19 +12,14 @@
namespace NArchive {
namespace NIso {
-HRESULT CInArchive::ReadBytes(void *data, UInt32 size, UInt32 &processedSize)
-{
- return ReadStream(_stream, data, size, &processedSize);
-}
-
Byte CInArchive::ReadByte()
{
if (m_BufferPos >= BlockSize)
m_BufferPos = 0;
if (m_BufferPos == 0)
{
- UInt32 processedSize;
- if (ReadBytes(m_Buffer, BlockSize, processedSize) != S_OK)
+ size_t processedSize = BlockSize;
+ if (ReadStream(_stream, m_Buffer, &processedSize) != S_OK)
throw 1;
if (processedSize != BlockSize)
throw 1;
@@ -192,7 +187,10 @@ void CInArchive::ReadDirRecord2(CDirRecord &r, Byte len)
void CInArchive::ReadDirRecord(CDirRecord &r)
{
- Byte len = ReadByte();
+ Byte len = ReadByte();
+ // Some CDs can have incorrect value len = 48 ('0') in VolumeDescriptor.
+ // But maybe we must use real "len" for other records.
+ len = 34;
ReadDirRecord2(r, len);
}
diff --git a/CPP/7zip/Archive/Iso/IsoIn.h b/CPP/7zip/Archive/Iso/IsoIn.h
index ab850bd9..4f9705c4 100755
--- a/CPP/7zip/Archive/Iso/IsoIn.h
+++ b/CPP/7zip/Archive/Iso/IsoIn.h
@@ -232,7 +232,6 @@ class CInArchive
bool _bootIsDefined;
CBootRecordDescriptor _bootDesc;
- HRESULT ReadBytes(void *data, UInt32 size, UInt32 &processedSize);
void Skeep(size_t size);
void SkeepZeros(size_t size);
Byte ReadByte();
diff --git a/CPP/7zip/Archive/Iso/IsoItem.h b/CPP/7zip/Archive/Iso/IsoItem.h
index e899d616..fcb9531f 100755
--- a/CPP/7zip/Archive/Iso/IsoItem.h
+++ b/CPP/7zip/Archive/Iso/IsoItem.h
@@ -36,9 +36,9 @@ struct CRecordingDateTime
if (!SystemTimeToFileTime(&st, &ft))
return false;
UInt64 value = (((UInt64)ft.dwHighDateTime) << 32) + ft.dwLowDateTime;
- value += (UInt64)((Int64)(int)GmtOffset * 15 * 60);
+ value -= (UInt64)((Int64)GmtOffset * 15 * 60 * 10000000);
ft.dwLowDateTime = (DWORD)value;
- ft.dwHighDateTime = DWORD(value >> 32);
+ ft.dwHighDateTime = (DWORD)(value >> 32);
return true;
}
};
diff --git a/CPP/7zip/Archive/Lzh/LzhIn.cpp b/CPP/7zip/Archive/Lzh/LzhIn.cpp
index 9c531848..6783654c 100755
--- a/CPP/7zip/Archive/Lzh/LzhIn.cpp
+++ b/CPP/7zip/Archive/Lzh/LzhIn.cpp
@@ -14,7 +14,9 @@ namespace NLzh {
HRESULT CInArchive::ReadBytes(void *data, UInt32 size, UInt32 &processedSize)
{
- RINOK(ReadStream(m_Stream, data, size, &processedSize));
+ size_t realProcessedSize = size;
+ RINOK(ReadStream(m_Stream, data, &realProcessedSize));
+ processedSize = (UInt32)realProcessedSize;
m_Position += processedSize;
return S_OK;
}
diff --git a/CPP/7zip/Archive/Lzma/LzmaArcRegister.cpp b/CPP/7zip/Archive/Lzma/LzmaArcRegister.cpp
new file mode 100755
index 00000000..bbeb177b
--- /dev/null
+++ b/CPP/7zip/Archive/Lzma/LzmaArcRegister.cpp
@@ -0,0 +1,14 @@
+// LzmaArcRegister.cpp
+
+#include "StdAfx.h"
+
+#include "../../Common/RegisterArc.h"
+
+#include "LzmaHandler.h"
+
+static IInArchive *CreateArc() { return new NArchive::NLzma::CHandler; }
+
+static CArcInfo g_ArcInfo =
+ { L"Lzma", L"lzma lzma86", 0, 0xA, {0 }, 0, true, CreateArc, NULL };
+
+REGISTER_ARC(Lzma)
diff --git a/CPP/7zip/Archive/Lzma/LzmaFiltersDecode.cpp b/CPP/7zip/Archive/Lzma/LzmaFiltersDecode.cpp
new file mode 100755
index 00000000..d3450616
--- /dev/null
+++ b/CPP/7zip/Archive/Lzma/LzmaFiltersDecode.cpp
@@ -0,0 +1,86 @@
+// LzmaFiltersDecode.cpp
+
+#include "StdAfx.h"
+
+#include "LzmaFiltersDecode.h"
+
+namespace NArchive {
+namespace NLzma {
+
+static const UInt64 k_LZMA = 0x030101;
+static const UInt64 k_BCJ = 0x03030103;
+
+HRESULT CDecoder::Code(
+ DECL_EXTERNAL_CODECS_LOC_VARS
+ const CHeader &block,
+ ISequentialInStream *inStream, ISequentialOutStream *outStream,
+ UInt64 *inProcessedSize, ICompressProgressInfo *progress)
+{
+ *inProcessedSize = (UInt64)(Int64)-1;
+
+ if (block.FilterMethod > 1)
+ return E_NOTIMPL;
+
+ if (!_lzmaDecoder)
+ {
+ RINOK(CreateCoder(EXTERNAL_CODECS_LOC_VARS k_LZMA, _lzmaDecoder, false));
+ if (_lzmaDecoder == 0)
+ return E_NOTIMPL;
+ }
+
+ {
+ CMyComPtr<ICompressSetDecoderProperties2> setDecoderProperties;
+ _lzmaDecoder.QueryInterface(IID_ICompressSetDecoderProperties2, &setDecoderProperties);
+ if (!setDecoderProperties)
+ return E_NOTIMPL;
+ RINOK(setDecoderProperties->SetDecoderProperties2(block.LzmaProps, 5));
+ }
+
+ bool filteredMode = (block.FilterMethod == 1);
+
+ CMyComPtr<ICompressSetOutStream> setOutStream;
+
+ if (filteredMode)
+ {
+ if (!_bcjStream)
+ {
+ CMyComPtr<ICompressCoder> coder;
+ RINOK(CreateCoder(EXTERNAL_CODECS_LOC_VARS k_BCJ, coder, false));
+ if (!coder)
+ return E_NOTIMPL;
+ coder.QueryInterface(IID_ISequentialOutStream, &_bcjStream);
+ if (!_bcjStream)
+ return E_NOTIMPL;
+ }
+
+ _bcjStream.QueryInterface(IID_ICompressSetOutStream, &setOutStream);
+ if (!setOutStream)
+ return E_NOTIMPL;
+ RINOK(setOutStream->SetOutStream(outStream));
+ outStream = _bcjStream;
+ }
+
+ const UInt64 *unpackSize = block.HasUnpackSize() ? &block.UnpackSize : NULL;
+ RINOK(_lzmaDecoder->Code(inStream, outStream, NULL, unpackSize, progress));
+
+ if (filteredMode)
+ {
+ CMyComPtr<IOutStreamFlush> flush;
+ _bcjStream.QueryInterface(IID_IOutStreamFlush, &flush);
+ if (flush)
+ {
+ RINOK(flush->Flush());
+ }
+ RINOK(setOutStream->ReleaseOutStream());
+ }
+
+ CMyComPtr<ICompressGetInStreamProcessedSize> getInStreamProcessedSize;
+ _lzmaDecoder.QueryInterface(IID_ICompressGetInStreamProcessedSize, &getInStreamProcessedSize);
+ if (getInStreamProcessedSize)
+ {
+ RINOK(getInStreamProcessedSize->GetInStreamProcessedSize(inProcessedSize));
+ }
+ return S_OK;
+}
+
+}}
diff --git a/CPP/7zip/Archive/Lzma/LzmaFiltersDecode.h b/CPP/7zip/Archive/Lzma/LzmaFiltersDecode.h
new file mode 100755
index 00000000..a9f4927b
--- /dev/null
+++ b/CPP/7zip/Archive/Lzma/LzmaFiltersDecode.h
@@ -0,0 +1,26 @@
+// LzmaFiltersDecode.h
+
+#ifndef __LZMA_FILTERS_DECODE_H
+#define __LZMA_FILTERS_DECODE_H
+
+#include "../../Common/CreateCoder.h"
+
+#include "LzmaItem.h"
+
+namespace NArchive {
+namespace NLzma {
+
+class CDecoder
+{
+ CMyComPtr<ICompressCoder> _lzmaDecoder;
+ CMyComPtr<ISequentialOutStream> _bcjStream;
+public:
+ HRESULT Code(DECL_EXTERNAL_CODECS_LOC_VARS
+ const CHeader &block,
+ ISequentialInStream *inStream, ISequentialOutStream *outStream,
+ UInt64 *inProcessedSize, ICompressProgressInfo *progress);
+};
+
+}}
+
+#endif
diff --git a/CPP/7zip/Archive/Lzma/LzmaHandler.cpp b/CPP/7zip/Archive/Lzma/LzmaHandler.cpp
new file mode 100755
index 00000000..70126aa4
--- /dev/null
+++ b/CPP/7zip/Archive/Lzma/LzmaHandler.cpp
@@ -0,0 +1,243 @@
+// LzmaHandler.cpp
+
+#include "StdAfx.h"
+
+#include "LzmaHandler.h"
+
+#include "Common/Defs.h"
+#include "Common/StringConvert.h"
+#include "Common/ComTry.h"
+#include "Common/IntToString.h"
+
+#include "Windows/PropVariant.h"
+
+#include "../../Common/ProgressUtils.h"
+#include "../../Common/StreamUtils.h"
+#include "../Common/DummyOutStream.h"
+
+#include "LzmaFiltersDecode.h"
+
+namespace NArchive {
+namespace NLzma {
+
+STATPROPSTG kProps[] =
+{
+ { NULL, kpidSize, VT_UI8},
+ { NULL, kpidPackedSize, VT_UI8},
+ { NULL, kpidMethod, VT_UI1}
+};
+
+IMP_IInArchive_Props
+IMP_IInArchive_ArcProps_NO
+
+STDMETHODIMP CHandler::GetNumberOfItems(UInt32 *numItems)
+{
+ *numItems = 1;
+ return S_OK;
+}
+
+static void ConvertUInt32ToString(UInt32 value, wchar_t *s)
+{
+ ConvertUInt64ToString(value, s + MyStringLen(s));
+}
+
+static void DictSizeToString(UInt32 value, wchar_t *s)
+{
+ for (int i = 0; i <= 31; i++)
+ if ((UInt32(1) << i) == value)
+ {
+ ConvertUInt32ToString(i, s);
+ return;
+ }
+ wchar_t c = L'b';
+ if ((value & ((1 << 20) - 1)) == 0)
+ {
+ value >>= 20;
+ c = L'm';
+ }
+ else if ((value & ((1 << 10) - 1)) == 0)
+ {
+ value >>= 10;
+ c = L'k';
+ }
+ ConvertUInt32ToString(value, s);
+ int p = MyStringLen(s);
+ s[p++] = c;
+ s[p++] = L'\0';
+}
+
+static void MyStrCat(wchar_t *d, const wchar_t *s)
+{
+ MyStringCopy(d + MyStringLen(d), s);
+}
+
+STDMETHODIMP CHandler::GetProperty(UInt32 index, PROPID propID, PROPVARIANT *value)
+{
+ if (index != 0)
+ return E_INVALIDARG;
+ NWindows::NCOM::CPropVariant propVariant;
+ switch(propID)
+ {
+ case kpidSize:
+ if (m_StreamInfo.HasUnpackSize())
+ propVariant = (UInt64)m_StreamInfo.UnpackSize;
+ break;
+ case kpidPackedSize:
+ propVariant = (UInt64)m_PackSize;
+ break;
+ case kpidMethod:
+ {
+ wchar_t s[64];
+ s[0] = '\0';
+ if (m_StreamInfo.IsThereFilter)
+ {
+ const wchar_t *f;
+ if (m_StreamInfo.FilterMethod == 0)
+ f = L"Copy";
+ else if (m_StreamInfo.FilterMethod == 1)
+ f = L"BCJ";
+ else
+ f = L"Unknown";
+ MyStrCat(s, f);
+ MyStrCat(s, L" ");
+ }
+ MyStrCat(s, L"LZMA:");
+ DictSizeToString(m_StreamInfo.GetDicSize(), s);
+ propVariant = s;
+ break;
+ }
+ }
+ propVariant.Detach(value);
+ return S_OK;
+}
+
+STDMETHODIMP CHandler::Open(IInStream *inStream,
+ const UInt64 * /* maxCheckStartPosition */,
+ IArchiveOpenCallback * /* openArchiveCallback */)
+{
+ {
+ RINOK(inStream->Seek(0, STREAM_SEEK_CUR, &m_StreamStartPosition));
+
+ HRESULT res = ReadStreamHeader(inStream, m_StreamInfo);
+ if (res != S_OK)
+ return S_FALSE;
+
+ Byte b;
+ RINOK(ReadStream_FALSE(inStream, &b, 1));
+ if (b != 0)
+ return S_FALSE;
+
+ UInt64 endPos;
+ RINOK(inStream->Seek(0, STREAM_SEEK_END, &endPos));
+ m_PackSize = endPos - m_StreamStartPosition - m_StreamInfo.GetHeaderSize();
+
+ m_Stream = inStream;
+ }
+ return S_OK;
+}
+
+STDMETHODIMP CHandler::Close()
+{
+ m_Stream.Release();
+ return S_OK;
+}
+
+
+STDMETHODIMP CHandler::Extract(const UInt32* indices, UInt32 numItems,
+ Int32 _aTestMode, IArchiveExtractCallback *extractCallback)
+{
+ COM_TRY_BEGIN
+ bool allFilesMode = (numItems == UInt32(-1));
+ if (!allFilesMode)
+ {
+ if (numItems == 0)
+ return S_OK;
+ if (numItems != 1)
+ return E_INVALIDARG;
+ if (indices[0] != 0)
+ return E_INVALIDARG;
+ }
+
+ bool testMode = (_aTestMode != 0);
+
+ RINOK(extractCallback->SetTotal(m_PackSize));
+
+ UInt64 currentTotalPacked = 0;
+
+ CDummyOutStream *outStreamSpec = new CDummyOutStream;
+ CMyComPtr<ISequentialOutStream> outStream(outStreamSpec);
+
+ {
+ CMyComPtr<ISequentialOutStream> realOutStream;
+ Int32 askMode = testMode ?
+ NArchive::NExtract::NAskMode::kTest :
+ NArchive::NExtract::NAskMode::kExtract;
+
+ RINOK(extractCallback->GetStream(0, &realOutStream, askMode));
+
+ outStreamSpec->SetStream(realOutStream);
+ outStreamSpec->Init();
+ if(!testMode && !realOutStream)
+ return S_OK;
+ extractCallback->PrepareOperation(askMode);
+ }
+
+ CLocalProgress *lps = new CLocalProgress;
+ CMyComPtr<ICompressProgressInfo> progress = lps;
+ lps->Init(extractCallback, true);
+
+ CDecoder decoder;
+ RINOK(m_Stream->Seek(m_StreamStartPosition, STREAM_SEEK_SET, NULL));
+ UInt64 streamPos = m_StreamStartPosition;
+ Int32 opRes = NArchive::NExtract::NOperationResult::kOK;
+ bool firstItem = true;
+ for (;;)
+ {
+ CHeader st;
+ HRESULT result = ReadStreamHeader(m_Stream, st);
+ if (result != S_OK)
+ {
+ if (firstItem)
+ return E_FAIL;
+ break;
+ }
+ firstItem = false;
+
+ lps->OutSize = outStreamSpec->GetSize();
+ lps->InSize = currentTotalPacked;
+ RINOK(lps->SetCur());
+
+ streamPos += st.GetHeaderSize();
+ UInt64 packProcessed;
+
+ {
+ result = decoder.Code(
+ EXTERNAL_CODECS_VARS
+ st, m_Stream, outStream, &packProcessed, progress);
+ if (result == E_NOTIMPL)
+ {
+ opRes = NArchive::NExtract::NOperationResult::kUnSupportedMethod;
+ break;
+ }
+ if (result == S_FALSE)
+ {
+ opRes = NArchive::NExtract::NOperationResult::kDataError;
+ break;
+ }
+ RINOK(result);
+ }
+
+ if (packProcessed == (UInt64)(Int64)-1)
+ break;
+ RINOK(m_Stream->Seek(streamPos + packProcessed, STREAM_SEEK_SET, NULL));
+ currentTotalPacked += packProcessed;
+ streamPos += packProcessed;
+ }
+ outStream.Release();
+ return extractCallback->SetOperationResult(opRes);
+ COM_TRY_END
+}
+
+IMPL_ISetCompressCodecsInfo
+
+}}
diff --git a/CPP/7zip/Archive/Lzma/LzmaHandler.h b/CPP/7zip/Archive/Lzma/LzmaHandler.h
new file mode 100755
index 00000000..e4078309
--- /dev/null
+++ b/CPP/7zip/Archive/Lzma/LzmaHandler.h
@@ -0,0 +1,69 @@
+// Lzma/Handler.h
+
+#ifndef __GZIP_HANDLER_H
+#define __GZIP_HANDLER_H
+
+#include "Common/MyCom.h"
+
+#include "../IArchive.h"
+#include "../../Common/CreateCoder.h"
+
+#include "LzmaIn.h"
+
+namespace NArchive {
+namespace NLzma {
+
+// const UInt64 k_LZMA = 0x030101;
+
+class CHandler:
+ public IInArchive,
+ PUBLIC_ISetCompressCodecsInfo
+ public CMyUnknownImp
+{
+public:
+ MY_QUERYINTERFACE_BEGIN
+ MY_QUERYINTERFACE_ENTRY(IInArchive)
+ QUERY_ENTRY_ISetCompressCodecsInfo
+ MY_QUERYINTERFACE_END
+ MY_ADDREF_RELEASE
+
+ STDMETHOD(Open)(IInStream *inStream,
+ const UInt64 *maxCheckStartPosition,
+ IArchiveOpenCallback *openArchiveCallback);
+ STDMETHOD(Close)();
+
+ STDMETHOD(GetNumberOfItems)(UInt32 *numItems);
+ STDMETHOD(GetProperty)(UInt32 index, PROPID propID, PROPVARIANT *value);
+ STDMETHOD(Extract)(const UInt32* indices, UInt32 numItems,
+ Int32 testMode, IArchiveExtractCallback *extractCallback);
+
+ STDMETHOD(GetArchiveProperty)(PROPID propID, PROPVARIANT *value);
+
+ STDMETHOD(GetNumberOfProperties)(UInt32 *numProperties);
+ STDMETHOD(GetPropertyInfo)(UInt32 index,
+ BSTR *name, PROPID *propID, VARTYPE *varType);
+
+ STDMETHOD(GetNumberOfArchiveProperties)(UInt32 *numProperties);
+ STDMETHOD(GetArchivePropertyInfo)(UInt32 index,
+ BSTR *name, PROPID *propID, VARTYPE *varType);
+
+ UString GetMethodString();
+public:
+ CHandler() { }
+
+private:
+ CHeader m_StreamInfo;
+ UInt64 m_StreamStartPosition;
+ UInt64 m_PackSize;
+
+ CMyComPtr<IInStream> m_Stream;
+
+ DECL_EXTERNAL_CODECS_VARS
+
+ DECL_ISetCompressCodecsInfo
+
+};
+
+}}
+
+#endif
diff --git a/CPP/7zip/Archive/Lzma/LzmaIn.cpp b/CPP/7zip/Archive/Lzma/LzmaIn.cpp
new file mode 100755
index 00000000..342b01e1
--- /dev/null
+++ b/CPP/7zip/Archive/Lzma/LzmaIn.cpp
@@ -0,0 +1,56 @@
+// Archive/LzmaIn.cpp
+
+#include "StdAfx.h"
+
+#include "LzmaIn.h"
+
+#include "../../Common/StreamUtils.h"
+
+namespace NArchive {
+namespace NLzma {
+
+static bool CheckDictSize(const Byte *p)
+{
+ UInt32 dicSize = GetUi32(p);
+ int i;
+ for (i = 1; i <= 30; i++)
+ if (dicSize == ((UInt32)2 << i) || dicSize == ((UInt32)3 << i))
+ return true;
+ return false;
+}
+
+HRESULT ReadStreamHeader(ISequentialInStream *inStream, CHeader &block)
+{
+ Byte sig[5 + 9];
+ RINOK(ReadStream_FALSE(inStream, sig, 5 + 8));
+
+ const Byte kMaxProp0Val = 5 * 5 * 9 - 1;
+ if (sig[0] > kMaxProp0Val)
+ return S_FALSE;
+
+ for (int i = 0; i < 5; i++)
+ block.LzmaProps[i] = sig[i];
+
+ block.IsThereFilter = false;
+ block.FilterMethod = 0;
+
+ if (!CheckDictSize(sig + 1))
+ {
+ if (sig[0] > 1 || sig[1] > kMaxProp0Val)
+ return S_FALSE;
+ block.IsThereFilter = true;
+ block.FilterMethod = sig[0];
+ for (int i = 0; i < 5; i++)
+ block.LzmaProps[i] = sig[i + 1];
+ if (!CheckDictSize(block.LzmaProps + 1))
+ return S_FALSE;
+ RINOK(ReadStream_FALSE(inStream, sig + 5 + 8, 1));
+ }
+ UInt32 unpOffset = 5 + (block.IsThereFilter ? 1 : 0);
+ block.UnpackSize = GetUi64(sig + unpOffset);
+ if (block.HasUnpackSize() && block.UnpackSize >= ((UInt64)1 << 56))
+ return S_FALSE;
+ return S_OK;
+}
+
+}}
diff --git a/CPP/7zip/Archive/Lzma/LzmaIn.h b/CPP/7zip/Archive/Lzma/LzmaIn.h
new file mode 100755
index 00000000..6f237f2d
--- /dev/null
+++ b/CPP/7zip/Archive/Lzma/LzmaIn.h
@@ -0,0 +1,16 @@
+// Archive/LzmaIn.h
+
+#ifndef __ARCHIVE_LZMA_IN_H
+#define __ARCHIVE_LZMA_IN_H
+
+#include "LzmaItem.h"
+#include "../../IStream.h"
+
+namespace NArchive {
+namespace NLzma {
+
+HRESULT ReadStreamHeader(ISequentialInStream *inStream, CHeader &st);
+
+}}
+
+#endif
diff --git a/CPP/7zip/Archive/Lzma/LzmaItem.h b/CPP/7zip/Archive/Lzma/LzmaItem.h
new file mode 100755
index 00000000..8fcae210
--- /dev/null
+++ b/CPP/7zip/Archive/Lzma/LzmaItem.h
@@ -0,0 +1,27 @@
+// Archive/LzmaItem.h
+
+#ifndef __ARCHIVE_LZMA_ITEM_H
+#define __ARCHIVE_LZMA_ITEM_H
+
+#include "Common/Types.h"
+
+#include "../../../../C/CpuArch.h"
+
+namespace NArchive {
+namespace NLzma {
+
+struct CHeader
+{
+ UInt64 UnpackSize;
+ bool IsThereFilter;
+ Byte FilterMethod;
+ Byte LzmaProps[5];
+
+ UInt32 GetDicSize() const { return GetUi32(LzmaProps + 1); }
+ bool HasUnpackSize() const { return (UnpackSize != (UInt64)(Int64)-1); }
+ unsigned GetHeaderSize() const { return 5 + 8 + (IsThereFilter ? 1 : 0); }
+};
+
+}}
+
+#endif
diff --git a/CPP/7zip/Archive/Lzma/StdAfx.h b/CPP/7zip/Archive/Lzma/StdAfx.h
new file mode 100755
index 00000000..e7fb6986
--- /dev/null
+++ b/CPP/7zip/Archive/Lzma/StdAfx.h
@@ -0,0 +1,8 @@
+// StdAfx.h
+
+#ifndef __STDAFX_H
+#define __STDAFX_H
+
+#include "../../../Common/MyWindows.h"
+
+#endif
diff --git a/CPP/7zip/Archive/Lzma/lzma.ico b/CPP/7zip/Archive/Lzma/lzma.ico
new file mode 100755
index 00000000..1f4f754c
--- /dev/null
+++ b/CPP/7zip/Archive/Lzma/lzma.ico
Binary files differ
diff --git a/CPP/7zip/Archive/Nsis/NsisDecode.cpp b/CPP/7zip/Archive/Nsis/NsisDecode.cpp
index b50ec5e0..7e126bd4 100755
--- a/CPP/7zip/Archive/Nsis/NsisDecode.cpp
+++ b/CPP/7zip/Archive/Nsis/NsisDecode.cpp
@@ -133,9 +133,9 @@ HRESULT CDecoder::Init(
return S_OK;
}
-HRESULT CDecoder::Read(void *data, UInt32 size, UInt32 *processedSize)
+HRESULT CDecoder::Read(void *data, size_t *processedSize)
{
- return ReadStream(_decoderInStream, data, size, processedSize);;
+ return ReadStream(_decoderInStream, data, processedSize);;
}
}}
diff --git a/CPP/7zip/Archive/Nsis/NsisDecode.h b/CPP/7zip/Archive/Nsis/NsisDecode.h
index 1a2fa41f..36aeb2b1 100755
--- a/CPP/7zip/Archive/Nsis/NsisDecode.h
+++ b/CPP/7zip/Archive/Nsis/NsisDecode.h
@@ -39,7 +39,7 @@ public:
HRESULT Init(
DECL_EXTERNAL_CODECS_LOC_VARS
IInStream *inStream, NMethodType::EEnum method, bool thereIsFilterFlag, bool &useFilter);
- HRESULT Read(void *data, UInt32 size, UInt32 *processedSize);
+ HRESULT Read(void *data, size_t *processedSize);
};
}}
diff --git a/CPP/7zip/Archive/Nsis/NsisHandler.cpp b/CPP/7zip/Archive/Nsis/NsisHandler.cpp
index 62c7ab38..b24d966d 100755
--- a/CPP/7zip/Archive/Nsis/NsisHandler.cpp
+++ b/CPP/7zip/Archive/Nsis/NsisHandler.cpp
@@ -12,6 +12,7 @@
#include "Windows/PropVariant.h"
#include "../Common/ItemNameUtils.h"
+#include "../../Common/StreamUtils.h"
using namespace NWindows;
@@ -233,8 +234,14 @@ STDMETHODIMP CHandler::GetProperty(UInt32 index, PROPID propID, PROPVARIANT *val
{
case kpidPath:
{
- const UString s = NItemName::WinNameToOSName(MultiByteToUnicodeString(item.GetReducedName(), CP_ACP));
- prop = (const wchar_t *)s;
+ UString s;
+ if (_archive.IsUnicode)
+ s = item.GetReducedNameU();
+ else
+ s = MultiByteToUnicodeString(item.GetReducedNameA(), CP_ACP);
+ s = NItemName::WinNameToOSName(s);
+ if (!s.IsEmpty())
+ prop = (const wchar_t *)s;
break;
}
case kpidIsFolder:
@@ -348,7 +355,7 @@ STDMETHODIMP CHandler::Extract(const UInt32* indices, UInt32 numItems,
continue;
RINOK(extractCallback->PrepareOperation(askMode));
if (!testMode)
- RINOK(realOutStream->Write((const char *)_archive.Script, (UInt32)_archive.Script.Length(), NULL));
+ RINOK(WriteStream(realOutStream, (const char *)_archive.Script, (UInt32)_archive.Script.Length()));
}
else
#endif
@@ -379,9 +386,8 @@ STDMETHODIMP CHandler::Extract(const UInt32* indices, UInt32 numItems,
UInt64 pos = _archive.GetPosOfSolidItem(index);
while(streamPos < pos)
{
- UInt32 curSize = (UInt32)MyMin(pos - streamPos, (UInt64)kBufferLength);
- UInt32 processedSize;
- HRESULT res = _archive.Decoder.Read(buffer, curSize, &processedSize);
+ size_t processedSize = (UInt32)MyMin(pos - streamPos, (UInt64)kBufferLength);
+ HRESULT res = _archive.Decoder.Read(buffer, &processedSize);
if (res != S_OK)
{
if (res != S_FALSE)
@@ -398,8 +404,8 @@ STDMETHODIMP CHandler::Extract(const UInt32* indices, UInt32 numItems,
}
if (streamPos == pos)
{
- UInt32 processedSize;
- RINOK(_archive.Decoder.Read(buffer, 4, &processedSize));
+ size_t processedSize = 4;
+ RINOK(_archive.Decoder.Read(buffer, &processedSize));
if (processedSize != 4)
return E_FAIL;
streamPos += processedSize;
@@ -433,8 +439,8 @@ STDMETHODIMP CHandler::Extract(const UInt32* indices, UInt32 numItems,
UInt32 curSize = kBufferLength;
if (sizeIsKnown && curSize > fullSize)
curSize = fullSize;
- UInt32 processedSize;
- HRESULT res = _archive.Decoder.Read(buffer, curSize, &processedSize);
+ size_t processedSize = curSize;
+ HRESULT res = _archive.Decoder.Read(buffer, &processedSize);
if (res != S_OK)
{
if (res != S_FALSE)
@@ -449,7 +455,7 @@ STDMETHODIMP CHandler::Extract(const UInt32* indices, UInt32 numItems,
break;
}
- fullSize -= processedSize;
+ fullSize -= (UInt32)processedSize;
streamPos += processedSize;
offset += processedSize;
@@ -460,7 +466,7 @@ STDMETHODIMP CHandler::Extract(const UInt32* indices, UInt32 numItems,
completed = currentTotalSize + offset;
RINOK(extractCallback->SetCompleted(&completed));
if (!testMode)
- RINOK(realOutStream->Write(buffer, processedSize, NULL));
+ RINOK(WriteStream(realOutStream, buffer, processedSize));
}
}
else
@@ -478,7 +484,7 @@ STDMETHODIMP CHandler::Extract(const UInt32* indices, UInt32 numItems,
fullSize -= processedSize;
streamPos += processedSize;
if (!testMode)
- RINOK(realOutStream->Write(buffer, processedSize, 0));
+ RINOK(WriteStream(realOutStream, buffer, processedSize));
}
}
}
diff --git a/CPP/7zip/Archive/Nsis/NsisIn.cpp b/CPP/7zip/Archive/Nsis/NsisIn.cpp
index 83080448..5c5c872f 100755
--- a/CPP/7zip/Archive/Nsis/NsisIn.cpp
+++ b/CPP/7zip/Archive/Nsis/NsisIn.cpp
@@ -2,6 +2,8 @@
#include "StdAfx.h"
+// #include <stdio.h>
+
#include "NsisIn.h"
#include "NsisDecode.h"
@@ -9,6 +11,7 @@
#include "../../Common/StreamUtils.h"
+#include "Common/StringConvert.h"
#include "Common/IntToString.h"
namespace NArchive {
@@ -27,6 +30,14 @@ public:
static const char *kCrLf = "\x0D\x0A";
#endif
+#define NS_UN_SKIP_CODE 0xE000
+#define NS_UN_VAR_CODE 0xE001
+#define NS_UN_SHELL_CODE 0xE002
+#define NS_UN_LANG_CODE 0xE003
+#define NS_UN_CODES_START NS_UN_SKIP_CODE
+#define NS_UN_CODES_END NS_UN_LANG_CODE
+
+
UInt32 GetUInt32FromMemLE(const Byte *p)
{
return p[0] | (((UInt32)p[1]) << 8) | (((UInt32)p[2]) << 16) | (((UInt32)p[3]) << 24);
@@ -60,12 +71,20 @@ static int CompareItems(void *const *p1, void *const *p2, void * /* param */)
const CItem &i1 = **(CItem **)p1;
const CItem &i2 = **(CItem **)p2;
RINOZ(MyCompare(i1.Pos, i2.Pos));
- RINOZ(i1.Prefix.Compare(i2.Prefix));
- RINOZ(i1.Name.Compare(i2.Name));
+ if (i1.IsUnicode)
+ {
+ RINOZ(i1.PrefixU.Compare(i2.PrefixU));
+ RINOZ(i1.NameU.Compare(i2.NameU));
+ }
+ else
+ {
+ RINOZ(i1.PrefixA.Compare(i2.PrefixA));
+ RINOZ(i1.NameA.Compare(i2.NameA));
+ }
return 0;
}
-AString CInArchive::ReadString(UInt32 pos)
+AString CInArchive::ReadStringA(UInt32 pos)
{
AString s;
UInt32 offset = GetOffset() + _stringsPos + pos;
@@ -81,6 +100,24 @@ AString CInArchive::ReadString(UInt32 pos)
return s;
}
+UString CInArchive::ReadStringU(UInt32 pos)
+{
+ UString s;
+ UInt32 offset = GetOffset() + _stringsPos + (pos * 2);
+ for (;;)
+ {
+ if (offset >= _size || offset + 1 >= _size)
+ throw 1;
+ char c0 = _data[offset++];
+ char c1 = _data[offset++];
+ wchar_t c = (c0 | ((wchar_t)c1 << 8));
+ if (c == 0)
+ break;
+ s += c;
+ }
+ return s;
+}
+
/*
static AString ParsePrefix(const AString &prefix)
{
@@ -466,13 +503,27 @@ static AString GetVar(UInt32 index)
return res;
}
-// $0..$9, $INSTDIR, etc are encoded as ASCII bytes starting from this value.
#define NS_SKIP_CODE 252
#define NS_VAR_CODE 253
#define NS_SHELL_CODE 254
#define NS_LANG_CODE 255
#define NS_CODES_START NS_SKIP_CODE
+static AString GetShellString(int index)
+{
+ AString res = "$";
+ if (index < kNumShellStrings)
+ {
+ const char *sz = kShellStrings[index];
+ if (sz[0] != 0)
+ return res + sz;
+ }
+ res += "SHELL[";
+ res += UIntToString(index);
+ res += "]";
+ return res;
+}
+
// Based on Dave Laundon's simplified process_string
AString GetNsisString(const AString &s)
{
@@ -487,26 +538,7 @@ AString GetNsisString(const AString &s)
nData |= (((int)(c1 & 0x7F)) << 7);
if (nVarIdx == NS_SHELL_CODE)
- {
- UInt32 index = c1;
- bool needPrint = true;
- res += "$";
- if (index < kNumShellStrings)
- {
- const char *sz = kShellStrings[index];
- if (sz[0] != 0)
- {
- res += sz;
- needPrint = false;
- }
- }
- if (needPrint)
- {
- res += "SHELL[";
- res += UIntToString(index);
- res += "]";
- }
- }
+ res += GetShellString(c1);
else if (nVarIdx == NS_VAR_CODE)
res += GetVar(nData);
else if (nVarIdx == NS_LANG_CODE)
@@ -523,9 +555,53 @@ AString GetNsisString(const AString &s)
return res;
}
+UString GetNsisString(const UString &s)
+{
+ UString res;
+ for (int i = 0; i < s.Length();)
+ {
+ wchar_t nVarIdx = s[i++];
+ if (nVarIdx > NS_UN_CODES_START && nVarIdx <= NS_UN_CODES_END)
+ {
+ if (i == s.Length())
+ break;
+ int nData = s[i++] & 0x7FFF;
+
+ if (nVarIdx == NS_UN_SHELL_CODE)
+ res += GetUnicodeString(GetShellString(nData >> 8));
+ else if (nVarIdx == NS_UN_VAR_CODE)
+ res += GetUnicodeString(GetVar(nData));
+ else if (nVarIdx == NS_UN_LANG_CODE)
+ res += L"NS_LANG_CODE";
+ }
+ else if (nVarIdx == NS_UN_SKIP_CODE)
+ {
+ if (i == s.Length())
+ break;
+ res += s[i++];
+ }
+ else // Normal char
+ res += (char)nVarIdx;
+ }
+ return res;
+}
+
+AString CInArchive::ReadString2A(UInt32 pos)
+{
+ return GetNsisString(ReadStringA(pos));
+}
+
+UString CInArchive::ReadString2U(UInt32 pos)
+{
+ return GetNsisString(ReadStringU(pos));
+}
+
AString CInArchive::ReadString2(UInt32 pos)
{
- return GetNsisString(ReadString(pos));
+ if (IsUnicode)
+ return UnicodeStringToMultiByte(ReadString2U(pos));
+ else
+ return ReadString2A(pos);
}
#define DEL_DIR 1
@@ -566,7 +642,8 @@ AString CEntry::GetParamsString(int numParams)
HRESULT CInArchive::ReadEntries(const CBlockHeader &bh)
{
_posInData = bh.Offset + GetOffset();
- AString prefix;
+ AString prefixA;
+ UString prefixU;
for (UInt32 i = 0; i < bh.Num; i++)
{
CEntry e;
@@ -585,11 +662,22 @@ HRESULT CInArchive::ReadEntries(const CBlockHeader &bh)
{
case EW_CREATEDIR:
{
- prefix.Empty();
- prefix = ReadString2(e.Params[0]);
+ if (IsUnicode)
+ {
+ prefixU.Empty();
+ prefixU = ReadString2U(e.Params[0]);
+ }
+ else
+ {
+ prefixA.Empty();
+ prefixA = ReadString2A(e.Params[0]);
+ }
#ifdef NSIS_SCRIPT
Script += " ";
- Script += prefix;
+ if (IsUnicode)
+ Script += UnicodeStringToMultiByte(prefixU);
+ else
+ Script += prefixA;
#endif
break;
}
@@ -597,9 +685,18 @@ HRESULT CInArchive::ReadEntries(const CBlockHeader &bh)
case EW_EXTRACTFILE:
{
CItem item;
- item.Prefix = prefix;
+ item.IsUnicode = IsUnicode;
+ if (IsUnicode)
+ {
+ item.PrefixU = prefixU;
+ item.NameU = ReadString2U(e.Params[1]);
+ }
+ else
+ {
+ item.PrefixA = prefixA;
+ item.NameA = ReadString2A(e.Params[1]);
+ }
/* UInt32 overwriteFlag = e.Params[0]; */
- item.Name = ReadString2(e.Params[1]);
item.Pos = e.Params[2];
item.DateTime.dwLowDateTime = e.Params[3];
item.DateTime.dwHighDateTime = e.Params[4];
@@ -614,7 +711,11 @@ HRESULT CInArchive::ReadEntries(const CBlockHeader &bh)
Items.Add(item);
#ifdef NSIS_SCRIPT
Script += " ";
- Script += item.Name;
+
+ if (IsUnicode)
+ Script += UnicodeStringToMultiByte(item.NameU);
+ else
+ Script += item.NameA;
#endif
break;
}
@@ -908,7 +1009,10 @@ HRESULT CInArchive::ReadEntries(const CBlockHeader &bh)
// if (IsSolid)
for (i = 0; i + 1 < Items.Size();)
{
- if (Items[i].Pos == Items[i + 1].Pos && (IsSolid || Items[i].Name == Items[i + 1].Name))
+ bool sameName = IsUnicode ?
+ (Items[i].NameU == Items[i + 1].NameU) :
+ (Items[i].NameA == Items[i + 1].NameA);
+ if (Items[i].Pos == Items[i + 1].Pos && (IsSolid || sameName))
Items.Delete(i + 1);
else
i++;
@@ -927,8 +1031,8 @@ HRESULT CInArchive::ReadEntries(const CBlockHeader &bh)
RINOK(_stream->Seek(GetPosOfNonSolidItem(i), STREAM_SEEK_SET, NULL));
const UInt32 kSigSize = 4 + 1 + 5;
BYTE sig[kSigSize];
- UInt32 processedSize;
- RINOK(ReadStream(_stream, sig, kSigSize, &processedSize));
+ size_t processedSize = kSigSize;
+ RINOK(ReadStream(_stream, sig, &processedSize));
if (processedSize < 4)
return S_FALSE;
UInt32 size = GetUInt32FromMemLE(sig);
@@ -977,7 +1081,37 @@ HRESULT CInArchive::Parse()
ReadBlockHeader(bhData);
_stringsPos = bhStrings.Offset;
+ UInt32 pos = GetOffset() + _stringsPos;
+ int numZeros0 = 0;
+ int numZeros1 = 0;
+ int i;
+ const kBlockSize = 256;
+ for (i = 0; i < kBlockSize; i++)
+ {
+ if (pos >= _size || pos + 1 >= _size)
+ break;
+ char c0 = _data[pos++];
+ char c1 = _data[pos++];
+ wchar_t c = (c0 | ((wchar_t)c1 << 8));
+ if (c >= NS_UN_CODES_START && c < NS_UN_CODES_END)
+ {
+ if (pos >= _size || pos + 1 >= _size)
+ break;
+ pos += 2;
+ numZeros1++;
+ }
+ else
+ {
+ if (c0 == 0 && c1 != 0)
+ numZeros0++;
+ if (c1 == 0)
+ numZeros1++;
+ }
+ // printf("\nnumZeros0 = %2x %2x", _data[pos + 0], _data[pos + 1]);
+ }
+ IsUnicode = (numZeros1 > numZeros0 * 3 + kBlockSize / 16);
+ // printf("\nnumZeros0 = %3d numZeros1 = %3d", numZeros0, numZeros1);
return ReadEntries(bhEntries);
}
@@ -1010,10 +1144,7 @@ HRESULT CInArchive::Open2(
const UInt32 kSigSize = 4 + 1 + 5 + 1; // size, flag, lzma props, lzma first byte
BYTE sig[kSigSize];
- UInt32 processedSize;
- RINOK(ReadStream(_stream, sig, kSigSize, &processedSize));
- if (processedSize != kSigSize)
- return S_FALSE;
+ RINOK(ReadStream_FALSE(_stream, sig, kSigSize));
UInt64 position;
RINOK(_stream->Seek(StreamOffset, STREAM_SEEK_SET, &position));
@@ -1065,11 +1196,11 @@ HRESULT CInArchive::Open2(
RINOK(Decoder.Init(
EXTERNAL_CODECS_LOC_VARS
_stream, Method, FilterFlag, UseFilter));
- UInt32 processedSize;
- RINOK(Decoder.Read(_data, unpackSize, &processedSize));
+ size_t processedSize = unpackSize;
+ RINOK(Decoder.Read(_data, &processedSize));
if (processedSize != unpackSize)
return S_FALSE;
- _size = (size_t)processedSize;
+ _size = processedSize;
if (IsSolid)
{
UInt32 size2 = ReadUInt32();
@@ -1081,9 +1212,7 @@ HRESULT CInArchive::Open2(
{
_data.SetCapacity(unpackSize);
_size = (size_t)unpackSize;
- RINOK(ReadStream(_stream, (Byte *)_data, unpackSize, &processedSize));
- if (processedSize != unpackSize)
- return S_FALSE;
+ RINOK(ReadStream_FALSE(_stream, (Byte *)_data, unpackSize));
}
return Parse();
}
@@ -1138,22 +1267,17 @@ HRESULT CInArchive::Open(
UInt64 headerPosition = 0;
while (position <= maxSize)
{
- UInt32 processedSize;
- RINOK(ReadStream(inStream, buffer, kStartHeaderSize, &processedSize));
- if (processedSize != kStartHeaderSize)
- return S_FALSE;
+ RINOK(ReadStream_FALSE(inStream, buffer, kStartHeaderSize));
headerPosition = position;
- position += processedSize;
+ position += kStartHeaderSize;
if(memcmp(buffer + 4, kSignature, kSignatureSize) == 0)
{
found = true;
break;
}
const UInt32 kRem = kStep - kStartHeaderSize;
- RINOK(ReadStream(inStream, buffer + kStartHeaderSize, kRem, &processedSize));
- if (processedSize != kRem)
- return S_FALSE;
- position += processedSize;
+ RINOK(ReadStream_FALSE(inStream, buffer + kStartHeaderSize, kRem));
+ position += kRem;
}
if (!found)
return S_FALSE;
diff --git a/CPP/7zip/Archive/Nsis/NsisIn.h b/CPP/7zip/Archive/Nsis/NsisIn.h
index 22c050f1..e7908862 100755
--- a/CPP/7zip/Archive/Nsis/NsisIn.h
+++ b/CPP/7zip/Archive/Nsis/NsisIn.h
@@ -56,41 +56,56 @@ struct CBlockHeader
struct CItem
{
- AString Prefix;
- AString Name;
- UInt32 Pos;
+ AString PrefixA;
+ UString PrefixU;
+ AString NameA;
+ UString NameU;
+ FILETIME DateTime;
+ bool IsUnicode;
+ bool UseFilter;
+ bool IsCompressed;
bool SizeIsDefined;
bool CompressedSizeIsDefined;
bool EstimatedSizeIsDefined;
+ UInt32 Pos;
UInt32 Size;
UInt32 CompressedSize;
UInt32 EstimatedSize;
- FILETIME DateTime;
UInt32 DictionarySize;
- bool IsCompressed;
- bool UseFilter;
- CItem(): UseFilter(false), SizeIsDefined(false), EstimatedSizeIsDefined(false),
- IsCompressed(true), CompressedSizeIsDefined(false), Size(0) {}
+
+ CItem(): IsUnicode(false), UseFilter(false), IsCompressed(true), SizeIsDefined(false),
+ CompressedSizeIsDefined(false), EstimatedSizeIsDefined(false), Size(0) {}
bool IsINSTDIR() const
{
- if (Prefix.Length() < 3)
- return false;
- return true;
+ return (PrefixA.Length() >= 3 || PrefixU.Length() >= 3);
}
- AString GetReducedName() const
+ AString GetReducedNameA() const
{
- AString prefix = Prefix;
+ AString prefix = PrefixA;
if (prefix.Length() > 0)
if (prefix[prefix.Length() - 1] != '\\')
prefix += '\\';
- AString s2 = prefix + Name;
+ AString s2 = prefix + NameA;
const int len = 9;
if (s2.Left(len).CompareNoCase("$INSTDIR\\") == 0)
s2 = s2.Mid(len);
return s2;
}
+
+ UString GetReducedNameU() const
+ {
+ UString prefix = PrefixU;
+ if (prefix.Length() > 0)
+ if (prefix[prefix.Length() - 1] != L'\\')
+ prefix += L'\\';
+ UString s2 = prefix + NameU;
+ const int len = 9;
+ if (s2.Left(len).CompareNoCase(L"$INSTDIR\\") == 0)
+ s2 = s2.Mid(len);
+ return s2;
+ }
};
@@ -105,7 +120,10 @@ class CInArchive
DECL_EXTERNAL_CODECS_LOC_VARS2
);
void ReadBlockHeader(CBlockHeader &bh);
- AString ReadString(UInt32 pos);
+ AString ReadStringA(UInt32 pos);
+ UString ReadStringU(UInt32 pos);
+ AString ReadString2A(UInt32 pos);
+ UString ReadString2U(UInt32 pos);
AString ReadString2(UInt32 pos);
HRESULT ReadEntries(const CBlockHeader &bh);
HRESULT Parse();
@@ -129,12 +147,13 @@ public:
UInt64 StreamOffset;
CDecoder Decoder;
CObjectVector<CItem> Items;
- bool IsSolid;
CFirstHeader FirstHeader;
NMethodType::EEnum Method;
- bool UseFilter;
UInt32 DictionarySize;
+ bool IsSolid;
+ bool UseFilter;
bool FilterFlag;
+ bool IsUnicode;
#ifdef NSIS_SCRIPT
AString Script;
diff --git a/CPP/7zip/Archive/RPM/RpmHandler.cpp b/CPP/7zip/Archive/RPM/RpmHandler.cpp
index 7cd881a1..9a9f9af4 100755
--- a/CPP/7zip/Archive/RPM/RpmHandler.cpp
+++ b/CPP/7zip/Archive/RPM/RpmHandler.cpp
@@ -5,20 +5,15 @@
#include "RpmHandler.h"
#include "RpmIn.h"
-#include "Common/Defs.h"
-#include "Common/StringConvert.h"
-#include "Common/NewHandler.h"
#include "Common/ComTry.h"
+#include "Common/MyString.h"
#include "Windows/PropVariant.h"
-#include "Windows/Defs.h"
-#include "../../Common/StreamObjects.h"
#include "../../Common/ProgressUtils.h"
-#include "../../Common/LimitedStreams.h"
+#include "../../Common/StreamUtils.h"
#include "../../Compress/Copy/CopyCoder.h"
-#include "../Common/ItemNameUtils.h"
using namespace NWindows;
@@ -44,10 +39,14 @@ STDMETHODIMP CHandler::Open(IInStream *inStream,
if(OpenArchive(inStream) != S_OK)
return S_FALSE;
RINOK(inStream->Seek(0, STREAM_SEEK_CUR, &m_Pos));
- m_InStream = inStream;
UInt64 endPosition;
RINOK(inStream->Seek(0, STREAM_SEEK_END, &endPosition));
m_Size = endPosition - m_Pos;
+
+ RINOK(inStream->Seek(m_Pos, STREAM_SEEK_SET, NULL));
+ RINOK(ReadStream_FALSE(inStream, _sig, sizeof(_sig) / sizeof(_sig[0])));
+
+ m_InStream = inStream;
return S_OK;
}
catch(...)
@@ -78,6 +77,21 @@ STDMETHODIMP CHandler::GetProperty(UInt32 /* index */, PROPID propID, PROPVARIAN
case kpidPackedSize:
prop = m_Size;
break;
+ case kpidExtension:
+ {
+ wchar_t s[32];
+ MyStringCopy(s, L"cpio.");
+ const wchar_t *ext;
+ if (_sig[0] == 0x1F && _sig[1] == 0x8B)
+ ext = L"gz";
+ else if (_sig[0] == 'B' && _sig[1] == 'Z' && _sig[2] == 'h')
+ ext = L"bz2";
+ else
+ ext = L"lzma";
+ MyStringCopy(s + MyStringLen(s), ext);
+ prop = s;
+ break;
+ }
}
prop.Detach(value);
return S_OK;
diff --git a/CPP/7zip/Archive/RPM/RpmHandler.h b/CPP/7zip/Archive/RPM/RpmHandler.h
index c78e8ce3..92efc107 100755
--- a/CPP/7zip/Archive/RPM/RpmHandler.h
+++ b/CPP/7zip/Archive/RPM/RpmHandler.h
@@ -22,6 +22,7 @@ private:
CMyComPtr<IInStream> m_InStream;
UInt64 m_Pos;
UInt64 m_Size;
+ Byte _sig[4];
};
}}
diff --git a/CPP/7zip/Archive/RPM/RpmIn.cpp b/CPP/7zip/Archive/RPM/RpmIn.cpp
index c1600894..db7a6f63 100755
--- a/CPP/7zip/Archive/RPM/RpmIn.cpp
+++ b/CPP/7zip/Archive/RPM/RpmIn.cpp
@@ -32,10 +32,7 @@ static HRESULT RedSigHeaderSig(IInStream *inStream, CSigHeaderSig &h)
{
char dat[kCSigHeaderSigSize];
char *cur = dat;
- UInt32 processedSize;
- RINOK(ReadStream(inStream, dat, kCSigHeaderSigSize, &processedSize));
- if (kCSigHeaderSigSize != processedSize)
- return S_FALSE;
+ RINOK(ReadStream_FALSE(inStream, dat, kCSigHeaderSigSize));
memmove(h.Magic, cur, 4);
cur += 4;
cur += 4;
@@ -51,10 +48,7 @@ HRESULT OpenArchive(IInStream *inStream)
char leadData[kLeadSize];
char *cur = leadData;
CLead lead;
- UInt32 processedSize;
- RINOK(ReadStream(inStream, leadData, kLeadSize, &processedSize));
- if (kLeadSize != processedSize)
- return S_FALSE;
+ RINOK(ReadStream_FALSE(inStream, leadData, kLeadSize));
memmove(lead.Magic, cur, 4);
cur += 4;
lead.Major = *cur++;
diff --git a/CPP/7zip/Archive/RPM/RpmRegister.cpp b/CPP/7zip/Archive/RPM/RpmRegister.cpp
index 76eb2470..61082bac 100755
--- a/CPP/7zip/Archive/RPM/RpmRegister.cpp
+++ b/CPP/7zip/Archive/RPM/RpmRegister.cpp
@@ -8,6 +8,6 @@
static IInArchive *CreateArc() { return new NArchive::NRpm::CHandler; }
static CArcInfo g_ArcInfo =
- { L"Rpm", L"rpm", L".cpio.gz", 0xEB, { 0}, 0, false, CreateArc, 0 };
+ { L"Rpm", L"rpm", 0, 0xEB, { 0}, 0, false, CreateArc, 0 };
REGISTER_ARC(Rpm)
diff --git a/CPP/7zip/Archive/Rar/RarHandler.cpp b/CPP/7zip/Archive/Rar/RarHandler.cpp
index fd0952d1..435c5c17 100755
--- a/CPP/7zip/Archive/Rar/RarHandler.cpp
+++ b/CPP/7zip/Archive/Rar/RarHandler.cpp
@@ -167,7 +167,7 @@ STDMETHODIMP CHandler::GetProperty(UInt32 index, PROPID propID, PROPVARIANT *va
case kpidIsFolder: prop = item.IsDirectory(); break;
case kpidSize: prop = item.UnPackSize; break;
case kpidPackedSize: prop = GetPackSize(index); break;
- case kpidLastWriteTime: RarTimeToProp(item.LastWriteTime, prop);
+ case kpidLastWriteTime: RarTimeToProp(item.LastWriteTime, prop); break;
case kpidCreationTime: if (item.IsCreationTimeDefined) RarTimeToProp(item.CreationTime, prop); break;
case kpidLastAccessTime: if (item.IsLastAccessTimeDefined) RarTimeToProp(item.LastAccessTime, prop); break;
case kpidAttributes: prop = item.GetWinAttributes(); break;
@@ -243,6 +243,17 @@ public:
{
_afterPart = L".rar";
basePart = name.Left(dotPos);
+ }
+ else if (!_newStyle)
+ {
+ if (ext.CompareNoCase(L"000") == 0 || ext.CompareNoCase(L"001") == 0)
+ {
+ _afterPart.Empty();
+ _first = false;
+ _changedPart = ext;
+ _unchangedPart = name.Left(dotPos + 1);
+ return true;
+ }
}
}
diff --git a/CPP/7zip/Archive/Rar/RarIn.cpp b/CPP/7zip/Archive/Rar/RarIn.cpp
index 0af72a48..efb87fb7 100755
--- a/CPP/7zip/Archive/Rar/RarIn.cpp
+++ b/CPP/7zip/Archive/Rar/RarIn.cpp
@@ -118,9 +118,7 @@ bool CInArchive::ReadBytesAndTestSize(void *data, UInt32 size)
((Byte *)data)[i] = bufData[m_CryptoPos++];
return (i == size);
}
- UInt32 processedSize;
- ReadStream(m_Stream, data, size, &processedSize);
- return (processedSize == size);
+ return (ReadStream_FALSE(m_Stream, data, size) == S_OK);
}
void CInArchive::ReadBytesAndTestResult(void *data, UInt32 size)
@@ -131,10 +129,10 @@ void CInArchive::ReadBytesAndTestResult(void *data, UInt32 size)
HRESULT CInArchive::ReadBytes(void *data, UInt32 size, UInt32 *processedSize)
{
- UInt32 realProcessedSize;
- HRESULT result = ReadStream(m_Stream, data, size, &realProcessedSize);
- if(processedSize != NULL)
- *processedSize = realProcessedSize;
+ size_t realProcessedSize = size;
+ HRESULT result = ReadStream(m_Stream, data, &realProcessedSize);
+ if (processedSize != NULL)
+ *processedSize = (UInt32)realProcessedSize;
AddToSeekValue(realProcessedSize);
return result;
}
@@ -465,7 +463,9 @@ HRESULT CInArchive::GetNextItem(CItemEx &item, ICryptoGetTextPassword *getTextPa
m_DecryptedData.SetCapacity(kDecryptedBufferSize);
}
RINOK(m_RarAES->Init());
- RINOK(ReadStream(m_Stream, (Byte *)m_DecryptedData, kDecryptedBufferSize, &m_DecryptedDataSize));
+ size_t decryptedDataSizeT = kDecryptedBufferSize;
+ RINOK(ReadStream(m_Stream, (Byte *)m_DecryptedData, &decryptedDataSizeT));
+ m_DecryptedDataSize = (UInt32)decryptedDataSizeT;
m_DecryptedDataSize = m_RarAES->Filter((Byte *)m_DecryptedData, m_DecryptedDataSize);
m_CryptoMode = true;
@@ -529,11 +529,6 @@ HRESULT CInArchive::GetNextItem(CItemEx &item, ICryptoGetTextPassword *getTextPa
}
}
-void CInArchive::DirectGetBytes(void *data, UInt32 size)
-{
- ReadStream(m_Stream, data, size, NULL);
-}
-
bool CInArchive::SeekInArchive(UInt64 position)
{
UInt64 newPosition;
diff --git a/CPP/7zip/Archive/Rar/RarIn.h b/CPP/7zip/Archive/Rar/RarIn.h
index f1dee321..94cea223 100755
--- a/CPP/7zip/Archive/Rar/RarIn.h
+++ b/CPP/7zip/Archive/Rar/RarIn.h
@@ -112,8 +112,6 @@ public:
void GetArchiveInfo(CInArchiveInfo &archiveInfo) const;
- void DirectGetBytes(void *data, UInt32 size);
-
bool SeekInArchive(UInt64 position);
ISequentialInStream *CreateLimitedStream(UInt64 position, UInt64 size);
};
diff --git a/CPP/7zip/Archive/Tar/TarHeader.h b/CPP/7zip/Archive/Tar/TarHeader.h
index 0ab31e52..19bb1cac 100755
--- a/CPP/7zip/Archive/Tar/TarHeader.h
+++ b/CPP/7zip/Archive/Tar/TarHeader.h
@@ -75,6 +75,15 @@ namespace NFileHeader
const char kDirectory = '5'; // Directory
const char kFIFO = '6'; // FIFO special file
const char kContiguous = '7'; // Contiguous file
+
+ const char kDumpDir = 'D'; /* GNUTYPE_DUMPDIR.
+ data: list of files created by the --incremental (-G) option
+ Each file name is preceded by either
+ - 'Y' (file should be in this archive)
+ - 'N' (file is a directory, or is not stored in the archive.)
+ Each file name is terminated by a null + an additional null after
+ the last file name. */
+
}
// Further link types may be defined later.
diff --git a/CPP/7zip/Archive/Tar/TarIn.cpp b/CPP/7zip/Archive/Tar/TarIn.cpp
index bae1db86..1318613a 100755
--- a/CPP/7zip/Archive/Tar/TarIn.cpp
+++ b/CPP/7zip/Archive/Tar/TarIn.cpp
@@ -13,9 +13,10 @@
namespace NArchive {
namespace NTar {
-HRESULT CInArchive::ReadBytes(void *data, UInt32 size, UInt32 &processedSize)
+HRESULT CInArchive::ReadBytes(void *data, size_t size, size_t &processedSize)
{
- RINOK(ReadStream(m_Stream, data, size, &processedSize));
+ processedSize = size;
+ RINOK(ReadStream(m_Stream, data, &processedSize));
m_Position += processedSize;
return S_OK;
}
@@ -93,7 +94,7 @@ HRESULT CInArchive::GetNextItemReal(bool &filled, CItemEx &item)
filled = false;
- UInt32 processedSize;
+ size_t processedSize;
item.HeaderPosition = m_Position;
RINOK(ReadBytes(record, NFileHeader::kRecordSize, processedSize));
if (processedSize == 0 ||
@@ -174,7 +175,8 @@ HRESULT CInArchive::GetNextItemReal(bool &filled, CItemEx &item)
AString prefix;
ReadString(cur, NFileHeader::kPrefixSize, prefix);
cur += NFileHeader::kPrefixSize;
- if (!prefix.IsEmpty() && item.IsMagic())
+ if (!prefix.IsEmpty() && item.IsMagic() &&
+ (item.LinkFlag != 'L' /* || prefix != "00000000000" */ ))
item.Name = prefix + AString('/') + item.Name;
if (item.LinkFlag == NFileHeader::NLinkFlag::kLink)
@@ -205,10 +207,12 @@ HRESULT CInArchive::GetNextItem(bool &filled, CItemEx &item)
return S_FALSE;
UInt64 headerPosition = item.HeaderPosition;
- UInt32 processedSize;
+ size_t processedSize;
AString fullName;
- char *buffer = fullName.GetBuffer((UInt32)item.Size + 1);
- RINOK(ReadBytes(buffer, (UInt32)item.Size, processedSize));
+ if (item.Size > (1 << 15))
+ return S_FALSE;
+ char *buffer = fullName.GetBuffer((int)item.Size + 1);
+ RINOK(ReadBytes(buffer, (size_t)item.Size, processedSize));
buffer[item.Size] = '\0';
fullName.ReleaseBuffer();
if (processedSize != item.Size)
@@ -224,6 +228,11 @@ HRESULT CInArchive::GetNextItem(bool &filled, CItemEx &item)
// pax Extended Header
return S_OK;
}
+ else if (item.LinkFlag == NFileHeader::NLinkFlag::kDumpDir)
+ {
+ // GNU Extensions to the Archive Format
+ return S_OK;
+ }
else if (item.LinkFlag > '7' || (item.LinkFlag < '0' && item.LinkFlag != 0))
return S_FALSE;
return S_OK;
diff --git a/CPP/7zip/Archive/Tar/TarIn.h b/CPP/7zip/Archive/Tar/TarIn.h
index 28781375..20c030ef 100755
--- a/CPP/7zip/Archive/Tar/TarIn.h
+++ b/CPP/7zip/Archive/Tar/TarIn.h
@@ -16,7 +16,7 @@ class CInArchive
CMyComPtr<IInStream> m_Stream;
UInt64 m_Position;
- HRESULT ReadBytes(void *data, UInt32 size, UInt32 &processedSize);
+ HRESULT ReadBytes(void *data, size_t size, size_t &processedSize);
public:
HRESULT Open(IInStream *inStream);
HRESULT GetNextItemReal(bool &filled, CItemEx &itemInfo);
diff --git a/CPP/7zip/Archive/Tar/TarItem.h b/CPP/7zip/Archive/Tar/TarItem.h
index 10b57cd0..451d74bc 100755
--- a/CPP/7zip/Archive/Tar/TarItem.h
+++ b/CPP/7zip/Archive/Tar/TarItem.h
@@ -35,16 +35,18 @@ public:
UInt32 DeviceMinor;
bool IsDirectory() const
- {
- if (LinkFlag == NFileHeader::NLinkFlag::kDirectory)
+ {
+ switch(LinkFlag)
+ {
+ case NFileHeader::NLinkFlag::kDirectory:
+ case NFileHeader::NLinkFlag::kDumpDir:
return true;
- if (LinkFlag == NFileHeader::NLinkFlag::kOldNormal ||
- LinkFlag == NFileHeader::NLinkFlag::kNormal)
- {
+ case NFileHeader::NLinkFlag::kOldNormal:
+ case NFileHeader::NLinkFlag::kNormal:
return NItemName::HasTailSlash(Name, CP_OEMCP);
- }
- return false;
}
+ return false;
+ }
bool IsMagic() const
{
diff --git a/CPP/7zip/Archive/Tar/TarOut.cpp b/CPP/7zip/Archive/Tar/TarOut.cpp
index e278edda..a697b4d2 100755
--- a/CPP/7zip/Archive/Tar/TarOut.cpp
+++ b/CPP/7zip/Archive/Tar/TarOut.cpp
@@ -14,11 +14,7 @@ namespace NTar {
HRESULT COutArchive::WriteBytes(const void *buffer, UInt32 size)
{
- UInt32 processedSize;
- RINOK(WriteStream(m_Stream, buffer, size, &processedSize));
- if(processedSize != size)
- return E_FAIL;
- return S_OK;
+ return WriteStream(m_Stream, buffer, size);
}
void COutArchive::Create(ISequentialOutStream *outStream)
diff --git a/CPP/7zip/Archive/Wim/WimHandler.cpp b/CPP/7zip/Archive/Wim/WimHandler.cpp
index 38c1c6ae..baa2c824 100755
--- a/CPP/7zip/Archive/Wim/WimHandler.cpp
+++ b/CPP/7zip/Archive/Wim/WimHandler.cpp
@@ -76,7 +76,7 @@ STDMETHODIMP CHandler::GetArchiveProperty(PROPID propID, PROPVARIANT *value)
{
UInt16 volIndex = m_Xmls[0].VolIndex;
if (volIndex < m_Volumes.Size())
- prop = m_Volumes[volIndex].Header.PartNumber;
+ prop = (UInt32)m_Volumes[volIndex].Header.PartNumber;
}
break;
case kpidNumVolumes: if (m_Volumes.Size() > 0) prop = (UInt32)(m_Volumes.Size() - 1);
@@ -413,7 +413,7 @@ STDMETHODIMP CHandler::Extract(const UInt32* indices, UInt32 numItems,
currentItemUnPacked = data.GetCapacity();
if (realOutStream)
{
- RINOK(WriteStream(realOutStream, (const Byte *)data, (UInt32)data.GetCapacity(), NULL));
+ RINOK(WriteStream(realOutStream, (const Byte *)data, data.GetCapacity()));
realOutStream.Release();
}
RINOK(extractCallback->SetOperationResult(NExtract::NOperationResult::kOK));
diff --git a/CPP/7zip/Archive/Wim/WimIn.cpp b/CPP/7zip/Archive/Wim/WimIn.cpp
index 951fc79b..e9efdaa4 100755
--- a/CPP/7zip/Archive/Wim/WimIn.cpp
+++ b/CPP/7zip/Archive/Wim/WimIn.cpp
@@ -21,27 +21,10 @@ namespace NWim{
static const int kChunkSizeBits = 15;
static const UInt32 kChunkSize = (1 << kChunkSizeBits);
-static HRESULT ReadBytes(ISequentialInStream *inStream, void *data, UInt32 size)
-{
- UInt32 realProcessedSize;
- RINOK(ReadStream(inStream, data, size, &realProcessedSize));
- return (realProcessedSize == size) ? S_OK : S_FALSE;
-}
-
-#ifdef LITTLE_ENDIAN_UNALIGN
-static inline UInt16 GetUInt16FromMem(const Byte *p) { return *(const UInt16 *)p; }
-static inline UInt32 GetUInt32FromMem(const Byte *p) { return *(const UInt32 *)p; }
-static inline UInt64 GetUInt64FromMem(const Byte *p) { return *(const UInt64 *)p; }
-#else
-static UInt16 GetUInt16FromMem(const Byte *p) { return p[0] | ((UInt16)p[1] << 8); }
-static UInt32 GetUInt32FromMem(const Byte *p) { return p[0] | ((UInt32)p[1] << 8) | ((UInt32)p[2] << 16) | ((UInt32)p[3] << 24); }
-static UInt64 GetUInt64FromMem(const Byte *p) { return GetUInt32FromMem(p) | ((UInt64)GetUInt32FromMem(p + 4) << 32); }
-#endif
-
static void GetFileTimeFromMem(const Byte *p, FILETIME *ft)
{
- ft->dwLowDateTime = GetUInt32FromMem(p);
- ft->dwHighDateTime = GetUInt32FromMem(p + 4);
+ ft->dwLowDateTime = GetUi32(p);
+ ft->dwHighDateTime = GetUi32(p + 4);
}
HRESULT CUnpacker::Unpack(IInStream *inStream, const CResource &resource,
@@ -70,7 +53,7 @@ HRESULT CUnpacker::Unpack(IInStream *inStream, const CResource &resource,
UInt64 numChunks = (resource.UnpackSize + kChunkSize - 1) >> kChunkSizeBits;
unsigned entrySize = ((resource.UnpackSize > (UInt64)1 << 32) ? 8 : 4);
UInt64 sizesBufSize64 = entrySize * (numChunks - 1);
- UInt32 sizesBufSize = (UInt32)sizesBufSize64;
+ size_t sizesBufSize = (size_t)sizesBufSize64;
if (sizesBufSize != sizesBufSize64)
return E_OUTOFMEMORY;
if (sizesBufSize > sizesBuf.GetCapacity())
@@ -78,7 +61,7 @@ HRESULT CUnpacker::Unpack(IInStream *inStream, const CResource &resource,
sizesBuf.Free();
sizesBuf.SetCapacity(sizesBufSize);
}
- RINOK(ReadBytes(inStream, (Byte *)sizesBuf, sizesBufSize));
+ RINOK(ReadStream_FALSE(inStream, (Byte *)sizesBuf, sizesBufSize));
const Byte *p = (const Byte *)sizesBuf;
if (!lzxDecoder)
@@ -96,17 +79,17 @@ HRESULT CUnpacker::Unpack(IInStream *inStream, const CResource &resource,
if (i > 0)
{
if (entrySize == 4)
- offset = GetUInt32FromMem(p);
+ offset = GetUi32(p);
else
- offset = GetUInt64FromMem(p);
+ offset = GetUi64(p);
p += entrySize;
}
UInt64 nextOffset = resource.PackSize - sizesBufSize64;
if (i + 1 < (UInt32)numChunks)
if (entrySize == 4)
- nextOffset = GetUInt32FromMem(p);
+ nextOffset = GetUi32(p);
else
- nextOffset = GetUInt64FromMem(p);
+ nextOffset = GetUi64(p);
if (nextOffset < offset)
return S_FALSE;
@@ -166,16 +149,16 @@ static const Byte kSignature[kSignatureSize] = { 'M', 'S', 'W', 'I', 'M', 0, 0,
static void GetResource(const Byte *p, CResource &res)
{
res.Flags = p[7];
- res.PackSize = GetUInt64FromMem(p) & (((UInt64)1 << 56) - 1);
- res.Offset = GetUInt64FromMem(p + 8);
- res.UnpackSize = GetUInt64FromMem(p + 16);
+ res.PackSize = GetUi64(p) & (((UInt64)1 << 56) - 1);
+ res.Offset = GetUi64(p + 8);
+ res.UnpackSize = GetUi64(p + 16);
}
static void GetStream(const Byte *p, CStreamInfo &s)
{
GetResource(p, s.Resource);
- s.PartNumber = GetUInt16FromMem(p + 24);
- s.RefCount = GetUInt32FromMem(p + 26);
+ s.PartNumber = GetUi16(p + 24);
+ s.RefCount = GetUi32(p + 26);
memcpy(s.Hash, p + 30, kHashSize);
}
@@ -187,22 +170,22 @@ static HRESULT ParseDirItem(const Byte *base, size_t pos, size_t size,
if (pos + 8 > size)
return S_FALSE;
const Byte *p = base + pos;
- UInt64 length = GetUInt64FromMem(p);
+ UInt64 length = GetUi64(p);
if (length == 0)
return S_OK;
if (pos + 102 > size || pos + length + 8 > size || length > ((UInt64)1 << 62))
return S_FALSE;
CItem item;
- item.Attributes = GetUInt32FromMem(p + 8);
- // item.SecurityId = GetUInt32FromMem(p + 0xC);
- UInt64 subdirOffset = GetUInt64FromMem(p + 0x10);
+ item.Attributes = GetUi32(p + 8);
+ // item.SecurityId = GetUi32(p + 0xC);
+ UInt64 subdirOffset = GetUi64(p + 0x10);
GetFileTimeFromMem(p + 0x28, &item.CreationTime);
GetFileTimeFromMem(p + 0x30, &item.LastAccessTime);
GetFileTimeFromMem(p + 0x38, &item.LastWriteTime);
memcpy(item.Hash, p + 0x40, kHashSize);
- // UInt16 shortNameLen = GetUInt16FromMem(p + 98);
- UInt16 fileNameLen = GetUInt16FromMem(p + 100);
+ // UInt16 shortNameLen = GetUi16(p + 98);
+ UInt16 fileNameLen = GetUi16(p + 100);
size_t tempPos = pos + 102;
if (tempPos + fileNameLen > size)
@@ -212,7 +195,7 @@ static HRESULT ParseDirItem(const Byte *base, size_t pos, size_t size,
MyStringCopy(sz, (const wchar_t *)prefix);
sz += prefix.Length();
for (UInt16 i = 0; i + 2 <= fileNameLen; i += 2)
- *sz++ = GetUInt16FromMem(base + tempPos + i);
+ *sz++ = GetUi16(base + tempPos + i);
*sz++ = '\0';
item.Name.ReleaseBuffer();
if (fileNameLen == 0 && item.IsDirectory() && !item.HasStream())
@@ -238,8 +221,8 @@ static HRESULT ParseDir(const Byte *base, size_t size,
if (pos + 8 > size)
return S_FALSE;
const Byte *p = base + pos;
- UInt32 totalLength = GetUInt32FromMem(p);
- // UInt32 numEntries = GetUInt32FromMem(p + 4);
+ UInt32 totalLength = GetUi32(p);
+ // UInt32 numEntries = GetUi32(p + 4);
pos += 8;
{
/*
@@ -249,7 +232,7 @@ static HRESULT ParseDir(const Byte *base, size_t size,
{
if (pos + 8 > size)
return S_FALSE;
- UInt64 len = GetUInt64FromMem(p + pos);
+ UInt64 len = GetUi64(p + pos);
entryLens.Add(len);
sum += len;
pos += 8;
@@ -322,25 +305,25 @@ HRESULT ReadHeader(IInStream *inStream, CHeader &h)
{
const UInt32 kHeaderSizeMax = 0xD0;
Byte p[kHeaderSizeMax];
- RINOK(ReadBytes(inStream, p, kHeaderSizeMax));
- UInt32 haderSize = GetUInt32FromMem(p + 8);
+ RINOK(ReadStream_FALSE(inStream, p, kHeaderSizeMax));
+ UInt32 haderSize = GetUi32(p + 8);
if (memcmp(p, kSignature, kSignatureSize) != 0)
return S_FALSE;
if (haderSize < 0x74)
return S_FALSE;
- h.Version = GetUInt32FromMem(p + 0x0C);
- h.Flags = GetUInt32FromMem(p + 0x10);
+ h.Version = GetUi32(p + 0x0C);
+ h.Flags = GetUi32(p + 0x10);
if (!h.IsSupported())
return S_FALSE;
- if (GetUInt32FromMem(p + 0x14) != kChunkSize)
+ if (GetUi32(p + 0x14) != kChunkSize)
return S_FALSE;
memcpy(h.Guid, p + 0x18, 16);
- h.PartNumber = GetUInt16FromMem(p + 0x28);
- h.NumParts = GetUInt16FromMem(p + 0x2A);
+ h.PartNumber = GetUi16(p + 0x28);
+ h.NumParts = GetUi16(p + 0x2A);
int offset = 0x2C;
if (h.IsNewVersion())
{
- h.NumImages = GetUInt32FromMem(p + offset);
+ h.NumImages = GetUi32(p + offset);
offset += 4;
}
GetResource(p + offset, h.OffsetResource);
@@ -352,7 +335,7 @@ HRESULT ReadHeader(IInStream *inStream, CHeader &h)
if (haderSize < 0xD0)
return S_FALSE;
GetResource(p + offset + 0x4C, h.IntegrityResource);
- h.BootIndex = GetUInt32FromMem(p + 0x48);
+ h.BootIndex = GetUi32(p + 0x48);
}
*/
return S_OK;
diff --git a/CPP/7zip/Archive/Z/ZHandler.cpp b/CPP/7zip/Archive/Z/ZHandler.cpp
index 73f391f7..81289050 100755
--- a/CPP/7zip/Archive/Z/ZHandler.cpp
+++ b/CPP/7zip/Archive/Z/ZHandler.cpp
@@ -55,10 +55,7 @@ STDMETHODIMP CHandler::Open(IInStream *stream,
{
RINOK(stream->Seek(0, STREAM_SEEK_CUR, &_streamStartPosition));
Byte buffer[kSignatureSize];
- UInt32 processedSize;
- RINOK(ReadStream(stream, buffer, kSignatureSize, &processedSize));
- if (processedSize != kSignatureSize)
- return S_FALSE;
+ RINOK(ReadStream_FALSE(stream, buffer, kSignatureSize));
if (buffer[0] != 0x1F || buffer[1] != 0x9D)
return S_FALSE;
_properties = buffer[2];
diff --git a/CPP/7zip/Archive/Zip/ZipAddCommon.cpp b/CPP/7zip/Archive/Zip/ZipAddCommon.cpp
index 0344f776..0f76b04a 100755
--- a/CPP/7zip/Archive/Zip/ZipAddCommon.cpp
+++ b/CPP/7zip/Archive/Zip/ZipAddCommon.cpp
@@ -43,7 +43,7 @@ static HRESULT GetStreamCRC(ISequentialInStream *inStream, UInt32 &resultCRC)
resultCRC = CRC_GET_DIGEST(crc);
return S_OK;
}
- crc = CrcUpdate(crc, buffer, realProcessedSize);
+ crc = CrcUpdate(crc, buffer, (size_t)realProcessedSize);
}
}
diff --git a/CPP/7zip/Archive/Zip/ZipHandler.cpp b/CPP/7zip/Archive/Zip/ZipHandler.cpp
index c3576eeb..7d478a36 100755
--- a/CPP/7zip/Archive/Zip/ZipHandler.cpp
+++ b/CPP/7zip/Archive/Zip/ZipHandler.cpp
@@ -81,6 +81,9 @@ STATPROPSTG kProps[] =
{ NULL, kpidSize, VT_UI8},
{ NULL, kpidPackedSize, VT_UI8},
{ NULL, kpidLastWriteTime, VT_FILETIME},
+ { NULL, kpidCreationTime, VT_FILETIME},
+ { NULL, kpidLastAccessTime, VT_FILETIME},
+
{ NULL, kpidAttributes, VT_UI4},
{ NULL, kpidEncrypted, VT_BOOL},
@@ -150,17 +153,18 @@ CHandler::CHandler():
InitMethodProperties();
}
-static void StringToProp(const CByteBuffer &data, UINT codePage, NWindows::NCOM::CPropVariant &prop)
+static AString BytesToString(const CByteBuffer &data)
{
- int size = (int)data.GetCapacity();
- if (size <= 0)
- return;
AString s;
- char *p = s.GetBuffer(size + 1);
- memcpy(p, (const Byte *)data, size);
- p[size] = '\0';
- s.ReleaseBuffer();
- prop = MultiByteToUnicodeString(s, codePage);
+ int size = (int)data.GetCapacity();
+ if (size > 0)
+ {
+ char *p = s.GetBuffer(size + 1);
+ memcpy(p, (const Byte *)data, size);
+ p[size] = '\0';
+ s.ReleaseBuffer();
+ }
+ return s;
}
IMP_IInArchive_Props
@@ -173,10 +177,8 @@ STDMETHODIMP CHandler::GetArchiveProperty(PROPID propID, PROPVARIANT *value)
switch(propID)
{
case kpidComment:
- {
- StringToProp(m_Archive.m_ArchiveInfo.Comment, CP_ACP, prop);
+ prop = MultiByteToUnicodeString(BytesToString(m_Archive.m_ArchiveInfo.Comment), CP_ACP);
break;
- }
}
prop.Detach(value);
COM_TRY_END
@@ -197,8 +199,7 @@ STDMETHODIMP CHandler::GetProperty(UInt32 index, PROPID propID, PROPVARIANT *val
switch(propID)
{
case kpidPath:
- prop = NItemName::GetOSName2(
- MultiByteToUnicodeString(item.Name, item.GetCodePage()));
+ prop = NItemName::GetOSName2(item.GetUnicodeString(item.Name));
break;
case kpidIsFolder:
prop = item.IsDirectory();
@@ -209,16 +210,39 @@ STDMETHODIMP CHandler::GetProperty(UInt32 index, PROPID propID, PROPVARIANT *val
case kpidPackedSize:
prop = item.PackSize;
break;
+ case kpidTimeType:
+ FILETIME utcFileTime;
+ if (item.CentralExtra.GetNtfsTime(NFileHeader::NNtfsExtra::kTagTime, utcFileTime))
+ prop = (UInt32)NFileTimeType::kWindows;
+ break;
+ case kpidCreationTime:
+ {
+ FILETIME ft;
+ if (item.CentralExtra.GetNtfsTime(NFileHeader::NNtfsExtra::kCTime, ft))
+ prop = ft;
+ break;
+ }
+ case kpidLastAccessTime:
+ {
+ FILETIME ft;
+ if (item.CentralExtra.GetNtfsTime(NFileHeader::NNtfsExtra::kATime, ft))
+ prop = ft;
+ break;
+ }
case kpidLastWriteTime:
{
- FILETIME localFileTime, utcFileTime;
- if (DosTimeToFileTime(item.Time, localFileTime))
+ FILETIME utcFileTime;
+ if (!item.CentralExtra.GetNtfsTime(NFileHeader::NNtfsExtra::kMTime, utcFileTime))
{
- if (!LocalFileTimeToFileTime(&localFileTime, &utcFileTime))
+ FILETIME localFileTime;
+ if (DosTimeToFileTime(item.Time, localFileTime))
+ {
+ if (!LocalFileTimeToFileTime(&localFileTime, &utcFileTime))
+ utcFileTime.dwHighDateTime = utcFileTime.dwLowDateTime = 0;
+ }
+ else
utcFileTime.dwHighDateTime = utcFileTime.dwLowDateTime = 0;
}
- else
- utcFileTime.dwHighDateTime = utcFileTime.dwLowDateTime = 0;
prop = utcFileTime;
break;
}
@@ -230,7 +254,7 @@ STDMETHODIMP CHandler::GetProperty(UInt32 index, PROPID propID, PROPVARIANT *val
break;
case kpidComment:
{
- StringToProp(item.Comment, item.GetCodePage(), prop);
+ prop = item.GetUnicodeString(BytesToString(item.Comment));
break;
}
case kpidCRC:
diff --git a/CPP/7zip/Archive/Zip/ZipHandler.h b/CPP/7zip/Archive/Zip/ZipHandler.h
index 28f44196..c8fa392c 100755
--- a/CPP/7zip/Archive/Zip/ZipHandler.h
+++ b/CPP/7zip/Archive/Zip/ZipHandler.h
@@ -59,6 +59,10 @@ private:
bool m_IsAesMode;
Byte m_AesKeyMode;
+ bool m_WriteNtfsTimeExtra;
+ bool m_ForseLocal;
+ bool m_ForseUtf8;
+
#ifdef COMPRESS_MT
UInt32 _numThreads;
#endif
@@ -77,6 +81,9 @@ private:
m_NumMatchFinderCyclesDefined = false;
m_IsAesMode = false;
m_AesKeyMode = 3; // aes-256
+ m_WriteNtfsTimeExtra = false;
+ m_ForseLocal = false;
+ m_ForseUtf8 = false;
#ifdef COMPRESS_MT
_numThreads = NWindows::NSystem::GetNumberOfProcessors();;
#endif
diff --git a/CPP/7zip/Archive/Zip/ZipHandlerOut.cpp b/CPP/7zip/Archive/Zip/ZipHandlerOut.cpp
index 453c37a3..2846c988 100755
--- a/CPP/7zip/Archive/Zip/ZipHandlerOut.cpp
+++ b/CPP/7zip/Archive/Zip/ZipHandlerOut.cpp
@@ -66,138 +66,179 @@ static bool IsAsciiString(const UString &s)
catch(const CSystemException &e) { return e.ErrorCode; } \
catch(...) { return E_OUTOFMEMORY; }
+static HRESULT GetTime(IArchiveUpdateCallback *callback, int index, PROPID propID, FILETIME &filetime)
+{
+ filetime.dwHighDateTime = filetime.dwLowDateTime = 0;
+ NCOM::CPropVariant prop;
+ RINOK(callback->GetProperty(index, propID, &prop));
+ if (prop.vt == VT_FILETIME)
+ filetime = prop.filetime;
+ else if (prop.vt != VT_EMPTY)
+ return E_INVALIDARG;
+ return S_OK;
+}
+
STDMETHODIMP CHandler::UpdateItems(ISequentialOutStream *outStream, UInt32 numItems,
- IArchiveUpdateCallback *updateCallback)
+ IArchiveUpdateCallback *callback)
{
COM_TRY_BEGIN2
CObjectVector<CUpdateItem> updateItems;
for(UInt32 i = 0; i < numItems; i++)
{
- CUpdateItem updateItem;
+ CUpdateItem ui;
Int32 newData;
Int32 newProperties;
UInt32 indexInArchive;
- if (!updateCallback)
+ if (!callback)
return E_FAIL;
- RINOK(updateCallback->GetUpdateItemInfo(i,
+ RINOK(callback->GetUpdateItemInfo(i,
&newData, // 1 - compress 0 - copy
&newProperties,
&indexInArchive));
- updateItem.NewProperties = IntToBool(newProperties);
- updateItem.NewData = IntToBool(newData);
- updateItem.IndexInArchive = indexInArchive;
- updateItem.IndexInClient = i;
+ ui.NewProperties = IntToBool(newProperties);
+ ui.NewData = IntToBool(newData);
+ ui.IndexInArchive = indexInArchive;
+ ui.IndexInClient = i;
// bool existInArchive = (indexInArchive != UInt32(-1));
if (IntToBool(newProperties))
{
- FILETIME utcFileTime;
UString name;
bool isDirectoryStatusDefined;
{
- NCOM::CPropVariant propVariant;
- RINOK(updateCallback->GetProperty(i, kpidAttributes, &propVariant));
- if (propVariant.vt == VT_EMPTY)
- updateItem.Attributes = 0;
- else if (propVariant.vt != VT_UI4)
+ NCOM::CPropVariant prop;
+ RINOK(callback->GetProperty(i, kpidAttributes, &prop));
+ if (prop.vt == VT_EMPTY)
+ ui.Attributes = 0;
+ else if (prop.vt != VT_UI4)
return E_INVALIDARG;
else
- updateItem.Attributes = propVariant.ulVal;
- }
- {
- NCOM::CPropVariant propVariant;
- RINOK(updateCallback->GetProperty(i, kpidLastWriteTime, &propVariant));
- if (propVariant.vt != VT_FILETIME)
- return E_INVALIDARG;
- utcFileTime = propVariant.filetime;
+ ui.Attributes = prop.ulVal;
}
+
{
- NCOM::CPropVariant propVariant;
- RINOK(updateCallback->GetProperty(i, kpidPath, &propVariant));
- if (propVariant.vt == VT_EMPTY)
+ NCOM::CPropVariant prop;
+ RINOK(callback->GetProperty(i, kpidPath, &prop));
+ if (prop.vt == VT_EMPTY)
name.Empty();
- else if (propVariant.vt != VT_BSTR)
+ else if (prop.vt != VT_BSTR)
return E_INVALIDARG;
else
- name = propVariant.bstrVal;
+ name = prop.bstrVal;
}
{
- NCOM::CPropVariant propVariant;
- RINOK(updateCallback->GetProperty(i, kpidIsFolder, &propVariant));
- if (propVariant.vt == VT_EMPTY)
+ NCOM::CPropVariant prop;
+ RINOK(callback->GetProperty(i, kpidIsFolder, &prop));
+ if (prop.vt == VT_EMPTY)
isDirectoryStatusDefined = false;
- else if (propVariant.vt != VT_BOOL)
+ else if (prop.vt != VT_BOOL)
return E_INVALIDARG;
else
{
- updateItem.IsDirectory = (propVariant.boolVal != VARIANT_FALSE);
+ ui.IsDirectory = (prop.boolVal != VARIANT_FALSE);
isDirectoryStatusDefined = true;
}
}
- FILETIME localFileTime;
- if(!FileTimeToLocalFileTime(&utcFileTime, &localFileTime))
- return E_INVALIDARG;
- if(!FileTimeToDosTime(localFileTime, updateItem.Time))
+
+ {
+ CPropVariant prop;
+ RINOK(callback->GetProperty(i, kpidTimeType, &prop));
+ if (prop.vt == VT_UI4)
+ ui.NtfsTimeIsDefined = (prop.ulVal == NFileTimeType::kWindows);
+ else
+ ui.NtfsTimeIsDefined = m_WriteNtfsTimeExtra;
+ }
+ RINOK(GetTime(callback, i, kpidLastWriteTime, ui.NtfsMTime));
+ RINOK(GetTime(callback, i, kpidLastAccessTime, ui.NtfsATime));
+ RINOK(GetTime(callback, i, kpidCreationTime, ui.NtfsCTime));
+
{
- // return E_INVALIDARG;
+ FILETIME localFileTime = { 0, 0 };
+ if (ui.NtfsMTime.dwHighDateTime != 0 ||
+ ui.NtfsMTime.dwLowDateTime != 0)
+ if (!FileTimeToLocalFileTime(&ui.NtfsMTime, &localFileTime))
+ return E_INVALIDARG;
+ FileTimeToDosTime(localFileTime, ui.Time);
}
if (!isDirectoryStatusDefined)
- updateItem.IsDirectory = ((updateItem.Attributes & FILE_ATTRIBUTE_DIRECTORY) != 0);
+ ui.IsDirectory = ((ui.Attributes & FILE_ATTRIBUTE_DIRECTORY) != 0);
name = NItemName::MakeLegalName(name);
- bool needSlash = updateItem.IsDirectory;
+ bool needSlash = ui.IsDirectory;
const wchar_t kSlash = L'/';
if (!name.IsEmpty())
{
if (name[name.Length() - 1] == kSlash)
{
- if (!updateItem.IsDirectory)
+ if (!ui.IsDirectory)
return E_INVALIDARG;
needSlash = false;
}
}
if (needSlash)
name += kSlash;
- updateItem.Name = UnicodeStringToMultiByte(name, CP_OEMCP);
- if (updateItem.Name.Length() > 0xFFFF)
+
+ bool tryUtf8 = true;
+ if (m_ForseLocal || !m_ForseUtf8)
+ {
+ bool defaultCharWasUsed;
+ ui.Name = UnicodeStringToMultiByte(name, CP_OEMCP, '_', defaultCharWasUsed);
+ tryUtf8 = (!m_ForseLocal && defaultCharWasUsed);
+ }
+
+ if (tryUtf8)
+ {
+ bool needUtf = false;
+ for (int i = 0; i < name.Length(); i++)
+ if ((unsigned)name[i] >= 0x80)
+ {
+ needUtf = true;
+ break;
+ }
+ ui.IsUtf8 = needUtf;
+ if (!ConvertUnicodeToUTF8(name, ui.Name))
+ return E_INVALIDARG;
+ }
+
+ if (ui.Name.Length() > 0xFFFF)
return E_INVALIDARG;
- updateItem.IndexInClient = i;
+ ui.IndexInClient = i;
/*
if(existInArchive)
{
const CItemEx &itemInfo = m_Items[indexInArchive];
- // updateItem.Commented = itemInfo.IsCommented();
- updateItem.Commented = false;
- if(updateItem.Commented)
+ // ui.Commented = itemInfo.IsCommented();
+ ui.Commented = false;
+ if(ui.Commented)
{
- updateItem.CommentRange.Position = itemInfo.GetCommentPosition();
- updateItem.CommentRange.Size = itemInfo.CommentSize;
+ ui.CommentRange.Position = itemInfo.GetCommentPosition();
+ ui.CommentRange.Size = itemInfo.CommentSize;
}
}
else
- updateItem.Commented = false;
+ ui.Commented = false;
*/
}
if (IntToBool(newData))
{
UInt64 size;
{
- NCOM::CPropVariant propVariant;
- RINOK(updateCallback->GetProperty(i, kpidSize, &propVariant));
- if (propVariant.vt != VT_UI8)
+ NCOM::CPropVariant prop;
+ RINOK(callback->GetProperty(i, kpidSize, &prop));
+ if (prop.vt != VT_UI8)
return E_INVALIDARG;
- size = propVariant.uhVal.QuadPart;
+ size = prop.uhVal.QuadPart;
}
- updateItem.Size = size;
+ ui.Size = size;
}
- updateItems.Add(updateItem);
+ updateItems.Add(ui);
}
CMyComPtr<ICryptoGetTextPassword2> getTextPassword;
if (!getTextPassword)
{
- CMyComPtr<IArchiveUpdateCallback> udateCallBack2(updateCallback);
+ CMyComPtr<IArchiveUpdateCallback> udateCallBack2(callback);
udateCallBack2.QueryInterface(IID_ICryptoGetTextPassword2, &getTextPassword);
}
CCompressionMethodMode options;
@@ -281,7 +322,7 @@ STDMETHODIMP CHandler::UpdateItems(ISequentialOutStream *outStream, UInt32 numIt
return Update(
EXTERNAL_CODECS_VARS
m_Items, updateItems, outStream,
- m_ArchiveIsOpen ? &m_Archive : NULL, &options, updateCallback);
+ m_ArchiveIsOpen ? &m_Archive : NULL, &options, callback);
COM_TRY_END2
}
@@ -406,6 +447,22 @@ STDMETHODIMP CHandler::SetProperties(const wchar_t **names, const PROPVARIANT *v
RINOK(ParsePropValue(name.Mid(1), prop, num));
m_Algo = num;
}
+ else if (name.CompareNoCase(L"TC") == 0)
+ return SetBoolProperty(m_WriteNtfsTimeExtra, prop);
+ else if (name.CompareNoCase(L"CL") == 0)
+ {
+ RINOK(SetBoolProperty(m_ForseLocal, prop));
+ if (m_ForseLocal)
+ m_ForseUtf8 = false;
+ return S_OK;
+ }
+ else if (name.CompareNoCase(L"CU") == 0)
+ {
+ RINOK(SetBoolProperty(m_ForseUtf8, prop));
+ if (m_ForseUtf8)
+ m_ForseLocal = false;
+ return S_OK;
+ }
else
return E_INVALIDARG;
}
diff --git a/CPP/7zip/Archive/Zip/ZipHeader.h b/CPP/7zip/Archive/Zip/ZipHeader.h
index 98ad17a3..0c978a7c 100755
--- a/CPP/7zip/Archive/Zip/ZipHeader.h
+++ b/CPP/7zip/Archive/Zip/ZipHeader.h
@@ -86,11 +86,23 @@ namespace NFileHeader
enum
{
kZip64 = 0x01,
+ kNTFS = 0x0A,
kStrongEncrypt = 0x17,
kWzAES = 0x9901
};
}
+ namespace NNtfsExtra
+ {
+ const UInt16 kTagTime = 1;
+ enum
+ {
+ kMTime = 0,
+ kATime = 1,
+ kCTime = 2
+ };
+ }
+
const UInt32 kLocalBlockSize = 26;
/*
struct CLocalBlock
@@ -156,13 +168,11 @@ namespace NFileHeader
namespace NFlags
{
- const int kNumUsedBits = 4;
- const int kUsedBitsMask = (1 << kNumUsedBits) - 1;
-
const int kEncrypted = 1 << 0;
const int kDescriptorUsedMask = 1 << 3;
const int kStrongEncrypted = 1 << 6;
-
+ const int kUtf8 = 1 << 11;
+
const int kImplodeDictionarySizeMask = 1 << 1;
const int kImplodeLiteralsOnMask = 1 << 2;
diff --git a/CPP/7zip/Archive/Zip/ZipIn.cpp b/CPP/7zip/Archive/Zip/ZipIn.cpp
index b579f9b4..f8e81c59 100755
--- a/CPP/7zip/Archive/Zip/ZipIn.cpp
+++ b/CPP/7zip/Archive/Zip/ZipIn.cpp
@@ -114,10 +114,10 @@ bool CInArchive::FindAndReadMarker(const UInt64 *searchHeaderSizeLimit)
HRESULT CInArchive::ReadBytes(void *data, UInt32 size, UInt32 *processedSize)
{
- UInt32 realProcessedSize;
- HRESULT result = ReadStream(m_Stream, data, size, &realProcessedSize);
+ size_t realProcessedSize = size;
+ HRESULT result = ReadStream(m_Stream, data, &realProcessedSize);
if(processedSize != NULL)
- *processedSize = realProcessedSize;
+ *processedSize = (UInt32)realProcessedSize;
m_Position += realProcessedSize;
return result;
}
@@ -304,7 +304,7 @@ HRESULT CInArchive::ReadLocalItem(CItemEx &item)
{
item.ExtractVersion.Version = ReadByte();
item.ExtractVersion.HostOS = ReadByte();
- item.Flags = ReadUInt16(); // & NFileHeader::NFlags::kUsedBitsMask;
+ item.Flags = ReadUInt16();
item.CompressionMethod = ReadUInt16();
item.Time = ReadUInt32();
item.FileCRC = ReadUInt32();
@@ -467,7 +467,7 @@ HRESULT CInArchive::ReadCdItem(CItemEx &item)
item.MadeByVersion.HostOS = ReadByte();
item.ExtractVersion.Version = ReadByte();
item.ExtractVersion.HostOS = ReadByte();
- item.Flags = ReadUInt16(); // & NFileHeader::NFlags::kUsedBitsMask;
+ item.Flags = ReadUInt16();
item.CompressionMethod = ReadUInt16();
item.Time = ReadUInt32();
item.FileCRC = ReadUInt32();
@@ -772,7 +772,7 @@ HRESULT CInArchive::ReadHeaders(CObjectVector<CItemEx> &items, CProgressVirt *pr
return S_FALSE;
UInt16 thisDiskNumber16 = ReadUInt16();
- if (!isZip64 || thisDiskNumber16)
+ if (!isZip64 || thisDiskNumber16 != 0xFFFF)
thisDiskNumber = thisDiskNumber16;
UInt16 startCDDiskNumber16 = ReadUInt16();
diff --git a/CPP/7zip/Archive/Zip/ZipItem.cpp b/CPP/7zip/Archive/Zip/ZipItem.cpp
index 480a1abb..484696f5 100755
--- a/CPP/7zip/Archive/Zip/ZipItem.cpp
+++ b/CPP/7zip/Archive/Zip/ZipItem.cpp
@@ -5,6 +5,7 @@
#include "ZipHeader.h"
#include "ZipItem.h"
#include "../Common/ItemNameUtils.h"
+#include "../../../../C/CpuArch.h"
namespace NArchive {
namespace NZip {
@@ -19,6 +20,37 @@ bool operator!=(const CVersion &v1, const CVersion &v2)
return !(v1 == v2);
}
+bool CExtraSubBlock::ExtractNtfsTime(int index, FILETIME &ft) const
+{
+ ft.dwHighDateTime = ft.dwLowDateTime = 0;
+ UInt32 size = (UInt32)Data.GetCapacity();
+ if (ID != NFileHeader::NExtraID::kNTFS || size < 32)
+ return false;
+ const Byte *p = (const Byte *)Data;
+ p += 4; // for reserved
+ size -= 4;
+ while (size > 4)
+ {
+ UInt16 tag = GetUi16(p);
+ UInt32 attrSize = GetUi16(p + 2);
+ p += 4;
+ size -= 4;
+ if (attrSize > size)
+ attrSize = size;
+
+ if (tag == NFileHeader::NNtfsExtra::kTagTime && attrSize >= 24)
+ {
+ p += 8 * index;
+ ft.dwLowDateTime = GetUi32(p);
+ ft.dwHighDateTime = GetUi32(p + 4);
+ return true;
+ }
+ p += attrSize;
+ size -= attrSize;
+ }
+ return false;
+}
+
bool CLocalItem::IsImplodeBigDictionary() const
{
if (CompressionMethod != NFileHeader::NCompressionMethod::kImploded)
@@ -126,5 +158,7 @@ void CLocalItem::SetBitMask(int bitMask, bool enable)
void CLocalItem::SetEncrypted(bool encrypted)
{ SetBitMask(NFileHeader::NFlags::kEncrypted, encrypted); }
+void CLocalItem::SetUtf8(bool isUtf8)
+ { SetBitMask(NFileHeader::NFlags::kUtf8, isUtf8); }
}}
diff --git a/CPP/7zip/Archive/Zip/ZipItem.h b/CPP/7zip/Archive/Zip/ZipItem.h
index 350e81b6..8d7cc3b4 100755
--- a/CPP/7zip/Archive/Zip/ZipItem.h
+++ b/CPP/7zip/Archive/Zip/ZipItem.h
@@ -6,6 +6,8 @@
#include "Common/Types.h"
#include "Common/MyString.h"
#include "Common/Buffer.h"
+#include "Common/UTFConvert.h"
+#include "Common/StringConvert.h"
#include "ZipHeader.h"
@@ -25,6 +27,7 @@ struct CExtraSubBlock
{
UInt16 ID;
CByteBuffer Data;
+ bool ExtractNtfsTime(int index, FILETIME &ft) const;
};
struct CWzAesExtraField
@@ -137,6 +140,17 @@ struct CExtraBlock
return GetWzAesField(aesField);
}
+ bool GetNtfsTime(int index, FILETIME &ft) const
+ {
+ for (int i = 0; i < SubBlocks.Size(); i++)
+ {
+ const CExtraSubBlock &sb = SubBlocks[i];
+ if (sb.ID == NFileHeader::NExtraID::kNTFS)
+ return sb.ExtractNtfsTime(index, ft);
+ }
+ return false;
+ }
+
/*
bool HasStrongCryptoField() const
{
@@ -147,14 +161,9 @@ struct CExtraBlock
void RemoveUnknownSubBlocks()
{
- for (int i = SubBlocks.Size() - 1; i >= 0;)
- {
- const CExtraSubBlock &subBlock = SubBlocks[i];
- if (subBlock.ID != NFileHeader::NExtraID::kWzAES)
+ for (int i = SubBlocks.Size() - 1; i >= 0; i--)
+ if (SubBlocks[i].ID != NFileHeader::NExtraID::kWzAES)
SubBlocks.Delete(i);
- else
- i--;
- }
}
};
@@ -173,6 +182,8 @@ public:
AString Name;
CExtraBlock LocalExtra;
+
+ bool IsUtf8() const { return (Flags & NFileHeader::NFlags::kUtf8) != 0; }
bool IsEncrypted() const { return (Flags & NFileHeader::NFlags::kEncrypted) != 0; }
bool IsStrongEncrypted() const { return IsEncrypted() && (Flags & NFileHeader::NFlags::kStrongEncrypted) != 0; };
@@ -186,6 +197,16 @@ public:
bool HasDescriptor() const { return (Flags & NFileHeader::NFlags::kDescriptorUsedMask) != 0; }
+ UString GetUnicodeString(const AString &s) const
+ {
+ UString res;
+ if (IsUtf8())
+ if (!ConvertUTF8ToUnicode(s, res))
+ res.Empty();
+ if (res.IsEmpty())
+ res = MultiByteToUnicodeString(s, GetCodePage());
+ return res;
+ }
private:
void SetFlagBits(int startBitNumber, int numBits, int value);
@@ -193,11 +214,9 @@ private:
public:
void ClearFlags() { Flags = 0; }
void SetEncrypted(bool encrypted);
+ void SetUtf8(bool isUtf8);
- WORD GetCodePage() const
- {
- return CP_OEMCP;
- }
+ WORD GetCodePage() const { return CP_OEMCP; }
};
class CItem: public CLocalItem
@@ -209,11 +228,16 @@ public:
UInt64 LocalHeaderPosition;
+ FILETIME NtfsMTime;
+ FILETIME NtfsATime;
+ FILETIME NtfsCTime;
+
CExtraBlock CentralExtra;
CByteBuffer Comment;
bool FromLocal;
bool FromCentral;
+ bool NtfsTimeIsDefined;
bool IsDirectory() const;
UInt32 GetWinAttributes() const;
@@ -235,7 +259,7 @@ public:
|| MadeByVersion.HostOS == NFileHeader::NHostOS::kNTFS
) ? CP_OEMCP : CP_ACP);
}
- CItem() : FromLocal(false), FromCentral(false) {}
+ CItem() : FromLocal(false), FromCentral(false), NtfsTimeIsDefined(false) {}
};
}}
diff --git a/CPP/7zip/Archive/Zip/ZipOut.cpp b/CPP/7zip/Archive/Zip/ZipOut.cpp
index d5e6895e..fd89b1e8 100755
--- a/CPP/7zip/Archive/Zip/ZipOut.cpp
+++ b/CPP/7zip/Archive/Zip/ZipOut.cpp
@@ -172,7 +172,8 @@ void COutArchive::WriteCentralHeader(const CItem &item)
WriteUInt32(isUnPack64 ? 0xFFFFFFFF: (UInt32)item.UnPackSize);
WriteUInt16((UInt16)item.Name.Length());
UInt16 zip64ExtraSize = (UInt16)((isUnPack64 ? 8: 0) + (isPack64 ? 8: 0) + (isPosition64 ? 8: 0));
- UInt16 centralExtraSize = (UInt16)(isZip64 ? (4 + zip64ExtraSize) : 0);
+ const UInt16 kNtfsExtraSize = 4 + 2 + 2 + (3 * 8);
+ UInt16 centralExtraSize = (UInt16)(isZip64 ? (4 + zip64ExtraSize) : 0) + (item.NtfsTimeIsDefined ? (4 + kNtfsExtraSize) : 0);
centralExtraSize = (UInt16)(centralExtraSize + item.CentralExtra.GetSize());
WriteUInt16(centralExtraSize); // test it;
WriteUInt16((UInt16)item.Comment.GetCapacity());
@@ -192,6 +193,20 @@ void COutArchive::WriteCentralHeader(const CItem &item)
if(isPosition64)
WriteUInt64(item.LocalHeaderPosition);
}
+ if (item.NtfsTimeIsDefined)
+ {
+ WriteUInt16(NFileHeader::NExtraID::kNTFS);
+ WriteUInt16(kNtfsExtraSize);
+ WriteUInt32(0); // reserved
+ WriteUInt16(NFileHeader::NNtfsExtra::kTagTime);
+ WriteUInt16(8 * 3);
+ WriteUInt32(item.NtfsMTime.dwLowDateTime);
+ WriteUInt32(item.NtfsMTime.dwHighDateTime);
+ WriteUInt32(item.NtfsATime.dwLowDateTime);
+ WriteUInt32(item.NtfsATime.dwHighDateTime);
+ WriteUInt32(item.NtfsCTime.dwLowDateTime);
+ WriteUInt32(item.NtfsCTime.dwHighDateTime);
+ }
WriteExtra(item.CentralExtra);
if (item.Comment.GetCapacity() > 0)
WriteBytes(item.Comment, (UInt32)item.Comment.GetCapacity());
diff --git a/CPP/7zip/Archive/Zip/ZipUpdate.cpp b/CPP/7zip/Archive/Zip/ZipUpdate.cpp
index 6cfa64e2..2ec08981 100755
--- a/CPP/7zip/Archive/Zip/ZipUpdate.cpp
+++ b/CPP/7zip/Archive/Zip/ZipUpdate.cpp
@@ -69,12 +69,19 @@ static void SetFileHeader(
item.UnPackSize = updateItem.Size;
bool isDirectory;
+ item.ClearFlags();
+
if (updateItem.NewProperties)
{
isDirectory = updateItem.IsDirectory;
item.Name = updateItem.Name;
+ item.SetUtf8(updateItem.IsUtf8);
item.ExternalAttributes = updateItem.Attributes;
item.Time = updateItem.Time;
+ item.NtfsMTime = updateItem.NtfsMTime;
+ item.NtfsATime = updateItem.NtfsATime;
+ item.NtfsCTime = updateItem.NtfsCTime;
+ item.NtfsTimeIsDefined = updateItem.NtfsTimeIsDefined;
}
else
isDirectory = item.IsDirectory();
@@ -86,7 +93,6 @@ static void SetFileHeader(
item.ExtractVersion.HostOS = kExtractHostOS;
item.InternalAttributes = 0; // test it
- item.ClearFlags();
item.SetEncrypted(!isDirectory && options.PasswordIsDefined);
if (isDirectory)
{
@@ -341,7 +347,13 @@ static HRESULT UpdateItemOldData(COutArchive &archive,
// item.ExternalAttributes = updateItem.Attributes;
// Test it
item.Name = updateItem.Name;
+ item.SetUtf8(updateItem.IsUtf8);
item.Time = updateItem.Time;
+ item.NtfsMTime = updateItem.NtfsMTime;
+ item.NtfsATime = updateItem.NtfsATime;
+ item.NtfsCTime = updateItem.NtfsCTime;
+ item.NtfsTimeIsDefined = updateItem.NtfsTimeIsDefined;
+
item.CentralExtra.RemoveUnknownSubBlocks();
item.LocalExtra.RemoveUnknownSubBlocks();
diff --git a/CPP/7zip/Archive/Zip/ZipUpdate.h b/CPP/7zip/Archive/Zip/ZipUpdate.h
index 168eedd6..5e67bead 100755
--- a/CPP/7zip/Archive/Zip/ZipUpdate.h
+++ b/CPP/7zip/Archive/Zip/ZipUpdate.h
@@ -27,6 +27,8 @@ struct CUpdateItem
bool NewData;
bool NewProperties;
bool IsDirectory;
+ bool NtfsTimeIsDefined;
+ bool IsUtf8;
int IndexInArchive;
int IndexInClient;
UInt32 Attributes;
@@ -35,7 +37,11 @@ struct CUpdateItem
AString Name;
// bool Commented;
// CUpdateRange CommentRange;
- CUpdateItem(): Size(0) {}
+ FILETIME NtfsMTime;
+ FILETIME NtfsATime;
+ FILETIME NtfsCTime;
+
+ CUpdateItem(): NtfsTimeIsDefined(false), IsUtf8(false), Size(0) {}
};
HRESULT Update(
diff --git a/CPP/7zip/Bundles/Alone/Alone.dsp b/CPP/7zip/Bundles/Alone/Alone.dsp
index 49a7f037..d50fb15e 100755
--- a/CPP/7zip/Bundles/Alone/Alone.dsp
+++ b/CPP/7zip/Bundles/Alone/Alone.dsp
@@ -708,22 +708,6 @@ SOURCE=..\..\Common\VirtThread.h
# PROP Default_Filter ""
# Begin Source File
-SOURCE=..\..\Compress\Branch\ARM.cpp
-# End Source File
-# Begin Source File
-
-SOURCE=..\..\Compress\Branch\ARM.h
-# End Source File
-# Begin Source File
-
-SOURCE=..\..\Compress\Branch\ARMThumb.cpp
-# End Source File
-# Begin Source File
-
-SOURCE=..\..\Compress\Branch\ARMThumb.h
-# End Source File
-# Begin Source File
-
SOURCE=..\..\Compress\Branch\BCJ2Register.cpp
# End Source File
# Begin Source File
@@ -740,35 +724,19 @@ SOURCE=..\..\Compress\Branch\BranchCoder.h
# End Source File
# Begin Source File
-SOURCE=..\..\Compress\Branch\BranchRegister.cpp
-# End Source File
-# Begin Source File
-
-SOURCE=..\..\Compress\Branch\Coder.h
-# End Source File
-# Begin Source File
-
-SOURCE=..\..\Compress\Branch\IA64.cpp
-# End Source File
-# Begin Source File
-
-SOURCE=..\..\Compress\Branch\IA64.h
-# End Source File
-# Begin Source File
-
-SOURCE=..\..\Compress\Branch\PPC.cpp
+SOURCE=..\..\Compress\Branch\BranchMisc.cpp
# End Source File
# Begin Source File
-SOURCE=..\..\Compress\Branch\PPC.h
+SOURCE=..\..\Compress\Branch\BranchMisc.h
# End Source File
# Begin Source File
-SOURCE=..\..\Compress\Branch\SPARC.cpp
+SOURCE=..\..\Compress\Branch\BranchRegister.cpp
# End Source File
# Begin Source File
-SOURCE=..\..\Compress\Branch\SPARC.h
+SOURCE=..\..\Compress\Branch\Coder.h
# End Source File
# Begin Source File
@@ -1272,31 +1240,6 @@ SOURCE=..\..\Compress\Z\ZDecoder.h
# PROP Default_Filter ""
# Begin Source File
-SOURCE=..\..\Compress\BWT\BlockSort.cpp
-
-!IF "$(CFG)" == "Alone - Win32 Release"
-
-# ADD CPP /O2
-# SUBTRACT CPP /YX /Yc /Yu
-
-!ELSEIF "$(CFG)" == "Alone - Win32 Debug"
-
-!ELSEIF "$(CFG)" == "Alone - Win32 ReleaseU"
-
-# ADD CPP /O2
-# SUBTRACT CPP /YX /Yc /Yu
-
-!ELSEIF "$(CFG)" == "Alone - Win32 DebugU"
-
-!ENDIF
-
-# End Source File
-# Begin Source File
-
-SOURCE=..\..\Compress\BWT\BlockSort.h
-# End Source File
-# Begin Source File
-
SOURCE=..\..\Compress\BWT\Mtf8.h
# End Source File
# End Group
@@ -1852,6 +1795,42 @@ SOURCE=..\..\Archive\Cab\CabItem.h
SOURCE=..\..\Archive\Cab\CabRegister.cpp
# End Source File
# End Group
+# Begin Group "Lzma - Ar"
+
+# PROP Default_Filter ""
+# Begin Source File
+
+SOURCE=..\..\Archive\Lzma\LzmaArcRegister.cpp
+# End Source File
+# Begin Source File
+
+SOURCE=..\..\Archive\Lzma\LzmaFiltersDecode.cpp
+# End Source File
+# Begin Source File
+
+SOURCE=..\..\Archive\Lzma\LzmaFiltersDecode.h
+# End Source File
+# Begin Source File
+
+SOURCE=..\..\Archive\Lzma\LzmaHandler.cpp
+# End Source File
+# Begin Source File
+
+SOURCE=..\..\Archive\Lzma\LzmaHandler.h
+# End Source File
+# Begin Source File
+
+SOURCE=..\..\Archive\Lzma\LzmaIn.cpp
+# End Source File
+# Begin Source File
+
+SOURCE=..\..\Archive\Lzma\LzmaIn.h
+# End Source File
+# Begin Source File
+
+SOURCE=..\..\Archive\Lzma\LzmaItem.h
+# End Source File
+# End Group
# End Group
# Begin Group "UI Common"
@@ -2213,28 +2192,6 @@ SOURCE=..\..\Crypto\Hash\Sha1.cpp
SOURCE=..\..\Crypto\Hash\Sha1.h
# End Source File
-# Begin Source File
-
-SOURCE=..\..\Crypto\Hash\Sha256.cpp
-
-!IF "$(CFG)" == "Alone - Win32 Release"
-
-# ADD CPP /O2
-# SUBTRACT CPP /YX /Yc /Yu
-
-!ELSEIF "$(CFG)" == "Alone - Win32 Debug"
-
-!ELSEIF "$(CFG)" == "Alone - Win32 ReleaseU"
-
-!ELSEIF "$(CFG)" == "Alone - Win32 DebugU"
-
-!ENDIF
-
-# End Source File
-# Begin Source File
-
-SOURCE=..\..\Crypto\Hash\Sha256.h
-# End Source File
# End Group
# End Group
# Begin Group "7-zip"
@@ -2268,113 +2225,302 @@ SOURCE=..\..\PropID.h
# Begin Group "C"
# PROP Default_Filter ""
-# Begin Group "C-Compress"
+# Begin Source File
-# PROP Default_Filter ""
-# Begin Group "C Lz"
+SOURCE=..\..\..\..\C\7zCrc.c
-# PROP Default_Filter ""
+!IF "$(CFG)" == "Alone - Win32 Release"
+
+# ADD CPP /O2
+# SUBTRACT CPP /YX /Yc /Yu
+
+!ELSEIF "$(CFG)" == "Alone - Win32 Debug"
+
+# SUBTRACT CPP /YX /Yc /Yu
+
+!ELSEIF "$(CFG)" == "Alone - Win32 ReleaseU"
+
+# SUBTRACT CPP /YX /Yc /Yu
+
+!ELSEIF "$(CFG)" == "Alone - Win32 DebugU"
+
+# SUBTRACT CPP /YX /Yc /Yu
+
+!ENDIF
+
+# End Source File
# Begin Source File
-SOURCE=..\..\..\..\C\Compress\Lz\LzHash.h
+SOURCE=..\..\..\..\C\7zCrc.h
# End Source File
# Begin Source File
-SOURCE=..\..\..\..\C\Compress\Lz\MatchFinder.c
+SOURCE=..\..\..\..\C\Aes.c
+
+!IF "$(CFG)" == "Alone - Win32 Release"
+
+# ADD CPP /O2
+# SUBTRACT CPP /YX /Yc /Yu
+
+!ELSEIF "$(CFG)" == "Alone - Win32 Debug"
+
+# SUBTRACT CPP /YX /Yc /Yu
+
+!ELSEIF "$(CFG)" == "Alone - Win32 ReleaseU"
+
+# SUBTRACT CPP /YX /Yc /Yu
+
+!ELSEIF "$(CFG)" == "Alone - Win32 DebugU"
+
# SUBTRACT CPP /YX /Yc /Yu
+
+!ENDIF
+
# End Source File
# Begin Source File
-SOURCE=..\..\..\..\C\Compress\Lz\MatchFinderMt.c
-# SUBTRACT CPP /YX /Yc /Yu
+SOURCE=..\..\..\..\C\Aes.h
# End Source File
# Begin Source File
-SOURCE=..\..\..\..\C\Compress\Lz\MatchFinderMt.h
+SOURCE=..\..\..\..\C\Alloc.c
+
+!IF "$(CFG)" == "Alone - Win32 Release"
+
+# ADD CPP /O2
+# SUBTRACT CPP /YX /Yc /Yu
+
+!ELSEIF "$(CFG)" == "Alone - Win32 Debug"
+
+# SUBTRACT CPP /YX /Yc /Yu
+
+!ELSEIF "$(CFG)" == "Alone - Win32 ReleaseU"
+
+# SUBTRACT CPP /YX /Yc /Yu
+
+!ELSEIF "$(CFG)" == "Alone - Win32 DebugU"
+
+# SUBTRACT CPP /YX /Yc /Yu
+
+!ENDIF
+
# End Source File
-# End Group
-# Begin Group "C Huffman"
+# Begin Source File
-# PROP Default_Filter ""
+SOURCE=..\..\..\..\C\Alloc.h
+# End Source File
# Begin Source File
-SOURCE=..\..\..\..\C\Compress\Huffman\HuffmanEncode.c
+SOURCE=..\..\..\..\C\Bcj2.c
+
+!IF "$(CFG)" == "Alone - Win32 Release"
+
+# ADD CPP /O2
+# SUBTRACT CPP /YX /Yc /Yu
+
+!ELSEIF "$(CFG)" == "Alone - Win32 Debug"
+
# SUBTRACT CPP /YX /Yc /Yu
+
+!ELSEIF "$(CFG)" == "Alone - Win32 ReleaseU"
+
+# SUBTRACT CPP /YX /Yc /Yu
+
+!ELSEIF "$(CFG)" == "Alone - Win32 DebugU"
+
+# SUBTRACT CPP /YX /Yc /Yu
+
+!ENDIF
+
# End Source File
# Begin Source File
-SOURCE=..\..\..\..\C\Compress\Huffman\HuffmanEncode.h
+SOURCE=..\..\..\..\C\Bcj2.h
# End Source File
-# End Group
-# Begin Group "C Branch"
-
-# PROP Default_Filter ""
# Begin Source File
-SOURCE=..\..\..\..\C\Compress\Branch\BranchARM.c
+SOURCE=..\..\..\..\C\Bra.c
+
+!IF "$(CFG)" == "Alone - Win32 Release"
+
+# ADD CPP /O2
+# SUBTRACT CPP /YX /Yc /Yu
+
+!ELSEIF "$(CFG)" == "Alone - Win32 Debug"
+
+# SUBTRACT CPP /YX /Yc /Yu
+
+!ELSEIF "$(CFG)" == "Alone - Win32 ReleaseU"
+
# SUBTRACT CPP /YX /Yc /Yu
+
+!ELSEIF "$(CFG)" == "Alone - Win32 DebugU"
+
+# SUBTRACT CPP /YX /Yc /Yu
+
+!ENDIF
+
# End Source File
# Begin Source File
-SOURCE=..\..\..\..\C\Compress\Branch\BranchARM.h
+SOURCE=..\..\..\..\C\Bra.h
# End Source File
# Begin Source File
-SOURCE=..\..\..\..\C\Compress\Branch\BranchARMThumb.c
+SOURCE=..\..\..\..\C\Bra86.c
+
+!IF "$(CFG)" == "Alone - Win32 Release"
+
+# ADD CPP /O2
+# SUBTRACT CPP /YX /Yc /Yu
+
+!ELSEIF "$(CFG)" == "Alone - Win32 Debug"
+
+# SUBTRACT CPP /YX /Yc /Yu
+
+!ELSEIF "$(CFG)" == "Alone - Win32 ReleaseU"
+
+# SUBTRACT CPP /YX /Yc /Yu
+
+!ELSEIF "$(CFG)" == "Alone - Win32 DebugU"
+
# SUBTRACT CPP /YX /Yc /Yu
+
+!ENDIF
+
# End Source File
# Begin Source File
-SOURCE=..\..\..\..\C\Compress\Branch\BranchARMThumb.h
+SOURCE=..\..\..\..\C\BraIA64.c
+# SUBTRACT CPP /YX /Yc /Yu
# End Source File
# Begin Source File
-SOURCE=..\..\..\..\C\Compress\Branch\BranchIA64.c
+SOURCE=..\..\..\..\C\BwtSort.c
+
+!IF "$(CFG)" == "Alone - Win32 Release"
+
+# ADD CPP /O2
+# SUBTRACT CPP /YX /Yc /Yu
+
+!ELSEIF "$(CFG)" == "Alone - Win32 Debug"
+
+# SUBTRACT CPP /YX /Yc /Yu
+
+!ELSEIF "$(CFG)" == "Alone - Win32 ReleaseU"
+
+# SUBTRACT CPP /YX /Yc /Yu
+
+!ELSEIF "$(CFG)" == "Alone - Win32 DebugU"
+
# SUBTRACT CPP /YX /Yc /Yu
+
+!ENDIF
+
+# End Source File
+# Begin Source File
+
+SOURCE=..\..\..\..\C\BwtSort.h
# End Source File
# Begin Source File
-SOURCE=..\..\..\..\C\Compress\Branch\BranchIA64.h
+SOURCE=..\..\..\..\C\CpuArch.h
# End Source File
# Begin Source File
-SOURCE=..\..\..\..\C\Compress\Branch\BranchPPC.c
+SOURCE=..\..\..\..\C\HuffEnc.c
+
+!IF "$(CFG)" == "Alone - Win32 Release"
+
+# ADD CPP /O2
+# SUBTRACT CPP /YX /Yc /Yu
+
+!ELSEIF "$(CFG)" == "Alone - Win32 Debug"
+
+# SUBTRACT CPP /YX /Yc /Yu
+
+!ELSEIF "$(CFG)" == "Alone - Win32 ReleaseU"
+
+# SUBTRACT CPP /YX /Yc /Yu
+
+!ELSEIF "$(CFG)" == "Alone - Win32 DebugU"
+
# SUBTRACT CPP /YX /Yc /Yu
+
+!ENDIF
+
# End Source File
# Begin Source File
-SOURCE=..\..\..\..\C\Compress\Branch\BranchPPC.h
+SOURCE=..\..\..\..\C\HuffEnc.h
# End Source File
# Begin Source File
-SOURCE=..\..\..\..\C\Compress\Branch\BranchSPARC.c
-# SUBTRACT CPP /YX /Yc /Yu
+SOURCE=..\..\..\..\C\IStream.h
# End Source File
# Begin Source File
-SOURCE=..\..\..\..\C\Compress\Branch\BranchSPARC.h
+SOURCE=..\..\..\..\C\LzFind.c
+
+!IF "$(CFG)" == "Alone - Win32 Release"
+
+# ADD CPP /O2
+# SUBTRACT CPP /YX /Yc /Yu
+
+!ELSEIF "$(CFG)" == "Alone - Win32 Debug"
+
+# SUBTRACT CPP /YX /Yc /Yu
+
+!ELSEIF "$(CFG)" == "Alone - Win32 ReleaseU"
+
+# SUBTRACT CPP /YX /Yc /Yu
+
+!ELSEIF "$(CFG)" == "Alone - Win32 DebugU"
+
+# SUBTRACT CPP /YX /Yc /Yu
+
+!ENDIF
+
# End Source File
# Begin Source File
-SOURCE=..\..\..\..\C\Compress\Branch\BranchTypes.h
+SOURCE=..\..\..\..\C\LzFind.h
# End Source File
# Begin Source File
-SOURCE=..\..\..\..\C\Compress\Branch\BranchX86.c
+SOURCE=..\..\..\..\C\LzFindMt.c
+
+!IF "$(CFG)" == "Alone - Win32 Release"
+
+# ADD CPP /O2
+# SUBTRACT CPP /YX /Yc /Yu
+
+!ELSEIF "$(CFG)" == "Alone - Win32 Debug"
+
+# SUBTRACT CPP /YX /Yc /Yu
+
+!ELSEIF "$(CFG)" == "Alone - Win32 ReleaseU"
+
# SUBTRACT CPP /YX /Yc /Yu
+
+!ELSEIF "$(CFG)" == "Alone - Win32 DebugU"
+
+# SUBTRACT CPP /YX /Yc /Yu
+
+!ENDIF
+
# End Source File
# Begin Source File
-SOURCE=..\..\..\..\C\Compress\Branch\BranchX86.h
+SOURCE=..\..\..\..\C\LzFindMt.h
# End Source File
-# End Group
-# End Group
-# Begin Group "C-Crypto"
+# Begin Source File
-# PROP Default_Filter ""
+SOURCE=..\..\..\..\C\LzHash.h
+# End Source File
# Begin Source File
-SOURCE=..\..\..\..\C\Crypto\Aes.c
+SOURCE=..\..\..\..\C\LzmaDec.c
!IF "$(CFG)" == "Alone - Win32 Release"
@@ -2398,30 +2544,67 @@ SOURCE=..\..\..\..\C\Crypto\Aes.c
# End Source File
# Begin Source File
-SOURCE=..\..\..\..\C\Crypto\Aes.h
+SOURCE=..\..\..\..\C\LzmaDec.h
# End Source File
-# End Group
# Begin Source File
-SOURCE=..\..\..\..\C\7zCrc.c
+SOURCE=..\..\..\..\C\LzmaEnc.c
+
+!IF "$(CFG)" == "Alone - Win32 Release"
+
+# ADD CPP /O2
+# SUBTRACT CPP /YX /Yc /Yu
+
+!ELSEIF "$(CFG)" == "Alone - Win32 Debug"
+
+# SUBTRACT CPP /YX /Yc /Yu
+
+!ELSEIF "$(CFG)" == "Alone - Win32 ReleaseU"
+
+# SUBTRACT CPP /YX /Yc /Yu
+
+!ELSEIF "$(CFG)" == "Alone - Win32 DebugU"
+
# SUBTRACT CPP /YX /Yc /Yu
+
+!ENDIF
+
# End Source File
# Begin Source File
-SOURCE=..\..\..\..\C\7zCrc.h
+SOURCE=..\..\..\..\C\LzmaEnc.h
# End Source File
# Begin Source File
-SOURCE=..\..\..\..\C\Alloc.c
-# SUBTRACT CPP /YX /Yc /Yu
+SOURCE=..\..\..\..\C\RotateDefs.h
# End Source File
# Begin Source File
-SOURCE=..\..\..\..\C\Alloc.h
+SOURCE=..\..\..\..\C\Sha256.c
+
+!IF "$(CFG)" == "Alone - Win32 Release"
+
+# ADD CPP /O2
+# SUBTRACT CPP /YX /Yc /Yu
+
+!ELSEIF "$(CFG)" == "Alone - Win32 Debug"
+
+# SUBTRACT CPP /YX /Yc /Yu
+
+!ELSEIF "$(CFG)" == "Alone - Win32 ReleaseU"
+
+# SUBTRACT CPP /YX /Yc /Yu
+
+!ELSEIF "$(CFG)" == "Alone - Win32 DebugU"
+
+# SUBTRACT CPP /YX /Yc /Yu
+
+!ENDIF
+
# End Source File
# Begin Source File
-SOURCE=..\..\..\..\C\IStream.h
+SOURCE=..\..\..\..\C\Sha256.h
# End Source File
# Begin Source File
@@ -2454,7 +2637,26 @@ SOURCE=..\..\..\..\C\Sort.h
# Begin Source File
SOURCE=..\..\..\..\C\Threads.c
+
+!IF "$(CFG)" == "Alone - Win32 Release"
+
+# ADD CPP /O2
+# SUBTRACT CPP /YX /Yc /Yu
+
+!ELSEIF "$(CFG)" == "Alone - Win32 Debug"
+
# SUBTRACT CPP /YX /Yc /Yu
+
+!ELSEIF "$(CFG)" == "Alone - Win32 ReleaseU"
+
+# SUBTRACT CPP /YX /Yc /Yu
+
+!ELSEIF "$(CFG)" == "Alone - Win32 DebugU"
+
+# SUBTRACT CPP /YX /Yc /Yu
+
+!ENDIF
+
# End Source File
# Begin Source File
diff --git a/CPP/7zip/Bundles/Alone/makefile b/CPP/7zip/Bundles/Alone/makefile
index de5f7e3f..e3dc8e5e 100755
--- a/CPP/7zip/Bundles/Alone/makefile
+++ b/CPP/7zip/Bundles/Alone/makefile
@@ -1,6 +1,5 @@
PROG = 7za.exe
LIBS = $(LIBS) user32.lib oleaut32.lib Advapi32.lib
-
CFLAGS = $(CFLAGS) -I ../../../ \
-DWIN_LONG_PATH \
-DCOMPRESS_MT \
@@ -146,6 +145,12 @@ GZ_OBJS = \
$O\GZipUpdate.obj \
$O\GZipRegister.obj \
+LZM_OBJS = \
+ $O\LzmaArcRegister.obj \
+ $O\LzmaFiltersDecode.obj \
+ $O\LzmaHandler.obj \
+ $O\LzmaIn.obj \
+
SPLIT_OBJS = \
$O\SplitHandler.obj \
$O\SplitHandlerOut.obj \
@@ -177,14 +182,10 @@ ZIP_OBJS = \
BRANCH_OPT_OBJS = \
- $O\BranchCoder.obj \
$O\x86.obj \
$O\x86_2.obj \
- $O\ARM.obj \
- $O\ARMThumb.obj \
- $O\IA64.obj \
- $O\PPC.obj \
- $O\SPARC.obj \
+ $O\BranchCoder.obj \
+ $O\BranchMisc.obj \
$O\BranchRegister.obj \
$O\BCJRegister.obj \
$O\BCJ2Register.obj \
@@ -255,7 +256,6 @@ CRYPTO_HASH_OBJS = \
$O\Pbkdf2HmacSha1.obj \
$O\RandGen.obj \
$O\Sha1.obj \
- $O\Sha256.obj \
CRYPTO_WZAES_OBJS = \
$O\WzAES.obj \
@@ -266,23 +266,19 @@ CRYPTO_ZIP_OBJS = \
C_OBJS = \
$O\Alloc.obj \
+ $O\Bra.obj \
+ $O\Bra86.obj \
+ $O\BraIA64.obj \
+ $O\BwtSort.obj \
+ $O\HuffEnc.obj \
+ $O\LzFind.obj \
+ $O\LzFindMt.obj \
+ $O\LzmaDec.obj \
+ $O\LzmaEnc.obj \
$O\Sort.obj \
$O\Threads.obj \
-
-C_LZ_OBJS = \
- $O\MatchFinder.obj \
- $O\MatchFinderMt.obj \
-
-C_BRANCH_OBJS = \
- $O\BranchARM.obj \
- $O\BranchARMThumb.obj \
- $O\BranchIA64.obj \
- $O\BranchPPC.obj \
- $O\BranchSPARC.obj \
- $O\BranchX86.obj \
-
-C_CRYPTO = \
$O\Aes.obj \
+ $O\Sha256.obj \
!include "../../Crc2.mak"
@@ -299,6 +295,7 @@ OBJS = \
$(BZ2_OBJS) \
$(CAB_OBJS) \
$(GZ_OBJS) \
+ $(LZM_OBJS) \
$(SPLIT_OBJS) \
$(TAR_OBJS) \
$(Z_OBJS) \
@@ -318,10 +315,6 @@ OBJS = \
$(SHRINK_OBJS) \
$(COMPRESS_Z_OBJS) \
$(C_OBJS) \
- $(C_LZ_OBJS) \
- $(C_BRANCH_OBJS) \
- $O\BlockSort.obj \
- $O\HuffmanEncode.obj \
$O\RangeCoderBit.obj \
$(7ZAES_OPT_OBJS) \
$(AES_OPT_OBJS) \
@@ -329,7 +322,6 @@ OBJS = \
$(CRYPTO_ZIP_OBJS) \
$(CRYPTO_WZAES_OBJS) \
$O\QuantumDecoder.obj \
- $(C_CRYPTO) \
$(CRC_OBJS) \
$O\resource.res
@@ -358,6 +350,8 @@ $(CAB_OBJS): ../../Archive/Cab/$(*B).cpp
$(COMPL)
$(GZ_OBJS): ../../Archive/GZip/$(*B).cpp
$(COMPL)
+$(LZM_OBJS): ../../Archive/Lzma/$(*B).cpp
+ $(COMPL)
$(SPLIT_OBJS): ../../Archive/Split/$(*B).cpp
$(COMPL)
$(TAR_OBJS): ../../Archive/Tar/$(*B).cpp
@@ -397,8 +391,6 @@ $(SHRINK_OBJS): ../../Compress/Shrink/$(*B).cpp
$(COMPRESS_Z_OBJS): ../../Compress/Z/$(*B).cpp
$(COMPL)
-$O\BlockSort.obj: ../../Compress/BWT/$(*B).cpp
- $(COMPL_O2)
$O\RangeCoderBit.obj: ../../Compress/RangeCoder/$(*B).cpp
$(COMPL)
$O\QuantumDecoder.obj: ../../Compress/Quantum/$(*B).cpp
@@ -417,12 +409,4 @@ $(CRYPTO_WZAES_OBJS): ../../Crypto/WzAES/$(*B).cpp
$(C_OBJS): ../../../../C/$(*B).c
$(COMPL_O2)
-$(C_LZ_OBJS): ../../../../C/Compress/Lz/$(*B).c
- $(COMPL_O2)
-$(C_BRANCH_OBJS): ../../../../C/Compress/Branch/$(*B).c
- $(COMPL_O2)
-$O\HuffmanEncode.obj: ../../../../C/Compress/Huffman/$(*B).c
- $(COMPL_O2)
-$(C_CRYPTO): ../../../../C/Crypto/$(*B).c
- $(COMPL_O2)
-!include "../../Crc.mak" \ No newline at end of file
+!include "../../Crc.mak"
diff --git a/CPP/7zip/Bundles/Alone7z/Alone.dsp b/CPP/7zip/Bundles/Alone7z/Alone.dsp
deleted file mode 100755
index b9f389bb..00000000
--- a/CPP/7zip/Bundles/Alone7z/Alone.dsp
+++ /dev/null
@@ -1,1453 +0,0 @@
-# Microsoft Developer Studio Project File - Name="Alone" - Package Owner=<4>
-# Microsoft Developer Studio Generated Build File, Format Version 6.00
-# ** DO NOT EDIT **
-
-# TARGTYPE "Win32 (x86) Console Application" 0x0103
-
-CFG=Alone - Win32 DebugU
-!MESSAGE This is not a valid makefile. To build this project using NMAKE,
-!MESSAGE use the Export Makefile command and run
-!MESSAGE
-!MESSAGE NMAKE /f "Alone.mak".
-!MESSAGE
-!MESSAGE You can specify a configuration when running NMAKE
-!MESSAGE by defining the macro CFG on the command line. For example:
-!MESSAGE
-!MESSAGE NMAKE /f "Alone.mak" CFG="Alone - Win32 DebugU"
-!MESSAGE
-!MESSAGE Possible choices for configuration are:
-!MESSAGE
-!MESSAGE "Alone - Win32 Release" (based on "Win32 (x86) Console Application")
-!MESSAGE "Alone - Win32 Debug" (based on "Win32 (x86) Console Application")
-!MESSAGE "Alone - Win32 ReleaseU" (based on "Win32 (x86) Console Application")
-!MESSAGE "Alone - Win32 DebugU" (based on "Win32 (x86) Console Application")
-!MESSAGE
-
-# Begin Project
-# PROP AllowPerConfigDependencies 0
-# PROP Scc_ProjName ""
-# PROP Scc_LocalPath ""
-CPP=cl.exe
-RSC=rc.exe
-
-!IF "$(CFG)" == "Alone - Win32 Release"
-
-# PROP BASE Use_MFC 0
-# PROP BASE Use_Debug_Libraries 0
-# PROP BASE Output_Dir "Release"
-# PROP BASE Intermediate_Dir "Release"
-# PROP BASE Target_Dir ""
-# PROP Use_MFC 0
-# PROP Use_Debug_Libraries 0
-# PROP Output_Dir "Release"
-# PROP Intermediate_Dir "Release"
-# PROP Ignore_Export_Lib 0
-# PROP Target_Dir ""
-# ADD BASE CPP /nologo /W3 /GX /O2 /D "WIN32" /D "NDEBUG" /D "_CONSOLE" /D "_MBCS" /YX /FD /c
-# ADD CPP /nologo /Gz /MT /W3 /GX /O1 /I "..\..\..\\" /D "NDEBUG" /D "_MBCS" /D "WIN32" /D "_CONSOLE" /D "COMPRESS_MF_MT" /D "COMPRESS_MT" /D "_NO_CRYPTO" /D "BREAK_HANDLER" /D "BENCH_MT" /Yu"StdAfx.h" /FD /c
-# ADD BASE RSC /l 0x419 /d "NDEBUG"
-# ADD RSC /l 0x419 /d "NDEBUG"
-BSC32=bscmake.exe
-# ADD BASE BSC32 /nologo
-# ADD BSC32 /nologo
-LINK32=link.exe
-# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /machine:I386
-# ADD LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /machine:I386 /out:"c:\UTIL\7zr.exe" /opt:NOWIN98
-# SUBTRACT LINK32 /pdb:none
-
-!ELSEIF "$(CFG)" == "Alone - Win32 Debug"
-
-# PROP BASE Use_MFC 0
-# PROP BASE Use_Debug_Libraries 1
-# PROP BASE Output_Dir "Debug"
-# PROP BASE Intermediate_Dir "Debug"
-# PROP BASE Target_Dir ""
-# PROP Use_MFC 0
-# PROP Use_Debug_Libraries 1
-# PROP Output_Dir "Debug"
-# PROP Intermediate_Dir "Debug"
-# PROP Ignore_Export_Lib 0
-# PROP Target_Dir ""
-# ADD BASE CPP /nologo /W3 /Gm /GX /ZI /Od /D "WIN32" /D "_DEBUG" /D "_CONSOLE" /D "_MBCS" /YX /FD /GZ /c
-# ADD CPP /nologo /Gz /MDd /W3 /Gm /GX /ZI /Od /I "..\..\..\\" /D "_DEBUG" /D "_MBCS" /D "WIN32" /D "_CONSOLE" /D "COMPRESS_MF_MT" /D "COMPRESS_MT" /D "_NO_CRYPTO" /D "BREAK_HANDLER" /D "BENCH_MT" /Yu"StdAfx.h" /FD /GZ /c
-# ADD BASE RSC /l 0x419 /d "_DEBUG"
-# ADD RSC /l 0x419 /d "_DEBUG"
-BSC32=bscmake.exe
-# ADD BASE BSC32 /nologo
-# ADD BSC32 /nologo
-LINK32=link.exe
-# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /debug /machine:I386 /pdbtype:sept
-# ADD LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /debug /machine:I386 /out:"c:\UTIL\7zr.exe" /pdbtype:sept
-
-!ELSEIF "$(CFG)" == "Alone - Win32 ReleaseU"
-
-# PROP BASE Use_MFC 0
-# PROP BASE Use_Debug_Libraries 0
-# PROP BASE Output_Dir "ReleaseU"
-# PROP BASE Intermediate_Dir "ReleaseU"
-# PROP BASE Ignore_Export_Lib 0
-# PROP BASE Target_Dir ""
-# PROP Use_MFC 0
-# PROP Use_Debug_Libraries 0
-# PROP Output_Dir "ReleaseU"
-# PROP Intermediate_Dir "ReleaseU"
-# PROP Ignore_Export_Lib 0
-# PROP Target_Dir ""
-# ADD BASE CPP /nologo /MD /W3 /GX /O2 /D "NDEBUG" /D "WIN32" /D "_CONSOLE" /D "EXCLUDE_COM" /D "NO_REGISTRY" /D "FORMAT_7Z" /D "FORMAT_BZIP2" /D "FORMAT_ZIP" /D "FORMAT_TAR" /D "FORMAT_GZIP" /D "COMPRESS_LZMA" /D "COMPRESS_BCJ_X86" /D "COMPRESS_BCJ2" /D "COMPRESS_COPY" /D "COMPRESS_MF_PAT" /D "COMPRESS_MF_BT" /D "COMPRESS_PPMD" /D "COMPRESS_DEFLATE" /D "COMPRESS_IMPLODE" /D "COMPRESS_BZIP2" /D "CRYPTO_ZIP" /Yu"StdAfx.h" /FD /c
-# ADD CPP /nologo /Gz /MD /W3 /GX /O1 /I "..\..\..\\" /D "NDEBUG" /D "UNICODE" /D "_UNICODE" /D "WIN32" /D "_CONSOLE" /D "COMPRESS_MF_MT" /D "COMPRESS_MT" /D "_NO_CRYPTO" /D "BREAK_HANDLER" /D "BENCH_MT" /Yu"StdAfx.h" /FD /c
-# ADD BASE RSC /l 0x419 /d "NDEBUG"
-# ADD RSC /l 0x419 /d "NDEBUG"
-BSC32=bscmake.exe
-# ADD BASE BSC32 /nologo
-# ADD BSC32 /nologo
-LINK32=link.exe
-# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /machine:I386 /out:"c:\UTIL\7za.exe" /opt:NOWIN98
-# SUBTRACT BASE LINK32 /pdb:none
-# ADD LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /machine:I386 /out:"c:\UTIL\7zr.exe" /opt:NOWIN98
-# SUBTRACT LINK32 /pdb:none
-
-!ELSEIF "$(CFG)" == "Alone - Win32 DebugU"
-
-# PROP BASE Use_MFC 0
-# PROP BASE Use_Debug_Libraries 1
-# PROP BASE Output_Dir "DebugU"
-# PROP BASE Intermediate_Dir "DebugU"
-# PROP BASE Ignore_Export_Lib 0
-# PROP BASE Target_Dir ""
-# PROP Use_MFC 0
-# PROP Use_Debug_Libraries 1
-# PROP Output_Dir "DebugU"
-# PROP Intermediate_Dir "DebugU"
-# PROP Ignore_Export_Lib 0
-# PROP Target_Dir ""
-# ADD BASE CPP /nologo /W3 /Gm /GX /ZI /Od /D "_DEBUG" /D "WIN32" /D "_CONSOLE" /D "EXCLUDE_COM" /D "NO_REGISTRY" /D "FORMAT_7Z" /D "FORMAT_BZIP2" /D "FORMAT_ZIP" /D "FORMAT_TAR" /D "FORMAT_GZIP" /D "COMPRESS_LZMA" /D "COMPRESS_BCJ_X86" /D "COMPRESS_BCJ2" /D "COMPRESS_COPY" /D "COMPRESS_MF_PAT" /D "COMPRESS_MF_BT" /D "COMPRESS_PPMD" /D "COMPRESS_DEFLATE" /D "COMPRESS_IMPLODE" /D "COMPRESS_BZIP2" /D "CRYPTO_ZIP" /D "_MBCS" /Yu"StdAfx.h" /FD /GZ /c
-# ADD CPP /nologo /Gz /W4 /Gm /GX /ZI /Od /I "..\..\..\\" /D "_DEBUG" /D "_UNICODE" /D "UNICODE" /D "WIN32" /D "_CONSOLE" /D "COMPRESS_MF_MT" /D "COMPRESS_MT" /D "_NO_CRYPTO" /D "BREAK_HANDLER" /D "BENCH_MT" /Yu"StdAfx.h" /FD /GZ /c
-# ADD BASE RSC /l 0x419 /d "_DEBUG"
-# ADD RSC /l 0x419 /d "_DEBUG"
-BSC32=bscmake.exe
-# ADD BASE BSC32 /nologo
-# ADD BSC32 /nologo
-LINK32=link.exe
-# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /debug /machine:I386 /out:"c:\UTIL\7za.exe" /pdbtype:sept
-# ADD LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /debug /machine:I386 /out:"c:\UTIL\7zr.exe" /pdbtype:sept
-
-!ENDIF
-
-# Begin Target
-
-# Name "Alone - Win32 Release"
-# Name "Alone - Win32 Debug"
-# Name "Alone - Win32 ReleaseU"
-# Name "Alone - Win32 DebugU"
-# Begin Group "Console"
-
-# PROP Default_Filter ""
-# Begin Source File
-
-SOURCE=..\..\UI\Console\ArError.h
-# End Source File
-# Begin Source File
-
-SOURCE=..\..\UI\Console\CompressionMode.h
-# End Source File
-# Begin Source File
-
-SOURCE=..\..\UI\Console\ConsoleClose.cpp
-# End Source File
-# Begin Source File
-
-SOURCE=..\..\UI\Console\ConsoleClose.h
-# End Source File
-# Begin Source File
-
-SOURCE=..\..\UI\Console\ExtractCallbackConsole.cpp
-# End Source File
-# Begin Source File
-
-SOURCE=..\..\UI\Console\ExtractCallbackConsole.h
-# End Source File
-# Begin Source File
-
-SOURCE=..\..\UI\Console\List.cpp
-# End Source File
-# Begin Source File
-
-SOURCE=..\..\UI\Console\List.h
-# End Source File
-# Begin Source File
-
-SOURCE=..\..\UI\Console\Main.cpp
-# End Source File
-# Begin Source File
-
-SOURCE=..\..\UI\Console\MainAr.cpp
-# End Source File
-# Begin Source File
-
-SOURCE=..\..\UI\Console\OpenCallbackConsole.cpp
-# End Source File
-# Begin Source File
-
-SOURCE=..\..\UI\Console\OpenCallbackConsole.h
-# End Source File
-# Begin Source File
-
-SOURCE=..\..\UI\Console\PercentPrinter.cpp
-# End Source File
-# Begin Source File
-
-SOURCE=..\..\UI\Console\PercentPrinter.h
-# End Source File
-# Begin Source File
-
-SOURCE=..\..\UI\Console\UpdateCallbackConsole.cpp
-# End Source File
-# Begin Source File
-
-SOURCE=..\..\UI\Console\UpdateCallbackConsole.h
-# End Source File
-# Begin Source File
-
-SOURCE=..\..\UI\Console\UserInputUtils.cpp
-# End Source File
-# Begin Source File
-
-SOURCE=..\..\UI\Console\UserInputUtils.h
-# End Source File
-# End Group
-# Begin Group "Spec"
-
-# PROP Default_Filter ""
-# Begin Source File
-
-SOURCE=.\resource.rc
-# End Source File
-# Begin Source File
-
-SOURCE=.\StdAfx.cpp
-# ADD CPP /Yc"StdAfx.h"
-# End Source File
-# Begin Source File
-
-SOURCE=.\StdAfx.h
-# End Source File
-# End Group
-# Begin Group "Common"
-
-# PROP Default_Filter ""
-# Begin Source File
-
-SOURCE=..\..\..\Common\AutoPtr.h
-# End Source File
-# Begin Source File
-
-SOURCE=..\..\..\Common\Buffer.h
-# End Source File
-# Begin Source File
-
-SOURCE=..\..\..\Common\CommandLineParser.cpp
-# End Source File
-# Begin Source File
-
-SOURCE=..\..\..\Common\CommandLineParser.h
-# End Source File
-# Begin Source File
-
-SOURCE=..\..\..\Common\ComTry.h
-# End Source File
-# Begin Source File
-
-SOURCE=..\..\..\Common\CRC.cpp
-# End Source File
-# Begin Source File
-
-SOURCE=..\..\..\Common\Defs.h
-# End Source File
-# Begin Source File
-
-SOURCE=..\..\..\Common\DynamicBuffer.h
-# End Source File
-# Begin Source File
-
-SOURCE=..\..\..\Common\IntToString.cpp
-# End Source File
-# Begin Source File
-
-SOURCE=..\..\..\Common\IntToString.h
-# End Source File
-# Begin Source File
-
-SOURCE=..\..\..\Common\ListFileUtils.cpp
-# End Source File
-# Begin Source File
-
-SOURCE=..\..\..\Common\ListFileUtils.h
-# End Source File
-# Begin Source File
-
-SOURCE=..\..\..\Common\MyCom.h
-# End Source File
-# Begin Source File
-
-SOURCE=..\..\..\Common\MyException.h
-# End Source File
-# Begin Source File
-
-SOURCE=..\..\..\Common\MyGuidDef.h
-# End Source File
-# Begin Source File
-
-SOURCE=..\..\..\Common\MyInitGuid.h
-# End Source File
-# Begin Source File
-
-SOURCE=..\..\..\Common\MyString.cpp
-# End Source File
-# Begin Source File
-
-SOURCE=..\..\..\Common\MyString.h
-# End Source File
-# Begin Source File
-
-SOURCE=..\..\..\Common\MyUnknown.h
-# End Source File
-# Begin Source File
-
-SOURCE=..\..\..\Common\MyVector.cpp
-# End Source File
-# Begin Source File
-
-SOURCE=..\..\..\Common\MyVector.h
-# End Source File
-# Begin Source File
-
-SOURCE=..\..\..\Common\MyWindows.cpp
-# End Source File
-# Begin Source File
-
-SOURCE=..\..\..\Common\MyWindows.h
-# End Source File
-# Begin Source File
-
-SOURCE=..\..\..\Common\NewHandler.cpp
-# End Source File
-# Begin Source File
-
-SOURCE=..\..\..\Common\NewHandler.h
-# End Source File
-# Begin Source File
-
-SOURCE=..\..\..\Common\Random.cpp
-# End Source File
-# Begin Source File
-
-SOURCE=..\..\..\Common\Random.h
-# End Source File
-# Begin Source File
-
-SOURCE=..\..\..\Common\StdInStream.cpp
-# End Source File
-# Begin Source File
-
-SOURCE=..\..\..\Common\StdInStream.h
-# End Source File
-# Begin Source File
-
-SOURCE=..\..\..\Common\StdOutStream.cpp
-# End Source File
-# Begin Source File
-
-SOURCE=..\..\..\Common\StdOutStream.h
-# End Source File
-# Begin Source File
-
-SOURCE=..\..\..\Common\StringConvert.cpp
-# End Source File
-# Begin Source File
-
-SOURCE=..\..\..\Common\StringConvert.h
-# End Source File
-# Begin Source File
-
-SOURCE=..\..\..\Common\StringToInt.cpp
-# End Source File
-# Begin Source File
-
-SOURCE=..\..\..\Common\StringToInt.h
-# End Source File
-# Begin Source File
-
-SOURCE=..\..\..\Common\Types.h
-# End Source File
-# Begin Source File
-
-SOURCE=..\..\..\Common\UTFConvert.cpp
-# End Source File
-# Begin Source File
-
-SOURCE=..\..\..\Common\UTFConvert.h
-# End Source File
-# Begin Source File
-
-SOURCE=..\..\..\Common\Wildcard.cpp
-# End Source File
-# Begin Source File
-
-SOURCE=..\..\..\Common\Wildcard.h
-# End Source File
-# End Group
-# Begin Group "Windows"
-
-# PROP Default_Filter ""
-# Begin Source File
-
-SOURCE=..\..\..\Windows\Defs.h
-# End Source File
-# Begin Source File
-
-SOURCE=..\..\..\Windows\Device.h
-# End Source File
-# Begin Source File
-
-SOURCE=..\..\..\Windows\DLL.cpp
-# End Source File
-# Begin Source File
-
-SOURCE=..\..\..\Windows\DLL.h
-# End Source File
-# Begin Source File
-
-SOURCE=..\..\..\Windows\Error.cpp
-# End Source File
-# Begin Source File
-
-SOURCE=..\..\..\Windows\Error.h
-# End Source File
-# Begin Source File
-
-SOURCE=..\..\..\Windows\FileDir.cpp
-# End Source File
-# Begin Source File
-
-SOURCE=..\..\..\Windows\FileDir.h
-# End Source File
-# Begin Source File
-
-SOURCE=..\..\..\Windows\FileFind.cpp
-# End Source File
-# Begin Source File
-
-SOURCE=..\..\..\Windows\FileFind.h
-# End Source File
-# Begin Source File
-
-SOURCE=..\..\..\Windows\FileIO.cpp
-# End Source File
-# Begin Source File
-
-SOURCE=..\..\..\Windows\FileIO.h
-# End Source File
-# Begin Source File
-
-SOURCE=..\..\..\Windows\FileName.cpp
-# End Source File
-# Begin Source File
-
-SOURCE=..\..\..\Windows\FileName.h
-# End Source File
-# Begin Source File
-
-SOURCE=..\..\..\Windows\Handle.h
-# End Source File
-# Begin Source File
-
-SOURCE=..\..\..\Windows\MemoryLock.cpp
-# End Source File
-# Begin Source File
-
-SOURCE=..\..\..\Windows\MemoryLock.h
-# End Source File
-# Begin Source File
-
-SOURCE=..\..\..\Windows\PropVariant.cpp
-# End Source File
-# Begin Source File
-
-SOURCE=..\..\..\Windows\PropVariant.h
-# End Source File
-# Begin Source File
-
-SOURCE=..\..\..\Windows\PropVariantConversions.cpp
-# End Source File
-# Begin Source File
-
-SOURCE=..\..\..\Windows\PropVariantConversions.h
-# End Source File
-# Begin Source File
-
-SOURCE=..\..\..\Windows\Synchronization.cpp
-# End Source File
-# Begin Source File
-
-SOURCE=..\..\..\Windows\Synchronization.h
-# End Source File
-# Begin Source File
-
-SOURCE=..\..\..\Windows\System.cpp
-# End Source File
-# Begin Source File
-
-SOURCE=..\..\..\Windows\System.h
-# End Source File
-# Begin Source File
-
-SOURCE=..\..\..\Windows\Thread.h
-# End Source File
-# Begin Source File
-
-SOURCE=..\..\..\Windows\Time.h
-# End Source File
-# End Group
-# Begin Group "7zip Common"
-
-# PROP Default_Filter ""
-# Begin Source File
-
-SOURCE=..\..\Common\CreateCoder.cpp
-# End Source File
-# Begin Source File
-
-SOURCE=..\..\Common\CreateCoder.h
-# End Source File
-# Begin Source File
-
-SOURCE=..\..\Archive\Common\CrossThreadProgress.cpp
-# End Source File
-# Begin Source File
-
-SOURCE=..\..\Archive\Common\CrossThreadProgress.h
-# End Source File
-# Begin Source File
-
-SOURCE=..\..\Common\FilePathAutoRename.cpp
-# End Source File
-# Begin Source File
-
-SOURCE=..\..\Common\FilePathAutoRename.h
-# End Source File
-# Begin Source File
-
-SOURCE=..\..\Common\FileStreams.cpp
-# End Source File
-# Begin Source File
-
-SOURCE=..\..\Common\FileStreams.h
-# End Source File
-# Begin Source File
-
-SOURCE=..\..\Common\FilterCoder.cpp
-# End Source File
-# Begin Source File
-
-SOURCE=..\..\Common\FilterCoder.h
-# End Source File
-# Begin Source File
-
-SOURCE=..\..\Common\InBuffer.cpp
-# End Source File
-# Begin Source File
-
-SOURCE=..\..\Common\InBuffer.h
-# End Source File
-# Begin Source File
-
-SOURCE=..\..\Common\InOutTempBuffer.cpp
-# End Source File
-# Begin Source File
-
-SOURCE=..\..\Common\InOutTempBuffer.h
-# End Source File
-# Begin Source File
-
-SOURCE=..\..\Common\LimitedStreams.cpp
-# End Source File
-# Begin Source File
-
-SOURCE=..\..\Common\LimitedStreams.h
-# End Source File
-# Begin Source File
-
-SOURCE=..\..\Common\LockedStream.cpp
-# End Source File
-# Begin Source File
-
-SOURCE=..\..\Common\LockedStream.h
-# End Source File
-# Begin Source File
-
-SOURCE=..\..\Common\LSBFDecoder.cpp
-# End Source File
-# Begin Source File
-
-SOURCE=..\..\Common\LSBFDecoder.h
-# End Source File
-# Begin Source File
-
-SOURCE=..\..\Common\LSBFEncoder.cpp
-# End Source File
-# Begin Source File
-
-SOURCE=..\..\Common\LSBFEncoder.h
-# End Source File
-# Begin Source File
-
-SOURCE=..\..\Common\MethodId.cpp
-# End Source File
-# Begin Source File
-
-SOURCE=..\..\Common\MethodId.h
-# End Source File
-# Begin Source File
-
-SOURCE=..\..\Common\MethodProps.cpp
-# End Source File
-# Begin Source File
-
-SOURCE=..\..\Common\MethodProps.h
-# End Source File
-# Begin Source File
-
-SOURCE=..\..\Common\MSBFDecoder.h
-# End Source File
-# Begin Source File
-
-SOURCE=..\..\Common\MSBFEncoder.h
-# End Source File
-# Begin Source File
-
-SOURCE=..\..\Common\OffsetStream.cpp
-# End Source File
-# Begin Source File
-
-SOURCE=..\..\Common\OffsetStream.h
-# End Source File
-# Begin Source File
-
-SOURCE=..\..\Common\OutBuffer.cpp
-# End Source File
-# Begin Source File
-
-SOURCE=..\..\Common\OutBuffer.h
-# End Source File
-# Begin Source File
-
-SOURCE=..\..\Common\ProgressMt.cpp
-# End Source File
-# Begin Source File
-
-SOURCE=..\..\Common\ProgressMt.h
-# End Source File
-# Begin Source File
-
-SOURCE=..\..\Common\ProgressUtils.cpp
-# End Source File
-# Begin Source File
-
-SOURCE=..\..\Common\ProgressUtils.h
-# End Source File
-# Begin Source File
-
-SOURCE=..\..\Common\RegisterArc.h
-# End Source File
-# Begin Source File
-
-SOURCE=..\..\Common\RegisterCodec.h
-# End Source File
-# Begin Source File
-
-SOURCE=..\..\Common\StreamBinder.cpp
-# End Source File
-# Begin Source File
-
-SOURCE=..\..\Common\StreamBinder.h
-# End Source File
-# Begin Source File
-
-SOURCE=..\..\Common\StreamObjects.cpp
-# End Source File
-# Begin Source File
-
-SOURCE=..\..\Common\StreamObjects.h
-# End Source File
-# Begin Source File
-
-SOURCE=..\..\Common\StreamUtils.cpp
-# End Source File
-# Begin Source File
-
-SOURCE=..\..\Common\StreamUtils.h
-# End Source File
-# Begin Source File
-
-SOURCE=..\..\Common\VirtThread.cpp
-# End Source File
-# Begin Source File
-
-SOURCE=..\..\Common\VirtThread.h
-# End Source File
-# End Group
-# Begin Group "Compress"
-
-# PROP Default_Filter ""
-# Begin Group "Branch"
-
-# PROP Default_Filter ""
-# Begin Source File
-
-SOURCE=..\..\Compress\Branch\BranchCoder.cpp
-# End Source File
-# Begin Source File
-
-SOURCE=..\..\Compress\Branch\BranchCoder.h
-# End Source File
-# Begin Source File
-
-SOURCE=..\..\Compress\Branch\Coder.h
-# End Source File
-# Begin Source File
-
-SOURCE=..\..\Compress\Branch\x86.cpp
-
-!IF "$(CFG)" == "Alone - Win32 Release"
-
-# ADD CPP /O2
-# SUBTRACT CPP /YX /Yc /Yu
-
-!ELSEIF "$(CFG)" == "Alone - Win32 Debug"
-
-!ELSEIF "$(CFG)" == "Alone - Win32 ReleaseU"
-
-# ADD CPP /O2
-# SUBTRACT CPP /YX /Yc /Yu
-
-!ELSEIF "$(CFG)" == "Alone - Win32 DebugU"
-
-!ENDIF
-
-# End Source File
-# Begin Source File
-
-SOURCE=..\..\Compress\Branch\x86.h
-# End Source File
-# Begin Source File
-
-SOURCE=..\..\Compress\Branch\x86_2.cpp
-
-!IF "$(CFG)" == "Alone - Win32 Release"
-
-# ADD CPP /O2
-# SUBTRACT CPP /YX /Yc /Yu
-
-!ELSEIF "$(CFG)" == "Alone - Win32 Debug"
-
-!ELSEIF "$(CFG)" == "Alone - Win32 ReleaseU"
-
-# ADD CPP /O2
-# SUBTRACT CPP /YX /Yc /Yu
-
-!ELSEIF "$(CFG)" == "Alone - Win32 DebugU"
-
-!ENDIF
-
-# End Source File
-# Begin Source File
-
-SOURCE=..\..\Compress\Branch\x86_2.h
-# End Source File
-# End Group
-# Begin Group "Copy"
-
-# PROP Default_Filter ""
-# Begin Source File
-
-SOURCE=..\..\Compress\Copy\CopyCoder.cpp
-# End Source File
-# Begin Source File
-
-SOURCE=..\..\Compress\Copy\CopyCoder.h
-# End Source File
-# Begin Source File
-
-SOURCE=..\..\Compress\Copy\CopyRegister.cpp
-# End Source File
-# End Group
-# Begin Group "LZ"
-
-# PROP Default_Filter ""
-# Begin Source File
-
-SOURCE=..\..\Compress\LZ\LZOutWindow.cpp
-
-!IF "$(CFG)" == "Alone - Win32 Release"
-
-# ADD CPP /O1
-
-!ELSEIF "$(CFG)" == "Alone - Win32 Debug"
-
-!ELSEIF "$(CFG)" == "Alone - Win32 ReleaseU"
-
-# ADD CPP /O1
-
-!ELSEIF "$(CFG)" == "Alone - Win32 DebugU"
-
-!ENDIF
-
-# End Source File
-# Begin Source File
-
-SOURCE=..\..\Compress\LZ\LZOutWindow.h
-# End Source File
-# End Group
-# Begin Group "LZMA"
-
-# PROP Default_Filter ""
-# Begin Source File
-
-SOURCE=..\..\Compress\LZMA\LZMA.h
-# End Source File
-# Begin Source File
-
-SOURCE=..\..\Compress\LZMA\LZMADecoder.cpp
-
-!IF "$(CFG)" == "Alone - Win32 Release"
-
-# ADD CPP /O2
-# SUBTRACT CPP /YX /Yc /Yu
-
-!ELSEIF "$(CFG)" == "Alone - Win32 Debug"
-
-!ELSEIF "$(CFG)" == "Alone - Win32 ReleaseU"
-
-# ADD CPP /O2
-# SUBTRACT CPP /YX /Yc /Yu
-
-!ELSEIF "$(CFG)" == "Alone - Win32 DebugU"
-
-!ENDIF
-
-# End Source File
-# Begin Source File
-
-SOURCE=..\..\Compress\LZMA\LZMADecoder.h
-# End Source File
-# Begin Source File
-
-SOURCE=..\..\Compress\LZMA\LZMAEncoder.cpp
-
-!IF "$(CFG)" == "Alone - Win32 Release"
-
-# ADD CPP /O2
-# SUBTRACT CPP /YX /Yc /Yu
-
-!ELSEIF "$(CFG)" == "Alone - Win32 Debug"
-
-!ELSEIF "$(CFG)" == "Alone - Win32 ReleaseU"
-
-# ADD CPP /O2
-# SUBTRACT CPP /YX /Yc /Yu
-
-!ELSEIF "$(CFG)" == "Alone - Win32 DebugU"
-
-!ENDIF
-
-# End Source File
-# Begin Source File
-
-SOURCE=..\..\Compress\LZMA\LZMAEncoder.h
-# End Source File
-# Begin Source File
-
-SOURCE=..\..\Compress\LZMA\LZMARegister.cpp
-# End Source File
-# End Group
-# Begin Group "RangeCoder"
-
-# PROP Default_Filter ""
-# Begin Source File
-
-SOURCE=..\..\Compress\RangeCoder\RangeCoder.h
-# End Source File
-# Begin Source File
-
-SOURCE=..\..\Compress\RangeCoder\RangeCoderBit.cpp
-
-!IF "$(CFG)" == "Alone - Win32 Release"
-
-# ADD CPP /O1
-
-!ELSEIF "$(CFG)" == "Alone - Win32 Debug"
-
-!ELSEIF "$(CFG)" == "Alone - Win32 ReleaseU"
-
-# ADD CPP /O1
-
-!ELSEIF "$(CFG)" == "Alone - Win32 DebugU"
-
-!ENDIF
-
-# End Source File
-# Begin Source File
-
-SOURCE=..\..\Compress\RangeCoder\RangeCoderBit.h
-# End Source File
-# Begin Source File
-
-SOURCE=..\..\Compress\RangeCoder\RangeCoderBitTree.h
-# End Source File
-# Begin Source File
-
-SOURCE=..\..\Compress\RangeCoder\RangeCoderOpt.h
-# End Source File
-# End Group
-# Begin Group "LZMA_Alone"
-
-# PROP Default_Filter ""
-# Begin Source File
-
-SOURCE=..\..\Compress\LZMA_Alone\LzmaBench.cpp
-# End Source File
-# Begin Source File
-
-SOURCE=..\..\Compress\LZMA_Alone\LzmaBench.h
-# End Source File
-# Begin Source File
-
-SOURCE=..\..\Compress\LZMA_Alone\LzmaBenchCon.cpp
-# End Source File
-# Begin Source File
-
-SOURCE=..\..\Compress\LZMA_Alone\LzmaBenchCon.h
-# End Source File
-# End Group
-# End Group
-# Begin Group "Archive"
-
-# PROP Default_Filter ""
-# Begin Group "7z"
-
-# PROP Default_Filter ""
-# Begin Source File
-
-SOURCE=..\..\Archive\7z\7zCompressionMode.cpp
-# End Source File
-# Begin Source File
-
-SOURCE=..\..\Archive\7z\7zCompressionMode.h
-# End Source File
-# Begin Source File
-
-SOURCE=..\..\Archive\7z\7zDecode.cpp
-# End Source File
-# Begin Source File
-
-SOURCE=..\..\Archive\7z\7zDecode.h
-# End Source File
-# Begin Source File
-
-SOURCE=..\..\Archive\7z\7zEncode.cpp
-# End Source File
-# Begin Source File
-
-SOURCE=..\..\Archive\7z\7zEncode.h
-# End Source File
-# Begin Source File
-
-SOURCE=..\..\Archive\7z\7zExtract.cpp
-# End Source File
-# Begin Source File
-
-SOURCE=..\..\Archive\7z\7zFolderInStream.cpp
-# End Source File
-# Begin Source File
-
-SOURCE=..\..\Archive\7z\7zFolderInStream.h
-# End Source File
-# Begin Source File
-
-SOURCE=..\..\Archive\7z\7zFolderOutStream.cpp
-# End Source File
-# Begin Source File
-
-SOURCE=..\..\Archive\7z\7zFolderOutStream.h
-# End Source File
-# Begin Source File
-
-SOURCE=..\..\Archive\7z\7zHandler.cpp
-# End Source File
-# Begin Source File
-
-SOURCE=..\..\Archive\7z\7zHandler.h
-# End Source File
-# Begin Source File
-
-SOURCE=..\..\Archive\7z\7zHandlerOut.cpp
-# End Source File
-# Begin Source File
-
-SOURCE=..\..\Archive\7z\7zHeader.cpp
-# End Source File
-# Begin Source File
-
-SOURCE=..\..\Archive\7z\7zHeader.h
-# End Source File
-# Begin Source File
-
-SOURCE=..\..\Archive\7z\7zIn.cpp
-# End Source File
-# Begin Source File
-
-SOURCE=..\..\Archive\7z\7zIn.h
-# End Source File
-# Begin Source File
-
-SOURCE=..\..\Archive\7z\7zItem.h
-# End Source File
-# Begin Source File
-
-SOURCE=..\..\Archive\7z\7zOut.cpp
-# End Source File
-# Begin Source File
-
-SOURCE=..\..\Archive\7z\7zOut.h
-# End Source File
-# Begin Source File
-
-SOURCE=..\..\Archive\7z\7zProperties.cpp
-# End Source File
-# Begin Source File
-
-SOURCE=..\..\Archive\7z\7zProperties.h
-# End Source File
-# Begin Source File
-
-SOURCE=..\..\Archive\7z\7zRegister.cpp
-# End Source File
-# Begin Source File
-
-SOURCE=..\..\Archive\7z\7zSpecStream.cpp
-# End Source File
-# Begin Source File
-
-SOURCE=..\..\Archive\7z\7zSpecStream.h
-# End Source File
-# Begin Source File
-
-SOURCE=..\..\Archive\7z\7zUpdate.cpp
-# End Source File
-# Begin Source File
-
-SOURCE=..\..\Archive\7z\7zUpdate.h
-# End Source File
-# End Group
-# Begin Group "Archive Common"
-
-# PROP Default_Filter ""
-# Begin Source File
-
-SOURCE=..\..\Archive\Common\CoderMixer2.cpp
-# End Source File
-# Begin Source File
-
-SOURCE=..\..\Archive\Common\CoderMixer2.h
-# End Source File
-# Begin Source File
-
-SOURCE=..\..\Archive\Common\CoderMixer2MT.cpp
-# End Source File
-# Begin Source File
-
-SOURCE=..\..\Archive\Common\CoderMixer2MT.h
-# End Source File
-# Begin Source File
-
-SOURCE=..\..\Archive\Common\DummyOutStream.cpp
-# End Source File
-# Begin Source File
-
-SOURCE=..\..\Archive\Common\DummyOutStream.h
-# End Source File
-# Begin Source File
-
-SOURCE=..\..\Archive\Common\HandlerOut.cpp
-# End Source File
-# Begin Source File
-
-SOURCE=..\..\Archive\Common\HandlerOut.h
-# End Source File
-# Begin Source File
-
-SOURCE=..\..\Archive\Common\InStreamWithCRC.cpp
-# End Source File
-# Begin Source File
-
-SOURCE=..\..\Archive\Common\InStreamWithCRC.h
-# End Source File
-# Begin Source File
-
-SOURCE=..\..\Archive\Common\ItemNameUtils.cpp
-# End Source File
-# Begin Source File
-
-SOURCE=..\..\Archive\Common\ItemNameUtils.h
-# End Source File
-# Begin Source File
-
-SOURCE=..\..\Archive\Common\MultiStream.cpp
-# End Source File
-# Begin Source File
-
-SOURCE=..\..\Archive\Common\MultiStream.h
-# End Source File
-# Begin Source File
-
-SOURCE=..\..\Archive\Common\OutStreamWithCRC.cpp
-# End Source File
-# Begin Source File
-
-SOURCE=..\..\Archive\Common\OutStreamWithCRC.h
-# End Source File
-# Begin Source File
-
-SOURCE=..\..\Archive\Common\ParseProperties.cpp
-# End Source File
-# Begin Source File
-
-SOURCE=..\..\Archive\Common\ParseProperties.h
-# End Source File
-# End Group
-# Begin Group "split"
-
-# PROP Default_Filter ""
-# Begin Source File
-
-SOURCE=..\..\Archive\Split\SplitHandler.cpp
-# End Source File
-# Begin Source File
-
-SOURCE=..\..\Archive\Split\SplitHandler.h
-# End Source File
-# End Group
-# End Group
-# Begin Group "UI Common"
-
-# PROP Default_Filter ""
-# Begin Source File
-
-SOURCE=..\..\UI\Common\ArchiveCommandLine.cpp
-# End Source File
-# Begin Source File
-
-SOURCE=..\..\UI\Common\ArchiveCommandLine.h
-# End Source File
-# Begin Source File
-
-SOURCE=..\..\UI\Common\ArchiveExtractCallback.cpp
-# End Source File
-# Begin Source File
-
-SOURCE=..\..\UI\Common\ArchiveExtractCallback.h
-# End Source File
-# Begin Source File
-
-SOURCE=..\..\UI\Common\ArchiveOpenCallback.cpp
-# End Source File
-# Begin Source File
-
-SOURCE=..\..\UI\Common\ArchiveOpenCallback.h
-# End Source File
-# Begin Source File
-
-SOURCE=..\..\UI\Common\DefaultName.cpp
-# End Source File
-# Begin Source File
-
-SOURCE=..\..\UI\Common\DefaultName.h
-# End Source File
-# Begin Source File
-
-SOURCE=..\..\UI\Common\EnumDirItems.cpp
-# End Source File
-# Begin Source File
-
-SOURCE=..\..\UI\Common\EnumDirItems.h
-# End Source File
-# Begin Source File
-
-SOURCE=..\..\UI\Common\Extract.cpp
-# End Source File
-# Begin Source File
-
-SOURCE=..\..\UI\Common\Extract.h
-# End Source File
-# Begin Source File
-
-SOURCE=..\..\UI\Common\ExtractingFilePath.cpp
-# End Source File
-# Begin Source File
-
-SOURCE=..\..\UI\Common\ExtractingFilePath.h
-# End Source File
-# Begin Source File
-
-SOURCE=..\..\UI\Common\LoadCodecs.cpp
-# End Source File
-# Begin Source File
-
-SOURCE=..\..\UI\Common\LoadCodecs.h
-# End Source File
-# Begin Source File
-
-SOURCE=..\..\UI\Common\OpenArchive.cpp
-# End Source File
-# Begin Source File
-
-SOURCE=..\..\UI\Common\OpenArchive.h
-# End Source File
-# Begin Source File
-
-SOURCE=..\..\UI\Common\Property.h
-# End Source File
-# Begin Source File
-
-SOURCE=..\..\UI\Common\PropIDUtils.cpp
-# End Source File
-# Begin Source File
-
-SOURCE=..\..\UI\Common\PropIDUtils.h
-# End Source File
-# Begin Source File
-
-SOURCE=..\..\UI\Common\SetProperties.cpp
-# End Source File
-# Begin Source File
-
-SOURCE=..\..\UI\Common\SetProperties.h
-# End Source File
-# Begin Source File
-
-SOURCE=..\..\UI\Common\SortUtils.cpp
-# End Source File
-# Begin Source File
-
-SOURCE=..\..\UI\Common\SortUtils.h
-# End Source File
-# Begin Source File
-
-SOURCE=..\..\UI\Common\TempFiles.cpp
-# End Source File
-# Begin Source File
-
-SOURCE=..\..\UI\Common\TempFiles.h
-# End Source File
-# Begin Source File
-
-SOURCE=..\..\UI\Common\Update.cpp
-# End Source File
-# Begin Source File
-
-SOURCE=..\..\UI\Common\Update.h
-# End Source File
-# Begin Source File
-
-SOURCE=..\..\UI\Common\UpdateAction.cpp
-# End Source File
-# Begin Source File
-
-SOURCE=..\..\UI\Common\UpdateAction.h
-# End Source File
-# Begin Source File
-
-SOURCE=..\..\UI\Common\UpdateCallback.cpp
-# End Source File
-# Begin Source File
-
-SOURCE=..\..\UI\Common\UpdateCallback.h
-# End Source File
-# Begin Source File
-
-SOURCE=..\..\UI\Common\UpdatePair.cpp
-# End Source File
-# Begin Source File
-
-SOURCE=..\..\UI\Common\UpdatePair.h
-# End Source File
-# Begin Source File
-
-SOURCE=..\..\UI\Common\UpdateProduce.cpp
-# End Source File
-# Begin Source File
-
-SOURCE=..\..\UI\Common\UpdateProduce.h
-# End Source File
-# Begin Source File
-
-SOURCE=..\..\UI\Common\WorkDir.cpp
-# End Source File
-# Begin Source File
-
-SOURCE=..\..\UI\Common\WorkDir.h
-# End Source File
-# End Group
-# Begin Group "7-zip"
-
-# PROP Default_Filter ""
-# Begin Source File
-
-SOURCE=..\..\ICoder.h
-# End Source File
-# Begin Source File
-
-SOURCE=..\..\IMyUnknown.h
-# End Source File
-# Begin Source File
-
-SOURCE=..\..\IPassword.h
-# End Source File
-# Begin Source File
-
-SOURCE=..\..\IProgress.h
-# End Source File
-# Begin Source File
-
-SOURCE=..\..\IStream.h
-# End Source File
-# Begin Source File
-
-SOURCE=..\..\PropID.h
-# End Source File
-# End Group
-# Begin Group "C"
-
-# PROP Default_Filter ""
-# Begin Group "C Branch"
-
-# PROP Default_Filter ""
-# Begin Source File
-
-SOURCE=..\..\..\..\C\Compress\Branch\BranchARM.c
-# SUBTRACT CPP /YX /Yc /Yu
-# End Source File
-# Begin Source File
-
-SOURCE=..\..\..\..\C\Compress\Branch\BranchARM.h
-# End Source File
-# Begin Source File
-
-SOURCE=..\..\..\..\C\Compress\Branch\BranchARMThumb.c
-# SUBTRACT CPP /YX /Yc /Yu
-# End Source File
-# Begin Source File
-
-SOURCE=..\..\..\..\C\Compress\Branch\BranchARMThumb.h
-# End Source File
-# Begin Source File
-
-SOURCE=..\..\..\..\C\Compress\Branch\BranchIA64.c
-# SUBTRACT CPP /YX /Yc /Yu
-# End Source File
-# Begin Source File
-
-SOURCE=..\..\..\..\C\Compress\Branch\BranchIA64.h
-# End Source File
-# Begin Source File
-
-SOURCE=..\..\..\..\C\Compress\Branch\BranchPPC.c
-# SUBTRACT CPP /YX /Yc /Yu
-# End Source File
-# Begin Source File
-
-SOURCE=..\..\..\..\C\Compress\Branch\BranchPPC.h
-# End Source File
-# Begin Source File
-
-SOURCE=..\..\..\..\C\Compress\Branch\BranchSPARC.c
-# SUBTRACT CPP /YX /Yc /Yu
-# End Source File
-# Begin Source File
-
-SOURCE=..\..\..\..\C\Compress\Branch\BranchSPARC.h
-# End Source File
-# Begin Source File
-
-SOURCE=..\..\..\..\C\Compress\Branch\BranchTypes.h
-# End Source File
-# Begin Source File
-
-SOURCE=..\..\..\..\C\Compress\Branch\BranchX86.c
-# SUBTRACT CPP /YX /Yc /Yu
-# End Source File
-# Begin Source File
-
-SOURCE=..\..\..\..\C\Compress\Branch\BranchX86.h
-# End Source File
-# End Group
-# Begin Source File
-
-SOURCE=..\..\..\..\C\7zCrc.c
-# SUBTRACT CPP /YX /Yc /Yu
-# End Source File
-# Begin Source File
-
-SOURCE=..\..\..\..\C\7zCrc.h
-# End Source File
-# Begin Source File
-
-SOURCE=..\..\..\..\C\Alloc.c
-# SUBTRACT CPP /YX /Yc /Yu
-# End Source File
-# Begin Source File
-
-SOURCE=..\..\..\..\C\Alloc.h
-# End Source File
-# Begin Source File
-
-SOURCE=..\..\..\..\C\IStream.h
-# End Source File
-# Begin Source File
-
-SOURCE=..\..\..\..\C\Compress\Lz\LzHash.h
-# End Source File
-# Begin Source File
-
-SOURCE=..\..\..\..\C\Compress\Lz\MatchFinder.c
-# SUBTRACT CPP /YX /Yc /Yu
-# End Source File
-# Begin Source File
-
-SOURCE=..\..\..\..\C\Compress\Lz\MatchFinder.h
-# End Source File
-# Begin Source File
-
-SOURCE=..\..\..\..\C\Compress\Lz\MatchFinderMt.c
-# SUBTRACT CPP /YX /Yc /Yu
-# End Source File
-# Begin Source File
-
-SOURCE=..\..\..\..\C\Compress\Lz\MatchFinderMt.h
-# End Source File
-# Begin Source File
-
-SOURCE=..\..\..\..\C\Threads.c
-# SUBTRACT CPP /YX /Yc /Yu
-# End Source File
-# Begin Source File
-
-SOURCE=..\..\..\..\C\Threads.h
-# End Source File
-# Begin Source File
-
-SOURCE=..\..\..\..\C\Types.h
-# End Source File
-# End Group
-# End Target
-# End Project
diff --git a/CPP/7zip/Bundles/Alone7z/Alone.dsw b/CPP/7zip/Bundles/Alone7z/Alone.dsw
deleted file mode 100755
index 65eca43f..00000000
--- a/CPP/7zip/Bundles/Alone7z/Alone.dsw
+++ /dev/null
@@ -1,29 +0,0 @@
-Microsoft Developer Studio Workspace File, Format Version 6.00
-# WARNING: DO NOT EDIT OR DELETE THIS WORKSPACE FILE!
-
-###############################################################################
-
-Project: "Alone"=.\Alone.dsp - Package Owner=<4>
-
-Package=<5>
-{{{
-}}}
-
-Package=<4>
-{{{
-}}}
-
-###############################################################################
-
-Global:
-
-Package=<5>
-{{{
-}}}
-
-Package=<3>
-{{{
-}}}
-
-###############################################################################
-
diff --git a/CPP/7zip/Bundles/Alone7z/makefile b/CPP/7zip/Bundles/Alone7z/makefile
index 1feb1fbd..53b94c1d 100755
--- a/CPP/7zip/Bundles/Alone7z/makefile
+++ b/CPP/7zip/Bundles/Alone7z/makefile
@@ -120,16 +120,22 @@ AR_COMMON_OBJS = \
$O\7zSpecStream.obj \
$O\7zUpdate.obj \
+LZM_OBJS = \
+ $O\LzmaArcRegister.obj \
+ $O\LzmaFiltersDecode.obj \
+ $O\LzmaHandler.obj \
+ $O\LzmaIn.obj \
+
+SPLIT_OBJS = \
+ $O\SplitHandler.obj \
+ $O\SplitHandlerOut.obj \
+ $O\SplitRegister.obj \
BRANCH_OPT_OBJS = \
- $O\BranchCoder.obj \
$O\x86.obj \
$O\x86_2.obj \
- $O\ARM.obj \
- $O\ARMThumb.obj \
- $O\IA64.obj \
- $O\PPC.obj \
- $O\SPARC.obj \
+ $O\BranchCoder.obj \
+ $O\BranchMisc.obj \
$O\BranchRegister.obj \
$O\BCJRegister.obj \
$O\BCJ2Register.obj \
@@ -142,9 +148,6 @@ COPY_OBJS = \
$O\CopyCoder.obj \
$O\CopyRegister.obj \
-LZ_OBJS = \
- $O\LZOutWindow.obj \
-
LZMA_OPT_OBJS = \
$O\LZMADecoder.obj \
$O\LZMAEncoder.obj \
@@ -155,23 +158,17 @@ LZMA_BENCH_OBJS = \
$O\LzmaBenchCon.obj \
C_OBJS = \
- $O\Alloc.obj \
$O\7zCrc.obj \
- $O\Sort.obj \
+ $O\Bra.obj \
+ $O\Bra86.obj \
+ $O\BraIA64.obj \
+ $O\Alloc.obj \
+ $O\LzmaDec.obj \
+ $O\LzmaEnc.obj \
+ $O\LzFind.obj \
+ $O\LzFindMt.obj \
$O\Threads.obj \
-C_LZ_OBJS = \
- $O\MatchFinder.obj \
- $O\MatchFinderMt.obj \
-
-C_BRANCH_OBJS = \
- $O\BranchARM.obj \
- $O\BranchARMThumb.obj \
- $O\BranchIA64.obj \
- $O\BranchPPC.obj \
- $O\BranchSPARC.obj \
- $O\BranchX86.obj \
-
OBJS = \
$O\StdAfx.obj \
$(CONSOLE_OBJS) \
@@ -181,16 +178,14 @@ OBJS = \
$(UI_COMMON_OBJS) \
$(AR_COMMON_OBJS) \
$(7Z_OBJS) \
+ $(LZM_OBJS) \
+ $(SPLIT_OBJS) \
$(BRANCH_OPT_OBJS) \
$(SWAP_OPT_OBJS) \
$(COPY_OBJS) \
- $(LZ_OBJS) \
$(LZMA_OPT_OBJS) \
$(LZMA_BENCH_OBJS) \
$(C_OBJS) \
- $(C_LZ_OBJS) \
- $(C_BRANCH_OBJS) \
- $O\RangeCoderBit.obj \
$(CRC_OBJS) \
$O\resource.res
@@ -213,24 +208,19 @@ $(AR_COMMON_OBJS): ../../Archive/Common/$(*B).cpp
$(7Z_OBJS): ../../Archive/7z/$(*B).cpp
$(COMPL)
+$(LZM_OBJS): ../../Archive/Lzma/$(*B).cpp
+ $(COMPL)
+$(SPLIT_OBJS): ../../Archive/Split/$(*B).cpp
+ $(COMPL)
$(BRANCH_OPT_OBJS): ../../Compress/Branch/$(*B).cpp
$(COMPL_O2)
$(SWAP_OPT_OBJS): ../../Compress/ByteSwap/$(*B).cpp
$(COMPL_O2)
$(COPY_OBJS): ../../Compress/Copy/$(*B).cpp
$(COMPL)
-$(LZ_OBJS): ../../Compress/LZ/$(*B).cpp
- $(COMPL)
$(LZMA_OPT_OBJS): ../../Compress/LZMA/$(*B).cpp
$(COMPL_O2)
$(LZMA_BENCH_OBJS): ../../Compress/LZMA_Alone/$(*B).cpp
$(COMPL)
-$O\RangeCoderBit.obj: ../../Compress/RangeCoder/$(*B).cpp
- $(COMPL)
-
$(C_OBJS): ../../../../C/$(*B).c
$(COMPL_O2)
-$(C_LZ_OBJS): ../../../../C/Compress/Lz/$(*B).c
- $(COMPL_O2)
-$(C_BRANCH_OBJS): ../../../../C/Compress/Branch/$(*B).c
- $(COMPL_O2)
diff --git a/CPP/7zip/Bundles/Format7z/makefile b/CPP/7zip/Bundles/Format7z/makefile
index 04bad9fd..b839ebac 100755
--- a/CPP/7zip/Bundles/Format7z/makefile
+++ b/CPP/7zip/Bundles/Format7z/makefile
@@ -80,14 +80,10 @@ COMPRESS_OBJS = \
$O\CodecExports.obj \
BRANCH_OPT_OBJS = \
- $O\BranchCoder.obj \
$O\x86.obj \
$O\x86_2.obj \
- $O\ARM.obj \
- $O\ARMThumb.obj \
- $O\IA64.obj \
- $O\PPC.obj \
- $O\SPARC.obj \
+ $O\BranchCoder.obj \
+ $O\BranchMisc.obj \
$O\BranchRegister.obj \
$O\BCJRegister.obj \
$O\BCJ2Register.obj \
@@ -135,26 +131,19 @@ AES_OPT_OBJS = \
CRYPTO_HASH_OBJS = \
$O\RandGen.obj \
$O\Sha1.obj \
- $O\Sha256.obj \
C_OBJS = \
$O\Alloc.obj \
+ $O\Bra.obj \
+ $O\Bra86.obj \
+ $O\BraIA64.obj \
+ $O\LzmaDec.obj \
+ $O\LzmaEnc.obj \
$O\Threads.obj \
-
-C_LZ_OBJS = \
- $O\MatchFinder.obj \
- $O\MatchFinderMt.obj \
-
-C_BRANCH_OBJS = \
- $O\BranchARM.obj \
- $O\BranchARMThumb.obj \
- $O\BranchIA64.obj \
- $O\BranchPPC.obj \
- $O\BranchSPARC.obj \
- $O\BranchX86.obj \
-
-C_CRYPTO = \
+ $O\LzFind.obj \
+ $O\LzFindMt.obj \
$O\Aes.obj \
+ $O\Sha256.obj \
!include "../../Crc2.mak"
@@ -178,13 +167,9 @@ OBJS = \
$(LZMA_OPT_OBJS) \
$(PPMD_OPT_OBJS) \
$(C_OBJS) \
- $(C_LZ_OBJS) \
- $(C_BRANCH_OBJS) \
- $O\RangeCoderBit.obj \
$(7ZAES_OPT_OBJS) \
$(AES_OPT_OBJS) \
$(CRYPTO_HASH_OBJS) \
- $(C_CRYPTO) \
$(CRC_OBJS) \
$O\resource.res
@@ -226,9 +211,6 @@ $(LZMA_OPT_OBJS): ../../Compress/LZMA/$(*B).cpp
$(PPMD_OPT_OBJS): ../../Compress/PPMD/$(*B).cpp
$(COMPL_O2)
-$O\RangeCoderBit.obj: ../../Compress/RangeCoder/$(*B).cpp
- $(COMPL)
-
$(AES_OPT_OBJS): ../../Crypto/AES/$(*B).cpp
$(COMPL_O2)
$(7ZAES_OPT_OBJS): ../../Crypto/7zAES/$(*B).cpp
@@ -238,11 +220,5 @@ $(CRYPTO_HASH_OBJS): ../../Crypto/Hash/$(*B).cpp
$(C_OBJS): ../../../../C/$(*B).c
$(COMPL_O2)
-$(C_BRANCH_OBJS): ../../../../C/Compress/Branch/$(*B).c
- $(COMPL_O2)
-$(C_LZ_OBJS): ../../../../C/Compress/Lz/$(*B).c
- $(COMPL_O2)
-$(C_CRYPTO): ../../../../C/Crypto/$(*B).c
- $(COMPL_O2)
!include "../../Crc.mak"
diff --git a/CPP/7zip/Bundles/Format7zExtract/makefile b/CPP/7zip/Bundles/Format7zExtract/makefile
index 10bec119..55cad33e 100755
--- a/CPP/7zip/Bundles/Format7zExtract/makefile
+++ b/CPP/7zip/Bundles/Format7zExtract/makefile
@@ -68,14 +68,10 @@ COMPRESS_OBJS = \
$O\CodecExports.obj \
BRANCH_OPT_OBJS = \
- $O\BranchCoder.obj \
$O\x86.obj \
$O\x86_2.obj \
- $O\ARM.obj \
- $O\ARMThumb.obj \
- $O\IA64.obj \
- $O\PPC.obj \
- $O\SPARC.obj \
+ $O\BranchCoder.obj \
+ $O\BranchMisc.obj \
$O\BranchRegister.obj \
$O\BCJRegister.obj \
$O\BCJ2Register.obj \
@@ -118,23 +114,15 @@ PPMD_OPT_OBJS = \
AES_OPT_OBJS = \
$O\MyAES.obj \
-CRYPTO_HASH_OBJS = \
- $O\Sha256.obj \
-
C_OBJS = \
$O\Alloc.obj \
+ $O\Bra.obj \
+ $O\Bra86.obj \
+ $O\BraIA64.obj \
+ $O\LzmaDec.obj \
$O\Threads.obj \
-
-C_BRANCH_OBJS = \
- $O\BranchARM.obj \
- $O\BranchARMThumb.obj \
- $O\BranchIA64.obj \
- $O\BranchPPC.obj \
- $O\BranchSPARC.obj \
- $O\BranchX86.obj \
-
-C_CRYPTO = \
$O\Aes.obj \
+ $O\Sha256.obj \
!include "../../Crc2.mak"
@@ -159,10 +147,7 @@ OBJS = \
$(PPMD_OPT_OBJS) \
$(7ZAES_OPT_OBJS) \
$(AES_OPT_OBJS) \
- $(CRYPTO_HASH_OBJS) \
$(C_OBJS) \
- $(C_BRANCH_OBJS) \
- $(C_CRYPTO) \
$(CRC_OBJS) \
$O\resource.res
@@ -208,13 +193,7 @@ $(AES_OPT_OBJS): ../../Crypto/AES/$(*B).cpp
$(COMPL_O2)
$(7ZAES_OPT_OBJS): ../../Crypto/7zAES/$(*B).cpp
$(COMPL_O2)
-$(CRYPTO_HASH_OBJS): ../../Crypto/Hash/$(*B).cpp
- $(COMPL_O2)
$(C_OBJS): ../../../../C/$(*B).c
$(COMPL_O2)
-$(C_BRANCH_OBJS): ../../../../C/Compress/Branch/$(*B).c
- $(COMPL_O2)
-$(C_CRYPTO): ../../../../C/Crypto/$(*B).c
- $(COMPL_O2)
!include "../../Crc.mak"
diff --git a/CPP/7zip/Bundles/Format7zExtractR/makefile b/CPP/7zip/Bundles/Format7zExtractR/makefile
index 0632e718..55069721 100755
--- a/CPP/7zip/Bundles/Format7zExtractR/makefile
+++ b/CPP/7zip/Bundles/Format7zExtractR/makefile
@@ -74,14 +74,10 @@ SWAP_OPT_OBJS = \
$O\ByteSwapRegister.obj \
BRANCH_OPT_OBJS = \
- $O\BranchCoder.obj \
$O\x86.obj \
$O\x86_2.obj \
- $O\ARM.obj \
- $O\ARMThumb.obj \
- $O\IA64.obj \
- $O\PPC.obj \
- $O\SPARC.obj \
+ $O\BranchCoder.obj \
+ $O\BranchMisc.obj \
$O\BranchRegister.obj \
$O\BCJRegister.obj \
$O\BCJ2Register.obj \
@@ -90,26 +86,19 @@ COPY_OBJS = \
$O\CopyCoder.obj \
$O\CopyRegister.obj \
-LZ_OBJS = \
- $O\LZOutWindow.obj \
-
LZMA_OPT_OBJS = \
$O\LZMADecoder.obj \
$O\LZMARegister.obj \
C_OBJS = \
- $O\Alloc.obj \
$O\7zCrc.obj \
+ $O\Alloc.obj \
+ $O\Bra.obj \
+ $O\Bra86.obj \
+ $O\BraIA64.obj \
+ $O\LzmaDec.obj \
$O\Threads.obj \
-C_BRANCH_OBJS = \
- $O\BranchARM.obj \
- $O\BranchARMThumb.obj \
- $O\BranchIA64.obj \
- $O\BranchPPC.obj \
- $O\BranchSPARC.obj \
- $O\BranchX86.obj \
-
OBJS = \
$O\StdAfx.obj \
$(CONSOLE_OBJS) \
@@ -123,10 +112,8 @@ OBJS = \
$(BRANCH_OPT_OBJS) \
$(SWAP_OPT_OBJS) \
$(COPY_OBJS) \
- $(LZ_OBJS) \
$(LZMA_OPT_OBJS) \
$(C_OBJS) \
- $(C_BRANCH_OBJS) \
$O\resource.res
@@ -154,12 +141,8 @@ $(SWAP_OPT_OBJS): ../../Compress/ByteSwap/$(*B).cpp
$(COMPL_O2)
$(COPY_OBJS): ../../Compress/Copy/$(*B).cpp
$(COMPL)
-$(LZ_OBJS): ../../Compress/LZ/$(*B).cpp
- $(COMPL)
$(LZMA_OPT_OBJS): ../../Compress/LZMA/$(*B).cpp
$(COMPL_O2)
$(C_OBJS): ../../../../C/$(*B).c
$(COMPL_O2)
-$(C_BRANCH_OBJS): ../../../../C/Compress/Branch/$(*B).c
- $(COMPL_O2)
diff --git a/CPP/7zip/Bundles/Format7zF/Format7z.dsp b/CPP/7zip/Bundles/Format7zF/Format7z.dsp
index 5b2f0098..7a41a82a 100755
--- a/CPP/7zip/Bundles/Format7zF/Format7z.dsp
+++ b/CPP/7zip/Bundles/Format7zF/Format7z.dsp
@@ -43,7 +43,7 @@ RSC=rc.exe
# PROP Ignore_Export_Lib 1
# PROP Target_Dir ""
# ADD BASE CPP /nologo /MT /W3 /GX /O2 /D "WIN32" /D "NDEBUG" /D "_WINDOWS" /D "_MBCS" /D "_USRDLL" /D "MY7Z_EXPORTS" /YX /FD /c
-# ADD CPP /nologo /Gz /MT /W3 /GX /O1 /I "..\..\..\\" /D "NDEBUG" /D "WIN32" /D "_WINDOWS" /D "_MBCS" /D "_USRDLL" /D "MY7Z_EXPORTS" /D "NO_REGISTRY" /D "COMPRESS_MF_MT" /D "COMPRESS_MT" /D "COMPRESS_BZIP2_MT" /D "EXTERNAL_CODECS" /D "_7ZIP_LARGE_PAGES" /Yu"StdAfx.h" /FD /c
+# ADD CPP /nologo /Gr /MT /W3 /GX /O1 /I "..\..\..\\" /D "NDEBUG" /D "WIN32" /D "_WINDOWS" /D "_MBCS" /D "_USRDLL" /D "MY7Z_EXPORTS" /D "NO_REGISTRY" /D "COMPRESS_MF_MT" /D "COMPRESS_MT" /D "COMPRESS_BZIP2_MT" /D "EXTERNAL_CODECS" /D "_7ZIP_LARGE_PAGES" /D "_LZMA_PROB32_" /FAcs /Yu"StdAfx.h" /FD /c
# ADD BASE MTL /nologo /D "NDEBUG" /mktyplib203 /win32
# ADD MTL /nologo /D "NDEBUG" /mktyplib203 /win32
# ADD BASE RSC /l 0x419 /d "NDEBUG"
@@ -70,7 +70,7 @@ LINK32=link.exe
# PROP Ignore_Export_Lib 1
# PROP Target_Dir ""
# ADD BASE CPP /nologo /MTd /W3 /Gm /GX /ZI /Od /D "WIN32" /D "_DEBUG" /D "_WINDOWS" /D "_MBCS" /D "_USRDLL" /D "MY7Z_EXPORTS" /YX /FD /GZ /c
-# ADD CPP /nologo /Gz /MTd /W3 /Gm /GX /ZI /Od /I "..\..\..\..\SDK" /I "..\..\..\\" /D "_DEBUG" /D "WIN32" /D "_WINDOWS" /D "_MBCS" /D "_USRDLL" /D "MY7Z_EXPORTS" /D "NO_REGISTRY" /D "COMPRESS_MF_MT" /D "COMPRESS_MT" /D "COMPRESS_BZIP2_MT" /D "EXTERNAL_CODECS" /D "_7ZIP_LARGE_PAGES" /Yu"StdAfx.h" /FD /GZ /c
+# ADD CPP /nologo /Gr /MTd /W3 /Gm /GX /ZI /Od /I "..\..\..\..\SDK" /I "..\..\..\\" /D "_DEBUG" /D "WIN32" /D "_WINDOWS" /D "_MBCS" /D "_USRDLL" /D "MY7Z_EXPORTS" /D "NO_REGISTRY" /D "COMPRESS_MF_MT" /D "COMPRESS_MT" /D "COMPRESS_BZIP2_MT" /D "EXTERNAL_CODECS" /D "_7ZIP_LARGE_PAGES" /D "_LZMA_PROB32" /Yu"StdAfx.h" /FD /GZ /c
# ADD BASE MTL /nologo /D "_DEBUG" /mktyplib203 /win32
# ADD MTL /nologo /D "_DEBUG" /mktyplib203 /win32
# ADD BASE RSC /l 0x419 /d "_DEBUG"
@@ -105,176 +105,188 @@ SOURCE=..\..\Archive\ArchiveExports.cpp
# End Source File
# Begin Source File
-SOURCE=..\..\Compress\CodecExports.cpp
+SOURCE=..\..\Archive\Arj\arj.ico
# End Source File
# Begin Source File
-SOURCE=..\..\Archive\DllExports2.cpp
+SOURCE=..\..\Archive\BZip2\bz2.ico
# End Source File
# Begin Source File
-SOURCE=.\resource.rc
+SOURCE=..\..\Archive\Cab\cab.ico
# End Source File
# Begin Source File
-SOURCE=.\StdAfx.cpp
-# ADD CPP /Yc"StdAfx.h"
+SOURCE=..\..\Compress\CodecExports.cpp
# End Source File
# Begin Source File
-SOURCE=.\StdAfx.h
+SOURCE=..\..\Archive\Cpio\cpio.ico
# End Source File
-# End Group
-# Begin Group "Common"
+# Begin Source File
-# PROP Default_Filter ""
+SOURCE=..\..\Archive\Deb\deb.ico
+# End Source File
# Begin Source File
-SOURCE=..\..\..\Common\Buffer.h
+SOURCE=..\..\Archive\DllExports2.cpp
# End Source File
# Begin Source File
-SOURCE=..\..\..\Common\CRC.cpp
+SOURCE=..\..\Archive\GZip\gz.ico
# End Source File
# Begin Source File
-SOURCE=..\..\..\Common\IntToString.cpp
+SOURCE=..\..\Archive\Iso\Iso.ico
# End Source File
# Begin Source File
-SOURCE=..\..\..\Common\IntToString.h
+SOURCE=..\..\Archive\Lzh\lzh.ico
# End Source File
# Begin Source File
-SOURCE=..\..\..\Common\MyCom.h
+SOURCE=..\..\Archive\Lzma\lzma.ico
# End Source File
# Begin Source File
-SOURCE=..\..\..\Common\MyException.h
+SOURCE=..\..\Archive\Rar\rar.ico
# End Source File
# Begin Source File
-SOURCE=..\..\..\Common\MyInitGuid.h
+SOURCE=.\resource.rc
# End Source File
# Begin Source File
-SOURCE=..\..\..\Common\MyString.cpp
+SOURCE=..\..\Archive\RPM\rpm.ico
# End Source File
# Begin Source File
-SOURCE=..\..\..\Common\MyString.h
+SOURCE=..\..\Archive\Split\Split.ico
# End Source File
# Begin Source File
-SOURCE=..\..\..\Common\MyUnknown.h
+SOURCE=.\StdAfx.cpp
+# ADD CPP /Yc"StdAfx.h"
# End Source File
# Begin Source File
-SOURCE=..\..\..\Common\MyVector.cpp
+SOURCE=.\StdAfx.h
# End Source File
# Begin Source File
-SOURCE=..\..\..\Common\MyVector.h
+SOURCE=..\..\Archive\Tar\tar.ico
# End Source File
# Begin Source File
-SOURCE=..\..\..\Common\MyWindows.h
+SOURCE=..\..\Archive\Wim\wim.ico
# End Source File
# Begin Source File
-SOURCE=..\..\..\Common\NewHandler.cpp
+SOURCE=..\..\Archive\Z\Z.ico
# End Source File
# Begin Source File
-SOURCE=..\..\..\Common\NewHandler.h
+SOURCE=..\..\Archive\Zip\zip.ico
# End Source File
+# End Group
+# Begin Group "Common"
+
+# PROP Default_Filter ""
# Begin Source File
-SOURCE=..\..\..\Common\StringConvert.cpp
+SOURCE=..\..\..\Common\Buffer.h
# End Source File
# Begin Source File
-SOURCE=..\..\..\Common\StringConvert.h
+SOURCE=..\..\..\Common\CRC.cpp
# End Source File
# Begin Source File
-SOURCE=..\..\..\Common\StringToInt.cpp
+SOURCE=..\..\..\Common\IntToString.cpp
# End Source File
# Begin Source File
-SOURCE=..\..\..\Common\StringToInt.h
+SOURCE=..\..\..\Common\IntToString.h
# End Source File
# Begin Source File
-SOURCE=..\..\..\Common\UTFConvert.cpp
+SOURCE=..\..\..\Common\MyCom.h
# End Source File
# Begin Source File
-SOURCE=..\..\..\Common\UTFConvert.h
+SOURCE=..\..\..\Common\MyException.h
# End Source File
# Begin Source File
-SOURCE=..\..\..\Common\Wildcard.cpp
+SOURCE=..\..\..\Common\MyInitGuid.h
# End Source File
# Begin Source File
-SOURCE=..\..\..\Common\Wildcard.h
+SOURCE=..\..\..\Common\MyString.cpp
# End Source File
-# End Group
-# Begin Group "Windows"
+# Begin Source File
-# PROP Default_Filter ""
+SOURCE=..\..\..\Common\MyString.h
+# End Source File
# Begin Source File
-SOURCE=..\..\..\Windows\FileDir.cpp
+SOURCE=..\..\..\Common\MyUnknown.h
# End Source File
# Begin Source File
-SOURCE=..\..\..\Windows\FileDir.h
+SOURCE=..\..\..\Common\MyVector.cpp
# End Source File
# Begin Source File
-SOURCE=..\..\..\Windows\FileFind.cpp
+SOURCE=..\..\..\Common\MyVector.h
# End Source File
# Begin Source File
-SOURCE=..\..\..\Windows\FileFind.h
+SOURCE=..\..\..\Common\MyWindows.h
# End Source File
# Begin Source File
-SOURCE=..\..\..\Windows\FileIO.cpp
+SOURCE=..\..\..\Common\NewHandler.cpp
# End Source File
# Begin Source File
-SOURCE=..\..\..\Windows\FileIO.h
+SOURCE=..\..\..\Common\NewHandler.h
# End Source File
# Begin Source File
-SOURCE=..\..\..\Windows\PropVariant.cpp
+SOURCE=..\..\..\Common\StringConvert.cpp
# End Source File
# Begin Source File
-SOURCE=..\..\..\Windows\PropVariant.h
+SOURCE=..\..\..\Common\StringConvert.h
# End Source File
# Begin Source File
-SOURCE=..\..\..\Windows\Synchronization.cpp
+SOURCE=..\..\..\Common\StringToInt.cpp
# End Source File
# Begin Source File
-SOURCE=..\..\..\Windows\Synchronization.h
+SOURCE=..\..\..\Common\StringToInt.h
# End Source File
# Begin Source File
-SOURCE=..\..\..\Windows\System.cpp
+SOURCE=..\..\..\Common\Types.h
# End Source File
# Begin Source File
-SOURCE=..\..\..\Windows\System.h
+SOURCE=..\..\..\Common\UTFConvert.cpp
# End Source File
# Begin Source File
-SOURCE=..\..\..\Windows\Thread.h
+SOURCE=..\..\..\Common\UTFConvert.h
+# End Source File
+# Begin Source File
+
+SOURCE=..\..\..\Common\Wildcard.cpp
+# End Source File
+# Begin Source File
+
+SOURCE=..\..\..\Common\Wildcard.h
# End Source File
# End Group
# Begin Group "Compress"
@@ -365,22 +377,6 @@ SOURCE=..\..\Compress\PPMD\PPMDType.h
# PROP Default_Filter ""
# Begin Source File
-SOURCE=..\..\Compress\Branch\ARM.cpp
-# End Source File
-# Begin Source File
-
-SOURCE=..\..\Compress\Branch\ARM.h
-# End Source File
-# Begin Source File
-
-SOURCE=..\..\Compress\Branch\ARMThumb.cpp
-# End Source File
-# Begin Source File
-
-SOURCE=..\..\Compress\Branch\ARMThumb.h
-# End Source File
-# Begin Source File
-
SOURCE=..\..\Compress\Branch\BCJ2Register.cpp
# End Source File
# Begin Source File
@@ -397,31 +393,15 @@ SOURCE=..\..\Compress\Branch\BranchCoder.h
# End Source File
# Begin Source File
-SOURCE=..\..\Compress\Branch\BranchRegister.cpp
-# End Source File
-# Begin Source File
-
-SOURCE=..\..\Compress\Branch\IA64.cpp
-# End Source File
-# Begin Source File
-
-SOURCE=..\..\Compress\Branch\IA64.h
-# End Source File
-# Begin Source File
-
-SOURCE=..\..\Compress\Branch\PPC.cpp
+SOURCE=..\..\Compress\Branch\BranchMisc.cpp
# End Source File
# Begin Source File
-SOURCE=..\..\Compress\Branch\PPC.h
+SOURCE=..\..\Compress\Branch\BranchMisc.h
# End Source File
# Begin Source File
-SOURCE=..\..\Compress\Branch\SPARC.cpp
-# End Source File
-# Begin Source File
-
-SOURCE=..\..\Compress\Branch\SPARC.h
+SOURCE=..\..\Compress\Branch\BranchRegister.cpp
# End Source File
# Begin Source File
@@ -588,6 +568,16 @@ SOURCE=..\..\Compress\Deflate\DeflateDecoder.h
# Begin Source File
SOURCE=..\..\Compress\Deflate\DeflateEncoder.cpp
+
+!IF "$(CFG)" == "7z - Win32 Release"
+
+# ADD CPP /O2
+# SUBTRACT CPP /YX /Yc /Yu
+
+!ELSEIF "$(CFG)" == "7z - Win32 Debug"
+
+!ENDIF
+
# End Source File
# Begin Source File
@@ -638,6 +628,18 @@ SOURCE=..\..\Compress\BZip2\BZip2Decoder.h
# Begin Source File
SOURCE=..\..\Compress\BZip2\BZip2Encoder.cpp
+
+!IF "$(CFG)" == "7z - Win32 Release"
+
+# ADD CPP /O2
+# SUBTRACT CPP /YX /Yc /Yu
+
+!ELSEIF "$(CFG)" == "7z - Win32 Debug"
+
+# SUBTRACT CPP /YX /Yc /Yu
+
+!ENDIF
+
# End Source File
# Begin Source File
@@ -693,14 +695,6 @@ SOURCE=..\..\Compress\Rar\RarCodecsRegister.cpp
# PROP Default_Filter ""
# Begin Source File
-SOURCE=..\..\Compress\BWT\BlockSort.cpp
-# End Source File
-# Begin Source File
-
-SOURCE=..\..\Compress\BWT\BlockSort.h
-# End Source File
-# Begin Source File
-
SOURCE=..\..\Compress\BWT\Mtf8.h
# End Source File
# End Group
@@ -963,24 +957,6 @@ SOURCE=..\..\Crypto\Hash\Sha1.cpp
SOURCE=..\..\Crypto\Hash\Sha1.h
# End Source File
-# Begin Source File
-
-SOURCE=..\..\Crypto\Hash\Sha256.cpp
-
-!IF "$(CFG)" == "7z - Win32 Release"
-
-# ADD CPP /O2
-# SUBTRACT CPP /YX /Yc /Yu
-
-!ELSEIF "$(CFG)" == "7z - Win32 Debug"
-
-!ENDIF
-
-# End Source File
-# Begin Source File
-
-SOURCE=..\..\Crypto\Hash\Sha256.h
-# End Source File
# End Group
# Begin Group "RarAES"
@@ -1020,6 +996,16 @@ SOURCE=..\..\Crypto\Rar20\Rar20Crypto.h
# Begin Source File
SOURCE=..\..\Crypto\WzAES\WzAES.cpp
+
+!IF "$(CFG)" == "7z - Win32 Release"
+
+# ADD CPP /O2
+# SUBTRACT CPP /YX /Yc /Yu
+
+!ELSEIF "$(CFG)" == "7z - Win32 Debug"
+
+!ENDIF
+
# End Source File
# Begin Source File
@@ -1226,19 +1212,9 @@ SOURCE=..\..\Common\VirtThread.h
# Begin Group "C"
# PROP Default_Filter ""
-# Begin Group "Compress C"
-
-# PROP Default_Filter ""
-# Begin Group "C-Lz"
-
-# PROP Default_Filter ""
# Begin Source File
-SOURCE=..\..\..\..\C\Compress\Lz\LzHash.h
-# End Source File
-# Begin Source File
-
-SOURCE=..\..\..\..\C\Compress\Lz\MatchFinder.c
+SOURCE=..\..\..\..\C\7zCrc.c
!IF "$(CFG)" == "7z - Win32 Release"
@@ -1254,11 +1230,11 @@ SOURCE=..\..\..\..\C\Compress\Lz\MatchFinder.c
# End Source File
# Begin Source File
-SOURCE=..\..\..\..\C\Compress\Lz\MatchFinder.h
+SOURCE=..\..\..\..\C\7zCrc.h
# End Source File
# Begin Source File
-SOURCE=..\..\..\..\C\Compress\Lz\MatchFinderMt.c
+SOURCE=..\..\..\..\C\Aes.c
!IF "$(CFG)" == "7z - Win32 Release"
@@ -1274,28 +1250,20 @@ SOURCE=..\..\..\..\C\Compress\Lz\MatchFinderMt.c
# End Source File
# Begin Source File
-SOURCE=..\..\..\..\C\Compress\Lz\MatchFinderMt.h
+SOURCE=..\..\..\..\C\Aes.h
# End Source File
-# End Group
-# Begin Group "Huffman"
-
-# PROP Default_Filter ""
# Begin Source File
-SOURCE=..\..\..\..\C\Compress\Huffman\HuffmanEncode.c
+SOURCE=..\..\..\..\C\Alloc.c
# SUBTRACT CPP /YX /Yc /Yu
# End Source File
# Begin Source File
-SOURCE=..\..\..\..\C\Compress\Huffman\HuffmanEncode.h
+SOURCE=..\..\..\..\C\Alloc.h
# End Source File
-# End Group
-# Begin Group "C Branch"
-
-# PROP Default_Filter ""
# Begin Source File
-SOURCE=..\..\..\..\C\Compress\Branch\BranchARM.c
+SOURCE=..\..\..\..\C\Bra.c
!IF "$(CFG)" == "7z - Win32 Release"
@@ -1311,11 +1279,11 @@ SOURCE=..\..\..\..\C\Compress\Branch\BranchARM.c
# End Source File
# Begin Source File
-SOURCE=..\..\..\..\C\Compress\Branch\BranchARM.h
+SOURCE=..\..\..\..\C\Bra.h
# End Source File
# Begin Source File
-SOURCE=..\..\..\..\C\Compress\Branch\BranchARMThumb.c
+SOURCE=..\..\..\..\C\Bra86.c
!IF "$(CFG)" == "7z - Win32 Release"
@@ -1331,11 +1299,23 @@ SOURCE=..\..\..\..\C\Compress\Branch\BranchARMThumb.c
# End Source File
# Begin Source File
-SOURCE=..\..\..\..\C\Compress\Branch\BranchARMThumb.h
+SOURCE=..\..\..\..\C\BraIA64.c
+
+!IF "$(CFG)" == "7z - Win32 Release"
+
+# ADD CPP /O2
+# SUBTRACT CPP /YX /Yc /Yu
+
+!ELSEIF "$(CFG)" == "7z - Win32 Debug"
+
+# SUBTRACT CPP /YX /Yc /Yu
+
+!ENDIF
+
# End Source File
# Begin Source File
-SOURCE=..\..\..\..\C\Compress\Branch\BranchIA64.c
+SOURCE=..\..\..\..\C\BwtSort.c
!IF "$(CFG)" == "7z - Win32 Release"
@@ -1351,11 +1331,15 @@ SOURCE=..\..\..\..\C\Compress\Branch\BranchIA64.c
# End Source File
# Begin Source File
-SOURCE=..\..\..\..\C\Compress\Branch\BranchIA64.h
+SOURCE=..\..\..\..\C\BwtSort.h
# End Source File
# Begin Source File
-SOURCE=..\..\..\..\C\Compress\Branch\BranchPPC.c
+SOURCE=..\..\..\..\C\CpuArch.h
+# End Source File
+# Begin Source File
+
+SOURCE=..\..\..\..\C\HuffEnc.c
!IF "$(CFG)" == "7z - Win32 Release"
@@ -1371,11 +1355,11 @@ SOURCE=..\..\..\..\C\Compress\Branch\BranchPPC.c
# End Source File
# Begin Source File
-SOURCE=..\..\..\..\C\Compress\Branch\BranchPPC.h
+SOURCE=..\..\..\..\C\HuffEnc.h
# End Source File
# Begin Source File
-SOURCE=..\..\..\..\C\Compress\Branch\BranchSPARC.c
+SOURCE=..\..\..\..\C\LzFind.c
!IF "$(CFG)" == "7z - Win32 Release"
@@ -1391,19 +1375,15 @@ SOURCE=..\..\..\..\C\Compress\Branch\BranchSPARC.c
# End Source File
# Begin Source File
-SOURCE=..\..\..\..\C\Compress\Branch\BranchSPARC.h
-# End Source File
-# Begin Source File
-
-SOURCE=..\..\..\..\C\Compress\Branch\BranchTypes.h
+SOURCE=..\..\..\..\C\LzFind.h
# End Source File
# Begin Source File
-SOURCE=..\..\..\..\C\Compress\Branch\BranchX86.c
+SOURCE=..\..\..\..\C\LzFindMt.c
!IF "$(CFG)" == "7z - Win32 Release"
-# ADD CPP /O2 /FAs
+# ADD CPP /O2
# SUBTRACT CPP /YX /Yc /Yu
!ELSEIF "$(CFG)" == "7z - Win32 Debug"
@@ -1415,16 +1395,15 @@ SOURCE=..\..\..\..\C\Compress\Branch\BranchX86.c
# End Source File
# Begin Source File
-SOURCE=..\..\..\..\C\Compress\Branch\BranchX86.h
+SOURCE=..\..\..\..\C\LzFindMt.h
# End Source File
-# End Group
-# End Group
-# Begin Group "Crypto-C"
+# Begin Source File
-# PROP Default_Filter ""
+SOURCE=..\..\..\..\C\LzHash.h
+# End Source File
# Begin Source File
-SOURCE=..\..\..\..\C\Crypto\Aes.c
+SOURCE=..\..\..\..\C\LzmaDec.c
!IF "$(CFG)" == "7z - Win32 Release"
@@ -1440,12 +1419,11 @@ SOURCE=..\..\..\..\C\Crypto\Aes.c
# End Source File
# Begin Source File
-SOURCE=..\..\..\..\C\Crypto\Aes.h
+SOURCE=..\..\..\..\C\LzmaDec.h
# End Source File
-# End Group
# Begin Source File
-SOURCE=..\..\..\..\C\7zCrc.c
+SOURCE=..\..\..\..\C\LzmaEnc.c
!IF "$(CFG)" == "7z - Win32 Release"
@@ -1461,24 +1439,31 @@ SOURCE=..\..\..\..\C\7zCrc.c
# End Source File
# Begin Source File
-SOURCE=..\..\..\..\C\7zCrc.h
+SOURCE=..\..\..\..\C\LzmaEnc.h
# End Source File
# Begin Source File
-SOURCE=..\..\..\..\C\Alloc.c
-# SUBTRACT CPP /YX /Yc /Yu
+SOURCE=..\..\..\..\C\RotateDefs.h
# End Source File
# Begin Source File
-SOURCE=..\..\..\..\C\Alloc.h
-# End Source File
-# Begin Source File
+SOURCE=..\..\..\..\C\Sha256.c
+
+!IF "$(CFG)" == "7z - Win32 Release"
+
+# ADD CPP /O2
+# SUBTRACT CPP /YX /Yc /Yu
+
+!ELSEIF "$(CFG)" == "7z - Win32 Debug"
+
+# SUBTRACT CPP /YX /Yc /Yu
+
+!ENDIF
-SOURCE=..\..\..\..\C\CpuArch.h
# End Source File
# Begin Source File
-SOURCE=..\..\..\..\C\IStream.h
+SOURCE=..\..\..\..\C\Sha256.h
# End Source File
# Begin Source File
@@ -2397,6 +2382,42 @@ SOURCE=..\..\Archive\Com\ComIn.h
SOURCE=..\..\Archive\Com\ComRegister.cpp
# End Source File
# End Group
+# Begin Group "Lzma Ar"
+
+# PROP Default_Filter ""
+# Begin Source File
+
+SOURCE=..\..\Archive\Lzma\LzmaArcRegister.cpp
+# End Source File
+# Begin Source File
+
+SOURCE=..\..\Archive\Lzma\LzmaFiltersDecode.cpp
+# End Source File
+# Begin Source File
+
+SOURCE=..\..\Archive\Lzma\LzmaFiltersDecode.h
+# End Source File
+# Begin Source File
+
+SOURCE=..\..\Archive\Lzma\LzmaHandler.cpp
+# End Source File
+# Begin Source File
+
+SOURCE=..\..\Archive\Lzma\LzmaHandler.h
+# End Source File
+# Begin Source File
+
+SOURCE=..\..\Archive\Lzma\LzmaIn.cpp
+# End Source File
+# Begin Source File
+
+SOURCE=..\..\Archive\Lzma\LzmaIn.h
+# End Source File
+# Begin Source File
+
+SOURCE=..\..\Archive\Lzma\LzmaItem.h
+# End Source File
+# End Group
# Begin Source File
SOURCE=..\..\Archive\IArchive.h
@@ -2426,65 +2447,61 @@ SOURCE=..\..\IProgress.h
SOURCE=..\..\IStream.h
# End Source File
# End Group
-# Begin Source File
-
-SOURCE=..\..\Archive\Arj\arj.ico
-# End Source File
-# Begin Source File
+# Begin Group "Windows"
-SOURCE=..\..\Archive\BZip2\bz2.ico
-# End Source File
+# PROP Default_Filter ""
# Begin Source File
-SOURCE=..\..\Archive\Cab\cab.ico
+SOURCE=..\..\..\Windows\FileDir.cpp
# End Source File
# Begin Source File
-SOURCE=..\..\Archive\Cpio\cpio.ico
+SOURCE=..\..\..\Windows\FileDir.h
# End Source File
# Begin Source File
-SOURCE=..\..\Archive\Deb\deb.ico
+SOURCE=..\..\..\Windows\FileFind.cpp
# End Source File
# Begin Source File
-SOURCE=..\..\Archive\GZip\gz.ico
+SOURCE=..\..\..\Windows\FileFind.h
# End Source File
# Begin Source File
-SOURCE=..\..\Archive\Iso\Iso.ico
+SOURCE=..\..\..\Windows\FileIO.cpp
# End Source File
# Begin Source File
-SOURCE=..\..\Archive\Lzh\lzh.ico
+SOURCE=..\..\..\Windows\FileIO.h
# End Source File
# Begin Source File
-SOURCE=..\..\Archive\Rar\rar.ico
+SOURCE=..\..\..\Windows\PropVariant.cpp
# End Source File
# Begin Source File
-SOURCE=..\..\Archive\RPM\rpm.ico
+SOURCE=..\..\..\Windows\PropVariant.h
# End Source File
# Begin Source File
-SOURCE=..\..\Archive\Split\Split.ico
+SOURCE=..\..\..\Windows\Synchronization.cpp
# End Source File
# Begin Source File
-SOURCE=..\..\Archive\Tar\tar.ico
+SOURCE=..\..\..\Windows\Synchronization.h
# End Source File
# Begin Source File
-SOURCE=..\..\Archive\Wim\wim.ico
+SOURCE=..\..\..\Windows\System.cpp
# End Source File
# Begin Source File
-SOURCE=..\..\Archive\Z\Z.ico
+SOURCE=..\..\..\Windows\System.h
# End Source File
# Begin Source File
-SOURCE=..\..\Archive\Zip\zip.ico
+SOURCE=..\..\..\Windows\Thread.h
# End Source File
+# End Group
# End Target
# End Project
diff --git a/CPP/7zip/Bundles/Format7zF/makefile b/CPP/7zip/Bundles/Format7zF/makefile
index 887386ee..328f8ab6 100755
--- a/CPP/7zip/Bundles/Format7zF/makefile
+++ b/CPP/7zip/Bundles/Format7zF/makefile
@@ -147,6 +147,12 @@ LZH_OBJS = \
$O\LzhOutStreamWithCRC.obj \
$O\LzhRegister.obj \
+LZM_OBJS = \
+ $O\LzmaArcRegister.obj \
+ $O\LzmaFiltersDecode.obj \
+ $O\LzmaHandler.obj \
+ $O\LzmaIn.obj \
+
NSIS_OBJS = \
$O\NsisDecode.obj \
$O\NsisHandler.obj \
@@ -204,17 +210,13 @@ COMPRESS_OBJS = \
$O\CodecExports.obj \
BRANCH_OPT_OBJS = \
+ $O\x86.obj \
+ $O\x86_2.obj \
$O\BranchCoder.obj \
+ $O\BranchMisc.obj \
$O\BranchRegister.obj \
$O\BCJRegister.obj \
$O\BCJ2Register.obj \
- $O\x86.obj \
- $O\x86_2.obj \
- $O\ARM.obj \
- $O\ARMThumb.obj \
- $O\IA64.obj \
- $O\PPC.obj \
- $O\SPARC.obj \
SWAP_OPT_OBJS = \
$O\ByteSwap.obj \
@@ -292,7 +294,6 @@ CRYPTO_HASH_OBJS = \
$O\Pbkdf2HmacSha1.obj \
$O\RandGen.obj \
$O\Sha1.obj \
- $O\Sha256.obj \
CRYPTO_WZAES_OBJS = \
$O\WzAES.obj \
@@ -311,23 +312,19 @@ CRYPTO_RARAES_OBJS = \
C_OBJS = \
$O\Alloc.obj \
- $O\Threads.obj \
+ $O\Bra.obj \
+ $O\Bra86.obj \
+ $O\BraIA64.obj \
+ $O\BwtSort.obj \
+ $O\HuffEnc.obj \
+ $O\LzFind.obj \
+ $O\LzFindMt.obj \
+ $O\LzmaDec.obj \
+ $O\LzmaEnc.obj \
$O\Sort.obj \
-
-C_LZ_OBJS = \
- $O\MatchFinder.obj \
- $O\MatchFinderMt.obj \
-
-C_BRANCH_OBJS = \
- $O\BranchARM.obj \
- $O\BranchARMThumb.obj \
- $O\BranchIA64.obj \
- $O\BranchPPC.obj \
- $O\BranchSPARC.obj \
- $O\BranchX86.obj \
-
-C_CRYPTO = \
+ $O\Threads.obj \
$O\Aes.obj \
+ $O\Sha256.obj \
!include "../../Crc2.mak"
@@ -350,6 +347,7 @@ OBJS = \
$(GZ_OBJS) \
$(ISO_OBJS) \
$(LZH_OBJS) \
+ $(LZM_OBJS) \
$(NSIS_OBJS) \
$(RAR_OBJS) \
$(RPM_OBJS) \
@@ -377,11 +375,6 @@ OBJS = \
$(COMPRESS_Z_OBJS) \
$O\QuantumDecoder.obj \
$(C_OBJS) \
- $(C_LZ_OBJS) \
- $(C_BRANCH_OBJS) \
- $(C_CRYPTO) \
- $O\HuffmanEncode.obj \
- $O\BlockSort.obj \
$O\RangeCoderBit.obj \
$(7ZAES_OPT_OBJS) \
$(AES_OPT_OBJS) \
@@ -429,6 +422,8 @@ $(ISO_OBJS): ../../Archive/Iso/$(*B).cpp
$(COMPL)
$(LZH_OBJS): ../../Archive/Lzh/$(*B).cpp
$(COMPL)
+$(LZM_OBJS): ../../Archive/Lzma/$(*B).cpp
+ $(COMPL)
$(NSIS_OBJS): ../../Archive/Nsis/$(*B).cpp
$(COMPL)
$(RAR_OBJS): ../../Archive/Rar/$(*B).cpp
@@ -483,8 +478,6 @@ $(COMPRESS_Z_OBJS): ../../Compress/Z/$(*B).cpp
$O\QuantumDecoder.obj: ../../Compress/Quantum/$(*B).cpp
$(COMPL)
-$O\BlockSort.obj: ../../Compress/BWT/$(*B).cpp
- $(COMPL_O2)
$O\RangeCoderBit.obj: ../../Compress/RangeCoder/$(*B).cpp
$(COMPL)
@@ -505,13 +498,5 @@ $(CRYPTO_RARAES_OBJS): ../../Crypto/RarAES/$(*B).cpp
$(C_OBJS): ../../../../C/$(*B).c
$(COMPL_O2)
-$(C_LZ_OBJS): ../../../../C/Compress/Lz/$(*B).c
- $(COMPL_O2)
-$(C_BRANCH_OBJS): ../../../../C/Compress/Branch/$(*B).c
- $(COMPL_O2)
-$O\HuffmanEncode.obj: ../../../../C/Compress/Huffman/$(*B).c
- $(COMPL_O2)
-$(C_CRYPTO): ../../../../C/Crypto/$(*B).c
- $(COMPL_O2)
!include "../../Crc.mak"
diff --git a/CPP/7zip/Bundles/Format7zF/resource.rc b/CPP/7zip/Bundles/Format7zF/resource.rc
index 365c0637..18ec9549 100755
--- a/CPP/7zip/Bundles/Format7zF/resource.rc
+++ b/CPP/7zip/Bundles/Format7zF/resource.rc
@@ -19,9 +19,10 @@ MY_VERSION_INFO_DLL("7z Standalone Plugin", "7za")
13 ICON "../../Archive/Tar/tar.ico"
14 ICON "../../Archive/GZip/gz.ico"
15 ICON "../../Archive/Wim/wim.ico"
+16 ICON "../../Archive/Lzma/lzma.ico"
STRINGTABLE
BEGIN
- 100 "7z:0 zip:1 bz2:2 bzip2:2 tbz2:2 tbz:2 rar:3 arj:4 z:5 taz:5 lzh:6 lha:6 cab:7 iso:8 split:9 rpm:10 deb:11 cpio:12 tar:13 gz:14 gzip:14 tgz:14 tpz:14 wim:15 swm:15"
+ 100 "7z:0 zip:1 bz2:2 bzip2:2 tbz2:2 tbz:2 rar:3 arj:4 z:5 taz:5 lzh:6 lha:6 cab:7 iso:8 split:9 rpm:10 deb:11 cpio:12 tar:13 gz:14 gzip:14 tgz:14 tpz:14 wim:15 swm:15 lzma:16"
END
diff --git a/CPP/7zip/Bundles/Format7zR/makefile b/CPP/7zip/Bundles/Format7zR/makefile
index 6e96a8a2..7fd28ad5 100755
--- a/CPP/7zip/Bundles/Format7zR/makefile
+++ b/CPP/7zip/Bundles/Format7zR/makefile
@@ -77,14 +77,10 @@ COMPRESS_OBJS = \
$O\CodecExports.obj \
BRANCH_OPT_OBJS = \
- $O\BranchCoder.obj \
$O\x86.obj \
$O\x86_2.obj \
- $O\ARM.obj \
- $O\ARMThumb.obj \
- $O\IA64.obj \
- $O\PPC.obj \
- $O\SPARC.obj \
+ $O\BranchCoder.obj \
+ $O\BranchMisc.obj \
$O\BranchRegister.obj \
$O\BCJRegister.obj \
$O\BCJ2Register.obj \
@@ -97,32 +93,23 @@ COPY_OBJS = \
$O\CopyCoder.obj \
$O\CopyRegister.obj \
-LZ_OBJS = \
- $O\LZOutWindow.obj \
-
LZMA_OPT_OBJS = \
$O\LZMADecoder.obj \
$O\LZMAEncoder.obj \
$O\LZMARegister.obj \
C_OBJS = \
- $O\Alloc.obj \
$O\7zCrc.obj \
- $O\Sort.obj \
+ $O\Alloc.obj \
+ $O\Bra.obj \
+ $O\Bra86.obj \
+ $O\BraIA64.obj \
+ $O\LzFind.obj \
+ $O\LzFindMt.obj \
+ $O\LzmaDec.obj \
+ $O\LzmaEnc.obj \
$O\Threads.obj \
-C_LZ_OBJS = \
- $O\MatchFinder.obj \
- $O\MatchFinderMt.obj \
-
-C_BRANCH_OBJS = \
- $O\BranchARM.obj \
- $O\BranchARMThumb.obj \
- $O\BranchIA64.obj \
- $O\BranchPPC.obj \
- $O\BranchSPARC.obj \
- $O\BranchX86.obj \
-
OBJS = \
$O\StdAfx.obj \
$(CONSOLE_OBJS) \
@@ -139,13 +126,9 @@ OBJS = \
$(SWAP_OPT_OBJS) \
$(COPY_OBJS) \
$(DEFLATE_OPT_OBJS) \
- $(LZ_OBJS) \
$(LZMA_OPT_OBJS) \
$(PPMD_OPT_OBJS) \
$(C_OBJS) \
- $(C_LZ_OBJS) \
- $(C_BRANCH_OBJS) \
- $O\RangeCoderBit.obj \
$O\resource.res
@@ -173,16 +156,8 @@ $(SWAP_OPT_OBJS): ../../Compress/ByteSwap/$(*B).cpp
$(COMPL_O2)
$(COPY_OBJS): ../../Compress/Copy/$(*B).cpp
$(COMPL)
-$(LZ_OBJS): ../../Compress/LZ/$(*B).cpp
- $(COMPL)
$(LZMA_OPT_OBJS): ../../Compress/LZMA/$(*B).cpp
$(COMPL_O2)
-$O\RangeCoderBit.obj: ../../Compress/RangeCoder/$(*B).cpp
- $(COMPL)
$(C_OBJS): ../../../../C/$(*B).c
$(COMPL_O2)
-$(C_LZ_OBJS): ../../../../C/Compress/Lz/$(*B).c
- $(COMPL_O2)
-$(C_BRANCH_OBJS): ../../../../C/Compress/Branch/$(*B).c
- $(COMPL_O2)
diff --git a/CPP/7zip/Bundles/SFXCon/SFXCon.dsp b/CPP/7zip/Bundles/SFXCon/SFXCon.dsp
index a0d21d0e..e272d88d 100755
--- a/CPP/7zip/Bundles/SFXCon/SFXCon.dsp
+++ b/CPP/7zip/Bundles/SFXCon/SFXCon.dsp
@@ -374,14 +374,6 @@ SOURCE=..\..\Crypto\AES\MyAES.h
SOURCE=..\..\Crypto\Hash\RotateDefs.h
# End Source File
-# Begin Source File
-
-SOURCE=..\..\Crypto\Hash\Sha256.cpp
-# End Source File
-# Begin Source File
-
-SOURCE=..\..\Crypto\Hash\Sha256.h
-# End Source File
# End Group
# End Group
# Begin Group "Windows"
@@ -735,53 +727,59 @@ SOURCE=..\..\UI\Common\PropIDUtils.h
# Begin Group "C"
# PROP Default_Filter ""
-# Begin Group "C Branch"
+# Begin Source File
-# PROP Default_Filter ""
+SOURCE=..\..\..\..\C\7zCrc.c
+# SUBTRACT CPP /YX /Yc /Yu
+# End Source File
# Begin Source File
-SOURCE=..\..\..\..\C\Compress\Branch\BranchTypes.h
+SOURCE=..\..\..\..\C\7zCrc.h
# End Source File
# Begin Source File
-SOURCE=..\..\..\..\C\Compress\Branch\BranchX86.c
+SOURCE=..\..\..\..\C\Aes.c
# SUBTRACT CPP /YX /Yc /Yu
# End Source File
# Begin Source File
-SOURCE=..\..\..\..\C\Compress\Branch\BranchX86.h
+SOURCE=..\..\..\..\C\Aes.h
# End Source File
-# End Group
-# Begin Group "C Crypto"
-
-# PROP Default_Filter ""
# Begin Source File
-SOURCE=..\..\..\..\C\Crypto\Aes.c
+SOURCE=..\..\..\..\C\Alloc.c
# SUBTRACT CPP /YX /Yc /Yu
# End Source File
# Begin Source File
-SOURCE=..\..\..\..\C\Crypto\Aes.h
+SOURCE=..\..\..\..\C\Alloc.h
# End Source File
-# End Group
# Begin Source File
-SOURCE=..\..\..\..\C\7zCrc.c
+SOURCE=..\..\..\..\C\Bra.h
+# End Source File
+# Begin Source File
+
+SOURCE=..\..\..\..\C\Bra86.c
# SUBTRACT CPP /YX /Yc /Yu
# End Source File
# Begin Source File
-SOURCE=..\..\..\..\C\7zCrc.h
+SOURCE=..\..\..\..\C\LzmaDec.c
+# SUBTRACT CPP /YX /Yc /Yu
# End Source File
# Begin Source File
-SOURCE=..\..\..\..\C\Alloc.c
+SOURCE=..\..\..\..\C\LzmaDec.h
+# End Source File
+# Begin Source File
+
+SOURCE=..\..\..\..\C\Sha256.c
# SUBTRACT CPP /YX /Yc /Yu
# End Source File
# Begin Source File
-SOURCE=..\..\..\..\C\Alloc.h
+SOURCE=..\..\..\..\C\Sha256.h
# End Source File
# Begin Source File
diff --git a/CPP/7zip/Bundles/SFXCon/makefile b/CPP/7zip/Bundles/SFXCon/makefile
index dbe07baa..c32b11cd 100755
--- a/CPP/7zip/Bundles/SFXCon/makefile
+++ b/CPP/7zip/Bundles/SFXCon/makefile
@@ -81,9 +81,9 @@ AR_COMMON_OBJS = \
$O\7zRegister.obj \
BRANCH_OPT_OBJS = \
- $O\BranchCoder.obj \
$O\x86.obj \
$O\x86_2.obj \
+ $O\BranchCoder.obj \
$O\BCJRegister.obj \
$O\BCJ2Register.obj \
@@ -109,18 +109,13 @@ PPMD_OPT_OBJS = \
AES_OPT_OBJS = \
$O\MyAES.obj \
-CRYPTO_HASH_OBJS = \
- $O\Sha256.obj \
-
C_OBJS = \
$O\Alloc.obj \
+ $O\Bra86.obj \
+ $O\LzmaDec.obj \
$O\Threads.obj \
-
-C_BRANCH_OBJS = \
- $O\BranchX86.obj \
-
-C_CRYPTO = \
$O\Aes.obj \
+ $O\Sha256.obj \
!include "../../Crc2.mak"
@@ -141,10 +136,7 @@ OBJS = \
$(PPMD_OPT_OBJS) \
$(7ZAES_OPT_OBJS) \
$(AES_OPT_OBJS) \
- $(CRYPTO_HASH_OBJS) \
$(C_OBJS) \
- $(C_BRANCH_OBJS) \
- $(C_CRYPTO) \
$(CRC_OBJS) \
$O\resource.res
@@ -184,13 +176,7 @@ $(AES_OPT_OBJS): ../../Crypto/AES/$(*B).cpp
$(COMPL)
$(7ZAES_OPT_OBJS): ../../Crypto/7zAES/$(*B).cpp
$(COMPL)
-$(CRYPTO_HASH_OBJS): ../../Crypto/Hash/$(*B).cpp
- $(COMPL)
$(C_OBJS): ../../../../C/$(*B).c
- $(COMPL_O1)
-$(C_BRANCH_OBJS): ../../../../C/Compress/Branch/$(*B).c
- $(COMPL_O1)
-$(C_CRYPTO): ../../../../C/Crypto/$(*B).c
- $(COMPL_O1)
+ $(COMPL_O2)
!include "../../Crc.mak"
diff --git a/CPP/7zip/Bundles/SFXSetup/SFXSetup.dsp b/CPP/7zip/Bundles/SFXSetup/SFXSetup.dsp
index 1fd348bc..3b0117a1 100755
--- a/CPP/7zip/Bundles/SFXSetup/SFXSetup.dsp
+++ b/CPP/7zip/Bundles/SFXSetup/SFXSetup.dsp
@@ -687,36 +687,41 @@ SOURCE=..\..\UI\FileManager\FormatUtils.h
# Begin Group "C"
# PROP Default_Filter ""
-# Begin Group "C Branch"
-
-# PROP Default_Filter ""
# Begin Source File
-SOURCE=..\..\..\..\C\Compress\Branch\BranchX86.c
+SOURCE=..\..\..\..\C\7zCrc.c
# SUBTRACT CPP /YX /Yc /Yu
# End Source File
# Begin Source File
-SOURCE=..\..\..\..\C\Compress\Branch\BranchX86.h
+SOURCE=..\..\..\..\C\7zCrc.h
# End Source File
-# End Group
# Begin Source File
-SOURCE=..\..\..\..\C\7zCrc.c
+SOURCE=..\..\..\..\C\Alloc.c
# SUBTRACT CPP /YX /Yc /Yu
# End Source File
# Begin Source File
-SOURCE=..\..\..\..\C\7zCrc.h
+SOURCE=..\..\..\..\C\Alloc.h
# End Source File
# Begin Source File
-SOURCE=..\..\..\..\C\Alloc.c
+SOURCE=..\..\..\..\C\Bra.h
+# End Source File
+# Begin Source File
+
+SOURCE=..\..\..\..\C\Bra86.c
# SUBTRACT CPP /YX /Yc /Yu
# End Source File
# Begin Source File
-SOURCE=..\..\..\..\C\Alloc.h
+SOURCE=..\..\..\..\C\LzmaDec.c
+# SUBTRACT CPP /YX /Yc /Yu
+# End Source File
+# Begin Source File
+
+SOURCE=..\..\..\..\C\LzmaDec.h
# End Source File
# Begin Source File
diff --git a/CPP/7zip/Bundles/SFXSetup/makefile b/CPP/7zip/Bundles/SFXSetup/makefile
index 10731a93..274730cd 100755
--- a/CPP/7zip/Bundles/SFXSetup/makefile
+++ b/CPP/7zip/Bundles/SFXSetup/makefile
@@ -83,9 +83,9 @@ AR_COMMON_OBJS = \
$O\7zRegister.obj \
BRANCH_OPT_OBJS = \
- $O\BranchCoder.obj \
$O\x86.obj \
$O\x86_2.obj \
+ $O\BranchCoder.obj \
$O\BCJRegister.obj \
$O\BCJ2Register.obj \
@@ -102,11 +102,10 @@ LZMA_OPT_OBJS = \
C_OBJS = \
$O\Alloc.obj \
+ $O\Bra86.obj \
+ $O\LzmaDec.obj \
$O\Threads.obj \
-C_BRANCH_OBJS = \
- $O\BranchX86.obj \
-
!include "../../Crc2.mak"
OBJS = \
@@ -127,7 +126,6 @@ OBJS = \
$(LZMA_OPT_OBJS) \
$O\MyMessages.obj \
$(C_OBJS) \
- $(C_BRANCH_OBJS) \
$(CRC_OBJS) \
$O\resource.res
@@ -169,8 +167,6 @@ $O\MyMessages.obj: ../../UI/Explorer/MyMessages.cpp
$(COMPL)
$(C_OBJS): ../../../../C/$(*B).c
- $(COMPL_O1)
-$(C_BRANCH_OBJS): ../../../../C/Compress/Branch/$(*B).c
- $(COMPL_O1)
+ $(COMPL_O2)
!include "../../Crc.mak"
diff --git a/CPP/7zip/Bundles/SFXWin/Main.cpp b/CPP/7zip/Bundles/SFXWin/Main.cpp
index 39ca5306..44f37560 100755
--- a/CPP/7zip/Bundles/SFXWin/Main.cpp
+++ b/CPP/7zip/Bundles/SFXWin/Main.cpp
@@ -117,6 +117,8 @@ int APIENTRY WinMain2()
*/
if (result == S_OK)
{
+ if (ecs->Messages.Size() > 0 || ecs->NumArchiveErrors != 0)
+ return NExitCode::kFatalError;
return 0;
}
if (result == E_ABORT)
diff --git a/CPP/7zip/Bundles/SFXWin/SFXWin.dsp b/CPP/7zip/Bundles/SFXWin/SFXWin.dsp
index 70de7602..0a78fe4d 100755
--- a/CPP/7zip/Bundles/SFXWin/SFXWin.dsp
+++ b/CPP/7zip/Bundles/SFXWin/SFXWin.dsp
@@ -374,14 +374,6 @@ SOURCE=..\..\Crypto\7zAES\MySHA256.h
SOURCE=..\..\Crypto\Hash\RotateDefs.h
# End Source File
-# Begin Source File
-
-SOURCE=..\..\Crypto\Hash\Sha256.cpp
-# End Source File
-# Begin Source File
-
-SOURCE=..\..\Crypto\Hash\Sha256.h
-# End Source File
# End Group
# End Group
# Begin Group "Dialogs"
@@ -835,49 +827,55 @@ SOURCE=..\..\UI\Explorer\MyMessages.h
# Begin Group "C"
# PROP Default_Filter ""
-# Begin Group "C Branch"
-
-# PROP Default_Filter ""
# Begin Source File
-SOURCE=..\..\..\..\C\Compress\Branch\BranchX86.c
+SOURCE=..\..\..\..\C\7zCrc.c
# SUBTRACT CPP /YX /Yc /Yu
# End Source File
# Begin Source File
-SOURCE=..\..\..\..\C\Compress\Branch\BranchX86.h
+SOURCE=..\..\..\..\C\7zCrc.h
# End Source File
-# End Group
-# Begin Group "C Crypto"
-
-# PROP Default_Filter ""
# Begin Source File
-SOURCE=..\..\..\..\C\Crypto\Aes.c
+SOURCE=..\..\..\..\C\Aes.c
# SUBTRACT CPP /YX /Yc /Yu
# End Source File
# Begin Source File
-SOURCE=..\..\..\..\C\Crypto\Aes.h
+SOURCE=..\..\..\..\C\Aes.h
# End Source File
-# End Group
# Begin Source File
-SOURCE=..\..\..\..\C\7zCrc.c
+SOURCE=..\..\..\..\C\Alloc.c
# SUBTRACT CPP /YX /Yc /Yu
# End Source File
# Begin Source File
-SOURCE=..\..\..\..\C\7zCrc.h
+SOURCE=..\..\..\..\C\Alloc.h
# End Source File
# Begin Source File
-SOURCE=..\..\..\..\C\Alloc.c
+SOURCE=..\..\..\..\C\Bra.h
+# End Source File
+# Begin Source File
+
+SOURCE=..\..\..\..\C\Bra86.c
# SUBTRACT CPP /YX /Yc /Yu
# End Source File
# Begin Source File
-SOURCE=..\..\..\..\C\Alloc.h
+SOURCE=..\..\..\..\C\LzmaDec.c
+# SUBTRACT CPP /YX /Yc /Yu
+# End Source File
+# Begin Source File
+
+SOURCE=..\..\..\..\C\LzmaDec.h
+# End Source File
+# Begin Source File
+
+SOURCE=..\..\..\..\C\Sha256.c
+# SUBTRACT CPP /YX /Yc /Yu
# End Source File
# Begin Source File
diff --git a/CPP/7zip/Bundles/SFXWin/makefile b/CPP/7zip/Bundles/SFXWin/makefile
index 55ebd8c6..a5f39559 100755
--- a/CPP/7zip/Bundles/SFXWin/makefile
+++ b/CPP/7zip/Bundles/SFXWin/makefile
@@ -90,9 +90,9 @@ AR_COMMON_OBJS = \
$O\7zRegister.obj \
BRANCH_OPT_OBJS = \
- $O\BranchCoder.obj \
$O\x86.obj \
$O\x86_2.obj \
+ $O\BranchCoder.obj \
$O\BCJRegister.obj \
$O\BCJ2Register.obj \
@@ -118,18 +118,13 @@ PPMD_OPT_OBJS = \
AES_OPT_OBJS = \
$O\MyAES.obj \
-CRYPTO_HASH_OBJS = \
- $O\Sha256.obj \
-
C_OBJS = \
$O\Alloc.obj \
+ $O\Bra86.obj \
+ $O\LzmaDec.obj \
$O\Threads.obj \
-
-C_BRANCH_OBJS = \
- $O\BranchX86.obj \
-
-C_CRYPTO = \
$O\Aes.obj \
+ $O\Sha256.obj \
!include "../../Crc2.mak"
@@ -150,14 +145,11 @@ OBJS = \
$(LZ_OBJS) \
$(LZMA_OPT_OBJS) \
$(PPMD_OPT_OBJS) \
- $(CRYPTO_HASH_OBJS) \
$(7ZAES_OPT_OBJS) \
$(AES_OPT_OBJS) \
$O\MyMessages.obj \
$(C_OBJS) \
- $(C_BRANCH_OBJS) \
$(CRC_OBJS) \
- $(C_CRYPTO) \
$O\resource.res
@@ -196,8 +188,6 @@ $(LZMA_OPT_OBJS): ../../Compress/LZMA/$(*B).cpp
$(PPMD_OPT_OBJS): ../../Compress/PPMD/$(*B).cpp
$(COMPL)
-$(CRYPTO_HASH_OBJS): ../../Crypto/Hash/$(*B).cpp
- $(COMPL)
$(7ZAES_OPT_OBJS): ../../Crypto/7zAES/$(*B).cpp
$(COMPL)
$(AES_OPT_OBJS): ../../Crypto/AES/$(*B).cpp
@@ -206,10 +196,6 @@ $(AES_OPT_OBJS): ../../Crypto/AES/$(*B).cpp
$O\MyMessages.obj: ../../UI/Explorer/MyMessages.cpp
$(COMPL)
$(C_OBJS): ../../../../C/$(*B).c
- $(COMPL_O1)
-$(C_BRANCH_OBJS): ../../../../C/Compress/Branch/$(*B).c
- $(COMPL_O1)
-$(C_CRYPTO): ../../../../C/Crypto/$(*B).c
- $(COMPL_O1)
+ $(COMPL_O2)
!include "../../Crc.mak"
diff --git a/CPP/7zip/Common/FileStreams.cpp b/CPP/7zip/Common/FileStreams.cpp
index bebcf14c..f1fa419f 100755
--- a/CPP/7zip/Common/FileStreams.cpp
+++ b/CPP/7zip/Common/FileStreams.cpp
@@ -18,7 +18,7 @@ static inline HRESULT ConvertBoolToHRESULT(bool result)
DWORD lastError = ::GetLastError();
if (lastError == 0)
return E_FAIL;
- return lastError;
+ return HRESULT_FROM_WIN32(lastError);
#else
return result ? S_OK: E_FAIL;
#endif
diff --git a/CPP/7zip/Common/FilterCoder.cpp b/CPP/7zip/Common/FilterCoder.cpp
index fd89d0e1..58690c3d 100755
--- a/CPP/7zip/Common/FilterCoder.cpp
+++ b/CPP/7zip/Common/FilterCoder.cpp
@@ -30,11 +30,8 @@ HRESULT CFilterCoder::WriteWithLimit(ISequentialOutStream *outStream, UInt32 siz
if (size > remSize)
size = (UInt32)remSize;
}
- UInt32 processedSize = 0;
- RINOK(WriteStream(outStream, _buffer, size, &processedSize));
- if (size != processedSize)
- return E_FAIL;
- _nowPos64 += processedSize;
+ RINOK(WriteStream(outStream, _buffer, size));
+ _nowPos64 += size;
return S_OK;
}
@@ -51,12 +48,12 @@ STDMETHODIMP CFilterCoder::Code(ISequentialInStream *inStream,
while(NeedMore())
{
- UInt32 processedSize;
+ size_t processedSize = kBufferSize - bufferPos;
// Change it: It can be optimized using ReadPart
- RINOK(ReadStream(inStream, _buffer + bufferPos, kBufferSize - bufferPos, &processedSize));
+ RINOK(ReadStream(inStream, _buffer + bufferPos, &processedSize));
- UInt32 endPos = bufferPos + processedSize;
+ UInt32 endPos = bufferPos + (UInt32)processedSize;
bufferPos = Filter->Filter(_buffer, endPos);
if (bufferPos > endPos)
@@ -149,10 +146,7 @@ STDMETHODIMP CFilterCoder::Flush()
if (Filter->Filter(_buffer, endPos) != endPos)
return E_FAIL;
}
- UInt32 processedSize;
- RINOK(WriteStream(_outStream, _buffer, _bufferPos, &processedSize));
- if (_bufferPos != processedSize)
- return E_FAIL;
+ RINOK(WriteStream(_outStream, _buffer, _bufferPos));
_bufferPos = 0;
}
CMyComPtr<IOutStreamFlush> flush;
@@ -196,11 +190,9 @@ STDMETHODIMP CFilterCoder::Read(void *data, UInt32 size, UInt32 *processedSize)
_buffer[i] = _buffer[i + _convertedPosEnd];
_bufferPos = i;
_convertedPosBegin = _convertedPosEnd = 0;
- UInt32 processedSizeTemp;
- UInt32 size0 = kBufferSize - _bufferPos;
- // Optimize it:
- RINOK(ReadStream(_inStream, _buffer + _bufferPos, size0, &processedSizeTemp));
- _bufferPos = _bufferPos + processedSizeTemp;
+ size_t processedSizeTemp = kBufferSize - _bufferPos;
+ RINOK(ReadStream(_inStream, _buffer + _bufferPos, &processedSizeTemp));
+ _bufferPos = _bufferPos + (UInt32)processedSizeTemp;
_convertedPosEnd = Filter->Filter(_buffer, _bufferPos);
if (_convertedPosEnd == 0)
{
diff --git a/CPP/7zip/Common/InOutTempBuffer.cpp b/CPP/7zip/Common/InOutTempBuffer.cpp
index ffaed32c..4cc0b2f2 100755
--- a/CPP/7zip/Common/InOutTempBuffer.cpp
+++ b/CPP/7zip/Common/InOutTempBuffer.cpp
@@ -92,7 +92,7 @@ HRESULT CInOutTempBuffer::WriteToStream(ISequentialOutStream *stream)
if (_currentPositionInBuffer < _bufferPosition)
{
UInt32 sizeToWrite = _bufferPosition - _currentPositionInBuffer;
- RINOK(WriteStream(stream, _buffer + _currentPositionInBuffer, sizeToWrite, NULL));
+ RINOK(WriteStream(stream, _buffer + _currentPositionInBuffer, sizeToWrite));
_currentPositionInBuffer += sizeToWrite;
}
if (!_tmpFileCreated)
@@ -104,7 +104,7 @@ HRESULT CInOutTempBuffer::WriteToStream(ISequentialOutStream *stream)
return E_FAIL;
if (localProcessedSize == 0)
return S_OK;
- RINOK(WriteStream(stream, _buffer, localProcessedSize, NULL));
+ RINOK(WriteStream(stream, _buffer, localProcessedSize));
}
}
diff --git a/CPP/7zip/Common/MemBlocks.cpp b/CPP/7zip/Common/MemBlocks.cpp
index 15702957..53f55242 100755
--- a/CPP/7zip/Common/MemBlocks.cpp
+++ b/CPP/7zip/Common/MemBlocks.cpp
@@ -125,13 +125,10 @@ HRESULT CMemBlocks::WriteToStream(size_t blockSize, ISequentialOutStream *outStr
UInt32 curSize = (UInt32)blockSize;
if (totalSize < curSize)
curSize = (UInt32)totalSize;
- UInt32 processedSize;
if (blockIndex >= Blocks.Size())
return E_FAIL;
- RINOK(WriteStream(outStream, Blocks[blockIndex], curSize, &processedSize));
- if (processedSize != curSize)
- return E_FAIL;
- totalSize -= processedSize;
+ RINOK(WriteStream(outStream, Blocks[blockIndex], curSize));
+ totalSize -= curSize;
}
return S_OK;
}
diff --git a/CPP/7zip/Common/StreamObjects.cpp b/CPP/7zip/Common/StreamObjects.cpp
index 32f8f306..95d1c878 100755
--- a/CPP/7zip/Common/StreamObjects.cpp
+++ b/CPP/7zip/Common/StreamObjects.cpp
@@ -8,11 +8,13 @@
STDMETHODIMP CSequentialInStreamImp::Read(void *data, UInt32 size, UInt32 *processedSize)
{
- UInt32 numBytesToRead = (UInt32)(MyMin(_pos + size, _size) - _pos);
- memmove(data, _dataPointer + _pos, numBytesToRead);
- _pos += numBytesToRead;
- if(processedSize != NULL)
- *processedSize = numBytesToRead;
+ size_t rem = _size - _pos;
+ if (size < rem)
+ rem = (size_t)size;
+ memcpy(data, _dataPointer + _pos, rem);
+ _pos += rem;
+ if (processedSize != NULL)
+ *processedSize = (UInt32)rem;
return S_OK;
}
@@ -21,13 +23,13 @@ void CWriteBuffer::Write(const void *data, size_t size)
{
size_t newCapacity = _size + size;
_buffer.EnsureCapacity(newCapacity);
- memmove(_buffer + _size, data, size);
+ memcpy(_buffer + _size, data, size);
_size += size;
}
STDMETHODIMP CSequentialOutStreamImp::Write(const void *data, UInt32 size, UInt32 *processedSize)
{
- _writeBuffer.Write(data, size);
+ _writeBuffer.Write(data, (size_t)size);
if(processedSize != NULL)
*processedSize = size;
return S_OK;
@@ -35,16 +37,14 @@ STDMETHODIMP CSequentialOutStreamImp::Write(const void *data, UInt32 size, UInt3
STDMETHODIMP CSequentialOutStreamImp2::Write(const void *data, UInt32 size, UInt32 *processedSize)
{
- UInt32 newSize = size;
- if (_pos + size > _size)
- newSize = (UInt32)(_size - _pos);
- memmove(_buffer + _pos, data, newSize);
- if(processedSize != NULL)
- *processedSize = newSize;
- _pos += newSize;
- if (newSize != size)
- return E_FAIL;
- return S_OK;
+ size_t rem = _size - _pos;
+ if (size < rem)
+ rem = (size_t)size;
+ memcpy(_buffer + _pos, data, rem);
+ _pos += rem;
+ if (processedSize != NULL)
+ *processedSize = (UInt32)rem;
+ return (rem == size ? S_OK : E_FAIL);
}
STDMETHODIMP CSequentialInStreamSizeCount::Read(void *data, UInt32 size, UInt32 *processedSize)
diff --git a/CPP/7zip/Common/StreamUtils.cpp b/CPP/7zip/Common/StreamUtils.cpp
index 1d951271..9cde2c40 100755
--- a/CPP/7zip/Common/StreamUtils.cpp
+++ b/CPP/7zip/Common/StreamUtils.cpp
@@ -2,20 +2,21 @@
#include "StdAfx.h"
-#include "../../Common/MyCom.h"
#include "StreamUtils.h"
-HRESULT ReadStream(ISequentialInStream *stream, void *data, UInt32 size, UInt32 *processedSize)
+static const UInt32 kBlockSize = ((UInt32)1 << 31);
+
+HRESULT ReadStream(ISequentialInStream *stream, void *data, size_t *processedSize)
{
- if (processedSize != 0)
- *processedSize = 0;
- while(size != 0)
+ size_t size = *processedSize;
+ *processedSize = 0;
+ while (size != 0)
{
+ UInt32 curSize = (size < kBlockSize) ? (UInt32)size : kBlockSize;
UInt32 processedSizeLoc;
- HRESULT res = stream->Read(data, size, &processedSizeLoc);
- if (processedSize != 0)
- *processedSize += processedSizeLoc;
- data = (Byte *)((Byte *)data + processedSizeLoc);
+ HRESULT res = stream->Read(data, curSize, &processedSizeLoc);
+ *processedSize += processedSizeLoc;
+ data = (void *)((Byte *)data + processedSizeLoc);
size -= processedSizeLoc;
RINOK(res);
if (processedSizeLoc == 0)
@@ -24,16 +25,27 @@ HRESULT ReadStream(ISequentialInStream *stream, void *data, UInt32 size, UInt32
return S_OK;
}
-HRESULT WriteStream(ISequentialOutStream *stream, const void *data, UInt32 size, UInt32 *processedSize)
+HRESULT ReadStream_FALSE(ISequentialInStream *stream, void *data, size_t size)
+{
+ size_t processedSize = size;
+ RINOK(ReadStream(stream, data, &processedSize));
+ return (size == processedSize) ? S_OK : S_FALSE;
+}
+
+HRESULT ReadStream_FAIL(ISequentialInStream *stream, void *data, size_t size)
+{
+ size_t processedSize = size;
+ RINOK(ReadStream(stream, data, &processedSize));
+ return (size == processedSize) ? S_OK : E_FAIL;
+}
+
+HRESULT WriteStream(ISequentialOutStream *stream, const void *data, size_t size)
{
- if (processedSize != 0)
- *processedSize = 0;
- while(size != 0)
+ while (size != 0)
{
+ UInt32 curSize = (size < kBlockSize) ? (UInt32)size : kBlockSize;
UInt32 processedSizeLoc;
- HRESULT res = stream->Write(data, size, &processedSizeLoc);
- if (processedSize != 0)
- *processedSize += processedSizeLoc;
+ HRESULT res = stream->Write(data, curSize, &processedSizeLoc);
data = (const void *)((const Byte *)data + processedSizeLoc);
size -= processedSizeLoc;
RINOK(res);
diff --git a/CPP/7zip/Common/StreamUtils.h b/CPP/7zip/Common/StreamUtils.h
index 59f88733..f1cfd184 100755
--- a/CPP/7zip/Common/StreamUtils.h
+++ b/CPP/7zip/Common/StreamUtils.h
@@ -5,7 +5,9 @@
#include "../IStream.h"
-HRESULT ReadStream(ISequentialInStream *stream, void *data, UInt32 size, UInt32 *processedSize);
-HRESULT WriteStream(ISequentialOutStream *stream, const void *data, UInt32 size, UInt32 *processedSize);
+HRESULT ReadStream(ISequentialInStream *stream, void *data, size_t *size);
+HRESULT ReadStream_FALSE(ISequentialInStream *stream, void *data, size_t size);
+HRESULT ReadStream_FAIL(ISequentialInStream *stream, void *data, size_t size);
+HRESULT WriteStream(ISequentialOutStream *stream, const void *data, size_t size);
#endif
diff --git a/CPP/7zip/Common/VirtThread.cpp b/CPP/7zip/Common/VirtThread.cpp
index 3567f98e..f12581ad 100755
--- a/CPP/7zip/Common/VirtThread.cpp
+++ b/CPP/7zip/Common/VirtThread.cpp
@@ -17,7 +17,7 @@ static THREAD_FUNC_DECL CoderThread(void *p)
}
}
-HRes CVirtThread::Create()
+WRes CVirtThread::Create()
{
RINOK(StartEvent.CreateIfNotCreated());
RINOK(FinishedEvent.CreateIfNotCreated());
diff --git a/CPP/7zip/Common/VirtThread.h b/CPP/7zip/Common/VirtThread.h
index 62c055b6..604b090b 100755
--- a/CPP/7zip/Common/VirtThread.h
+++ b/CPP/7zip/Common/VirtThread.h
@@ -14,7 +14,7 @@ struct CVirtThread
bool ExitEvent;
~CVirtThread();
- HRes Create();
+ WRes Create();
void Start();
void WaitFinish() { FinishedEvent.Lock(); }
virtual void Execute() = 0;
diff --git a/CPP/7zip/Compress/Arj/ArjDecoder1.cpp b/CPP/7zip/Compress/Arj/ArjDecoder1.cpp
index dda3721a..df859971 100755
--- a/CPP/7zip/Compress/Arj/ArjDecoder1.cpp
+++ b/CPP/7zip/Compress/Arj/ArjDecoder1.cpp
@@ -237,7 +237,7 @@ UInt32 CCoder::decode_p()
}
-STDMETHODIMP CCoder::CodeReal(ISequentialInStream *inStream,
+HRESULT CCoder::CodeReal(ISequentialInStream *inStream,
ISequentialOutStream *outStream, const UInt64 * /* inSize */, const UInt64 *outSize,
ICompressProgressInfo *progress)
{
@@ -297,7 +297,7 @@ STDMETHODIMP CCoder::CodeReal(ISequentialInStream *inStream,
UInt32 len = number - 256 + kMatchMinLen;
UInt32 distance = decode_p();
if (distance >= pos)
- throw "data error";
+ return S_FALSE;
m_OutWindowStream.CopyBlock(distance, len);
pos += len;
}
diff --git a/CPP/7zip/Compress/Arj/ArjDecoder1.h b/CPP/7zip/Compress/Arj/ArjDecoder1.h
index 434a0a41..b337ec72 100755
--- a/CPP/7zip/Compress/Arj/ArjDecoder1.h
+++ b/CPP/7zip/Compress/Arj/ArjDecoder1.h
@@ -86,13 +86,11 @@ class CCoder :
UInt32 decode_c();
UInt32 decode_p();
-public:
-
- MY_UNKNOWN_IMP
-
- STDMETHOD(CodeReal)(ISequentialInStream *inStream,
+ HRESULT CodeReal(ISequentialInStream *inStream,
ISequentialOutStream *outStream, const UInt64 *inSize, const UInt64 *outSize,
ICompressProgressInfo *progress);
+public:
+ MY_UNKNOWN_IMP
STDMETHOD(Code)(ISequentialInStream *inStream,
ISequentialOutStream *outStream, const UInt64 *inSize, const UInt64 *outSize,
diff --git a/CPP/7zip/Compress/Arj/ArjDecoder2.cpp b/CPP/7zip/Compress/Arj/ArjDecoder2.cpp
index 24c101d1..a0eca445 100755
--- a/CPP/7zip/Compress/Arj/ArjDecoder2.cpp
+++ b/CPP/7zip/Compress/Arj/ArjDecoder2.cpp
@@ -12,7 +12,7 @@ static const UInt32 kHistorySize = 26624;
// static const UInt32 kMatchMaxLen = 256;
static const UInt32 kMatchMinLen = 3;
-STDMETHODIMP CCoder::CodeReal(ISequentialInStream *inStream,
+HRESULT CCoder::CodeReal(ISequentialInStream *inStream,
ISequentialOutStream *outStream, const UInt64 * /* inSize */, const UInt64 *outSize,
ICompressProgressInfo * /* progress */)
{
@@ -71,7 +71,7 @@ STDMETHODIMP CCoder::CodeReal(ISequentialInStream *inStream,
if (width != 0)
distance += m_InBitStream.ReadBits(width);
if (distance >= pos)
- throw "data error";
+ return S_FALSE;
m_OutWindowStream.CopyBlock(distance, len);
pos += len;
}
diff --git a/CPP/7zip/Compress/Arj/ArjDecoder2.h b/CPP/7zip/Compress/Arj/ArjDecoder2.h
index 7a33f6bd..67a54eba 100755
--- a/CPP/7zip/Compress/Arj/ArjDecoder2.h
+++ b/CPP/7zip/Compress/Arj/ArjDecoder2.h
@@ -47,12 +47,11 @@ class CCoder :
};
friend class CCoderReleaser;
-public:
- MY_UNKNOWN_IMP
-
- STDMETHOD(CodeReal)(ISequentialInStream *inStream,
+ HRESULT CodeReal(ISequentialInStream *inStream,
ISequentialOutStream *outStream, const UInt64 *inSize, const UInt64 *outSize,
ICompressProgressInfo *progress);
+public:
+ MY_UNKNOWN_IMP
STDMETHOD(Code)(ISequentialInStream *inStream,
ISequentialOutStream *outStream, const UInt64 *inSize, const UInt64 *outSize,
diff --git a/CPP/7zip/Compress/BZip2/BZip2.dsp b/CPP/7zip/Compress/BZip2/BZip2.dsp
deleted file mode 100755
index e26819a0..00000000
--- a/CPP/7zip/Compress/BZip2/BZip2.dsp
+++ /dev/null
@@ -1,316 +0,0 @@
-# Microsoft Developer Studio Project File - Name="BZip2" - Package Owner=<4>
-# Microsoft Developer Studio Generated Build File, Format Version 6.00
-# ** DO NOT EDIT **
-
-# TARGTYPE "Win32 (x86) Dynamic-Link Library" 0x0102
-
-CFG=BZip2 - Win32 Debug
-!MESSAGE This is not a valid makefile. To build this project using NMAKE,
-!MESSAGE use the Export Makefile command and run
-!MESSAGE
-!MESSAGE NMAKE /f "BZip2.mak".
-!MESSAGE
-!MESSAGE You can specify a configuration when running NMAKE
-!MESSAGE by defining the macro CFG on the command line. For example:
-!MESSAGE
-!MESSAGE NMAKE /f "BZip2.mak" CFG="BZip2 - Win32 Debug"
-!MESSAGE
-!MESSAGE Possible choices for configuration are:
-!MESSAGE
-!MESSAGE "BZip2 - Win32 Release" (based on "Win32 (x86) Dynamic-Link Library")
-!MESSAGE "BZip2 - Win32 Debug" (based on "Win32 (x86) Dynamic-Link Library")
-!MESSAGE
-
-# Begin Project
-# PROP AllowPerConfigDependencies 0
-# PROP Scc_ProjName ""
-# PROP Scc_LocalPath ""
-CPP=cl.exe
-MTL=midl.exe
-RSC=rc.exe
-
-!IF "$(CFG)" == "BZip2 - Win32 Release"
-
-# PROP BASE Use_MFC 0
-# PROP BASE Use_Debug_Libraries 0
-# PROP BASE Output_Dir "Release"
-# PROP BASE Intermediate_Dir "Release"
-# PROP BASE Target_Dir ""
-# PROP Use_MFC 0
-# PROP Use_Debug_Libraries 0
-# PROP Output_Dir "Release"
-# PROP Intermediate_Dir "Release"
-# PROP Ignore_Export_Lib 1
-# PROP Target_Dir ""
-# ADD BASE CPP /nologo /MT /W3 /GX /O2 /D "WIN32" /D "NDEBUG" /D "_WINDOWS" /D "_MBCS" /D "_USRDLL" /D "BZIP2_EXPORTS" /YX /FD /c
-# ADD CPP /nologo /Gz /MD /W3 /GX /O1 /I "..\..\..\\" /D "NDEBUG" /D "BZ_NO_STDIO" /D "WIN32" /D "_WINDOWS" /D "_MBCS" /D "_USRDLL" /D "BZIP2_EXPORTS" /D "COMPRESS_BZIP2_MT" /Yu"StdAfx.h" /FD /c
-# ADD BASE MTL /nologo /D "NDEBUG" /mktyplib203 /win32
-# ADD MTL /nologo /D "NDEBUG" /mktyplib203 /win32
-# ADD BASE RSC /l 0x419 /d "NDEBUG"
-# ADD RSC /l 0x419 /d "NDEBUG"
-BSC32=bscmake.exe
-# ADD BASE BSC32 /nologo
-# ADD BSC32 /nologo
-LINK32=link.exe
-# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /dll /machine:I386
-# ADD LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /dll /machine:I386 /out:"C:\Program Files\7-Zip\Codecs\BZip2.dll" /opt:NOWIN98
-# SUBTRACT LINK32 /pdb:none
-
-!ELSEIF "$(CFG)" == "BZip2 - Win32 Debug"
-
-# PROP BASE Use_MFC 0
-# PROP BASE Use_Debug_Libraries 1
-# PROP BASE Output_Dir "Debug"
-# PROP BASE Intermediate_Dir "Debug"
-# PROP BASE Target_Dir ""
-# PROP Use_MFC 0
-# PROP Use_Debug_Libraries 1
-# PROP Output_Dir "Debug"
-# PROP Intermediate_Dir "Debug"
-# PROP Ignore_Export_Lib 1
-# PROP Target_Dir ""
-# ADD BASE CPP /nologo /MTd /W3 /Gm /GX /ZI /Od /D "WIN32" /D "_DEBUG" /D "_WINDOWS" /D "_MBCS" /D "_USRDLL" /D "BZIP2_EXPORTS" /YX /FD /GZ /c
-# ADD CPP /nologo /Gz /MDd /W3 /Gm /GX /ZI /Od /I "..\..\..\\" /D "_DEBUG" /D "WIN32" /D "_WINDOWS" /D "_MBCS" /D "_USRDLL" /D "BZIP2_EXPORTS" /D "COMPRESS_BZIP2_MT" /Yu"StdAfx.h" /FD /GZ /c
-# ADD BASE MTL /nologo /D "_DEBUG" /mktyplib203 /win32
-# ADD MTL /nologo /D "_DEBUG" /mktyplib203 /win32
-# ADD BASE RSC /l 0x419 /d "_DEBUG"
-# ADD RSC /l 0x419 /d "_DEBUG"
-BSC32=bscmake.exe
-# ADD BASE BSC32 /nologo
-# ADD BSC32 /nologo
-LINK32=link.exe
-# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /dll /debug /machine:I386 /pdbtype:sept
-# ADD LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /dll /debug /machine:I386 /out:"C:\Program Files\7-Zip\Codecs\BZip2.dll" /pdbtype:sept
-
-!ENDIF
-
-# Begin Target
-
-# Name "BZip2 - Win32 Release"
-# Name "BZip2 - Win32 Debug"
-# Begin Group "Spec"
-
-# PROP Default_Filter ""
-# Begin Source File
-
-SOURCE=..\Codec.def
-# End Source File
-# Begin Source File
-
-SOURCE=..\CodecExports.cpp
-# End Source File
-# Begin Source File
-
-SOURCE=..\DllExports.cpp
-# End Source File
-# Begin Source File
-
-SOURCE=.\resource.rc
-# End Source File
-# Begin Source File
-
-SOURCE=.\StdAfx.cpp
-# ADD CPP /Yc"StdAfx.h"
-# End Source File
-# Begin Source File
-
-SOURCE=.\StdAfx.h
-# End Source File
-# End Group
-# Begin Group "Common"
-
-# PROP Default_Filter ""
-# Begin Source File
-
-SOURCE=..\..\..\Common\NewHandler.cpp
-# End Source File
-# Begin Source File
-
-SOURCE=..\..\..\Common\NewHandler.h
-# End Source File
-# End Group
-# Begin Group "Huffman"
-
-# PROP Default_Filter ""
-# Begin Source File
-
-SOURCE=..\Huffman\HuffmanDecoder.h
-# End Source File
-# Begin Source File
-
-SOURCE=..\..\..\..\C\Compress\Huffman\HuffmanEncode.c
-
-!IF "$(CFG)" == "BZip2 - Win32 Release"
-
-# ADD CPP /O2
-# SUBTRACT CPP /YX /Yc /Yu
-
-!ELSEIF "$(CFG)" == "BZip2 - Win32 Debug"
-
-# SUBTRACT CPP /YX /Yc /Yu
-
-!ENDIF
-
-# End Source File
-# Begin Source File
-
-SOURCE=..\..\..\..\C\Compress\Huffman\HuffmanEncode.h
-# End Source File
-# Begin Source File
-
-SOURCE=..\..\..\..\C\Sort.c
-
-!IF "$(CFG)" == "BZip2 - Win32 Release"
-
-# ADD CPP /O2
-# SUBTRACT CPP /YX /Yc /Yu
-
-!ELSEIF "$(CFG)" == "BZip2 - Win32 Debug"
-
-# SUBTRACT CPP /YX /Yc /Yu
-
-!ENDIF
-
-# End Source File
-# Begin Source File
-
-SOURCE=..\..\..\..\C\Sort.h
-# End Source File
-# End Group
-# Begin Group "7-Zip Common"
-
-# PROP Default_Filter ""
-# Begin Source File
-
-SOURCE=..\..\Common\InBuffer.cpp
-# End Source File
-# Begin Source File
-
-SOURCE=..\..\Common\InBuffer.h
-# End Source File
-# Begin Source File
-
-SOURCE=..\..\Common\MSBFDecoder.h
-# End Source File
-# Begin Source File
-
-SOURCE=..\..\Common\MSBFEncoder.h
-# End Source File
-# Begin Source File
-
-SOURCE=..\..\Common\OutBuffer.cpp
-# End Source File
-# Begin Source File
-
-SOURCE=..\..\Common\OutBuffer.h
-# End Source File
-# End Group
-# Begin Group "BWT"
-
-# PROP Default_Filter ""
-# Begin Source File
-
-SOURCE=..\BWT\BlockSort.cpp
-
-!IF "$(CFG)" == "BZip2 - Win32 Release"
-
-# ADD CPP /O2
-# SUBTRACT CPP /YX /Yc /Yu
-
-!ELSEIF "$(CFG)" == "BZip2 - Win32 Debug"
-
-!ENDIF
-
-# End Source File
-# Begin Source File
-
-SOURCE=..\BWT\BlockSort.h
-# End Source File
-# Begin Source File
-
-SOURCE=..\BWT\Mtf8.h
-# End Source File
-# End Group
-# Begin Group "Windows"
-
-# PROP Default_Filter ""
-# Begin Source File
-
-SOURCE=..\..\..\Windows\Synchronization.cpp
-# End Source File
-# Begin Source File
-
-SOURCE=..\..\..\Windows\Synchronization.h
-# End Source File
-# Begin Source File
-
-SOURCE=..\..\..\Windows\Thread.h
-# End Source File
-# End Group
-# Begin Group "Ń"
-
-# PROP Default_Filter ""
-# Begin Source File
-
-SOURCE=..\..\..\..\C\Alloc.c
-# SUBTRACT CPP /YX /Yc /Yu
-# End Source File
-# Begin Source File
-
-SOURCE=..\..\..\..\C\Alloc.h
-# End Source File
-# End Group
-# Begin Source File
-
-SOURCE=.\BZip2Const.h
-# End Source File
-# Begin Source File
-
-SOURCE=.\BZip2CRC.cpp
-# End Source File
-# Begin Source File
-
-SOURCE=.\BZip2CRC.h
-# End Source File
-# Begin Source File
-
-SOURCE=.\BZip2Decoder.cpp
-
-!IF "$(CFG)" == "BZip2 - Win32 Release"
-
-# ADD CPP /O2
-# SUBTRACT CPP /YX /Yc /Yu
-
-!ELSEIF "$(CFG)" == "BZip2 - Win32 Debug"
-
-!ENDIF
-
-# End Source File
-# Begin Source File
-
-SOURCE=.\BZip2Decoder.h
-# End Source File
-# Begin Source File
-
-SOURCE=.\BZip2Encoder.cpp
-
-!IF "$(CFG)" == "BZip2 - Win32 Release"
-
-# ADD CPP /O2
-# SUBTRACT CPP /YX /Yc /Yu
-
-!ELSEIF "$(CFG)" == "BZip2 - Win32 Debug"
-
-!ENDIF
-
-# End Source File
-# Begin Source File
-
-SOURCE=.\BZip2Encoder.h
-# End Source File
-# Begin Source File
-
-SOURCE=.\BZip2Register.cpp
-# End Source File
-# End Target
-# End Project
diff --git a/CPP/7zip/Compress/BZip2/BZip2Decoder.cpp b/CPP/7zip/Compress/BZip2/BZip2Decoder.cpp
index 3f7dbc58..47ffa7c8 100755
--- a/CPP/7zip/Compress/BZip2/BZip2Decoder.cpp
+++ b/CPP/7zip/Compress/BZip2/BZip2Decoder.cpp
@@ -432,10 +432,12 @@ CDecoder::~CDecoder()
Free();
}
-HRes CDecoder::Create()
+#define RINOK_THREAD(x) { WRes __result_ = (x); if(__result_ != 0) return __result_; }
+
+HRESULT CDecoder::Create()
{
- RINOK(CanProcessEvent.CreateIfNotCreated());
- RINOK(CanStartWaitingEvent.CreateIfNotCreated());
+ RINOK_THREAD(CanProcessEvent.CreateIfNotCreated());
+ RINOK_THREAD(CanStartWaitingEvent.CreateIfNotCreated());
if (m_States != 0 && m_NumThreadsPrev == NumThreads)
return S_OK;
Free();
@@ -454,7 +456,7 @@ HRes CDecoder::Create()
ti.Decoder = this;
if (MtMode)
{
- HRes res = ti.Create();
+ HRESULT res = ti.Create();
if (res != S_OK)
{
NumThreads = t;
@@ -524,9 +526,12 @@ HRESULT CDecoder::DecodeFile(bool &isBZ, ICompressProgressInfo *progress)
CState &s = m_States[t];
if (!s.Alloc())
return E_OUTOFMEMORY;
- s.StreamWasFinishedEvent.Reset();
- s.WaitingWasStartedEvent.Reset();
- s.CanWriteEvent.Reset();
+ if (MtMode)
+ {
+ RINOK(s.StreamWasFinishedEvent.Reset());
+ RINOK(s.WaitingWasStartedEvent.Reset());
+ RINOK(s.CanWriteEvent.Reset());
+ }
}
#else
if (!m_States[0].Alloc())
@@ -647,12 +652,13 @@ STDMETHODIMP CDecoder::GetInStreamProcessedSize(UInt64 *value)
static THREAD_FUNC_DECL MFThread(void *p) { ((CState *)p)->ThreadFunc(); return 0; }
-HRes CState::Create()
+HRESULT CState::Create()
{
- RINOK(StreamWasFinishedEvent.CreateIfNotCreated());
- RINOK(WaitingWasStartedEvent.CreateIfNotCreated());
- RINOK(CanWriteEvent.CreateIfNotCreated());
- return Thread.Create(MFThread, this);
+ RINOK_THREAD(StreamWasFinishedEvent.CreateIfNotCreated());
+ RINOK_THREAD(WaitingWasStartedEvent.CreateIfNotCreated());
+ RINOK_THREAD(CanWriteEvent.CreateIfNotCreated());
+ RINOK_THREAD(Thread.Create(MFThread, this));
+ return S_OK;
}
void CState::FinishStream()
diff --git a/CPP/7zip/Compress/BZip2/BZip2Decoder.h b/CPP/7zip/Compress/BZip2/BZip2Decoder.h
index 9c965b49..511302d5 100755
--- a/CPP/7zip/Compress/BZip2/BZip2Decoder.h
+++ b/CPP/7zip/Compress/BZip2/BZip2Decoder.h
@@ -17,13 +17,7 @@
#include "../../../Windows/Synchronization.h"
#endif
-#if _MSC_VER >= 1300
-#define NO_INLINE __declspec(noinline) __fastcall
-#else
-#ifdef _MSC_VER
-#define NO_INLINE __fastcall
-#endif
-#endif
+#define NO_INLINE MY_FAST_CALL
namespace NCompress {
namespace NBZip2 {
@@ -50,7 +44,7 @@ struct CState
Byte MtPad[1 << 8]; // It's pad for Multi-Threading. Must be >= Cache_Line_Size.
- HRes Create();
+ HRESULT Create();
void FinishStream();
void ThreadFunc();
@@ -126,7 +120,7 @@ public:
UInt32 BlockSizeMax;
CDecoder();
~CDecoder();
- HRes Create();
+ HRESULT Create();
void Free();
#else
diff --git a/CPP/7zip/Compress/BZip2/BZip2Encoder.cpp b/CPP/7zip/Compress/BZip2/BZip2Encoder.cpp
index ac5f78e1..2491ef17 100755
--- a/CPP/7zip/Compress/BZip2/BZip2Encoder.cpp
+++ b/CPP/7zip/Compress/BZip2/BZip2Encoder.cpp
@@ -5,19 +5,15 @@
extern "C"
{
#include "../../../../C/Alloc.h"
+#include "../../../../C/BwtSort.h"
+#include "../../../../C/HuffEnc.h"
}
#include "BZip2Encoder.h"
-#include "../BWT/BlockSort.h"
#include "../BWT/Mtf8.h"
#include "BZip2CRC.h"
-extern "C"
-{
- #include "../../../../C/Compress/Huffman/HuffmanEncode.h"
-}
-
namespace NCompress {
namespace NBZip2 {
@@ -61,12 +57,15 @@ static THREAD_FUNC_DECL MFThread(void *threadCoderInfo)
return ((CThreadInfo *)threadCoderInfo)->ThreadFunc();
}
-HRes CThreadInfo::Create()
+#define RINOK_THREAD(x) { WRes __result_ = (x); if(__result_ != 0) return __result_; }
+
+HRESULT CThreadInfo::Create()
{
- RINOK(StreamWasFinishedEvent.Create());
- RINOK(WaitingWasStartedEvent.Create());
- RINOK(CanWriteEvent.Create());
- return Thread.Create(MFThread, this);
+ RINOK_THREAD(StreamWasFinishedEvent.Create());
+ RINOK_THREAD(WaitingWasStartedEvent.Create());
+ RINOK_THREAD(CanWriteEvent.Create());
+ RINOK_THREAD(Thread.Create(MFThread, this));
+ return S_OK;
}
void CThreadInfo::FinishStream(bool needLeave)
@@ -145,10 +144,10 @@ CEncoder::~CEncoder()
Free();
}
-HRes CEncoder::Create()
+HRESULT CEncoder::Create()
{
- RINOK(CanProcessEvent.CreateIfNotCreated());
- RINOK(CanStartWaitingEvent.CreateIfNotCreated());
+ RINOK_THREAD(CanProcessEvent.CreateIfNotCreated());
+ RINOK_THREAD(CanStartWaitingEvent.CreateIfNotCreated());
if (ThreadsInfo != 0 && m_NumThreadsPrev == NumThreads)
return S_OK;
try
@@ -167,7 +166,7 @@ HRes CEncoder::Create()
ti.Encoder = this;
if (MtMode)
{
- HRes res = ti.Create();
+ HRESULT res = ti.Create();
if (res != S_OK)
{
NumThreads = t;
@@ -733,9 +732,12 @@ HRESULT CEncoder::CodeReal(ISequentialInStream *inStream,
{
#ifdef COMPRESS_BZIP2_MT
CThreadInfo &ti = ThreadsInfo[t];
- ti.StreamWasFinishedEvent.Reset();
- ti.WaitingWasStartedEvent.Reset();
- ti.CanWriteEvent.Reset();
+ if (MtMode)
+ {
+ RINOK(ti.StreamWasFinishedEvent.Reset());
+ RINOK(ti.WaitingWasStartedEvent.Reset());
+ RINOK(ti.CanWriteEvent.Reset());
+ }
#else
CThreadInfo &ti = ThreadsInfo;
ti.Encoder = this;
diff --git a/CPP/7zip/Compress/BZip2/BZip2Encoder.h b/CPP/7zip/Compress/BZip2/BZip2Encoder.h
index 02d4cde3..98cd20d6 100755
--- a/CPP/7zip/Compress/BZip2/BZip2Encoder.h
+++ b/CPP/7zip/Compress/BZip2/BZip2Encoder.h
@@ -70,9 +70,9 @@ public:
void SetPos(UInt32 bitPos)
{
m_Pos = bitPos / 8;
- m_BitPos = 8 - (bitPos & 7);
+ m_BitPos = 8 - ((int)bitPos & 7);
}
- void SetCurState(UInt32 bitPos, Byte curByte)
+ void SetCurState(int bitPos, Byte curByte)
{
m_BitPos = 8 - bitPos;
m_CurByte = curByte;
@@ -103,7 +103,7 @@ private:
UInt32 m_CRCs[1 << kNumPassesMax];
UInt32 m_NumCrcs;
- int m_BlockIndex;
+ UInt32 m_BlockIndex;
void WriteBits2(UInt32 value, UInt32 numBits);
void WriteByte2(Byte b);
@@ -128,7 +128,7 @@ public:
UInt64 m_PackSize;
Byte MtPad[1 << 8]; // It's pad for Multi-Threading. Must be >= Cache_Line_Size.
- HRes Create();
+ HRESULT Create();
void FinishStream(bool needLeave);
DWORD ThreadFunc();
#endif
@@ -189,7 +189,7 @@ public:
void WriteCRC(UInt32 v);
#ifdef COMPRESS_BZIP2_MT
- HRes Create();
+ HRESULT Create();
void Free();
#endif
diff --git a/CPP/7zip/Compress/BZip2/makefile b/CPP/7zip/Compress/BZip2/makefile
deleted file mode 100755
index 6e467583..00000000
--- a/CPP/7zip/Compress/BZip2/makefile
+++ /dev/null
@@ -1,58 +0,0 @@
-PROG = BZip2.dll
-DEF_FILE = ../Codec.def
-CFLAGS = $(CFLAGS) -I ../../../ -DCOMPRESS_BZIP2_MT -D_7ZIP_LARGE_PAGES
-LIBS = $(LIBS) oleaut32.lib
-
-COMPRESS_OBJS = \
- $O\CodecExports.obj \
- $O\DllExports.obj \
-
-BZIP2_OBJS = \
- $O\BZip2CRC.obj \
- $O\BZip2Register.obj \
-
-BZIP2_OPT_OBJS = \
- $O\BZip2Decoder.obj \
- $O\BZip2Encoder.obj \
-
-WIN_OBJS = \
- $O\Synchronization.obj
-
-7ZIP_COMMON_OBJS = \
- $O\InBuffer.obj \
- $O\OutBuffer.obj \
-
-C_OBJS = \
- $O\Alloc.obj \
- $O\Sort.obj \
-
-OBJS = \
- $O\StdAfx.obj \
- $(COMPRESS_OBJS) \
- $(BZIP2_OBJS) \
- $(BZIP2_OPT_OBJS) \
- $(WIN_OBJS) \
- $(7ZIP_COMMON_OBJS) \
- $O\BlockSort.obj \
- $(C_OBJS) \
- $O\HuffmanEncode.obj \
- $O\resource.res
-
-!include "../../../Build.mak"
-
-$(COMPRESS_OBJS): ../$(*B).cpp
- $(COMPL)
-$(BZIP2_OBJS): $(*B).cpp
- $(COMPL)
-$(BZIP2_OPT_OBJS): $(*B).cpp
- $(COMPL_O2)
-$(WIN_OBJS): ../../../Windows/$(*B).cpp
- $(COMPL)
-$(7ZIP_COMMON_OBJS): ../../Common/$(*B).cpp
- $(COMPL)
-$O\BlockSort.obj: ../BWT/$(*B).cpp
- $(COMPL_O2)
-$(C_OBJS): ../../../../C/$(*B).c
- $(COMPL_O2)
-$O\HuffmanEncode.obj: ../../../../C/Compress/Huffman/$(*B).c
- $(COMPL_O2)
diff --git a/CPP/7zip/Compress/BZip2/resource.rc b/CPP/7zip/Compress/BZip2/resource.rc
deleted file mode 100755
index c5bea782..00000000
--- a/CPP/7zip/Compress/BZip2/resource.rc
+++ /dev/null
@@ -1,3 +0,0 @@
-#include "../../MyVersionInfo.rc"
-
-MY_VERSION_INFO_DLL("BZip2 Codec", "BZip2")
diff --git a/CPP/7zip/Compress/Branch/ARM.cpp b/CPP/7zip/Compress/Branch/ARM.cpp
deleted file mode 100755
index 5870bc03..00000000
--- a/CPP/7zip/Compress/Branch/ARM.cpp
+++ /dev/null
@@ -1,19 +0,0 @@
-// ARM.cpp
-
-#include "StdAfx.h"
-#include "ARM.h"
-
-extern "C"
-{
-#include "../../../../C/Compress/Branch/BranchARM.h"
-}
-
-UInt32 CBC_ARM_Encoder::SubFilter(Byte *data, UInt32 size)
-{
- return ::ARM_Convert(data, size, _bufferPos, 1);
-}
-
-UInt32 CBC_ARM_Decoder::SubFilter(Byte *data, UInt32 size)
-{
- return ::ARM_Convert(data, size, _bufferPos, 0);
-}
diff --git a/CPP/7zip/Compress/Branch/ARM.h b/CPP/7zip/Compress/Branch/ARM.h
deleted file mode 100755
index 5561299b..00000000
--- a/CPP/7zip/Compress/Branch/ARM.h
+++ /dev/null
@@ -1,10 +0,0 @@
-// ARM.h
-
-#ifndef __ARM_H
-#define __ARM_H
-
-#include "BranchCoder.h"
-
-MyClassA(BC_ARM, 0x05, 1)
-
-#endif
diff --git a/CPP/7zip/Compress/Branch/ARMThumb.cpp b/CPP/7zip/Compress/Branch/ARMThumb.cpp
deleted file mode 100755
index 7df641ac..00000000
--- a/CPP/7zip/Compress/Branch/ARMThumb.cpp
+++ /dev/null
@@ -1,20 +0,0 @@
-// ARMThumb.cpp
-
-#include "StdAfx.h"
-
-#include "ARMThumb.h"
-
-extern "C"
-{
-#include "../../../../C/Compress/Branch/BranchARMThumb.h"
-}
-
-UInt32 CBC_ARMThumb_Encoder::SubFilter(Byte *data, UInt32 size)
-{
- return ::ARMThumb_Convert(data, size, _bufferPos, 1);
-}
-
-UInt32 CBC_ARMThumb_Decoder::SubFilter(Byte *data, UInt32 size)
-{
- return ::ARMThumb_Convert(data, size, _bufferPos, 0);
-}
diff --git a/CPP/7zip/Compress/Branch/ARMThumb.h b/CPP/7zip/Compress/Branch/ARMThumb.h
deleted file mode 100755
index 601e40bf..00000000
--- a/CPP/7zip/Compress/Branch/ARMThumb.h
+++ /dev/null
@@ -1,10 +0,0 @@
-// ARMThumb.h
-
-#ifndef __ARMTHUMB_H
-#define __ARMTHUMB_H
-
-#include "BranchCoder.h"
-
-MyClassA(BC_ARMThumb, 0x07, 1)
-
-#endif
diff --git a/CPP/7zip/Compress/Branch/Branch.dsp b/CPP/7zip/Compress/Branch/Branch.dsp
deleted file mode 100755
index 795a534a..00000000
--- a/CPP/7zip/Compress/Branch/Branch.dsp
+++ /dev/null
@@ -1,433 +0,0 @@
-# Microsoft Developer Studio Project File - Name="Branch" - Package Owner=<4>
-# Microsoft Developer Studio Generated Build File, Format Version 6.00
-# ** DO NOT EDIT **
-
-# TARGTYPE "Win32 (x86) Dynamic-Link Library" 0x0102
-
-CFG=Branch - Win32 Debug
-!MESSAGE This is not a valid makefile. To build this project using NMAKE,
-!MESSAGE use the Export Makefile command and run
-!MESSAGE
-!MESSAGE NMAKE /f "Branch.mak".
-!MESSAGE
-!MESSAGE You can specify a configuration when running NMAKE
-!MESSAGE by defining the macro CFG on the command line. For example:
-!MESSAGE
-!MESSAGE NMAKE /f "Branch.mak" CFG="Branch - Win32 Debug"
-!MESSAGE
-!MESSAGE Possible choices for configuration are:
-!MESSAGE
-!MESSAGE "Branch - Win32 Release" (based on "Win32 (x86) Dynamic-Link Library")
-!MESSAGE "Branch - Win32 Debug" (based on "Win32 (x86) Dynamic-Link Library")
-!MESSAGE
-
-# Begin Project
-# PROP AllowPerConfigDependencies 0
-# PROP Scc_ProjName ""
-# PROP Scc_LocalPath ""
-CPP=cl.exe
-MTL=midl.exe
-RSC=rc.exe
-
-!IF "$(CFG)" == "Branch - Win32 Release"
-
-# PROP BASE Use_MFC 0
-# PROP BASE Use_Debug_Libraries 0
-# PROP BASE Output_Dir "Release"
-# PROP BASE Intermediate_Dir "Release"
-# PROP BASE Target_Dir ""
-# PROP Use_MFC 0
-# PROP Use_Debug_Libraries 0
-# PROP Output_Dir "Release"
-# PROP Intermediate_Dir "Release"
-# PROP Ignore_Export_Lib 1
-# PROP Target_Dir ""
-# ADD BASE CPP /nologo /MT /W3 /GX /O2 /D "WIN32" /D "NDEBUG" /D "_WINDOWS" /D "_MBCS" /D "_USRDLL" /D "BRANCH_EXPORTS" /YX /FD /c
-# ADD CPP /nologo /Gz /MD /W3 /GX /O2 /I "..\..\..\\" /D "WIN32" /D "NDEBUG" /D "_WINDOWS" /D "_MBCS" /D "_USRDLL" /D "BRANCH_EXPORTS" /FD /c
-# SUBTRACT CPP /YX /Yc /Yu
-# ADD BASE MTL /nologo /D "NDEBUG" /mktyplib203 /win32
-# ADD MTL /nologo /D "NDEBUG" /mktyplib203 /win32
-# ADD BASE RSC /l 0x419 /d "NDEBUG"
-# ADD RSC /l 0x419 /d "NDEBUG"
-BSC32=bscmake.exe
-# ADD BASE BSC32 /nologo
-# ADD BSC32 /nologo
-LINK32=link.exe
-# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /dll /machine:I386
-# ADD LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /dll /machine:I386 /out:"C:\Program Files\7-Zip\Codecs\Branch.dll" /opt:NOWIN98
-# SUBTRACT LINK32 /pdb:none
-
-!ELSEIF "$(CFG)" == "Branch - Win32 Debug"
-
-# PROP BASE Use_MFC 0
-# PROP BASE Use_Debug_Libraries 1
-# PROP BASE Output_Dir "Debug"
-# PROP BASE Intermediate_Dir "Debug"
-# PROP BASE Target_Dir ""
-# PROP Use_MFC 0
-# PROP Use_Debug_Libraries 1
-# PROP Output_Dir "Debug"
-# PROP Intermediate_Dir "Debug"
-# PROP Ignore_Export_Lib 1
-# PROP Target_Dir ""
-# ADD BASE CPP /nologo /MTd /W3 /Gm /GX /ZI /Od /D "WIN32" /D "_DEBUG" /D "_WINDOWS" /D "_MBCS" /D "_USRDLL" /D "BRANCH_EXPORTS" /YX /FD /GZ /c
-# ADD CPP /nologo /Gz /MTd /W3 /Gm /GX /ZI /Od /I "..\..\..\\" /D "WIN32" /D "_DEBUG" /D "_WINDOWS" /D "_MBCS" /D "_USRDLL" /D "BRANCH_EXPORTS" /Yu"StdAfx.h" /FD /GZ /c
-# ADD BASE MTL /nologo /D "_DEBUG" /mktyplib203 /win32
-# ADD MTL /nologo /D "_DEBUG" /mktyplib203 /win32
-# ADD BASE RSC /l 0x419 /d "_DEBUG"
-# ADD RSC /l 0x419 /d "_DEBUG"
-BSC32=bscmake.exe
-# ADD BASE BSC32 /nologo
-# ADD BSC32 /nologo
-LINK32=link.exe
-# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /dll /debug /machine:I386 /pdbtype:sept
-# ADD LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /dll /debug /machine:I386 /out:"C:\Program Files\7-Zip\Codecs\Branch.dll" /pdbtype:sept
-
-!ENDIF
-
-# Begin Target
-
-# Name "Branch - Win32 Release"
-# Name "Branch - Win32 Debug"
-# Begin Group "Spec"
-
-# PROP Default_Filter ""
-# Begin Source File
-
-SOURCE=..\Codec.def
-# End Source File
-# Begin Source File
-
-SOURCE=..\CodecExports.cpp
-# End Source File
-# Begin Source File
-
-SOURCE=..\DllExports.cpp
-# End Source File
-# Begin Source File
-
-SOURCE=.\resource.rc
-# End Source File
-# Begin Source File
-
-SOURCE=.\StdAfx.cpp
-# ADD CPP /Yc"StdAfx.h"
-# End Source File
-# Begin Source File
-
-SOURCE=.\StdAfx.h
-# End Source File
-# End Group
-# Begin Group "Methods"
-
-# PROP Default_Filter ""
-# Begin Source File
-
-SOURCE=.\ARM.cpp
-
-!IF "$(CFG)" == "Branch - Win32 Release"
-
-# ADD CPP /O2
-# SUBTRACT CPP /YX /Yc /Yu
-
-!ELSEIF "$(CFG)" == "Branch - Win32 Debug"
-
-!ENDIF
-
-# End Source File
-# Begin Source File
-
-SOURCE=.\ARM.h
-# End Source File
-# Begin Source File
-
-SOURCE=.\ARMThumb.cpp
-
-!IF "$(CFG)" == "Branch - Win32 Release"
-
-# ADD CPP /O2
-# SUBTRACT CPP /YX /Yc /Yu
-
-!ELSEIF "$(CFG)" == "Branch - Win32 Debug"
-
-!ENDIF
-
-# End Source File
-# Begin Source File
-
-SOURCE=.\ARMThumb.h
-# End Source File
-# Begin Source File
-
-SOURCE=.\BCJ2Register.cpp
-# End Source File
-# Begin Source File
-
-SOURCE=.\BCJRegister.cpp
-# End Source File
-# Begin Source File
-
-SOURCE=.\BranchCoder.cpp
-# End Source File
-# Begin Source File
-
-SOURCE=.\BranchCoder.h
-# End Source File
-# Begin Source File
-
-SOURCE=.\BranchRegister.cpp
-# End Source File
-# Begin Source File
-
-SOURCE=.\BranchTypes.h
-# End Source File
-# Begin Source File
-
-SOURCE=.\BranchX86.h
-# End Source File
-# Begin Source File
-
-SOURCE=.\IA64.cpp
-
-!IF "$(CFG)" == "Branch - Win32 Release"
-
-# ADD CPP /O2
-# SUBTRACT CPP /YX /Yc /Yu
-
-!ELSEIF "$(CFG)" == "Branch - Win32 Debug"
-
-!ENDIF
-
-# End Source File
-# Begin Source File
-
-SOURCE=.\IA64.h
-# End Source File
-# Begin Source File
-
-SOURCE=.\PPC.cpp
-
-!IF "$(CFG)" == "Branch - Win32 Release"
-
-# ADD CPP /O2
-# SUBTRACT CPP /YX /Yc /Yu
-
-!ELSEIF "$(CFG)" == "Branch - Win32 Debug"
-
-!ENDIF
-
-# End Source File
-# Begin Source File
-
-SOURCE=.\PPC.h
-# End Source File
-# Begin Source File
-
-SOURCE=.\SPARC.cpp
-# End Source File
-# Begin Source File
-
-SOURCE=.\SPARC.h
-# End Source File
-# Begin Source File
-
-SOURCE=.\x86.cpp
-
-!IF "$(CFG)" == "Branch - Win32 Release"
-
-# ADD CPP /O2
-# SUBTRACT CPP /YX /Yc /Yu
-
-!ELSEIF "$(CFG)" == "Branch - Win32 Debug"
-
-!ENDIF
-
-# End Source File
-# Begin Source File
-
-SOURCE=.\x86.h
-# End Source File
-# Begin Source File
-
-SOURCE=.\x86_2.cpp
-
-!IF "$(CFG)" == "Branch - Win32 Release"
-
-# ADD CPP /O2
-# SUBTRACT CPP /YX /Yc /Yu
-
-!ELSEIF "$(CFG)" == "Branch - Win32 Debug"
-
-!ENDIF
-
-# End Source File
-# Begin Source File
-
-SOURCE=.\x86_2.h
-# End Source File
-# End Group
-# Begin Group "Stream"
-
-# PROP Default_Filter ""
-# Begin Source File
-
-SOURCE=..\..\Common\InBuffer.cpp
-# End Source File
-# Begin Source File
-
-SOURCE=..\..\Common\InBuffer.h
-# End Source File
-# Begin Source File
-
-SOURCE=..\..\Common\OutBuffer.cpp
-# End Source File
-# Begin Source File
-
-SOURCE=..\..\Common\OutBuffer.h
-# End Source File
-# End Group
-# Begin Group "RangeCoder"
-
-# PROP Default_Filter ""
-# Begin Source File
-
-SOURCE=..\RangeCoder\RangeCoder.h
-# End Source File
-# Begin Source File
-
-SOURCE=..\RangeCoder\RangeCoderBit.h
-# End Source File
-# End Group
-# Begin Group "C"
-
-# PROP Default_Filter ""
-# Begin Group "C Branch"
-
-# PROP Default_Filter ""
-# Begin Source File
-
-SOURCE=..\..\..\..\C\Compress\Branch\BranchARM.c
-
-!IF "$(CFG)" == "Branch - Win32 Release"
-
-!ELSEIF "$(CFG)" == "Branch - Win32 Debug"
-
-# SUBTRACT CPP /YX /Yc /Yu
-
-!ENDIF
-
-# End Source File
-# Begin Source File
-
-SOURCE=..\..\..\..\C\Compress\Branch\BranchARM.h
-# End Source File
-# Begin Source File
-
-SOURCE=..\..\..\..\C\Compress\Branch\BranchARMThumb.c
-
-!IF "$(CFG)" == "Branch - Win32 Release"
-
-!ELSEIF "$(CFG)" == "Branch - Win32 Debug"
-
-# SUBTRACT CPP /YX /Yc /Yu
-
-!ENDIF
-
-# End Source File
-# Begin Source File
-
-SOURCE=..\..\..\..\C\Compress\Branch\BranchARMThumb.h
-# End Source File
-# Begin Source File
-
-SOURCE=..\..\..\..\C\Compress\Branch\BranchIA64.c
-
-!IF "$(CFG)" == "Branch - Win32 Release"
-
-!ELSEIF "$(CFG)" == "Branch - Win32 Debug"
-
-# SUBTRACT CPP /YX /Yc /Yu
-
-!ENDIF
-
-# End Source File
-# Begin Source File
-
-SOURCE=..\..\..\..\C\Compress\Branch\BranchIA64.h
-# End Source File
-# Begin Source File
-
-SOURCE=..\..\..\..\C\Compress\Branch\BranchPPC.c
-
-!IF "$(CFG)" == "Branch - Win32 Release"
-
-!ELSEIF "$(CFG)" == "Branch - Win32 Debug"
-
-# SUBTRACT CPP /YX /Yc /Yu
-
-!ENDIF
-
-# End Source File
-# Begin Source File
-
-SOURCE=..\..\..\..\C\Compress\Branch\BranchPPC.h
-# End Source File
-# Begin Source File
-
-SOURCE=..\..\..\..\C\Compress\Branch\BranchSPARC.c
-
-!IF "$(CFG)" == "Branch - Win32 Release"
-
-!ELSEIF "$(CFG)" == "Branch - Win32 Debug"
-
-# SUBTRACT CPP /YX /Yc /Yu
-
-!ENDIF
-
-# End Source File
-# Begin Source File
-
-SOURCE=..\..\..\..\C\Compress\Branch\BranchSPARC.h
-# End Source File
-# Begin Source File
-
-SOURCE=..\..\..\..\C\Compress\Branch\BranchTypes.h
-# End Source File
-# Begin Source File
-
-SOURCE=..\..\..\..\C\Compress\Branch\BranchX86.c
-
-!IF "$(CFG)" == "Branch - Win32 Release"
-
-!ELSEIF "$(CFG)" == "Branch - Win32 Debug"
-
-# SUBTRACT CPP /YX /Yc /Yu
-
-!ENDIF
-
-# End Source File
-# Begin Source File
-
-SOURCE=..\..\..\..\C\Compress\Branch\BranchX86.h
-# End Source File
-# End Group
-# Begin Source File
-
-SOURCE=..\..\..\..\C\Alloc.c
-
-!IF "$(CFG)" == "Branch - Win32 Release"
-
-!ELSEIF "$(CFG)" == "Branch - Win32 Debug"
-
-# SUBTRACT CPP /YX /Yc /Yu
-
-!ENDIF
-
-# End Source File
-# Begin Source File
-
-SOURCE=..\..\..\..\C\Alloc.h
-# End Source File
-# End Group
-# End Target
-# End Project
diff --git a/CPP/7zip/Compress/Branch/Branch.dsw b/CPP/7zip/Compress/Branch/Branch.dsw
deleted file mode 100755
index 841c85a3..00000000
--- a/CPP/7zip/Compress/Branch/Branch.dsw
+++ /dev/null
@@ -1,29 +0,0 @@
-Microsoft Developer Studio Workspace File, Format Version 6.00
-# WARNING: DO NOT EDIT OR DELETE THIS WORKSPACE FILE!
-
-###############################################################################
-
-Project: "Branch"=.\Branch.dsp - Package Owner=<4>
-
-Package=<5>
-{{{
-}}}
-
-Package=<4>
-{{{
-}}}
-
-###############################################################################
-
-Global:
-
-Package=<5>
-{{{
-}}}
-
-Package=<3>
-{{{
-}}}
-
-###############################################################################
-
diff --git a/CPP/7zip/Compress/Branch/BranchMisc.cpp b/CPP/7zip/Compress/Branch/BranchMisc.cpp
new file mode 100755
index 00000000..ff4eafbe
--- /dev/null
+++ b/CPP/7zip/Compress/Branch/BranchMisc.cpp
@@ -0,0 +1,39 @@
+// BranchMisc.cpp
+
+#include "StdAfx.h"
+#include "BranchMisc.h"
+
+extern "C"
+{
+#include "../../../../C/Bra.h"
+}
+
+UInt32 CBC_ARM_Encoder::SubFilter(Byte *data, UInt32 size)
+ { return (UInt32)::ARM_Convert(data, size, _bufferPos, 1); }
+
+UInt32 CBC_ARM_Decoder::SubFilter(Byte *data, UInt32 size)
+ { return (UInt32)::ARM_Convert(data, size, _bufferPos, 0); }
+
+UInt32 CBC_ARMT_Encoder::SubFilter(Byte *data, UInt32 size)
+ { return (UInt32)::ARMT_Convert(data, size, _bufferPos, 1); }
+
+UInt32 CBC_ARMT_Decoder::SubFilter(Byte *data, UInt32 size)
+ { return (UInt32)::ARMT_Convert(data, size, _bufferPos, 0); }
+
+UInt32 CBC_PPC_Encoder::SubFilter(Byte *data, UInt32 size)
+ { return (UInt32)::PPC_Convert(data, size, _bufferPos, 1); }
+
+UInt32 CBC_PPC_Decoder::SubFilter(Byte *data, UInt32 size)
+ { return (UInt32)::PPC_Convert(data, size, _bufferPos, 0); }
+
+UInt32 CBC_SPARC_Encoder::SubFilter(Byte *data, UInt32 size)
+ { return (UInt32)::SPARC_Convert(data, size, _bufferPos, 1); }
+
+UInt32 CBC_SPARC_Decoder::SubFilter(Byte *data, UInt32 size)
+ { return (UInt32)::SPARC_Convert(data, size, _bufferPos, 0); }
+
+UInt32 CBC_IA64_Encoder::SubFilter(Byte *data, UInt32 size)
+ { return (UInt32)::IA64_Convert(data, size, _bufferPos, 1); }
+
+UInt32 CBC_IA64_Decoder::SubFilter(Byte *data, UInt32 size)
+ { return (UInt32)::IA64_Convert(data, size, _bufferPos, 0); }
diff --git a/CPP/7zip/Compress/Branch/BranchMisc.h b/CPP/7zip/Compress/Branch/BranchMisc.h
new file mode 100755
index 00000000..219eec1c
--- /dev/null
+++ b/CPP/7zip/Compress/Branch/BranchMisc.h
@@ -0,0 +1,14 @@
+// BranchMisc.h
+
+#ifndef __BRANCHMISC_H
+#define __BRANCHMISC_H
+
+#include "BranchCoder.h"
+
+MyClassA(BC_ARM, 0x05, 1)
+MyClassA(BC_ARMT, 0x07, 1)
+MyClassA(BC_PPC, 0x02, 5)
+MyClassA(BC_SPARC, 0x08, 5)
+MyClassA(BC_IA64, 0x04, 1)
+
+#endif
diff --git a/CPP/7zip/Compress/Branch/BranchRegister.cpp b/CPP/7zip/Compress/Branch/BranchRegister.cpp
index 2ccdcc64..69fbe5d3 100755
--- a/CPP/7zip/Compress/Branch/BranchRegister.cpp
+++ b/CPP/7zip/Compress/Branch/BranchRegister.cpp
@@ -4,31 +4,27 @@
#include "../../Common/RegisterCodec.h"
-#include "PPC.h"
-#include "IA64.h"
-#include "ARM.h"
-#include "ARMThumb.h"
-#include "SPARC.h"
+#include "BranchMisc.h"
#define CREATE_CODEC(x) \
static void *CreateCodec ## x() { return (void *)(ICompressFilter *)(new C ## x ## _Decoder); } \
static void *CreateCodec ## x ## Out() { return (void *)(ICompressFilter *)(new C ## x ## _Encoder); }
-CREATE_CODEC(BC_PPC_B)
+CREATE_CODEC(BC_PPC)
CREATE_CODEC(BC_IA64)
CREATE_CODEC(BC_ARM)
-CREATE_CODEC(BC_ARMThumb)
+CREATE_CODEC(BC_ARMT)
CREATE_CODEC(BC_SPARC)
#define METHOD_ITEM(x, id1, id2, name) { CreateCodec ## x, CreateCodec ## x ## Out, 0x03030000 + (id1 * 256) + id2, name, 1, true }
static CCodecInfo g_CodecsInfo[] =
{
- METHOD_ITEM(BC_PPC_B, 0x02, 0x05, L"BC_PPC_B"),
- METHOD_ITEM(BC_IA64, 0x04, 1, L"BC_IA64"),
- METHOD_ITEM(BC_ARM, 0x05, 1, L"BC_ARM"),
- METHOD_ITEM(BC_ARMThumb,0x07, 1, L"BC_ARMThumb"),
- METHOD_ITEM(BC_SPARC, 0x08, 0x05, L"BC_SPARC")
+ METHOD_ITEM(BC_PPC, 0x02, 0x05, L"PPC"),
+ METHOD_ITEM(BC_IA64, 0x04, 1, L"IA64"),
+ METHOD_ITEM(BC_ARM, 0x05, 1, L"ARM"),
+ METHOD_ITEM(BC_ARMT, 0x07, 1, L"ARMT"),
+ METHOD_ITEM(BC_SPARC, 0x08, 0x05, L"SPARC")
};
REGISTER_CODECS(Branch)
diff --git a/CPP/7zip/Compress/Branch/IA64.cpp b/CPP/7zip/Compress/Branch/IA64.cpp
deleted file mode 100755
index ae4766a3..00000000
--- a/CPP/7zip/Compress/Branch/IA64.cpp
+++ /dev/null
@@ -1,19 +0,0 @@
-// IA64.cpp
-
-#include "StdAfx.h"
-#include "IA64.h"
-
-extern "C"
-{
-#include "../../../../C/Compress/Branch/BranchIA64.h"
-}
-
-UInt32 CBC_IA64_Encoder::SubFilter(Byte *data, UInt32 size)
-{
- return ::IA64_Convert(data, size, _bufferPos, 1);
-}
-
-UInt32 CBC_IA64_Decoder::SubFilter(Byte *data, UInt32 size)
-{
- return ::IA64_Convert(data, size, _bufferPos, 0);
-}
diff --git a/CPP/7zip/Compress/Branch/IA64.h b/CPP/7zip/Compress/Branch/IA64.h
deleted file mode 100755
index 7fe715ed..00000000
--- a/CPP/7zip/Compress/Branch/IA64.h
+++ /dev/null
@@ -1,10 +0,0 @@
-// IA64.h
-
-#ifndef __IA64_H
-#define __IA64_H
-
-#include "BranchCoder.h"
-
-MyClassA(BC_IA64, 0x04, 1)
-
-#endif
diff --git a/CPP/7zip/Compress/Branch/PPC.cpp b/CPP/7zip/Compress/Branch/PPC.cpp
deleted file mode 100755
index ecd4b3d8..00000000
--- a/CPP/7zip/Compress/Branch/PPC.cpp
+++ /dev/null
@@ -1,19 +0,0 @@
-// PPC.cpp
-
-#include "StdAfx.h"
-#include "PPC.h"
-
-extern "C"
-{
-#include "../../../../C/Compress/Branch/BranchPPC.h"
-}
-
-UInt32 CBC_PPC_B_Encoder::SubFilter(Byte *data, UInt32 size)
-{
- return ::PPC_B_Convert(data, size, _bufferPos, 1);
-}
-
-UInt32 CBC_PPC_B_Decoder::SubFilter(Byte *data, UInt32 size)
-{
- return ::PPC_B_Convert(data, size, _bufferPos, 0);
-}
diff --git a/CPP/7zip/Compress/Branch/PPC.h b/CPP/7zip/Compress/Branch/PPC.h
deleted file mode 100755
index a0e33444..00000000
--- a/CPP/7zip/Compress/Branch/PPC.h
+++ /dev/null
@@ -1,10 +0,0 @@
-// PPC.h
-
-#ifndef __PPC_H
-#define __PPC_H
-
-#include "BranchCoder.h"
-
-MyClassA(BC_PPC_B, 0x02, 5)
-
-#endif
diff --git a/CPP/7zip/Compress/Branch/SPARC.cpp b/CPP/7zip/Compress/Branch/SPARC.cpp
deleted file mode 100755
index 5678eb31..00000000
--- a/CPP/7zip/Compress/Branch/SPARC.cpp
+++ /dev/null
@@ -1,19 +0,0 @@
-// SPARC.cpp
-
-#include "StdAfx.h"
-#include "SPARC.h"
-
-extern "C"
-{
-#include "../../../../C/Compress/Branch/BranchSPARC.h"
-}
-
-UInt32 CBC_SPARC_Encoder::SubFilter(Byte *data, UInt32 size)
-{
- return ::SPARC_Convert(data, size, _bufferPos, 1);
-}
-
-UInt32 CBC_SPARC_Decoder::SubFilter(Byte *data, UInt32 size)
-{
- return ::SPARC_Convert(data, size, _bufferPos, 0);
-}
diff --git a/CPP/7zip/Compress/Branch/SPARC.h b/CPP/7zip/Compress/Branch/SPARC.h
deleted file mode 100755
index e0a682ef..00000000
--- a/CPP/7zip/Compress/Branch/SPARC.h
+++ /dev/null
@@ -1,10 +0,0 @@
-// SPARC.h
-
-#ifndef __SPARC_H
-#define __SPARC_H
-
-#include "BranchCoder.h"
-
-MyClassA(BC_SPARC, 0x08, 5)
-
-#endif
diff --git a/CPP/7zip/Compress/Branch/makefile b/CPP/7zip/Compress/Branch/makefile
deleted file mode 100755
index 73ae75b2..00000000
--- a/CPP/7zip/Compress/Branch/makefile
+++ /dev/null
@@ -1,63 +0,0 @@
-PROG = Branch.dll
-DEF_FILE = ../Codec.def
-CFLAGS = $(CFLAGS) -I ../../../
-LIBS = $(LIBS) oleaut32.lib
-
-COMPRESS_OBJS = \
- $O\CodecExports.obj \
- $O\DllExports.obj \
-
-BRANCH_OPT_OBJS = \
- $O\ARM.obj \
- $O\ARMThumb.obj \
- $O\BranchCoder.obj \
- $O\IA64.obj \
- $O\PPC.obj \
- $O\SPARC.obj \
- $O\x86.obj \
- $O\x86_2.obj \
- $O\BranchRegister.obj \
- $O\BCJRegister.obj \
- $O\BCJ2Register.obj \
-
-C_OBJS = \
- $O\Alloc.obj \
-
-C_BRANCH_OBJS = \
- $O\BranchARM.obj \
- $O\BranchARMThumb.obj \
- $O\BranchIA64.obj \
- $O\BranchPPC.obj \
- $O\BranchSPARC.obj \
- $O\BranchX86.obj \
-
-7ZIP_COMMON_OBJS = \
- $O\InBuffer.obj \
- $O\OutBuffer.obj \
-
-
-OBJS = \
- $O\StdAfx.obj \
- $(COMPRESS_OBJS) \
- $(BRANCH_OPT_OBJS) \
- $(7ZIP_COMMON_OBJS) \
- $O\RangeCoderBit.obj \
- $(C_OBJS) \
- $(C_BRANCH_OBJS) \
- $O\resource.res
-
-
-!include "../../../Build.mak"
-
-$(COMPRESS_OBJS): ../$(*B).cpp
- $(COMPL)
-$(BRANCH_OPT_OBJS): $(*B).cpp
- $(COMPL_O2)
-$(7ZIP_COMMON_OBJS): ../../Common/$(*B).cpp
- $(COMPL)
-$O\RangeCoderBit.obj: ../RangeCoder/$(*B).cpp
- $(COMPL)
-$(C_OBJS): ../../../../C/$(*B).c
- $(COMPL_O2)
-$(C_BRANCH_OBJS): ../../../../C/Compress/Branch/$(*B).c
- $(COMPL_O2)
diff --git a/CPP/7zip/Compress/Branch/resource.rc b/CPP/7zip/Compress/Branch/resource.rc
deleted file mode 100755
index 5476d4fa..00000000
--- a/CPP/7zip/Compress/Branch/resource.rc
+++ /dev/null
@@ -1,3 +0,0 @@
-#include "../../MyVersionInfo.rc"
-
-MY_VERSION_INFO_DLL("Branch Filter", "Branch")
diff --git a/CPP/7zip/Compress/Branch/x86.h b/CPP/7zip/Compress/Branch/x86.h
index 58176600..e898cb7e 100755
--- a/CPP/7zip/Compress/Branch/x86.h
+++ b/CPP/7zip/Compress/Branch/x86.h
@@ -6,7 +6,7 @@
#include "BranchCoder.h"
extern "C"
{
-#include "../../../../C/Compress/Branch/BranchX86.h"
+#include "../../../../C/Bra.h"
}
struct CBranch86
diff --git a/CPP/7zip/Compress/ByteSwap/ByteSwap.dsp b/CPP/7zip/Compress/ByteSwap/ByteSwap.dsp
deleted file mode 100755
index 14c42981..00000000
--- a/CPP/7zip/Compress/ByteSwap/ByteSwap.dsp
+++ /dev/null
@@ -1,133 +0,0 @@
-# Microsoft Developer Studio Project File - Name="ByteSwap" - Package Owner=<4>
-# Microsoft Developer Studio Generated Build File, Format Version 6.00
-# ** DO NOT EDIT **
-
-# TARGTYPE "Win32 (x86) Dynamic-Link Library" 0x0102
-
-CFG=ByteSwap - Win32 Debug
-!MESSAGE This is not a valid makefile. To build this project using NMAKE,
-!MESSAGE use the Export Makefile command and run
-!MESSAGE
-!MESSAGE NMAKE /f "ByteSwap.mak".
-!MESSAGE
-!MESSAGE You can specify a configuration when running NMAKE
-!MESSAGE by defining the macro CFG on the command line. For example:
-!MESSAGE
-!MESSAGE NMAKE /f "ByteSwap.mak" CFG="ByteSwap - Win32 Debug"
-!MESSAGE
-!MESSAGE Possible choices for configuration are:
-!MESSAGE
-!MESSAGE "ByteSwap - Win32 Release" (based on "Win32 (x86) Dynamic-Link Library")
-!MESSAGE "ByteSwap - Win32 Debug" (based on "Win32 (x86) Dynamic-Link Library")
-!MESSAGE
-
-# Begin Project
-# PROP AllowPerConfigDependencies 0
-# PROP Scc_ProjName ""
-# PROP Scc_LocalPath ""
-CPP=cl.exe
-MTL=midl.exe
-RSC=rc.exe
-
-!IF "$(CFG)" == "ByteSwap - Win32 Release"
-
-# PROP BASE Use_MFC 0
-# PROP BASE Use_Debug_Libraries 0
-# PROP BASE Output_Dir "Release"
-# PROP BASE Intermediate_Dir "Release"
-# PROP BASE Target_Dir ""
-# PROP Use_MFC 0
-# PROP Use_Debug_Libraries 0
-# PROP Output_Dir "Release"
-# PROP Intermediate_Dir "Release"
-# PROP Ignore_Export_Lib 1
-# PROP Target_Dir ""
-# ADD BASE CPP /nologo /MT /W3 /GX /O2 /D "WIN32" /D "NDEBUG" /D "_WINDOWS" /D "_MBCS" /D "_USRDLL" /D "BYTESWAP_EXPORTS" /YX /FD /c
-# ADD CPP /nologo /Gz /MD /W3 /GX /O1 /I "..\..\..\\" /D "WIN32" /D "NDEBUG" /D "_WINDOWS" /D "_MBCS" /D "_USRDLL" /D "BYTESWAP_EXPORTS" /Yu"StdAfx.h" /FD /c
-# ADD BASE MTL /nologo /D "NDEBUG" /mktyplib203 /win32
-# ADD MTL /nologo /D "NDEBUG" /mktyplib203 /win32
-# ADD BASE RSC /l 0x419 /d "NDEBUG"
-# ADD RSC /l 0x419 /d "NDEBUG"
-BSC32=bscmake.exe
-# ADD BASE BSC32 /nologo
-# ADD BSC32 /nologo
-LINK32=link.exe
-# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /dll /machine:I386
-# ADD LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /dll /machine:I386 /out:"C:\Program Files\7-Zip\Codecs\Swap.dll" /opt:NOWIN98
-# SUBTRACT LINK32 /pdb:none
-
-!ELSEIF "$(CFG)" == "ByteSwap - Win32 Debug"
-
-# PROP BASE Use_MFC 0
-# PROP BASE Use_Debug_Libraries 1
-# PROP BASE Output_Dir "Debug"
-# PROP BASE Intermediate_Dir "Debug"
-# PROP BASE Target_Dir ""
-# PROP Use_MFC 0
-# PROP Use_Debug_Libraries 1
-# PROP Output_Dir "Debug"
-# PROP Intermediate_Dir "Debug"
-# PROP Ignore_Export_Lib 1
-# PROP Target_Dir ""
-# ADD BASE CPP /nologo /MTd /W3 /Gm /GX /ZI /Od /D "WIN32" /D "_DEBUG" /D "_WINDOWS" /D "_MBCS" /D "_USRDLL" /D "BYTESWAP_EXPORTS" /YX /FD /GZ /c
-# ADD CPP /nologo /Gz /MTd /W3 /Gm /GX /ZI /Od /I "..\..\..\\" /D "WIN32" /D "_DEBUG" /D "_WINDOWS" /D "_MBCS" /D "_USRDLL" /D "BYTESWAP_EXPORTS" /Yu"StdAfx.h" /FD /GZ /c
-# ADD BASE MTL /nologo /D "_DEBUG" /mktyplib203 /win32
-# ADD MTL /nologo /D "_DEBUG" /mktyplib203 /win32
-# ADD BASE RSC /l 0x419 /d "_DEBUG"
-# ADD RSC /l 0x419 /d "_DEBUG"
-BSC32=bscmake.exe
-# ADD BASE BSC32 /nologo
-# ADD BSC32 /nologo
-LINK32=link.exe
-# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /dll /debug /machine:I386 /pdbtype:sept
-# ADD LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /dll /debug /machine:I386 /out:"C:\Program Files\7-Zip\Codecs\Swap.dll" /pdbtype:sept
-
-!ENDIF
-
-# Begin Target
-
-# Name "ByteSwap - Win32 Release"
-# Name "ByteSwap - Win32 Debug"
-# Begin Group "Spec"
-
-# PROP Default_Filter ""
-# Begin Source File
-
-SOURCE=..\Codec.def
-# End Source File
-# Begin Source File
-
-SOURCE=..\CodecExports.cpp
-# End Source File
-# Begin Source File
-
-SOURCE=..\DllExports.cpp
-# End Source File
-# Begin Source File
-
-SOURCE=.\resource.rc
-# End Source File
-# Begin Source File
-
-SOURCE=.\StdAfx.cpp
-# ADD CPP /Yc"StdAfx.h"
-# End Source File
-# Begin Source File
-
-SOURCE=.\StdAfx.h
-# End Source File
-# End Group
-# Begin Source File
-
-SOURCE=.\ByteSwap.cpp
-# End Source File
-# Begin Source File
-
-SOURCE=.\ByteSwap.h
-# End Source File
-# Begin Source File
-
-SOURCE=.\ByteSwapRegister.cpp
-# End Source File
-# End Target
-# End Project
diff --git a/CPP/7zip/Compress/ByteSwap/ByteSwap.dsw b/CPP/7zip/Compress/ByteSwap/ByteSwap.dsw
deleted file mode 100755
index 413d7e6e..00000000
--- a/CPP/7zip/Compress/ByteSwap/ByteSwap.dsw
+++ /dev/null
@@ -1,29 +0,0 @@
-Microsoft Developer Studio Workspace File, Format Version 6.00
-# WARNING: DO NOT EDIT OR DELETE THIS WORKSPACE FILE!
-
-###############################################################################
-
-Project: "ByteSwap"=.\ByteSwap.dsp - Package Owner=<4>
-
-Package=<5>
-{{{
-}}}
-
-Package=<4>
-{{{
-}}}
-
-###############################################################################
-
-Global:
-
-Package=<5>
-{{{
-}}}
-
-Package=<3>
-{{{
-}}}
-
-###############################################################################
-
diff --git a/CPP/7zip/Compress/ByteSwap/makefile b/CPP/7zip/Compress/ByteSwap/makefile
deleted file mode 100755
index 80e8af78..00000000
--- a/CPP/7zip/Compress/ByteSwap/makefile
+++ /dev/null
@@ -1,25 +0,0 @@
-PROG = Swap.dll
-DEF_FILE = ../Codec.def
-CFLAGS = $(CFLAGS) -I ../../../
-LIBS = $(LIBS) oleaut32.lib
-
-COMPRESS_OBJS = \
- $O\CodecExports.obj \
- $O\DllExports.obj \
-
-SWAP_OPT_OBJS = \
- $O\ByteSwap.obj \
- $O\ByteSwapRegister.obj \
-
-OBJS = \
- $O\StdAfx.obj \
- $(COMPRESS_OBJS) \
- $(SWAP_OPT_OBJS) \
- $O\resource.res
-
-!include "../../../Build.mak"
-
-$(COMPRESS_OBJS): ../$(*B).cpp
- $(COMPL)
-$(SWAP_OPT_OBJS): $(*B).cpp
- $(COMPL_O2)
diff --git a/CPP/7zip/Compress/ByteSwap/resource.rc b/CPP/7zip/Compress/ByteSwap/resource.rc
deleted file mode 100755
index 21c0c505..00000000
--- a/CPP/7zip/Compress/ByteSwap/resource.rc
+++ /dev/null
@@ -1,3 +0,0 @@
-#include "../../MyVersionInfo.rc"
-
-MY_VERSION_INFO_DLL("SWAP filter Codec", "SWAP")
diff --git a/CPP/7zip/Compress/CodecExports.cpp b/CPP/7zip/Compress/CodecExports.cpp
index a4a85b64..7500d923 100755
--- a/CPP/7zip/Compress/CodecExports.cpp
+++ b/CPP/7zip/Compress/CodecExports.cpp
@@ -48,7 +48,7 @@ static HRESULT FindCodecClassId(const GUID *clsID, UInt32 isCoder2, bool isFilte
UInt64 id = 0;
for (int j = 0; j < 8; j++)
id |= ((UInt64)clsID->Data4[j]) << (8 * j);
- for (UInt32 i = 0; i < g_NumCodecs; i++)
+ for (unsigned i = 0; i < g_NumCodecs; i++)
{
const CCodecInfo &codec = *g_Codecs[i];
if (id != codec.Id || encode && !codec.CreateEncoder || !encode && !codec.CreateDecoder)
@@ -142,7 +142,7 @@ STDAPI GetMethodProperty(UInt32 codecIndex, PROPID propID, PROPVARIANT *value)
if (codec.NumInStreams != 1)
{
value->vt = VT_UI4;
- value->ulVal = codec.NumInStreams;
+ value->ulVal = (ULONG)codec.NumInStreams;
}
break;
}
diff --git a/CPP/7zip/Compress/Copy/Copy.dsw b/CPP/7zip/Compress/Copy/Copy.dsw
deleted file mode 100755
index 53ddf6cf..00000000
--- a/CPP/7zip/Compress/Copy/Copy.dsw
+++ /dev/null
@@ -1,29 +0,0 @@
-Microsoft Developer Studio Workspace File, Format Version 6.00
-# WARNING: DO NOT EDIT OR DELETE THIS WORKSPACE FILE!
-
-###############################################################################
-
-Project: "Copy"=".\Copy.dsp" - Package Owner=<4>
-
-Package=<5>
-{{{
-}}}
-
-Package=<4>
-{{{
-}}}
-
-###############################################################################
-
-Global:
-
-Package=<5>
-{{{
-}}}
-
-Package=<3>
-{{{
-}}}
-
-###############################################################################
-
diff --git a/CPP/7zip/Compress/Copy/CopyCoder.cpp b/CPP/7zip/Compress/Copy/CopyCoder.cpp
index 8e18db2b..d5285185 100755
--- a/CPP/7zip/Compress/Copy/CopyCoder.cpp
+++ b/CPP/7zip/Compress/Copy/CopyCoder.cpp
@@ -42,7 +42,7 @@ STDMETHODIMP CCopyCoder::Code(ISequentialInStream *inStream,
RINOK(inStream->Read(_buffer, size, &realProcessedSize));
if (realProcessedSize == 0)
break;
- RINOK(WriteStream(outStream, _buffer, realProcessedSize, NULL));
+ RINOK(WriteStream(outStream, _buffer, realProcessedSize));
TotalSize += realProcessedSize;
if (progress != NULL)
{
diff --git a/CPP/7zip/Compress/Copy/makefile b/CPP/7zip/Compress/Copy/makefile
deleted file mode 100755
index 4588a341..00000000
--- a/CPP/7zip/Compress/Copy/makefile
+++ /dev/null
@@ -1,37 +0,0 @@
-PROG = Copy.dll
-DEF_FILE = ../Codec.def
-CFLAGS = $(CFLAGS) -I ../../../
-LIBS = $(LIBS) oleaut32.lib
-
-COMPRESS_OBJS = \
- $O\CodecExports.obj \
- $O\DllExports.obj \
-
-COPY_OBJS = \
- $O\CopyCoder.obj \
- $O\CopyRegister.obj \
-
-7ZIP_COMMON_OBJS = \
- $O\StreamUtils.obj \
-
-C_OBJS = \
- $O\Alloc.obj \
-
-OBJS = \
- $O\StdAfx.obj \
- $(COMPRESS_OBJS) \
- $(COPY_OBJS) \
- $(7ZIP_COMMON_OBJS) \
- $(C_OBJS) \
- $O\resource.res
-
-!include "../../../Build.mak"
-
-$(COMPRESS_OBJS): ../$(*B).cpp
- $(COMPL)
-$(COPY_OBJS): $(*B).cpp
- $(COMPL)
-$(7ZIP_COMMON_OBJS): ../../Common/$(*B).cpp
- $(COMPL)
-$(C_OBJS): ../../../../C/$(*B).c
- $(COMPL_O2)
diff --git a/CPP/7zip/Compress/Copy/resource.rc b/CPP/7zip/Compress/Copy/resource.rc
deleted file mode 100755
index 234c85bf..00000000
--- a/CPP/7zip/Compress/Copy/resource.rc
+++ /dev/null
@@ -1,3 +0,0 @@
-#include "../../MyVersionInfo.rc"
-
-MY_VERSION_INFO_DLL("Copy Codec", "Copy")
diff --git a/CPP/7zip/Compress/Deflate/Deflate.dsp b/CPP/7zip/Compress/Deflate/Deflate.dsp
deleted file mode 100755
index 11854458..00000000
--- a/CPP/7zip/Compress/Deflate/Deflate.dsp
+++ /dev/null
@@ -1,350 +0,0 @@
-# Microsoft Developer Studio Project File - Name="Deflate" - Package Owner=<4>
-# Microsoft Developer Studio Generated Build File, Format Version 6.00
-# ** DO NOT EDIT **
-
-# TARGTYPE "Win32 (x86) Dynamic-Link Library" 0x0102
-
-CFG=Deflate - Win32 Debug
-!MESSAGE This is not a valid makefile. To build this project using NMAKE,
-!MESSAGE use the Export Makefile command and run
-!MESSAGE
-!MESSAGE NMAKE /f "Deflate.mak".
-!MESSAGE
-!MESSAGE You can specify a configuration when running NMAKE
-!MESSAGE by defining the macro CFG on the command line. For example:
-!MESSAGE
-!MESSAGE NMAKE /f "Deflate.mak" CFG="Deflate - Win32 Debug"
-!MESSAGE
-!MESSAGE Possible choices for configuration are:
-!MESSAGE
-!MESSAGE "Deflate - Win32 Release" (based on "Win32 (x86) Dynamic-Link Library")
-!MESSAGE "Deflate - Win32 Debug" (based on "Win32 (x86) Dynamic-Link Library")
-!MESSAGE
-
-# Begin Project
-# PROP AllowPerConfigDependencies 0
-# PROP Scc_ProjName ""
-# PROP Scc_LocalPath ""
-CPP=cl.exe
-MTL=midl.exe
-RSC=rc.exe
-
-!IF "$(CFG)" == "Deflate - Win32 Release"
-
-# PROP BASE Use_MFC 0
-# PROP BASE Use_Debug_Libraries 0
-# PROP BASE Output_Dir "Release"
-# PROP BASE Intermediate_Dir "Release"
-# PROP BASE Target_Dir ""
-# PROP Use_MFC 0
-# PROP Use_Debug_Libraries 0
-# PROP Output_Dir "Release"
-# PROP Intermediate_Dir "Release"
-# PROP Ignore_Export_Lib 1
-# PROP Target_Dir ""
-# ADD BASE CPP /nologo /MT /W3 /GX /O2 /D "WIN32" /D "NDEBUG" /D "_WINDOWS" /D "_MBCS" /D "_USRDLL" /D "DEFLATE_EXPORTS" /YX /FD /c
-# ADD CPP /nologo /Gz /MD /W3 /GX /O1 /I "..\..\..\\" /D "NDEBUG" /D "WIN32" /D "_WINDOWS" /D "_MBCS" /D "_USRDLL" /D "DEFLATE_EXPORTS" /D "_ST_MODE" /Yu"StdAfx.h" /FD /c
-# ADD BASE MTL /nologo /D "NDEBUG" /mktyplib203 /win32
-# ADD MTL /nologo /D "NDEBUG" /mktyplib203 /win32
-# ADD BASE RSC /l 0x419 /d "NDEBUG"
-# ADD RSC /l 0x409 /d "NDEBUG"
-BSC32=bscmake.exe
-# ADD BASE BSC32 /nologo
-# ADD BSC32 /nologo
-LINK32=link.exe
-# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /dll /machine:I386
-# ADD LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /dll /machine:I386 /out:"C:\Program Files\7-Zip\Codecs\Deflate.dll" /opt:NOWIN98
-# SUBTRACT LINK32 /pdb:none
-
-!ELSEIF "$(CFG)" == "Deflate - Win32 Debug"
-
-# PROP BASE Use_MFC 0
-# PROP BASE Use_Debug_Libraries 1
-# PROP BASE Output_Dir "Debug"
-# PROP BASE Intermediate_Dir "Debug"
-# PROP BASE Target_Dir ""
-# PROP Use_MFC 0
-# PROP Use_Debug_Libraries 1
-# PROP Output_Dir "Debug"
-# PROP Intermediate_Dir "Debug"
-# PROP Ignore_Export_Lib 1
-# PROP Target_Dir ""
-# ADD BASE CPP /nologo /MTd /W3 /Gm /GX /ZI /Od /D "WIN32" /D "_DEBUG" /D "_WINDOWS" /D "_MBCS" /D "_USRDLL" /D "DEFLATE_EXPORTS" /YX /FD /GZ /c
-# ADD CPP /nologo /Gz /MDd /W3 /Gm /GX /ZI /Od /I "..\..\..\\" /D "_DEBUG" /D "WIN32" /D "_WINDOWS" /D "_MBCS" /D "_USRDLL" /D "DEFLATE_EXPORTS" /D "_ST_MODE" /Yu"StdAfx.h" /FD /GZ /c
-# ADD BASE MTL /nologo /D "_DEBUG" /mktyplib203 /win32
-# ADD MTL /nologo /D "_DEBUG" /mktyplib203 /win32
-# ADD BASE RSC /l 0x419 /d "_DEBUG"
-# ADD RSC /l 0x409 /d "_DEBUG"
-BSC32=bscmake.exe
-# ADD BASE BSC32 /nologo
-# ADD BSC32 /nologo
-LINK32=link.exe
-# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /dll /debug /machine:I386 /pdbtype:sept
-# ADD LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /dll /debug /machine:I386 /out:"C:\Program Files\7-Zip\Codecs\Deflate.dll" /pdbtype:sept
-
-!ENDIF
-
-# Begin Target
-
-# Name "Deflate - Win32 Release"
-# Name "Deflate - Win32 Debug"
-# Begin Group "Spec"
-
-# PROP Default_Filter ""
-# Begin Source File
-
-SOURCE=..\Codec.def
-# End Source File
-# Begin Source File
-
-SOURCE=..\CodecExports.cpp
-# End Source File
-# Begin Source File
-
-SOURCE=..\DllExports.cpp
-# End Source File
-# Begin Source File
-
-SOURCE=.\resource.rc
-# End Source File
-# Begin Source File
-
-SOURCE=.\StdAfx.cpp
-# ADD CPP /Yc"StdAfx.h"
-# End Source File
-# Begin Source File
-
-SOURCE=.\StdAfx.h
-# End Source File
-# End Group
-# Begin Group "Huffman"
-
-# PROP Default_Filter ""
-# Begin Source File
-
-SOURCE=..\Huffman\HuffmanDecoder.h
-# End Source File
-# End Group
-# Begin Group "Interface"
-
-# PROP Default_Filter ""
-# End Group
-# Begin Group "7zip Common"
-
-# PROP Default_Filter ""
-# Begin Source File
-
-SOURCE=..\..\Common\InBuffer.cpp
-# End Source File
-# Begin Source File
-
-SOURCE=..\..\Common\InBuffer.h
-# End Source File
-# Begin Source File
-
-SOURCE=..\..\Common\LSBFDecoder.cpp
-# End Source File
-# Begin Source File
-
-SOURCE=..\..\Common\LSBFDecoder.h
-# End Source File
-# Begin Source File
-
-SOURCE=..\..\Common\LSBFEncoder.cpp
-# End Source File
-# Begin Source File
-
-SOURCE=..\..\Common\LSBFEncoder.h
-# End Source File
-# Begin Source File
-
-SOURCE=..\..\Common\OutBuffer.cpp
-# End Source File
-# Begin Source File
-
-SOURCE=..\..\Common\OutBuffer.h
-# End Source File
-# End Group
-# Begin Group "Common"
-
-# PROP Default_Filter ""
-# Begin Source File
-
-SOURCE=..\..\..\Common\NewHandler.cpp
-# End Source File
-# Begin Source File
-
-SOURCE=..\..\..\Common\NewHandler.h
-# End Source File
-# End Group
-# Begin Group "Windows"
-
-# PROP Default_Filter ""
-# End Group
-# Begin Group "LZ"
-
-# PROP Default_Filter ""
-# Begin Source File
-
-SOURCE=..\LZ\LZOutWindow.cpp
-# End Source File
-# Begin Source File
-
-SOURCE=..\LZ\LZOutWindow.h
-# End Source File
-# End Group
-# Begin Group "LZ_C"
-
-# PROP Default_Filter ""
-# Begin Source File
-
-SOURCE=..\..\..\..\C\7zCrc.c
-
-!IF "$(CFG)" == "Deflate - Win32 Release"
-
-# ADD CPP /O2
-# SUBTRACT CPP /YX /Yc /Yu
-
-!ELSEIF "$(CFG)" == "Deflate - Win32 Debug"
-
-# SUBTRACT CPP /YX /Yc /Yu
-
-!ENDIF
-
-# End Source File
-# Begin Source File
-
-SOURCE=..\..\..\..\C\7zCrc.h
-# End Source File
-# Begin Source File
-
-SOURCE=..\..\..\..\C\Alloc.c
-# SUBTRACT CPP /YX /Yc /Yu
-# End Source File
-# Begin Source File
-
-SOURCE=..\..\..\..\C\Alloc.h
-# End Source File
-# Begin Source File
-
-SOURCE=..\..\..\..\C\Compress\Lz\LzHash.h
-# End Source File
-# Begin Source File
-
-SOURCE=..\..\..\..\C\Compress\Lz\MatchFinder.c
-
-!IF "$(CFG)" == "Deflate - Win32 Release"
-
-# ADD CPP /O2
-# SUBTRACT CPP /YX /Yc /Yu
-
-!ELSEIF "$(CFG)" == "Deflate - Win32 Debug"
-
-# SUBTRACT CPP /YX /Yc /Yu
-
-!ENDIF
-
-# End Source File
-# Begin Source File
-
-SOURCE=..\..\..\..\C\Compress\Lz\MatchFinder.h
-# End Source File
-# End Group
-# Begin Group "C Huffman"
-
-# PROP Default_Filter ""
-# Begin Source File
-
-SOURCE=..\..\..\..\C\Compress\Huffman\HuffmanEncode.c
-
-!IF "$(CFG)" == "Deflate - Win32 Release"
-
-# ADD CPP /O2
-# SUBTRACT CPP /YX /Yc /Yu
-
-!ELSEIF "$(CFG)" == "Deflate - Win32 Debug"
-
-# SUBTRACT CPP /YX /Yc /Yu
-
-!ENDIF
-
-# End Source File
-# Begin Source File
-
-SOURCE=..\..\..\..\C\Compress\Huffman\HuffmanEncode.h
-# End Source File
-# Begin Source File
-
-SOURCE=..\..\..\..\C\Sort.c
-
-!IF "$(CFG)" == "Deflate - Win32 Release"
-
-# ADD CPP /O2
-# SUBTRACT CPP /YX /Yc /Yu
-
-!ELSEIF "$(CFG)" == "Deflate - Win32 Debug"
-
-# SUBTRACT CPP /YX /Yc /Yu
-
-!ENDIF
-
-# End Source File
-# Begin Source File
-
-SOURCE=..\..\..\..\C\Sort.h
-# End Source File
-# End Group
-# Begin Source File
-
-SOURCE=.\Deflate64Register.cpp
-# End Source File
-# Begin Source File
-
-SOURCE=.\DeflateConst.h
-# End Source File
-# Begin Source File
-
-SOURCE=.\DeflateDecoder.cpp
-
-!IF "$(CFG)" == "Deflate - Win32 Release"
-
-# ADD CPP /O2
-# SUBTRACT CPP /YX /Yc /Yu
-
-!ELSEIF "$(CFG)" == "Deflate - Win32 Debug"
-
-!ENDIF
-
-# End Source File
-# Begin Source File
-
-SOURCE=.\DeflateDecoder.h
-# End Source File
-# Begin Source File
-
-SOURCE=.\DeflateEncoder.cpp
-
-!IF "$(CFG)" == "Deflate - Win32 Release"
-
-# ADD CPP /O2
-# SUBTRACT CPP /YX /Yc /Yu
-
-!ELSEIF "$(CFG)" == "Deflate - Win32 Debug"
-
-!ENDIF
-
-# End Source File
-# Begin Source File
-
-SOURCE=.\DeflateEncoder.h
-# End Source File
-# Begin Source File
-
-SOURCE=.\DeflateNsisRegister.cpp
-# End Source File
-# Begin Source File
-
-SOURCE=.\DeflateRegister.cpp
-# End Source File
-# End Target
-# End Project
diff --git a/CPP/7zip/Compress/Deflate/Deflate.dsw b/CPP/7zip/Compress/Deflate/Deflate.dsw
deleted file mode 100755
index f17203ed..00000000
--- a/CPP/7zip/Compress/Deflate/Deflate.dsw
+++ /dev/null
@@ -1,29 +0,0 @@
-Microsoft Developer Studio Workspace File, Format Version 6.00
-# WARNING: DO NOT EDIT OR DELETE THIS WORKSPACE FILE!
-
-###############################################################################
-
-Project: "Deflate"=.\Deflate.dsp - Package Owner=<4>
-
-Package=<5>
-{{{
-}}}
-
-Package=<4>
-{{{
-}}}
-
-###############################################################################
-
-Global:
-
-Package=<5>
-{{{
-}}}
-
-Package=<3>
-{{{
-}}}
-
-###############################################################################
-
diff --git a/CPP/7zip/Compress/Deflate/DeflateEncoder.cpp b/CPP/7zip/Compress/Deflate/DeflateEncoder.cpp
index 2c623750..44ff42b4 100755
--- a/CPP/7zip/Compress/Deflate/DeflateEncoder.cpp
+++ b/CPP/7zip/Compress/Deflate/DeflateEncoder.cpp
@@ -2,6 +2,8 @@
#include "StdAfx.h"
+#include <stdio.h>
+
#include "DeflateEncoder.h"
#include "Windows/Defs.h"
@@ -9,8 +11,8 @@
extern "C"
{
#include "../../../../C/Alloc.h"
+#include "../../../../C/HuffEnc.h"
}
-// #include "../LZ/BinTree/BinTree3Z.h"
#if _MSC_VER >= 1300
#define NO_INLINE __declspec(noinline)
@@ -18,11 +20,6 @@ extern "C"
#define NO_INLINE
#endif
-extern "C"
-{
- #include "../../../../C/Compress/Huffman/HuffmanEncode.h"
-}
-
namespace NCompress {
namespace NDeflate {
namespace NEncoder {
@@ -31,7 +28,7 @@ const int kNumDivPassesMax = 10; // [0, 16); ratio/speed/ram tradeoff; use big v
const UInt32 kNumTables = (1 << kNumDivPassesMax);
static UInt32 kFixedHuffmanCodeBlockSizeMax = (1 << 8); // [0, (1 << 32)); ratio/speed tradeoff; use big value for better compression ratio.
-static UInt32 kDivideCodeBlockSizeMin = (1 << 6); // [1, (1 << 32)); ratio/speed tradeoff; use small value for better compression ratio.
+static UInt32 kDivideCodeBlockSizeMin = (1 << 7); // [1, (1 << 32)); ratio/speed tradeoff; use small value for better compression ratio.
static UInt32 kDivideBlockSizeMin = (1 << 6); // [1, (1 << 32)); ratio/speed tradeoff; use small value for better compression ratio.
static const UInt32 kMaxUncompressedBlockSize = ((1 << 16) - 1) * 1; // [1, (1 << 32))
@@ -40,11 +37,11 @@ static const UInt32 kMatchArrayLimit = kMatchArraySize - kMatchMaxLen * 4 * size
static const UInt32 kBlockUncompressedSizeThreshold = kMaxUncompressedBlockSize -
kMatchMaxLen - kNumOpts;
-static const int kMaxCodeBitLength = 12;
+static const int kMaxCodeBitLength = 11;
static const int kMaxLevelBitLength = 7;
-static Byte kNoLiteralStatPrice = 12;
-static Byte kNoLenStatPrice = 12;
+static Byte kNoLiteralStatPrice = 11;
+static Byte kNoLenStatPrice = 11;
static Byte kNoPosStatPrice = 6;
static Byte g_LenSlots[kNumLenSymbolsMax];
@@ -85,19 +82,9 @@ inline UInt32 GetPosSlot(UInt32 pos)
return g_FastPos[pos >> 8] + 16;
}
-void *SzAlloc(size_t size)
-{
- if (size == 0)
- return 0;
- return malloc(size);
-}
-
-void SzFree(void *address)
-{
- free(address);
-}
-
-ISzAlloc g_Alloc = { SzAlloc, SzFree };
+static void *SzAlloc(void *p, size_t size) { p = p; return MyAlloc(size); }
+static void SzFree(void *p, void *address) { p = p; MyFree(address); }
+static ISzAlloc g_Alloc = { SzAlloc, SzFree };
CCoder::CCoder(bool deflate64Mode):
m_Deflate64Mode(deflate64Mode),
@@ -591,10 +578,10 @@ NO_INLINE void CCoder::LevelTableCode(const Byte *levels, int numLevels, const B
}
}
-NO_INLINE void CCoder::MakeTables()
+NO_INLINE void CCoder::MakeTables(unsigned maxHuffLen)
{
- Huffman_Generate(mainFreqs, mainCodes, m_NewLevels.litLenLevels, kFixedMainTableSize, kMaxCodeBitLength);
- Huffman_Generate(distFreqs, distCodes, m_NewLevels.distLevels, kDistTableSize64, kMaxCodeBitLength);
+ Huffman_Generate(mainFreqs, mainCodes, m_NewLevels.litLenLevels, kFixedMainTableSize, maxHuffLen);
+ Huffman_Generate(distFreqs, distCodes, m_NewLevels.distLevels, kDistTableSize64, maxHuffLen);
}
NO_INLINE UInt32 Huffman_GetPrice(const UInt32 *freqs, const Byte *lens, UInt32 num)
@@ -632,7 +619,7 @@ NO_INLINE void CCoder::TryBlock()
if (m_OptimumCurrentIndex == m_OptimumEndIndex)
{
if (m_Pos >= kMatchArrayLimit || BlockSizeRes >= blockSize || !m_SecondPass &&
- ((Inline_MatchFinder_GetNumAvailableBytes(&_lzInWindow) == 0) || m_ValueIndex >= m_ValueBlockSize))
+ ((Inline_MatchFinder_GetNumAvailableBytes(&_lzInWindow) == 0) || m_ValueIndex >= m_ValueBlockSize))
break;
}
UInt32 pos;
@@ -773,7 +760,11 @@ NO_INLINE UInt32 CCoder::TryDynBlock(int tableIndex, UInt32 numPasses)
{
m_Pos = posTemp;
TryBlock();
- MakeTables();
+ unsigned numHuffBits =
+ (m_ValueIndex > 18000 ? 12 :
+ (m_ValueIndex > 7000 ? 11 :
+ (m_ValueIndex > 2000 ? 10 : 9)));
+ MakeTables(numHuffBits);
SetPrices(m_NewLevels);
}
@@ -893,11 +884,12 @@ void CCoder::CodeBlock(int tableIndex, bool finalBlock)
WriteBits(NBlockType::kFixedHuffman, kBlockTypeFieldSize);
TryFixedBlock(tableIndex);
int i;
+ const int kMaxStaticHuffLen = 9;
for (i = 0; i < kFixedMainTableSize; i++)
- mainFreqs[i] = (UInt32)1 << (kNumHuffmanBits - m_NewLevels.litLenLevels[i]);
+ mainFreqs[i] = (UInt32)1 << (kMaxStaticHuffLen - m_NewLevels.litLenLevels[i]);
for (i = 0; i < kFixedDistTableSize; i++)
- distFreqs[i] = (UInt32)1 << (kNumHuffmanBits - m_NewLevels.distLevels[i]);
- MakeTables();
+ distFreqs[i] = (UInt32)1 << (kMaxStaticHuffLen - m_NewLevels.distLevels[i]);
+ MakeTables(kMaxStaticHuffLen);
}
else
{
@@ -921,9 +913,13 @@ void CCoder::CodeBlock(int tableIndex, bool finalBlock)
}
}
-HRes Read(void *object, void *data, UInt32 size, UInt32 *processedSize)
+SRes Read(void *object, void *data, size_t *size)
{
- return (HRes)((CSeqInStream *)object)->RealStream->Read(data, size, processedSize);
+ const UInt32 kStepSize = (UInt32)1 << 31;
+ UInt32 curSize = ((*size < kStepSize) ? (UInt32)*size : kStepSize);
+ HRESULT res = ((CSeqInStream *)object)->RealStream->Read(data, curSize, &curSize);
+ *size = curSize;
+ return (SRes)res;
}
HRESULT CCoder::CodeReal(ISequentialInStream *inStream,
@@ -935,7 +931,7 @@ HRESULT CCoder::CodeReal(ISequentialInStream *inStream,
RINOK(Create());
- m_ValueBlockSize = (1 << 13) + (1 << 12) * m_NumDivPasses;
+ m_ValueBlockSize = (7 << 10) + (1 << 12) * m_NumDivPasses;
UInt64 nowPos = 0;
diff --git a/CPP/7zip/Compress/Deflate/DeflateEncoder.h b/CPP/7zip/Compress/Deflate/DeflateEncoder.h
index a7b2bb5b..4cdfa707 100755
--- a/CPP/7zip/Compress/Deflate/DeflateEncoder.h
+++ b/CPP/7zip/Compress/Deflate/DeflateEncoder.h
@@ -12,7 +12,7 @@
extern "C"
{
- #include "../../../../C/Compress/Lz/MatchFinder.h"
+ #include "../../../../C/LzFind.h"
}
namespace NCompress {
@@ -132,7 +132,7 @@ public:
void WriteBits(UInt32 value, int numBits);
void LevelTableCode(const Byte *levels, int numLevels, const Byte *lens, const UInt32 *codes);
- void MakeTables();
+ void MakeTables(unsigned maxHuffLen);
UInt32 GetLzBlockPrice() const;
void TryBlock();
UInt32 TryDynBlock(int tableIndex, UInt32 numPasses);
diff --git a/CPP/7zip/Compress/Deflate/makefile b/CPP/7zip/Compress/Deflate/makefile
deleted file mode 100755
index 302d2888..00000000
--- a/CPP/7zip/Compress/Deflate/makefile
+++ /dev/null
@@ -1,63 +0,0 @@
-PROG = Deflate.dll
-DEF_FILE = ../Codec.def
-CFLAGS = $(CFLAGS) -I ../../../
-LIBS = $(LIBS) oleaut32.lib
-
-COMPRESS_OBJS = \
- $O\CodecExports.obj \
- $O\DllExports.obj \
-
-DEFLATE_OPT_OBJS = \
- $O\DeflateDecoder.obj \
- $O\DeflateEncoder.obj \
- $O\DeflateRegister.obj \
- $O\Deflate64Register.obj \
- $O\DeflateNsisRegister.obj \
-
-7ZIP_COMMON_OBJS = \
- $O\InBuffer.obj \
- $O\OutBuffer.obj \
- $O\LSBFDecoder.obj \
- $O\LSBFEncoder.obj \
-
-LZ_OBJS = \
- $O\LZOutWindow.obj \
-
-C_OBJS = \
- $O\Alloc.obj \
- $O\7zCrc.obj \
- $O\Sort.obj \
-
-C_LZ_OBJS = \
- $O\MatchFinder.obj \
-
-!include "../../Crc2.mak"
-
-OBJS = \
- $O\StdAfx.obj \
- $(COMPRESS_OBJS) \
- $(DEFLATE_OPT_OBJS) \
- $(7ZIP_COMMON_OBJS) \
- $(LZ_OBJS) \
- $(C_OBJS) \
- $(C_LZ_OBJS) \
- $O\HuffmanEncode.obj \
- $O\resource.res
-
-!include "../../../Build.mak"
-
-$(COMPRESS_OBJS): ../$(*B).cpp
- $(COMPL)
-$(DEFLATE_OPT_OBJS): $(*B).cpp
- $(COMPL_O2)
-$(7ZIP_COMMON_OBJS): ../../Common/$(*B).cpp
- $(COMPL)
-$(LZ_OBJS): ../LZ/$(*B).cpp
- $(COMPL)
-$(C_OBJS): ../../../../C/$(*B).c
- $(COMPL_O2)
-$(C_LZ_OBJS): ../../../../C/Compress/Lz/$(*B).c
- $(COMPL_O2)
-$O\HuffmanEncode.obj: ../../../../C/Compress/Huffman/$(*B).c
- $(COMPL_O2)
-!include "../../Crc.mak"
diff --git a/CPP/7zip/Compress/Deflate/resource.rc b/CPP/7zip/Compress/Deflate/resource.rc
deleted file mode 100755
index 910bc281..00000000
--- a/CPP/7zip/Compress/Deflate/resource.rc
+++ /dev/null
@@ -1,3 +0,0 @@
-#include "../../MyVersionInfo.rc"
-
-MY_VERSION_INFO_DLL("Deflate Codec", "Deflate")
diff --git a/CPP/7zip/Compress/Huffman/HuffmanDecoder.h b/CPP/7zip/Compress/Huffman/HuffmanDecoder.h
index 57115197..df67e8c9 100755
--- a/CPP/7zip/Compress/Huffman/HuffmanDecoder.h
+++ b/CPP/7zip/Compress/Huffman/HuffmanDecoder.h
@@ -22,7 +22,8 @@ public:
bool SetCodeLengths(const Byte *codeLengths)
{
- int lenCounts[kNumBitsMax + 1], tmpPositions[kNumBitsMax + 1];
+ int lenCounts[kNumBitsMax + 1];
+ UInt32 tmpPositions[kNumBitsMax + 1];
int i;
for(i = 1; i <= kNumBitsMax; i++)
lenCounts[i] = 0;
diff --git a/CPP/7zip/Compress/LZMA/LZMA.dsp b/CPP/7zip/Compress/LZMA/LZMA.dsp
deleted file mode 100755
index 2e699d43..00000000
--- a/CPP/7zip/Compress/LZMA/LZMA.dsp
+++ /dev/null
@@ -1,367 +0,0 @@
-# Microsoft Developer Studio Project File - Name="LZMA" - Package Owner=<4>
-# Microsoft Developer Studio Generated Build File, Format Version 6.00
-# ** DO NOT EDIT **
-
-# TARGTYPE "Win32 (x86) Dynamic-Link Library" 0x0102
-
-CFG=LZMA - Win32 Debug
-!MESSAGE This is not a valid makefile. To build this project using NMAKE,
-!MESSAGE use the Export Makefile command and run
-!MESSAGE
-!MESSAGE NMAKE /f "LZMA.mak".
-!MESSAGE
-!MESSAGE You can specify a configuration when running NMAKE
-!MESSAGE by defining the macro CFG on the command line. For example:
-!MESSAGE
-!MESSAGE NMAKE /f "LZMA.mak" CFG="LZMA - Win32 Debug"
-!MESSAGE
-!MESSAGE Possible choices for configuration are:
-!MESSAGE
-!MESSAGE "LZMA - Win32 Release" (based on "Win32 (x86) Dynamic-Link Library")
-!MESSAGE "LZMA - Win32 Debug" (based on "Win32 (x86) Dynamic-Link Library")
-!MESSAGE
-
-# Begin Project
-# PROP AllowPerConfigDependencies 0
-# PROP Scc_ProjName ""
-# PROP Scc_LocalPath ""
-CPP=cl.exe
-MTL=midl.exe
-RSC=rc.exe
-
-!IF "$(CFG)" == "LZMA - Win32 Release"
-
-# PROP BASE Use_MFC 0
-# PROP BASE Use_Debug_Libraries 0
-# PROP BASE Output_Dir "Release"
-# PROP BASE Intermediate_Dir "Release"
-# PROP BASE Target_Dir ""
-# PROP Use_MFC 0
-# PROP Use_Debug_Libraries 0
-# PROP Output_Dir "Release"
-# PROP Intermediate_Dir "Release"
-# PROP Ignore_Export_Lib 1
-# PROP Target_Dir ""
-# ADD BASE CPP /nologo /MT /W3 /GX /O2 /D "WIN32" /D "NDEBUG" /D "_WINDOWS" /D "_MBCS" /D "_USRDLL" /D "LZMA_EXPORTS" /YX /FD /c
-# ADD CPP /nologo /Gz /MD /W3 /GX /O1 /I "../../../" /D "NDEBUG" /D "WIN32" /D "_WINDOWS" /D "_MBCS" /D "_USRDLL" /D "LZMA_EXPORTS" /D "COMPRESS_MF_MT" /D "_7ZIP_LARGE_PAGES" /Yu"StdAfx.h" /FD /c
-# ADD BASE MTL /nologo /D "NDEBUG" /mktyplib203 /win32
-# ADD MTL /nologo /D "NDEBUG" /mktyplib203 /win32
-# ADD BASE RSC /l 0x419 /d "NDEBUG"
-# ADD RSC /l 0x419 /d "NDEBUG"
-BSC32=bscmake.exe
-# ADD BASE BSC32 /nologo
-# ADD BSC32 /nologo
-LINK32=link.exe
-# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /dll /machine:I386
-# ADD LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /dll /machine:I386 /out:"C:\Program Files\7-zip\Codecs\LZMA.dll" /opt:NOWIN98
-# SUBTRACT LINK32 /pdb:none /debug
-
-!ELSEIF "$(CFG)" == "LZMA - Win32 Debug"
-
-# PROP BASE Use_MFC 0
-# PROP BASE Use_Debug_Libraries 1
-# PROP BASE Output_Dir "Debug"
-# PROP BASE Intermediate_Dir "Debug"
-# PROP BASE Target_Dir ""
-# PROP Use_MFC 0
-# PROP Use_Debug_Libraries 1
-# PROP Output_Dir "Debug"
-# PROP Intermediate_Dir "Debug"
-# PROP Ignore_Export_Lib 1
-# PROP Target_Dir ""
-# ADD BASE CPP /nologo /MTd /W3 /Gm /GX /ZI /Od /D "WIN32" /D "_DEBUG" /D "_WINDOWS" /D "_MBCS" /D "_USRDLL" /D "LZMA_EXPORTS" /YX /FD /GZ /c
-# ADD CPP /nologo /Gz /MTd /W3 /Gm /GX /ZI /Od /I "../../../" /D "_DEBUG" /D "WIN32" /D "_WINDOWS" /D "_MBCS" /D "_USRDLL" /D "LZMA_EXPORTS" /D "COMPRESS_MF_MT" /D "_7ZIP_LARGE_PAGES" /Yu"StdAfx.h" /FD /GZ /c
-# ADD BASE MTL /nologo /D "_DEBUG" /mktyplib203 /win32
-# ADD MTL /nologo /D "_DEBUG" /mktyplib203 /win32
-# ADD BASE RSC /l 0x419 /d "_DEBUG"
-# ADD RSC /l 0x419 /d "_DEBUG"
-BSC32=bscmake.exe
-# ADD BASE BSC32 /nologo
-# ADD BSC32 /nologo
-LINK32=link.exe
-# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /dll /debug /machine:I386 /pdbtype:sept
-# ADD LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /dll /debug /machine:I386 /out:"C:\Program Files\7-zip\Codecs\LZMA.dll" /pdbtype:sept
-
-!ENDIF
-
-# Begin Target
-
-# Name "LZMA - Win32 Release"
-# Name "LZMA - Win32 Debug"
-# Begin Group "Spec"
-
-# PROP Default_Filter ""
-# Begin Source File
-
-SOURCE=..\Codec.def
-# End Source File
-# Begin Source File
-
-SOURCE=..\CodecExports.cpp
-# End Source File
-# Begin Source File
-
-SOURCE=..\DllExports.cpp
-# End Source File
-# Begin Source File
-
-SOURCE=.\resource.rc
-# End Source File
-# Begin Source File
-
-SOURCE=.\StdAfx.cpp
-# ADD CPP /Yc"StdAfx.h"
-# End Source File
-# Begin Source File
-
-SOURCE=.\StdAfx.h
-# End Source File
-# End Group
-# Begin Group "7-zip Common"
-
-# PROP Default_Filter ""
-# Begin Source File
-
-SOURCE=..\..\Common\InBuffer.cpp
-# End Source File
-# Begin Source File
-
-SOURCE=..\..\Common\InBuffer.h
-# End Source File
-# Begin Source File
-
-SOURCE=..\..\Common\OutBuffer.cpp
-# End Source File
-# Begin Source File
-
-SOURCE=..\..\Common\OutBuffer.h
-# End Source File
-# Begin Source File
-
-SOURCE=..\..\Common\StreamUtils.cpp
-# End Source File
-# Begin Source File
-
-SOURCE=..\..\Common\StreamUtils.h
-# End Source File
-# End Group
-# Begin Group "RangeCoder"
-
-# PROP Default_Filter ""
-# Begin Source File
-
-SOURCE=..\RangeCoder\RangeCoder.h
-# End Source File
-# Begin Source File
-
-SOURCE=..\RangeCoder\RangeCoderBit.cpp
-# End Source File
-# Begin Source File
-
-SOURCE=..\RangeCoder\RangeCoderBit.h
-# End Source File
-# Begin Source File
-
-SOURCE=..\RangeCoder\RangeCoderBitTree.h
-# End Source File
-# Begin Source File
-
-SOURCE=..\RangeCoder\RangeCoderOpt.h
-# End Source File
-# End Group
-# Begin Group "Interface"
-
-# PROP Default_Filter ""
-# Begin Source File
-
-SOURCE=..\..\ICoder.h
-# End Source File
-# Begin Source File
-
-SOURCE=..\..\IStream.h
-# End Source File
-# End Group
-# Begin Group "LZ"
-
-# PROP Default_Filter ""
-# Begin Source File
-
-SOURCE=..\LZ\LZOutWindow.cpp
-# End Source File
-# Begin Source File
-
-SOURCE=..\LZ\LZOutWindow.h
-# End Source File
-# End Group
-# Begin Group "Common"
-
-# PROP Default_Filter ""
-# Begin Source File
-
-SOURCE=..\..\..\Common\ComTry.h
-# End Source File
-# Begin Source File
-
-SOURCE=..\..\..\Common\Defs.h
-# End Source File
-# Begin Source File
-
-SOURCE=..\..\..\Common\Exception.h
-# End Source File
-# Begin Source File
-
-SOURCE=..\..\..\Common\MyCom.h
-# End Source File
-# Begin Source File
-
-SOURCE=..\..\..\Common\MyUnknown.h
-# End Source File
-# Begin Source File
-
-SOURCE=..\..\..\Common\MyWindows.h
-# End Source File
-# End Group
-# Begin Group "C"
-
-# PROP Default_Filter ""
-# Begin Group "C_Lz"
-
-# PROP Default_Filter ""
-# Begin Source File
-
-SOURCE=..\..\..\..\C\Compress\Lz\LzHash.h
-# End Source File
-# Begin Source File
-
-SOURCE=..\..\..\..\C\Compress\Lz\MatchFinder.c
-
-!IF "$(CFG)" == "LZMA - Win32 Release"
-
-# ADD CPP /O2
-# SUBTRACT CPP /YX /Yc /Yu
-
-!ELSEIF "$(CFG)" == "LZMA - Win32 Debug"
-
-# SUBTRACT CPP /YX /Yc /Yu
-
-!ENDIF
-
-# End Source File
-# Begin Source File
-
-SOURCE=..\..\..\..\C\Compress\Lz\MatchFinder.h
-# End Source File
-# Begin Source File
-
-SOURCE=..\..\..\..\C\Compress\Lz\MatchFinderMt.c
-
-!IF "$(CFG)" == "LZMA - Win32 Release"
-
-# ADD CPP /O2
-# SUBTRACT CPP /YX /Yc /Yu
-
-!ELSEIF "$(CFG)" == "LZMA - Win32 Debug"
-
-# SUBTRACT CPP /YX /Yc /Yu
-
-!ENDIF
-
-# End Source File
-# Begin Source File
-
-SOURCE=..\..\..\..\C\Compress\Lz\MatchFinderMt.h
-# End Source File
-# End Group
-# Begin Source File
-
-SOURCE=..\..\..\..\C\7zCrc.c
-
-!IF "$(CFG)" == "LZMA - Win32 Release"
-
-# ADD CPP /O2
-# SUBTRACT CPP /YX /Yc /Yu
-
-!ELSEIF "$(CFG)" == "LZMA - Win32 Debug"
-
-# SUBTRACT CPP /YX /Yc /Yu
-
-!ENDIF
-
-# End Source File
-# Begin Source File
-
-SOURCE=..\..\..\..\C\7zCrc.h
-# End Source File
-# Begin Source File
-
-SOURCE=..\..\..\..\C\Alloc.c
-# SUBTRACT CPP /YX /Yc /Yu
-# End Source File
-# Begin Source File
-
-SOURCE=..\..\..\..\C\Alloc.h
-# End Source File
-# Begin Source File
-
-SOURCE=..\..\..\..\C\IStream.h
-# End Source File
-# Begin Source File
-
-SOURCE=..\..\..\..\C\Threads.c
-# SUBTRACT CPP /YX /Yc /Yu
-# End Source File
-# Begin Source File
-
-SOURCE=..\..\..\..\C\Threads.h
-# End Source File
-# Begin Source File
-
-SOURCE=..\..\..\..\C\Types.h
-# End Source File
-# End Group
-# Begin Source File
-
-SOURCE=.\LZMA.h
-# End Source File
-# Begin Source File
-
-SOURCE=.\LZMADecoder.cpp
-
-!IF "$(CFG)" == "LZMA - Win32 Release"
-
-# ADD CPP /O2
-# SUBTRACT CPP /YX /Yc /Yu
-
-!ELSEIF "$(CFG)" == "LZMA - Win32 Debug"
-
-!ENDIF
-
-# End Source File
-# Begin Source File
-
-SOURCE=.\LZMADecoder.h
-# End Source File
-# Begin Source File
-
-SOURCE=.\LZMAEncoder.cpp
-
-!IF "$(CFG)" == "LZMA - Win32 Release"
-
-# ADD CPP /O2 /FAs
-# SUBTRACT CPP /YX /Yc /Yu
-
-!ELSEIF "$(CFG)" == "LZMA - Win32 Debug"
-
-!ENDIF
-
-# End Source File
-# Begin Source File
-
-SOURCE=.\LZMAEncoder.h
-# End Source File
-# Begin Source File
-
-SOURCE=.\LZMARegister.cpp
-# End Source File
-# End Target
-# End Project
diff --git a/CPP/7zip/Compress/LZMA/LZMA.dsw b/CPP/7zip/Compress/LZMA/LZMA.dsw
deleted file mode 100755
index f750e453..00000000
--- a/CPP/7zip/Compress/LZMA/LZMA.dsw
+++ /dev/null
@@ -1,29 +0,0 @@
-Microsoft Developer Studio Workspace File, Format Version 6.00
-# WARNING: DO NOT EDIT OR DELETE THIS WORKSPACE FILE!
-
-###############################################################################
-
-Project: "LZMA"=".\LZMA.dsp" - Package Owner=<4>
-
-Package=<5>
-{{{
-}}}
-
-Package=<4>
-{{{
-}}}
-
-###############################################################################
-
-Global:
-
-Package=<5>
-{{{
-}}}
-
-Package=<3>
-{{{
-}}}
-
-###############################################################################
-
diff --git a/CPP/7zip/Compress/LZMA/LZMA.h b/CPP/7zip/Compress/LZMA/LZMA.h
deleted file mode 100755
index 7bc4c438..00000000
--- a/CPP/7zip/Compress/LZMA/LZMA.h
+++ /dev/null
@@ -1,82 +0,0 @@
-// LZMA.h
-
-#ifndef __LZMA_H
-#define __LZMA_H
-
-namespace NCompress {
-namespace NLZMA {
-
-const UInt32 kNumRepDistances = 4;
-
-const int kNumStates = 12;
-
-const Byte kLiteralNextStates[kNumStates] = {0, 0, 0, 0, 1, 2, 3, 4, 5, 6, 4, 5};
-const Byte kMatchNextStates[kNumStates] = {7, 7, 7, 7, 7, 7, 7, 10, 10, 10, 10, 10};
-const Byte kRepNextStates[kNumStates] = {8, 8, 8, 8, 8, 8, 8, 11, 11, 11, 11, 11};
-const Byte kShortRepNextStates[kNumStates]= {9, 9, 9, 9, 9, 9, 9, 11, 11, 11, 11, 11};
-
-class CState
-{
-public:
- Byte Index;
- void Init() { Index = 0; }
- void UpdateChar() { Index = kLiteralNextStates[Index]; }
- void UpdateMatch() { Index = kMatchNextStates[Index]; }
- void UpdateRep() { Index = kRepNextStates[Index]; }
- void UpdateShortRep() { Index = kShortRepNextStates[Index]; }
- bool IsCharState() const { return Index < 7; }
-};
-
-const int kNumPosSlotBits = 6;
-const int kDicLogSizeMin = 0;
-const int kDicLogSizeMax = 32;
-const int kDistTableSizeMax = kDicLogSizeMax * 2;
-
-const UInt32 kNumLenToPosStates = 4;
-
-inline UInt32 GetLenToPosState(UInt32 len)
-{
- len -= 2;
- if (len < kNumLenToPosStates)
- return len;
- return kNumLenToPosStates - 1;
-}
-
-namespace NLength {
-
-const int kNumPosStatesBitsMax = 4;
-const UInt32 kNumPosStatesMax = (1 << kNumPosStatesBitsMax);
-
-const int kNumPosStatesBitsEncodingMax = 4;
-const UInt32 kNumPosStatesEncodingMax = (1 << kNumPosStatesBitsEncodingMax);
-
-const int kNumLowBits = 3;
-const int kNumMidBits = 3;
-const int kNumHighBits = 8;
-const UInt32 kNumLowSymbols = 1 << kNumLowBits;
-const UInt32 kNumMidSymbols = 1 << kNumMidBits;
-const UInt32 kNumSymbolsTotal = kNumLowSymbols + kNumMidSymbols + (1 << kNumHighBits);
-
-}
-
-const UInt32 kMatchMinLen = 2;
-const UInt32 kMatchMaxLen = kMatchMinLen + NLength::kNumSymbolsTotal - 1;
-
-const int kNumAlignBits = 4;
-const UInt32 kAlignTableSize = 1 << kNumAlignBits;
-const UInt32 kAlignMask = (kAlignTableSize - 1);
-
-const UInt32 kStartPosModelIndex = 4;
-const UInt32 kEndPosModelIndex = 14;
-const UInt32 kNumPosModels = kEndPosModelIndex - kStartPosModelIndex;
-
-const UInt32 kNumFullDistances = 1 << (kEndPosModelIndex / 2);
-
-const int kNumLitPosStatesBitsEncodingMax = 4;
-const int kNumLitContextBitsMax = 8;
-
-const int kNumMoveBits = 5;
-
-}}
-
-#endif
diff --git a/CPP/7zip/Compress/LZMA/LZMADecoder.cpp b/CPP/7zip/Compress/LZMA/LZMADecoder.cpp
index 1b73855c..1df7fe6c 100755
--- a/CPP/7zip/Compress/LZMA/LZMADecoder.cpp
+++ b/CPP/7zip/Compress/LZMA/LZMADecoder.cpp
@@ -4,333 +4,187 @@
#include "LZMADecoder.h"
#include "../../../Common/Defs.h"
+#include "../../Common/StreamUtils.h"
+
+extern "C"
+{
+ #include "../../../../C/Alloc.h"
+}
+
+static HRESULT SResToHRESULT(SRes res)
+{
+ switch(res)
+ {
+ case SZ_OK: return S_OK;
+ case SZ_ERROR_MEM: return E_OUTOFMEMORY;
+ case SZ_ERROR_PARAM: return E_INVALIDARG;
+ // case SZ_ERROR_PROGRESS: return E_ABORT;
+ case SZ_ERROR_DATA: return S_FALSE;
+ }
+ return E_FAIL;
+}
namespace NCompress {
namespace NLZMA {
-const int kLenIdFinished = -1;
-const int kLenIdNeedInit = -2;
+static const UInt32 kInBufSize = 1 << 20;
-void CDecoder::Init()
+CDecoder::CDecoder(): _inBuf(0), _outSizeDefined(false)
{
- {
- for(int i = 0; i < kNumStates; i++)
- {
- for (UInt32 j = 0; j <= _posStateMask; j++)
- {
- _isMatch[i][j].Init();
- _isRep0Long[i][j].Init();
- }
- _isRep[i].Init();
- _isRepG0[i].Init();
- _isRepG1[i].Init();
- _isRepG2[i].Init();
- }
- }
- {
- for (UInt32 i = 0; i < kNumLenToPosStates; i++)
- _posSlotDecoder[i].Init();
- }
- {
- for(UInt32 i = 0; i < kNumFullDistances - kEndPosModelIndex; i++)
- _posDecoders[i].Init();
- }
- _posAlignDecoder.Init();
- _lenDecoder.Init(_posStateMask + 1);
- _repMatchLenDecoder.Init(_posStateMask + 1);
- _literalDecoder.Init();
-
- _state.Init();
- _reps[0] = _reps[1] = _reps[2] = _reps[3] = 0;
+ LzmaDec_Construct(&_state);
}
-HRESULT CDecoder::CodeSpec(UInt32 curSize)
-{
- if (_outSizeDefined)
- {
- const UInt64 rem = _outSize - _outWindowStream.GetProcessedSize();
- if (curSize > rem)
- curSize = (UInt32)rem;
- }
+static void *SzAlloc(void *p, size_t size) { p = p; return MyAlloc(size); }
+static void SzFree(void *p, void *address) { p = p; MyFree(address); }
+static ISzAlloc g_Alloc = { SzAlloc, SzFree };
- if (_remainLen == kLenIdFinished)
- return S_OK;
- if (_remainLen == kLenIdNeedInit)
- {
- _rangeDecoder.Init();
- Init();
- _remainLen = 0;
- }
- if (curSize == 0)
- return S_OK;
+CDecoder::~CDecoder()
+{
+ LzmaDec_Free(&_state, &g_Alloc);
+ MyFree(_inBuf);
+}
- UInt32 rep0 = _reps[0];
- UInt32 rep1 = _reps[1];
- UInt32 rep2 = _reps[2];
- UInt32 rep3 = _reps[3];
- CState state = _state;
- Byte previousByte;
+STDMETHODIMP CDecoder::SetDecoderProperties2(const Byte *prop, UInt32 size)
+{
+ RINOK(SResToHRESULT(LzmaDec_Allocate(&_state, prop, size, &g_Alloc)));
- while(_remainLen > 0 && curSize > 0)
+ if (_inBuf == 0)
{
- previousByte = _outWindowStream.GetByte(rep0);
- _outWindowStream.PutByte(previousByte);
- _remainLen--;
- curSize--;
+ _inBuf = (Byte *)MyAlloc(kInBufSize);
+ if (_inBuf == 0)
+ return E_OUTOFMEMORY;
}
- UInt64 nowPos64 = _outWindowStream.GetProcessedSize();
- if (nowPos64 == 0)
- previousByte = 0;
- else
- previousByte = _outWindowStream.GetByte(0);
- while(curSize > 0)
- {
- {
- #ifdef _NO_EXCEPTIONS
- if (_rangeDecoder.Stream.ErrorCode != S_OK)
- return _rangeDecoder.Stream.ErrorCode;
- #endif
- if (_rangeDecoder.Stream.WasFinished())
- return S_FALSE;
- UInt32 posState = UInt32(nowPos64) & _posStateMask;
- if (_isMatch[state.Index][posState].Decode(&_rangeDecoder) == 0)
- {
- if(!state.IsCharState())
- previousByte = _literalDecoder.DecodeWithMatchByte(&_rangeDecoder,
- (UInt32)nowPos64, previousByte, _outWindowStream.GetByte(rep0));
- else
- previousByte = _literalDecoder.DecodeNormal(&_rangeDecoder,
- (UInt32)nowPos64, previousByte);
- _outWindowStream.PutByte(previousByte);
- state.UpdateChar();
- curSize--;
- nowPos64++;
- }
- else
- {
- UInt32 len;
- if(_isRep[state.Index].Decode(&_rangeDecoder) == 1)
- {
- len = 0;
- if(_isRepG0[state.Index].Decode(&_rangeDecoder) == 0)
- {
- if(_isRep0Long[state.Index][posState].Decode(&_rangeDecoder) == 0)
- {
- state.UpdateShortRep();
- len = 1;
- }
- }
- else
- {
- UInt32 distance;
- if(_isRepG1[state.Index].Decode(&_rangeDecoder) == 0)
- distance = rep1;
- else
- {
- if (_isRepG2[state.Index].Decode(&_rangeDecoder) == 0)
- distance = rep2;
- else
- {
- distance = rep3;
- rep3 = rep2;
- }
- rep2 = rep1;
- }
- rep1 = rep0;
- rep0 = distance;
- }
- if (len == 0)
- {
- len = _repMatchLenDecoder.Decode(&_rangeDecoder, posState) + kMatchMinLen;
- state.UpdateRep();
- }
- }
- else
- {
- rep3 = rep2;
- rep2 = rep1;
- rep1 = rep0;
- len = kMatchMinLen + _lenDecoder.Decode(&_rangeDecoder, posState);
- state.UpdateMatch();
- UInt32 posSlot = _posSlotDecoder[GetLenToPosState(len)].Decode(&_rangeDecoder);
- if (posSlot >= kStartPosModelIndex)
- {
- UInt32 numDirectBits = (posSlot >> 1) - 1;
- rep0 = ((2 | (posSlot & 1)) << numDirectBits);
+ return S_OK;
+}
- if (posSlot < kEndPosModelIndex)
- rep0 += NRangeCoder::ReverseBitTreeDecode(_posDecoders +
- rep0 - posSlot - 1, &_rangeDecoder, numDirectBits);
- else
- {
- rep0 += (_rangeDecoder.DecodeDirectBits(
- numDirectBits - kNumAlignBits) << kNumAlignBits);
- rep0 += _posAlignDecoder.ReverseDecode(&_rangeDecoder);
- if (rep0 == 0xFFFFFFFF)
- {
- _remainLen = kLenIdFinished;
- return S_OK;
- }
- }
- }
- else
- rep0 = posSlot;
- }
- UInt32 locLen = len;
- if (len > curSize)
- locLen = (UInt32)curSize;
- if (!_outWindowStream.CopyBlock(rep0, locLen))
- return S_FALSE;
- previousByte = _outWindowStream.GetByte(0);
- curSize -= locLen;
- nowPos64 += locLen;
- len -= locLen;
- if (len != 0)
- {
- _remainLen = (Int32)len;
- break;
- }
+STDMETHODIMP CDecoder::GetInStreamProcessedSize(UInt64 *value) { *value = _inSizeProcessed; return S_OK; }
+STDMETHODIMP CDecoder::SetInStream(ISequentialInStream *inStream) { _inStream = inStream; return S_OK; }
+STDMETHODIMP CDecoder::ReleaseInStream() { _inStream.Release(); return S_OK; }
- #ifdef _NO_EXCEPTIONS
- if (_outWindowStream.ErrorCode != S_OK)
- return _outWindowStream.ErrorCode;
- #endif
- }
- }
- }
- if (_rangeDecoder.Stream.WasFinished())
- return S_FALSE;
- _reps[0] = rep0;
- _reps[1] = rep1;
- _reps[2] = rep2;
- _reps[3] = rep3;
- _state = state;
+STDMETHODIMP CDecoder::SetOutStreamSize(const UInt64 *outSize)
+{
+ _outSizeDefined = (outSize != NULL);
+ if (_outSizeDefined)
+ _outSize = *outSize;
+ LzmaDec_Init(&_state);
+
+ _inPos = _inSize = 0;
+ _inSizeProcessed = _outSizeProcessed = 0;
return S_OK;
}
-STDMETHODIMP CDecoder::CodeReal(ISequentialInStream *inStream,
- ISequentialOutStream *outStream,
- const UInt64 *, const UInt64 *outSize,
- ICompressProgressInfo *progress)
+STDMETHODIMP CDecoder::Code(ISequentialInStream *inStream,
+ ISequentialOutStream *outStream, const UInt64 * /* inSize */,
+ const UInt64 *outSize, ICompressProgressInfo *progress)
{
- SetInStream(inStream);
- _outWindowStream.SetStream(outStream);
+ if (_inBuf == 0)
+ return S_FALSE;
SetOutStreamSize(outSize);
- CDecoderFlusher flusher(this);
for (;;)
{
- UInt32 curSize = 1 << 18;
- RINOK(CodeSpec(curSize));
- if (_remainLen == kLenIdFinished)
- break;
- if (progress != NULL)
+ if (_inPos == _inSize)
{
- UInt64 inSize = _rangeDecoder.GetProcessedSize();
- UInt64 nowPos64 = _outWindowStream.GetProcessedSize();
- RINOK(progress->SetRatioInfo(&inSize, &nowPos64));
+ _inPos = _inSize = 0;
+ RINOK(inStream->Read(_inBuf, kInBufSize, &_inSize));
}
- if (_outSizeDefined)
- if (_outWindowStream.GetProcessedSize() >= _outSize)
- break;
- }
- flusher.NeedFlush = false;
- return Flush();
-}
-
-
-#ifdef _NO_EXCEPTIONS
-
-#define LZMA_TRY_BEGIN
-#define LZMA_TRY_END
-
-#else
-#define LZMA_TRY_BEGIN try {
-#define LZMA_TRY_END } \
- catch(const CInBufferException &e) { return e.ErrorCode; } \
- catch(const CLZOutWindowException &e) { return e.ErrorCode; } \
- catch(...) { return S_FALSE; }
+ SizeT dicPos = _state.dicPos;
+ SizeT curSize = _state.dicBufSize - dicPos;
+ const UInt32 kStepSize = ((UInt32)1 << 22);
+ if (curSize > kStepSize)
+ curSize = (SizeT)kStepSize;
+
+ ELzmaFinishMode finishMode = LZMA_FINISH_ANY;
+ if (_outSizeDefined)
+ {
+ const UInt64 rem = _outSize - _outSizeProcessed;
+ if (rem < curSize)
+ {
+ curSize = (SizeT)rem;
+ /*
+ // finishMode = LZMA_FINISH_END;
+ we can't use LZMA_FINISH_END here to allow partial decoding
+ */
+ }
+ }
-#endif
+ SizeT inSizeProcessed = _inSize - _inPos;
+ ELzmaStatus status;
+ SRes res = LzmaDec_DecodeToDic(&_state, dicPos + curSize, _inBuf + _inPos, &inSizeProcessed, finishMode, &status);
+ _inPos += (UInt32)inSizeProcessed;
+ _inSizeProcessed += inSizeProcessed;
+ SizeT outSizeProcessed = _state.dicPos - dicPos;
+ _outSizeProcessed += outSizeProcessed;
-STDMETHODIMP CDecoder::Code(ISequentialInStream *inStream,
- ISequentialOutStream *outStream, const UInt64 *inSize, const UInt64 *outSize,
- ICompressProgressInfo *progress)
-{
- LZMA_TRY_BEGIN
- return CodeReal(inStream, outStream, inSize, outSize, progress);
- LZMA_TRY_END
-}
-
-STDMETHODIMP CDecoder::SetDecoderProperties2(const Byte *properties, UInt32 size)
-{
- if (size < 5)
- return E_INVALIDARG;
- int lc = properties[0] % 9;
- Byte remainder = (Byte)(properties[0] / 9);
- int lp = remainder % 5;
- int pb = remainder / 5;
- if (pb > NLength::kNumPosStatesBitsMax)
- return E_INVALIDARG;
- _posStateMask = (1 << pb) - 1;
- UInt32 dictionarySize = 0;
- for (int i = 0; i < 4; i++)
- dictionarySize += ((UInt32)(properties[1 + i])) << (i * 8);
- if (!_outWindowStream.Create(dictionarySize))
- return E_OUTOFMEMORY;
- if (!_literalDecoder.Create(lp, lc))
- return E_OUTOFMEMORY;
- if (!_rangeDecoder.Create(1 << 20))
- return E_OUTOFMEMORY;
- return S_OK;
-}
+ bool finished = (inSizeProcessed == 0 && outSizeProcessed == 0);
+ bool stopDecoding = (_outSizeDefined && _outSizeProcessed >= _outSize);
-STDMETHODIMP CDecoder::GetInStreamProcessedSize(UInt64 *value)
-{
- *value = _rangeDecoder.GetProcessedSize();
- return S_OK;
-}
-
-STDMETHODIMP CDecoder::SetInStream(ISequentialInStream *inStream)
-{
- _rangeDecoder.SetStream(inStream);
- return S_OK;
-}
-
-STDMETHODIMP CDecoder::ReleaseInStream()
-{
- _rangeDecoder.ReleaseStream();
- return S_OK;
-}
+ if (res != 0 || _state.dicPos == _state.dicBufSize || finished || stopDecoding)
+ {
+ HRESULT res2 = WriteStream(outStream, _state.dic, _state.dicPos);
+ if (res != 0)
+ return S_FALSE;
+ RINOK(res2);
+ if (stopDecoding)
+ return S_OK;
+ if (finished)
+ return (status == LZMA_STATUS_FINISHED_WITH_MARK ? S_OK : S_FALSE);
+ }
+ if (_state.dicPos == _state.dicBufSize)
+ _state.dicPos = 0;
-STDMETHODIMP CDecoder::SetOutStreamSize(const UInt64 *outSize)
-{
- _outSizeDefined = (outSize != NULL);
- if (_outSizeDefined)
- _outSize = *outSize;
- _remainLen = kLenIdNeedInit;
- _outWindowStream.Init();
- return S_OK;
+ if (progress != NULL)
+ {
+ RINOK(progress->SetRatioInfo(&_inSizeProcessed, &_outSizeProcessed));
+ }
+ }
}
#ifndef NO_READ_FROM_CODER
STDMETHODIMP CDecoder::Read(void *data, UInt32 size, UInt32 *processedSize)
{
- LZMA_TRY_BEGIN
if (processedSize)
*processedSize = 0;
- const UInt64 startPos = _outWindowStream.GetProcessedSize();
- _outWindowStream.SetMemStream((Byte *)data);
- RINOK(CodeSpec(size));
- if (processedSize)
- *processedSize = (UInt32)(_outWindowStream.GetProcessedSize() - startPos);
- return Flush();
- LZMA_TRY_END
+ do
+ {
+ if (_inPos == _inSize)
+ {
+ _inPos = _inSize = 0;
+ RINOK(_inStream->Read(_inBuf, kInBufSize, &_inSize));
+ }
+ {
+ SizeT inProcessed = _inSize - _inPos;
+
+ if (_outSizeDefined)
+ {
+ const UInt64 rem = _outSize - _outSizeProcessed;
+ if (rem < size)
+ size = (UInt32)rem;
+ }
+
+ SizeT outProcessed = size;
+ ELzmaStatus status;
+ SRes res = LzmaDec_DecodeToBuf(&_state, (Byte *)data, &outProcessed,
+ _inBuf + _inPos, &inProcessed, LZMA_FINISH_ANY, &status);
+ _inPos += (UInt32)inProcessed;
+ _inSizeProcessed += inProcessed;
+ _outSizeProcessed += outProcessed;
+ size -= (UInt32)outProcessed;
+ data = (Byte *)data + outProcessed;
+ if (processedSize)
+ *processedSize += (UInt32)outProcessed;
+ RINOK(SResToHRESULT(res));
+ if (inProcessed == 0 && outProcessed == 0)
+ return S_OK;
+ }
+ }
+ while (size != 0);
+ return S_OK;
}
#endif
diff --git a/CPP/7zip/Compress/LZMA/LZMADecoder.h b/CPP/7zip/Compress/LZMA/LZMADecoder.h
index bc44a5a9..be5df30d 100755
--- a/CPP/7zip/Compress/LZMA/LZMADecoder.h
+++ b/CPP/7zip/Compress/LZMA/LZMADecoder.h
@@ -1,151 +1,19 @@
-// LZMA/Decoder.h
+// LZMADecoder.h
#ifndef __LZMA_DECODER_H
#define __LZMA_DECODER_H
#include "../../../Common/MyCom.h"
#include "../../ICoder.h"
-#include "../LZ/LZOutWindow.h"
-#include "../RangeCoder/RangeCoderBitTree.h"
extern "C"
{
- #include "../../../../C/Alloc.h"
+ #include "../../../../C/LzmaDec.h"
}
-#include "LZMA.h"
-
namespace NCompress {
namespace NLZMA {
-typedef NRangeCoder::CBitDecoder<kNumMoveBits> CMyBitDecoder;
-
-class CLiteralDecoder2
-{
- CMyBitDecoder _decoders[0x300];
-public:
- void Init()
- {
- for (int i = 0; i < 0x300; i++)
- _decoders[i].Init();
- }
- Byte DecodeNormal(NRangeCoder::CDecoder *rangeDecoder)
- {
- UInt32 symbol = 1;
- RC_INIT_VAR
- do
- {
- // symbol = (symbol << 1) | _decoders[0][symbol].Decode(rangeDecoder);
- RC_GETBIT(kNumMoveBits, _decoders[symbol].Prob, symbol)
- }
- while (symbol < 0x100);
- RC_FLUSH_VAR
- return (Byte)symbol;
- }
- Byte DecodeWithMatchByte(NRangeCoder::CDecoder *rangeDecoder, Byte matchByte)
- {
- UInt32 symbol = 1;
- RC_INIT_VAR
- do
- {
- UInt32 matchBit = (matchByte >> 7) & 1;
- matchByte <<= 1;
- // UInt32 bit = _decoders[1 + matchBit][symbol].Decode(rangeDecoder);
- // symbol = (symbol << 1) | bit;
- UInt32 bit;
- RC_GETBIT2(kNumMoveBits, _decoders[0x100 + (matchBit << 8) + symbol].Prob, symbol,
- bit = 0, bit = 1)
- if (matchBit != bit)
- {
- while (symbol < 0x100)
- {
- // symbol = (symbol << 1) | _decoders[0][symbol].Decode(rangeDecoder);
- RC_GETBIT(kNumMoveBits, _decoders[symbol].Prob, symbol)
- }
- break;
- }
- }
- while (symbol < 0x100);
- RC_FLUSH_VAR
- return (Byte)symbol;
- }
-};
-
-class CLiteralDecoder
-{
- CLiteralDecoder2 *_coders;
- int _numPrevBits;
- int _numPosBits;
- UInt32 _posMask;
-public:
- CLiteralDecoder(): _coders(0) {}
- ~CLiteralDecoder() { Free(); }
- void Free()
- {
- MyFree(_coders);
- _coders = 0;
- }
- bool Create(int numPosBits, int numPrevBits)
- {
- if (_coders == 0 || (numPosBits + numPrevBits) !=
- (_numPrevBits + _numPosBits) )
- {
- Free();
- UInt32 numStates = 1 << (numPosBits + numPrevBits);
- _coders = (CLiteralDecoder2 *)MyAlloc(numStates * sizeof(CLiteralDecoder2));
- }
- _numPosBits = numPosBits;
- _posMask = (1 << numPosBits) - 1;
- _numPrevBits = numPrevBits;
- return (_coders != 0);
- }
- void Init()
- {
- UInt32 numStates = 1 << (_numPrevBits + _numPosBits);
- for (UInt32 i = 0; i < numStates; i++)
- _coders[i].Init();
- }
- UInt32 GetState(UInt32 pos, Byte prevByte) const
- { return ((pos & _posMask) << _numPrevBits) + (prevByte >> (8 - _numPrevBits)); }
- Byte DecodeNormal(NRangeCoder::CDecoder *rangeDecoder, UInt32 pos, Byte prevByte)
- { return _coders[GetState(pos, prevByte)].DecodeNormal(rangeDecoder); }
- Byte DecodeWithMatchByte(NRangeCoder::CDecoder *rangeDecoder, UInt32 pos, Byte prevByte, Byte matchByte)
- { return _coders[GetState(pos, prevByte)].DecodeWithMatchByte(rangeDecoder, matchByte); }
-};
-
-namespace NLength {
-
-class CDecoder
-{
- CMyBitDecoder _choice;
- CMyBitDecoder _choice2;
- NRangeCoder::CBitTreeDecoder<kNumMoveBits, kNumLowBits> _lowCoder[kNumPosStatesMax];
- NRangeCoder::CBitTreeDecoder<kNumMoveBits, kNumMidBits> _midCoder[kNumPosStatesMax];
- NRangeCoder::CBitTreeDecoder<kNumMoveBits, kNumHighBits> _highCoder;
-public:
- void Init(UInt32 numPosStates)
- {
- _choice.Init();
- _choice2.Init();
- for (UInt32 posState = 0; posState < numPosStates; posState++)
- {
- _lowCoder[posState].Init();
- _midCoder[posState].Init();
- }
- _highCoder.Init();
- }
- UInt32 Decode(NRangeCoder::CDecoder *rangeDecoder, UInt32 posState)
- {
- if(_choice.Decode(rangeDecoder) == 0)
- return _lowCoder[posState].Decode(rangeDecoder);
- if(_choice2.Decode(rangeDecoder) == 0)
- return kNumLowSymbols + _midCoder[posState].Decode(rangeDecoder);
- return kNumLowSymbols + kNumMidSymbols + _highCoder.Decode(rangeDecoder);
- }
-};
-
-}
-
class CDecoder:
public ICompressCoder,
public ICompressSetDecoderProperties2,
@@ -157,38 +25,15 @@ class CDecoder:
#endif
public CMyUnknownImp
{
- CLZOutWindow _outWindowStream;
- NRangeCoder::CDecoder _rangeDecoder;
-
- CMyBitDecoder _isMatch[kNumStates][NLength::kNumPosStatesMax];
- CMyBitDecoder _isRep[kNumStates];
- CMyBitDecoder _isRepG0[kNumStates];
- CMyBitDecoder _isRepG1[kNumStates];
- CMyBitDecoder _isRepG2[kNumStates];
- CMyBitDecoder _isRep0Long[kNumStates][NLength::kNumPosStatesMax];
-
- NRangeCoder::CBitTreeDecoder<kNumMoveBits, kNumPosSlotBits> _posSlotDecoder[kNumLenToPosStates];
-
- CMyBitDecoder _posDecoders[kNumFullDistances - kEndPosModelIndex];
- NRangeCoder::CBitTreeDecoder<kNumMoveBits, kNumAlignBits> _posAlignDecoder;
-
- NLength::CDecoder _lenDecoder;
- NLength::CDecoder _repMatchLenDecoder;
-
- CLiteralDecoder _literalDecoder;
-
- UInt32 _posStateMask;
-
- ///////////////////
- // State
- UInt32 _reps[4];
- CState _state;
- Int32 _remainLen; // -1 means end of stream. // -2 means need Init
- UInt64 _outSize;
+ CMyComPtr<ISequentialInStream> _inStream;
+ Byte *_inBuf;
+ UInt32 _inPos;
+ UInt32 _inSize;
+ CLzmaDec _state;
bool _outSizeDefined;
-
- void Init();
- HRESULT CodeSpec(UInt32 size);
+ UInt64 _outSize;
+ UInt64 _inSizeProcessed;
+ UInt64 _outSizeProcessed;
public:
#ifndef NO_READ_FROM_CODER
@@ -204,34 +49,8 @@ public:
ICompressGetInStreamProcessedSize)
#endif
- void ReleaseStreams()
- {
- _outWindowStream.ReleaseStream();
- ReleaseInStream();
- }
-
- class CDecoderFlusher
- {
- CDecoder *_decoder;
- public:
- bool NeedFlush;
- CDecoderFlusher(CDecoder *decoder): _decoder(decoder), NeedFlush(true) {}
- ~CDecoderFlusher()
- {
- if (NeedFlush)
- _decoder->Flush();
- _decoder->ReleaseStreams();
- }
- };
-
- HRESULT Flush() { return _outWindowStream.Flush(); }
-
- STDMETHOD(CodeReal)(ISequentialInStream *inStream,
- ISequentialOutStream *outStream, const UInt64 *inSize, const UInt64 *outSize,
- ICompressProgressInfo *progress);
-
STDMETHOD(Code)(ISequentialInStream *inStream,
- ISequentialOutStream *outStream, const UInt64 *inSize, const UInt64 *outSize,
+ ISequentialOutStream *outStream, const UInt64 *_inSize, const UInt64 *outSize,
ICompressProgressInfo *progress);
STDMETHOD(SetDecoderProperties2)(const Byte *data, UInt32 size);
@@ -246,8 +65,9 @@ public:
STDMETHOD(Read)(void *data, UInt32 size, UInt32 *processedSize);
#endif
- CDecoder(): _outSizeDefined(false) {}
- virtual ~CDecoder() {}
+ CDecoder();
+ virtual ~CDecoder();
+
};
}}
diff --git a/CPP/7zip/Compress/LZMA/LZMAEncoder.cpp b/CPP/7zip/Compress/LZMA/LZMAEncoder.cpp
index 021099d8..25faa730 100755
--- a/CPP/7zip/Compress/LZMA/LZMAEncoder.cpp
+++ b/CPP/7zip/Compress/LZMA/LZMAEncoder.cpp
@@ -16,255 +16,71 @@
#endif
#endif
-#include "../../../Common/Defs.h"
-#include "../../Common/StreamUtils.h"
-
#include "LZMAEncoder.h"
-// extern "C" { #include "../../../../C/7zCrc.h" }
-
-// #define SHOW_STAT
-
-
-namespace NCompress {
-namespace NLZMA {
-
-// struct CCrcInit { CCrcInit() { InitCrcTable(); } } g_CrcInit;
-
-const int kDefaultDictionaryLogSize = 22;
-const UInt32 kNumFastBytesDefault = 0x20;
-
-#ifndef LZMA_LOG_BSR
-Byte g_FastPos[1 << kNumLogBits];
-
-class CFastPosInit
-{
-public:
- CFastPosInit() { Init(); }
- void Init()
- {
- const Byte kFastSlots = kNumLogBits * 2;
- int c = 2;
- g_FastPos[0] = 0;
- g_FastPos[1] = 1;
-
- for (Byte slotFast = 2; slotFast < kFastSlots; slotFast++)
- {
- UInt32 k = (1 << ((slotFast >> 1) - 1));
- for (UInt32 j = 0; j < k; j++, c++)
- g_FastPos[c] = slotFast;
- }
- }
-} g_FastPosInit;
-#endif
+#include "../../Common/StreamUtils.h"
-void CLiteralEncoder2::Encode(NRangeCoder::CEncoder *rangeEncoder, Byte symbol)
-{
- UInt32 context = 1;
- int i = 8;
- do
- {
- i--;
- UInt32 bit = (symbol >> i) & 1;
- _encoders[context].Encode(rangeEncoder, bit);
- context = (context << 1) | bit;
- }
- while(i != 0);
+extern "C"
+{
+#include "../../../../C/Alloc.h"
}
-void CLiteralEncoder2::EncodeMatched(NRangeCoder::CEncoder *rangeEncoder,
- Byte matchByte, Byte symbol)
+static HRESULT SResToHRESULT(SRes res)
{
- UInt32 context = 1;
- int i = 8;
- do
+ switch(res)
{
- i--;
- UInt32 bit = (symbol >> i) & 1;
- UInt32 matchBit = (matchByte >> i) & 1;
- _encoders[0x100 + (matchBit << 8) + context].Encode(rangeEncoder, bit);
- context = (context << 1) | bit;
- if (matchBit != bit)
- {
- while(i != 0)
- {
- i--;
- UInt32 bit = (symbol >> i) & 1;
- _encoders[context].Encode(rangeEncoder, bit);
- context = (context << 1) | bit;
- }
- break;
- }
+ case SZ_OK: return S_OK;
+ case SZ_ERROR_MEM: return E_OUTOFMEMORY;
+ case SZ_ERROR_PARAM: return E_INVALIDARG;
+ // case SZ_ERROR_THREAD: return E_FAIL;
}
- while(i != 0);
+ return E_FAIL;
}
-UInt32 CLiteralEncoder2::GetPrice(bool matchMode, Byte matchByte, Byte symbol) const
-{
- UInt32 price = 0;
- UInt32 context = 1;
- int i = 8;
- if (matchMode)
- {
- do
- {
- i--;
- UInt32 matchBit = (matchByte >> i) & 1;
- UInt32 bit = (symbol >> i) & 1;
- price += _encoders[0x100 + (matchBit << 8) + context].GetPrice(bit);
- context = (context << 1) | bit;
- if (matchBit != bit)
- break;
- }
- while (i != 0);
- }
- while(i != 0)
- {
- i--;
- UInt32 bit = (symbol >> i) & 1;
- price += _encoders[context].GetPrice(bit);
- context = (context << 1) | bit;
- }
- return price;
-};
-
+namespace NCompress {
+namespace NLZMA {
-namespace NLength {
+static const UInt32 kStreamStepSize = (UInt32)1 << 31;
-void CEncoder::Init(UInt32 numPosStates)
+static SRes MyRead(void *object, void *data, size_t *size)
{
- _choice.Init();
- _choice2.Init();
- for (UInt32 posState = 0; posState < numPosStates; posState++)
- {
- _lowCoder[posState].Init();
- _midCoder[posState].Init();
- }
- _highCoder.Init();
+ UInt32 curSize = ((*size < kStreamStepSize) ? (UInt32)*size : kStreamStepSize);
+ HRESULT res = ((CSeqInStream *)object)->RealStream->Read(data, curSize, &curSize);
+ *size = curSize;
+ return (SRes)res;
}
-void CEncoder::Encode(NRangeCoder::CEncoder *rangeEncoder, UInt32 symbol, UInt32 posState)
+static size_t MyWrite(void *object, const void *data, size_t size)
{
- if(symbol < kNumLowSymbols)
- {
- _choice.Encode(rangeEncoder, 0);
- _lowCoder[posState].Encode(rangeEncoder, symbol);
- }
- else
- {
- _choice.Encode(rangeEncoder, 1);
- if(symbol < kNumLowSymbols + kNumMidSymbols)
- {
- _choice2.Encode(rangeEncoder, 0);
- _midCoder[posState].Encode(rangeEncoder, symbol - kNumLowSymbols);
- }
- else
- {
- _choice2.Encode(rangeEncoder, 1);
- _highCoder.Encode(rangeEncoder, symbol - kNumLowSymbols - kNumMidSymbols);
- }
- }
+ CSeqOutStream *p = (CSeqOutStream *)object;
+ p->Res = WriteStream(p->RealStream, data, size);
+ if (p->Res != 0)
+ return 0;
+ return size;
}
-void CEncoder::SetPrices(UInt32 posState, UInt32 numSymbols, UInt32 *prices) const
-{
- UInt32 a0 = _choice.GetPrice0();
- UInt32 a1 = _choice.GetPrice1();
- UInt32 b0 = a1 + _choice2.GetPrice0();
- UInt32 b1 = a1 + _choice2.GetPrice1();
- UInt32 i = 0;
- for (i = 0; i < kNumLowSymbols; i++)
- {
- if (i >= numSymbols)
- return;
- prices[i] = a0 + _lowCoder[posState].GetPrice(i);
- }
- for (; i < kNumLowSymbols + kNumMidSymbols; i++)
- {
- if (i >= numSymbols)
- return;
- prices[i] = b0 + _midCoder[posState].GetPrice(i - kNumLowSymbols);
- }
- for (; i < numSymbols; i++)
- prices[i] = b1 + _highCoder.GetPrice(i - kNumLowSymbols - kNumMidSymbols);
-}
+static void *SzBigAlloc(void *, size_t size) { return BigAlloc(size); }
+static void SzBigFree(void *, void *address) { BigFree(address); }
+static ISzAlloc g_BigAlloc = { SzBigAlloc, SzBigFree };
-}
+static void *SzAlloc(void *, size_t size) { return MyAlloc(size); }
+static void SzFree(void *, void *address) { MyFree(address); }
+static ISzAlloc g_Alloc = { SzAlloc, SzFree };
-CEncoder::CEncoder():
- _numFastBytes(kNumFastBytesDefault),
- _distTableSize(kDefaultDictionaryLogSize * 2),
- _posStateBits(2),
- _posStateMask(4 - 1),
- _numLiteralPosStateBits(0),
- _numLiteralContextBits(3),
- _dictionarySize(1 << kDefaultDictionaryLogSize),
- _matchFinderCycles(0),
- #ifdef COMPRESS_MF_MT
- _multiThread(false),
- #endif
- _writeEndMark(false)
+CEncoder::CEncoder()
{
- MatchFinder_Construct(&_matchFinderBase);
- // _maxMode = false;
- _fastMode = false;
- #ifdef COMPRESS_MF_MT
- MatchFinderMt_Construct(&_matchFinderMt);
- _matchFinderMt.MatchFinder = &_matchFinderBase;
- #endif
+ _seqInStream.SeqInStream.Read = MyRead;
+ _seqOutStream.SeqOutStream.Write = MyWrite;
+ _encoder = 0;
+ _encoder = LzmaEnc_Create(&g_Alloc);
+ if (_encoder == 0)
+ throw 1;
}
-
-static void *SzAlloc(size_t size) { return BigAlloc(size); }
-static void SzFree(void *address) { BigFree(address); }
-ISzAlloc g_Alloc = { SzAlloc, SzFree };
-
CEncoder::~CEncoder()
{
- #ifdef COMPRESS_MF_MT
- MatchFinderMt_Destruct(&_matchFinderMt, &g_Alloc);
- #endif
- MatchFinder_Free(&_matchFinderBase, &g_Alloc);
-}
-
-static const UInt32 kBigHashDicLimit = (UInt32)1 << 24;
-
-HRESULT CEncoder::Create()
-{
- if (!_rangeEncoder.Create(1 << 20))
- return E_OUTOFMEMORY;
- bool btMode = (_matchFinderBase.btMode != 0);
- #ifdef COMPRESS_MF_MT
- _mtMode = (_multiThread && !_fastMode && btMode);
- #endif
-
- if (!_literalEncoder.Create(_numLiteralPosStateBits, _numLiteralContextBits))
- return E_OUTOFMEMORY;
-
- _matchFinderBase.bigHash = (_dictionarySize > kBigHashDicLimit);
-
- UInt32 numCycles = 16 + (_numFastBytes >> 1);
- if (!btMode)
- numCycles >>= 1;
- if (_matchFinderCycles != 0)
- numCycles = _matchFinderCycles;
- _matchFinderBase.cutValue = numCycles;
- #ifdef COMPRESS_MF_MT
- if (_mtMode)
- {
- RINOK(MatchFinderMt_Create(&_matchFinderMt, _dictionarySize, kNumOpts, _numFastBytes, kMatchMaxLen, &g_Alloc));
- _matchFinderObj = &_matchFinderMt;
- MatchFinderMt_CreateVTable(&_matchFinderMt, &_matchFinder);
- }
- else
- #endif
- {
- if (!MatchFinder_Create(&_matchFinderBase, _dictionarySize, kNumOpts, _numFastBytes, kMatchMaxLen, &g_Alloc))
- return E_OUTOFMEMORY;
- _matchFinderObj = &_matchFinderBase;
- MatchFinder_CreateVTable(&_matchFinderBase, &_matchFinder);
- }
- return S_OK;
+ if (_encoder != 0)
+ LzmaEnc_Destroy(_encoder, &g_Alloc, &g_BigAlloc);
}
inline wchar_t GetUpperChar(wchar_t c)
@@ -274,7 +90,7 @@ inline wchar_t GetUpperChar(wchar_t c)
return c;
}
-static int ParseMatchFinder(const wchar_t *s, int *btMode, UInt32 *numHashBytes /* , int *skipModeBits */)
+static int ParseMatchFinder(const wchar_t *s, int *btMode, int *numHashBytes)
{
wchar_t c = GetUpperChar(*s++);
if (c == L'H')
@@ -299,1249 +115,113 @@ static int ParseMatchFinder(const wchar_t *s, int *btMode, UInt32 *numHashBytes
if (numHashBytesLoc < 2 || numHashBytesLoc > 4)
return 0;
c = GetUpperChar(*s++);
- /*
- int skipModeBitsLoc = 0;
- if (c == L'D')
- {
- skipModeBitsLoc = 2;
- c = GetUpperChar(*s++);
- }
- */
if (c != L'\0')
return 0;
*btMode = 1;
*numHashBytes = numHashBytesLoc;
- // *skipModeBits = skipModeBitsLoc;
return 1;
}
STDMETHODIMP CEncoder::SetCoderProperties(const PROPID *propIDs,
const PROPVARIANT *properties, UInt32 numProperties)
{
+ CLzmaEncProps props;
+ LzmaEncProps_Init(&props);
+
for (UInt32 i = 0; i < numProperties; i++)
{
const PROPVARIANT &prop = properties[i];
- switch(propIDs[i])
+ switch (propIDs[i])
{
case NCoderPropID::kNumFastBytes:
- {
- if (prop.vt != VT_UI4)
- return E_INVALIDARG;
- UInt32 numFastBytes = prop.ulVal;
- if(numFastBytes < 5 || numFastBytes > kMatchMaxLen)
- return E_INVALIDARG;
- _numFastBytes = numFastBytes;
- break;
- }
+ if (prop.vt != VT_UI4) return E_INVALIDARG; props.fb = prop.ulVal; break;
case NCoderPropID::kMatchFinderCycles:
- {
- if (prop.vt != VT_UI4)
- return E_INVALIDARG;
- _matchFinderCycles = prop.ulVal;
- break;
- }
+ if (prop.vt != VT_UI4) return E_INVALIDARG; props.mc = prop.ulVal; break;
case NCoderPropID::kAlgorithm:
- {
- if (prop.vt != VT_UI4)
- return E_INVALIDARG;
- UInt32 maximize = prop.ulVal;
- _fastMode = (maximize == 0);
- // _maxMode = (maximize >= 2);
- break;
- }
- case NCoderPropID::kMatchFinder:
- {
- if (prop.vt != VT_BSTR)
- return E_INVALIDARG;
- if (!ParseMatchFinder(prop.bstrVal, &_matchFinderBase.btMode, &_matchFinderBase.numHashBytes /* , &_matchFinderBase.skipModeBits */))
- return E_INVALIDARG;
- break;
- }
- case NCoderPropID::kMultiThread:
- {
- if (prop.vt != VT_BOOL)
- return E_INVALIDARG;
- #ifdef COMPRESS_MF_MT
- Bool newMultiThread = (prop.boolVal == VARIANT_TRUE);
- if (newMultiThread != _multiThread)
- {
- ReleaseMatchFinder();
- _multiThread = newMultiThread;
- }
- #endif
- break;
- }
- case NCoderPropID::kNumThreads:
- {
- if (prop.vt != VT_UI4)
- return E_INVALIDARG;
- #ifdef COMPRESS_MF_MT
- Bool newMultiThread = (prop.ulVal > 1) ? True : False;
- if (newMultiThread != _multiThread)
- {
- ReleaseMatchFinder();
- _multiThread = newMultiThread;
- }
- #endif
- break;
- }
+ if (prop.vt != VT_UI4) return E_INVALIDARG; props.algo = prop.ulVal; break;
case NCoderPropID::kDictionarySize:
- {
- const int kDicLogSizeMaxCompress = 30; // must be <= ((kNumLogBits - 1) * 2) + 7 = 31;
- if (prop.vt != VT_UI4)
- return E_INVALIDARG;
- UInt32 dictionarySize = prop.ulVal;
- if (dictionarySize < UInt32(1 << kDicLogSizeMin) ||
- dictionarySize > UInt32(1 << kDicLogSizeMaxCompress))
- return E_INVALIDARG;
- _dictionarySize = dictionarySize;
- UInt32 dicLogSize;
- for(dicLogSize = 0; dicLogSize < (UInt32)kDicLogSizeMaxCompress; dicLogSize++)
- if (dictionarySize <= (UInt32(1) << dicLogSize))
- break;
- _distTableSize = dicLogSize * 2;
- break;
- }
+ if (prop.vt != VT_UI4) return E_INVALIDARG; props.dictSize = prop.ulVal; break;
case NCoderPropID::kPosStateBits:
- {
- if (prop.vt != VT_UI4)
- return E_INVALIDARG;
- UInt32 value = prop.ulVal;
- if (value > (UInt32)NLength::kNumPosStatesBitsEncodingMax)
- return E_INVALIDARG;
- _posStateBits = value;
- _posStateMask = (1 << _posStateBits) - 1;
- break;
- }
+ if (prop.vt != VT_UI4) return E_INVALIDARG; props.pb = prop.ulVal; break;
case NCoderPropID::kLitPosBits:
- {
- if (prop.vt != VT_UI4)
- return E_INVALIDARG;
- UInt32 value = prop.ulVal;
- if (value > (UInt32)kNumLitPosStatesBitsEncodingMax)
- return E_INVALIDARG;
- _numLiteralPosStateBits = value;
- break;
- }
+ if (prop.vt != VT_UI4) return E_INVALIDARG; props.lp = prop.ulVal; break;
case NCoderPropID::kLitContextBits:
- {
- if (prop.vt != VT_UI4)
- return E_INVALIDARG;
- UInt32 value = prop.ulVal;
- if (value > (UInt32)kNumLitContextBitsMax)
- return E_INVALIDARG;
- _numLiteralContextBits = value;
- break;
- }
+ if (prop.vt != VT_UI4) return E_INVALIDARG; props.lc = prop.ulVal; break;
+ case NCoderPropID::kNumThreads:
+ if (prop.vt != VT_UI4) return E_INVALIDARG; props.numThreads = prop.ulVal; break;
+ case NCoderPropID::kMultiThread:
+ if (prop.vt != VT_BOOL) return E_INVALIDARG; props.numThreads = ((prop.boolVal == VARIANT_TRUE) ? 2 : 1); break;
case NCoderPropID::kEndMarker:
- {
- if (prop.vt != VT_BOOL)
- return E_INVALIDARG;
- SetWriteEndMarkerMode(prop.boolVal == VARIANT_TRUE);
- break;
- }
+ if (prop.vt != VT_BOOL) return E_INVALIDARG; props.writeEndMark = (prop.boolVal == VARIANT_TRUE); break;
+ case NCoderPropID::kMatchFinder:
+ if (prop.vt != VT_BSTR) return E_INVALIDARG;
+ if (!ParseMatchFinder(prop.bstrVal, &props.btMode, &props.numHashBytes /* , &_matchFinderBase.skipModeBits */))
+ return E_INVALIDARG; break;
default:
return E_INVALIDARG;
}
}
- return S_OK;
+ return SResToHRESULT(LzmaEnc_SetProps(_encoder, &props));
}
STDMETHODIMP CEncoder::WriteCoderProperties(ISequentialOutStream *outStream)
{
- const UInt32 kPropSize = 5;
- Byte properties[kPropSize];
- properties[0] = (Byte)((_posStateBits * 5 + _numLiteralPosStateBits) * 9 + _numLiteralContextBits);
- for (int i = 0; i < 4; i++)
- properties[1 + i] = Byte(_dictionarySize >> (8 * i));
- return WriteStream(outStream, properties, kPropSize, NULL);
+ Byte props[LZMA_PROPS_SIZE];
+ size_t size = LZMA_PROPS_SIZE;
+ RINOK(LzmaEnc_WriteProperties(_encoder, props, &size));
+ return WriteStream(outStream, props, size);
}
STDMETHODIMP CEncoder::SetOutStream(ISequentialOutStream *outStream)
{
- _rangeEncoder.SetStream(outStream);
+ _seqOutStream.RealStream = outStream;
+ _seqOutStream.Res = S_OK;
return S_OK;
}
STDMETHODIMP CEncoder::ReleaseOutStream()
{
- _rangeEncoder.ReleaseStream();
+ _seqOutStream.RealStream.Release();
return S_OK;
}
-HRESULT CEncoder::Init()
+typedef struct _CCompressProgressImp
{
- CBaseState::Init();
-
- _rangeEncoder.Init();
+ ICompressProgress p;
+ ICompressProgressInfo *Progress;
+ HRESULT Res;
+} CCompressProgressImp;
- for(int i = 0; i < kNumStates; i++)
- {
- for (UInt32 j = 0; j <= _posStateMask; j++)
- {
- _isMatch[i][j].Init();
- _isRep0Long[i][j].Init();
- }
- _isRep[i].Init();
- _isRepG0[i].Init();
- _isRepG1[i].Init();
- _isRepG2[i].Init();
- }
-
- _literalEncoder.Init();
-
- {
- for(UInt32 i = 0; i < kNumLenToPosStates; i++)
- _posSlotEncoder[i].Init();
- }
- {
- for(UInt32 i = 0; i < kNumFullDistances - kEndPosModelIndex; i++)
- _posEncoders[i].Init();
- }
+#define PROGRESS_UNKNOWN_VALUE ((UInt64)(Int64)-1)
- _lenEncoder.Init(1 << _posStateBits);
- _repMatchLenEncoder.Init(1 << _posStateBits);
+#define CONVERT_PR_VAL(x) (x == PROGRESS_UNKNOWN_VALUE ? NULL : &x)
- _posAlignEncoder.Init();
-
- _longestMatchWasFound = false;
- _optimumEndIndex = 0;
- _optimumCurrentIndex = 0;
- _additionalOffset = 0;
-
- return S_OK;
-}
-
-#ifdef SHOW_STAT
-static int ttt = 0;
-#endif
-
-void CEncoder::MovePos(UInt32 num)
+SRes CompressProgress(void *pp, UInt64 inSize, UInt64 outSize)
{
- #ifdef SHOW_STAT
- ttt += num;
- printf("\n MovePos %d", num);
- #endif
- if (num != 0)
- {
- _additionalOffset += num;
- _matchFinder.Skip(_matchFinderObj, num);
- }
-}
-
-UInt32 CEncoder::Backward(UInt32 &backRes, UInt32 cur)
-{
- _optimumEndIndex = cur;
- UInt32 posMem = _optimum[cur].PosPrev;
- UInt32 backMem = _optimum[cur].BackPrev;
- do
- {
- if (_optimum[cur].Prev1IsChar)
- {
- _optimum[posMem].MakeAsChar();
- _optimum[posMem].PosPrev = posMem - 1;
- if (_optimum[cur].Prev2)
- {
- _optimum[posMem - 1].Prev1IsChar = false;
- _optimum[posMem - 1].PosPrev = _optimum[cur].PosPrev2;
- _optimum[posMem - 1].BackPrev = _optimum[cur].BackPrev2;
- }
- }
- UInt32 posPrev = posMem;
- UInt32 backCur = backMem;
-
- backMem = _optimum[posPrev].BackPrev;
- posMem = _optimum[posPrev].PosPrev;
-
- _optimum[posPrev].BackPrev = backCur;
- _optimum[posPrev].PosPrev = cur;
- cur = posPrev;
- }
- while(cur != 0);
- backRes = _optimum[0].BackPrev;
- _optimumCurrentIndex = _optimum[0].PosPrev;
- return _optimumCurrentIndex;
-}
-
-/*
-Out:
- (lenRes == 1) && (backRes == 0xFFFFFFFF) means Literal
-*/
-
-UInt32 CEncoder::GetOptimum(UInt32 position, UInt32 &backRes)
-{
- if(_optimumEndIndex != _optimumCurrentIndex)
- {
- const COptimal &optimum = _optimum[_optimumCurrentIndex];
- UInt32 lenRes = optimum.PosPrev - _optimumCurrentIndex;
- backRes = optimum.BackPrev;
- _optimumCurrentIndex = optimum.PosPrev;
- return lenRes;
- }
- _optimumCurrentIndex = _optimumEndIndex = 0;
-
- UInt32 numAvailableBytes = _matchFinder.GetNumAvailableBytes(_matchFinderObj);
-
- UInt32 lenMain, numDistancePairs;
- if (!_longestMatchWasFound)
- {
- lenMain = ReadMatchDistances(numDistancePairs);
- }
- else
- {
- lenMain = _longestMatchLength;
- numDistancePairs = _numDistancePairs;
- _longestMatchWasFound = false;
- }
-
- const Byte *data = _matchFinder.GetPointerToCurrentPos(_matchFinderObj) - 1;
- if (numAvailableBytes < 2)
- {
- backRes = (UInt32)(-1);
- return 1;
- }
- if (numAvailableBytes > kMatchMaxLen)
- numAvailableBytes = kMatchMaxLen;
-
- UInt32 reps[kNumRepDistances];
- UInt32 repLens[kNumRepDistances];
- UInt32 repMaxIndex = 0;
- UInt32 i;
- for(i = 0; i < kNumRepDistances; i++)
- {
- reps[i] = _repDistances[i];
- const Byte *data2 = data - (reps[i] + 1);
- if (data[0] != data2[0] || data[1] != data2[1])
- {
- repLens[i] = 0;
- continue;
- }
- UInt32 lenTest;
- for (lenTest = 2; lenTest < numAvailableBytes && data[lenTest] == data2[lenTest]; lenTest++);
- repLens[i] = lenTest;
- if (lenTest > repLens[repMaxIndex])
- repMaxIndex = i;
- }
- if(repLens[repMaxIndex] >= _numFastBytes)
- {
- backRes = repMaxIndex;
- UInt32 lenRes = repLens[repMaxIndex];
- MovePos(lenRes - 1);
- return lenRes;
- }
-
- UInt32 *matchDistances = _matchDistances;
- if(lenMain >= _numFastBytes)
- {
- backRes = matchDistances[numDistancePairs - 1] + kNumRepDistances;
- MovePos(lenMain - 1);
- return lenMain;
- }
- Byte currentByte = *data;
- Byte matchByte = *(data - (reps[0] + 1));
-
- if(lenMain < 2 && currentByte != matchByte && repLens[repMaxIndex] < 2)
- {
- backRes = (UInt32)-1;
- return 1;
- }
-
- _optimum[0].State = _state;
-
- UInt32 posState = (position & _posStateMask);
-
- _optimum[1].Price = _isMatch[_state.Index][posState].GetPrice0() +
- _literalEncoder.GetSubCoder(position, _previousByte)->GetPrice(!_state.IsCharState(), matchByte, currentByte);
- _optimum[1].MakeAsChar();
-
- UInt32 matchPrice = _isMatch[_state.Index][posState].GetPrice1();
- UInt32 repMatchPrice = matchPrice + _isRep[_state.Index].GetPrice1();
-
- if(matchByte == currentByte)
- {
- UInt32 shortRepPrice = repMatchPrice + GetRepLen1Price(_state, posState);
- if(shortRepPrice < _optimum[1].Price)
- {
- _optimum[1].Price = shortRepPrice;
- _optimum[1].MakeAsShortRep();
- }
- }
- UInt32 lenEnd = ((lenMain >= repLens[repMaxIndex]) ? lenMain : repLens[repMaxIndex]);
-
- if(lenEnd < 2)
- {
- backRes = _optimum[1].BackPrev;
- return 1;
- }
-
- _optimum[1].PosPrev = 0;
- for (i = 0; i < kNumRepDistances; i++)
- _optimum[0].Backs[i] = reps[i];
-
- UInt32 len = lenEnd;
- do
- _optimum[len--].Price = kIfinityPrice;
- while (len >= 2);
-
- for(i = 0; i < kNumRepDistances; i++)
- {
- UInt32 repLen = repLens[i];
- if (repLen < 2)
- continue;
- UInt32 price = repMatchPrice + GetPureRepPrice(i, _state, posState);
- do
- {
- UInt32 curAndLenPrice = price + _repMatchLenEncoder.GetPrice(repLen - 2, posState);
- COptimal &optimum = _optimum[repLen];
- if (curAndLenPrice < optimum.Price)
- {
- optimum.Price = curAndLenPrice;
- optimum.PosPrev = 0;
- optimum.BackPrev = i;
- optimum.Prev1IsChar = false;
- }
- }
- while(--repLen >= 2);
- }
-
- UInt32 normalMatchPrice = matchPrice + _isRep[_state.Index].GetPrice0();
-
- len = ((repLens[0] >= 2) ? repLens[0] + 1 : 2);
- if (len <= lenMain)
- {
- UInt32 offs = 0;
- while (len > matchDistances[offs])
- offs += 2;
- for(; ; len++)
- {
- UInt32 distance = matchDistances[offs + 1];
- UInt32 curAndLenPrice = normalMatchPrice + GetPosLenPrice(distance, len, posState);
- COptimal &optimum = _optimum[len];
- if (curAndLenPrice < optimum.Price)
- {
- optimum.Price = curAndLenPrice;
- optimum.PosPrev = 0;
- optimum.BackPrev = distance + kNumRepDistances;
- optimum.Prev1IsChar = false;
- }
- if (len == matchDistances[offs])
- {
- offs += 2;
- if (offs == numDistancePairs)
- break;
- }
- }
- }
-
- UInt32 cur = 0;
-
- for (;;)
- {
- cur++;
- if(cur == lenEnd)
- {
- return Backward(backRes, cur);
- }
- UInt32 numAvailableBytesFull = _matchFinder.GetNumAvailableBytes(_matchFinderObj);
- UInt32 newLen, numDistancePairs;
- newLen = ReadMatchDistances(numDistancePairs);
- if(newLen >= _numFastBytes)
- {
- _numDistancePairs = numDistancePairs;
- _longestMatchLength = newLen;
- _longestMatchWasFound = true;
- return Backward(backRes, cur);
- }
- position++;
- COptimal &curOptimum = _optimum[cur];
- UInt32 posPrev = curOptimum.PosPrev;
- CState state;
- if (curOptimum.Prev1IsChar)
- {
- posPrev--;
- if (curOptimum.Prev2)
- {
- state = _optimum[curOptimum.PosPrev2].State;
- if (curOptimum.BackPrev2 < kNumRepDistances)
- state.UpdateRep();
- else
- state.UpdateMatch();
- }
- else
- state = _optimum[posPrev].State;
- state.UpdateChar();
- }
- else
- state = _optimum[posPrev].State;
- if (posPrev == cur - 1)
- {
- if (curOptimum.IsShortRep())
- state.UpdateShortRep();
- else
- state.UpdateChar();
- }
- else
- {
- UInt32 pos;
- if (curOptimum.Prev1IsChar && curOptimum.Prev2)
- {
- posPrev = curOptimum.PosPrev2;
- pos = curOptimum.BackPrev2;
- state.UpdateRep();
- }
- else
- {
- pos = curOptimum.BackPrev;
- if (pos < kNumRepDistances)
- state.UpdateRep();
- else
- state.UpdateMatch();
- }
- const COptimal &prevOptimum = _optimum[posPrev];
- if (pos < kNumRepDistances)
- {
- reps[0] = prevOptimum.Backs[pos];
- UInt32 i;
- for(i = 1; i <= pos; i++)
- reps[i] = prevOptimum.Backs[i - 1];
- for(; i < kNumRepDistances; i++)
- reps[i] = prevOptimum.Backs[i];
- }
- else
- {
- reps[0] = (pos - kNumRepDistances);
- for(UInt32 i = 1; i < kNumRepDistances; i++)
- reps[i] = prevOptimum.Backs[i - 1];
- }
- }
- curOptimum.State = state;
- for(UInt32 i = 0; i < kNumRepDistances; i++)
- curOptimum.Backs[i] = reps[i];
- UInt32 curPrice = curOptimum.Price;
- const Byte *data = _matchFinder.GetPointerToCurrentPos(_matchFinderObj) - 1;
- const Byte currentByte = *data;
- const Byte matchByte = *(data - (reps[0] + 1));
-
- UInt32 posState = (position & _posStateMask);
-
- UInt32 curAnd1Price = curPrice +
- _isMatch[state.Index][posState].GetPrice0() +
- _literalEncoder.GetSubCoder(position, *(data - 1))->GetPrice(!state.IsCharState(), matchByte, currentByte);
-
- COptimal &nextOptimum = _optimum[cur + 1];
-
- bool nextIsChar = false;
- if (curAnd1Price < nextOptimum.Price)
- {
- nextOptimum.Price = curAnd1Price;
- nextOptimum.PosPrev = cur;
- nextOptimum.MakeAsChar();
- nextIsChar = true;
- }
-
- UInt32 matchPrice = curPrice + _isMatch[state.Index][posState].GetPrice1();
- UInt32 repMatchPrice = matchPrice + _isRep[state.Index].GetPrice1();
-
- if(matchByte == currentByte &&
- !(nextOptimum.PosPrev < cur && nextOptimum.BackPrev == 0))
- {
- UInt32 shortRepPrice = repMatchPrice + GetRepLen1Price(state, posState);
- if(shortRepPrice <= nextOptimum.Price)
- {
- nextOptimum.Price = shortRepPrice;
- nextOptimum.PosPrev = cur;
- nextOptimum.MakeAsShortRep();
- nextIsChar = true;
- }
- }
- /*
- if(newLen == 2 && matchDistances[2] >= kDistLimit2) // test it maybe set 2000 ?
- continue;
- */
-
- numAvailableBytesFull = MyMin(kNumOpts - 1 - cur, numAvailableBytesFull);
- UInt32 numAvailableBytes = numAvailableBytesFull;
-
- if (numAvailableBytes < 2)
- continue;
- if (numAvailableBytes > _numFastBytes)
- numAvailableBytes = _numFastBytes;
- if (!nextIsChar && matchByte != currentByte) // speed optimization
- {
- // try Literal + rep0
- const Byte *data2 = data - (reps[0] + 1);
- UInt32 limit = MyMin(numAvailableBytesFull, _numFastBytes + 1);
- UInt32 temp;
- for (temp = 1; temp < limit && data[temp] == data2[temp]; temp++);
- UInt32 lenTest2 = temp - 1;
- if (lenTest2 >= 2)
- {
- CState state2 = state;
- state2.UpdateChar();
- UInt32 posStateNext = (position + 1) & _posStateMask;
- UInt32 nextRepMatchPrice = curAnd1Price +
- _isMatch[state2.Index][posStateNext].GetPrice1() +
- _isRep[state2.Index].GetPrice1();
- // for (; lenTest2 >= 2; lenTest2--)
- {
- UInt32 offset = cur + 1 + lenTest2;
- while(lenEnd < offset)
- _optimum[++lenEnd].Price = kIfinityPrice;
- UInt32 curAndLenPrice = nextRepMatchPrice + GetRepPrice(
- 0, lenTest2, state2, posStateNext);
- COptimal &optimum = _optimum[offset];
- if (curAndLenPrice < optimum.Price)
- {
- optimum.Price = curAndLenPrice;
- optimum.PosPrev = cur + 1;
- optimum.BackPrev = 0;
- optimum.Prev1IsChar = true;
- optimum.Prev2 = false;
- }
- }
- }
- }
-
- UInt32 startLen = 2; // speed optimization
- for(UInt32 repIndex = 0; repIndex < kNumRepDistances; repIndex++)
- {
- // UInt32 repLen = _matchFinder.GetMatchLen(0 - 1, reps[repIndex], newLen); // test it;
- const Byte *data2 = data - (reps[repIndex] + 1);
- if (data[0] != data2[0] || data[1] != data2[1])
- continue;
- UInt32 lenTest;
- for (lenTest = 2; lenTest < numAvailableBytes && data[lenTest] == data2[lenTest]; lenTest++);
- while(lenEnd < cur + lenTest)
- _optimum[++lenEnd].Price = kIfinityPrice;
- UInt32 lenTestTemp = lenTest;
- UInt32 price = repMatchPrice + GetPureRepPrice(repIndex, state, posState);
- do
- {
- UInt32 curAndLenPrice = price + _repMatchLenEncoder.GetPrice(lenTest - 2, posState);
- COptimal &optimum = _optimum[cur + lenTest];
- if (curAndLenPrice < optimum.Price)
- {
- optimum.Price = curAndLenPrice;
- optimum.PosPrev = cur;
- optimum.BackPrev = repIndex;
- optimum.Prev1IsChar = false;
- }
- }
- while(--lenTest >= 2);
- lenTest = lenTestTemp;
-
- if (repIndex == 0)
- startLen = lenTest + 1;
-
- // if (_maxMode)
- {
- UInt32 lenTest2 = lenTest + 1;
- UInt32 limit = MyMin(numAvailableBytesFull, lenTest2 + _numFastBytes);
- for (; lenTest2 < limit && data[lenTest2] == data2[lenTest2]; lenTest2++);
- lenTest2 -= lenTest + 1;
- if (lenTest2 >= 2)
- {
- CState state2 = state;
- state2.UpdateRep();
- UInt32 posStateNext = (position + lenTest) & _posStateMask;
- UInt32 curAndLenCharPrice =
- price + _repMatchLenEncoder.GetPrice(lenTest - 2, posState) +
- _isMatch[state2.Index][posStateNext].GetPrice0() +
- _literalEncoder.GetSubCoder(position + lenTest, data[lenTest - 1])->GetPrice(
- true, data2[lenTest], data[lenTest]);
- state2.UpdateChar();
- posStateNext = (position + lenTest + 1) & _posStateMask;
- UInt32 nextRepMatchPrice = curAndLenCharPrice +
- _isMatch[state2.Index][posStateNext].GetPrice1() +
- _isRep[state2.Index].GetPrice1();
-
- // for(; lenTest2 >= 2; lenTest2--)
- {
- UInt32 offset = cur + lenTest + 1 + lenTest2;
- while(lenEnd < offset)
- _optimum[++lenEnd].Price = kIfinityPrice;
- UInt32 curAndLenPrice = nextRepMatchPrice + GetRepPrice(
- 0, lenTest2, state2, posStateNext);
- COptimal &optimum = _optimum[offset];
- if (curAndLenPrice < optimum.Price)
- {
- optimum.Price = curAndLenPrice;
- optimum.PosPrev = cur + lenTest + 1;
- optimum.BackPrev = 0;
- optimum.Prev1IsChar = true;
- optimum.Prev2 = true;
- optimum.PosPrev2 = cur;
- optimum.BackPrev2 = repIndex;
- }
- }
- }
- }
- }
-
- // for(UInt32 lenTest = 2; lenTest <= newLen; lenTest++)
- if (newLen > numAvailableBytes)
- {
- newLen = numAvailableBytes;
- for (numDistancePairs = 0; newLen > matchDistances[numDistancePairs]; numDistancePairs += 2);
- matchDistances[numDistancePairs] = newLen;
- numDistancePairs += 2;
- }
- if (newLen >= startLen)
- {
- UInt32 normalMatchPrice = matchPrice + _isRep[state.Index].GetPrice0();
- while(lenEnd < cur + newLen)
- _optimum[++lenEnd].Price = kIfinityPrice;
-
- UInt32 offs = 0;
- while(startLen > matchDistances[offs])
- offs += 2;
- UInt32 curBack = matchDistances[offs + 1];
- UInt32 posSlot = GetPosSlot2(curBack);
- for(UInt32 lenTest = /*2*/ startLen; ; lenTest++)
- {
- UInt32 curAndLenPrice = normalMatchPrice;
- UInt32 lenToPosState = GetLenToPosState(lenTest);
- if (curBack < kNumFullDistances)
- curAndLenPrice += _distancesPrices[lenToPosState][curBack];
- else
- curAndLenPrice += _posSlotPrices[lenToPosState][posSlot] + _alignPrices[curBack & kAlignMask];
-
- curAndLenPrice += _lenEncoder.GetPrice(lenTest - kMatchMinLen, posState);
-
- COptimal &optimum = _optimum[cur + lenTest];
- if (curAndLenPrice < optimum.Price)
- {
- optimum.Price = curAndLenPrice;
- optimum.PosPrev = cur;
- optimum.BackPrev = curBack + kNumRepDistances;
- optimum.Prev1IsChar = false;
- }
-
- if (/*_maxMode && */lenTest == matchDistances[offs])
- {
- // Try Match + Literal + Rep0
- const Byte *data2 = data - (curBack + 1);
- UInt32 lenTest2 = lenTest + 1;
- UInt32 limit = MyMin(numAvailableBytesFull, lenTest2 + _numFastBytes);
- for (; lenTest2 < limit && data[lenTest2] == data2[lenTest2]; lenTest2++);
- lenTest2 -= lenTest + 1;
- if (lenTest2 >= 2)
- {
- CState state2 = state;
- state2.UpdateMatch();
- UInt32 posStateNext = (position + lenTest) & _posStateMask;
- UInt32 curAndLenCharPrice = curAndLenPrice +
- _isMatch[state2.Index][posStateNext].GetPrice0() +
- _literalEncoder.GetSubCoder(position + lenTest, data[lenTest - 1])->GetPrice(
- true, data2[lenTest], data[lenTest]);
- state2.UpdateChar();
- posStateNext = (posStateNext + 1) & _posStateMask;
- UInt32 nextRepMatchPrice = curAndLenCharPrice +
- _isMatch[state2.Index][posStateNext].GetPrice1() +
- _isRep[state2.Index].GetPrice1();
-
- // for(; lenTest2 >= 2; lenTest2--)
- {
- UInt32 offset = cur + lenTest + 1 + lenTest2;
- while(lenEnd < offset)
- _optimum[++lenEnd].Price = kIfinityPrice;
- UInt32 curAndLenPrice = nextRepMatchPrice + GetRepPrice(0, lenTest2, state2, posStateNext);
- COptimal &optimum = _optimum[offset];
- if (curAndLenPrice < optimum.Price)
- {
- optimum.Price = curAndLenPrice;
- optimum.PosPrev = cur + lenTest + 1;
- optimum.BackPrev = 0;
- optimum.Prev1IsChar = true;
- optimum.Prev2 = true;
- optimum.PosPrev2 = cur;
- optimum.BackPrev2 = curBack + kNumRepDistances;
- }
- }
- }
- offs += 2;
- if (offs == numDistancePairs)
- break;
- curBack = matchDistances[offs + 1];
- if (curBack >= kNumFullDistances)
- posSlot = GetPosSlot2(curBack);
- }
- }
- }
- }
-}
-
-static inline bool ChangePair(UInt32 smallDist, UInt32 bigDist)
-{
- return ((bigDist >> 7) > smallDist);
-}
-
-UInt32 CEncoder::ReadMatchDistances(UInt32 &numDistancePairs)
-{
- UInt32 lenRes = 0;
- numDistancePairs = _matchFinder.GetMatches(_matchFinderObj, _matchDistances);
- #ifdef SHOW_STAT
- printf("\n i = %d numPairs = %d ", ttt, numDistancePairs / 2);
- if (ttt >= 61994)
- ttt = ttt;
-
- ttt++;
- for (UInt32 i = 0; i < numDistancePairs; i += 2)
- printf("%2d %6d | ", _matchDistances[i], _matchDistances[i + 1]);
- #endif
- if (numDistancePairs > 0)
- {
- lenRes = _matchDistances[numDistancePairs - 2];
- if (lenRes == _numFastBytes)
- {
- UInt32 numAvail = _matchFinder.GetNumAvailableBytes(_matchFinderObj) + 1;
- const Byte *pby = _matchFinder.GetPointerToCurrentPos(_matchFinderObj) - 1;
- UInt32 distance = _matchDistances[numDistancePairs - 1] + 1;
- if (numAvail > kMatchMaxLen)
- numAvail = kMatchMaxLen;
-
- const Byte *pby2 = pby - distance;
- for (; lenRes < numAvail && pby[lenRes] == pby2[lenRes]; lenRes++);
- }
- }
- _additionalOffset++;
- return lenRes;
-}
-
-UInt32 CEncoder::GetOptimumFast(UInt32 &backRes)
-{
- UInt32 numAvailableBytes = _matchFinder.GetNumAvailableBytes(_matchFinderObj);
- UInt32 lenMain, numDistancePairs;
- if (!_longestMatchWasFound)
- {
- lenMain = ReadMatchDistances(numDistancePairs);
- }
- else
- {
- lenMain = _longestMatchLength;
- numDistancePairs = _numDistancePairs;
- _longestMatchWasFound = false;
- }
-
- const Byte *data = _matchFinder.GetPointerToCurrentPos(_matchFinderObj) - 1;
- if (numAvailableBytes > kMatchMaxLen)
- numAvailableBytes = kMatchMaxLen;
- if (numAvailableBytes < 2)
- {
- backRes = (UInt32)(-1);
- return 1;
- }
-
- UInt32 repLens[kNumRepDistances];
- UInt32 repMaxIndex = 0;
-
- for(UInt32 i = 0; i < kNumRepDistances; i++)
- {
- const Byte *data2 = data - (_repDistances[i] + 1);
- if (data[0] != data2[0] || data[1] != data2[1])
- {
- repLens[i] = 0;
- continue;
- }
- UInt32 len;
- for (len = 2; len < numAvailableBytes && data[len] == data2[len]; len++);
- if(len >= _numFastBytes)
- {
- backRes = i;
- MovePos(len - 1);
- return len;
- }
- repLens[i] = len;
- if (len > repLens[repMaxIndex])
- repMaxIndex = i;
- }
- UInt32 *matchDistances = _matchDistances;
- if(lenMain >= _numFastBytes)
- {
- backRes = matchDistances[numDistancePairs - 1] + kNumRepDistances;
- MovePos(lenMain - 1);
- return lenMain;
- }
-
- UInt32 backMain = 0; // for GCC
- if (lenMain >= 2)
- {
- backMain = matchDistances[numDistancePairs - 1];
- while (numDistancePairs > 2 && lenMain == matchDistances[numDistancePairs - 4] + 1)
- {
- if (!ChangePair(matchDistances[numDistancePairs - 3], backMain))
- break;
- numDistancePairs -= 2;
- lenMain = matchDistances[numDistancePairs - 2];
- backMain = matchDistances[numDistancePairs - 1];
- }
- if (lenMain == 2 && backMain >= 0x80)
- lenMain = 1;
- }
-
- if (repLens[repMaxIndex] >= 2)
- {
- if (repLens[repMaxIndex] + 1 >= lenMain ||
- repLens[repMaxIndex] + 2 >= lenMain && (backMain > (1 << 9)) ||
- repLens[repMaxIndex] + 3 >= lenMain && (backMain > (1 << 15)))
- {
- backRes = repMaxIndex;
- UInt32 lenRes = repLens[repMaxIndex];
- MovePos(lenRes - 1);
- return lenRes;
- }
- }
-
- if (lenMain >= 2 && numAvailableBytes > 2)
- {
- numAvailableBytes = _matchFinder.GetNumAvailableBytes(_matchFinderObj);
- _longestMatchLength = ReadMatchDistances(_numDistancePairs);
- if (_longestMatchLength >= 2)
- {
- UInt32 newDistance = matchDistances[_numDistancePairs - 1];
- if (_longestMatchLength >= lenMain && newDistance < backMain ||
- _longestMatchLength == lenMain + 1 && !ChangePair(backMain, newDistance) ||
- _longestMatchLength > lenMain + 1 ||
- _longestMatchLength + 1 >= lenMain && lenMain >= 3 && ChangePair(newDistance, backMain))
- {
- _longestMatchWasFound = true;
- backRes = UInt32(-1);
- return 1;
- }
- }
- data = _matchFinder.GetPointerToCurrentPos(_matchFinderObj) - 1;
- for(UInt32 i = 0; i < kNumRepDistances; i++)
- {
- const Byte *data2 = data - (_repDistances[i] + 1);
- if (data[1] != data2[1] || data[2] != data2[2])
- {
- repLens[i] = 0;
- continue;
- }
- UInt32 len;
- for (len = 2; len < numAvailableBytes && data[len] == data2[len]; len++);
- if (len + 1 >= lenMain)
- {
- _longestMatchWasFound = true;
- backRes = UInt32(-1);
- return 1;
- }
- }
- backRes = backMain + kNumRepDistances;
- MovePos(lenMain - 2);
- return lenMain;
- }
- backRes = UInt32(-1);
- return 1;
-}
-
-HRESULT CEncoder::Flush(UInt32 nowPos)
-{
- // ReleaseMFStream();
- if (_matchFinderBase.result != SZ_OK)
- return _matchFinderBase.result;
- WriteEndMarker(nowPos & _posStateMask);
- _rangeEncoder.FlushData();
- return _rangeEncoder.FlushStream();
-}
-
-void CEncoder::WriteEndMarker(UInt32 posState)
-{
- // This function for writing End Mark for stream version of LZMA.
- // In current version this feature is not used.
- if (!_writeEndMark)
- return;
-
- _isMatch[_state.Index][posState].Encode(&_rangeEncoder, 1);
- _isRep[_state.Index].Encode(&_rangeEncoder, 0);
- _state.UpdateMatch();
- UInt32 len = kMatchMinLen; // kMatchMaxLen;
- _lenEncoder.Encode(&_rangeEncoder, len - kMatchMinLen, posState, !_fastMode);
- UInt32 posSlot = (1 << kNumPosSlotBits) - 1;
- UInt32 lenToPosState = GetLenToPosState(len);
- _posSlotEncoder[lenToPosState].Encode(&_rangeEncoder, posSlot);
- UInt32 footerBits = 30;
- UInt32 posReduced = (UInt32(1) << footerBits) - 1;
- _rangeEncoder.EncodeDirectBits(posReduced >> kNumAlignBits, footerBits - kNumAlignBits);
- _posAlignEncoder.ReverseEncode(&_rangeEncoder, posReduced & kAlignMask);
-}
-
-HRESULT CEncoder::CodeReal(ISequentialInStream *inStream,
- ISequentialOutStream *outStream,
- const UInt64 *inSize, const UInt64 *outSize,
- ICompressProgressInfo *progress)
-{
- // _needReleaseMFStream = false;
- #ifdef COMPRESS_MF_MT
- #ifdef USE_ALLOCA
- alloca(0x300);
- #endif
- #endif
- CCoderReleaser coderReleaser(this);
- RINOK(SetStreams(inStream, outStream, inSize, outSize));
- for (;;)
- {
- UInt64 processedInSize;
- UInt64 processedOutSize;
- Int32 finished;
- RINOK(CodeOneBlock(&processedInSize, &processedOutSize, &finished));
- if (finished != 0)
- break;
- if (progress != 0)
- {
- RINOK(progress->SetRatioInfo(&processedInSize, &processedOutSize));
- }
- }
- return S_OK;
-}
-
-HRESULT CEncoder::SetStreams(ISequentialInStream *inStream,
- ISequentialOutStream *outStream,
- const UInt64 * /* inSize */, const UInt64 * /* outSize */)
-{
- _inStream = inStream;
- _finished = false;
- RINOK(Create());
- RINOK(SetOutStream(outStream));
- RINOK(Init());
-
- if (!_fastMode)
- {
- FillDistancesPrices();
- FillAlignPrices();
- }
-
- _lenEncoder.SetTableSize(_numFastBytes + 1 - kMatchMinLen);
- _lenEncoder.UpdateTables(1 << _posStateBits);
- _repMatchLenEncoder.SetTableSize(_numFastBytes + 1 - kMatchMinLen);
- _repMatchLenEncoder.UpdateTables(1 << _posStateBits);
-
- nowPos64 = 0;
- return S_OK;
-}
-
-static HRes MyRead(void *object, void *data, UInt32 size, UInt32 *processedSize)
-{
- return (HRes)((CSeqInStream *)object)->RealStream->Read(data, size, processedSize);
-}
-
-HRESULT CEncoder::CodeOneBlock(UInt64 *inSize, UInt64 *outSize, Int32 *finished)
-{
- if (_inStream != 0)
- {
- _seqInStream.RealStream = _inStream;
- _seqInStream.SeqInStream.Read = MyRead;
- _matchFinderBase.stream = &_seqInStream.SeqInStream;
- _matchFinder.Init(_matchFinderObj);
- _needReleaseMFStream = true;
- _inStream = 0;
- }
-
-
- *finished = 1;
- if (_finished)
- return _matchFinderBase.result;
- _finished = true;
-
- if (nowPos64 == 0)
- {
- if (_matchFinder.GetNumAvailableBytes(_matchFinderObj) == 0)
- return Flush((UInt32)nowPos64);
- UInt32 len, numDistancePairs;
- len = ReadMatchDistances(numDistancePairs);
- UInt32 posState = UInt32(nowPos64) & _posStateMask;
- _isMatch[_state.Index][posState].Encode(&_rangeEncoder, 0);
- _state.UpdateChar();
- Byte curByte = _matchFinder.GetIndexByte(_matchFinderObj, 0 - _additionalOffset);
- _literalEncoder.GetSubCoder(UInt32(nowPos64), _previousByte)->Encode(&_rangeEncoder, curByte);
- _previousByte = curByte;
- _additionalOffset--;
- nowPos64++;
- }
-
- UInt32 nowPos32 = (UInt32)nowPos64;
- UInt32 progressPosValuePrev = nowPos32;
-
- if (_matchFinder.GetNumAvailableBytes(_matchFinderObj) == 0)
- return Flush(nowPos32);
-
- for (;;)
- {
- #ifdef _NO_EXCEPTIONS
- if (_rangeEncoder.Stream.ErrorCode != S_OK)
- return _rangeEncoder.Stream.ErrorCode;
- #endif
- UInt32 pos, len;
-
- if (_fastMode)
- len = GetOptimumFast(pos);
- else
- len = GetOptimum(nowPos32, pos);
-
- UInt32 posState = nowPos32 & _posStateMask;
- if(len == 1 && pos == 0xFFFFFFFF)
- {
- _isMatch[_state.Index][posState].Encode(&_rangeEncoder, 0);
- Byte curByte = _matchFinder.GetIndexByte(_matchFinderObj, 0 - _additionalOffset);
- CLiteralEncoder2 *subCoder = _literalEncoder.GetSubCoder(nowPos32, _previousByte);
- if(_state.IsCharState())
- subCoder->Encode(&_rangeEncoder, curByte);
- else
- {
- Byte matchByte = _matchFinder.GetIndexByte(_matchFinderObj, 0 - _repDistances[0] - 1 - _additionalOffset);
- subCoder->EncodeMatched(&_rangeEncoder, matchByte, curByte);
- }
- _state.UpdateChar();
- _previousByte = curByte;
- }
- else
- {
- _isMatch[_state.Index][posState].Encode(&_rangeEncoder, 1);
- if(pos < kNumRepDistances)
- {
- _isRep[_state.Index].Encode(&_rangeEncoder, 1);
- if(pos == 0)
- {
- _isRepG0[_state.Index].Encode(&_rangeEncoder, 0);
- _isRep0Long[_state.Index][posState].Encode(&_rangeEncoder, ((len == 1) ? 0 : 1));
- }
- else
- {
- UInt32 distance = _repDistances[pos];
- _isRepG0[_state.Index].Encode(&_rangeEncoder, 1);
- if (pos == 1)
- _isRepG1[_state.Index].Encode(&_rangeEncoder, 0);
- else
- {
- _isRepG1[_state.Index].Encode(&_rangeEncoder, 1);
- _isRepG2[_state.Index].Encode(&_rangeEncoder, pos - 2);
- if (pos == 3)
- _repDistances[3] = _repDistances[2];
- _repDistances[2] = _repDistances[1];
- }
- _repDistances[1] = _repDistances[0];
- _repDistances[0] = distance;
- }
- if (len == 1)
- _state.UpdateShortRep();
- else
- {
- _repMatchLenEncoder.Encode(&_rangeEncoder, len - kMatchMinLen, posState, !_fastMode);
- _state.UpdateRep();
- }
- }
- else
- {
- _isRep[_state.Index].Encode(&_rangeEncoder, 0);
- _state.UpdateMatch();
- _lenEncoder.Encode(&_rangeEncoder, len - kMatchMinLen, posState, !_fastMode);
- pos -= kNumRepDistances;
- UInt32 posSlot = GetPosSlot(pos);
- _posSlotEncoder[GetLenToPosState(len)].Encode(&_rangeEncoder, posSlot);
-
- if (posSlot >= kStartPosModelIndex)
- {
- UInt32 footerBits = ((posSlot >> 1) - 1);
- UInt32 base = ((2 | (posSlot & 1)) << footerBits);
- UInt32 posReduced = pos - base;
-
- if (posSlot < kEndPosModelIndex)
- NRangeCoder::ReverseBitTreeEncode(_posEncoders + base - posSlot - 1,
- &_rangeEncoder, footerBits, posReduced);
- else
- {
- _rangeEncoder.EncodeDirectBits(posReduced >> kNumAlignBits, footerBits - kNumAlignBits);
- _posAlignEncoder.ReverseEncode(&_rangeEncoder, posReduced & kAlignMask);
- _alignPriceCount++;
- }
- }
- _repDistances[3] = _repDistances[2];
- _repDistances[2] = _repDistances[1];
- _repDistances[1] = _repDistances[0];
- _repDistances[0] = pos;
- _matchPriceCount++;
- }
- _previousByte = _matchFinder.GetIndexByte(_matchFinderObj, len - 1 - _additionalOffset);
- }
- _additionalOffset -= len;
- nowPos32 += len;
- if (_additionalOffset == 0)
- {
- if (!_fastMode)
- {
- if (_matchPriceCount >= (1 << 7))
- FillDistancesPrices();
- if (_alignPriceCount >= kAlignTableSize)
- FillAlignPrices();
- }
- if (_matchFinder.GetNumAvailableBytes(_matchFinderObj) == 0)
- return Flush(nowPos32);
- if (nowPos32 - progressPosValuePrev >= (1 << 14))
- {
- nowPos64 += nowPos32 - progressPosValuePrev;
- *inSize = nowPos64;
- *outSize = _rangeEncoder.GetProcessedSize();
- _finished = false;
- *finished = 0;
- return _matchFinderBase.result;
- }
- }
- }
+ CCompressProgressImp *p = (CCompressProgressImp *)pp;
+ p->Res = p->Progress->SetRatioInfo(CONVERT_PR_VAL(inSize), CONVERT_PR_VAL(outSize));
+ return (SRes)p->Res;
}
STDMETHODIMP CEncoder::Code(ISequentialInStream *inStream,
- ISequentialOutStream *outStream, const UInt64 *inSize, const UInt64 *outSize,
+ ISequentialOutStream *outStream, const UInt64 * /* inSize */,
+ const UInt64 * /* outSize */,
ICompressProgressInfo *progress)
{
- #ifndef _NO_EXCEPTIONS
- try
- {
- #endif
- return CodeReal(inStream, outStream, inSize, outSize, progress);
- #ifndef _NO_EXCEPTIONS
- }
- catch(const COutBufferException &e) { return e.ErrorCode; }
- catch(...) { return E_FAIL; }
- #endif
+ CCompressProgressImp progressImp;
+ progressImp.p.Progress = CompressProgress;
+ progressImp.Progress = progress;
+ progressImp.Res = SZ_OK;
+
+ _seqInStream.RealStream = inStream;
+ SetOutStream(outStream);
+ SRes res = LzmaEnc_Encode(_encoder, &_seqOutStream.SeqOutStream, &_seqInStream.SeqInStream, progress ? &progressImp.p : NULL, &g_Alloc, &g_BigAlloc);
+ ReleaseOutStream();
+ if (res == SZ_ERROR_WRITE && _seqOutStream.Res != S_OK)
+ return _seqOutStream.Res;
+ if (res == SZ_ERROR_PROGRESS && progressImp.Res != S_OK)
+ return progressImp.Res;
+ return SResToHRESULT(res);
}
-void CEncoder::FillDistancesPrices()
-{
- UInt32 tempPrices[kNumFullDistances];
- for (UInt32 i = kStartPosModelIndex; i < kNumFullDistances; i++)
- {
- UInt32 posSlot = GetPosSlot(i);
- UInt32 footerBits = ((posSlot >> 1) - 1);
- UInt32 base = ((2 | (posSlot & 1)) << footerBits);
- tempPrices[i] = NRangeCoder::ReverseBitTreeGetPrice(_posEncoders +
- base - posSlot - 1, footerBits, i - base);
- }
-
- for (UInt32 lenToPosState = 0; lenToPosState < kNumLenToPosStates; lenToPosState++)
- {
- UInt32 posSlot;
- NRangeCoder::CBitTreeEncoder<kNumMoveBits, kNumPosSlotBits> &encoder = _posSlotEncoder[lenToPosState];
- UInt32 *posSlotPrices = _posSlotPrices[lenToPosState];
- for (posSlot = 0; posSlot < _distTableSize; posSlot++)
- posSlotPrices[posSlot] = encoder.GetPrice(posSlot);
- for (posSlot = kEndPosModelIndex; posSlot < _distTableSize; posSlot++)
- posSlotPrices[posSlot] += ((((posSlot >> 1) - 1) - kNumAlignBits) << NRangeCoder::kNumBitPriceShiftBits);
-
- UInt32 *distancesPrices = _distancesPrices[lenToPosState];
- UInt32 i;
- for (i = 0; i < kStartPosModelIndex; i++)
- distancesPrices[i] = posSlotPrices[i];
- for (; i < kNumFullDistances; i++)
- distancesPrices[i] = posSlotPrices[GetPosSlot(i)] + tempPrices[i];
- }
- _matchPriceCount = 0;
-}
-
-void CEncoder::FillAlignPrices()
-{
- for (UInt32 i = 0; i < kAlignTableSize; i++)
- _alignPrices[i] = _posAlignEncoder.ReverseGetPrice(i);
- _alignPriceCount = 0;
-}
-
}}
diff --git a/CPP/7zip/Compress/LZMA/LZMAEncoder.h b/CPP/7zip/Compress/LZMA/LZMAEncoder.h
index da159795..711ac0b4 100755
--- a/CPP/7zip/Compress/LZMA/LZMAEncoder.h
+++ b/CPP/7zip/Compress/LZMA/LZMAEncoder.h
@@ -8,419 +8,39 @@
extern "C"
{
- #include "../../../../C/Alloc.h"
- #include "../../../../C/Compress/Lz/MatchFinder.h"
- #ifdef COMPRESS_MF_MT
- #include "../../../../C/Compress/Lz/MatchFinderMt.h"
- #endif
+ #include "../../../../C/LzmaEnc.h"
}
-#include "../RangeCoder/RangeCoderBitTree.h"
-
-#include "LZMA.h"
-
namespace NCompress {
namespace NLZMA {
-typedef NRangeCoder::CBitEncoder<kNumMoveBits> CMyBitEncoder;
-
-class CBaseState
-{
-protected:
- CState _state;
- Byte _previousByte;
- UInt32 _repDistances[kNumRepDistances];
- void Init()
- {
- _state.Init();
- _previousByte = 0;
- for(UInt32 i = 0 ; i < kNumRepDistances; i++)
- _repDistances[i] = 0;
- }
-};
-
-struct COptimal
-{
- CState State;
-
- bool Prev1IsChar;
- bool Prev2;
-
- UInt32 PosPrev2;
- UInt32 BackPrev2;
-
- UInt32 Price;
- UInt32 PosPrev; // posNext;
- UInt32 BackPrev;
- UInt32 Backs[kNumRepDistances];
- void MakeAsChar() { BackPrev = UInt32(-1); Prev1IsChar = false; }
- void MakeAsShortRep() { BackPrev = 0; ; Prev1IsChar = false; }
- bool IsShortRep() { return (BackPrev == 0); }
-};
-
-
-// #define LZMA_LOG_BRANCH
-
-#if _MSC_VER >= 1400
-// Must give gain in core 2. but slower ~2% on k8.
-// #define LZMA_LOG_BSR
-#endif
-
-#ifndef LZMA_LOG_BSR
-static const int kNumLogBits = 13; // don't change it !
-extern Byte g_FastPos[];
-#endif
-inline UInt32 GetPosSlot(UInt32 pos)
+struct CSeqInStream
{
- #ifdef LZMA_LOG_BSR
- if (pos < 2)
- return pos;
- unsigned long index;
- _BitScanReverse(&index, pos);
- return (index + index) + ((pos >> (index - 1)) & 1);
- #else
- if (pos < (1 << kNumLogBits))
- return g_FastPos[pos];
- if (pos < (1 << (kNumLogBits * 2 - 1)))
- return g_FastPos[pos >> (kNumLogBits - 1)] + (kNumLogBits - 1) * 2;
- return g_FastPos[pos >> (kNumLogBits - 1) * 2] + (kNumLogBits - 1) * 4;
- #endif
-}
-
-inline UInt32 GetPosSlot2(UInt32 pos)
-{
- #ifdef LZMA_LOG_BSR
- unsigned long index;
- _BitScanReverse(&index, pos);
- return (index + index) + ((pos >> (index - 1)) & 1);
- #else
- #ifdef LZMA_LOG_BRANCH
- if (pos < (1 << (kNumLogBits + 6)))
- return g_FastPos[pos >> 6] + 12;
- if (pos < (1 << (kNumLogBits * 2 + 5)))
- return g_FastPos[pos >> (kNumLogBits + 5)] + (kNumLogBits + 5) * 2;
- return g_FastPos[pos >> (kNumLogBits * 2 + 4)] + (kNumLogBits * 2 + 4) * 2;
- #else
- // it's faster with VC6-32bit.
- UInt32 s = 6 + ((kNumLogBits - 1) & (UInt32)((Int32)(((1 << (kNumLogBits + 6)) - 1) - pos) >> 31));
- return g_FastPos[pos >> s] + (s * 2);
- #endif
- #endif
-}
-
-const UInt32 kIfinityPrice = 0xFFFFFFF;
-
-const UInt32 kNumOpts = 1 << 12;
-
-
-class CLiteralEncoder2
-{
- CMyBitEncoder _encoders[0x300];
-public:
- void Init()
- {
- for (int i = 0; i < 0x300; i++)
- _encoders[i].Init();
- }
- void Encode(NRangeCoder::CEncoder *rangeEncoder, Byte symbol);
- void EncodeMatched(NRangeCoder::CEncoder *rangeEncoder, Byte matchByte, Byte symbol);
- UInt32 GetPrice(bool matchMode, Byte matchByte, Byte symbol) const;
-};
-
-class CLiteralEncoder
-{
- CLiteralEncoder2 *_coders;
- int _numPrevBits;
- int _numPosBits;
- UInt32 _posMask;
-public:
- CLiteralEncoder(): _coders(0) {}
- ~CLiteralEncoder() { Free(); }
- void Free()
- {
- MyFree(_coders);
- _coders = 0;
- }
- bool Create(int numPosBits, int numPrevBits)
- {
- if (_coders == 0 || (numPosBits + numPrevBits) != (_numPrevBits + _numPosBits))
- {
- Free();
- UInt32 numStates = 1 << (numPosBits + numPrevBits);
- _coders = (CLiteralEncoder2 *)MyAlloc(numStates * sizeof(CLiteralEncoder2));
- }
- _numPosBits = numPosBits;
- _posMask = (1 << numPosBits) - 1;
- _numPrevBits = numPrevBits;
- return (_coders != 0);
- }
- void Init()
- {
- UInt32 numStates = 1 << (_numPrevBits + _numPosBits);
- for (UInt32 i = 0; i < numStates; i++)
- _coders[i].Init();
- }
- CLiteralEncoder2 *GetSubCoder(UInt32 pos, Byte prevByte)
- { return &_coders[((pos & _posMask) << _numPrevBits) + (prevByte >> (8 - _numPrevBits))]; }
-};
-
-namespace NLength {
-
-class CEncoder
-{
- CMyBitEncoder _choice;
- CMyBitEncoder _choice2;
- NRangeCoder::CBitTreeEncoder<kNumMoveBits, kNumLowBits> _lowCoder[kNumPosStatesEncodingMax];
- NRangeCoder::CBitTreeEncoder<kNumMoveBits, kNumMidBits> _midCoder[kNumPosStatesEncodingMax];
- NRangeCoder::CBitTreeEncoder<kNumMoveBits, kNumHighBits> _highCoder;
-public:
- void Init(UInt32 numPosStates);
- void Encode(NRangeCoder::CEncoder *rangeEncoder, UInt32 symbol, UInt32 posState);
- void SetPrices(UInt32 posState, UInt32 numSymbols, UInt32 *prices) const;
+ ISeqInStream SeqInStream;
+ ISequentialInStream *RealStream;
};
-const UInt32 kNumSpecSymbols = kNumLowSymbols + kNumMidSymbols;
-
-class CPriceTableEncoder: public CEncoder
+struct CSeqOutStream
{
- UInt32 _prices[kNumPosStatesEncodingMax][kNumSymbolsTotal];
- UInt32 _tableSize;
- UInt32 _counters[kNumPosStatesEncodingMax];
-public:
- void SetTableSize(UInt32 tableSize) { _tableSize = tableSize; }
- UInt32 GetPrice(UInt32 symbol, UInt32 posState) const { return _prices[posState][symbol]; }
- void UpdateTable(UInt32 posState)
- {
- SetPrices(posState, _tableSize, _prices[posState]);
- _counters[posState] = _tableSize;
- }
- void UpdateTables(UInt32 numPosStates)
- {
- for (UInt32 posState = 0; posState < numPosStates; posState++)
- UpdateTable(posState);
- }
- void Encode(NRangeCoder::CEncoder *rangeEncoder, UInt32 symbol, UInt32 posState, bool updatePrice)
- {
- CEncoder::Encode(rangeEncoder, symbol, posState);
- if (updatePrice)
- if (--_counters[posState] == 0)
- UpdateTable(posState);
- }
+ ISeqOutStream SeqOutStream;
+ CMyComPtr<ISequentialOutStream> RealStream;
+ HRESULT Res;
};
-}
-
-typedef struct _CSeqInStream
-{
- ISeqInStream SeqInStream;
- CMyComPtr<ISequentialInStream> RealStream;
-} CSeqInStream;
-
-
class CEncoder :
public ICompressCoder,
public ICompressSetOutStream,
public ICompressSetCoderProperties,
public ICompressWriteCoderProperties,
- public CBaseState,
public CMyUnknownImp
{
- NRangeCoder::CEncoder _rangeEncoder;
-
- IMatchFinder _matchFinder;
- void *_matchFinderObj;
-
- #ifdef COMPRESS_MF_MT
- Bool _multiThread;
- Bool _mtMode;
- CMatchFinderMt _matchFinderMt;
- #endif
-
- CMatchFinder _matchFinderBase;
- #ifdef COMPRESS_MF_MT
- Byte _pad1[kMtCacheLineDummy];
- #endif
-
- COptimal _optimum[kNumOpts];
-
- CMyBitEncoder _isMatch[kNumStates][NLength::kNumPosStatesEncodingMax];
- CMyBitEncoder _isRep[kNumStates];
- CMyBitEncoder _isRepG0[kNumStates];
- CMyBitEncoder _isRepG1[kNumStates];
- CMyBitEncoder _isRepG2[kNumStates];
- CMyBitEncoder _isRep0Long[kNumStates][NLength::kNumPosStatesEncodingMax];
-
- NRangeCoder::CBitTreeEncoder<kNumMoveBits, kNumPosSlotBits> _posSlotEncoder[kNumLenToPosStates];
-
- CMyBitEncoder _posEncoders[kNumFullDistances - kEndPosModelIndex];
- NRangeCoder::CBitTreeEncoder<kNumMoveBits, kNumAlignBits> _posAlignEncoder;
-
- NLength::CPriceTableEncoder _lenEncoder;
- NLength::CPriceTableEncoder _repMatchLenEncoder;
-
- CLiteralEncoder _literalEncoder;
-
- UInt32 _matchDistances[kMatchMaxLen * 2 + 2 + 1];
-
- bool _fastMode;
- // bool _maxMode;
- UInt32 _numFastBytes;
- UInt32 _longestMatchLength;
- UInt32 _numDistancePairs;
-
- UInt32 _additionalOffset;
-
- UInt32 _optimumEndIndex;
- UInt32 _optimumCurrentIndex;
-
- bool _longestMatchWasFound;
-
- UInt32 _posSlotPrices[kNumLenToPosStates][kDistTableSizeMax];
+ CLzmaEncHandle _encoder;
- UInt32 _distancesPrices[kNumLenToPosStates][kNumFullDistances];
-
- UInt32 _alignPrices[kAlignTableSize];
- UInt32 _alignPriceCount;
-
- UInt32 _distTableSize;
-
- UInt32 _posStateBits;
- UInt32 _posStateMask;
- UInt32 _numLiteralPosStateBits;
- UInt32 _numLiteralContextBits;
-
- UInt32 _dictionarySize;
-
- UInt32 _matchPriceCount;
- UInt64 nowPos64;
- bool _finished;
- ISequentialInStream *_inStream;
-
CSeqInStream _seqInStream;
-
- UInt32 _matchFinderCycles;
- // int _numSkip
-
- bool _writeEndMark;
-
- bool _needReleaseMFStream;
-
- void ReleaseMatchFinder()
- {
- _matchFinder.Init = 0;
- _seqInStream.RealStream.Release();
- }
-
- void ReleaseMFStream()
- {
- if (_matchFinderObj && _needReleaseMFStream)
- {
- #ifdef COMPRESS_MF_MT
- if (_mtMode)
- MatchFinderMt_ReleaseStream(&_matchFinderMt);
- #endif
- _needReleaseMFStream = false;
- }
- _seqInStream.RealStream.Release();
- }
-
- UInt32 ReadMatchDistances(UInt32 &numDistancePairs);
-
- void MovePos(UInt32 num);
- UInt32 GetRepLen1Price(CState state, UInt32 posState) const
- {
- return _isRepG0[state.Index].GetPrice0() +
- _isRep0Long[state.Index][posState].GetPrice0();
- }
-
- UInt32 GetPureRepPrice(UInt32 repIndex, CState state, UInt32 posState) const
- {
- UInt32 price;
- if(repIndex == 0)
- {
- price = _isRepG0[state.Index].GetPrice0();
- price += _isRep0Long[state.Index][posState].GetPrice1();
- }
- else
- {
- price = _isRepG0[state.Index].GetPrice1();
- if (repIndex == 1)
- price += _isRepG1[state.Index].GetPrice0();
- else
- {
- price += _isRepG1[state.Index].GetPrice1();
- price += _isRepG2[state.Index].GetPrice(repIndex - 2);
- }
- }
- return price;
- }
- UInt32 GetRepPrice(UInt32 repIndex, UInt32 len, CState state, UInt32 posState) const
- {
- return _repMatchLenEncoder.GetPrice(len - kMatchMinLen, posState) +
- GetPureRepPrice(repIndex, state, posState);
- }
- /*
- UInt32 GetPosLen2Price(UInt32 pos, UInt32 posState) const
- {
- if (pos >= kNumFullDistances)
- return kIfinityPrice;
- return _distancesPrices[0][pos] + _lenEncoder.GetPrice(0, posState);
- }
- UInt32 GetPosLen3Price(UInt32 pos, UInt32 len, UInt32 posState) const
- {
- UInt32 price;
- UInt32 lenToPosState = GetLenToPosState(len);
- if (pos < kNumFullDistances)
- price = _distancesPrices[lenToPosState][pos];
- else
- price = _posSlotPrices[lenToPosState][GetPosSlot2(pos)] +
- _alignPrices[pos & kAlignMask];
- return price + _lenEncoder.GetPrice(len - kMatchMinLen, posState);
- }
- */
- UInt32 GetPosLenPrice(UInt32 pos, UInt32 len, UInt32 posState) const
- {
- UInt32 price;
- UInt32 lenToPosState = GetLenToPosState(len);
- if (pos < kNumFullDistances)
- price = _distancesPrices[lenToPosState][pos];
- else
- price = _posSlotPrices[lenToPosState][GetPosSlot2(pos)] +
- _alignPrices[pos & kAlignMask];
- return price + _lenEncoder.GetPrice(len - kMatchMinLen, posState);
- }
-
- UInt32 Backward(UInt32 &backRes, UInt32 cur);
- UInt32 GetOptimum(UInt32 position, UInt32 &backRes);
- UInt32 GetOptimumFast(UInt32 &backRes);
-
- void FillDistancesPrices();
- void FillAlignPrices();
-
- void ReleaseStreams()
- {
- ReleaseMFStream();
- ReleaseOutStream();
- }
-
- HRESULT Flush(UInt32 nowPos);
- class CCoderReleaser
- {
- CEncoder *_coder;
- public:
- CCoderReleaser(CEncoder *coder): _coder(coder) {}
- ~CCoderReleaser() { _coder->ReleaseStreams(); }
- };
- friend class CCoderReleaser;
-
- void WriteEndMarker(UInt32 posState);
+ CSeqOutStream _seqOutStream;
public:
CEncoder();
- void SetWriteEndMarkerMode(bool writeEndMarker)
- { _writeEndMark= writeEndMarker; }
-
- HRESULT Create();
MY_UNKNOWN_IMP3(
ICompressSetOutStream,
@@ -428,20 +48,7 @@ public:
ICompressWriteCoderProperties
)
- HRESULT Init();
-
- // ICompressCoder interface
- HRESULT SetStreams(ISequentialInStream *inStream,
- ISequentialOutStream *outStream,
- const UInt64 *inSize, const UInt64 *outSize);
- HRESULT CodeOneBlock(UInt64 *inSize, UInt64 *outSize, Int32 *finished);
-
- HRESULT CodeReal(ISequentialInStream *inStream,
- ISequentialOutStream *outStream,
- const UInt64 *inSize, const UInt64 *outSize,
- ICompressProgressInfo *progress);
-
- // ICompressCoder interface
+
STDMETHOD(Code)(ISequentialInStream *inStream,
ISequentialOutStream *outStream,
const UInt64 *inSize, const UInt64 *outSize,
diff --git a/CPP/7zip/Compress/LZMA/makefile b/CPP/7zip/Compress/LZMA/makefile
deleted file mode 100755
index 4a108b42..00000000
--- a/CPP/7zip/Compress/LZMA/makefile
+++ /dev/null
@@ -1,70 +0,0 @@
-PROG = LZMA.dll
-DEF_FILE = ../Codec.def
-CFLAGS = $(CFLAGS) -I ../../../ \
- -DCOMPRESS_MF_MT \
- -D_7ZIP_LARGE_PAGES \
-
-LIBS = $(LIBS) oleaut32.lib
-
-COMPRESS_OBJS = \
- $O\CodecExports.obj \
- $O\DllExports.obj \
-
-COMMON_OBJS = \
- $O\CRC.obj \
-
-LZMA_OPT_OBJS = \
- $O\LZMADecoder.obj \
- $O\LZMAEncoder.obj \
- $O\LZMARegister.obj \
-
-7ZIP_COMMON_OBJS = \
- $O\InBuffer.obj \
- $O\OutBuffer.obj \
- $O\StreamUtils.obj \
-
-LZ_OBJS = \
- $O\LZOutWindow.obj \
-
-C_OBJS = \
- $O\Threads.obj \
- $O\Alloc.obj \
-
-C_LZ_OBJS = \
- $O\MatchFinder.obj \
- $O\MatchFinderMt.obj \
-
-!include "../../Crc2.mak"
-
-OBJS = \
- $O\StdAfx.obj \
- $(COMPRESS_OBJS) \
- $(COMMON_OBJS) \
- $(LZMA_OPT_OBJS) \
- $(7ZIP_COMMON_OBJS) \
- $(LZ_OBJS) \
- $(C_OBJS) \
- $(C_LZ_OBJS) \
- $(CRC_OBJS) \
- $O\RangeCoderBit.obj \
- $O\resource.res
-
-!include "../../../Build.mak"
-
-$(COMPRESS_OBJS): ../$(*B).cpp
- $(COMPL)
-$(COMMON_OBJS): ../../../Common/$(*B).cpp
- $(COMPL)
-$(LZMA_OPT_OBJS): $(*B).cpp
- $(COMPL_O2)
-$(7ZIP_COMMON_OBJS): ../../Common/$(*B).cpp
- $(COMPL)
-$(LZ_OBJS): ../LZ/$(*B).cpp
- $(COMPL)
-$O\RangeCoderBit.obj: ../RangeCoder/$(*B).cpp
- $(COMPL)
-$(C_OBJS): ../../../../C/$(*B).c
- $(COMPL_O2)
-$(C_LZ_OBJS): ../../../../C/Compress/Lz/$(*B).c
- $(COMPL_O2)
-!include "../../Crc.mak"
diff --git a/CPP/7zip/Compress/LZMA/resource.rc b/CPP/7zip/Compress/LZMA/resource.rc
deleted file mode 100755
index 1b2b6abb..00000000
--- a/CPP/7zip/Compress/LZMA/resource.rc
+++ /dev/null
@@ -1,3 +0,0 @@
-#include "../../MyVersionInfo.rc"
-
-MY_VERSION_INFO_DLL("LZMA Codec", "LZMA")
diff --git a/CPP/7zip/Compress/LZMA_Alone/AloneLZMA.dsp b/CPP/7zip/Compress/LZMA_Alone/AloneLZMA.dsp
index 39fee934..a09c3069 100755
--- a/CPP/7zip/Compress/LZMA_Alone/AloneLZMA.dsp
+++ b/CPP/7zip/Compress/LZMA_Alone/AloneLZMA.dsp
@@ -371,134 +371,132 @@ SOURCE=..\..\Common\StreamUtils.h
# Begin Group "C"
# PROP Default_Filter ""
-# Begin Group "C-Lz"
+# Begin Group "LzmaUtil"
# PROP Default_Filter ""
# Begin Source File
-SOURCE=..\..\..\..\C\Compress\Lz\MatchFinder.c
+SOURCE=..\..\..\..\C\LzmaUtil\Lzma86Dec.c
# SUBTRACT CPP /YX /Yc /Yu
# End Source File
# Begin Source File
-SOURCE=..\..\..\..\C\Compress\Lz\MatchFinder.h
+SOURCE=..\..\..\..\C\LzmaUtil\Lzma86Dec.h
# End Source File
# Begin Source File
-SOURCE=..\..\..\..\C\Compress\Lz\MatchFinderMt.c
+SOURCE=..\..\..\..\C\LzmaUtil\Lzma86Enc.c
# SUBTRACT CPP /YX /Yc /Yu
# End Source File
# Begin Source File
-SOURCE=..\..\..\..\C\Compress\Lz\MatchFinderMt.h
+SOURCE=..\..\..\..\C\LzmaUtil\Lzma86Enc.h
# End Source File
+# End Group
# Begin Source File
-SOURCE=..\..\..\..\C\Threads.c
+SOURCE=..\..\..\..\C\7zCrc.c
# SUBTRACT CPP /YX /Yc /Yu
# End Source File
# Begin Source File
-SOURCE=..\..\..\..\C\Threads.h
+SOURCE=..\..\..\..\C\7zCrc.h
# End Source File
-# End Group
-# Begin Group "LZMA_C"
-
-# PROP Default_Filter ""
# Begin Source File
-SOURCE=..\..\..\..\C\Compress\Lzma\LzmaDecode.c
+SOURCE=..\..\..\..\C\Alloc.c
# SUBTRACT CPP /YX /Yc /Yu
# End Source File
# Begin Source File
-SOURCE=..\..\..\..\C\Compress\Lzma\LzmaDecode.h
+SOURCE=..\..\..\..\C\Alloc.h
# End Source File
# Begin Source File
-SOURCE=..\..\..\..\C\Compress\Lzma\LzmaTypes.h
+SOURCE=..\..\..\..\C\Bra.h
# End Source File
-# End Group
-# Begin Group "Branch"
-
-# PROP Default_Filter ""
# Begin Source File
-SOURCE=..\..\..\..\C\Compress\Branch\BranchTypes.h
+SOURCE=..\..\..\..\C\Bra86.c
+# SUBTRACT CPP /YX /Yc /Yu
# End Source File
# Begin Source File
-SOURCE=..\..\..\..\C\Compress\Branch\BranchX86.c
+SOURCE=..\..\..\..\C\LzFind.c
# SUBTRACT CPP /YX /Yc /Yu
# End Source File
# Begin Source File
-SOURCE=..\..\..\..\C\Compress\Branch\BranchX86.h
+SOURCE=..\..\..\..\C\LzFind.h
# End Source File
-# End Group
# Begin Source File
-SOURCE=..\..\..\..\C\7zCrc.c
+SOURCE=..\..\..\..\C\LzFindMt.c
# SUBTRACT CPP /YX /Yc /Yu
# End Source File
# Begin Source File
-SOURCE=..\..\..\..\C\7zCrc.h
+SOURCE=..\..\..\..\C\LzFindMt.h
# End Source File
# Begin Source File
-SOURCE=..\..\..\..\C\Alloc.c
+SOURCE=..\..\..\..\C\LzHash.h
+# End Source File
+# Begin Source File
+
+SOURCE=..\..\..\..\C\LzmaDec.c
# SUBTRACT CPP /YX /Yc /Yu
# End Source File
# Begin Source File
-SOURCE=..\..\..\..\C\Alloc.h
+SOURCE=..\..\..\..\C\LzmaDec.h
# End Source File
# Begin Source File
-SOURCE=..\..\..\..\C\Types.h
+SOURCE=..\..\..\..\C\LzmaEnc.c
+# SUBTRACT CPP /YX /Yc /Yu
# End Source File
-# End Group
# Begin Source File
-SOURCE=..\..\ICoder.h
+SOURCE=..\..\..\..\C\LzmaEnc.h
# End Source File
# Begin Source File
-SOURCE=.\LzmaAlone.cpp
+SOURCE=..\..\..\..\C\Threads.c
+# SUBTRACT CPP /YX /Yc /Yu
# End Source File
# Begin Source File
-SOURCE=.\LzmaBench.cpp
+SOURCE=..\..\..\..\C\Threads.h
# End Source File
# Begin Source File
-SOURCE=.\LzmaBench.h
+SOURCE=..\..\..\..\C\Types.h
# End Source File
+# End Group
# Begin Source File
-SOURCE=.\LzmaBenchCon.cpp
+SOURCE=..\..\ICoder.h
# End Source File
# Begin Source File
-SOURCE=.\LzmaBenchCon.h
+SOURCE=.\LzmaAlone.cpp
# End Source File
# Begin Source File
-SOURCE=.\LzmaRam.cpp
+SOURCE=.\LzmaBench.cpp
# End Source File
# Begin Source File
-SOURCE=.\LzmaRam.h
+SOURCE=.\LzmaBench.h
# End Source File
# Begin Source File
-SOURCE=.\LzmaRamDecode.c
-# SUBTRACT CPP /YX /Yc /Yu
+SOURCE=.\LzmaBenchCon.cpp
# End Source File
# Begin Source File
-SOURCE=.\LzmaRamDecode.h
+SOURCE=.\LzmaBenchCon.h
# End Source File
# End Target
# End Project
diff --git a/CPP/7zip/Compress/LZMA_Alone/LzmaAlone.cpp b/CPP/7zip/Compress/LZMA_Alone/LzmaAlone.cpp
index 0e83f576..0d2800bd 100755
--- a/CPP/7zip/Compress/LZMA_Alone/LzmaAlone.cpp
+++ b/CPP/7zip/Compress/LZMA_Alone/LzmaAlone.cpp
@@ -26,15 +26,19 @@
#include "../LZMA/LZMAEncoder.h"
#include "LzmaBenchCon.h"
-#include "LzmaRam.h"
#ifdef COMPRESS_MF_MT
#include "../../../Windows/System.h"
#endif
+#include "../../MyVersion.h"
+
+
extern "C"
{
-#include "LzmaRamDecode.h"
+ #include "../../../../C/Alloc.h"
+ #include "../../../../C/LzmaUtil/Lzma86Dec.h"
+ #include "../../../../C/LzmaUtil/Lzma86Enc.h"
}
using namespace NCommandLineParser;
@@ -105,7 +109,7 @@ static void PrintHelp()
" b: Benchmark\n"
"<Switches>\n"
" -a{N}: set compression mode - [0, 1], default: 1 (max)\n"
- " -d{N}: set dictionary - [0,30], default: 23 (8MB)\n"
+ " -d{N}: set dictionary - [12, 30], default: 23 (8MB)\n"
" -fb{N}: set number of fast bytes - [5, 273], default: 128\n"
" -mc{N}: set number of cycles for match finder\n"
" -lc{N}: set number of literal context bits - [0, 8], default: 3\n"
@@ -159,7 +163,7 @@ int main2(int n, const char *args[])
g_IsNT = IsItWindowsNT();
#endif
- fprintf(stderr, "\nLZMA 4.56 Copyright (c) 1999-2007 Igor Pavlov 2007-10-19\n");
+ fprintf(stderr, "\nLZMA " MY_VERSION_COPYRIGHT_DATE "\n");
if (n == 1)
{
@@ -306,7 +310,7 @@ int main2(int n, const char *args[])
inStreamSpec->File.GetLength(fileSize);
if (fileSize > 0xF0000000)
throw "File is too big";
- UInt32 inSize = (UInt32)fileSize;
+ size_t inSize = (size_t)fileSize;
Byte *inBuffer = 0;
if (inSize != 0)
{
@@ -315,18 +319,15 @@ int main2(int n, const char *args[])
throw kCantAllocate;
}
- UInt32 processedSize;
- if (ReadStream(inStream, inBuffer, (UInt32)inSize, &processedSize) != S_OK)
+ if (ReadStream_FAIL(inStream, inBuffer, inSize) != S_OK)
throw "Can not read";
- if ((UInt32)inSize != processedSize)
- throw "Read size error";
Byte *outBuffer = 0;
- size_t outSizeProcessed;
+ size_t outSize;
if (encodeMode)
{
// we allocate 105% of original size for output buffer
- size_t outSize = (size_t)fileSize / 20 * 21 + (1 << 16);
+ outSize = (size_t)fileSize / 20 * 21 + (1 << 16);
if (outSize != 0)
{
outBuffer = (Byte *)MyAlloc((size_t)outSize);
@@ -335,8 +336,8 @@ int main2(int n, const char *args[])
}
if (!dictionaryIsDefined)
dictionary = 1 << 23;
- int res = LzmaRamEncode(inBuffer, inSize, outBuffer, outSize, &outSizeProcessed,
- dictionary, parser[NKey::kFilter86].PostCharIndex == 0 ? SZ_FILTER_YES : SZ_FILTER_AUTO);
+ int res = Lzma86_Encode(outBuffer, &outSize, inBuffer, inSize,
+ 5, dictionary, parser[NKey::kFilter86].PostCharIndex == 0 ? SZ_FILTER_YES : SZ_FILTER_AUTO);
if (res != 0)
{
fprintf(stderr, "\nEncoder error = %d\n", (int)res);
@@ -345,20 +346,25 @@ int main2(int n, const char *args[])
}
else
{
- size_t outSize;
- if (LzmaRamGetUncompressedSize(inBuffer, inSize, &outSize) != 0)
+ UInt64 outSize64;
+ if (Lzma86_GetUnpackSize(inBuffer, inSize, &outSize64) != 0)
throw "data error";
+ outSize = (size_t)outSize64;
+ if (outSize != outSize64)
+ throw "too big";
if (outSize != 0)
{
outBuffer = (Byte *)MyAlloc(outSize);
if (outBuffer == 0)
throw kCantAllocate;
}
- int res = LzmaRamDecompress(inBuffer, inSize, outBuffer, outSize, &outSizeProcessed, malloc, free);
+ int res = Lzma86_Decode(outBuffer, &outSize, inBuffer, &inSize);
+ if (inSize != (size_t)fileSize)
+ throw "incorrect processed size";
if (res != 0)
throw "LzmaDecoder error";
}
- if (WriteStream(outStream, outBuffer, (UInt32)outSizeProcessed, &processedSize) != S_OK)
+ if (WriteStream(outStream, outBuffer, outSize) != S_OK)
throw kWriteError;
MyFree(outBuffer);
MyFree(inBuffer);
@@ -486,40 +492,22 @@ int main2(int n, const char *args[])
NCompress::NLZMA::CDecoder *decoderSpec = new NCompress::NLZMA::CDecoder;
CMyComPtr<ICompressCoder> decoder = decoderSpec;
const UInt32 kPropertiesSize = 5;
- Byte properties[kPropertiesSize];
- UInt32 processedSize;
- if (ReadStream(inStream, properties, kPropertiesSize, &processedSize) != S_OK)
- {
- fprintf(stderr, kReadError);
- return 1;
- }
- if (processedSize != kPropertiesSize)
+ Byte header[kPropertiesSize + 8];
+ if (ReadStream_FALSE(inStream, header, kPropertiesSize + 8) != S_OK)
{
fprintf(stderr, kReadError);
return 1;
}
- if (decoderSpec->SetDecoderProperties2(properties, kPropertiesSize) != S_OK)
+ if (decoderSpec->SetDecoderProperties2(header, kPropertiesSize) != S_OK)
{
fprintf(stderr, "SetDecoderProperties error");
return 1;
}
fileSize = 0;
for (int i = 0; i < 8; i++)
- {
- Byte b;
- if (inStream->Read(&b, 1, &processedSize) != S_OK)
- {
- fprintf(stderr, kReadError);
- return 1;
- }
- if (processedSize != 1)
- {
- fprintf(stderr, kReadError);
- return 1;
- }
- fileSize |= ((UInt64)b) << (8 * i);
- }
- if (decoder->Code(inStream, outStream, 0, &fileSize, 0) != S_OK)
+ fileSize |= ((UInt64)header[kPropertiesSize + i]) << (8 * i);
+
+ if (decoder->Code(inStream, outStream, 0, (fileSize == (UInt64)(Int64)-1) ? 0 : &fileSize, 0) != S_OK)
{
fprintf(stderr, "Decoder error");
return 1;
@@ -536,7 +524,7 @@ int main2(int n, const char *args[])
return 0;
}
-int main(int n, const char *args[])
+int MY_CDECL main(int n, const char *args[])
{
try { return main2(n, args); }
catch(const char *s)
diff --git a/CPP/7zip/Compress/LZMA_Alone/LzmaBench.cpp b/CPP/7zip/Compress/LZMA_Alone/LzmaBench.cpp
index 4cd2d63e..cbb0aa86 100755
--- a/CPP/7zip/Compress/LZMA_Alone/LzmaBench.cpp
+++ b/CPP/7zip/Compress/LZMA_Alone/LzmaBench.cpp
@@ -438,17 +438,14 @@ static UInt64 MyMultDiv64(UInt64 value, UInt64 elapsedTime, UInt64 freq)
UInt64 GetCompressRating(UInt32 dictionarySize, UInt64 elapsedTime, UInt64 freq, UInt64 size)
{
UInt64 t = GetLogSize(dictionarySize) - (kBenchMinDicLogSize << kSubBits);
- // UInt64 numCommandsForOne = 1000 + ((t * t * 7) >> (2 * kSubBits)); // AMD K8
- UInt64 numCommandsForOne = 870 + ((t * t * 5) >> (2 * kSubBits)); // Intel Core2
-
+ UInt64 numCommandsForOne = 870 + ((t * t * 5) >> (2 * kSubBits));
UInt64 numCommands = (UInt64)(size) * numCommandsForOne;
return MyMultDiv64(numCommands, elapsedTime, freq);
}
UInt64 GetDecompressRating(UInt64 elapsedTime, UInt64 freq, UInt64 outSize, UInt64 inSize, UInt32 numIterations)
{
- // UInt64 numCommands = (inSize * 216 + outSize * 14) * numIterations; // AMD K8
- UInt64 numCommands = (inSize * 220 + outSize * 8) * numIterations; // Intel Core2
+ UInt64 numCommands = (inSize * 200 + outSize * 4) * numIterations;
return MyMultDiv64(numCommands, elapsedTime, freq);
}
@@ -796,10 +793,9 @@ HRESULT LzmaBench(
{
for (UInt32 j = 0; j < numSubDecoderThreads; j++)
{
- size_t allocaSize = ((i * numSubDecoderThreads + j) * 16 * 21) & 0x7FF;
HRESULT res = encoder.CreateDecoderThread(j, (i == 0 && j == 0)
#ifdef USE_ALLOCA
- , allocaSize
+ , ((i * numSubDecoderThreads + j) * 16 * 21) & 0x7FF
#endif
);
RINOK(res);
diff --git a/CPP/7zip/Compress/LZMA_Alone/LzmaRam.cpp b/CPP/7zip/Compress/LZMA_Alone/LzmaRam.cpp
deleted file mode 100755
index b86d1ea9..00000000
--- a/CPP/7zip/Compress/LZMA_Alone/LzmaRam.cpp
+++ /dev/null
@@ -1,226 +0,0 @@
-// LzmaRam.cpp
-
-#include "StdAfx.h"
-#include "../../../Common/Types.h"
-#include "../LZMA/LZMADecoder.h"
-#include "../LZMA/LZMAEncoder.h"
-#include "LzmaRam.h"
-
-extern "C"
-{
- #include "../../../../C/Compress/Branch/BranchX86.h"
-}
-
-class CInStreamRam:
- public ISequentialInStream,
- public CMyUnknownImp
-{
- const Byte *Data;
- size_t Size;
- size_t Pos;
-public:
- MY_UNKNOWN_IMP
- void Init(const Byte *data, size_t size)
- {
- Data = data;
- Size = size;
- Pos = 0;
- }
- STDMETHOD(Read)(void *data, UInt32 size, UInt32 *processedSize);
-};
-
-STDMETHODIMP CInStreamRam::Read(void *data, UInt32 size, UInt32 *processedSize)
-{
- if (size > (Size - Pos))
- size = (UInt32)(Size - Pos);
- for (UInt32 i = 0; i < size; i++)
- ((Byte *)data)[i] = Data[Pos + i];
- Pos += size;
- if(processedSize != NULL)
- *processedSize = size;
- return S_OK;
-}
-
-class COutStreamRam:
- public ISequentialOutStream,
- public CMyUnknownImp
-{
- size_t Size;
-public:
- Byte *Data;
- size_t Pos;
- bool Overflow;
- void Init(Byte *data, size_t size)
- {
- Data = data;
- Size = size;
- Pos = 0;
- Overflow = false;
- }
- void SetPos(size_t pos)
- {
- Overflow = false;
- Pos = pos;
- }
- MY_UNKNOWN_IMP
- HRESULT WriteByte(Byte b)
- {
- if (Pos >= Size)
- {
- Overflow = true;
- return E_FAIL;
- }
- Data[Pos++] = b;
- return S_OK;
- }
- STDMETHOD(Write)(const void *data, UInt32 size, UInt32 *processedSize);
-};
-
-STDMETHODIMP COutStreamRam::Write(const void *data, UInt32 size, UInt32 *processedSize)
-{
- UInt32 i;
- for (i = 0; i < size && Pos < Size; i++)
- Data[Pos++] = ((const Byte *)data)[i];
- if(processedSize != NULL)
- *processedSize = i;
- if (i != size)
- {
- Overflow = true;
- return E_FAIL;
- }
- return S_OK;
-}
-
-#define SZ_RAM_E_FAIL (1)
-#define SZ_RAM_E_OUTOFMEMORY (2)
-#define SZE_OUT_OVERFLOW (3)
-
-int LzmaRamEncode(
- const Byte *inBuffer, size_t inSize,
- Byte *outBuffer, size_t outSize, size_t *outSizeProcessed,
- UInt32 dictionarySize, ESzFilterMode filterMode)
-{
- #ifndef _NO_EXCEPTIONS
- try {
- #endif
-
- *outSizeProcessed = 0;
- const size_t kIdSize = 1;
- const size_t kLzmaPropsSize = 5;
- const size_t kMinDestSize = kIdSize + kLzmaPropsSize + 8;
- if (outSize < kMinDestSize)
- return SZE_OUT_OVERFLOW;
- NCompress::NLZMA::CEncoder *encoderSpec = new NCompress::NLZMA::CEncoder;
- CMyComPtr<ICompressCoder> encoder = encoderSpec;
-
- PROPID propIDs[] =
- {
- NCoderPropID::kAlgorithm,
- NCoderPropID::kDictionarySize,
- NCoderPropID::kNumFastBytes,
- };
- const int kNumProps = sizeof(propIDs) / sizeof(propIDs[0]);
- PROPVARIANT properties[kNumProps];
- properties[0].vt = VT_UI4;
- properties[1].vt = VT_UI4;
- properties[2].vt = VT_UI4;
- properties[0].ulVal = (UInt32)2;
- properties[1].ulVal = (UInt32)dictionarySize;
- properties[2].ulVal = (UInt32)64;
-
- if (encoderSpec->SetCoderProperties(propIDs, properties, kNumProps) != S_OK)
- return 1;
-
- COutStreamRam *outStreamSpec = new COutStreamRam;
- if (outStreamSpec == 0)
- return SZ_RAM_E_OUTOFMEMORY;
- CMyComPtr<ISequentialOutStream> outStream = outStreamSpec;
- CInStreamRam *inStreamSpec = new CInStreamRam;
- if (inStreamSpec == 0)
- return SZ_RAM_E_OUTOFMEMORY;
- CMyComPtr<ISequentialInStream> inStream = inStreamSpec;
-
- outStreamSpec->Init(outBuffer, outSize);
- if (outStreamSpec->WriteByte(0) != S_OK)
- return SZE_OUT_OVERFLOW;
-
- if (encoderSpec->WriteCoderProperties(outStream) != S_OK)
- return SZE_OUT_OVERFLOW;
- if (outStreamSpec->Pos != kIdSize + kLzmaPropsSize)
- return 1;
-
- int i;
- for (i = 0; i < 8; i++)
- {
- UInt64 t = (UInt64)(inSize);
- if (outStreamSpec->WriteByte((Byte)((t) >> (8 * i))) != S_OK)
- return SZE_OUT_OVERFLOW;
- }
-
- Byte *filteredStream = 0;
-
- bool useFilter = (filterMode != SZ_FILTER_NO);
- if (useFilter)
- {
- if (inSize != 0)
- {
- filteredStream = (Byte *)MyAlloc(inSize);
- if (filteredStream == 0)
- return SZ_RAM_E_OUTOFMEMORY;
- memmove(filteredStream, inBuffer, inSize);
- }
- UInt32 x86State;
- x86_Convert_Init(x86State);
- x86_Convert(filteredStream, (SizeT)inSize, 0, &x86State, 1);
- }
-
- size_t minSize = 0;
- int numPasses = (filterMode == SZ_FILTER_AUTO) ? 3 : 1;
- bool bestIsFiltered = false;
- int mainResult = 0;
- size_t startPos = outStreamSpec->Pos;
- for (i = 0; i < numPasses; i++)
- {
- if (numPasses > 1 && i == numPasses - 1 && !bestIsFiltered)
- break;
- outStreamSpec->SetPos(startPos);
- bool curModeIsFiltered = false;
- if (useFilter && i == 0)
- curModeIsFiltered = true;
- if (numPasses > 1 && i == numPasses - 1)
- curModeIsFiltered = true;
-
- inStreamSpec->Init(curModeIsFiltered ? filteredStream : inBuffer, inSize);
-
- HRESULT lzmaResult = encoder->Code(inStream, outStream, 0, 0, 0);
-
- mainResult = 0;
- if (lzmaResult == E_OUTOFMEMORY)
- {
- mainResult = SZ_RAM_E_OUTOFMEMORY;
- break;
- }
- if (i == 0 || outStreamSpec->Pos <= minSize)
- {
- minSize = outStreamSpec->Pos;
- bestIsFiltered = curModeIsFiltered;
- }
- if (outStreamSpec->Overflow)
- mainResult = SZE_OUT_OVERFLOW;
- else if (lzmaResult != S_OK)
- {
- mainResult = SZ_RAM_E_FAIL;
- break;
- }
- }
- *outSizeProcessed = outStreamSpec->Pos;
- if (bestIsFiltered)
- outBuffer[0] = 1;
- if (useFilter)
- MyFree(filteredStream);
- return mainResult;
-
- #ifndef _NO_EXCEPTIONS
- } catch(...) { return SZ_RAM_E_OUTOFMEMORY; }
- #endif
-}
diff --git a/CPP/7zip/Compress/LZMA_Alone/LzmaRam.h b/CPP/7zip/Compress/LZMA_Alone/LzmaRam.h
deleted file mode 100755
index 1244dc86..00000000
--- a/CPP/7zip/Compress/LZMA_Alone/LzmaRam.h
+++ /dev/null
@@ -1,46 +0,0 @@
-// LzmaRam.h
-
-#ifndef __LzmaRam_h
-#define __LzmaRam_h
-
-#include <stdlib.h>
-#include "../../../Common/Types.h"
-
-/*
-LzmaRamEncode: BCJ + LZMA RAM->RAM compressing.
-It uses .lzma format, but it writes one additional byte to .lzma file:
- 0: - no filter
- 1: - x86(BCJ) filter.
-
-To provide best compression ratio dictionarySize mustbe >= inSize
-
-LzmaRamEncode allocates Data with MyAlloc/BigAlloc functions.
-RAM Requirements:
- RamSize = dictionarySize * 9.5 + 6MB + FilterBlockSize
- FilterBlockSize = 0, if useFilter == false
- FilterBlockSize = inSize, if useFilter == true
-
- Return code:
- 0 - OK
- 1 - Unspecified Error
- 2 - Memory allocating error
- 3 - Output buffer OVERFLOW
-
-If you use SZ_FILTER_AUTO mode, then encoder will use 2 or 3 passes:
- 2 passes when FILTER_NO provides better compression.
- 3 passes when FILTER_YES provides better compression.
-*/
-
-enum ESzFilterMode
-{
- SZ_FILTER_NO,
- SZ_FILTER_YES,
- SZ_FILTER_AUTO
-};
-
-int LzmaRamEncode(
- const Byte *inBuffer, size_t inSize,
- Byte *outBuffer, size_t outSize, size_t *outSizeProcessed,
- UInt32 dictionarySize, ESzFilterMode filterMode);
-
-#endif
diff --git a/CPP/7zip/Compress/LZMA_Alone/LzmaRamDecode.c b/CPP/7zip/Compress/LZMA_Alone/LzmaRamDecode.c
deleted file mode 100755
index 29f798be..00000000
--- a/CPP/7zip/Compress/LZMA_Alone/LzmaRamDecode.c
+++ /dev/null
@@ -1,78 +0,0 @@
-/* LzmaRamDecode.c */
-
-#include "LzmaRamDecode.h"
-#ifdef _SZ_ONE_DIRECTORY
-#include "LzmaDecode.h"
-#include "BranchX86.h"
-#else
-#include "../../../../C/Compress/Lzma/LzmaDecode.h"
-#include "../../../../C/Compress/Branch/BranchX86.h"
-#endif
-
-#define LZMA_PROPS_SIZE 14
-#define LZMA_SIZE_OFFSET 6
-
-int LzmaRamGetUncompressedSize(
- const unsigned char *inBuffer,
- size_t inSize,
- size_t *outSize)
-{
- unsigned int i;
- if (inSize < LZMA_PROPS_SIZE)
- return 1;
- *outSize = 0;
- for(i = 0; i < sizeof(size_t); i++)
- *outSize += ((size_t)inBuffer[LZMA_SIZE_OFFSET + i]) << (8 * i);
- for(; i < 8; i++)
- if (inBuffer[LZMA_SIZE_OFFSET + i] != 0)
- return 1;
- return 0;
-}
-
-#define SZE_DATA_ERROR (1)
-#define SZE_OUTOFMEMORY (2)
-
-int LzmaRamDecompress(
- const unsigned char *inBuffer,
- size_t inSize,
- unsigned char *outBuffer,
- size_t outSize,
- size_t *outSizeProcessed,
- void * (*allocFunc)(size_t size),
- void (*freeFunc)(void *))
-{
- CLzmaDecoderState state; /* it's about 24 bytes structure, if int is 32-bit */
- int result;
- SizeT outSizeProcessedLoc;
- SizeT inProcessed;
- int useFilter;
-
- if (inSize < LZMA_PROPS_SIZE)
- return 1;
- useFilter = inBuffer[0];
-
- *outSizeProcessed = 0;
- if (useFilter > 1)
- return 1;
-
- if (LzmaDecodeProperties(&state.Properties, inBuffer + 1, LZMA_PROPERTIES_SIZE) != LZMA_RESULT_OK)
- return 1;
- state.Probs = (CProb *)allocFunc(LzmaGetNumProbs(&state.Properties) * sizeof(CProb));
- if (state.Probs == 0)
- return SZE_OUTOFMEMORY;
-
- result = LzmaDecode(&state,
- inBuffer + LZMA_PROPS_SIZE, (SizeT)inSize - LZMA_PROPS_SIZE, &inProcessed,
- outBuffer, (SizeT)outSize, &outSizeProcessedLoc);
- freeFunc(state.Probs);
- if (result != LZMA_RESULT_OK)
- return 1;
- *outSizeProcessed = (size_t)outSizeProcessedLoc;
- if (useFilter == 1)
- {
- UInt32 x86State;
- x86_Convert_Init(x86State);
- x86_Convert(outBuffer, (SizeT)outSizeProcessedLoc, 0, &x86State, 0);
- }
- return 0;
-}
diff --git a/CPP/7zip/Compress/LZMA_Alone/LzmaRamDecode.h b/CPP/7zip/Compress/LZMA_Alone/LzmaRamDecode.h
deleted file mode 100755
index 7e641c55..00000000
--- a/CPP/7zip/Compress/LZMA_Alone/LzmaRamDecode.h
+++ /dev/null
@@ -1,55 +0,0 @@
-/* LzmaRamDecode.h */
-
-#ifndef __LzmaRamDecode_h
-#define __LzmaRamDecode_h
-
-#include <stdlib.h>
-
-/*
-LzmaRamGetUncompressedSize:
- In:
- inBuffer - input data
- inSize - input data size
- Out:
- outSize - uncompressed size
- Return code:
- 0 - OK
- 1 - Error in headers
-*/
-
-int LzmaRamGetUncompressedSize(
- const unsigned char *inBuffer,
- size_t inSize,
- size_t *outSize);
-
-
-/*
-LzmaRamDecompress:
- In:
- inBuffer - input data
- inSize - input data size
- outBuffer - output data
- outSize - output size
- allocFunc - alloc function (can be malloc)
- freeFunc - free function (can be free)
- Out:
- outSizeProcessed - processed size
- Return code:
- 0 - OK
- 1 - Error in headers / data stream
- 2 - Memory allocating error
-
-Memory requirements depend from properties of LZMA stream.
-With default lzma settings it's about 16 KB.
-*/
-
-int LzmaRamDecompress(
- const unsigned char *inBuffer,
- size_t inSize,
- unsigned char *outBuffer,
- size_t outSize,
- size_t *outSizeProcessed,
- void * (*allocFunc)(size_t size),
- void (*freeFunc)(void *));
-
-#endif
diff --git a/CPP/7zip/Compress/LZMA_Alone/makefile b/CPP/7zip/Compress/LZMA_Alone/makefile
index 16e76376..69196871 100755
--- a/CPP/7zip/Compress/LZMA_Alone/makefile
+++ b/CPP/7zip/Compress/LZMA_Alone/makefile
@@ -1,49 +1,13 @@
PROG = lzma.exe
+LIBS = $(LIBS) user32.lib
CFLAGS = $(CFLAGS) \
-DCOMPRESS_MF_MT \
-DBENCH_MT \
-LIBS = $(LIBS) oleaut32.lib user32.lib
-
-!IFDEF CPU
-LIBS = $(LIBS) bufferoverflowU.lib
-CFLAGS = $(CFLAGS) -GS- -Zc:forScope -W4 -Wp64 -DUNICODE -D_UNICODE
-!ENDIF
-
-!IFNDEF O
-!IFDEF CPU
-O=$(CPU)
-!ELSE
-O=O
-!ENDIF
-!ENDIF
-
-!IFDEF MY_STATIC_LINK
-!IFNDEF MY_SINGLE_THREAD
-CFLAGS = $(CFLAGS) -MT
-!ENDIF
-!ELSE
-CFLAGS = $(CFLAGS) -MD
-!ENDIF
-
-CFLAGS = $(CFLAGS) -nologo -EHsc -c -Fo$O/
-CFLAGS_O1 = $(CFLAGS) -O1
-CFLAGS_O2 = $(CFLAGS) -O2
-
-LFLAGS = $(LFLAGS) -nologo -OPT:NOWIN98
-
-PROGPATH = $O\$(PROG)
-
-COMPL_O1 = $(CPP) $(CFLAGS_O1) $**
-COMPL_O2 = $(CPP) $(CFLAGS_O2) $**
-COMPL = $(CPP) $(CFLAGS_O1) $**
-
-
LZMA_OBJS = \
$O\LzmaAlone.obj \
$O\LzmaBench.obj \
$O\LzmaBenchCon.obj \
- $O\LzmaRam.obj \
LZMA_OPT_OBJS = \
$O\LZMADecoder.obj \
@@ -66,44 +30,33 @@ WIN_OBJS = \
$O\OutBuffer.obj \
$O\StreamUtils.obj \
-LZ_OBJS = \
- $O\LZOutWindow.obj \
-
C_OBJS = \
- $O\Alloc.obj \
$O\7zCrc.obj \
+ $O\Alloc.obj \
+ $O\Bra86.obj \
+ $O\LzFind.obj \
+ $O\LzFindMt.obj \
+ $O\LzmaDec.obj \
+ $O\LzmaEnc.obj \
$O\Threads.obj \
-C_LZ_OBJS = \
- $O\MatchFinder.obj \
- $O\MatchFinderMt.obj \
+C_LZMAUTIL_OBJS = \
+ $O\Lzma86Dec.obj \
+ $O\Lzma86Enc.obj \
OBJS = \
+ $O\StdAfx.obj \
$(LZMA_OBJS) \
$(LZMA_OPT_OBJS) \
$(COMMON_OBJS) \
$(WIN_OBJS) \
$(7ZIP_COMMON_OBJS) \
- $(LZ_OBJS) \
$(C_OBJS) \
- $(C_LZ_OBJS) \
- $O\LzmaRamDecode.obj \
- $O\LzmaDecode.obj \
+ $(C_LZMAUTIL_OBJS) \
$O\FileStreams.obj \
$O\FileIO.obj \
- $O\RangeCoderBit.obj \
- $O\BranchX86.obj \
-
-all: $(PROGPATH)
-
-clean:
- -del /Q $(PROGPATH) $O\*.exe $O\*.dll $O\*.obj $O\*.lib $O\*.exp $O\*.res $O\*.pch
-
-$O:
- if not exist "$O" mkdir "$O"
-$(PROGPATH): $O $(OBJS)
- link $(LFLAGS) -out:$(PROGPATH) $(OBJS) $(LIBS)
+!include "../../../Build.mak"
$(LZMA_OBJS): $(*B).cpp
@@ -116,21 +69,11 @@ $(WIN_OBJS): ../../../Windows/$(*B).cpp
$(COMPL)
$(7ZIP_COMMON_OBJS): ../../Common/$(*B).cpp
$(COMPL)
-$(LZ_OBJS): ../LZ/$(*B).cpp
- $(COMPL)
-$O\RangeCoderBit.obj: ../RangeCoder/$(*B).cpp
- $(COMPL)
-$O\LzmaRamDecode.obj: LzmaRamDecode.c
- $(COMPL_O1)
-$O\LzmaDecode.obj: ../../../../C/Compress/Lzma/LzmaDecode.c
- $(COMPL_O2)
-$O\BranchX86.obj: ../../../../C/Compress/Branch/BranchX86.c
- $(COMPL_O2)
$O\FileStreams.obj: ../../Common/FileStreams.cpp
$(COMPL)
$O\FileIO.obj: ../../../Windows/FileIO.cpp
$(COMPL)
$(C_OBJS): ../../../../C/$(*B).c
$(COMPL_O2)
-$(C_LZ_OBJS): ../../../../C/Compress/Lz/$(*B).c
+$(C_LZMAUTIL_OBJS): ../../../../C/LzmaUtil/$(*B).c
$(COMPL_O2)
diff --git a/CPP/7zip/Compress/LZMA_Alone/makefile.gcc b/CPP/7zip/Compress/LZMA_Alone/makefile.gcc
index 4fed05e6..b5a5f1d1 100755
--- a/CPP/7zip/Compress/LZMA_Alone/makefile.gcc
+++ b/CPP/7zip/Compress/LZMA_Alone/makefile.gcc
@@ -22,11 +22,8 @@ OBJS = \
LzmaAlone.o \
LzmaBench.o \
LzmaBenchCon.o \
- LzmaRam.o \
LZMADecoder.o \
LZMAEncoder.o \
- LZOutWindow.o \
- RangeCoderBit.o \
InBuffer.o \
OutBuffer.o \
FileStreams.o \
@@ -41,10 +38,12 @@ OBJS = \
MyVector.o \
7zCrc.o \
Alloc.o \
- BranchX86.o \
- MatchFinder.o \
- LzmaDecode.o \
- LzmaRamDecode.o \
+ Bra86.o \
+ LzFind.o \
+ LzmaDec.o \
+ LzmaEnc.o \
+ Lzma86Dec.o \
+ Lzma86Enc.o \
all: $(PROG)
@@ -61,21 +60,12 @@ LzmaBench.o: LzmaBench.cpp
LzmaBenchCon.o: LzmaBenchCon.cpp
$(CXX) $(CFLAGS) LzmaBenchCon.cpp
-LzmaRam.o: LzmaRam.cpp
- $(CXX) $(CFLAGS) LzmaRam.cpp
-
LZMADecoder.o: ../LZMA/LZMADecoder.cpp
$(CXX) $(CFLAGS) ../LZMA/LZMADecoder.cpp
LZMAEncoder.o: ../LZMA/LZMAEncoder.cpp
$(CXX) $(CFLAGS) ../LZMA/LZMAEncoder.cpp
-LZOutWindow.o: ../LZ/LZOutWindow.cpp
- $(CXX) $(CFLAGS) ../LZ/LZOutWindow.cpp
-
-RangeCoderBit.o: ../RangeCoder/RangeCoderBit.cpp
- $(CXX) $(CFLAGS) ../RangeCoder/RangeCoderBit.cpp
-
InBuffer.o: ../../Common/InBuffer.cpp
$(CXX) $(CFLAGS) ../../Common/InBuffer.cpp
@@ -122,17 +112,23 @@ MyVector.o: ../../../Common/MyVector.cpp
Alloc.o: ../../../../C/Alloc.c
$(CXX_C) $(CFLAGS) ../../../../C/Alloc.c
-BranchX86.o: ../../../../C/Compress/Branch/BranchX86.c
- $(CXX_C) $(CFLAGS) ../../../../C/Compress/Branch/BranchX86.c
+Bra86.o: ../../../../C/Bra86.c
+ $(CXX_C) $(CFLAGS) ../../../../C/Bra86.c
+
+LzFind.o: ../../../../C/LzFind.c
+ $(CXX_C) $(CFLAGS) ../../../../C/LzFind.c
+
+LzmaDec.o: ../../../../C/LzmaDec.c
+ $(CXX_C) $(CFLAGS) ../../../../C/LzmaDec.c
-MatchFinder.o: ../../../../C/Compress/Lz/MatchFinder.c
- $(CXX_C) $(CFLAGS) ../../../../C/Compress/Lz/MatchFinder.c
+LzmaEnc.o: ../../../../C/LzmaEnc.c
+ $(CXX_C) $(CFLAGS) ../../../../C/LzmaEnc.c
-LzmaDecode.o: ../../../../C/Compress/Lzma/LzmaDecode.c
- $(CXX_C) $(CFLAGS) ../../../../C/Compress/Lzma/LzmaDecode.c
+Lzma86Dec.o: ../../../../C/LzmaUtil/Lzma86Dec.c
+ $(CXX_C) $(CFLAGS) ../../../../C/LzmaUtil/Lzma86Dec.c
-LzmaRamDecode.o: LzmaRamDecode.c
- $(CXX_C) $(CFLAGS) LzmaRamDecode.c
+Lzma86Enc.o: ../../../../C/LzmaUtil/Lzma86Enc.c
+ $(CXX_C) $(CFLAGS) ../../../../C/LzmaUtil/Lzma86Enc.c
clean:
-$(RM) $(PROG) $(OBJS)
diff --git a/CPP/7zip/Compress/Lzx/LzxDecoder.cpp b/CPP/7zip/Compress/Lzx/LzxDecoder.cpp
index 5ed05b53..94ce6fc9 100755
--- a/CPP/7zip/Compress/Lzx/LzxDecoder.cpp
+++ b/CPP/7zip/Compress/Lzx/LzxDecoder.cpp
@@ -38,7 +38,7 @@ STDMETHODIMP CDecoder::Flush()
return m_x86ConvertOutStreamSpec->Flush();
}
-UInt32 CDecoder::ReadBits(UInt32 numBits) { return m_InBitStream.ReadBits(numBits); }
+UInt32 CDecoder::ReadBits(int numBits) { return m_InBitStream.ReadBits(numBits); }
#define RIF(x) { if (!(x)) return false; }
@@ -63,12 +63,12 @@ bool CDecoder::ReadTable(Byte *lastLevels, Byte *newLevels, UInt32 numSymbols)
UInt32 number = m_LevelDecoder.DecodeSymbol(&m_InBitStream);
if (number == kLevelSymbolZeros)
{
- num = kLevelSymbolZerosStartValue + ReadBits(kLevelSymbolZerosNumBits);
+ num = kLevelSymbolZerosStartValue + (int)ReadBits(kLevelSymbolZerosNumBits);
symbol = 0;
}
else if (number == kLevelSymbolZerosBig)
{
- num = kLevelSymbolZerosBigStartValue + ReadBits(kLevelSymbolZerosBigNumBits);
+ num = kLevelSymbolZerosBigStartValue + (int)ReadBits(kLevelSymbolZerosBigNumBits);
symbol = 0;
}
else if (number == kLevelSymbolSame || number <= kNumHuffmanBits)
@@ -77,7 +77,7 @@ bool CDecoder::ReadTable(Byte *lastLevels, Byte *newLevels, UInt32 numSymbols)
num = 1;
else
{
- num = kLevelSymbolSameStartValue + ReadBits(kLevelSymbolSameNumBits);
+ num = kLevelSymbolSameStartValue + (int)ReadBits(kLevelSymbolSameNumBits);
number = m_LevelDecoder.DecodeSymbol(&m_InBitStream);
if (number > kNumHuffmanBits)
return false;
@@ -262,7 +262,7 @@ HRESULT CDecoder::CodeSpec(UInt32 curSize)
int numDirectBits;
if (posSlot < kNumPowerPosSlots)
{
- numDirectBits = (posSlot >> 1) - 1;
+ numDirectBits = (int)(posSlot >> 1) - 1;
distance = ((2 | (posSlot & 1)) << numDirectBits);
}
else
@@ -297,7 +297,7 @@ HRESULT CDecoder::CodeSpec(UInt32 curSize)
next -= locLen;
if (len != 0)
{
- _remainLen = len;
+ _remainLen = (int)len;
return S_OK;
}
}
diff --git a/CPP/7zip/Compress/Lzx/LzxDecoder.h b/CPP/7zip/Compress/Lzx/LzxDecoder.h
index 777067e0..4a577d38 100755
--- a/CPP/7zip/Compress/Lzx/LzxDecoder.h
+++ b/CPP/7zip/Compress/Lzx/LzxDecoder.h
@@ -63,7 +63,7 @@ public:
void MovePos(UInt32 numBits)
{
- m_BitPos += numBits;
+ m_BitPos += (int)numBits;
Normalize();
}
@@ -76,8 +76,8 @@ public:
UInt32 ReadBitsBig(int numBits)
{
- UInt32 numBits0 = numBits / 2;
- UInt32 numBits1 = numBits - numBits0;
+ int numBits0 = numBits / 2;
+ int numBits1 = numBits - numBits0;
UInt32 res = ReadBits(numBits0) << numBits1;
return res + ReadBits(numBits1);
}
@@ -128,7 +128,7 @@ class CDecoder :
bool _wimMode;
- UInt32 ReadBits(UInt32 numBits);
+ UInt32 ReadBits(int numBits);
bool ReadTable(Byte *lastLevels, Byte *newLevels, UInt32 numSymbols);
bool ReadTables();
void ClearPrevLevels();
diff --git a/CPP/7zip/Compress/PPMD/PPMD.dsp b/CPP/7zip/Compress/PPMD/PPMD.dsp
deleted file mode 100755
index c98d809d..00000000
--- a/CPP/7zip/Compress/PPMD/PPMD.dsp
+++ /dev/null
@@ -1,242 +0,0 @@
-# Microsoft Developer Studio Project File - Name="PPMD" - Package Owner=<4>
-# Microsoft Developer Studio Generated Build File, Format Version 6.00
-# ** DO NOT EDIT **
-
-# TARGTYPE "Win32 (x86) Dynamic-Link Library" 0x0102
-
-CFG=PPMD - Win32 Debug
-!MESSAGE This is not a valid makefile. To build this project using NMAKE,
-!MESSAGE use the Export Makefile command and run
-!MESSAGE
-!MESSAGE NMAKE /f "PPMD.mak".
-!MESSAGE
-!MESSAGE You can specify a configuration when running NMAKE
-!MESSAGE by defining the macro CFG on the command line. For example:
-!MESSAGE
-!MESSAGE NMAKE /f "PPMD.mak" CFG="PPMD - Win32 Debug"
-!MESSAGE
-!MESSAGE Possible choices for configuration are:
-!MESSAGE
-!MESSAGE "PPMD - Win32 Release" (based on "Win32 (x86) Dynamic-Link Library")
-!MESSAGE "PPMD - Win32 Debug" (based on "Win32 (x86) Dynamic-Link Library")
-!MESSAGE
-
-# Begin Project
-# PROP AllowPerConfigDependencies 0
-# PROP Scc_ProjName ""
-# PROP Scc_LocalPath ""
-CPP=cl.exe
-MTL=midl.exe
-RSC=rc.exe
-
-!IF "$(CFG)" == "PPMD - Win32 Release"
-
-# PROP BASE Use_MFC 0
-# PROP BASE Use_Debug_Libraries 0
-# PROP BASE Output_Dir "Release"
-# PROP BASE Intermediate_Dir "Release"
-# PROP BASE Target_Dir ""
-# PROP Use_MFC 0
-# PROP Use_Debug_Libraries 0
-# PROP Output_Dir "Release"
-# PROP Intermediate_Dir "Release"
-# PROP Ignore_Export_Lib 1
-# PROP Target_Dir ""
-# ADD BASE CPP /nologo /MT /W3 /GX /O2 /D "WIN32" /D "NDEBUG" /D "_WINDOWS" /D "_MBCS" /D "_USRDLL" /D "PPMD_EXPORTS" /YX /FD /c
-# ADD CPP /nologo /Gz /MD /W3 /GX /O1 /I "..\..\..\\" /D "WIN32" /D "NDEBUG" /D "_WINDOWS" /D "_MBCS" /D "_USRDLL" /D "PPMD_EXPORTS" /Yu"StdAfx.h" /FD /c
-# ADD BASE MTL /nologo /D "NDEBUG" /mktyplib203 /win32
-# ADD MTL /nologo /D "NDEBUG" /mktyplib203 /win32
-# ADD BASE RSC /l 0x419 /d "NDEBUG"
-# ADD RSC /l 0x419 /d "NDEBUG"
-BSC32=bscmake.exe
-# ADD BASE BSC32 /nologo
-# ADD BSC32 /nologo
-LINK32=link.exe
-# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /dll /machine:I386
-# ADD LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /dll /machine:I386 /out:"C:\Program Files\7-Zip\Codecs\PPMd.dll" /opt:NOWIN98
-# SUBTRACT LINK32 /pdb:none
-
-!ELSEIF "$(CFG)" == "PPMD - Win32 Debug"
-
-# PROP BASE Use_MFC 0
-# PROP BASE Use_Debug_Libraries 1
-# PROP BASE Output_Dir "Debug"
-# PROP BASE Intermediate_Dir "Debug"
-# PROP BASE Target_Dir ""
-# PROP Use_MFC 0
-# PROP Use_Debug_Libraries 1
-# PROP Output_Dir "Debug"
-# PROP Intermediate_Dir "Debug"
-# PROP Ignore_Export_Lib 1
-# PROP Target_Dir ""
-# ADD BASE CPP /nologo /MTd /W3 /Gm /GX /ZI /Od /D "WIN32" /D "_DEBUG" /D "_WINDOWS" /D "_MBCS" /D "_USRDLL" /D "PPMD_EXPORTS" /YX /FD /GZ /c
-# ADD CPP /nologo /Gz /MTd /W3 /Gm /GX /ZI /Od /I "..\..\..\\" /D "WIN32" /D "_DEBUG" /D "_WINDOWS" /D "_MBCS" /D "_USRDLL" /D "PPMD_EXPORTS" /Yu"StdAfx.h" /FD /GZ /c
-# ADD BASE MTL /nologo /D "_DEBUG" /mktyplib203 /win32
-# ADD MTL /nologo /D "_DEBUG" /mktyplib203 /win32
-# ADD BASE RSC /l 0x419 /d "_DEBUG"
-# ADD RSC /l 0x419 /d "_DEBUG"
-BSC32=bscmake.exe
-# ADD BASE BSC32 /nologo
-# ADD BSC32 /nologo
-LINK32=link.exe
-# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /dll /debug /machine:I386 /pdbtype:sept
-# ADD LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /dll /debug /machine:I386 /out:"C:\Program Files\7-Zip\Codecs\PPMd.dll" /pdbtype:sept
-
-!ENDIF
-
-# Begin Target
-
-# Name "PPMD - Win32 Release"
-# Name "PPMD - Win32 Debug"
-# Begin Group "Spec"
-
-# PROP Default_Filter ""
-# Begin Source File
-
-SOURCE=..\Codec.def
-# End Source File
-# Begin Source File
-
-SOURCE=..\CodecExports.cpp
-# End Source File
-# Begin Source File
-
-SOURCE=..\DllExports.cpp
-# End Source File
-# Begin Source File
-
-SOURCE=.\resource.rc
-# End Source File
-# Begin Source File
-
-SOURCE=.\StdAfx.cpp
-# ADD CPP /Yc
-# End Source File
-# Begin Source File
-
-SOURCE=.\StdAfx.h
-# End Source File
-# End Group
-# Begin Group "PPMD"
-
-# PROP Default_Filter ""
-# Begin Source File
-
-SOURCE=.\PPMDContext.h
-# End Source File
-# Begin Source File
-
-SOURCE=.\PPMDDecode.h
-# End Source File
-# Begin Source File
-
-SOURCE=.\PPMDDecoder.cpp
-
-!IF "$(CFG)" == "PPMD - Win32 Release"
-
-# ADD CPP /O2
-# SUBTRACT CPP /YX /Yc /Yu
-
-!ELSEIF "$(CFG)" == "PPMD - Win32 Debug"
-
-!ENDIF
-
-# End Source File
-# Begin Source File
-
-SOURCE=.\PPMDDecoder.h
-# End Source File
-# Begin Source File
-
-SOURCE=.\PPMDEncode.h
-# End Source File
-# Begin Source File
-
-SOURCE=.\PPMDEncoder.cpp
-
-!IF "$(CFG)" == "PPMD - Win32 Release"
-
-# ADD CPP /O2
-# SUBTRACT CPP /YX /Yc /Yu
-
-!ELSEIF "$(CFG)" == "PPMD - Win32 Debug"
-
-!ENDIF
-
-# End Source File
-# Begin Source File
-
-SOURCE=.\PPMDEncoder.h
-# End Source File
-# Begin Source File
-
-SOURCE=.\PPMDRegister.cpp
-# End Source File
-# Begin Source File
-
-SOURCE=.\PPMDSubAlloc.h
-# End Source File
-# Begin Source File
-
-SOURCE=.\PPMDType.h
-# End Source File
-# End Group
-# Begin Group "7zip common"
-
-# PROP Default_Filter ""
-# Begin Source File
-
-SOURCE=..\..\Common\InBuffer.cpp
-# End Source File
-# Begin Source File
-
-SOURCE=..\..\Common\InBuffer.h
-# End Source File
-# Begin Source File
-
-SOURCE=..\..\Common\OutBuffer.cpp
-# End Source File
-# Begin Source File
-
-SOURCE=..\..\Common\OutBuffer.h
-# End Source File
-# Begin Source File
-
-SOURCE=..\..\Common\StreamUtils.cpp
-# End Source File
-# Begin Source File
-
-SOURCE=..\..\Common\StreamUtils.h
-# End Source File
-# End Group
-# Begin Group "RangeCoder"
-
-# PROP Default_Filter ""
-# Begin Source File
-
-SOURCE=..\RangeCoder\RangeCoder.h
-# End Source File
-# End Group
-# Begin Group "Common"
-
-# PROP Default_Filter ""
-# Begin Source File
-
-SOURCE=..\..\..\Common\Types.h
-# End Source File
-# End Group
-# Begin Group "Ń"
-
-# PROP Default_Filter ""
-# Begin Source File
-
-SOURCE=..\..\..\..\C\Alloc.c
-# SUBTRACT CPP /YX /Yc /Yu
-# End Source File
-# Begin Source File
-
-SOURCE=..\..\..\..\C\Alloc.h
-# End Source File
-# End Group
-# End Target
-# End Project
diff --git a/CPP/7zip/Compress/PPMD/PPMD.dsw b/CPP/7zip/Compress/PPMD/PPMD.dsw
deleted file mode 100755
index 8032f3db..00000000
--- a/CPP/7zip/Compress/PPMD/PPMD.dsw
+++ /dev/null
@@ -1,29 +0,0 @@
-Microsoft Developer Studio Workspace File, Format Version 6.00
-# WARNING: DO NOT EDIT OR DELETE THIS WORKSPACE FILE!
-
-###############################################################################
-
-Project: "PPMD"=.\PPMD.dsp - Package Owner=<4>
-
-Package=<5>
-{{{
-}}}
-
-Package=<4>
-{{{
-}}}
-
-###############################################################################
-
-Global:
-
-Package=<5>
-{{{
-}}}
-
-Package=<3>
-{{{
-}}}
-
-###############################################################################
-
diff --git a/CPP/7zip/Compress/PPMD/PPMDEncoder.cpp b/CPP/7zip/Compress/PPMD/PPMDEncoder.cpp
index fe99ea5a..cefd2478 100755
--- a/CPP/7zip/Compress/PPMD/PPMDEncoder.cpp
+++ b/CPP/7zip/Compress/PPMD/PPMDEncoder.cpp
@@ -81,7 +81,7 @@ STDMETHODIMP CEncoder::WriteCoderProperties(ISequentialOutStream *outStream)
properties[0] = _order;
for (int i = 0; i < 4; i++)
properties[1 + i] = Byte(_usedMemorySize >> (8 * i));
- return WriteStream(outStream, properties, kPropSize, NULL);
+ return WriteStream(outStream, properties, kPropSize);
}
const UInt32 kUsedMemorySizeDefault = (1 << 24);
diff --git a/CPP/7zip/Compress/PPMD/makefile b/CPP/7zip/Compress/PPMD/makefile
deleted file mode 100755
index f146edb0..00000000
--- a/CPP/7zip/Compress/PPMD/makefile
+++ /dev/null
@@ -1,43 +0,0 @@
-PROG = PPMd.dll
-DEF_FILE = ../Codec.def
-CFLAGS = $(CFLAGS) -I ../../../ -D_7ZIP_LARGE_PAGES
-LIBS = $(LIBS) oleaut32.lib
-
-COMPRESS_OBJS = \
- $O\CodecExports.obj \
- $O\DllExports.obj \
-
-PPMD_OPT_OBJS = \
- $O\PPMDDecoder.obj \
- $O\PPMDEncoder.obj \
- $O\PPMDRegister.obj \
-
-7ZIP_COMMON_OBJS = \
- $O\InBuffer.obj \
- $O\OutBuffer.obj \
- $O\StreamUtils.obj \
-
-C_OBJS = \
- $O\Alloc.obj \
-
-OBJS = \
- $O\StdAfx.obj \
- $(COMPRESS_OBJS) \
- $(PPMD_OPT_OBJS) \
- $(7ZIP_COMMON_OBJS) \
- $(C_OBJS) \
- $O\resource.res
-
-
-!include "../../../Build.mak"
-
-$(COMPRESS_OBJS): ../$(*B).cpp
- $(COMPL)
-$(PPMD_OPT_OBJS): $(*B).cpp
- $(COMPL_O2)
-$(7ZIP_COMMON_OBJS): ../../Common/$(*B).cpp
- $(COMPL)
-$(C_OBJS): ../../../../C/$(*B).c
- $(COMPL_O2)
-
-
diff --git a/CPP/7zip/Compress/PPMD/resource.rc b/CPP/7zip/Compress/PPMD/resource.rc
deleted file mode 100755
index fed98e19..00000000
--- a/CPP/7zip/Compress/PPMD/resource.rc
+++ /dev/null
@@ -1,3 +0,0 @@
-#include "../../MyVersionInfo.rc"
-
-MY_VERSION_INFO_DLL("PPMd Codec", "PPMd")
diff --git a/CPP/7zip/Compress/RangeCoder/RangeCoder.h b/CPP/7zip/Compress/RangeCoder/RangeCoder.h
index bbb2ba82..0a6b4064 100755
--- a/CPP/7zip/Compress/RangeCoder/RangeCoder.h
+++ b/CPP/7zip/Compress/RangeCoder/RangeCoder.h
@@ -71,13 +71,12 @@ public:
Low = (UInt32)Low << 8;
}
- void EncodeDirectBits(UInt32 value, int numTotalBits)
+ void EncodeDirectBits(UInt32 value, int numBits)
{
- for (int i = numTotalBits - 1; i >= 0; i--)
+ for (numBits--; numBits >= 0; numBits--)
{
Range >>= 1;
- if (((value >> i) & 1) == 1)
- Low += Range;
+ Low += Range & (0 - ((value >> numBits) & 1));
if (Range < kTopValue)
{
Range <<= 8;
diff --git a/CPP/7zip/Compress/RangeCoder/RangeCoderBit.cpp b/CPP/7zip/Compress/RangeCoder/RangeCoderBit.cpp
index 8e4c4d3a..9a7c0a05 100755
--- a/CPP/7zip/Compress/RangeCoder/RangeCoderBit.cpp
+++ b/CPP/7zip/Compress/RangeCoder/RangeCoderBit.cpp
@@ -7,74 +7,30 @@
namespace NCompress {
namespace NRangeCoder {
-UInt32 CPriceTables::ProbPrices[kBitModelTotal >> kNumMoveReducingBits];
-static CPriceTables g_PriceTables;
-
-CPriceTables::CPriceTables() { Init(); }
+UInt32 ProbPrices[kBitModelTotal >> kNumMoveReducingBits];
-void CPriceTables::Init()
+struct CPriceTables { CPriceTables()
{
- const int kNumBits = (kNumBitModelTotalBits - kNumMoveReducingBits);
- for(int i = kNumBits - 1; i >= 0; i--)
- {
- UInt32 start = 1 << (kNumBits - i - 1);
- UInt32 end = 1 << (kNumBits - i);
- for (UInt32 j = start; j < end; j++)
- ProbPrices[j] = (i << kNumBitPriceShiftBits) +
- (((end - j) << kNumBitPriceShiftBits) >> (kNumBits - i - 1));
- }
-
- /*
- // simplest: bad solution
- for(UInt32 i = 1; i < (kBitModelTotal >> kNumMoveReducingBits) - 1; i++)
- ProbPrices[i] = kBitPrice;
- */
-
- /*
- const double kDummyMultMid = (1.0 / kBitPrice) / 2;
- const double kDummyMultMid = 0;
- // float solution
- double ln2 = log(double(2));
- double lnAll = log(double(kBitModelTotal >> kNumMoveReducingBits));
- for(UInt32 i = 1; i < (kBitModelTotal >> kNumMoveReducingBits) - 1; i++)
- ProbPrices[i] = UInt32((fabs(lnAll - log(double(i))) / ln2 + kDummyMultMid) * kBitPrice);
- */
-
- /*
- // experimental, slow, solution:
- for(UInt32 i = 1; i < (kBitModelTotal >> kNumMoveReducingBits) - 1; i++)
+ for (UInt32 i = (1 << kNumMoveReducingBits) / 2; i < kBitModelTotal; i += (1 << kNumMoveReducingBits))
{
- const int kCyclesBits = 5;
- const UInt32 kCycles = (1 << kCyclesBits);
-
- UInt32 range = UInt32(-1);
+ const int kCyclesBits = kNumBitPriceShiftBits;
+ UInt32 w = i;
UInt32 bitCount = 0;
- for (UInt32 j = 0; j < kCycles; j++)
+ for (int j = 0; j < kCyclesBits; j++)
{
- range >>= (kNumBitModelTotalBits - kNumMoveReducingBits);
- range *= i;
- while(range < (1 << 31))
+ w = w * w;
+ bitCount <<= 1;
+ while (w >= ((UInt32)1 << 16))
{
- range <<= 1;
+ w >>= 1;
bitCount++;
}
}
- bitCount <<= kNumBitPriceShiftBits;
- range -= (1 << 31);
- for (int k = kNumBitPriceShiftBits - 1; k >= 0; k--)
- {
- range <<= 1;
- if (range > (1 << 31))
- {
- bitCount += (1 << k);
- range -= (1 << 31);
- }
- }
- ProbPrices[i] = (bitCount
- // + (1 << (kCyclesBits - 1))
- ) >> kCyclesBits;
+ ProbPrices[i >> kNumMoveReducingBits] = ((kNumBitModelTotalBits << kCyclesBits) - 15 - bitCount);
}
- */
}
+};
+
+static CPriceTables g_PriceTables;
}}
diff --git a/CPP/7zip/Compress/RangeCoder/RangeCoderBit.h b/CPP/7zip/Compress/RangeCoder/RangeCoderBit.h
index 624f887c..0ac50dfe 100755
--- a/CPP/7zip/Compress/RangeCoder/RangeCoderBit.h
+++ b/CPP/7zip/Compress/RangeCoder/RangeCoderBit.h
@@ -11,18 +11,12 @@ namespace NRangeCoder {
const int kNumBitModelTotalBits = 11;
const UInt32 kBitModelTotal = (1 << kNumBitModelTotalBits);
-const int kNumMoveReducingBits = 2;
+const int kNumMoveReducingBits = 4;
-const int kNumBitPriceShiftBits = 6;
+const int kNumBitPriceShiftBits = 4;
const UInt32 kBitPrice = 1 << kNumBitPriceShiftBits;
-class CPriceTables
-{
-public:
- static UInt32 ProbPrices[kBitModelTotal >> kNumMoveReducingBits];
- static void Init();
- CPriceTables();
-};
+extern UInt32 ProbPrices[kBitModelTotal >> kNumMoveReducingBits];
template <int numMoveBits>
class CBitModel
@@ -74,11 +68,10 @@ public:
}
UInt32 GetPrice(UInt32 symbol) const
{
- return CPriceTables::ProbPrices[
- (((this->Prob - symbol) ^ ((-(int)symbol))) & (kBitModelTotal - 1)) >> kNumMoveReducingBits];
+ return ProbPrices[(this->Prob ^ ((-(int)symbol)) & (kBitModelTotal - 1)) >> kNumMoveReducingBits];
}
- UInt32 GetPrice0() const { return CPriceTables::ProbPrices[this->Prob >> kNumMoveReducingBits]; }
- UInt32 GetPrice1() const { return CPriceTables::ProbPrices[(kBitModelTotal - this->Prob) >> kNumMoveReducingBits]; }
+ UInt32 GetPrice0() const { return ProbPrices[this->Prob >> kNumMoveReducingBits]; }
+ UInt32 GetPrice1() const { return ProbPrices[(this->Prob ^ (kBitModelTotal - 1)) >> kNumMoveReducingBits]; }
};
diff --git a/CPP/7zip/Compress/RangeCoder/RangeCoderBitTree.h b/CPP/7zip/Compress/RangeCoder/RangeCoderBitTree.h
index 4f0c78b4..97dd9b38 100755
--- a/CPP/7zip/Compress/RangeCoder/RangeCoderBitTree.h
+++ b/CPP/7zip/Compress/RangeCoder/RangeCoderBitTree.h
@@ -16,7 +16,7 @@ class CBitTreeEncoder
public:
void Init()
{
- for(UInt32 i = 1; i < (1 << NumBitLevels); i++)
+ for(UInt32 i = 0; i < (1 << NumBitLevels); i++)
Models[i].Init();
}
void Encode(CEncoder *rangeEncoder, UInt32 symbol)
@@ -74,7 +74,7 @@ class CBitTreeDecoder
public:
void Init()
{
- for(UInt32 i = 1; i < (1 << NumBitLevels); i++)
+ for(UInt32 i = 0; i < (1 << NumBitLevels); i++)
Models[i].Init();
}
UInt32 Decode(CDecoder *rangeDecoder)
diff --git a/CPP/7zip/Compress/Rar/Rar29.dsp b/CPP/7zip/Compress/Rar/Rar29.dsp
index c5ee2228..9eb36ac3 100755
--- a/CPP/7zip/Compress/Rar/Rar29.dsp
+++ b/CPP/7zip/Compress/Rar/Rar29.dsp
@@ -182,19 +182,19 @@ SOURCE=..\..\..\Common\CRC.cpp
# End Source File
# Begin Source File
-SOURCE=..\..\..\Common\NewHandler.cpp
+SOURCE=..\..\..\Common\MyVector.cpp
# End Source File
# Begin Source File
-SOURCE=..\..\..\Common\NewHandler.h
+SOURCE=..\..\..\Common\MyVector.h
# End Source File
# Begin Source File
-SOURCE=..\..\..\Common\Vector.cpp
+SOURCE=..\..\..\Common\NewHandler.cpp
# End Source File
# Begin Source File
-SOURCE=..\..\..\Common\Vector.h
+SOURCE=..\..\..\Common\NewHandler.h
# End Source File
# End Group
# Begin Group "Rar3"
diff --git a/CPP/7zip/Compress/Rar/Rar2Decoder.cpp b/CPP/7zip/Compress/Rar/Rar2Decoder.cpp
index 057a1a60..28d50213 100755
--- a/CPP/7zip/Compress/Rar/Rar2Decoder.cpp
+++ b/CPP/7zip/Compress/Rar/Rar2Decoder.cpp
@@ -69,16 +69,6 @@ Byte CFilter::Decode(int &channelDelta, Byte deltaByte)
}
}
-class CException
-{
-public:
- enum ECauseType
- {
- kData
- } Cause;
- CException(ECauseType cause): Cause(cause) {}
-};
-
static const char *kNumberErrorMessage = "Number error";
static const UInt32 kHistorySize = 1 << 20;
@@ -307,7 +297,7 @@ bool CDecoder::DecodeLz(Int32 pos)
return true;
}
-STDMETHODIMP CDecoder::CodeReal(ISequentialInStream *inStream,
+HRESULT CDecoder::CodeReal(ISequentialInStream *inStream,
ISequentialOutStream *outStream, const UInt64 *inSize, const UInt64 *outSize,
ICompressProgressInfo *progress)
{
@@ -373,7 +363,7 @@ STDMETHODIMP CDecoder::CodeReal(ISequentialInStream *inStream,
}
}
if (pos > unPackSize)
- throw CException(CException::kData);
+ return S_FALSE;
if (!ReadLastTables())
return S_FALSE;
diff --git a/CPP/7zip/Compress/Rar/Rar2Decoder.h b/CPP/7zip/Compress/Rar/Rar2Decoder.h
index 9567de0a..7906b1fc 100755
--- a/CPP/7zip/Compress/Rar/Rar2Decoder.h
+++ b/CPP/7zip/Compress/Rar/Rar2Decoder.h
@@ -147,6 +147,10 @@ class CDecoder :
bool DecodeMm(UInt32 pos);
bool DecodeLz(Int32 pos);
+ HRESULT CodeReal(ISequentialInStream *inStream,
+ ISequentialOutStream *outStream, const UInt64 *inSize, const UInt64 *outSize,
+ ICompressProgressInfo *progress);
+
public:
CDecoder();
@@ -158,10 +162,6 @@ public:
m_InBitStream.ReleaseStream();
}
- STDMETHOD(CodeReal)(ISequentialInStream *inStream,
- ISequentialOutStream *outStream, const UInt64 *inSize, const UInt64 *outSize,
- ICompressProgressInfo *progress);
-
STDMETHOD(Code)(ISequentialInStream *inStream,
ISequentialOutStream *outStream, const UInt64 *inSize, const UInt64 *outSize,
ICompressProgressInfo *progress);
diff --git a/CPP/7zip/Compress/Rar/Rar3Decoder.cpp b/CPP/7zip/Compress/Rar/Rar3Decoder.cpp
index e629f4df..5ba13646 100755
--- a/CPP/7zip/Compress/Rar/Rar3Decoder.cpp
+++ b/CPP/7zip/Compress/Rar/Rar3Decoder.cpp
@@ -58,11 +58,7 @@ CDecoder::~CDecoder()
HRESULT CDecoder::WriteDataToStream(const Byte *data, UInt32 size)
{
- UInt32 processedSize;
- HRESULT res = WriteStream(_outStream, data, size, &processedSize);
- if (res == S_OK && processedSize != size)
- res = E_FAIL;
- return res;
+ return WriteStream(_outStream, data, size);
}
HRESULT CDecoder::WriteData(const Byte *data, UInt32 size)
diff --git a/CPP/7zip/Compress/Rar/Rar3Vm.h b/CPP/7zip/Compress/Rar/Rar3Vm.h
index d31fcd0a..8b2e01f1 100755
--- a/CPP/7zip/Compress/Rar/Rar3Vm.h
+++ b/CPP/7zip/Compress/Rar/Rar3Vm.h
@@ -11,9 +11,6 @@
#include "../../../../C/CpuArch.h"
#define RARVM_STANDARD_FILTERS
-#ifdef LITTLE_ENDIAN_UNALIGN
-#define RARVM_LITTLE_ENDIAN_UNALIGN
-#endif
namespace NCompress {
namespace NRar3 {
@@ -37,27 +34,8 @@ public:
namespace NVm {
-inline UInt32 GetValue32(const void *addr)
-{
- #ifdef RARVM_LITTLE_ENDIAN_UNALIGN
- return *(const UInt32 *)addr;
- #else
- const Byte *b = (const Byte *)addr;
- return UInt32((UInt32)b[0]|((UInt32)b[1]<<8)|((UInt32)b[2]<<16)|((UInt32)b[3]<<24));
- #endif
-}
-
-inline void SetValue32(void *addr, UInt32 value)
-{
- #ifdef RARVM_LITTLE_ENDIAN_UNALIGN
- *(UInt32 *)addr = value;
- #else
- ((Byte *)addr)[0] = (Byte)value;
- ((Byte *)addr)[1] = (Byte)(value >> 8);
- ((Byte *)addr)[2] = (Byte)(value >> 16);
- ((Byte *)addr)[3] = (Byte)(value >> 24);
- #endif
-}
+inline UInt32 GetValue32(const void *addr) { return GetUi32(addr); }
+inline void SetValue32(void *addr, UInt32 value) { SetUi32(addr, value); }
UInt32 ReadEncodedUInt32(CMemBitDecoder &inp);
@@ -147,14 +125,7 @@ class CVm
if (byteMode)
return(*(const Byte *)addr);
else
- {
- #ifdef RARVM_LITTLE_ENDIAN_UNALIGN
- return *(const UInt32 *)addr;
- #else
- const Byte *b = (const Byte *)addr;
- return UInt32((UInt32)b[0]|((UInt32)b[1]<<8)|((UInt32)b[2]<<16)|((UInt32)b[3]<<24));
- #endif
- }
+ return GetUi32(addr);
}
static void SetValue(bool byteMode, void *addr, UInt32 value)
@@ -162,16 +133,7 @@ class CVm
if (byteMode)
*(Byte *)addr = (Byte)value;
else
- {
- #ifdef RARVM_LITTLE_ENDIAN_UNALIGN
- *(UInt32 *)addr = value;
- #else
- ((Byte *)addr)[0] = (Byte)value;
- ((Byte *)addr)[1] = (Byte)(value >> 8);
- ((Byte *)addr)[2] = (Byte)(value >> 16);
- ((Byte *)addr)[3] = (Byte)(value >> 24);
- #endif
- }
+ SetUi32(addr, value);
}
UInt32 GetFixedGlobalValue32(UInt32 globalOffset) { return GetValue(false, &Mem[kGlobalOffset + globalOffset]); }
diff --git a/CPP/7zip/Compress/Rar/makefile b/CPP/7zip/Compress/Rar/makefile
index f55bf17e..27cedbd9 100755
--- a/CPP/7zip/Compress/Rar/makefile
+++ b/CPP/7zip/Compress/Rar/makefile
@@ -16,7 +16,7 @@ RAR29_OPT_OBJS = \
COMMON_OBJS = \
$O\CRC.obj \
- $O\Vector.obj \
+ $O\MyVector.obj \
7ZIP_COMMON_OBJS = \
$O\InBuffer.obj \
diff --git a/CPP/7zip/Crypto/7zAES/7zAES.cpp b/CPP/7zip/Crypto/7zAES/7zAES.cpp
index 97332b44..ce6b7aef 100755
--- a/CPP/7zip/Crypto/7zAES/7zAES.cpp
+++ b/CPP/7zip/Crypto/7zAES/7zAES.cpp
@@ -7,9 +7,13 @@
#include "../../Common/StreamObjects.h"
#include "../../Common/StreamUtils.h"
#include "../AES/MyAES.h"
-#include "../Hash/Sha256.h"
#include "7zAES.h"
+extern "C"
+{
+#include "../../../../C/Sha256.h"
+}
+
#ifndef EXTRACT_ONLY
#include "../Hash/RandGen.h"
#endif
@@ -43,19 +47,20 @@ void CKeyInfo::CalculateDigest()
}
else
{
- NCrypto::NSha256::CContext sha;
+ CSha256 sha;
+ Sha256_Init(&sha);
const UInt64 numRounds = UInt64(1) << (NumCyclesPower);
Byte temp[8] = { 0,0,0,0,0,0,0,0 };
for (UInt64 round = 0; round < numRounds; round++)
{
- sha.Update(Salt, SaltSize);
- sha.Update(Password, Password.GetCapacity());
- sha.Update(temp, 8);
+ Sha256_Update(&sha, Salt, (size_t)SaltSize);
+ Sha256_Update(&sha, Password, Password.GetCapacity());
+ Sha256_Update(&sha, temp, 8);
for (int i = 0; i < 8; i++)
if (++(temp[i]) != 0)
break;
}
- sha.Final(Key);
+ Sha256_Final(&sha, Key);
}
}
@@ -129,7 +134,7 @@ STDMETHODIMP CEncoder::ResetSalt()
STDMETHODIMP CEncoder::ResetInitVector()
{
_ivSize = 8;
- g_RandomGenerator.Generate(_iv, _ivSize);
+ g_RandomGenerator.Generate(_iv, (unsigned)_ivSize);
return S_OK;
}
@@ -142,7 +147,7 @@ STDMETHODIMP CEncoder::WriteCoderProperties(ISequentialOutStream *outStream)
UInt32 ivSize = _ivSize;
// _key.NumCyclesPower = 0x3F;
- _key.NumCyclesPower = 18;
+ _key.NumCyclesPower = 19;
Byte firstByte = (Byte)(_key.NumCyclesPower |
(((_key.SaltSize == 0) ? 0 : 1) << 7) |
@@ -156,11 +161,11 @@ STDMETHODIMP CEncoder::WriteCoderProperties(ISequentialOutStream *outStream)
RINOK(outStream->Write(&secondByte, 1, NULL));
if (_key.SaltSize > 0)
{
- RINOK(WriteStream(outStream, _key.Salt, _key.SaltSize, NULL));
+ RINOK(WriteStream(outStream, _key.Salt, _key.SaltSize));
}
if (ivSize > 0)
{
- RINOK(WriteStream(outStream, _iv, ivSize, NULL));
+ RINOK(WriteStream(outStream, _iv, ivSize));
}
return S_OK;
}
@@ -208,8 +213,8 @@ STDMETHODIMP CDecoder::SetDecoderProperties2(const Byte *data, UInt32 size)
STDMETHODIMP CBaseCoder::CryptoSetPassword(const Byte *data, UInt32 size)
{
- _key.Password.SetCapacity(size);
- memcpy(_key.Password, data, size);
+ _key.Password.SetCapacity((size_t)size);
+ memcpy(_key.Password, data, (size_t)size);
return S_OK;
}
diff --git a/CPP/7zip/Crypto/AES/MyAES.cpp b/CPP/7zip/Crypto/AES/MyAES.cpp
index 926e8969..842a634e 100755
--- a/CPP/7zip/Crypto/AES/MyAES.cpp
+++ b/CPP/7zip/Crypto/AES/MyAES.cpp
@@ -12,14 +12,14 @@ STDMETHODIMP CAesCbcEncoder::Init() { return S_OK; }
STDMETHODIMP_(UInt32) CAesCbcEncoder::Filter(Byte *data, UInt32 size)
{
- return AesCbcEncode(&Aes, data, size);
+ return (UInt32)AesCbc_Encode(&Aes, data, size);
}
STDMETHODIMP CAesCbcEncoder::SetKey(const Byte *data, UInt32 size)
{
if ((size & 0x7) != 0 || size < 16 || size > 32)
return E_INVALIDARG;
- AesSetKeyEncode(&Aes.aes, data, size);
+ Aes_SetKeyEncode(&Aes.aes, data, size);
return S_OK;
}
@@ -27,7 +27,7 @@ STDMETHODIMP CAesCbcEncoder::SetInitVector(const Byte *data, UInt32 size)
{
if (size != AES_BLOCK_SIZE)
return E_INVALIDARG;
- AesCbcInit(&Aes, data);
+ AesCbc_Init(&Aes, data);
return S_OK;
}
@@ -35,14 +35,14 @@ STDMETHODIMP CAesCbcDecoder::Init() { return S_OK; }
STDMETHODIMP_(UInt32) CAesCbcDecoder::Filter(Byte *data, UInt32 size)
{
- return AesCbcDecode(&Aes, data, size);
+ return (UInt32)AesCbc_Decode(&Aes, data, size);
}
STDMETHODIMP CAesCbcDecoder::SetKey(const Byte *data, UInt32 size)
{
if ((size & 0x7) != 0 || size < 16 || size > 32)
return E_INVALIDARG;
- AesSetKeyDecode(&Aes.aes, data, size);
+ Aes_SetKeyDecode(&Aes.aes, data, size);
return S_OK;
}
@@ -50,7 +50,7 @@ STDMETHODIMP CAesCbcDecoder::SetInitVector(const Byte *data, UInt32 size)
{
if (size != AES_BLOCK_SIZE)
return E_INVALIDARG;
- AesCbcInit(&Aes, data);
+ AesCbc_Init(&Aes, data);
return S_OK;
}
diff --git a/CPP/7zip/Crypto/AES/MyAES.h b/CPP/7zip/Crypto/AES/MyAES.h
index 29bd83c6..ee1d2828 100755
--- a/CPP/7zip/Crypto/AES/MyAES.h
+++ b/CPP/7zip/Crypto/AES/MyAES.h
@@ -10,7 +10,7 @@
extern "C"
{
-#include "../../../../C/Crypto/Aes.h"
+#include "../../../../C/Aes.h"
}
namespace NCrypto {
diff --git a/CPP/7zip/Crypto/Hash/Sha1.cpp b/CPP/7zip/Crypto/Hash/Sha1.cpp
index 0e1d2ecf..8d56b3dc 100755
--- a/CPP/7zip/Crypto/Hash/Sha1.cpp
+++ b/CPP/7zip/Crypto/Hash/Sha1.cpp
@@ -5,7 +5,10 @@
#include "StdAfx.h"
#include "Sha1.h"
-#include "RotateDefs.h"
+extern "C"
+{
+#include "../../../../C/RotateDefs.h"
+}
namespace NCrypto {
namespace NSha1 {
diff --git a/CPP/7zip/Crypto/Hash/Sha256.h b/CPP/7zip/Crypto/Hash/Sha256.h
deleted file mode 100755
index e4788f41..00000000
--- a/CPP/7zip/Crypto/Hash/Sha256.h
+++ /dev/null
@@ -1,30 +0,0 @@
-// Crypto/Sha256.h
-
-#ifndef __CRYPTO_SHA256_H
-#define __CRYPTO_SHA256_H
-
-#include "Common/Types.h"
-
-namespace NCrypto {
-namespace NSha256 {
-
-class CContext
-{
- static const UInt32 K[64];
-
- UInt32 _state[8];
- UInt64 _count;
- Byte _buffer[64];
- static void Transform(UInt32 *digest, const UInt32 *data);
- void WriteByteBlock();
-public:
- enum {DIGESTSIZE = 32};
- CContext() { Init(); } ;
- void Init();
- void Update(const Byte *data, size_t size);
- void Final(Byte *digest);
-};
-
-}}
-
-#endif
diff --git a/CPP/7zip/Crypto/RarAES/RarAES.cpp b/CPP/7zip/Crypto/RarAES/RarAES.cpp
index f978e275..cb907ec2 100755
--- a/CPP/7zip/Crypto/RarAES/RarAES.cpp
+++ b/CPP/7zip/Crypto/RarAES/RarAES.cpp
@@ -76,14 +76,14 @@ STDMETHODIMP CDecoder::CryptoSetPassword(const Byte *data, UInt32 size)
STDMETHODIMP CDecoder::Init()
{
Calculate();
- AesSetKeyDecode(&Aes.aes, aesKey, kRarAesKeySize);
- AesCbcInit(&Aes, aesInit);
+ Aes_SetKeyDecode(&Aes.aes, aesKey, kRarAesKeySize);
+ AesCbc_Init(&Aes, aesInit);
return S_OK;
}
STDMETHODIMP_(UInt32) CDecoder::Filter(Byte *data, UInt32 size)
{
- return AesCbcDecode(&Aes, data, size);
+ return (UInt32)AesCbc_Decode(&Aes, data, size);
}
void CDecoder::Calculate()
diff --git a/CPP/7zip/Crypto/RarAES/RarAES.h b/CPP/7zip/Crypto/RarAES/RarAES.h
index aea948d8..a99ad531 100755
--- a/CPP/7zip/Crypto/RarAES/RarAES.h
+++ b/CPP/7zip/Crypto/RarAES/RarAES.h
@@ -12,7 +12,7 @@
extern "C"
{
-#include "../../../../C/Crypto/Aes.h"
+#include "../../../../C/Aes.h"
}
namespace NCrypto {
diff --git a/CPP/7zip/Crypto/WzAES/WzAES.cpp b/CPP/7zip/Crypto/WzAES/WzAES.cpp
index 106f2d94..704ea9fc 100755
--- a/CPP/7zip/Crypto/WzAES/WzAES.cpp
+++ b/CPP/7zip/Crypto/WzAES/WzAES.cpp
@@ -47,12 +47,12 @@ void CBaseCoder::EncryptData(Byte *data, UInt32 size)
{
if (++_counter[0] == 0)
_counter[1]++;
- UInt32 outBuf[4];
- AesEncode32(_counter, outBuf, Aes.rkey, Aes.numRounds2);
- SetUi32(_buffer, outBuf[0]);
- SetUi32(_buffer + 4, outBuf[1]);
- SetUi32(_buffer + 8, outBuf[2]);
- SetUi32(_buffer + 12, outBuf[3]);
+ UInt32 temp[4];
+ Aes_Encode32(&Aes, temp, _counter);
+ SetUi32(_buffer, temp[0]);
+ SetUi32(_buffer + 4, temp[1]);
+ SetUi32(_buffer + 8, temp[2]);
+ SetUi32(_buffer + 12, temp[3]);
pos = 0;
}
*data++ ^= _buffer[pos++];
@@ -115,17 +115,10 @@ STDMETHODIMP CBaseCoder::Init()
for (int i = 0; i < 4; i++)
_counter[i] = 0;
- AesSetKeyEncode(&Aes, buf, keySize);
+ Aes_SetKeyEncode(&Aes, buf, keySize);
return S_OK;
}
-static HRESULT SafeWrite(ISequentialOutStream *outStream, const Byte *data, UInt32 size)
-{
- UInt32 processedSize;
- RINOK(WriteStream(outStream, data, size, &processedSize));
- return ((processedSize == size) ? S_OK : E_FAIL);
-}
-
/*
STDMETHODIMP CEncoder::WriteCoderProperties(ISequentialOutStream *outStream)
{
@@ -139,15 +132,15 @@ HRESULT CEncoder::WriteHeader(ISequentialOutStream *outStream)
UInt32 saltSize = _key.GetSaltSize();
g_RandomGenerator.Generate(_key.Salt, saltSize);
Init();
- RINOK(SafeWrite(outStream, _key.Salt, saltSize));
- return SafeWrite(outStream, _key.PwdVerifComputed, kPwdVerifCodeSize);
+ RINOK(WriteStream(outStream, _key.Salt, saltSize));
+ return WriteStream(outStream, _key.PwdVerifComputed, kPwdVerifCodeSize);
}
HRESULT CEncoder::WriteFooter(ISequentialOutStream *outStream)
{
Byte mac[kMacSize];
_hmac.Final(mac, kMacSize);
- return SafeWrite(outStream, mac, kMacSize);
+ return WriteStream(outStream, mac, kMacSize);
}
STDMETHODIMP CDecoder::SetDecoderProperties2(const Byte *data, UInt32 size)
@@ -167,10 +160,7 @@ HRESULT CDecoder::ReadHeader(ISequentialInStream *inStream)
UInt32 saltSize = _key.GetSaltSize();
UInt32 extraSize = saltSize + kPwdVerifCodeSize;
Byte temp[kSaltSizeMax + kPwdVerifCodeSize];
- UInt32 processedSize;
- RINOK(ReadStream(inStream, temp, extraSize, &processedSize));
- if (processedSize != extraSize)
- return E_FAIL;
+ RINOK(ReadStream_FAIL(inStream, temp, extraSize));
UInt32 i;
for (i = 0; i < saltSize; i++)
_key.Salt[i] = temp[i];
@@ -195,11 +185,8 @@ bool CDecoder::CheckPasswordVerifyCode()
HRESULT CDecoder::CheckMac(ISequentialInStream *inStream, bool &isOK)
{
isOK = false;
- UInt32 processedSize;
Byte mac1[kMacSize];
- RINOK(ReadStream(inStream, mac1, kMacSize, &processedSize));
- if (processedSize != kMacSize)
- return E_FAIL;
+ RINOK(ReadStream_FAIL(inStream, mac1, kMacSize));
Byte mac2[kMacSize];
_hmac.Final(mac2, kMacSize);
isOK = CompareArrays(mac1, mac2, kMacSize);
diff --git a/CPP/7zip/Crypto/WzAES/WzAES.h b/CPP/7zip/Crypto/WzAES/WzAES.h
index 72a493a1..fa14410a 100755
--- a/CPP/7zip/Crypto/WzAES/WzAES.h
+++ b/CPP/7zip/Crypto/WzAES/WzAES.h
@@ -23,7 +23,7 @@ specified in password Based File Encryption Utility:
extern "C"
{
-#include "../../../../C/Crypto/Aes.h"
+#include "../../../../C/Aes.h"
}
namespace NCrypto {
diff --git a/CPP/7zip/Crypto/Zip/ZipCipher.cpp b/CPP/7zip/Crypto/Zip/ZipCipher.cpp
index 639776ce..b466f8a7 100755
--- a/CPP/7zip/Crypto/Zip/ZipCipher.cpp
+++ b/CPP/7zip/Crypto/Zip/ZipCipher.cpp
@@ -36,12 +36,8 @@ HRESULT CEncoder::WriteHeader(ISequentialOutStream *outStream)
header[kHeaderSize - 1] = Byte(_crc >> 24);
header[kHeaderSize - 2] = Byte(_crc >> 16);
- UInt32 processedSize;
_cipher.EncryptHeader(header);
- RINOK(WriteStream(outStream, header, kHeaderSize, &processedSize));
- if (processedSize != kHeaderSize)
- return E_FAIL;
- return S_OK;
+ return WriteStream(outStream, header, kHeaderSize);
}
STDMETHODIMP_(UInt32) CEncoder::Filter(Byte *data, UInt32 size)
@@ -61,10 +57,7 @@ STDMETHODIMP CDecoder::CryptoSetPassword(const Byte *data, UInt32 size)
HRESULT CDecoder::ReadHeader(ISequentialInStream *inStream)
{
Byte header[kHeaderSize];
- UInt32 processedSize;
- RINOK(ReadStream(inStream, header, kHeaderSize, &processedSize));
- if (processedSize != kHeaderSize)
- return E_FAIL;
+ RINOK(ReadStream_FAIL(inStream, header, kHeaderSize));
_cipher.DecryptHeader(header);
return S_OK;
}
diff --git a/CPP/7zip/ICoder.h b/CPP/7zip/ICoder.h
index a4976534..7b0ace12 100755
--- a/CPP/7zip/ICoder.h
+++ b/CPP/7zip/ICoder.h
@@ -39,6 +39,7 @@ namespace NCoderPropID
kDictionarySize = 0x400,
kUsedMemorySize,
kOrder,
+ kBlockSize,
kPosStateBits = 0x440,
kLitContextBits,
kLitPosBits,
diff --git a/CPP/7zip/MyVersion.h b/CPP/7zip/MyVersion.h
index af5c7d31..6e57dea3 100755
--- a/CPP/7zip/MyVersion.h
+++ b/CPP/7zip/MyVersion.h
@@ -1,8 +1,8 @@
#define MY_VER_MAJOR 4
-#define MY_VER_MINOR 57
-#define MY_VER_BUILD 0
-#define MY_VERSION "4.57"
-#define MY_7ZIP_VERSION "7-Zip 4.57"
-#define MY_DATE "2007-12-06"
-#define MY_COPYRIGHT "Copyright (c) 1999-2007 Igor Pavlov"
+#define MY_VER_MINOR 58
+#define MY_VER_BUILD 10
+#define MY_VERSION " 4.58 beta"
+#define MY_7ZIP_VERSION "7-Zip 4.58 beta"
+#define MY_DATE "2008-05-05"
+#define MY_COPYRIGHT "Copyright (c) 1999-2008 Igor Pavlov"
#define MY_VERSION_COPYRIGHT_DATE MY_VERSION " " MY_COPYRIGHT " " MY_DATE
diff --git a/CPP/7zip/PropID.h b/CPP/7zip/PropID.h
index a13fe27f..40450ee1 100755
--- a/CPP/7zip/PropID.h
+++ b/CPP/7zip/PropID.h
@@ -45,6 +45,7 @@ enum
kpidLinks,
kpidNumBlocks,
kpidNumVolumes,
+ kpidTimeType,
kpidTotalSize = 0x1100,
kpidFreeSpace,
diff --git a/CPP/7zip/UI/Agent/AgentOut.cpp b/CPP/7zip/UI/Agent/AgentOut.cpp
index 4c6ba1a1..7976e1a2 100755
--- a/CPP/7zip/UI/Agent/AgentOut.cpp
+++ b/CPP/7zip/UI/Agent/AgentOut.cpp
@@ -250,7 +250,7 @@ STDMETHODIMP CAgent::DoOperation(
UString resultPath;
int pos;
if(!NFile::NDirectory::MyGetFullPathName(archiveName, resultPath, pos))
- throw 141716;
+ return E_FAIL;
NFile::NDirectory::CreateComplexDirectory(resultPath.Left(pos));
}
if (!outStreamSpec->Create(archiveName, true))
@@ -282,7 +282,7 @@ STDMETHODIMP CAgent::DoOperation(
catch(...)
{
delete []propValues;
- throw;
+ return E_FAIL;
}
delete []propValues;
}
@@ -295,7 +295,8 @@ STDMETHODIMP CAgent::DoOperation(
CInFileStream *sfxStreamSpec = new CInFileStream;
CMyComPtr<IInStream> sfxStream(sfxStreamSpec);
if (!sfxStreamSpec->Open(sfxModule))
- throw "Can't open sfx module";
+ return E_FAIL;
+ // throw "Can't open sfx module";
RINOK(CopyBlock(sfxStream, outStream));
}
diff --git a/CPP/7zip/UI/Agent/AgentProxy.cpp b/CPP/7zip/UI/Agent/AgentProxy.cpp
index bb0d0530..a50a26c7 100755
--- a/CPP/7zip/UI/Agent/AgentProxy.cpp
+++ b/CPP/7zip/UI/Agent/AgentProxy.cpp
@@ -228,7 +228,20 @@ HRESULT CProxyArchive::ReadObjects(IInArchive *archive, IProgress *progress)
CProxyFolder *currentItem = &RootFolder;
UString fileName;
if(propVariantPath.vt == VT_EMPTY)
+ {
fileName = DefaultName;
+
+ NCOM::CPropVariant prop;
+ RINOK(archive->GetProperty(i, kpidExtension, &prop));
+ if (prop.vt == VT_BSTR)
+ {
+ fileName += L'.';
+ fileName += prop.bstrVal;
+ }
+ else if (prop.vt != VT_EMPTY)
+ return E_FAIL;
+
+ }
else
{
if(propVariantPath.vt != VT_BSTR)
diff --git a/CPP/7zip/UI/Client7z/Client7z.cpp b/CPP/7zip/UI/Client7z/Client7z.cpp
index fce1c4f6..e059d3ac 100755
--- a/CPP/7zip/UI/Client7z/Client7z.cpp
+++ b/CPP/7zip/UI/Client7z/Client7z.cpp
@@ -275,7 +275,7 @@ STDMETHODIMP CArchiveExtractCallback::GetStream(UInt32 index,
else
{
if (propVariant.vt != VT_UI4)
- throw "incorrect item";
+ return E_FAIL;
_processedFileInfo.Attributes = propVariant.ulVal;
_processedFileInfo.AttributesAreDefined = true;
}
@@ -684,11 +684,7 @@ STDMETHODIMP CArchiveUpdateCallback::CryptoGetTextPassword2(Int32 *passwordIsDef
//////////////////////////////////////////////////////////////////////////
// Main function
-int
-#ifdef _MSC_VER
-__cdecl
-#endif
-main(int argc, char* argv[])
+int MY_CDECL main(int argc, char* argv[])
{
#ifdef _WIN32
#ifndef _UNICODE
diff --git a/CPP/7zip/UI/Common/ArchiveExtractCallback.h b/CPP/7zip/UI/Common/ArchiveExtractCallback.h
index fd30d64d..756dfb08 100755
--- a/CPP/7zip/UI/Common/ArchiveExtractCallback.h
+++ b/CPP/7zip/UI/Common/ArchiveExtractCallback.h
@@ -95,7 +95,7 @@ private:
public:
CArchiveExtractCallback():
WriteModified(true),
- WriteCreated(false),
+ WriteCreated(true),
WriteAccessed(false),
_multiArchives(false)
{
diff --git a/CPP/7zip/UI/Common/DirItem.h b/CPP/7zip/UI/Common/DirItem.h
index 89bd4cd3..d2f2ab43 100755
--- a/CPP/7zip/UI/Common/DirItem.h
+++ b/CPP/7zip/UI/Common/DirItem.h
@@ -5,30 +5,31 @@
#include "Common/MyString.h"
#include "Common/Types.h"
+#include "../../Archive/IArchive.h"
struct CDirItem
{
- UInt32 Attributes;
FILETIME CreationTime;
FILETIME LastAccessTime;
FILETIME LastWriteTime;
UInt64 Size;
UString Name;
UString FullPath;
+ UInt32 Attributes;
bool IsDirectory() const { return (Attributes & FILE_ATTRIBUTE_DIRECTORY) != 0 ; }
};
struct CArchiveItem
{
- bool IsDirectory;
- // DWORD Attributes;
- // NWindows::NCOM::CPropVariant LastWriteTime;
FILETIME LastWriteTime;
- bool SizeIsDefined;
UInt64 Size;
UString Name;
+ bool IsDirectory;
+ bool SizeIsDefined;
bool Censored;
- int IndexInServer;
+ UInt32 IndexInServer;
+ int FileTimeType;
+ CArchiveItem(): IsDirectory(false), SizeIsDefined(false), Censored(false), FileTimeType(-1) {}
};
#endif
diff --git a/CPP/7zip/UI/Common/LoadCodecs.cpp b/CPP/7zip/UI/Common/LoadCodecs.cpp
index 087340a1..52b2ebe8 100755
--- a/CPP/7zip/UI/Common/LoadCodecs.cpp
+++ b/CPP/7zip/UI/Common/LoadCodecs.cpp
@@ -482,10 +482,10 @@ int CCodecs::FindFormatForArchiveType(const UString &arcType) const
extern unsigned int g_NumCodecs;
STDAPI CreateCoder2(bool encode, UInt32 index, const GUID *iid, void **outObject);
STDAPI GetMethodProperty(UInt32 codecIndex, PROPID propID, PROPVARIANT *value);
-// STDAPI GetNumberOfMethods(UINT32 *numCodecs);
+// STDAPI GetNumberOfMethods(UInt32 *numCodecs);
#endif
-STDMETHODIMP CCodecs::GetNumberOfMethods(UINT32 *numMethods)
+STDMETHODIMP CCodecs::GetNumberOfMethods(UInt32 *numMethods)
{
*numMethods =
#ifdef EXPORT_CODECS
@@ -495,7 +495,7 @@ STDMETHODIMP CCodecs::GetNumberOfMethods(UINT32 *numMethods)
return S_OK;
}
-STDMETHODIMP CCodecs::GetProperty(UINT32 index, PROPID propID, PROPVARIANT *value)
+STDMETHODIMP CCodecs::GetProperty(UInt32 index, PROPID propID, PROPVARIANT *value)
{
#ifdef EXPORT_CODECS
if (index < g_NumCodecs)
@@ -525,7 +525,7 @@ STDMETHODIMP CCodecs::GetProperty(UINT32 index, PROPID propID, PROPVARIANT *valu
return Libs[ci.LibIndex].GetMethodProperty(ci.CodecIndex, propID, value);
}
-STDMETHODIMP CCodecs::CreateDecoder(UINT32 index, const GUID *iid, void **coder)
+STDMETHODIMP CCodecs::CreateDecoder(UInt32 index, const GUID *iid, void **coder)
{
#ifdef EXPORT_CODECS
if (index < g_NumCodecs)
@@ -541,7 +541,7 @@ STDMETHODIMP CCodecs::CreateDecoder(UINT32 index, const GUID *iid, void **coder)
return S_OK;
}
-STDMETHODIMP CCodecs::CreateEncoder(UINT32 index, const GUID *iid, void **coder)
+STDMETHODIMP CCodecs::CreateEncoder(UInt32 index, const GUID *iid, void **coder)
{
#ifdef EXPORT_CODECS
if (index < g_NumCodecs)
diff --git a/CPP/7zip/UI/Common/LoadCodecs.h b/CPP/7zip/UI/Common/LoadCodecs.h
index 231680b5..dadcf7c2 100755
--- a/CPP/7zip/UI/Common/LoadCodecs.h
+++ b/CPP/7zip/UI/Common/LoadCodecs.h
@@ -154,10 +154,10 @@ public:
MY_UNKNOWN_IMP
#ifdef EXTERNAL_CODECS
- STDMETHOD(GetNumberOfMethods)(UINT32 *numMethods);
- STDMETHOD(GetProperty)(UINT32 index, PROPID propID, PROPVARIANT *value);
- STDMETHOD(CreateDecoder)(UINT32 index, const GUID *interfaceID, void **coder);
- STDMETHOD(CreateEncoder)(UINT32 index, const GUID *interfaceID, void **coder);
+ STDMETHOD(GetNumberOfMethods)(UInt32 *numMethods);
+ STDMETHOD(GetProperty)(UInt32 index, PROPID propID, PROPVARIANT *value);
+ STDMETHOD(CreateDecoder)(UInt32 index, const GUID *interfaceID, void **coder);
+ STDMETHOD(CreateEncoder)(UInt32 index, const GUID *interfaceID, void **coder);
#endif
int GetCodecLibIndex(UInt32 index);
diff --git a/CPP/7zip/UI/Common/OpenArchive.cpp b/CPP/7zip/UI/Common/OpenArchive.cpp
index 2874f6a7..4bd93455 100755
--- a/CPP/7zip/UI/Common/OpenArchive.cpp
+++ b/CPP/7zip/UI/Common/OpenArchive.cpp
@@ -37,7 +37,18 @@ HRESULT GetArchiveItemPath(IInArchive *archive, UInt32 index, const UString &def
{
RINOK(GetArchiveItemPath(archive, index, result));
if (result.IsEmpty())
+ {
result = defaultName;
+ NCOM::CPropVariant prop;
+ RINOK(archive->GetProperty(index, kpidExtension, &prop));
+ if (prop.vt == VT_BSTR)
+ {
+ result += L'.';
+ result += prop.bstrVal;
+ }
+ else if (prop.vt != VT_EMPTY)
+ return E_FAIL;
+ }
return S_OK;
}
@@ -129,12 +140,12 @@ HRESULT OpenArchive(
{
CIntVector orderIndices2;
CByteBuffer byteBuffer;
- const UInt32 kBufferSize = (200 << 10);
+ const size_t kBufferSize = (200 << 10);
byteBuffer.SetCapacity(kBufferSize);
Byte *buffer = byteBuffer;
RINOK(inStream->Seek(0, STREAM_SEEK_SET, NULL));
- UInt32 processedSize;
- RINOK(ReadStream(inStream, buffer, kBufferSize, &processedSize));
+ size_t processedSize = kBufferSize;
+ RINOK(ReadStream(inStream, buffer, &processedSize));
for (UInt32 pos = 0; pos < processedSize; pos++)
{
for (int i = 0; i < orderIndices.Size(); i++)
@@ -159,16 +170,16 @@ HRESULT OpenArchive(
else if (extension == L"000" || extension == L"001")
{
CByteBuffer byteBuffer;
- const UInt32 kBufferSize = (1 << 10);
+ const size_t kBufferSize = (1 << 10);
byteBuffer.SetCapacity(kBufferSize);
Byte *buffer = byteBuffer;
RINOK(inStream->Seek(0, STREAM_SEEK_SET, NULL));
- UInt32 processedSize;
- RINOK(ReadStream(inStream, buffer, kBufferSize, &processedSize));
+ size_t processedSize = kBufferSize;
+ RINOK(ReadStream(inStream, buffer, &processedSize));
if (processedSize >= 16)
{
Byte kRarHeader[] = {0x52 , 0x61, 0x72, 0x21, 0x1a, 0x07, 0x00};
- if (TestSignature(buffer, kRarHeader, 7) && buffer[9] == 0x73 && (buffer[10] && 1) != 0)
+ if (TestSignature(buffer, kRarHeader, 7) && buffer[9] == 0x73 && (buffer[10] & 1) != 0)
{
for (int i = 0; i < orderIndices.Size(); i++)
{
diff --git a/CPP/7zip/UI/Common/SetProperties.cpp b/CPP/7zip/UI/Common/SetProperties.cpp
index b1434ace..201e95b5 100755
--- a/CPP/7zip/UI/Common/SetProperties.cpp
+++ b/CPP/7zip/UI/Common/SetProperties.cpp
@@ -44,9 +44,23 @@ HRESULT SetProperties(IUnknown *unknown, const CObjectVector<CProperty> &propert
{
const CProperty &property = properties[i];
NCOM::CPropVariant propVariant;
- if (!property.Value.IsEmpty())
+ UString name = property.Name;
+ if (property.Value.IsEmpty())
+ {
+ if (!name.IsEmpty())
+ {
+ wchar_t c = name[name.Length() - 1];
+ if (c == L'-')
+ propVariant = false;
+ else if (c == L'+')
+ propVariant = true;
+ if (propVariant.vt != VT_EMPTY)
+ name = name.Left(name.Length() - 1);
+ }
+ }
+ else
ParseNumberString(property.Value, propVariant);
- realNames.Add(property.Name);
+ realNames.Add(name);
values[i] = propVariant;
}
CRecordVector<const wchar_t *> names;
diff --git a/CPP/7zip/UI/Common/Update.cpp b/CPP/7zip/UI/Common/Update.cpp
index ec5ebc80..8e879246 100755
--- a/CPP/7zip/UI/Common/Update.cpp
+++ b/CPP/7zip/UI/Common/Update.cpp
@@ -2,10 +2,6 @@
#include "StdAfx.h"
-#ifdef _WIN32
-#include <mapi.h>
-#endif
-
#include "Update.h"
#include "Common/IntToString.h"
@@ -338,9 +334,9 @@ static HRESULT Compress(
switch(value)
{
case NFileTimeType::kWindows:
- case NFileTimeType::kDOS:
case NFileTimeType::kUnix:
- fileTimeType = NFileTimeType::EEnum(value);
+ case NFileTimeType::kDOS:
+ fileTimeType = (NFileTimeType::EEnum)value;
break;
default:
return E_FAIL;
@@ -516,11 +512,31 @@ HRESULT EnumerateInArchiveItems(const NWildcard::CCensor &censor,
RINOK(GetArchiveItemFileTime(archive, i,
archiveFileInfo.LastWriteTime, ai.LastWriteTime));
- CPropVariant propertySize;
- RINOK(archive->GetProperty(i, kpidSize, &propertySize));
- ai.SizeIsDefined = (propertySize.vt != VT_EMPTY);
- if (ai.SizeIsDefined)
- ai.Size = ConvertPropVariantToUInt64(propertySize);
+ {
+ CPropVariant prop;
+ RINOK(archive->GetProperty(i, kpidSize, &prop));
+ ai.SizeIsDefined = (prop.vt != VT_EMPTY);
+ if (ai.SizeIsDefined)
+ ai.Size = ConvertPropVariantToUInt64(prop);
+ }
+
+ {
+ CPropVariant prop;
+ RINOK(archive->GetProperty(i, kpidTimeType, &prop));
+ if (prop.vt == VT_UI4)
+ {
+ ai.FileTimeType = (int)(NFileTimeType::EEnum)prop.ulVal;
+ switch(ai.FileTimeType)
+ {
+ case NFileTimeType::kWindows:
+ case NFileTimeType::kUnix:
+ case NFileTimeType::kDOS:
+ break;
+ default:
+ return E_FAIL;
+ }
+ }
+ }
ai.IndexInServer = i;
archiveItems.Add(ai);
@@ -593,6 +609,17 @@ struct CEnumDirItemUpdateCallback: public IEnumDirItemCallback
HRESULT CheckBreak() { return Callback->CheckBreak(); }
};
+#ifdef _WIN32
+typedef ULONG (FAR PASCAL MY_MAPISENDDOCUMENTS)(
+ ULONG_PTR ulUIParam,
+ LPSTR lpszDelimChar,
+ LPSTR lpszFilePaths,
+ LPSTR lpszFileNames,
+ ULONG ulReserved
+);
+typedef MY_MAPISENDDOCUMENTS FAR *MY_LPMAPISENDDOCUMENTS;
+#endif
+
HRESULT UpdateArchive(
CCodecs *codecs,
const NWildcard::CCensor &censor,
@@ -814,7 +841,7 @@ HRESULT UpdateArchive(
errorInfo.Message = L"can not load Mapi32.dll";
return E_FAIL;
}
- LPMAPISENDDOCUMENTS fnSend = (LPMAPISENDDOCUMENTS)
+ MY_LPMAPISENDDOCUMENTS fnSend = (MY_LPMAPISENDDOCUMENTS)
mapiLib.GetProcAddress("MAPISendDocuments");
if (fnSend == 0)
{
diff --git a/CPP/7zip/UI/Common/UpdatePair.cpp b/CPP/7zip/UI/Common/UpdatePair.cpp
index b4fb2a15..2ee0f167 100755
--- a/CPP/7zip/UI/Common/UpdatePair.cpp
+++ b/CPP/7zip/UI/Common/UpdatePair.cpp
@@ -14,8 +14,7 @@
using namespace NWindows;
using namespace NTime;
-static int MyCompareTime(NFileTimeType::EEnum fileTimeType,
- const FILETIME &time1, const FILETIME &time2)
+static int MyCompareTime(NFileTimeType::EEnum fileTimeType, const FILETIME &time1, const FILETIME &time2)
{
switch(fileTimeType)
{
@@ -24,16 +23,8 @@ static int MyCompareTime(NFileTimeType::EEnum fileTimeType,
case NFileTimeType::kUnix:
{
UInt32 unixTime1, unixTime2;
- if (!FileTimeToUnixTime(time1, unixTime1))
- {
- unixTime1 = 0;
- // throw 4191614;
- }
- if (!FileTimeToUnixTime(time2, unixTime2))
- {
- unixTime2 = 0;
- // throw 4191615;
- }
+ FileTimeToUnixTime(time1, unixTime1);
+ FileTimeToUnixTime(time2, unixTime2);
return MyCompare(unixTime1, unixTime2);
}
case NFileTimeType::kDOS:
@@ -41,12 +32,6 @@ static int MyCompareTime(NFileTimeType::EEnum fileTimeType,
UInt32 dosTime1, dosTime2;
FileTimeToDosTime(time1, dosTime1);
FileTimeToDosTime(time2, dosTime2);
- /*
- if (!FileTimeToDosTime(time1, dosTime1))
- throw 4191616;
- if (!FileTimeToDosTime(time2, dosTime2))
- throw 4191617;
- */
return MyCompare(dosTime1, dosTime2);
}
}
@@ -125,7 +110,8 @@ void GetUpdatePairInfoList(
throw 1082022;; // TTString(kNotCensoredCollisionMessaged + dirItem.Name);
pair.DirItemIndex = dirItemIndex2;
pair.ArchiveItemIndex = archiveItemIndex2;
- switch (MyCompareTime(fileTimeType, dirItem.LastWriteTime, archiveItem.LastWriteTime))
+ switch (MyCompareTime(archiveItem.FileTimeType != - 1 ?
+ (NFileTimeType::EEnum)archiveItem.FileTimeType : fileTimeType, dirItem.LastWriteTime, archiveItem.LastWriteTime))
{
case -1:
pair.State = NUpdateArchive::NPairState::kNewInArchive;
diff --git a/CPP/7zip/UI/Console/List.cpp b/CPP/7zip/UI/Console/List.cpp
index 7a2b9628..6ba2830e 100755
--- a/CPP/7zip/UI/Console/List.cpp
+++ b/CPP/7zip/UI/Console/List.cpp
@@ -295,7 +295,16 @@ HRESULT CFieldPrinter::PrintItemInfo(IInArchive *archive,
PrintSpaces(fieldInfo.PrefixSpacesWidth);
NCOM::CPropVariant propVariant;
- RINOK(archive->GetProperty(index, fieldInfo.PropID, &propVariant));
+ if (fieldInfo.PropID == kpidPath)
+ {
+ UString s;
+ RINOK(GetArchiveItemPath(archive, index, defaultItemName, s));
+ propVariant = s;
+ }
+ else
+ {
+ RINOK(archive->GetProperty(index, fieldInfo.PropID, &propVariant));
+ }
if (techMode)
{
g_StdOut << fieldInfo.Name << " = ";
diff --git a/CPP/7zip/UI/Console/Main.cpp b/CPP/7zip/UI/Console/Main.cpp
index de496530..265d2212 100755
--- a/CPP/7zip/UI/Console/Main.cpp
+++ b/CPP/7zip/UI/Console/Main.cpp
@@ -1,4 +1,4 @@
-/ Main.cpp
+// Main.cpp
#include "StdAfx.h"
@@ -298,7 +298,7 @@ int Main2(
stdStream << endl << "Codecs:" << endl;
#ifdef EXTERNAL_CODECS
- UINT32 numMethods;
+ UInt32 numMethods;
if (codecs->GetNumberOfMethods(&numMethods) == S_OK)
for (UInt32 j = 0; j < numMethods; j++)
{
diff --git a/CPP/7zip/UI/Console/MainAr.cpp b/CPP/7zip/UI/Console/MainAr.cpp
index fd42e4f6..6cc5cf9d 100755
--- a/CPP/7zip/UI/Console/MainAr.cpp
+++ b/CPP/7zip/UI/Console/MainAr.cpp
@@ -48,11 +48,7 @@ static const char *kMemoryExceptionMessage = "\n\nERROR: Can't allocate required
static const char *kUnknownExceptionMessage = "\n\nUnknown Error\n";
static const char *kInternalExceptionMessage = "\n\nInternal Error #";
-int
-#ifdef _MSC_VER
-__cdecl
-#endif
-main
+int MY_CDECL main
(
#ifndef _WIN32
int numArguments, const char *arguments[]
diff --git a/CPP/7zip/UI/Console/UpdateCallbackConsole.cpp b/CPP/7zip/UI/Console/UpdateCallbackConsole.cpp
index 1d4420da..dd4e2b9e 100755
--- a/CPP/7zip/UI/Console/UpdateCallbackConsole.cpp
+++ b/CPP/7zip/UI/Console/UpdateCallbackConsole.cpp
@@ -144,10 +144,8 @@ HRESULT CUpdateCallbackConsole::SetCompleted(const UInt64 *completeValue)
HRESULT CUpdateCallbackConsole::SetRatioInfo(const UInt64 * /* inSize */, const UInt64 * /* outSize */)
{
- /*
if (NConsoleClose::TestBreakSignal())
return E_ABORT;
- */
return S_OK;
}
diff --git a/CPP/7zip/UI/Explorer/ContextMenu.cpp b/CPP/7zip/UI/Explorer/ContextMenu.cpp
index 06210412..5a736eb1 100755
--- a/CPP/7zip/UI/Explorer/ContextMenu.cpp
+++ b/CPP/7zip/UI/Explorer/ContextMenu.cpp
@@ -352,7 +352,7 @@ STDMETHODIMP CZipContextMenu::QueryContextMenu(HMENU hMenu, UINT indexMenu,
{
CCommandMapItem commandMapItem;
if(!popupMenu.CreatePopup())
- throw 210503;
+ return E_FAIL;
menuDestroyer.Attach(popupMenu);
commandMapItem.CommandInternalID = kCommandNULL;
commandMapItem.Verb = kMainVerb;
diff --git a/CPP/7zip/UI/Far/ExtractEngine.cpp b/CPP/7zip/UI/Far/ExtractEngine.cpp
index c6583aae..2ffb14c1 100755
--- a/CPP/7zip/UI/Far/ExtractEngine.cpp
+++ b/CPP/7zip/UI/Far/ExtractEngine.cpp
@@ -101,13 +101,15 @@ STDMETHODIMP CExtractCallBackImp::AskOverwrite(
*answer = NOverwriteAnswer::kAutoRename;
break;
default:
- throw 20413;
+ return E_FAIL;
}
return S_OK;
}
STDMETHODIMP CExtractCallBackImp::PrepareOperation(const wchar_t *name, bool /* isFolder */, INT32 /* askExtractMode */, const UINT64 * /* position */)
{
+ if(WasEscPressed())
+ return E_ABORT;
m_CurrentFilePath = name;
return S_OK;
}
diff --git a/CPP/7zip/UI/Far/Plugin.cpp b/CPP/7zip/UI/Far/Plugin.cpp
index c176ac92..40851c0c 100755
--- a/CPP/7zip/UI/Far/Plugin.cpp
+++ b/CPP/7zip/UI/Far/Plugin.cpp
@@ -68,6 +68,9 @@ static void MyGetFileTime(IFolderFolder *anArchiveFolder, UInt32 itemIndex,
fileTime = propVariant.filetime;
}
}
+
+#define kDotsReplaceString "[[..]]"
+#define kDotsReplaceStringU L"[[..]]"
void CPlugin::ReadPluginPanelItem(PluginPanelItem &panelItem, UInt32 itemIndex)
{
@@ -83,6 +86,9 @@ void CPlugin::ReadPluginPanelItem(PluginPanelItem &panelItem, UInt32 itemIndex)
if (oemString.Length() > kFileNameSizeMax)
oemString = oemString.Left(kFileNameSizeMax);
+ if (oemString == "..")
+ oemString = kDotsReplaceString;
+
MyStringCopy(panelItem.FindData.cFileName, (const char *)oemString);
panelItem.FindData.cAlternateFileName[0] = 0;
@@ -194,12 +200,15 @@ void CPlugin::FreeFindData(struct PluginPanelItem *panelItems,
}
-void CPlugin::EnterToDirectory(const UString &aDirName)
+void CPlugin::EnterToDirectory(const UString &dirName)
{
CMyComPtr<IFolderFolder> newFolder;
- _folder->BindToFolder(aDirName, &newFolder);
+ UString s = dirName;
+ if (dirName == kDotsReplaceStringU)
+ s = L"..";
+ _folder->BindToFolder(s, &newFolder);
if (newFolder == NULL)
- if (aDirName.IsEmpty())
+ if (dirName.IsEmpty())
return;
else
throw 40325;
diff --git a/CPP/7zip/UI/FileManager/App.cpp b/CPP/7zip/UI/FileManager/App.cpp
index 86479f04..4a4dcc96 100755
--- a/CPP/7zip/UI/FileManager/App.cpp
+++ b/CPP/7zip/UI/FileManager/App.cpp
@@ -443,6 +443,12 @@ static void ReducePathToRealFileSystemPath(UString &path)
path = path.Left(pos + 1);
if (path.Length() == 3 && path[1] == L':')
break;
+ if (path.Length() > 2 && path[0] == '\\' && path[1] == '\\')
+ {
+ int nextPos = path.Find('\\', 2); // pos after \\COMPNAME
+ if (nextPos > 0 && path.Find('\\', nextPos + 1) == pos)
+ break;
+ }
path = path.Left(pos);
}
}
@@ -524,6 +530,12 @@ void CApp::OnCopy(bool move, bool copyToSame, int srcPanelIndex)
destPath = copyDialog.Value;
+ if (destPath.IsEmpty())
+ {
+ srcPanel.MessageBox(LangString(IDS_OPERATION_IS_NOT_SUPPORTED, 0x03020208));
+ return;
+ }
+
if (!IsPathAbsolute(destPath))
{
if (!srcPanel.IsFSFolder())
@@ -534,6 +546,13 @@ void CApp::OnCopy(bool move, bool copyToSame, int srcPanelIndex)
destPath = srcPanel._currentFolderPrefix + destPath;
}
+ if (destPath.Length() > 0 && destPath[0] == '\\')
+ if (destPath.Length() == 1 || destPath[1] != '\\')
+ {
+ srcPanel.MessageBox(LangString(IDS_OPERATION_IS_NOT_SUPPORTED, 0x03020208));
+ return;
+ }
+
if (indices.Size() > 1 || (destPath.Length() > 0 && destPath.ReverseFind('\\') == destPath.Length() - 1) ||
IsThereFolderOfPath(destPath))
{
diff --git a/CPP/7zip/UI/FileManager/ExtractCallback.cpp b/CPP/7zip/UI/FileManager/ExtractCallback.cpp
index 8b27b217..7998d5cc 100755
--- a/CPP/7zip/UI/FileManager/ExtractCallback.cpp
+++ b/CPP/7zip/UI/FileManager/ExtractCallback.cpp
@@ -162,7 +162,7 @@ STDMETHODIMP CExtractCallbackImp::AskOverwrite(
*answer = NOverwriteAnswer::kYes;
break;
default:
- throw 20413;
+ return E_FAIL;
}
return S_OK;
}
@@ -408,7 +408,7 @@ STDMETHODIMP CExtractCallbackImp::AskWrite(
OverwriteMode = NExtract::NOverwriteMode::kAutoRename;
break;
default:
- throw 20413;
+ return E_FAIL;
}
}
}
diff --git a/CPP/7zip/UI/FileManager/FM.cpp b/CPP/7zip/UI/FileManager/FM.cpp
index b9a51193..66e5a086 100755
--- a/CPP/7zip/UI/FileManager/FM.cpp
+++ b/CPP/7zip/UI/FileManager/FM.cpp
@@ -766,38 +766,40 @@ void OnSize(HWND hWnd)
MoveSubWindows(hWnd);
}
+int Window_GetRealHeight(NWindows::CWindow &w)
+{
+ RECT rect;
+ WINDOWPLACEMENT placement;
+ w.GetWindowRect(&rect);
+ int res = rect.bottom - rect.top;
+ if (w.GetPlacement(&placement))
+ res += placement.rcNormalPosition.top;
+ return res;
+}
+
void MoveSubWindows(HWND hWnd)
{
RECT rect;
::GetClientRect(hWnd, &rect);
int xSize = rect.right;
- int kHeaderSize = 0;
- int ySize = MyMax(int(rect.bottom - kHeaderSize), 0);
+ int headerSize = 0;
if (g_App._rebar)
- {
- RECT barRect;
- g_App._rebar.GetWindowRect(&barRect);
- kHeaderSize = barRect.bottom - barRect.top;
- ySize = MyMax(int(rect.bottom - kHeaderSize), 0);
- }
+ headerSize = Window_GetRealHeight(g_App._rebar);
+ int ySize = MyMax((int)(rect.bottom - headerSize), 0);
- // g_App._headerToolBar.Move(0, 2, xSize, kHeaderSize - 2);
- RECT rect2 = rect;
- rect2.bottom = 0;
- // g_App._headerReBar.SizeToRect(&rect2);
if (g_App.NumPanels > 1)
{
- g_App.Panels[0].Move(0, kHeaderSize, g_Splitter.GetPos(), ySize);
+ g_App.Panels[0].Move(0, headerSize, g_Splitter.GetPos(), ySize);
int xWidth1 = g_Splitter.GetPos() + kSplitterWidth;
- g_App.Panels[1].Move(xWidth1, kHeaderSize, xSize - xWidth1, ySize);
+ g_App.Panels[1].Move(xWidth1, headerSize, xSize - xWidth1, ySize);
}
else
{
/*
int otherPanel = 1 - g_App.LastFocusedPanel;
if (g_App.PanelsCreated[otherPanel])
- g_App.Panels[otherPanel].Move(0, kHeaderSize, 0, ySize);
+ g_App.Panels[otherPanel].Move(0, headerSize, 0, ySize);
*/
- g_App.Panels[g_App.LastFocusedPanel].Move(0, kHeaderSize, xSize, ySize);
+ g_App.Panels[g_App.LastFocusedPanel].Move(0, headerSize, xSize, ySize);
}
}
diff --git a/CPP/7zip/UI/FileManager/Panel.cpp b/CPP/7zip/UI/FileManager/Panel.cpp
index ac6e7d4b..9807b958 100755
--- a/CPP/7zip/UI/FileManager/Panel.cpp
+++ b/CPP/7zip/UI/FileManager/Panel.cpp
@@ -515,7 +515,7 @@ bool CPanel::OnCreate(CREATESTRUCT * /* createStruct */)
_statusBar.Create(WS_CHILD | WS_VISIBLE, L"Status", (*this), _statusBarID);
// _statusBar2.Create(WS_CHILD | WS_VISIBLE, L"Status", (*this), _statusBarID + 1);
- int sizes[] = {150, 200, 250, -1};
+ int sizes[] = {150, 250, 350, -1};
_statusBar.SetParts(4, sizes);
// _statusBar2.SetParts(5, sizes);
diff --git a/CPP/7zip/UI/FileManager/PanelItemOpen.cpp b/CPP/7zip/UI/FileManager/PanelItemOpen.cpp
index 7a42b2d0..bf746282 100755
--- a/CPP/7zip/UI/FileManager/PanelItemOpen.cpp
+++ b/CPP/7zip/UI/FileManager/PanelItemOpen.cpp
@@ -145,8 +145,13 @@ static const wchar_t *kStartExtensions[] =
{
L"exe", L"bat", L"com",
L"chm",
- L"msi", L"doc", L"xls", L"ppt", L"wps", L"wpt", L"wks", L"xlr", L"wdb",
+ L"msi", L"doc", L"xls", L"ppt", L"pps", L"wps", L"wpt", L"wks", L"xlr", L"wdb",
+
+ L"docx", L"docm", L"dotx", L"dotm", L"xlsx", L"xlsm", L"xltx", L"xltm", L"xlsb",
+ L"xlam", L"pptx", L"pptm", L"potx", L"potm", L"ppam", L"ppsx", L"ppsm", L"xsn",
+
L"odt", L"ods",
+ L"wb3",
L"pdf"
};
diff --git a/CPP/7zip/UI/FileManager/PanelListNotify.cpp b/CPP/7zip/UI/FileManager/PanelListNotify.cpp
index 69b06119..572118d0 100755
--- a/CPP/7zip/UI/FileManager/PanelListNotify.cpp
+++ b/CPP/7zip/UI/FileManager/PanelListNotify.cpp
@@ -9,7 +9,6 @@
#include "Windows/PropVariant.h"
#include "Windows/PropVariantConversions.h"
-// #include "Windows/COM.h"
#include "../Common/PropIDUtils.h"
#include "../../PropID.h"
@@ -19,26 +18,56 @@
using namespace NWindows;
-static UString ConvertSizeToString(UINT64 value)
+static UString ConvertSizeToStringShort(UInt64 value)
{
- wchar_t s[64];
- if (value < (UINT64(10000) << 0) /*&& ((value & 0x3FF) != 0 || value == 0)*/)
+ wchar_t s[32];
+ wchar_t c, c2 = L'B';
+ if (value < (UInt64)10000)
{
- ConvertUInt64ToString(value, s);
- return UString(s) + L" B";
+ c = L'B';
+ c2 = L'\0';
}
- if (value < (UINT64(10000) << 10))
+ else if (value < ((UInt64)10000 << 10))
{
- ConvertUInt64ToString((value >> 10), s);
- return UString(s) + L" K";
+ value >>= 10;
+ c = L'K';
}
- if (value < (UINT64(10000) << 20))
+ else if (value < ((UInt64)10000 << 20))
{
- ConvertUInt64ToString((value >> 20), s);
- return UString(s) + L" M";
+ value >>= 20;
+ c = L'M';
}
- ConvertUInt64ToString((value >> 30), s);
- return UString(s) + L" G";
+ else
+ {
+ value >>= 30;
+ c = L'G';
+ }
+ ConvertUInt64ToString(value, s);
+ int p = MyStringLen(s);
+ s[p++] = L' ';
+ s[p++] = c;
+ s[p++] = c2;
+ s[p++] = L'\0';
+ return s;
+}
+
+static UString ConvertSizeToString(UInt64 value)
+{
+ wchar_t s[32];
+ ConvertUInt64ToString(value, s);
+ int i = MyStringLen(s);
+ int pos = sizeof(s) / sizeof(s[0]);
+ s[--pos] = L'\0';
+ while (i > 3)
+ {
+ s[--pos] = s[--i];
+ s[--pos] = s[--i];
+ s[--pos] = s[--i];
+ s[--pos] = L' ';
+ }
+ while (i > 0)
+ s[--pos] = s[--i];
+ return s + pos;
}
LRESULT CPanel::SetItemText(LVITEMW &item)
@@ -60,11 +89,11 @@ LRESULT CPanel::SetItemText(LVITEMW &item)
}
if (!defined)
{
- NCOM::CPropVariant propVariant;
- _folder->GetProperty(index, kpidAttributes, &propVariant);
+ NCOM::CPropVariant prop;
+ _folder->GetProperty(index, kpidAttributes, &prop);
UINT32 attributes = 0;
- if (propVariant.vt == VT_UI4)
- attributes = propVariant.ulVal;
+ if (prop.vt == VT_UI4)
+ attributes = prop.ulVal;
else
{
if (IsItemFolder(index))
@@ -109,7 +138,7 @@ LRESULT CPanel::SetItemText(LVITEMW &item)
*/
// const NFind::CFileInfo &aFileInfo = m_Files[index];
- NCOM::CPropVariant propVariant;
+ NCOM::CPropVariant prop;
/*
bool needRead = true;
if (propID == kpidSize)
@@ -117,26 +146,26 @@ LRESULT CPanel::SetItemText(LVITEMW &item)
CComPtr<IFolderGetItemFullSize> getItemFullSize;
if (_folder.QueryInterface(&getItemFullSize) == S_OK)
{
- if (getItemFullSize->GetItemFullSize(index, &propVariant) == S_OK)
+ if (getItemFullSize->GetItemFullSize(index, &prop) == S_OK)
needRead = false;
}
}
if (needRead)
*/
- if (_folder->GetProperty(realIndex, propID, &propVariant) != S_OK)
+ if (_folder->GetProperty(realIndex, propID, &prop) != S_OK)
throw 2723407;
- if ((propID == kpidSize || propID == kpidPackedSize ||
- propID == kpidTotalSize || propID == kpidFreeSpace ||
- propID == kpidClusterSize)
- &&
- (propVariant.vt == VT_UI8 || propVariant.vt == VT_UI4))
- s = ConvertSizeToString(ConvertPropVariantToUInt64(propVariant));
+ if ((propID == kpidSize || propID == kpidPackedSize || propID == kpidClusterSize ||
+ propID == kpidNumSubFolders || propID == kpidNumSubFiles) &&
+ (prop.vt == VT_UI8 || prop.vt == VT_UI4))
+ s = ConvertSizeToString(ConvertPropVariantToUInt64(prop));
+ else if ((propID == kpidTotalSize || propID == kpidFreeSpace) &&
+ (prop.vt == VT_UI8 || prop.vt == VT_UI4))
+ s = ConvertSizeToStringShort(ConvertPropVariantToUInt64(prop));
else
- s = ConvertPropertyToString(propVariant, propID, false);
-
{
+ s = ConvertPropertyToString(prop, propID, false);
s.Replace(wchar_t(0xA), L' ');
s.Replace(wchar_t(0xD), L' ');
}
@@ -364,7 +393,7 @@ void CPanel::OnRefreshStatusBar()
if (indices.Size() > 0)
{
- UINT64 totalSize = 0;
+ UInt64 totalSize = 0;
for (int i = 0; i < indices.Size(); i++)
totalSize += GetItemSize(indices[i]);
selectSizeString = ConvertSizeToString(totalSize);
@@ -380,9 +409,9 @@ void CPanel::OnRefreshStatusBar()
if (realIndex != kParentIndex)
{
sizeString = ConvertSizeToString(GetItemSize(realIndex));
- NCOM::CPropVariant propVariant;
- if (_folder->GetProperty(realIndex, kpidLastWriteTime, &propVariant) == S_OK)
- dateString = ConvertPropertyToString(propVariant, kpidLastWriteTime, false);
+ NCOM::CPropVariant prop;
+ if (_folder->GetProperty(realIndex, kpidLastWriteTime, &prop) == S_OK)
+ dateString = ConvertPropertyToString(prop, kpidLastWriteTime, false);
}
}
_statusBar.SetText(2, sizeString);
diff --git a/CPP/7zip/UI/FileManager/ProgressDialog2.rc b/CPP/7zip/UI/FileManager/ProgressDialog2.rc
index d505033f..58cdec36 100755
--- a/CPP/7zip/UI/FileManager/ProgressDialog2.rc
+++ b/CPP/7zip/UI/FileManager/ProgressDialog2.rc
@@ -10,7 +10,7 @@
#define bYPos (ySize - marg - bYSize)
#undef bXSize
-#define bXSize 72
+#define bXSize 80
#define bXPos1 (xSize - marg - bXSize)
#define bXPos2 (bXPos1 - 10 - bXSize)
diff --git a/CPP/7zip/UI/GUI/CompressDialog.cpp b/CPP/7zip/UI/GUI/CompressDialog.cpp
index 6836f724..51d215bc 100755
--- a/CPP/7zip/UI/GUI/CompressDialog.cpp
+++ b/CPP/7zip/UI/GUI/CompressDialog.cpp
@@ -409,6 +409,8 @@ void CCompressDialog::CheckControlsEnable()
EnableItem(IDC_STATIC_COMPRESS_ENCRYPTION_METHOD, fi.Encrypt);
EnableItem(IDC_COMPRESS_COMBO_ENCRYPTION_METHOD, fi.Encrypt);
EnableItem(IDC_COMPRESS_CHECK_ENCRYPT_FILE_NAMES, fi.EncryptFileNames);
+
+ ShowItem(IDC_COMPRESS_CHECK_ENCRYPT_FILE_NAMES, fi.EncryptFileNames);
}
bool CCompressDialog::IsSFX()
@@ -1022,13 +1024,16 @@ void CCompressDialog::SetDictionary()
}
case kBZip2:
{
- UInt32 defaultDictionary;
- if (level >= 5)
- defaultDictionary = (900 << 10);
- else if (level >= 3)
- defaultDictionary = (500 << 10);
- else
- defaultDictionary = (100 << 10);
+ // UInt32 defaultDictionary;
+ if (defaultDictionary == UInt32(-1))
+ {
+ if (level >= 5)
+ defaultDictionary = (900 << 10);
+ else if (level >= 3)
+ defaultDictionary = (500 << 10);
+ else
+ defaultDictionary = (100 << 10);
+ }
for (int i = 1; i <= 9; i++)
{
UInt32 dictionary = (i * 100) << 10;
diff --git a/CPP/Build.mak b/CPP/Build.mak
index d2595560..fd411aba 100755
--- a/CPP/Build.mak
+++ b/CPP/Build.mak
@@ -1,7 +1,9 @@
!IFDEF CPU
+!IFNDEF NO_BUFFEROVERFLOWU
LIBS = $(LIBS) bufferoverflowU.lib
-CFLAGS = $(CFLAGS) -GS- -Zc:forScope
!ENDIF
+!ENDIF
+
!IFNDEF O
!IFDEF CPU
@@ -21,7 +23,7 @@ MY_ML = ml64
COMPL_ASM = $(MY_ML) -c -Fo$O/ $**
-CFLAGS = $(CFLAGS) -nologo -c -Fo$O/ -EHsc -Gz -WX -Gy
+CFLAGS = $(CFLAGS) -nologo -c -Fo$O/ -WX -EHsc -Gr -Gy -GR-
!IFDEF MY_STATIC_LINK
!IFNDEF MY_SINGLE_THREAD
@@ -32,14 +34,15 @@ CFLAGS = $(CFLAGS) -MD
!ENDIF
!IFDEF NEW_COMPILER
-CFLAGS_O1 = $(CFLAGS) -O1 -W4 -Wp64
-CFLAGS_O2 = $(CFLAGS) -O2 -W4 -Wp64
+CFLAGS = $(CFLAGS) -W4 -GS- -Zc:forScope
!ELSE
-CFLAGS_O1 = $(CFLAGS) -O1 -W3
-CFLAGS_O2 = $(CFLAGS) -O2 -W3
+CFLAGS = $(CFLAGS) -W3
!ENDIF
-LFLAGS = $(LFLAGS) -nologo -OPT:NOWIN98 -OPT:REF
+CFLAGS_O1 = $(CFLAGS) -O1
+CFLAGS_O2 = $(CFLAGS) -O2
+
+LFLAGS = $(LFLAGS) -nologo -OPT:NOWIN98 -OPT:REF -OPT:ICF
!IFDEF DEF_FILE
LFLAGS = $(LFLAGS) -DLL -DEF:$(DEF_FILE)
diff --git a/CPP/Common/CRC.cpp b/CPP/Common/CRC.cpp
index b768128c..f151471b 100755
--- a/CPP/Common/CRC.cpp
+++ b/CPP/Common/CRC.cpp
@@ -7,8 +7,4 @@ extern "C"
#include "../../C/7zCrc.h"
}
-class CCRCTableInit
-{
-public:
- CCRCTableInit() { CrcGenerateTable(); }
-} g_CRCTableInit;
+struct CCRCTableInit { CCRCTableInit() { CrcGenerateTable(); } } g_CRCTableInit;
diff --git a/CPP/Common/ListFileUtils.cpp b/CPP/Common/ListFileUtils.cpp
index 4f8a9e59..cf03d324 100755
--- a/CPP/Common/ListFileUtils.cpp
+++ b/CPP/Common/ListFileUtils.cpp
@@ -2,6 +2,7 @@
#include "StdAfx.h"
+#include "MyWindows.h"
#include "../Windows/FileIO.h"
#include "ListFileUtils.h"
diff --git a/CPP/Common/StringConvert.cpp b/CPP/Common/StringConvert.cpp
index c0b19e16..762efd8d 100755
--- a/CPP/Common/StringConvert.cpp
+++ b/CPP/Common/StringConvert.cpp
@@ -26,23 +26,31 @@ UString MultiByteToUnicodeString(const AString &srcString, UINT codePage)
return resultString;
}
-AString UnicodeStringToMultiByte(const UString &srcString, UINT codePage)
+AString UnicodeStringToMultiByte(const UString &s, UINT codePage, char defaultChar, bool &defaultCharWasUsed)
{
- AString resultString;
- if(!srcString.IsEmpty())
+ AString dest;
+ defaultCharWasUsed = false;
+ if (!s.IsEmpty())
{
- int numRequiredBytes = srcString.Length() * 2;
- char defaultChar = '_';
- int numChars = WideCharToMultiByte(codePage, 0, srcString,
- srcString.Length(), resultString.GetBuffer(numRequiredBytes),
- numRequiredBytes + 1, &defaultChar, NULL);
+ int numRequiredBytes = s.Length() * 2;
+ BOOL defUsed;
+ int numChars = WideCharToMultiByte(codePage, 0, s, s.Length(),
+ dest.GetBuffer(numRequiredBytes), numRequiredBytes + 1,
+ &defaultChar, &defUsed);
+ defaultCharWasUsed = (defUsed != FALSE);
#ifndef _WIN32_WCE
if(numChars == 0)
throw 282229;
#endif
- resultString.ReleaseBuffer(numChars);
+ dest.ReleaseBuffer(numChars);
}
- return resultString;
+ return dest;
+}
+
+AString UnicodeStringToMultiByte(const UString &srcString, UINT codePage)
+{
+ bool defaultCharWasUsed;
+ return UnicodeStringToMultiByte(srcString, codePage, '_', defaultCharWasUsed);
}
#ifndef _WIN32_WCE
diff --git a/CPP/Common/StringConvert.h b/CPP/Common/StringConvert.h
index 32d8a3a1..0c37eb07 100755
--- a/CPP/Common/StringConvert.h
+++ b/CPP/Common/StringConvert.h
@@ -8,8 +8,10 @@
#include "Types.h"
UString MultiByteToUnicodeString(const AString &srcString, UINT codePage = CP_ACP);
+AString UnicodeStringToMultiByte(const UString &srcString, UINT codePage, char defaultChar, bool &defaultCharWasUsed);
AString UnicodeStringToMultiByte(const UString &srcString, UINT codePage = CP_ACP);
+
inline const wchar_t* GetUnicodeString(const wchar_t* unicodeString)
{ return unicodeString; }
inline const UString& GetUnicodeString(const UString &unicodeString)
diff --git a/CPP/Common/Types.h b/CPP/Common/Types.h
index 41d785e9..9365b327 100755
--- a/CPP/Common/Types.h
+++ b/CPP/Common/Types.h
@@ -3,55 +3,9 @@
#ifndef __COMMON_TYPES_H
#define __COMMON_TYPES_H
-#ifndef _7ZIP_BYTE_DEFINED
-#define _7ZIP_BYTE_DEFINED
-typedef unsigned char Byte;
-#endif
+#include "../../C/Types.h"
-#ifndef _7ZIP_INT16_DEFINED
-#define _7ZIP_INT16_DEFINED
-typedef short Int16;
-#endif
-
-#ifndef _7ZIP_UINT16_DEFINED
-#define _7ZIP_UINT16_DEFINED
-typedef unsigned short UInt16;
-#endif
-
-#ifndef _7ZIP_INT32_DEFINED
-#define _7ZIP_INT32_DEFINED
-typedef int Int32;
-#endif
-
-#ifndef _7ZIP_UINT32_DEFINED
-#define _7ZIP_UINT32_DEFINED
-typedef unsigned int UInt32;
-#endif
-
-#ifdef _MSC_VER
-
-#ifndef _7ZIP_INT64_DEFINED
-#define _7ZIP_INT64_DEFINED
-typedef __int64 Int64;
-#endif
-
-#ifndef _7ZIP_UINT64_DEFINED
-#define _7ZIP_UINT64_DEFINED
-typedef unsigned __int64 UInt64;
-#endif
-
-#else
-
-#ifndef _7ZIP_INT64_DEFINED
-#define _7ZIP_INT64_DEFINED
-typedef long long int Int64;
-#endif
-
-#ifndef _7ZIP_UINT64_DEFINED
-#define _7ZIP_UINT64_DEFINED
-typedef unsigned long long int UInt64;
-#endif
+typedef int HRes;
#endif
-#endif
diff --git a/CPP/Windows/PropVariantConversions.cpp b/CPP/Windows/PropVariantConversions.cpp
index 993dac76..0596d723 100755
--- a/CPP/Windows/PropVariantConversions.cpp
+++ b/CPP/Windows/PropVariantConversions.cpp
@@ -66,6 +66,11 @@ bool ConvertFileTimeToString(const FILETIME &ft, char *s, bool includeTime, bool
{
*s++ = ':';
UIntToStringSpec(st.wSecond, s, 2);
+ /*
+ s += 2;
+ *s++ = '.';
+ UIntToStringSpec(st.wMilliseconds, s, 3);
+ */
}
}
/*
diff --git a/CPP/Windows/Synchronization.h b/CPP/Windows/Synchronization.h
index c16f7b4d..e9668de8 100755
--- a/CPP/Windows/Synchronization.h
+++ b/CPP/Windows/Synchronization.h
@@ -26,9 +26,9 @@ public:
operator HANDLE() { return _object.handle; }
CBaseEvent() { Event_Construct(&_object); }
~CBaseEvent() { Close(); }
- HRes Close() { return Event_Close(&_object); }
+ WRes Close() { return Event_Close(&_object); }
#ifdef _WIN32
- HRes Create(bool manualReset, bool initiallyOwn, LPCTSTR name = NULL,
+ WRes Create(bool manualReset, bool initiallyOwn, LPCTSTR name = NULL,
LPSECURITY_ATTRIBUTES securityAttributes = NULL)
{
_object.handle = ::CreateEvent(securityAttributes, BoolToBOOL(manualReset),
@@ -37,7 +37,7 @@ public:
return 0;
return ::GetLastError();
}
- HRes Open(DWORD desiredAccess, bool inheritHandle, LPCTSTR name)
+ WRes Open(DWORD desiredAccess, bool inheritHandle, LPCTSTR name)
{
_object.handle = ::OpenEvent(desiredAccess, BoolToBOOL(inheritHandle), name);
if (_object.handle != 0)
@@ -46,27 +46,27 @@ public:
}
#endif
- HRes Set() { return Event_Set(&_object); }
+ WRes Set() { return Event_Set(&_object); }
// bool Pulse() { return BOOLToBool(::PulseEvent(_handle)); }
- HRes Reset() { return Event_Reset(&_object); }
- HRes Lock() { return Event_Wait(&_object); }
+ WRes Reset() { return Event_Reset(&_object); }
+ WRes Lock() { return Event_Wait(&_object); }
};
class CManualResetEvent: public CBaseEvent
{
public:
- HRes Create(bool initiallyOwn = false)
+ WRes Create(bool initiallyOwn = false)
{
return ManualResetEvent_Create(&_object, initiallyOwn ? 1: 0);
}
- HRes CreateIfNotCreated()
+ WRes CreateIfNotCreated()
{
if (IsCreated())
return 0;
return ManualResetEvent_CreateNotSignaled(&_object);
}
#ifdef _WIN32
- HRes CreateWithName(bool initiallyOwn, LPCTSTR name)
+ WRes CreateWithName(bool initiallyOwn, LPCTSTR name)
{
return CBaseEvent::Create(true, initiallyOwn, name);
}
@@ -76,11 +76,11 @@ public:
class CAutoResetEvent: public CBaseEvent
{
public:
- HRes Create()
+ WRes Create()
{
return AutoResetEvent_CreateNotSignaled(&_object);
}
- HRes CreateIfNotCreated()
+ WRes CreateIfNotCreated()
{
if (IsCreated())
return 0;
@@ -92,13 +92,13 @@ public:
class CObject: public CHandle
{
public:
- HRes Lock(DWORD timeoutInterval = INFINITE)
+ WRes Lock(DWORD timeoutInterval = INFINITE)
{ return (::WaitForSingleObject(_handle, timeoutInterval) == WAIT_OBJECT_0 ? 0 : ::GetLastError()); }
};
class CMutex: public CObject
{
public:
- HRes Create(bool initiallyOwn, LPCTSTR name = NULL,
+ WRes Create(bool initiallyOwn, LPCTSTR name = NULL,
LPSECURITY_ATTRIBUTES securityAttributes = NULL)
{
_handle = ::CreateMutex(securityAttributes, BoolToBOOL(initiallyOwn), name);
@@ -106,14 +106,14 @@ public:
return 0;
return ::GetLastError();
}
- HRes Open(DWORD desiredAccess, bool inheritHandle, LPCTSTR name)
+ WRes Open(DWORD desiredAccess, bool inheritHandle, LPCTSTR name)
{
_handle = ::OpenMutex(desiredAccess, BoolToBOOL(inheritHandle), name);
if (_handle != 0)
return 0;
return ::GetLastError();
}
- HRes Release()
+ WRes Release()
{
return ::ReleaseMutex(_handle) ? 0 : ::GetLastError();
}
@@ -133,15 +133,15 @@ class CSemaphore
public:
CSemaphore() { Semaphore_Construct(&_object); }
~CSemaphore() { Close(); }
- HRes Close() { return Semaphore_Close(&_object); }
+ WRes Close() { return Semaphore_Close(&_object); }
operator HANDLE() { return _object.handle; }
- HRes Create(UInt32 initiallyCount, UInt32 maxCount)
+ WRes Create(UInt32 initiallyCount, UInt32 maxCount)
{
return Semaphore_Create(&_object, initiallyCount, maxCount);
}
- HRes Release() { return Semaphore_Release1(&_object); }
- HRes Release(UInt32 releaseCount) { return Semaphore_ReleaseN(&_object, releaseCount); }
- HRes Lock() { return Semaphore_Wait(&_object); }
+ WRes Release() { return Semaphore_Release1(&_object); }
+ WRes Release(UInt32 releaseCount) { return Semaphore_ReleaseN(&_object, releaseCount); }
+ WRes Lock() { return Semaphore_Wait(&_object); }
};
class CCriticalSection
diff --git a/CPP/Windows/Thread.h b/CPP/Windows/Thread.h
index a46a5688..59760d4d 100755
--- a/CPP/Windows/Thread.h
+++ b/CPP/Windows/Thread.h
@@ -19,10 +19,10 @@ public:
CThread() { Thread_Construct(&thread); }
~CThread() { Close(); }
bool IsCreated() { return Thread_WasCreated(&thread) != 0; }
- HRes Close() { return Thread_Close(&thread); }
- HRes Create(THREAD_FUNC_RET_TYPE (THREAD_FUNC_CALL_TYPE *startAddress)(void *), LPVOID parameter)
+ WRes Close() { return Thread_Close(&thread); }
+ WRes Create(THREAD_FUNC_RET_TYPE (THREAD_FUNC_CALL_TYPE *startAddress)(void *), LPVOID parameter)
{ return Thread_Create(&thread, startAddress, parameter); }
- HRes Wait() { return Thread_Wait(&thread); }
+ WRes Wait() { return Thread_Wait(&thread); }
#ifdef _WIN32
DWORD Resume() { return ::ResumeThread(thread.handle); }
diff --git a/DOC/7zC.txt b/DOC/7zC.txt
index 84129547..9a239c6c 100755
--- a/DOC/7zC.txt
+++ b/DOC/7zC.txt
@@ -1,7 +1,7 @@
-7z ANSI-C Decoder 4.48
+7z ANSI-C Decoder 4.58
----------------------
-7z ANSI-C Decoder 4.48 Copyright (C) 1999-2006 Igor Pavlov
+7z ANSI-C Decoder 4.58 Copyright (C) 1999-2008 Igor Pavlov
7z ANSI-C provides 7z/LZMA decoding.
7z ANSI-C version is simplified version ported from C++ code.
@@ -20,17 +20,12 @@ Read lzma.txt for information about license.
Files
---------------------
-7zAlloc.* - Allocate and Free
-7zBuffer.* - Buffer structure
-7zCrc.* - CRC32 code
-7zDecode.* - Low level memory->memory decoding
-7zExtract.* - High level stream->memory decoding
+7zDecode.* - Low level 7z decoding
+7zExtract.* - High level 7z decoding
7zHeader.* - .7z format constants
7zIn.* - .7z archive opening
7zItem.* - .7z structures
7zMain.c - Test application
-7zMethodID.* - MethodID structure
-7zTypes.h - Base types and constants
How To Use
@@ -85,17 +80,6 @@ extracts files from archive.7z to current folder.
How to use .7z Decoder
----------------------
-.7z Decoder can be compiled in one of two modes:
-
-1) Default mode. In that mode 7z Decoder will read full compressed
- block to RAM before decompressing.
-
-2) Mode with defined _LZMA_IN_CB. In that mode 7z Decoder can read
- compressed block by parts. And you can specify desired buffer size.
- So memory requirements can be reduced. But decompressing speed will
- be 5-10% lower and code size is slightly larger.
-
-
Memory allocation
~~~~~~~~~~~~~~~~~
@@ -104,26 +88,27 @@ Memory allocation
2) Main pool
Such scheme can allow you to avoid fragmentation of allocated blocks.
+
Steps for using 7z decoder
--------------------------
Use code at 7zMain.c as example.
1) Declare variables:
- inStream /* implements ISzInStream interface */
- CArchiveDatabaseEx db; /* 7z archive database structure */
- ISzAlloc allocImp; /* memory functions for main pool */
- ISzAlloc allocTempImp; /* memory functions for temporary pool */
+ inStream /* implements ISzInStream interface */
+ CSzArEx db; /* 7z archive database structure */
+ ISzAlloc allocImp; /* memory functions for main pool */
+ ISzAlloc allocTempImp; /* memory functions for temporary pool */
-2) call InitCrcTable(); function to initialize CRC structures.
+2) call CrcGenerateTable(); function to initialize CRC structures.
-3) call SzArDbExInit(&db); function to initialize db structures.
+3) call SzArEx_Init(&db); function to initialize db structures.
-4) call SzArchiveOpen(inStream, &db, &allocMain, &allocTemp) to open archive
+4) call SzArEx_Open(&db, inStream, &allocMain, &allocTemp) to open archive
This function opens archive "inStream" and reads headers to "db".
All items in "db" will be allocated with "allocMain" functions.
-SzArchiveOpen function allocates and frees temporary structures by "allocTemp" functions.
+SzArEx_Open function allocates and frees temporary structures by "allocTemp" functions.
5) List items or Extract items
@@ -131,9 +116,9 @@ SzArchiveOpen function allocates and frees temporary structures by "allocTemp" f
~~~~~~~~~~~~~
{
UInt32 i;
- for (i = 0; i < db.Database.NumFiles; i++)
+ for (i = 0; i < db.db.NumFiles; i++)
{
- CFileItem *f = db.Database.Files + i;
+ CFileItem *f = db.db.Files + i;
printf("%10d %s\n", (int)f->Size, f->Name);
}
}
@@ -141,9 +126,9 @@ SzArchiveOpen function allocates and frees temporary structures by "allocTemp" f
Extracting code:
~~~~~~~~~~~~~~~~
- SZ_RESULT SzExtract(
- ISzInStream *inStream,
+ SZ_RESULT SzAr_Extract(
CArchiveDatabaseEx *db,
+ ISzInStream *inStream,
UInt32 fileIndex, /* index of file */
UInt32 *blockIndex, /* index of solid block */
Byte **outBuffer, /* pointer to pointer to output buffer (allocated with allocMain) */
@@ -163,7 +148,7 @@ SzArchiveOpen function allocates and frees temporary structures by "allocTemp" f
After decompressing you must free "outBuffer":
allocImp.Free(outBuffer);
-6) call SzArDbExFree(&db, allocImp.Free) to free allocated items in "db".
+6) call SzArEx_Free(&db, allocImp.Free) to free allocated items in "db".
@@ -173,7 +158,6 @@ Memory requirements for .7z decoding
Memory usage for Archive opening:
- Temporary pool:
- - Memory for compressed .7z headers (if _LZMA_IN_CB is not defined)
- Memory for uncompressed .7z headers
- some other temporary blocks
- Main pool:
@@ -187,7 +171,6 @@ Memory usage for Archive opening:
Memory usage for archive Decompressing:
- Temporary pool:
- - Memory for compressed solid block (if _LZMA_IN_CB is not defined)
- Memory for LZMA decompressing structures
- Main pool:
- Memory for decompressed solid block
@@ -195,38 +178,13 @@ Memory usage for archive Decompressing:
temprorary buffers can be about 15% of solid block size.
-If _LZMA_IN_CB is defined, 7z Decoder will not allocate memory for
-compressed blocks. Instead of this, you must allocate buffer with desired
+7z Decoder doesn't allocate memory for compressed blocks.
+Instead of this, you must allocate buffer with desired
size before calling 7z Decoder. Use 7zMain.c as example.
-
-EXIT codes
------------
-
-7z Decoder functions can return one of the following codes:
-
-#define SZ_OK (0)
-#define SZE_DATA_ERROR (1)
-#define SZE_OUTOFMEMORY (2)
-#define SZE_CRC_ERROR (3)
-
-#define SZE_NOTIMPL (4)
-#define SZE_FAIL (5)
-
-#define SZE_ARCHIVE_ERROR (6)
-
-
-
-LZMA Defines
-------------
-
-_LZMA_IN_CB - Use special callback mode for input stream to reduce memory requirements
-
-_SZ_FILE_SIZE_32 - define it if you need only support for files smaller than 4 GB
-_SZ_NO_INT_64 - define it if your compiler doesn't support long long int or __int64.
-
-_LZMA_PROB32 - it can increase LZMA decompressing speed on some 32-bit CPUs.
+Defines
+-------
_SZ_ALLOC_DEBUG - define it if you want to debug alloc/free operations to stderr.
diff --git a/DOC/7zFormat.txt b/DOC/7zFormat.txt
index e1cf7380..c0855381 100755
--- a/DOC/7zFormat.txt
+++ b/DOC/7zFormat.txt
@@ -238,24 +238,19 @@ Folder
{
BYTE
{
- 0:3 DecompressionMethod.IDSize
- 4:
- 0 - IsSimple
- 1 - Is not simple
- 5:
- 0 - No Attributes
- 1 - There Are Attributes
- 7:
- 0 - Last Method in Alternative_Method_List
- 1 - There are more alternative methods
+ 0:3 CodecIdSize
+ 4: Is Complex Coder
+ 5: There Are Attributes
+ 6: Reserved
+ 7: There are more alternative methods. (Not used anymore, must be 0).
}
- BYTE DecompressionMethod.ID[DecompressionMethod.IDSize]
- if (!IsSimple)
+ BYTE CodecId[CodecIdSize]
+ if (Is Complex Coder)
{
UINT64 NumInStreams;
UINT64 NumOutStreams;
}
- if (DecompressionMethod[0] != 0)
+ if (There Are Attributes)
{
UINT64 PropertiesSize
BYTE Properties[PropertiesSize]
diff --git a/DOC/7zip.nsi b/DOC/7zip.nsi
index b4dad123..77443e34 100755
--- a/DOC/7zip.nsi
+++ b/DOC/7zip.nsi
@@ -2,8 +2,8 @@
;Defines
!define VERSION_MAJOR 4
-!define VERSION_MINOR 57
-!define VERSION_POSTFIX_FULL ""
+!define VERSION_MINOR 58
+!define VERSION_POSTFIX_FULL " beta"
!ifdef WIN64
!ifdef IA64
!define VERSION_SYS_POSTFIX_FULL " for Windows IA-64"
@@ -231,7 +231,9 @@ Section
File nl.txt
File nb.txt
File nn.txt
+ File pa-in.txt
File pl.txt
+ File ps.txt
File pt.txt
File pt-br.txt
File ro.txt
@@ -413,7 +415,9 @@ Section "Uninstall"
Delete $INSTDIR\Lang\nl.txt
Delete $INSTDIR\Lang\nb.txt
Delete $INSTDIR\Lang\nn.txt
+ Delete $INSTDIR\Lang\pa-in.txt
Delete $INSTDIR\Lang\pl.txt
+ Delete $INSTDIR\Lang\ps.txt
Delete $INSTDIR\Lang\pt.txt
Delete $INSTDIR\Lang\pt-br.txt
Delete $INSTDIR\Lang\ro.txt
diff --git a/DOC/7zip.wxs b/DOC/7zip.wxs
index 10a9dd41..88a9efe2 100755
--- a/DOC/7zip.wxs
+++ b/DOC/7zip.wxs
@@ -1,8 +1,8 @@
<?xml version="1.0"?>
<?define VerMajor = "4" ?>
-<?define VerMinor = "57" ?>
-<?define VerBuild = "00" ?>
+<?define VerMinor = "58" ?>
+<?define VerBuild = "10" ?>
<?define MmVer = "$(var.VerMajor).$(var.VerMinor)" ?>
<?define MmHex = "0$(var.VerMajor)$(var.VerMinor)" ?>
<?define MmmmVer = "$(var.MmVer).$(var.VerBuild).0" ?>
@@ -270,7 +270,9 @@
<File Id="nl.txt" Name="nl.txt" />
<File Id="nb.txt" Name="nb.txt" />
<File Id="nn.txt" Name="nn.txt" />
+ <File Id="pa_in.txt" Name="pa-in.txt" />
<File Id="pl.txt" Name="pl.txt" />
+ <File Id="ps.txt" Name="ps.txt" />
<File Id="pt.txt" Name="pt.txt" />
<File Id="pt_br.txt" Name="pt-br.txt" />
<File Id="ro.txt" Name="ro.txt" />
diff --git a/DOC/Methods.txt b/DOC/Methods.txt
index e6156690..bba9f10e 100755
--- a/DOC/Methods.txt
+++ b/DOC/Methods.txt
@@ -1,4 +1,4 @@
-7-Zip method IDs (4.56)
+7-Zip method IDs (4.58)
-----------------------
Each compression or crypto method in 7z has unique binary value (ID).
@@ -40,19 +40,19 @@ List of defined IDs
03 - BCJ
1B - BCJ2
02 - PPC
- 05 - BC_PPC_B (Big Endian)
+ 05 - PPC (Big Endian)
03 - Alpha
- 01 - BC_Alpha
+ 01 - Alpha
04 - IA64
- 01 - BC_IA64
+ 01 - IA64
05 - ARM
- 01 - BC_ARM
+ 01 - ARM
06 - M68
- 05 - BC_M68_B (Big Endian)
+ 05 - M68 (Big Endian)
07 - ARM Thumb
- 01 - BC_ARMThumb
+ 01 - ARMT
08 - SPARC
- 05 - BC_SPARC
+ 05 - SPARC
04 - PPMD
01 - Version
diff --git a/DOC/history.txt b/DOC/history.txt
index a76b7ec0..a3a66e2d 100755
--- a/DOC/history.txt
+++ b/DOC/history.txt
@@ -1,294 +1,400 @@
Sources history of the 7-Zip
----------------------------
- Version 4.56 beta 2007-09-13
- --------------------------------------
- - some fixes in LZ encoder (LZMA and Deflate) code.
- size_t was replaces to ptrdiff_t.
- size_t version worked incorrectly with some compilers.
-
-
- Version 4.46 beta 2007-05-25
- --------------------------------------
- - CPP Synchronization objects now return HRes (error code) instead of bool.
-
-
- Version 4.45 beta 2007-04-16
- --------------------------------------
- - 7-Zip now uses C version of CRC, so you must call CrcGenerateTable at
- stratup code, or you must add CPP/Common/CRC.cpp to your project.
- - Method ID in .7z now is 63-bit integer (UInt64).
-
-
- Version 4.30 beta 2005-11-18
- --------------------------------------
- - Security.h::AddLockMemoryPrivilege - installs "Large pages" feature
- - MemoryLock.h::EnableLockMemoryPrivilege - enables "Large pages" feature
- - Alloc.h::SetLargePageSize - sets optimal LargePageSize size
-
-
- Version 4.27 2005-09-21
- --------------------------------------
- - Some GUIDs/interfaces were changed.
- IStream.h:
- ISequentialInStream::Read now works as old ReadPart
- ISequentialOutStream::Write now works as old WritePart
-
-
- Version 4.26 beta 2005-08-05
- --------------------------------------
- - MyAlloc(0)/BigAlloc(0) now return 0
-
-
- Version 4.25 beta 2005-07-31
- --------------------------------------
- - More 64-bit compatibilty
-
-
- Version 4.24 beta 2005-07-06
- --------------------------------------
- - Common\NewHandler.h: using throw() for code size optimization.
-
-
- Version 4.23 2005-06-29
- --------------------------------------
- - Bug was fixed: memory leak in Cab decoder.
-
-
- Version 4.19 beta 2005-05-21
- --------------------------------------
- - BZip2 code was rewritten. Now 7-Zip doesn't use original BZip2 code.
- Old (original) version was moved to folder 7zip/Compress/BZip2Original/
-
-
- Version 4.14 beta 2005-01-11
- --------------------------------------
- - STL using was reduced
- - 7za now supports Split(001) archves
-
-
- Version 4.10 beta 2004-10-21
- --------------------------------------
- - Codecs now use new interface: ICompressSetDecoderProperties2
-
-
- Version 4.07 beta 2004-10-03
- --------------------------------------
- - some interfaces were changed slightly to support
- -stdin -stdout mode.
- - FilterCoder for simple filters
- - Wildcard censor class was changed.
- - Bug was fixed: when encrypted stream was multiple 16,
- it used additional 16 empty bytes.
-
-
- Version 3.11 2003-10-06
- --------------------------------------
- File functions support unicode strings even
- on Windows 95/98/ME.
-
-
- Version 3.08.02 2003-09-20
- --------------------------------------
- More compatible with GCC.
-
-
- Version 3.08.02 beta 2003-08-20
- --------------------------------------
- Extracting bug in 7zExtract.cpp was fixed.
-
-
- Version 3.08 beta 2003-08-19
- --------------------------------------
- Big source code reconstruction.
-
-
- Version 2.30 Beta 32 2003-05-15
- --------------------------------------
- Small changes in Deflate decoder.
-
-
- Version 2.30 Beta 31 2003-04-29
- --------------------------------------
- Common/NewHandler.cpp
- HeapAlloc in (included to beta 30) was changed to malloc.
- HeapAlloc worked slower in Win95/98/Me.
-
-
- Version 2.30 Beta 30 2003-04-21
- --------------------------------------
- new file: Common/String.cpp
- Common/NewHandler.* were changed
+4.58 alpha 9 2008-04-29
+-------------------------
+- BUG was fixed: 7-Zip showed incorrect timestamps in ISO files.
+
+
+4.58 alpha 8 2008-04-15
+-------------------------
+- BUG in 4.58 alpha 5/6/7 was fixed:
+ LZMA encoder worked incorrectly, if lp != 0.
+- Unicode (UTF-8) support for filenames in .ZIP archives. Now there are 3 modes:
+ 1) Default mode: 7-Zip uses UTF-8, if the local code page doesn't contain required symbols.
+ 2) -mcu switch: 7-Zip uses UTF-8, if there are non-ASCII symbols.
+ 3) -mcl switch: 7-Zip uses local code page.
+- Now it's possible to use -mSW- and -mSW+ switches instead of -mSW=off and -mSW=on
+
+
+4.58 alpha 7 2008-04-08
+-------------------------
+- BUG was fixed: BZip2Encoder and BZip2Decoder used CEvent objects without
+ creating, when BZip2 code was called with one thread (with -mmt1 switch or with
+ default switches on single thread CPU).
+- .lzma support.
+- RPM and NSIS support was improved.
+- LZMA now stores only (2 << n) or (3 << n) dictionary size value to LZMA properties.
+
+
+4.58 alpha 6 2008-03-27
+-------------------------
+- NTFS time extra in ZIP.
+- New item property - kpidTimeType - VT_UI4 (0 - NTFS, 1 - Unix, 2 - DOS).
+- Static CRC table is not required now for Lzma Encoder (in Lz MatchFinder).
+
+
+4.58 alpha 5 2008-03-19
+-------------------------
+- Creation time (-mtc switch) for .7z archives
+- LZMA encoder was converted to ANSI-C
+
+
+4.58 alpha 3 2008-02-25
+-------------------------
+- Speed optimizations for LZMA decoding. Now it uses C code instead of C++.
+- 7-Zip now has 128 MB dictionary limit for 32-bit version:
+ It's for speed optimization: kNumLogBits = 9 + sizeof(size_t) / 2;
+- TAR: 'D' link flag support.
+- 7-Zip now can unpack multivolume RAR archives created with
+ "old style volume names" scheme (-vn switch) and names *.001, *.002, ...
+- Fixed bugs:
+ - 7-Zip FM could not copy / move files to root network folders like \\COMPNAME\FOLDERNAME\
+ In case of move it removed original files.
+ - SFX-WIN: if there are errors, it still could return 0.
+ - ZIP (.XPS file) isZip64 && thisDiskNumber16 == 0xFFFF.
+ - ZIP name updating:
+ If zip file contains extra field and you try to change properties of files,
+ 7-zip tries to delete all extra fileds (except for WzAES).
+ And that code could hang.
+ - 7-Zip GUI didn't suggest BZip2 dictionary size used in previous run.
+ - If creation time stamp was included in .RAR archive, 7-zip used creation time stamp
+ as modification time stamp.
+
+4.58 alpha 2 2007-12-31
+-------------------------
+- Small changes in Deflate and LZMA compression.
+- Some speed optimizations.
+
+
+4.57
+----
+- Bug was fixed:
+ Anti item is created for wrong file:
+ http://sourceforge.net/forum/forum.php?thread_id=1880366&forum_id=45798
+
+
+4.52 beta 2007-07-32
+-------------------------
+- 7-Zip could not decompress some cab files
+- "." dir creating at FAT was fixed / long names
+
+
+4.50 beta 2007-07-24
+-------------------------
+- 7-Zip now replaces unsupported filenames (like "nul", "com1") during extracting.
+- New switch for command line version:
+ -ssc[-] enables/disables case-sensitive mode.
+- 7z.exe l shows archive comment for zip archives
+- Some bugs were fixed: long paths names shorter than 4.
+- Speed optimizations for AES encryption.
+
+
+
+4.56 beta 2007-09-13
+-------------------------
+- some fixes in LZ encoder (LZMA and Deflate) code.
+ size_t was replaces to ptrdiff_t.
+ size_t version worked incorrectly with some compilers.
+
+4.46 beta 2007-05-25
+-------------------------
+- CPP Synchronization objects now return HRes (error code) instead of bool.
+
+
+4.45 beta 2007-04-16
+-------------------------
+- 7-Zip now uses C version of CRC, so you must call CrcGenerateTable at
+ stratup code, or you must add CPP/Common/CRC.cpp to your project.
+- Method ID in .7z now is 63-bit integer (UInt64).
+- Open error messages
+- unRar 1.5 fixed
+- unShrink fixed
+- BUG of 4.43 beta and 4.44 beta was fixed.
+ 7-Zip compressing to .zip in multi-threading mode didn't work in some cases.
+
+
+4.44 beta 2007-01-20
+-------------------------
+
+- Bug was fixed: LZMAEncoder.cpp::CEncoder::GetOptimumFast
+ it was:
+ data++
+ fixed version:
+ data = _matchFinder.GetPointerToCurrentPos(_matchFinderObj) - 1;
+ It could lead to very small cpmpression ratio decreasing when block needs move.
+
+
+4.30 beta 2005-11-18
+-------------------------
+- Security.h::AddLockMemoryPrivilege - installs "Large pages" feature
+- MemoryLock.h::EnableLockMemoryPrivilege - enables "Large pages" feature
+- Alloc.h::SetLargePageSize - sets optimal LargePageSize size
+
+
+4.27 2005-09-21
+-------------------------
+- Some GUIDs/interfaces were changed.
+ IStream.h:
+ ISequentialInStream::Read now works as old ReadPart
+ ISequentialOutStream::Write now works as old WritePart
+
+
+4.26 beta 2005-08-05
+-------------------------
+- MyAlloc(0)/BigAlloc(0) now return 0
+
+
+4.25 beta 2005-07-31
+-------------------------
+- More 64-bit compatibilty
- Version 2.30 Beta 29 2003-04-07
- --------------------------------------
- Small changes in LZMA code.
+4.24 beta 2005-07-06
+-------------------------
+- Common\NewHandler.h: using throw() for code size optimization.
- Version 2.30 Beta 28 2003-02-16
- --------------------------------------
- Processing anti-files was corrected.
-
- Version 2.30 Beta 27 2003-01-24
- --------------------------------------
- Project/Archiver/Format/Common/ArchiveInterface.h:
- new IArchiveOpenVolumeCallback interface.
+4.23 2005-06-29
+-------------------------
+- Bug was fixed: memory leak in Cab decoder.
- Version 2.30 Beta 26 2003-01-12
- --------------------------------------
- SDK/Interface/PropID.h:
- kpidComment now is kpidCommented
+4.19 beta 2005-05-21
+-------------------------
+- BZip2 code was rewritten. Now 7-Zip doesn't use original BZip2 code.
+ Old (original) version was moved to folder 7zip/Compress/BZip2Original/
- Version 2.30 Beta 25 2003-01-02
- --------------------------------------
- Main archive interfaces were changed.
-
+4.14 beta 2005-01-11
+-------------------------
+- STL using was reduced
+- 7za now supports Split(001) archves
- Version 2.30 Beta 24 2002-11-01
- --------------------------------------
- SDK/Windows/Synchronization.h
- SDK/Windows/Synchronization.cpp
- - some changes.
-
-
- Version 2.30 Beta 23 2002-09-07
- --------------------------------------
- Project/FileManager folder was added.
- Notation of some source files was changed.
-
-
- Version 2.30 Beta 22 2002-08-28
- --------------------------------------
- Project/FileManager folder was added.
- Notation of some source files was changed.
-
-
-
- Version 2.30 Beta 21 2002-07-08
- --------------------------------------
- Project/Compress/LZ/MatchFinder/BinTree/BinTree.h
- Project/Compress/LZ/MatchFinder/BinTree/BinTreeMain.h
- Project/Compress/LZ/MatchFinder/BinTree/HC.h
- Project/Compress/LZ/MatchFinder/BinTree/HCMain.h
- - RAM requirements for LZMA (7z) compression were reduced.
+4.10 beta 2004-10-21
+-------------------------
+- Codecs now use new interface: ICompressSetDecoderProperties2
- Version 2.30 Beta 20 2002-07-01
- --------------------------------------
- - SDK/Stream/WindowOut.h
- now it uses only required memory (dictionary size).
- - Project/Archiver/Resource
- contains common resurces
+4.07 beta 2004-10-03
+-------------------------
+- some interfaces were changed slightly to support
+ -stdin -stdout mode.
+- FilterCoder for simple filters
+- Wildcard censor class was changed.
+- Bug was fixed: when encrypted stream was multiple 16,
+ it used additional 16 empty bytes.
- Version 2.30 Beta 19 2002-04-11
- --------------------------------------
- - SDK/Archive/Rar/Handler.cpp
- supporting RAR29
- Version 2.30 Beta 18 2002-03-25
- --------------------------------------
- - SDK/Archive/Cab/MSZipDecoder.cpp
- SDK/Archive/Cab/LZXDecoder.cpp:
- bug with corrupted archives was fixed
- - Project/Compress/LZ/MatchFinder/BinTree/BinTree.h
- - Project/Compress/LZ/MatchFinder/BinTree/BinTreeMain.h
- some speed optimization (using prefetching)
+3.11 2003-10-06
+-------------------------
+ File functions support unicode strings even
+ on Windows 95/98/ME.
- Version 2.30 Beta 17 2002-03-03
- --------------------------------------
- - ARJ suppport.
+3.08.02 2003-09-20
+-------------------------
+ More compatible with GCC.
- Version 2.30 Beta 16 2002-02-24
- --------------------------------------
- - Project/Compress/LZ/LZMA/Decoder.cpp:
- Bug was fixed: LZMA could not extract more than 4 GB.
- - RPM and CPIO formats.
- - Project/Compress/LZ/LZMA/Encoder.*
- Project/Archiver/Format/7z/OutHandler.cpp
- New fast compression mode for LZMA: -m0a=0.
- - New match finders for LZMA: bt4b, hc3, hc4.
+3.08.02 beta 2003-08-20
+-------------------------
+ Extracting bug in 7zExtract.cpp was fixed.
-
- Version 2.30 Beta 15 2002-02-17
- --------------------------------------
- - Compression ratio in LZMA was slightly improved:
- Project/Compress/LZ/LZMA/Encoder.*
- Project/Archiver/Format/7z/OutHandler.cpp
-
-
- Version 2.30 Beta 14 2002-02-10
- --------------------------------------
- - Supporting multithreading for LZMA:
- Project/Compress/LZ/MatchFinder/MT
- - Common/String.h:
- CStringBase::Replace function was fixed.
-
-
- Version 2.30 Beta 13 2002-01-27
- --------------------------------------
- - Compress/LZ/MatchFinder/BinTree3.h:
- method
- - Compress/LZ/MatchFinder/BinTreemain.h:
- - one VirtualAlloc array was splitted to
- the for 3 arrays.
- - Hash-functions were changed.
-
-
-
- Version 2.30 Beta 12 2002-01-16
- --------------------------------------
- - Compress/LZ/MatchFinder/BinTreemain.h:
- Compress/LZ/MatchFinder/Patricia.h:
- Compress/PPM/PPMd/SubAlloc.h:
- Beta 11 bugs were fixed:
- - VirtualFree was used incorrectly
- - checking WIN32 instead _WINDOWS.
- Compress/LZ/MatchFinder/Patricia.h:
- Beta 11 bug with deleting m_Hash2Descendants was fixed.
-
-
- Version 2.30 Beta 11 2002-01-15
- --------------------------------------
- - Compress/LZ/MatchFinder/BinTreemain.h:
- Compress/LZ/MatchFinder/Patricia.h:
- Compress/PPM/PPMd/SubAlloc.h:
- using VirtualAlloc for memory allocating
- - Exlorer/ContextMenu.cpp:
- Testing supporting.
- CreateProcess instead WinExec
- - Format/Common/IArchiveHandler.h:
- Exlorer/ProxyHandler.cpp:
- FAR/Plugin.cpp:
- New properties names: Method, HostOS.
- - Exlorer/OverwriteDialog.cpp:
- FAR/OverwriteDialog.cpp:
- Windows/PropVariantConversions.h
- Using National time format was eliminated.
-
-
-
- Version 2.30 Beta 10 2002-01-11
- --------------------------------------
- - Exlorer/ContextMenu.cpp: bug with context menu on
- Windows NT4 in Unicode version was fixed.
- - Format/7z/UpdateArchiveEngine.cpp: bug was fixed -
- Updating in Beta 8 and 9 didn't work.
- - Exlorer/CCompressDialog.cpp: history growing bug was fixed.
-
-
- Version 2.30 Beta 9 2002-01-08
- --------------------------------------
- - SDK/Common/Vector.h: sopporting sorted object vectors .
- - Lang features.
- - Two new match finders: pat3h and pat4h.
- - SDK/Archive/Zip/InEngine.cpp: bug was fixed.
- - SDK/Windows/FileDir.cpp: function CreateComplexDirectory
- was changed.
+
+3.08 beta 2003-08-19
+-------------------------
+ Big source code reconstruction.
+
+
+2.30 Beta 32 2003-05-15
+-------------------------
+ Small changes in Deflate decoder.
+
+
+2.30 Beta 31 2003-04-29
+-------------------------
+ Common/NewHandler.cpp
+ HeapAlloc in (included to beta 30) was changed to malloc.
+ HeapAlloc worked slower in Win95/98/Me.
+
+
+2.30 Beta 30 2003-04-21
+-------------------------
+ new file: Common/String.cpp
+ Common/NewHandler.* were changed
+
+
+2.30 Beta 29 2003-04-07
+-------------------------
+ Small changes in LZMA code.
+
+
+2.30 Beta 28 2003-02-16
+-------------------------
+ Processing anti-files was corrected.
+
+
+2.30 Beta 27 2003-01-24
+-------------------------
+ Project/Archiver/Format/Common/ArchiveInterface.h:
+ new IArchiveOpenVolumeCallback interface.
+
+
+2.30 Beta 26 2003-01-12
+-------------------------
+ SDK/Interface/PropID.h:
+ kpidComment now is kpidCommented
+
+
+2.30 Beta 25 2003-01-02
+-------------------------
+ Main archive interfaces were changed.
+
+
+2.30 Beta 24 2002-11-01
+-------------------------
+ SDK/Windows/Synchronization.h
+ SDK/Windows/Synchronization.cpp
+ - some changes.
+
+
+2.30 Beta 23 2002-09-07
+-------------------------
+ Project/FileManager folder was added.
+ Notation of some source files was changed.
+
+
+2.30 Beta 22 2002-08-28
+-------------------------
+ Project/FileManager folder was added.
+ Notation of some source files was changed.
+
+
+
+2.30 Beta 21 2002-07-08
+-------------------------
+ Project/Compress/LZ/MatchFinder/BinTree/BinTree.h
+ Project/Compress/LZ/MatchFinder/BinTree/BinTreeMain.h
+ Project/Compress/LZ/MatchFinder/BinTree/HC.h
+ Project/Compress/LZ/MatchFinder/BinTree/HCMain.h
+ - RAM requirements for LZMA (7z) compression were reduced.
+
+
+2.30 Beta 20 2002-07-01
+-------------------------
+- SDK/Stream/WindowOut.h
+ now it uses only required memory (dictionary size).
+- Project/Archiver/Resource
+ contains common resurces
+
+
+2.30 Beta 19 2002-04-11
+-------------------------
+- SDK/Archive/Rar/Handler.cpp
+ supporting RAR29
+
+2.30 Beta 18 2002-03-25
+-------------------------
+- SDK/Archive/Cab/MSZipDecoder.cpp
+ SDK/Archive/Cab/LZXDecoder.cpp:
+ bug with corrupted archives was fixed
+- Project/Compress/LZ/MatchFinder/BinTree/BinTree.h
+- Project/Compress/LZ/MatchFinder/BinTree/BinTreeMain.h
+ some speed optimization (using prefetching)
+
+
+2.30 Beta 17 2002-03-03
+-------------------------
+- ARJ suppport.
+
+
+2.30 Beta 16 2002-02-24
+-------------------------
+- Project/Compress/LZ/LZMA/Decoder.cpp:
+ Bug was fixed: LZMA could not extract more than 4 GB.
+- RPM and CPIO formats.
+- Project/Compress/LZ/LZMA/Encoder.*
+ Project/Archiver/Format/7z/OutHandler.cpp
+ New fast compression mode for LZMA: -m0a=0.
+- New match finders for LZMA: bt4b, hc3, hc4.
+
+
+2.30 Beta 15 2002-02-17
+-------------------------
+- Compression ratio in LZMA was slightly improved:
+ Project/Compress/LZ/LZMA/Encoder.*
+ Project/Archiver/Format/7z/OutHandler.cpp
+
+
+2.30 Beta 14 2002-02-10
+-------------------------
+- Supporting multithreading for LZMA:
+ Project/Compress/LZ/MatchFinder/MT
+- Common/String.h:
+ CStringBase::Replace function was fixed.
+
+
+2.30 Beta 13 2002-01-27
+-------------------------
+- Compress/LZ/MatchFinder/BinTree3.h:
+ method
+- Compress/LZ/MatchFinder/BinTreemain.h:
+ - one VirtualAlloc array was splitted to
+ the for 3 arrays.
+ - Hash-functions were changed.
+
+
+
+2.30 Beta 12 2002-01-16
+-------------------------
+- Compress/LZ/MatchFinder/BinTreemain.h:
+ Compress/LZ/MatchFinder/Patricia.h:
+ Compress/PPM/PPMd/SubAlloc.h:
+ Beta 11 bugs were fixed:
+ - VirtualFree was used incorrectly
+ - checking WIN32 instead _WINDOWS.
+ Compress/LZ/MatchFinder/Patricia.h:
+ Beta 11 bug with deleting m_Hash2Descendants was fixed.
+
+
+2.30 Beta 11 2002-01-15
+-------------------------
+- Compress/LZ/MatchFinder/BinTreemain.h:
+ Compress/LZ/MatchFinder/Patricia.h:
+ Compress/PPM/PPMd/SubAlloc.h:
+ using VirtualAlloc for memory allocating
+- Exlorer/ContextMenu.cpp:
+ Testing supporting.
+ CreateProcess instead WinExec
+- Format/Common/IArchiveHandler.h:
+ Exlorer/ProxyHandler.cpp:
+ FAR/Plugin.cpp:
+ New properties names: Method, HostOS.
+- Exlorer/OverwriteDialog.cpp:
+ FAR/OverwriteDialog.cpp:
+ Windows/PropVariantConversions.h
+ Using National time format was eliminated.
+
+
+
+2.30 Beta 10 2002-01-11
+-------------------------
+- Exlorer/ContextMenu.cpp: bug with context menu on
+ Windows NT4 in Unicode version was fixed.
+- Format/7z/UpdateArchiveEngine.cpp: bug was fixed -
+ Updating in Beta 8 and 9 didn't work.
+- Exlorer/CCompressDialog.cpp: history growing bug was fixed.
+
+
+2.30 Beta 9 2002-01-08
+-------------------------
+- SDK/Common/Vector.h: sopporting sorted object vectors .
+- Lang features.
+- Two new match finders: pat3h and pat4h.
+- SDK/Archive/Zip/InEngine.cpp: bug was fixed.
+- SDK/Windows/FileDir.cpp: function CreateComplexDirectory
+ was changed.
diff --git a/DOC/lzma.txt b/DOC/lzma.txt
index 9392dc40..38a5d33c 100755
--- a/DOC/lzma.txt
+++ b/DOC/lzma.txt
@@ -1,7 +1,7 @@
-LZMA SDK 4.49
--------------
+LZMA SDK 4.58 beta
+------------------
-LZMA SDK Copyright (C) 1999-2007 Igor Pavlov
+LZMA SDK Copyright (C) 1999-2008 Igor Pavlov
LZMA SDK provides the documentation, samples, header files, libraries,
and tools you need to develop applications that use LZMA compression.
@@ -24,26 +24,21 @@ LZMA SDK is available under any of the following licenses:
1) GNU Lesser General Public License (GNU LGPL)
2) Common Public License (CPL)
-3) Simplified license for unmodified code (read SPECIAL EXCEPTION)
-4) Proprietary license
+3) Common Development and Distribution License (CDDL) Version 1.0
+4) Simplified license for unmodified code (read SPECIAL EXCEPTION)
-It means that you can select one of these four options and follow rules of that license.
+It means that you can select one of these options and follow rules of that license.
-1,2) GNU LGPL and CPL licenses are pretty similar and both these
-licenses are classified as
+1,2,3) GNU LGPL, CPL and CDDL licenses are classified as
- "Free software licenses" at http://www.gnu.org/
- "OSI-approved" at http://www.opensource.org/
-
-3) SPECIAL EXCEPTION
+4) Simplified license for unmodified code (read SPECIAL EXCEPTION)
Igor Pavlov, as the author of this code, expressly permits you
to statically or dynamically link your code (or bind by name)
-to the files from LZMA SDK without subjecting your linked
-code to the terms of the CPL or GNU LGPL.
-Any modifications or additions to files from LZMA SDK, however,
-are subject to the GNU LGPL or CPL terms.
+to the files from LZMA SDK.
SPECIAL EXCEPTION allows you to use LZMA SDK in applications with closed code,
while you keep LZMA SDK code unmodified.
@@ -56,27 +51,21 @@ Agreement you have for any previous version of LZMA SDK developed by Igor Pavlov
SPECIAL EXCEPTION #2 allows owners of proprietary licenses to use latest version
of LZMA SDK as update for previous versions.
+Some files in LZMA SDK are placed in public domain.
+Some of these "public domain" files:
+C\Types.h,
+C\LzmaLib.*
+C\LzmaLibUtil.*
+LzmaAlone.cpp,
+LzmaAlone.cs,
+LzmaAlone.java
-SPECIAL EXCEPTION #3: Igor Pavlov, as the author of this code, expressly permits
-you to use code of the following files:
-BranchTypes.h, LzmaTypes.h, LzmaTest.c, LzmaStateTest.c, LzmaAlone.cpp,
-LzmaAlone.cs, LzmaAlone.java
-as public domain code.
+So you can change them as you want and use "SPECIAL EXCEPTION"
+for other unmodified files. For example, you can edit C\Types.h to solve some
+compatibility problems with your compiler.
-4) Proprietary license
-
-LZMA SDK also can be available under a proprietary license which
-can include:
-
-1) Right to modify code without subjecting modified code to the
-terms of the CPL or GNU LGPL
-2) Technical support for code
-
-To request such proprietary license or any additional consultations,
-send email message from that page:
-http://www.7-zip.org/support.html
-
+-----
You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software
@@ -85,92 +74,82 @@ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
You should have received a copy of the Common Public License
along with this library.
+You should have received a copy of the Common Development and Distribution
+License Version 1.0 along with this library.
+
LZMA SDK Contents
-----------------
LZMA SDK includes:
- - C++ source code of LZMA compressing and decompressing
- - ANSI-C compatible source code for LZMA decompressing
- - C# source code for LZMA compressing and decompressing
- - Java source code for LZMA compressing and decompressing
+ - ANSI-C/C++/C#/Java source code for LZMA compressing and decompressing
- Compiled file->file LZMA compressing/decompressing program for Windows system
-ANSI-C LZMA decompression code was ported from original C++ sources to C.
-Also it was simplified and optimized for code size.
-But it is fully compatible with LZMA from 7-Zip.
-
UNIX/Linux version
------------------
-To compile C++ version of file->file LZMA, go to directory
-C/7zip/Compress/LZMA_Alone
-and type "make" or "make clean all" to recompile all.
+To compile C++ version of file->file LZMA encoding, go to directory
+C++/7zip/Compress/LZMA_Alone
+and call make to recompile it:
+ make -f makefile.gcc clean all
In some UNIX/Linux versions you must compile LZMA with static libraries.
-To compile with static libraries, change string in makefile
-LIB = -lm
-to string
+To compile with static libraries, you can use
LIB = -lm -static
Files
---------------------
-C - C source code
-CPP - CPP source code
-CS - C# source code
-Java - Java source code
-lzma.txt - LZMA SDK description (this file)
+lzma.txt - LZMA SDK description (this file)
7zFormat.txt - 7z Format description
-7zC.txt - 7z ANSI-C Decoder description (this file)
+7zC.txt - 7z ANSI-C Decoder description
methods.txt - Compression method IDs for .7z
-LGPL.txt - GNU Lesser General Public License
-CPL.html - Common Public License
-lzma.exe - Compiled file->file LZMA encoder/decoder for Windows
-history.txt - history of the LZMA SDK
+lzma.exe - Compiled file->file LZMA encoder/decoder for Windows
+history.txt - history of the LZMA SDK
+LGPL.txt - GNU Lesser General Public License
+CPL.html - Common Public License
+CDDL.html - Common Development and Distribution License (CDDL)
Source code structure
---------------------
-C - C files
- Compress - files related to compression/decompression
- Lz - files related to LZ (Lempel-Ziv) compression algorithm
- Lzma - ANSI-C compatible LZMA decompressor
-
- LzmaDecode.h - interface for LZMA decoding on ANSI-C
- LzmaDecode.c - LZMA decoding on ANSI-C (new fastest version)
- LzmaDecodeSize.c - LZMA decoding on ANSI-C (old size-optimized version)
- LzmaTest.c - test application that decodes LZMA encoded file
- LzmaTypes.h - basic types for LZMA Decoder
- LzmaStateDecode.h - interface for LZMA decoding (State version)
- LzmaStateDecode.c - LZMA decoding on ANSI-C (State version)
- LzmaStateTest.c - test application (State version)
-
- Branch - Filters for x86, IA-64, ARM, ARM-Thumb, PowerPC and SPARC code
+C/ - C files
+ 7zCrc*.* - CRC code
+ Alloc.* - Memory allocation functions
+ Bra*.* - Filters for x86, IA-64, ARM, ARM-Thumb, PowerPC and SPARC code
+ LzFind.* - Match finder for LZ (LZMA) encoders
+ LzFindMt.* - Match finder for LZ (LZMA) encoders for multithreading encoding
+ LzHash.h - Additional file for LZ match finder
+ LzmaDec.* - LZMA decoding
+ LzmaEnc.* - LZMA encoding
+ LzmaLib.* - LZMA Library for DLL calling
+ Types.h - Basic types for another .c files
+ Threads.* - The code for multithreading.
+
+ LzmaLib - LZMA Library (.DLL for Windows)
+
+ LzmaUtil - LZMA Utility (file->file LZMA encoder/decoder).
Archive - files related to archiving
- 7z_C - 7z ANSI-C Decoder
-
+ 7z - 7z ANSI-C Decoder
-CPP -- CPP files
+CPP/ -- CPP files
Common - common files for C++ projects
Windows - common files for Windows related code
+
7zip - files related to 7-Zip Project
Common - common files for 7-Zip
Compress - files related to compression/decompression
- LZ - files related to LZ (Lempel-Ziv) compression algorithm
-
Copy - Copy coder
RangeCoder - Range Coder (special code of compression/decompression)
LZMA - LZMA compression/decompression on C++
LZMA_Alone - file->file LZMA compression/decompression
-
Branch - Filters for x86, IA-64, ARM, ARM-Thumb, PowerPC and SPARC code
Archive - files related to archiving
@@ -192,7 +171,7 @@ CPP -- CPP files
-CS - C# files
+CS/ - C# files
7zip
Common - some common files for 7-Zip
Compress - files related to compression/decompression
@@ -201,46 +180,40 @@ CS - C# files
LzmaAlone - file->file LZMA compression/decompression
RangeCoder - Range Coder (special code of compression/decompression)
-Java - Java files
+Java/ - Java files
SevenZip
Compression - files related to compression/decompression
LZ - files related to LZ (Lempel-Ziv) compression algorithm
LZMA - LZMA compression/decompression
RangeCoder - Range Coder (special code of compression/decompression)
-C/C++ source code of LZMA SDK is part of 7-Zip project.
-
-You can find ANSI-C LZMA decompressing code at folder
- C/7zip/Compress/Lzma
-7-Zip doesn't use that ANSI-C LZMA code and that code was developed
-specially for this SDK. And files from C/7zip/Compress/Lzma do not need
-files from other directories of SDK for compiling.
+C/C++ source code of LZMA SDK is part of 7-Zip project.
7-Zip source code can be downloaded from 7-Zip's SourceForge page:
http://sourceforge.net/projects/sevenzip/
+
LZMA features
-------------
- Variable dictionary size (up to 1 GB)
- - Estimated compressing speed: about 1 MB/s on 1 GHz CPU
+ - Estimated compressing speed: about 2 MB/s on 2 GHz CPU
- Estimated decompressing speed:
- - 8-12 MB/s on 1 GHz Intel Pentium 3 or AMD Athlon
- - 500-1000 KB/s on 100 MHz ARM, MIPS, PowerPC or other simple RISC
- - Small memory requirements for decompressing (8-32 KB + DictionarySize)
- - Small code size for decompressing: 2-8 KB (depending from
- speed optimizations)
+ - 20-30 MB/s on 2 GHz Core 2 or AMD Athlon 64
+ - 1-2 MB/s on 200 MHz ARM, MIPS, PowerPC or other simple RISC
+ - Small memory requirements for decompressing (16 KB + DictionarySize)
+ - Small code size for decompressing: 5-8 KB
LZMA decoder uses only integer operations and can be
implemented in any modern 32-bit CPU (or on 16-bit CPU with some conditions).
-Some critical operations that affect to speed of LZMA decompression:
+Some critical operations that affect the speed of LZMA decompression:
1) 32*16 bit integer multiply
2) Misspredicted branches (penalty mostly depends from pipeline length)
3) 32-bit shift and arithmetic operations
-Speed of LZMA decompressing mostly depends from CPU speed.
+The speed of LZMA decompressing mostly depends from CPU speed.
Memory speed has no big meaning. But if your CPU has small data cache,
overall weight of memory speed will slightly increase.
@@ -260,11 +233,11 @@ Usage: LZMA <e|d> inputFile outputFile [<switches>...]
b: Benchmark. There are two tests: compressing and decompressing
with LZMA method. Benchmark shows rating in MIPS (million
instructions per second). Rating value is calculated from
- measured speed and it is normalized with AMD Athlon 64 X2 CPU
- results. Also Benchmark checks possible hardware errors (RAM
+ measured speed and it is normalized with Intel's Core 2 results.
+ Also Benchmark checks possible hardware errors (RAM
errors in most cases). Benchmark uses these settings:
- (-a1, -d21, -fb32, -mfbt4). You can change only -d. Also you
- can change number of iterations. Example for 30 iterations:
+ (-a1, -d21, -fb32, -mfbt4). You can change only -d parameter.
+ Also you can change the number of iterations. Example for 30 iterations:
LZMA b 30
Default number of iterations is 10.
@@ -345,32 +318,29 @@ Compression ratio hints
Recommendations
---------------
-To increase compression ratio for LZMA compressing it's desirable
+To increase the compression ratio for LZMA compressing it's desirable
to have aligned data (if it's possible) and also it's desirable to locate
data in such order, where code is grouped in one place and data is
grouped in other place (it's better than such mixing: code, data, code,
data, ...).
-Using Filters
--------------
-You can increase compression ratio for some data types, using
+Filters
+-------
+You can increase the compression ratio for some data types, using
special filters before compressing. For example, it's possible to
-increase compression ratio on 5-10% for code for those CPU ISAs:
+increase the compression ratio on 5-10% for code for those CPU ISAs:
x86, IA-64, ARM, ARM-Thumb, PowerPC, SPARC.
-You can find C/C++ source code of such filters in folder "7zip/Compress/Branch"
+You can find C source code of such filters in C/Bra*.* files
-You can check compression ratio gain of these filters with such
+You can check the compression ratio gain of these filters with such
7-Zip commands (example for ARM code):
No filter:
7z a a1.7z a.bin -m0=lzma
With filter for little-endian ARM code:
- 7z a a2.7z a.bin -m0=bc_arm -m1=lzma
-
-With filter for big-endian ARM code (using additional Swap4 filter):
- 7z a a3.7z a.bin -m0=swap4 -m1=bc_arm -m2=lzma
+ 7z a a2.7z a.bin -m0=arm -m1=lzma
It works in such manner:
Compressing = Filter_encoding + LZMA_encoding
@@ -383,8 +353,7 @@ since compression ratio with filtering is higher.
These filters convert CALL (calling procedure) instructions
from relative offsets to absolute addresses, so such data becomes more
-compressible. Source code of these CALL filters is pretty simple
-(about 20 lines of C++), so you can convert it from C++ version yourself.
+compressible.
For some ISAs (for example, for MIPS) it's impossible to get gain from such filter.
@@ -392,7 +361,7 @@ For some ISAs (for example, for MIPS) it's impossible to get gain from such filt
LZMA compressed file format
---------------------------
Offset Size Description
- 0 1 Special LZMA properties for compressed data
+ 0 1 Special LZMA properties (lc,lp, pb in encoded form)
1 4 Dictionary size (little endian)
5 8 Uncompressed size (little endian). -1 means unknown size
13 Compressed data
@@ -401,263 +370,285 @@ Offset Size Description
ANSI-C LZMA Decoder
~~~~~~~~~~~~~~~~~~~
-To compile ANSI-C LZMA Decoder you can use one of the following files sets:
-1) LzmaDecode.h + LzmaDecode.c + LzmaTest.c (fastest version)
-2) LzmaDecode.h + LzmaDecodeSize.c + LzmaTest.c (old size-optimized version)
-3) LzmaStateDecode.h + LzmaStateDecode.c + LzmaStateTest.c (zlib-like interface)
+Please note that interfaces for ANSI-C code were changed in LZMA SDK 4.58.
+If you want to use old interfaces you can download previous version of LZMA SDK
+from sourceforge.net site.
+
+To use ANSI-C LZMA Decoder you need the following files:
+1) LzmaDec.h + LzmaDec.c + Types.h
+LzmaUtil/LzmaUtil.c is example application that uses these files.
Memory requirements for LZMA decoding
-------------------------------------
-LZMA decoder doesn't allocate memory itself, so you must
-allocate memory and send it to LZMA.
-
Stack usage of LZMA decoding function for local variables is not
-larger than 200 bytes.
+larger than 200-400 bytes.
+
+LZMA Decoder uses dictionary buffer and internal state structure.
+Internal state structure consumes
+ state_size = (4 + (1.5 << (lc + lp))) KB
+by default (lc=3, lp=0), state_size = 16 KB.
+
How To decompress data
----------------------
-LZMA Decoder (ANSI-C version) now supports 5 interfaces:
+LZMA Decoder (ANSI-C version) now supports 2 interfaces:
1) Single-call Decompressing
-2) Single-call Decompressing with input stream callback
-3) Multi-call Decompressing with output buffer
-4) Multi-call Decompressing with input callback and output buffer
-5) Multi-call State Decompressing (zlib-like interface)
+2) Multi-call State Decompressing (zlib-like interface)
+
+You must use external allocator:
+Example:
+void *SzAlloc(void *p, size_t size) { p = p; return malloc(size); }
+void SzFree(void *p, void *address) { p = p; free(address); }
+ISzAlloc alloc = { SzAlloc, SzFree };
+
+You can use p = p; operator to disable compiler warnings.
-Variant-5 is similar to Variant-4, but Variant-5 doesn't use callback functions.
-Decompressing steps
--------------------
+Single-call Decompressing
+-------------------------
+When to use: RAM->RAM decompressing
+Compile files: LzmaDec.h + LzmaDec.c + Types.h
+Compile defines: no defines
+Memory Requirements:
+ - Input buffer: compressed size
+ - Output buffer: uncompressed size
+ - LZMA Internal Structures: state_size (16 KB for default settings)
-1) read LZMA properties (5 bytes):
- unsigned char properties[LZMA_PROPERTIES_SIZE];
+Interface:
+ int LzmaDecode(Byte *dest, SizeT *destLen, const Byte *src, SizeT *srcLen,
+ const Byte *propData, unsigned propSize, ELzmaFinishMode finishMode,
+ ELzmaStatus *status, ISzAlloc *alloc);
+ In:
+ dest - output data
+ destLen - output data size
+ src - input data
+ srcLen - input data size
+ propData - LZMA properties (5 bytes)
+ propSize - size of propData buffer (5 bytes)
+ finishMode - It has meaning only if the decoding reaches output limit (*destLen).
+ LZMA_FINISH_ANY - Decode just destLen bytes.
+ LZMA_FINISH_END - Stream must be finished after (*destLen).
+ You can use LZMA_FINISH_END, when you know that
+ current output buffer covers last bytes of stream.
+ alloc - Memory allocator.
+
+ Out:
+ destLen - processed output size
+ srcLen - processed input size
+
+ Output:
+ SZ_OK
+ status:
+ LZMA_STATUS_FINISHED_WITH_MARK
+ LZMA_STATUS_NOT_FINISHED
+ LZMA_STATUS_MAYBE_FINISHED_WITHOUT_MARK
+ SZ_ERROR_DATA - Data error
+ SZ_ERROR_MEM - Memory allocation error
+ SZ_ERROR_UNSUPPORTED - Unsupported properties
+ SZ_ERROR_INPUT_EOF - It needs more bytes in input buffer (src).
+
+ If LZMA decoder sees end_marker before reaching output limit, it returns OK result,
+ and output value of destLen will be less than output buffer size limit.
+
+ You can use multiple checks to test data integrity after full decompression:
+ 1) Check Result and "status" variable.
+ 2) Check that output(destLen) = uncompressedSize, if you know real uncompressedSize.
+ 3) Check that output(srcLen) = compressedSize, if you know real compressedSize.
+ You must use correct finish mode in that case. */
+
+
+Multi-call State Decompressing (zlib-like interface)
+----------------------------------------------------
-2) read uncompressed size (8 bytes, little-endian)
+When to use: file->file decompressing
+Compile files: LzmaDec.h + LzmaDec.c + Types.h
-3) Decode properties:
+Memory Requirements:
+ - Buffer for input stream: any size (for example, 16 KB)
+ - Buffer for output stream: any size (for example, 16 KB)
+ - LZMA Internal Structures: state_size (16 KB for default settings)
+ - LZMA dictionary (dictionary size is encoded in LZMA properties header)
- CLzmaDecoderState state; /* it's 24-140 bytes structure, if int is 32-bit */
+1) read LZMA properties (5 bytes) and uncompressed size (8 bytes, little-endian) to header:
+ unsigned char header[LZMA_PROPERTIES_SIZE + 8];
+ ReadFile(inFile, header, sizeof(header)
- if (LzmaDecodeProperties(&state.Properties, properties, LZMA_PROPERTIES_SIZE) != LZMA_RESULT_OK)
- return PrintError(rs, "Incorrect stream properties");
+2) Allocate CLzmaDec structures (state + dictionary) using LZMA properties
-4) Allocate memory block for internal Structures:
+ CLzmaDec state;
+ LzmaDec_Constr(&state);
+ res = LzmaDec_Allocate(&state, header, LZMA_PROPS_SIZE, &g_Alloc);
+ if (res != SZ_OK)
+ return res;
- state.Probs = (CProb *)malloc(LzmaGetNumProbs(&state.Properties) * sizeof(CProb));
- if (state.Probs == 0)
- return PrintError(rs, kCantAllocateMessage);
+3) Init LzmaDec structure before any new LZMA stream. And call LzmaDec_DecodeToBuf in loop
- LZMA decoder uses array of CProb variables as internal structure.
- By default, CProb is unsigned_short. But you can define _LZMA_PROB32 to make
- it unsigned_int. It can increase speed on some 32-bit CPUs, but memory
- usage will be doubled in that case.
+ LzmaDec_Init(&state);
+ for (;;)
+ {
+ ...
+ int res = LzmaDec_DecodeToBuf(CLzmaDec *p, Byte *dest, SizeT *destLen,
+ const Byte *src, SizeT *srcLen, ELzmaFinishMode finishMode);
+ ...
+ }
-5) Main Decompressing
+4) Free all allocated structures
+ LzmaDec_Free(&state, &g_Alloc);
-You must use one of the following interfaces:
+For full code example, look at C/LzmaUtil/LzmaUtil.c code.
-5.1 Single-call Decompressing
------------------------------
-When to use: RAM->RAM decompressing
-Compile files: LzmaDecode.h, LzmaDecode.c
-Compile defines: no defines
-Memory Requirements:
- - Input buffer: compressed size
- - Output buffer: uncompressed size
- - LZMA Internal Structures (~16 KB for default settings)
-Interface:
- int res = LzmaDecode(&state,
- inStream, compressedSize, &inProcessed,
- outStream, outSize, &outProcessed);
+How To compress data
+--------------------
+Compile files: LzmaEnc.h + LzmaEnc.c + Types.h +
+LzFind.c + LzFind.h + LzFindMt.c + LzFindMt.h + LzHash.h
-5.2 Single-call Decompressing with input stream callback
---------------------------------------------------------
-When to use: File->RAM or Flash->RAM decompressing.
-Compile files: LzmaDecode.h, LzmaDecode.c
-Compile defines: _LZMA_IN_CB
Memory Requirements:
- - Buffer for input stream: any size (for example, 16 KB)
- - Output buffer: uncompressed size
- - LZMA Internal Structures (~16 KB for default settings)
+ - (dictSize * 11.5 + 6 MB) + state_size
-Interface:
- typedef struct _CBuffer
- {
- ILzmaInCallback InCallback;
- FILE *File;
- unsigned char Buffer[kInBufferSize];
- } CBuffer;
+Lzma Encoder can use two memory allocators:
+1) alloc - for small arrays.
+2) allocBig - for big arrays.
- int LzmaReadCompressed(void *object, const unsigned char **buffer, SizeT *size)
- {
- CBuffer *bo = (CBuffer *)object;
- *buffer = bo->Buffer;
- *size = MyReadFile(bo->File, bo->Buffer, kInBufferSize);
- return LZMA_RESULT_OK;
- }
+For example, you can use Large RAM Pages (2 MB) in allocBig allocator for
+better compression speed. Note that Windows has bad implementation for
+Large RAM Pages.
+It's OK to use same allocator for alloc and allocBig.
- CBuffer g_InBuffer;
- g_InBuffer.File = inFile;
- g_InBuffer.InCallback.Read = LzmaReadCompressed;
- int res = LzmaDecode(&state,
- &g_InBuffer.InCallback,
- outStream, outSize, &outProcessed);
+Single-call Compression with callbacks
+--------------------------------------
+Check C/LzmaUtil/LzmaUtil.c as example,
-5.3 Multi-call decompressing with output buffer
------------------------------------------------
-When to use: RAM->File decompressing
-Compile files: LzmaDecode.h, LzmaDecode.c
-Compile defines: _LZMA_OUT_READ
-Memory Requirements:
- - Input buffer: compressed size
- - Buffer for output stream: any size (for example, 16 KB)
- - LZMA Internal Structures (~16 KB for default settings)
- - LZMA dictionary (dictionary size is encoded in stream properties)
-
-Interface:
+When to use: file->file decompressing
- state.Dictionary = (unsigned char *)malloc(state.Properties.DictionarySize);
+1) you must implement callback structures for interfaces:
+ISeqInStream
+ISeqOutStream
+ICompressProgress
+ISzAlloc
- LzmaDecoderInit(&state);
- do
- {
- LzmaDecode(&state,
- inBuffer, inAvail, &inProcessed,
- g_OutBuffer, outAvail, &outProcessed);
- inAvail -= inProcessed;
- inBuffer += inProcessed;
- }
- while you need more bytes
+static void *SzAlloc(void *p, size_t size) { p = p; return MyAlloc(size); }
+static void SzFree(void *p, void *address) { p = p; MyFree(address); }
+static ISzAlloc g_Alloc = { SzAlloc, SzFree };
- see LzmaTest.c for more details.
+ CFileSeqInStream inStream;
+ CFileSeqOutStream outStream;
+ inStream.funcTable.Read = MyRead;
+ inStream.file = inFile;
+ outStream.funcTable.Write = MyWrite;
+ outStream.file = outFile;
-5.4 Multi-call decompressing with input callback and output buffer
-------------------------------------------------------------------
-When to use: File->File decompressing
-Compile files: LzmaDecode.h, LzmaDecode.c
-Compile defines: _LZMA_IN_CB, _LZMA_OUT_READ
-Memory Requirements:
- - Buffer for input stream: any size (for example, 16 KB)
- - Buffer for output stream: any size (for example, 16 KB)
- - LZMA Internal Structures (~16 KB for default settings)
- - LZMA dictionary (dictionary size is encoded in stream properties)
-
-Interface:
- state.Dictionary = (unsigned char *)malloc(state.Properties.DictionarySize);
-
- LzmaDecoderInit(&state);
- do
- {
- LzmaDecode(&state,
- &bo.InCallback,
- g_OutBuffer, outAvail, &outProcessed);
- }
- while you need more bytes
+2) Create CLzmaEncHandle object;
- see LzmaTest.c for more details:
+ CLzmaEncHandle enc;
+ enc = LzmaEnc_Create(&g_Alloc);
+ if (enc == 0)
+ return SZ_ERROR_MEM;
-5.5 Multi-call State Decompressing (zlib-like interface)
-------------------------------------------------------------------
-When to use: file->file decompressing
-Compile files: LzmaStateDecode.h, LzmaStateDecode.c
-Compile defines:
-Memory Requirements:
- - Buffer for input stream: any size (for example, 16 KB)
- - Buffer for output stream: any size (for example, 16 KB)
- - LZMA Internal Structures (~16 KB for default settings)
- - LZMA dictionary (dictionary size is encoded in stream properties)
-
-Interface:
- state.Dictionary = (unsigned char *)malloc(state.Properties.DictionarySize);
+3) initialize CLzmaEncProps properties;
-
- LzmaDecoderInit(&state);
- do
- {
- res = LzmaDecode(&state,
- inBuffer, inAvail, &inProcessed,
- g_OutBuffer, outAvail, &outProcessed,
- finishDecoding);
- inAvail -= inProcessed;
- inBuffer += inProcessed;
- }
- while you need more bytes
+ LzmaEncProps_Init(&props);
- see LzmaStateTest.c for more details:
+ Then you can change some properties in that structure.
+4) Send LZMA properties to LZMA Encoder
-6) Free all allocated blocks
+ res = LzmaEnc_SetProps(enc, &props);
+5) Write encoded properties to header
-Note
-----
-LzmaDecodeSize.c is size-optimized version of LzmaDecode.c.
-But compiled code of LzmaDecodeSize.c can be larger than
-compiled code of LzmaDecode.c. So it's better to use
-LzmaDecode.c in most cases.
+ Byte header[LZMA_PROPS_SIZE + 8];
+ size_t headerSize = LZMA_PROPS_SIZE;
+ UInt64 fileSize;
+ int i;
+ res = LzmaEnc_WriteProperties(enc, header, &headerSize);
+ fileSize = MyGetFileLength(inFile);
+ for (i = 0; i < 8; i++)
+ header[headerSize++] = (Byte)(fileSize >> (8 * i));
+ MyWriteFileAndCheck(outFile, header, headerSize)
-EXIT codes
------------
+6) Call encoding function:
+ res = LzmaEnc_Encode(enc, &outStream.funcTable, &inStream.funcTable,
+ NULL, &g_Alloc, &g_Alloc);
-LZMA decoder can return one of the following codes:
+7) Destroy LZMA Encoder Object
+ LzmaEnc_Destroy(enc, &g_Alloc, &g_Alloc);
-#define LZMA_RESULT_OK 0
-#define LZMA_RESULT_DATA_ERROR 1
-If you use callback function for input data and you return some
-error code, LZMA Decoder also returns that code.
+If callback function return some error code, LzmaEnc_Encode also returns that code.
+Single-call RAM->RAM Compression
+--------------------------------
-LZMA Defines
-------------
+Single-call RAM->RAM Compression is similar to Compression with callbacks,
+but you provide pointers to buffers instead of pointers to stream callbacks:
-_LZMA_IN_CB - Use callback for input data
+HRes LzmaEncode(Byte *dest, SizeT *destLen, const Byte *src, SizeT srcLen,
+ CLzmaEncProps *props, Byte *propsEncoded, SizeT *propsSize, int writeEndMark,
+ ICompressProgress *progress, ISzAlloc *alloc, ISzAlloc *allocBig);
-_LZMA_OUT_READ - Use read function for output data
+Return code:
+ SZ_OK - OK
+ SZ_ERROR_MEM - Memory allocation error
+ SZ_ERROR_PARAM - Incorrect paramater
+ SZ_ERROR_OUTPUT_EOF - output buffer overflow
+ SZ_ERROR_THREAD - errors in multithreading functions (only for Mt version)
-_LZMA_LOC_OPT - Enable local speed optimizations inside code.
- _LZMA_LOC_OPT is only for LzmaDecodeSize.c (size-optimized version).
- _LZMA_LOC_OPT doesn't affect LzmaDecode.c (speed-optimized version)
- and LzmaStateDecode.c
-_LZMA_PROB32 - It can increase speed on some 32-bit CPUs,
- but memory usage will be doubled in that case
-_LZMA_UINT32_IS_ULONG - Define it if int is 16-bit on your compiler
- and long is 32-bit.
+LZMA Defines
+------------
+
+_LZMA_SIZE_OPT - Enable some optimizations in LZMA Decoder to get smaller executable code.
-_LZMA_SYSTEM_SIZE_T - Define it if you want to use system's size_t.
- You can use it to enable 64-bit sizes supporting
+_LZMA_PROB32 - It can increase the speed on some 32-bit CPUs, but memory usage for
+ some structures will be doubled in that case.
+_LZMA_UINT32_IS_ULONG - Define it if int is 16-bit on your compiler and long is 32-bit.
+
+_LZMA_NO_SYSTEM_SIZE_T - Define it if you don't want to use size_t type.
C++ LZMA Encoder/Decoder
~~~~~~~~~~~~~~~~~~~~~~~~
C++ LZMA code use COM-like interfaces. So if you want to use it,
you can study basics of COM/OLE.
+C++ LZMA code is just wrapper over ANSI-C code.
-By default, LZMA Encoder contains all Match Finders.
-But for compressing it's enough to have just one of them.
-So for reducing size of compressing code you can define:
- #define COMPRESS_MF_BT
- #define COMPRESS_MF_BT4
-and it will use only bt4 match finder.
+C++ Notes
+~~~~~~~~~~~~~~~~~~~~~~~~
+If you use some C++ code folders in 7-Zip (for example, C++ code for .7z handling),
+you must check that you correctly work with "new" operator.
+7-Zip can be compiled with MSVC 6.0 that doesn't throw "exception" from "new" operator.
+So 7-Zip uses "CPP\Common\NewHandler.cpp" that redefines "new" operator:
+operator new(size_t size)
+{
+ void *p = ::malloc(size);
+ if (p == 0)
+ throw CNewException();
+ return p;
+}
+If you use MSCV that throws exception for "new" operator, you can compile without
+"NewHandler.cpp". So standard exception will be used. Actually some code of
+7-Zip catches any exception in internal code and converts it to HRESULT code.
+So you don't need to catch CNewException, if you call COM interfaces of 7-Zip.
---
http://www.7-zip.org
+http://www.7-zip.org/sdk.html
http://www.7-zip.org/support.html
diff --git a/DOC/readme.txt b/DOC/readme.txt
index 5d897821..82061804 100755
--- a/DOC/readme.txt
+++ b/DOC/readme.txt
@@ -1,4 +1,4 @@
-7-Zip 4.57 Sources
+7-Zip 4.58 Sources
------------------
7-Zip is a file archiver for Windows 95/98/ME/NT/2000/2003/XP/Vista.
@@ -63,6 +63,10 @@ Tools / Options / Directories
To compile 7-Zip for AMD64 and IA64 you need:
Windows Server 2003 SP1 Platform SDK from microsoft.com
+Also you need Microsoft Macro Assembler:
+ - ml.exe for x86
+ - ml64.exe for AMD64
+You can use ml.exe from Windows SDK for Windows Vista or some other version.
Compiling under Unix/Linux