aboutsummaryrefslogtreecommitdiff
path: root/CPP/7zip/Bundles/LzmaCon/LzmaAlone.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'CPP/7zip/Bundles/LzmaCon/LzmaAlone.cpp')
-rw-r--r--[-rwxr-xr-x]CPP/7zip/Bundles/LzmaCon/LzmaAlone.cpp138
1 files changed, 92 insertions, 46 deletions
diff --git a/CPP/7zip/Bundles/LzmaCon/LzmaAlone.cpp b/CPP/7zip/Bundles/LzmaCon/LzmaAlone.cpp
index 1f759b4..677fb8f 100755..100644
--- a/CPP/7zip/Bundles/LzmaCon/LzmaAlone.cpp
+++ b/CPP/7zip/Bundles/LzmaCon/LzmaAlone.cpp
@@ -49,6 +49,8 @@ enum Enum
{
kHelp1 = 0,
kHelp2,
+ kMethod,
+ kLevel,
kAlgo,
kDict,
kFb,
@@ -67,25 +69,25 @@ enum Enum
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"MT", NSwitchType::kUnLimitedPostString, false, 0 },
- { L"EOS", NSwitchType::kSimple, false },
- { L"SI", NSwitchType::kSimple, false },
- { L"SO", NSwitchType::kSimple, false },
- { L"F86", NSwitchType::kPostChar, false, 0, 0, L"+" }
+ { "?", NSwitchType::kSimple, false },
+ { "H", NSwitchType::kSimple, false },
+ { "MM", NSwitchType::kString, false, 1 },
+ { "X", NSwitchType::kString, false, 1 },
+ { "A", NSwitchType::kString, false, 1 },
+ { "D", NSwitchType::kString, false, 1 },
+ { "FB", NSwitchType::kString, false, 1 },
+ { "MC", NSwitchType::kString, false, 1 },
+ { "LC", NSwitchType::kString, false, 1 },
+ { "LP", NSwitchType::kString, false, 1 },
+ { "PB", NSwitchType::kString, false, 1 },
+ { "MF", NSwitchType::kString, false, 1 },
+ { "MT", NSwitchType::kString, false, 0 },
+ { "EOS", NSwitchType::kSimple, false },
+ { "SI", NSwitchType::kSimple, false },
+ { "SO", NSwitchType::kSimple, false },
+ { "F86", NSwitchType::kChar, false, 0, "+" }
};
-static const int kNumSwitches = sizeof(kSwitchForms) / sizeof(kSwitchForms[0]);
-
static void PrintMessage(const char *s)
{
fputs(s, stderr);
@@ -134,19 +136,14 @@ static void WriteArgumentsToStringList(int numArgs, const char *args[], UStringV
static bool GetNumber(const wchar_t *s, UInt32 &value)
{
value = 0;
- if (MyStringLen(s) == 0)
+ if (*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;
+ value = ConvertStringToUInt32(s, &end);
+ return *end == 0;
}
-static void ParseUInt32(const CParser &parser, int index, UInt32 &res)
+static void ParseUInt32(const CParser &parser, unsigned index, UInt32 &res)
{
if (parser[index].ThereIs)
if (!GetNumber(parser[index].PostStrings[0], res))
@@ -176,7 +173,8 @@ int main2(int numArgs, const char *args[])
UStringVector commandStrings;
WriteArgumentsToStringList(numArgs, args, commandStrings);
- CParser parser(kNumSwitches);
+
+ CParser parser(ARRAY_SIZE(kSwitchForms));
try
{
parser.ParseStrings(kSwitchForms, commandStrings);
@@ -186,33 +184,50 @@ int main2(int numArgs, const char *args[])
IncorrectCommand();
}
- if(parser[NKey::kHelp1].ThereIs || parser[NKey::kHelp2].ThereIs)
+ if (parser[NKey::kHelp1].ThereIs || parser[NKey::kHelp2].ThereIs)
{
PrintHelp();
return 0;
}
const UStringVector &nonSwitchStrings = parser.NonSwitchStrings;
- int paramIndex = 0;
+ unsigned paramIndex = 0;
if (paramIndex >= nonSwitchStrings.Size())
IncorrectCommand();
const UString &command = nonSwitchStrings[paramIndex++];
+ CObjectVector<CProperty> props;
bool dictDefined = false;
- UInt32 dict = (UInt32)-1;
- if(parser[NKey::kDict].ThereIs)
+ UInt32 dict = (UInt32)(Int32)-1;
+ if (parser[NKey::kDict].ThereIs)
{
UInt32 dicLog;
- if (!GetNumber(parser[NKey::kDict].PostStrings[0], dicLog))
+ const UString &s = parser[NKey::kDict].PostStrings[0];
+ if (!GetNumber(s, dicLog))
IncorrectCommand();
dict = 1 << dicLog;
dictDefined = true;
+ CProperty prop;
+ prop.Name = L"d";
+ prop.Value = s;
+ props.Add(prop);
+ }
+ if (parser[NKey::kLevel].ThereIs)
+ {
+ UInt32 level = 5;
+ const UString &s = parser[NKey::kLevel].PostStrings[0];
+ if (!GetNumber(s, level))
+ IncorrectCommand();
+ CProperty prop;
+ prop.Name = L"x";
+ prop.Value = s;
+ props.Add(prop);
}
UString mf = L"BT4";
if (parser[NKey::kMatchFinder].ThereIs)
mf = parser[NKey::kMatchFinder].PostStrings[0];
- UInt32 numThreads = (UInt32)-1;
+ UInt32 numThreads = (UInt32)(Int32)-1;
#ifndef _7ZIP_ST
if (parser[NKey::kMultiThread].ThereIs)
@@ -224,10 +239,25 @@ int main2(int numArgs, const char *args[])
else
if (!GetNumber(s, numThreads))
IncorrectCommand();
+ CProperty prop;
+ prop.Name = L"mt";
+ prop.Value = s;
+ props.Add(prop);
}
#endif
- if (command.CompareNoCase(L"b") == 0)
+ if (parser[NKey::kMethod].ThereIs)
+ {
+ UString s = parser[NKey::kMethod].PostStrings[0];
+ if (s.IsEmpty() || s[0] != '=')
+ IncorrectCommand();
+ CProperty prop;
+ prop.Name = L"m";
+ prop.Value = s.Ptr(1);
+ props.Add(prop);
+ }
+
+ if (MyStringCompareNoCase(command, L"b") == 0)
{
const UInt32 kNumDefaultItereations = 1;
UInt32 numIterations = kNumDefaultItereations;
@@ -236,16 +266,25 @@ int main2(int numArgs, const char *args[])
if (!GetNumber(nonSwitchStrings[paramIndex++], numIterations))
numIterations = kNumDefaultItereations;
}
- return LzmaBenchCon(stderr, numIterations, numThreads, dict);
+ HRESULT res = BenchCon(props, numIterations, stderr);
+ if (res != S_OK)
+ {
+ if (res != E_ABORT)
+ {
+ PrintMessage("Benchmark Error");
+ return 1;
+ }
+ }
+ return 0;
}
- if (numThreads == (UInt32)-1)
+ if (numThreads == (UInt32)(Int32)-1)
numThreads = 1;
bool encodeMode = false;
- if (command.CompareNoCase(L"e") == 0)
+ if (MyStringCompareNoCase(command, L"e") == 0)
encodeMode = true;
- else if (command.CompareNoCase(L"d") == 0)
+ else if (MyStringCompareNoCase(command, L"d") == 0)
encodeMode = false;
else
IncorrectCommand();
@@ -267,7 +306,7 @@ int main2(int numArgs, const char *args[])
const UString &inputName = nonSwitchStrings[paramIndex++];
inStreamSpec = new CInFileStream;
inStream = inStreamSpec;
- if (!inStreamSpec->Open(GetSystemString(inputName)))
+ if (!inStreamSpec->Open(us2fs(inputName)))
{
fprintf(stderr, "\nError: can not open input file %s\n",
(const char *)GetOemString(inputName));
@@ -289,7 +328,7 @@ int main2(int numArgs, const char *args[])
const UString &outputName = nonSwitchStrings[paramIndex++];
outStreamSpec = new COutFileStream;
outStream = outStreamSpec;
- if (!outStreamSpec->Create(GetSystemString(outputName), true))
+ if (!outStreamSpec->Create(us2fs(outputName), true))
{
fprintf(stderr, "\nError: can not open output file %s\n",
(const char *)GetOemString(outputName));
@@ -398,7 +437,7 @@ int main2(int numArgs, const char *args[])
if (!GetNumber(parser[NKey::kMc].PostStrings[0], mc))
IncorrectCommand();
- PROPID propIDs[] =
+ const PROPID propIDs[] =
{
NCoderPropID::kDictionarySize,
NCoderPropID::kPosStateBits,
@@ -411,7 +450,7 @@ int main2(int numArgs, const char *args[])
NCoderPropID::kNumThreads,
NCoderPropID::kMatchFinderCycles,
};
- const int kNumPropsMax = sizeof(propIDs) / sizeof(propIDs[0]);
+ const unsigned kNumPropsMax = ARRAY_SIZE(propIDs);
PROPVARIANT props[kNumPropsMax];
for (int p = 0; p < 6; p++)
@@ -437,7 +476,7 @@ int main2(int numArgs, const char *args[])
props[9].vt = VT_UI4;
props[9].ulVal = (UInt32)mc;
- int numProps = kNumPropsMax;
+ unsigned numProps = kNumPropsMax;
if (!mcDefined)
numProps--;
@@ -467,7 +506,7 @@ int main2(int numArgs, const char *args[])
}
else if (result != S_OK)
{
- fprintf(stderr, "\nEncoder error = %X\n", (unsigned int)result);
+ fprintf(stderr, "\nEncoder error = %X\n", (unsigned)result);
return 1;
}
}
@@ -492,11 +531,18 @@ int main2(int numArgs, const char *args[])
for (int i = 0; i < 8; i++)
fileSize |= ((UInt64)header[kPropertiesSize + i]) << (8 * i);
- if (decoder->Code(inStream, outStream, 0, (fileSize == (UInt64)(Int64)-1) ? 0 : &fileSize, 0) != S_OK)
+ bool isSizeDefined = (fileSize != (UInt64)(Int64)-1);
+ HRESULT res = decoder->Code(inStream, outStream, 0, isSizeDefined ? &fileSize : NULL, 0) != S_OK;
+ if (res != S_OK)
{
PrintMessage("Decoder error");
return 1;
}
+ if (isSizeDefined && decoderSpec->GetOutputProcessedSize() != fileSize)
+ {
+ PrintMessage("Error: incorrect uncompressed size in header");
+ return 1;
+ }
}
if (outStreamSpec != NULL)
{
@@ -512,7 +558,7 @@ int main2(int numArgs, const char *args[])
int MY_CDECL main(int numArgs, const char *args[])
{
try { return main2(numArgs, args); }
- catch(const char *s)
+ catch (const char *s)
{
fprintf(stderr, "\nError: %s\n", s);
return 1;