4.44 beta

This commit is contained in:
Igor Pavlov
2007-01-20 00:00:00 +00:00
committed by Kornel Lesiński
parent 804edc5756
commit d9666cf046
1331 changed files with 10535 additions and 13791 deletions

View File

@@ -0,0 +1,449 @@
# Microsoft Developer Studio Project File - Name="AloneLZMA" - Package Owner=<4>
# Microsoft Developer Studio Generated Build File, Format Version 6.00
# ** DO NOT EDIT **
# TARGTYPE "Win32 (x86) Console Application" 0x0103
CFG=AloneLZMA - 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 "AloneLZMA.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 "AloneLZMA.mak" CFG="AloneLZMA - Win32 DebugU"
!MESSAGE
!MESSAGE Possible choices for configuration are:
!MESSAGE
!MESSAGE "AloneLZMA - Win32 Release" (based on "Win32 (x86) Console Application")
!MESSAGE "AloneLZMA - Win32 Debug" (based on "Win32 (x86) Console Application")
!MESSAGE "AloneLZMA - Win32 ReleaseU" (based on "Win32 (x86) Console Application")
!MESSAGE "AloneLZMA - 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)" == "AloneLZMA - 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 /GX /O2 /I "..\..\..\\" /D "NDEBUG" /D "_MBCS" /D "WIN32" /D "_CONSOLE" /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\lzma.exe" /opt:NOWIN98
# SUBTRACT LINK32 /pdb:none
!ELSEIF "$(CFG)" == "AloneLZMA - 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 /W3 /Gm /GX /ZI /Od /I "..\..\..\\" /D "_DEBUG" /D "_MBCS" /D "WIN32" /D "_CONSOLE" /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\lzma.exe" /pdbtype:sept
!ELSEIF "$(CFG)" == "AloneLZMA - 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 /MD /W3 /GX /O2 /I "..\..\..\\" /D "NDEBUG" /D "UNICODE" /D "_UNICODE" /D "WIN32" /D "_CONSOLE" /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\7za2.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\lzma.exe" /opt:NOWIN98
# SUBTRACT LINK32 /pdb:none
!ELSEIF "$(CFG)" == "AloneLZMA - 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 /W3 /Gm /GX /ZI /Od /I "..\..\..\\" /D "_DEBUG" /D "_UNICODE" /D "UNICODE" /D "WIN32" /D "_CONSOLE" /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\7za2.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\lzma.exe" /pdbtype:sept
!ENDIF
# Begin Target
# Name "AloneLZMA - Win32 Release"
# Name "AloneLZMA - Win32 Debug"
# Name "AloneLZMA - Win32 ReleaseU"
# Name "AloneLZMA - Win32 DebugU"
# Begin Group "Spec"
# PROP Default_Filter ""
# 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 "Compress"
# PROP Default_Filter ""
# Begin Group "LZMA"
# PROP Default_Filter ""
# Begin Source File
SOURCE=..\LZMA\LZMA.h
# End Source File
# Begin Source File
SOURCE=..\LZMA\LZMADecoder.cpp
# End Source File
# Begin Source File
SOURCE=..\LZMA\LZMADecoder.h
# End Source File
# Begin Source File
SOURCE=..\LZMA\LZMAEncoder.cpp
# End Source File
# Begin Source File
SOURCE=..\LZMA\LZMAEncoder.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 "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
# End Group
# Begin Group "Windows"
# PROP Default_Filter ""
# Begin Source File
SOURCE=..\..\..\Windows\FileIO.cpp
# End Source File
# Begin Source File
SOURCE=..\..\..\Windows\FileIO.h
# End Source File
# End Group
# Begin Group "Common"
# PROP Default_Filter ""
# Begin Source File
SOURCE=..\..\..\Common\Alloc.cpp
# End Source File
# Begin Source File
SOURCE=..\..\..\Common\Alloc.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\CRC.cpp
# End Source File
# Begin Source File
SOURCE=..\..\..\Common\CRC.h
# End Source File
# Begin Source File
SOURCE=..\..\..\Common\Defs.h
# End Source File
# Begin Source File
SOURCE=..\..\..\Windows\Defs.h
# End Source File
# Begin Source File
SOURCE=..\..\..\Common\MyCom.h
# 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\String.cpp
# End Source File
# Begin Source File
SOURCE=..\..\..\Common\String.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\Vector.cpp
# End Source File
# Begin Source File
SOURCE=..\..\..\Common\Vector.h
# End Source File
# End Group
# Begin Group "7zip Common"
# PROP Default_Filter ""
# 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\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 "C"
# PROP Default_Filter ""
# Begin Group "C-Lz"
# PROP Default_Filter ""
# 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
# End Group
# Begin Group "LZMA_C"
# PROP Default_Filter ""
# Begin Source File
SOURCE=..\..\..\..\C\Compress\Lzma\LzmaDecode.c
# SUBTRACT CPP /YX /Yc /Yu
# End Source File
# Begin Source File
SOURCE=..\..\..\..\C\Compress\Lzma\LzmaDecode.h
# End Source File
# Begin Source File
SOURCE=..\..\..\..\C\Compress\Lzma\LzmaTypes.h
# End Source File
# End Group
# Begin Group "Branch"
# PROP Default_Filter ""
# 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
# End Group
# Begin Source File
SOURCE=..\..\ICoder.h
# End Source File
# Begin Source File
SOURCE=.\LzmaAlone.cpp
# End Source File
# Begin Source File
SOURCE=.\LzmaBench.cpp
# End Source File
# Begin Source File
SOURCE=.\LzmaBench.h
# End Source File
# Begin Source File
SOURCE=.\LzmaRam.cpp
# End Source File
# Begin Source File
SOURCE=.\LzmaRam.h
# End Source File
# Begin Source File
SOURCE=.\LzmaRamDecode.c
# SUBTRACT CPP /YX /Yc /Yu
# End Source File
# Begin Source File
SOURCE=.\LzmaRamDecode.h
# End Source File
# End Target
# End Project

