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>2007-09-04 04:00:00 +0400
committerKornel LesiƄski <kornel@geekhood.net>2016-05-28 02:15:54 +0300
commitb82f80647dd2b3890cdbebfe2aae44f7564baf5a (patch)
tree043d13c287b1485cc06cd6fb9fd6f8bfd0e061c0 /CPP/Common
parent051769bbc577aeede90558b6ab5c9be187940ca0 (diff)
4.54 beta
Diffstat (limited to 'CPP/Common')
-rwxr-xr-xCPP/Common/Lang.cpp72
-rwxr-xr-xCPP/Common/Lang.h2
-rwxr-xr-xCPP/Common/ListFileUtils.cpp24
-rwxr-xr-xCPP/Common/ListFileUtils.h2
-rwxr-xr-xCPP/Common/StdInStream.cpp2
5 files changed, 51 insertions, 51 deletions
diff --git a/CPP/Common/Lang.cpp b/CPP/Common/Lang.cpp
index 803209cf..7316ade4 100755
--- a/CPP/Common/Lang.cpp
+++ b/CPP/Common/Lang.cpp
@@ -5,40 +5,18 @@
#include "Lang.h"
#include "TextConfig.h"
-#include "StdInStream.h"
+#include "../Windows/FileIO.h"
#include "UTFConvert.h"
#include "Defs.h"
-/*
-static UInt32 HexStringToNumber(const char *string, int &finishPos)
+static bool HexStringToNumber(const UString &s, UInt32 &value)
{
- UInt32 number = 0;
- for (finishPos = 0; finishPos < 8; finishPos++)
- {
- char c = string[finishPos];
- int a;
- if (c >= '0' && c <= '9')
- a = c - '0';
- else if (c >= 'A' && c <= 'F')
- a = 10 + c - 'A';
- else if (c >= 'a' && c <= 'f')
- a = 10 + c - 'a';
- else
- return number;
- number *= 0x10;
- number += a;
- }
- return number;
-}
-*/
-static bool HexStringToNumber(const UString &string, UInt32 &aResultValue)
-{
- aResultValue = 0;
- if (string.IsEmpty())
+ value = 0;
+ if (s.IsEmpty())
return false;
- for (int i = 0; i < string.Length(); i++)
+ for (int i = 0; i < s.Length(); i++)
{
- wchar_t c = string[i];
+ wchar_t c = s[i];
int a;
if (c >= L'0' && c <= L'9')
a = c - L'0';
@@ -48,17 +26,17 @@ static bool HexStringToNumber(const UString &string, UInt32 &aResultValue)
a = 10 + c - L'a';
else
return false;
- aResultValue *= 0x10;
- aResultValue += a;
+ value *= 0x10;
+ value += a;
}
return true;
}
-static bool WaitNextLine(const AString &string, int &pos)
+static bool WaitNextLine(const AString &s, int &pos)
{
- for (;pos < string.Length(); pos++)
- if (string[pos] == 0x0A)
+ for (; pos < s.Length(); pos++)
+ if (s[pos] == 0x0A)
return true;
return false;
}
@@ -70,19 +48,29 @@ static int CompareLangItems(void *const *elem1, void *const *elem2, void *)
return MyCompare(langPair1.Value, langPair2.Value);
}
-bool CLang::Open(LPCTSTR fileName)
+bool CLang::Open(LPCWSTR fileName)
{
_langPairs.Clear();
- CStdInStream file;
+ NWindows::NFile::NIO::CInFile file;
if (!file.Open(fileName))
return false;
- AString string;
- file.ReadToString(string);
+ UInt64 length;
+ if (!file.GetLength(length))
+ return false;
+ if (length > (1 << 20))
+ return false;
+ AString s;
+ char *p = s.GetBuffer((int)length + 1);
+ UInt32 processed;
+ if (!file.Read(p, (UInt32)length, processed))
+ return false;
+ p[(UInt32)length] = 0;
+ s.ReleaseBuffer();
file.Close();
int pos = 0;
- if (string.Length() >= 3)
+ if (s.Length() >= 3)
{
- if (Byte(string[0]) == 0xEF && Byte(string[1]) == 0xBB && Byte(string[2]) == 0xBF)
+ if (Byte(s[0]) == 0xEF && Byte(s[1]) == 0xBB && Byte(s[2]) == 0xBF)
pos += 3;
}
@@ -90,15 +78,15 @@ bool CLang::Open(LPCTSTR fileName)
// read header
AString stringID = ";!@Lang@!UTF-8!";
- if (string.Mid(pos, stringID.Length()) != stringID)
+ if (s.Mid(pos, stringID.Length()) != stringID)
return false;
pos += stringID.Length();
- if (!WaitNextLine(string, pos))
+ if (!WaitNextLine(s, pos))
return false;
CObjectVector<CTextConfigPair> pairs;
- if (!GetTextConfig(string.Mid(pos), pairs))
+ if (!GetTextConfig(s.Mid(pos), pairs))
return false;
_langPairs.Reserve(_langPairs.Size());
diff --git a/CPP/Common/Lang.h b/CPP/Common/Lang.h
index acbf8a6b..cf978758 100755
--- a/CPP/Common/Lang.h
+++ b/CPP/Common/Lang.h
@@ -17,7 +17,7 @@ class CLang
{
CObjectVector<CLangPair> _langPairs;
public:
- bool Open(LPCTSTR fileName);
+ bool Open(LPCWSTR fileName);
void Clear() { _langPairs.Clear(); }
int FindItem(UInt32 value) const;
bool GetMessage(UInt32 value, UString &message) const;
diff --git a/CPP/Common/ListFileUtils.cpp b/CPP/Common/ListFileUtils.cpp
index 349622ed..4f8a9e59 100755
--- a/CPP/Common/ListFileUtils.cpp
+++ b/CPP/Common/ListFileUtils.cpp
@@ -2,8 +2,9 @@
#include "StdAfx.h"
+#include "../Windows/FileIO.h"
+
#include "ListFileUtils.h"
-#include "StdInStream.h"
#include "StringConvert.h"
#include "UTFConvert.h"
@@ -15,14 +16,25 @@ static void RemoveQuote(UString &s)
s = s.Mid(1, s.Length() - 2);
}
-bool ReadNamesFromListFile(LPCTSTR fileName, UStringVector &resultStrings, UINT codePage)
+bool ReadNamesFromListFile(LPCWSTR fileName, UStringVector &resultStrings, UINT codePage)
{
- CStdInStream file;
+ NWindows::NFile::NIO::CInFile file;
if (!file.Open(fileName))
return false;
-
+ UInt64 length;
+ if (!file.GetLength(length))
+ return false;
+ if (length > ((UInt32)1 << 31))
+ return false;
AString s;
- file.ReadToString(s);
+ char *p = s.GetBuffer((int)length + 1);
+ UInt32 processed;
+ if (!file.Read(p, (UInt32)length, processed))
+ return false;
+ p[(UInt32)length] = 0;
+ s.ReleaseBuffer();
+ file.Close();
+
UString u;
#ifdef CP_UTF8
if (codePage == CP_UTF8)
@@ -43,7 +55,7 @@ bool ReadNamesFromListFile(LPCTSTR fileName, UStringVector &resultStrings, UINT
for(int i = 0; i < u.Length(); i++)
{
wchar_t c = u[i];
- if (c == L'\n')
+ if (c == L'\n' || c == 0xD)
{
t.Trim();
RemoveQuote(t);
diff --git a/CPP/Common/ListFileUtils.h b/CPP/Common/ListFileUtils.h
index 182d32fa..c58a8bd4 100755
--- a/CPP/Common/ListFileUtils.h
+++ b/CPP/Common/ListFileUtils.h
@@ -6,6 +6,6 @@
#include "MyString.h"
#include "Types.h"
-bool ReadNamesFromListFile(LPCTSTR fileName, UStringVector &strings, UINT codePage = CP_OEMCP);
+bool ReadNamesFromListFile(LPCWSTR fileName, UStringVector &strings, UINT codePage = CP_OEMCP);
#endif
diff --git a/CPP/Common/StdInStream.cpp b/CPP/Common/StdInStream.cpp
index 923f366e..8fed7bc0 100755
--- a/CPP/Common/StdInStream.cpp
+++ b/CPP/Common/StdInStream.cpp
@@ -75,7 +75,7 @@ bool CStdInStream::Eof()
int CStdInStream::GetChar()
{
- int c = getc(_stream);
+ int c = fgetc(_stream); // getc() doesn't work in BeOS?
if(c == EOF && !Eof())
throw kReadErrorMessage;
return c;