View File

@@ -0,0 +1,29 @@
Microsoft Developer Studio Workspace File, Format Version 6.00
# WARNING: DO NOT EDIT OR DELETE THIS WORKSPACE FILE!
###############################################################################
Project: "AloneLZMA"=.\AloneLZMA.dsp - Package Owner=<4>
Package=<5>
{{{
}}}
Package=<4>
{{{
}}}
###############################################################################
Global:
Package=<5>
{{{
}}}
Package=<3>
{{{
}}}
###############################################################################

View File

@@ -0,0 +1,526 @@
// LzmaAlone.cpp
#include "StdAfx.h"
#include "../../../Common/MyWindows.h"
#include "../../../Common/MyInitGuid.h"
#include <stdio.h>
#if defined(_WIN32) || defined(OS2) || defined(MSDOS)
#include <fcntl.h>
#include <io.h>
#define MY_SET_BINARY_MODE(file) _setmode(_fileno(file), O_BINARY)
#else
#define MY_SET_BINARY_MODE(file)
#endif
#include "../../../Common/CommandLineParser.h"
#include "../../../Common/StringConvert.h"
#include "../../../Common/StringToInt.h"
#include "../../Common/FileStreams.h"
#include "../../Common/StreamUtils.h"
#include "../LZMA/LZMADecoder.h"
#include "../LZMA/LZMAEncoder.h"
#include "LzmaBench.h"
#include "LzmaRam.h"
extern "C"
{
#include "LzmaRamDecode.h"
}
using namespace NCommandLineParser;
#ifdef _WIN32
bool g_IsNT = false;
static inline bool IsItWindowsNT()
{
OSVERSIONINFO versionInfo;
versionInfo.dwOSVersionInfoSize = sizeof(versionInfo);
if (!::GetVersionEx(&versionInfo))
return false;
return (versionInfo.dwPlatformId == VER_PLATFORM_WIN32_NT);
}
#endif
static const char *kCantAllocate = "Can not allocate memory";
static const char *kReadError = "Read error";
static const char *kWriteError = "Write error";
namespace NKey {
enum Enum
{
kHelp1 = 0,
kHelp2,
kMode,
kDictionary,
kFastBytes,
kMatchFinderCycles,
kLitContext,
kLitPos,
kPosBits,
kMatchFinder,
kEOS,
kStdIn,
kStdOut,
kFilter86
};
}
static const CSwitchForm kSwitchForms[] =
{
{ L"?", NSwitchType::kSimple, false },
{ L"H", NSwitchType::kSimple, false },
{ L"A", NSwitchType::kUnLimitedPostString, false, 1 },
{ L"D", NSwitchType::kUnLimitedPostString, false, 1 },
{ L"FB", NSwitchType::kUnLimitedPostString, false, 1 },
{ L"MC", NSwitchType::kUnLimitedPostString, false, 1 },
{ L"LC", NSwitchType::kUnLimitedPostString, false, 1 },
{ L"LP", NSwitchType::kUnLimitedPostString, false, 1 },
{ L"PB", NSwitchType::kUnLimitedPostString, false, 1 },
{ L"MF", NSwitchType::kUnLimitedPostString, false, 1 },
{ L"EOS", NSwitchType::kSimple, false },
{ L"SI", NSwitchType::kSimple, false },
{ L"SO", NSwitchType::kSimple, false },
{ L"F86", NSwitchType::kSimple, false }
};
static const int kNumSwitches = sizeof(kSwitchForms) / sizeof(kSwitchForms[0]);
static void PrintHelp()
{
fprintf(stderr, "\nUsage: LZMA <e|d> inputFile outputFile [<switches>...]\n"
" e: encode file\n"
" d: decode file\n"
" 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"
" -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"
" -lp{N}: set number of literal pos bits - [0, 4], default: 0\n"
" -pb{N}: set number of pos bits - [0, 4], default: 2\n"
" -mf{MF_ID}: set Match Finder: [bt2, bt3, bt4, hc4], default: bt4\n"
" -eos: write End Of Stream marker\n"
" -si: read data from stdin\n"
" -so: write data to stdout\n"
);
}
static void PrintHelpAndExit(const char *s)
{
fprintf(stderr, "\nError: %s\n\n", s);
PrintHelp();
throw -1;
}
static void IncorrectCommand()
{
PrintHelpAndExit("Incorrect command");
}
static void WriteArgumentsToStringList(int numArguments, const char *arguments[],
UStringVector &strings)
{
for(int i = 1; i < numArguments; i++)
strings.Add(MultiByteToUnicodeString(arguments[i]));
}
static bool GetNumber(const wchar_t *s, UInt32 &value)
{
value = 0;
if (MyStringLen(s) == 0)
return false;
const wchar_t *end;
UInt64 res = ConvertStringToUInt64(s, &end);
if (*end != L'\0')
return false;
if (res > 0xFFFFFFFF)
return false;
value = UInt32(res);
return true;
}
int main2(int n, const char *args[])
{
#ifdef _WIN32
g_IsNT = IsItWindowsNT();
#endif
fprintf(stderr, "\nLZMA 4.44 Copyright (c) 1999-2006 Igor Pavlov 2006-12-26\n");
if (n == 1)
{
PrintHelp();
return 0;
}
bool unsupportedTypes = (sizeof(Byte) != 1 || sizeof(UInt32) < 4 || sizeof(UInt64) < 4);
if (unsupportedTypes)
{
fprintf(stderr, "Unsupported base types. Edit Common/Types.h and recompile");
return 1;
}
UStringVector commandStrings;
WriteArgumentsToStringList(n, args, commandStrings);
CParser parser(kNumSwitches);
try
{
parser.ParseStrings(kSwitchForms, commandStrings);
}
catch(...)
{
IncorrectCommand();
}
if(parser[NKey::kHelp1].ThereIs || parser[NKey::kHelp2].ThereIs)
{
PrintHelp();
return 0;
}
const UStringVector &nonSwitchStrings = parser.NonSwitchStrings;
int paramIndex = 0;
if (paramIndex >= nonSwitchStrings.Size())
IncorrectCommand();
const UString &command = nonSwitchStrings[paramIndex++];
bool dictionaryIsDefined = false;
UInt32 dictionary = 1 << 21;
if(parser[NKey::kDictionary].ThereIs)
{
UInt32 dicLog;
if (!GetNumber(parser[NKey::kDictionary].PostStrings[0], dicLog))
IncorrectCommand();
dictionary = 1 << dicLog;
dictionaryIsDefined = true;
}
UString mf = L"BT4";
if (parser[NKey::kMatchFinder].ThereIs)
mf = parser[NKey::kMatchFinder].PostStrings[0];
if (command.CompareNoCase(L"b") == 0)
{
const UInt32 kNumDefaultItereations = 10;
UInt32 numIterations = kNumDefaultItereations;
{
if (paramIndex < nonSwitchStrings.Size())
if (!GetNumber(nonSwitchStrings[paramIndex++], numIterations))
numIterations = kNumDefaultItereations;
}
return LzmaBenchmark(stderr, numIterations, dictionary);
}
bool encodeMode = false;
if (command.CompareNoCase(L"e") == 0)
encodeMode = true;
else if (command.CompareNoCase(L"d") == 0)
encodeMode = false;
else
IncorrectCommand();
bool stdInMode = parser[NKey::kStdIn].ThereIs;
bool stdOutMode = parser[NKey::kStdOut].ThereIs;
CMyComPtr<ISequentialInStream> inStream;
CInFileStream *inStreamSpec = 0;
if (stdInMode)
{
inStream = new CStdInFileStream;
MY_SET_BINARY_MODE(stdin);
}
else
{
if (paramIndex >= nonSwitchStrings.Size())
IncorrectCommand();
const UString &inputName = nonSwitchStrings[paramIndex++];
inStreamSpec = new CInFileStream;
inStream = inStreamSpec;
if (!inStreamSpec->Open(GetSystemString(inputName)))
{
fprintf(stderr, "\nError: can not open input file %s\n",
(const char *)GetOemString(inputName));
return 1;
}
}
CMyComPtr<ISequentialOutStream> outStream;
if (stdOutMode)
{
outStream = new CStdOutFileStream;
MY_SET_BINARY_MODE(stdout);
}
else
{
if (paramIndex >= nonSwitchStrings.Size())
IncorrectCommand();
const UString &outputName = nonSwitchStrings[paramIndex++];
COutFileStream *outStreamSpec = new COutFileStream;
outStream = outStreamSpec;
if (!outStreamSpec->Create(GetSystemString(outputName), true))
{
fprintf(stderr, "\nError: can not open output file %s\n",
(const char *)GetOemString(outputName));
return 1;
}
}
if (parser[NKey::kFilter86].ThereIs)
{
// -f86 switch is for x86 filtered mode: BCJ + LZMA.
if (parser[NKey::kEOS].ThereIs || stdInMode)
throw "Can not use stdin in this mode";
UInt64 fileSize;
inStreamSpec->File.GetLength(fileSize);
if (fileSize > 0xF0000000)
throw "File is too big";
UInt32 inSize = (UInt32)fileSize;
Byte *inBuffer = 0;
if (inSize != 0)
{
inBuffer = (Byte *)MyAlloc((size_t)inSize);
if (inBuffer == 0)
throw kCantAllocate;
}
UInt32 processedSize;
if (ReadStream(inStream, inBuffer, (UInt32)inSize, &processedSize) != S_OK)
throw "Can not read";
if ((UInt32)inSize != processedSize)
throw "Read size error";
Byte *outBuffer = 0;
size_t outSizeProcessed;
if (encodeMode)
{
// we allocate 105% of original size for output buffer
size_t outSize = (size_t)fileSize / 20 * 21 + (1 << 16);
if (outSize != 0)
{
outBuffer = (Byte *)MyAlloc((size_t)outSize);
if (outBuffer == 0)
throw kCantAllocate;
}
if (!dictionaryIsDefined)
dictionary = 1 << 23;
int res = LzmaRamEncode(inBuffer, inSize, outBuffer, outSize, &outSizeProcessed,
dictionary, SZ_FILTER_AUTO);
if (res != 0)
{
fprintf(stderr, "\nEncoder error = %d\n", (int)res);
return 1;
}
}
else
{
size_t outSize;
if (LzmaRamGetUncompressedSize(inBuffer, inSize, &outSize) != 0)
throw "data error";
if (outSize != 0)
{
outBuffer = (Byte *)MyAlloc(outSize);
if (outBuffer == 0)
throw kCantAllocate;
}
int res = LzmaRamDecompress(inBuffer, inSize, outBuffer, outSize, &outSizeProcessed, malloc, free);
if (res != 0)
throw "LzmaDecoder error";
}
if (WriteStream(outStream, outBuffer, (UInt32)outSizeProcessed, &processedSize) != S_OK)
throw kWriteError;
MyFree(outBuffer);
MyFree(inBuffer);
return 0;
}
UInt64 fileSize;
if (encodeMode)
{
NCompress::NLZMA::CEncoder *encoderSpec =
new NCompress::NLZMA::CEncoder;
CMyComPtr<ICompressCoder> encoder = encoderSpec;
if (!dictionaryIsDefined)
dictionary = 1 << 23;
UInt32 posStateBits = 2;
UInt32 litContextBits = 3; // for normal files
// UInt32 litContextBits = 0; // for 32-bit data
UInt32 litPosBits = 0;
// UInt32 litPosBits = 2; // for 32-bit data
UInt32 algorithm = 1;
UInt32 numFastBytes = 128;
UInt32 matchFinderCycles = 16 + numFastBytes / 2;
bool matchFinderCyclesDefined = false;
bool eos = parser[NKey::kEOS].ThereIs || stdInMode;
if(parser[NKey::kMode].ThereIs)
if (!GetNumber(parser[NKey::kMode].PostStrings[0], algorithm))
IncorrectCommand();
if(parser[NKey::kFastBytes].ThereIs)
if (!GetNumber(parser[NKey::kFastBytes].PostStrings[0], numFastBytes))
IncorrectCommand();
matchFinderCyclesDefined = parser[NKey::kMatchFinderCycles].ThereIs;
if (matchFinderCyclesDefined)
if (!GetNumber(parser[NKey::kMatchFinderCycles].PostStrings[0], matchFinderCycles))
IncorrectCommand();
if(parser[NKey::kLitContext].ThereIs)
if (!GetNumber(parser[NKey::kLitContext].PostStrings[0], litContextBits))
IncorrectCommand();
if(parser[NKey::kLitPos].ThereIs)
if (!GetNumber(parser[NKey::kLitPos].PostStrings[0], litPosBits))
IncorrectCommand();
if(parser[NKey::kPosBits].ThereIs)
if (!GetNumber(parser[NKey::kPosBits].PostStrings[0], posStateBits))
IncorrectCommand();
PROPID propIDs[] =
{
NCoderPropID::kDictionarySize,
NCoderPropID::kPosStateBits,
NCoderPropID::kLitContextBits,
NCoderPropID::kLitPosBits,
NCoderPropID::kAlgorithm,
NCoderPropID::kNumFastBytes,
NCoderPropID::kMatchFinder,
NCoderPropID::kEndMarker,
NCoderPropID::kMatchFinderCycles
};
const int kNumPropsMax = sizeof(propIDs) / sizeof(propIDs[0]);
/*
NWindows::NCOM::CPropVariant properties[kNumProps];
properties[0] = UInt32(dictionary);
properties[1] = UInt32(posStateBits);
properties[2] = UInt32(litContextBits);
properties[3] = UInt32(litPosBits);
properties[4] = UInt32(algorithm);
properties[5] = UInt32(numFastBytes);
properties[6] = mf;
properties[7] = eos;
*/
PROPVARIANT properties[kNumPropsMax];
for (int p = 0; p < 6; p++)
properties[p].vt = VT_UI4;
properties[0].ulVal = UInt32(dictionary);
properties[1].ulVal = UInt32(posStateBits);
properties[2].ulVal = UInt32(litContextBits);
properties[3].ulVal = UInt32(litPosBits);
properties[4].ulVal = UInt32(algorithm);
properties[5].ulVal = UInt32(numFastBytes);
properties[8].vt = VT_UI4;
properties[8].ulVal = UInt32(matchFinderCycles);
properties[6].vt = VT_BSTR;
properties[6].bstrVal = (BSTR)(const wchar_t *)mf;
properties[7].vt = VT_BOOL;
properties[7].boolVal = eos ? VARIANT_TRUE : VARIANT_FALSE;
int numProps = kNumPropsMax;
if (!matchFinderCyclesDefined)
numProps--;
if (encoderSpec->SetCoderProperties(propIDs, properties, numProps) != S_OK)
IncorrectCommand();
encoderSpec->WriteCoderProperties(outStream);
if (eos || stdInMode)
fileSize = (UInt64)(Int64)-1;
else
inStreamSpec->File.GetLength(fileSize);
for (int i = 0; i < 8; i++)
{
Byte b = Byte(fileSize >> (8 * i));
if (outStream->Write(&b, 1, 0) != S_OK)
{
fprintf(stderr, kWriteError);
return 1;
}
}
HRESULT result = encoder->Code(inStream, outStream, 0, 0, 0);
if (result == E_OUTOFMEMORY)
{
fprintf(stderr, "\nError: Can not allocate memory\n");
return 1;
}
else if (result != S_OK)
{
fprintf(stderr, "\nEncoder error = %X\n", (unsigned int)result);
return 1;
}
}
else
{
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)
{
fprintf(stderr, kReadError);
return 1;
}
if (decoderSpec->SetDecoderProperties2(properties, 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)
{
fprintf(stderr, "Decoder error");
return 1;
}
}
return 0;
}
int main(int n, const char *args[])
{
try { return main2(n, args); }
catch(const char *s)
{
fprintf(stderr, "\nError: %s\n", s);
return 1;
}
catch(...)
{
fprintf(stderr, "\nError\n");
return 1;
}
}

View File

@@ -0,0 +1,506 @@
// LzmaBench.cpp
#include "StdAfx.h"
#include "LzmaBench.h"
#ifndef _WIN32
#include <time.h>
#endif
#include "../../../Common/CRC.h"
#include "../LZMA/LZMADecoder.h"
#include "../LZMA/LZMAEncoder.h"
static const UInt32 kAdditionalSize =
#ifdef _WIN32_WCE
(1 << 20);
#else
(6 << 20);
#endif
static const UInt32 kCompressedAdditionalSize = (1 << 10);
static const UInt32 kMaxLzmaPropSize = 10;
class CRandomGenerator
{
UInt32 A1;
UInt32 A2;
public:
CRandomGenerator() { Init(); }
void Init() { A1 = 362436069; A2 = 521288629;}
UInt32 GetRnd()
{
return
((A1 = 36969 * (A1 & 0xffff) + (A1 >> 16)) << 16) ^
((A2 = 18000 * (A2 & 0xffff) + (A2 >> 16)) );
}
};
class CBitRandomGenerator
{
CRandomGenerator RG;
UInt32 Value;
int NumBits;
public:
void Init()
{
Value = 0;
NumBits = 0;
}
UInt32 GetRnd(int numBits)
{
if (NumBits > numBits)
{
UInt32 result = Value & ((1 << numBits) - 1);
Value >>= numBits;
NumBits -= numBits;
return result;
}
numBits -= NumBits;
UInt32 result = (Value << numBits);
Value = RG.GetRnd();
result |= Value & ((1 << numBits) - 1);
Value >>= numBits;
NumBits = 32 - numBits;
return result;
}
};
class CBenchRandomGenerator
{
CBitRandomGenerator RG;
UInt32 Pos;
UInt32 Rep0;
public:
UInt32 BufferSize;
Byte *Buffer;
CBenchRandomGenerator(): Buffer(0) {}
~CBenchRandomGenerator() { Free(); }
void Free()
{
::MidFree(Buffer);
Buffer = 0;
}
bool Alloc(UInt32 bufferSize)
{
if (Buffer != 0 && BufferSize == bufferSize)
return true;
Free();
Buffer = (Byte *)::MidAlloc(bufferSize);
Pos = 0;
BufferSize = bufferSize;
return (Buffer != 0);
}
UInt32 GetRndBit() { return RG.GetRnd(1); }
/*
UInt32 GetLogRand(int maxLen)
{
UInt32 len = GetRnd() % (maxLen + 1);
return GetRnd() & ((1 << len) - 1);
}
*/
UInt32 GetLogRandBits(int numBits)
{
UInt32 len = RG.GetRnd(numBits);
return RG.GetRnd(len);
}
UInt32 GetOffset()
{
if (GetRndBit() == 0)
return GetLogRandBits(4);
return (GetLogRandBits(4) << 10) | RG.GetRnd(10);
}
UInt32 GetLen1() { return RG.GetRnd(1 + (int)RG.GetRnd(2)); }
UInt32 GetLen2() { return RG.GetRnd(2 + (int)RG.GetRnd(2)); }
void Generate()
{
RG.Init();
Rep0 = 1;
while(Pos < BufferSize)
{
if (GetRndBit() == 0 || Pos < 1)
Buffer[Pos++] = (Byte)RG.GetRnd(8);
else
{
UInt32 len;
if (RG.GetRnd(3) == 0)
len = 1 + GetLen1();
else
{
do
Rep0 = GetOffset();
while (Rep0 >= Pos);
Rep0++;
len = 2 + GetLen2();
}
for (UInt32 i = 0; i < len && Pos < BufferSize; i++, Pos++)
Buffer[Pos] = Buffer[Pos - Rep0];
}
}
}
};
class CBenchmarkInStream:
public ISequentialInStream,
public CMyUnknownImp
{
const Byte *Data;
UInt32 Pos;
UInt32 Size;
public:
MY_UNKNOWN_IMP
void Init(const Byte *data, UInt32 size)
{
Data = data;
Size = size;
Pos = 0;
}
STDMETHOD(Read)(void *data, UInt32 size, UInt32 *processedSize);
};
STDMETHODIMP CBenchmarkInStream::Read(void *data, UInt32 size, UInt32 *processedSize)
{
UInt32 remain = Size - Pos;
if (size > remain)
size = remain;
for (UInt32 i = 0; i < size; i++)
((Byte *)data)[i] = Data[Pos + i];
Pos += size;
if(processedSize != NULL)
*processedSize = size;
return S_OK;
}
class CBenchmarkOutStream:
public ISequentialOutStream,
public CMyUnknownImp
{
UInt32 BufferSize;
FILE *_f;
public:
UInt32 Pos;
Byte *Buffer;
CBenchmarkOutStream(): _f(0), Buffer(0) {}
virtual ~CBenchmarkOutStream() { delete []Buffer; }
void Init(FILE *f, UInt32 bufferSize)
{
delete []Buffer;
Buffer = 0;
Buffer = new Byte[bufferSize];
Pos = 0;
BufferSize = bufferSize;
_f = f;
}
MY_UNKNOWN_IMP
STDMETHOD(Write)(const void *data, UInt32 size, UInt32 *processedSize);
};
STDMETHODIMP CBenchmarkOutStream::Write(const void *data, UInt32 size, UInt32 *processedSize)
{
UInt32 i;
for (i = 0; i < size && Pos < BufferSize; i++)
Buffer[Pos++] = ((const Byte *)data)[i];
if(processedSize != NULL)
*processedSize = i;
if (i != size)
{
fprintf(_f, "\nERROR: Buffer is full\n");
return E_FAIL;
}
return S_OK;
}
class CCrcOutStream:
public ISequentialOutStream,
public CMyUnknownImp
{
public:
CCRC CRC;
MY_UNKNOWN_IMP
void Init() { CRC.Init(); }
STDMETHOD(Write)(const void *data, UInt32 size, UInt32 *processedSize);
};
STDMETHODIMP CCrcOutStream::Write(const void *data, UInt32 size, UInt32 *processedSize)
{
CRC.Update(data, size);
if(processedSize != NULL)
*processedSize = size;
return S_OK;
}
static UInt64 GetTimeCount()
{
#ifdef _WIN32
LARGE_INTEGER value;
if (::QueryPerformanceCounter(&value))
return value.QuadPart;
return GetTickCount();
#else
return clock();
#endif
}
static UInt64 GetFreq()
{
#ifdef _WIN32
LARGE_INTEGER value;
if (::QueryPerformanceFrequency(&value))
return value.QuadPart;
return 1000;
#else
return CLOCKS_PER_SEC;
#endif
}
struct CProgressInfo:
public ICompressProgressInfo,
public CMyUnknownImp
{
UInt64 ApprovedStart;
UInt64 InSize;
UInt64 Time;
void Init()
{
InSize = 0;
Time = 0;
}
MY_UNKNOWN_IMP
STDMETHOD(SetRatioInfo)(const UInt64 *inSize, const UInt64 *outSize);
};
STDMETHODIMP CProgressInfo::SetRatioInfo(const UInt64 *inSize, const UInt64 * /* outSize */)
{
if (*inSize >= ApprovedStart && InSize == 0)
{
Time = ::GetTimeCount();
InSize = *inSize;
}
return S_OK;
}
static const int kSubBits = 8;
static UInt32 GetLogSize(UInt32 size)
{
for (int i = kSubBits; i < 32; i++)
for (UInt32 j = 0; j < (1 << kSubBits); j++)
if (size <= (((UInt32)1) << i) + (j << (i - kSubBits)))
return (i << kSubBits) + j;
return (32 << kSubBits);
}
static UInt64 MyMultDiv64(UInt64 value, UInt64 elapsedTime)
{
UInt64 freq = GetFreq();
UInt64 elTime = elapsedTime;
while(freq > 1000000)
{
freq >>= 1;
elTime >>= 1;
}
if (elTime == 0)
elTime = 1;
return value * freq / elTime;
}
static UInt64 GetCompressRating(UInt32 dictionarySize, UInt64 elapsedTime, UInt64 size)
{
UInt64 t = GetLogSize(dictionarySize) - (18 << kSubBits);
UInt64 numCommandsForOne = 1060 + ((t * t * 10) >> (2 * kSubBits));
UInt64 numCommands = (UInt64)(size) * numCommandsForOne;
return MyMultDiv64(numCommands, elapsedTime);
}
static UInt64 GetDecompressRating(UInt64 elapsedTime,
UInt64 outSize, UInt64 inSize)
{
UInt64 numCommands = inSize * 220 + outSize * 20;
return MyMultDiv64(numCommands, elapsedTime);
}
/*
static UInt64 GetTotalRating(
UInt32 dictionarySize,
bool isBT4,
UInt64 elapsedTimeEn, UInt64 sizeEn,
UInt64 elapsedTimeDe,
UInt64 inSizeDe, UInt64 outSizeDe)
{
return (GetCompressRating(dictionarySize, isBT4, elapsedTimeEn, sizeEn) +
GetDecompressRating(elapsedTimeDe, inSizeDe, outSizeDe)) / 2;
}
*/
static void PrintRating(FILE *f, UInt64 rating)
{
fprintf(f, "%5d MIPS", (unsigned int)(rating / 1000000));
}
static void PrintResults(
FILE *f,
UInt32 dictionarySize,
UInt64 elapsedTime,
UInt64 size,
bool decompressMode, UInt64 secondSize)
{
UInt64 speed = MyMultDiv64(size, elapsedTime);
fprintf(f, "%6d KB/s ", (unsigned int)(speed / 1024));
UInt64 rating;
if (decompressMode)
rating = GetDecompressRating(elapsedTime, size, secondSize);
else
rating = GetCompressRating(dictionarySize, elapsedTime, size);
PrintRating(f, rating);
}
static void ThrowError(FILE *f, HRESULT result, const char *s)
{
fprintf(f, "\nError: ");
if (result == E_ABORT)
fprintf(f, "User break");
if (result == E_OUTOFMEMORY)
fprintf(f, "Can not allocate memory");
else
fprintf(f, s);
fprintf(f, "\n");
}
const wchar_t *bt2 = L"BT2";
const wchar_t *bt4 = L"BT4";
int LzmaBenchmark(FILE *f, UInt32 numIterations, UInt32 dictionarySize)
{
if (numIterations == 0)
return 0;
if (dictionarySize < (1 << 18))
{
fprintf(f, "\nError: dictionary size for benchmark must be >= 19 (512 KB)\n");
return 1;
}
fprintf(f, "\n Compressing Decompressing\n\n");
NCompress::NLZMA::CEncoder *encoderSpec = new NCompress::NLZMA::CEncoder;
CMyComPtr<ICompressCoder> encoder = encoderSpec;
NCompress::NLZMA::CDecoder *decoderSpec = new NCompress::NLZMA::CDecoder;
CMyComPtr<ICompressCoder> decoder = decoderSpec;
CBenchmarkOutStream *propStreamSpec = new CBenchmarkOutStream;
CMyComPtr<ISequentialOutStream> propStream = propStreamSpec;
propStreamSpec->Init(f, kMaxLzmaPropSize);
PROPID propIDs[] =
{
NCoderPropID::kDictionarySize
};
const int kNumProps = sizeof(propIDs) / sizeof(propIDs[0]);
PROPVARIANT properties[kNumProps];
properties[0].vt = VT_UI4;
properties[0].ulVal = UInt32(dictionarySize);
const UInt32 kBufferSize = dictionarySize + kAdditionalSize;
const UInt32 kCompressedBufferSize = (kBufferSize / 2) + kCompressedAdditionalSize;
if (encoderSpec->SetCoderProperties(propIDs, properties, kNumProps) != S_OK)
{
fprintf(f, "\nError: Incorrect command\n");
return 1;
}
encoderSpec->WriteCoderProperties(propStream);
CBenchRandomGenerator rg;
if (!rg.Alloc(kBufferSize))
{
fprintf(f, "\nError: Can't allocate memory\n");
return 1;
}
rg.Generate();
CCRC crc;
crc.Update(rg.Buffer, rg.BufferSize);
CProgressInfo *progressInfoSpec = new CProgressInfo;
CMyComPtr<ICompressProgressInfo> progressInfo = progressInfoSpec;
progressInfoSpec->ApprovedStart = dictionarySize;
UInt64 totalBenchSize = 0;
UInt64 totalEncodeTime = 0;
UInt64 totalDecodeTime = 0;
UInt64 totalCompressedSize = 0;
for (UInt32 i = 0; i < numIterations; i++)
{
progressInfoSpec->Init();
CBenchmarkInStream *inStreamSpec = new CBenchmarkInStream;
inStreamSpec->Init(rg.Buffer, rg.BufferSize);
CMyComPtr<ISequentialInStream> inStream = inStreamSpec;
CBenchmarkOutStream *outStreamSpec = new CBenchmarkOutStream;
outStreamSpec->Init(f, kCompressedBufferSize);
CMyComPtr<ISequentialOutStream> outStream = outStreamSpec;
HRESULT result = encoder->Code(inStream, outStream, 0, 0, progressInfo);
UInt64 encodeTime = ::GetTimeCount() - progressInfoSpec->Time;
UInt32 compressedSize = outStreamSpec->Pos;
if(result != S_OK)
{
ThrowError(f, result, "Encoder Error");
return 1;
}
if (progressInfoSpec->InSize == 0)
{
fprintf(f, "\nError: Internal ERROR 1282\n");
return 1;
}
///////////////////////
// Decompressing
CCrcOutStream *crcOutStreamSpec = new CCrcOutStream;
CMyComPtr<ISequentialOutStream> crcOutStream = crcOutStreamSpec;
UInt64 decodeTime = 0;
for (int j = 0; j < 2; j++)
{
inStreamSpec->Init(outStreamSpec->Buffer, compressedSize);
crcOutStreamSpec->Init();
if (decoderSpec->SetDecoderProperties2(propStreamSpec->Buffer, propStreamSpec->Pos) != S_OK)
{
fprintf(f, "\nError: Set Decoder Properties Error\n");
return 1;
}
UInt64 outSize = kBufferSize;
UInt64 startTime = ::GetTimeCount();
result = decoder->Code(inStream, crcOutStream, 0, &outSize, 0);
decodeTime = ::GetTimeCount() - startTime;
if(result != S_OK)
{
ThrowError(f, result, "Decode Error");
return 1;
}
if (crcOutStreamSpec->CRC.GetDigest() != crc.GetDigest())
{
fprintf(f, "\nError: CRC Error\n");
return 1;
}
}
UInt64 benchSize = kBufferSize - progressInfoSpec->InSize;
PrintResults(f, dictionarySize, encodeTime, benchSize, false, 0);
fprintf(f, " ");
PrintResults(f, dictionarySize, decodeTime, kBufferSize, true, compressedSize);
fprintf(f, "\n");
totalBenchSize += benchSize;
totalEncodeTime += encodeTime;
totalDecodeTime += decodeTime;
totalCompressedSize += compressedSize;
}
fprintf(f, "---------------------------------------------------\n");
PrintResults(f, dictionarySize, totalEncodeTime, totalBenchSize, false, 0);
fprintf(f, " ");
PrintResults(f, dictionarySize, totalDecodeTime,
kBufferSize * numIterations, true, totalCompressedSize);
fprintf(f, " Average\n");
return 0;
}

View File

@@ -0,0 +1,11 @@
// LzmaBench.h
#ifndef __LzmaBench_h
#define __LzmaBench_h
#include <stdio.h>
#include "../../../Common/Types.h"
int LzmaBenchmark(FILE *f, UInt32 numIterations, UInt32 dictionarySize);
#endif

View File

@@ -0,0 +1,227 @@
// 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 _prevMask;
UInt32 _prevPos;
x86_Convert_Init(_prevMask, _prevPos);
x86_Convert(filteredStream, (UInt32)inSize, 0, &_prevMask, &_prevPos, 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
}

View File

@@ -0,0 +1,46 @@
// 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

View File

@@ -0,0 +1,79 @@
/* 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 _prevMask;
UInt32 _prevPos;
x86_Convert_Init(_prevMask, _prevPos);
x86_Convert(outBuffer, (UInt32)outSizeProcessedLoc, 0, &_prevMask, &_prevPos, 0);
}
return 0;
}

View File

@@ -0,0 +1,55 @@
/* 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

View File

@@ -0,0 +1,3 @@
// StdAfx.cpp
#include "StdAfx.h"

View File

@@ -0,0 +1,8 @@
// StdAfx.h
#ifndef __STDAFX_H
#define __STDAFX_H
#include "../../../Common/MyWindows.h"
#endif

View File

@@ -0,0 +1,124 @@
PROG = lzma.exe
CFLAGS = $(CFLAGS) -I ../../../
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/ -WX
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\LzmaRam.obj \
LZMA_OPT_OBJS = \
$O\LZMADecoder.obj \
$O\LZMAEncoder.obj \
COMMON_OBJS = \
$O\Alloc.obj \
$O\CRC.obj \
$O\CommandLineParser.obj \
$O\String.obj \
$O\StringConvert.obj \
$O\StringToInt.obj \
$O\Vector.obj
7ZIP_COMMON_OBJS = \
$O\InBuffer.obj \
$O\OutBuffer.obj \
$O\StreamUtils.obj \
LZ_OBJS = \
$O\LZOutWindow.obj \
C_OBJS = \
$O\7zCrc.obj \
C_LZ_OBJS = \
$O\MatchFinder.obj \
OBJS = \
$(LZMA_OBJS) \
$(LZMA_OPT_OBJS) \
$(COMMON_OBJS) \
$(7ZIP_COMMON_OBJS) \
$(LZ_OBJS) \
$(C_OBJS) \
$(C_LZ_OBJS) \
$O\LzmaRamDecode.obj \
$O\LzmaDecode.obj \
$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)
$(LZMA_OBJS): $(*B).cpp
$(COMPL)
$(LZMA_OPT_OBJS): ../LZMA/$(*B).cpp
$(COMPL_O2)
$(COMMON_OBJS): ../../../Common/$(*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
$(COMPL_O2)

View File

@@ -0,0 +1,117 @@
PROG = lzma
CXX = g++ -O2 -Wall
CXX_C = gcc -O2 -Wall
LIB = -lm
RM = rm -f
CFLAGS = -c -I ../../../
OBJS = \
LzmaAlone.o \
LzmaBench.o \
LzmaRam.o \
LzmaRamDecode.o \
LzmaDecode.o \
BranchX86.o \
LZMADecoder.o \
LZMAEncoder.o \
7zCrc.o \
MatchFinder.o \
LZOutWindow.o \
RangeCoderBit.o \
InBuffer.o \
OutBuffer.o \
FileStreams.o \
StreamUtils.o \
Alloc.o \
C_FileIO.o \
CommandLineParser.o \
CRC.o \
String.o \
StringConvert.o \
StringToInt.o \
Vector.o \
all: $(PROG)
$(PROG): $(OBJS)
$(CXX) -o $(PROG) $(LDFLAGS) $(OBJS) $(LIB)
LzmaAlone.o: LzmaAlone.cpp
$(CXX) $(CFLAGS) LzmaAlone.cpp
LzmaBench.o: LzmaBench.cpp
$(CXX) $(CFLAGS) LzmaBench.cpp
LzmaRam.o: LzmaRam.cpp
$(CXX) $(CFLAGS) LzmaRam.cpp
LzmaRamDecode.o: LzmaRamDecode.c
$(CXX_C) $(CFLAGS) LzmaRamDecode.c
LzmaDecode.o: ../../../../C/Compress/Lzma/LzmaDecode.c
$(CXX_C) $(CFLAGS) ../../../../C/Compress/Lzma/LzmaDecode.c
BranchX86.o: ../../../../C/Compress/Branch/BranchX86.c
$(CXX_C) $(CFLAGS) ../../../../C/Compress/Branch/BranchX86.c
LZMADecoder.o: ../LZMA/LZMADecoder.cpp
$(CXX) $(CFLAGS) ../LZMA/LZMADecoder.cpp
LZMAEncoder.o: ../LZMA/LZMAEncoder.cpp
$(CXX) $(CFLAGS) ../LZMA/LZMAEncoder.cpp
MatchFinder.o: ../../../../C/Compress/Lz/MatchFinder.c
$(CXX_C) $(CFLAGS) ../../../../C/Compress/Lz/MatchFinder.c
7zCrc.o: ../../../../C/7zCrc.c
$(CXX_C) $(CFLAGS) ../../../../C/7zCrc.c
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
OutBuffer.o: ../../Common/OutBuffer.cpp
$(CXX) $(CFLAGS) ../../Common/OutBuffer.cpp
FileStreams.o: ../../Common/FileStreams.cpp
$(CXX) $(CFLAGS) ../../Common/FileStreams.cpp
StreamUtils.o: ../../Common/StreamUtils.cpp
$(CXX) $(CFLAGS) ../../Common/StreamUtils.cpp
Alloc.o: ../../../Common/Alloc.cpp
$(CXX) $(CFLAGS) ../../../Common/Alloc.cpp
C_FileIO.o: ../../../Common/C_FileIO.cpp
$(CXX) $(CFLAGS) ../../../Common/C_FileIO.cpp
CommandLineParser.o: ../../../Common/CommandLineParser.cpp
$(CXX) $(CFLAGS) ../../../Common/CommandLineParser.cpp
CRC.o: ../../../Common/CRC.cpp
$(CXX) $(CFLAGS) ../../../Common/CRC.cpp
MyWindows.o: ../../../Common/MyWindows.cpp
$(CXX) $(CFLAGS) ../../../Common/MyWindows.cpp
String.o: ../../../Common/String.cpp
$(CXX) $(CFLAGS) ../../../Common/String.cpp
StringConvert.o: ../../../Common/StringConvert.cpp
$(CXX) $(CFLAGS) ../../../Common/StringConvert.cpp
StringToInt.o: ../../../Common/StringToInt.cpp
$(CXX) $(CFLAGS) ../../../Common/StringToInt.cpp
Vector.o: ../../../Common/Vector.cpp
$(CXX) $(CFLAGS) ../../../Common/Vector.cpp
clean:
-$(RM) $(PROG) $(OBJS)