PhysicsFS 2.0.3 imported.
This commit is contained in:
parent
bcc0937726
commit
993311d151
459 changed files with 87785 additions and 0 deletions
35
lib/physfs-2.0.3/lzma/CPP/Common/AutoPtr.h
Normal file
35
lib/physfs-2.0.3/lzma/CPP/Common/AutoPtr.h
Normal file
|
@ -0,0 +1,35 @@
|
|||
// Common/AutoPtr.h
|
||||
|
||||
#ifndef __COMMON_AUTOPTR_H
|
||||
#define __COMMON_AUTOPTR_H
|
||||
|
||||
template<class T> class CMyAutoPtr
|
||||
{
|
||||
T *_p;
|
||||
public:
|
||||
CMyAutoPtr(T *p = 0) : _p(p) {}
|
||||
CMyAutoPtr(CMyAutoPtr<T>& p): _p(p.release()) {}
|
||||
CMyAutoPtr<T>& operator=(CMyAutoPtr<T>& p)
|
||||
{
|
||||
reset(p.release());
|
||||
return (*this);
|
||||
}
|
||||
~CMyAutoPtr() { delete _p; }
|
||||
T& operator*() const { return *_p; }
|
||||
// T* operator->() const { return (&**this); }
|
||||
T* get() const { return _p; }
|
||||
T* release()
|
||||
{
|
||||
T *tmp = _p;
|
||||
_p = 0;
|
||||
return tmp;
|
||||
}
|
||||
void reset(T* p = 0)
|
||||
{
|
||||
if (p != _p)
|
||||
delete _p;
|
||||
_p = p;
|
||||
}
|
||||
};
|
||||
|
||||
#endif
|
77
lib/physfs-2.0.3/lzma/CPP/Common/Buffer.h
Normal file
77
lib/physfs-2.0.3/lzma/CPP/Common/Buffer.h
Normal file
|
@ -0,0 +1,77 @@
|
|||
// Common/Buffer.h
|
||||
|
||||
#ifndef __COMMON_BUFFER_H
|
||||
#define __COMMON_BUFFER_H
|
||||
|
||||
#include "Defs.h"
|
||||
|
||||
template <class T> class CBuffer
|
||||
{
|
||||
protected:
|
||||
size_t _capacity;
|
||||
T *_items;
|
||||
public:
|
||||
void Free()
|
||||
{
|
||||
delete []_items;
|
||||
_items = 0;
|
||||
_capacity = 0;
|
||||
}
|
||||
CBuffer(): _capacity(0), _items(0) {};
|
||||
CBuffer(const CBuffer &buffer): _capacity(0), _items(0) { *this = buffer; }
|
||||
CBuffer(size_t size): _items(0), _capacity(0) { SetCapacity(size); }
|
||||
virtual ~CBuffer() { delete []_items; }
|
||||
operator T *() { return _items; };
|
||||
operator const T *() const { return _items; };
|
||||
size_t GetCapacity() const { return _capacity; }
|
||||
void SetCapacity(size_t newCapacity)
|
||||
{
|
||||
if (newCapacity == _capacity)
|
||||
return;
|
||||
T *newBuffer;
|
||||
if (newCapacity > 0)
|
||||
{
|
||||
newBuffer = new T[newCapacity];
|
||||
if(_capacity > 0)
|
||||
memmove(newBuffer, _items, MyMin(_capacity, newCapacity) * sizeof(T));
|
||||
}
|
||||
else
|
||||
newBuffer = 0;
|
||||
delete []_items;
|
||||
_items = newBuffer;
|
||||
_capacity = newCapacity;
|
||||
}
|
||||
CBuffer& operator=(const CBuffer &buffer)
|
||||
{
|
||||
Free();
|
||||
if(buffer._capacity > 0)
|
||||
{
|
||||
SetCapacity(buffer._capacity);
|
||||
memmove(_items, buffer._items, buffer._capacity * sizeof(T));
|
||||
}
|
||||
return *this;
|
||||
}
|
||||
};
|
||||
|
||||
template <class T>
|
||||
bool operator==(const CBuffer<T>& b1, const CBuffer<T>& b2)
|
||||
{
|
||||
if (b1.GetCapacity() != b2.GetCapacity())
|
||||
return false;
|
||||
for (size_t i = 0; i < b1.GetCapacity(); i++)
|
||||
if (b1[i] != b2[i])
|
||||
return false;
|
||||
return true;
|
||||
}
|
||||
|
||||
template <class T>
|
||||
bool operator!=(const CBuffer<T>& b1, const CBuffer<T>& b2)
|
||||
{
|
||||
return !(b1 == b2);
|
||||
}
|
||||
|
||||
typedef CBuffer<char> CCharBuffer;
|
||||
typedef CBuffer<wchar_t> CWCharBuffer;
|
||||
typedef CBuffer<unsigned char> CByteBuffer;
|
||||
|
||||
#endif
|
14
lib/physfs-2.0.3/lzma/CPP/Common/CRC.cpp
Normal file
14
lib/physfs-2.0.3/lzma/CPP/Common/CRC.cpp
Normal file
|
@ -0,0 +1,14 @@
|
|||
// Common/CRC.cpp
|
||||
|
||||
#include "StdAfx.h"
|
||||
|
||||
extern "C"
|
||||
{
|
||||
#include "../../C/7zCrc.h"
|
||||
}
|
||||
|
||||
class CCRCTableInit
|
||||
{
|
||||
public:
|
||||
CCRCTableInit() { CrcGenerateTable(); }
|
||||
} g_CRCTableInit;
|
88
lib/physfs-2.0.3/lzma/CPP/Common/C_FileIO.cpp
Normal file
88
lib/physfs-2.0.3/lzma/CPP/Common/C_FileIO.cpp
Normal file
|
@ -0,0 +1,88 @@
|
|||
// Common/C_FileIO.h
|
||||
|
||||
#include "C_FileIO.h"
|
||||
|
||||
#include <fcntl.h>
|
||||
#include <unistd.h>
|
||||
|
||||
namespace NC {
|
||||
namespace NFile {
|
||||
namespace NIO {
|
||||
|
||||
bool CFileBase::OpenBinary(const char *name, int flags)
|
||||
{
|
||||
#ifdef O_BINARY
|
||||
flags |= O_BINARY;
|
||||
#endif
|
||||
Close();
|
||||
_handle = ::open(name, flags, 0666);
|
||||
return _handle != -1;
|
||||
}
|
||||
|
||||
bool CFileBase::Close()
|
||||
{
|
||||
if(_handle == -1)
|
||||
return true;
|
||||
if (close(_handle) != 0)
|
||||
return false;
|
||||
_handle = -1;
|
||||
return true;
|
||||
}
|
||||
|
||||
bool CFileBase::GetLength(UInt64 &length) const
|
||||
{
|
||||
off_t curPos = Seek(0, SEEK_CUR);
|
||||
off_t lengthTemp = Seek(0, SEEK_END);
|
||||
Seek(curPos, SEEK_SET);
|
||||
length = (UInt64)lengthTemp;
|
||||
return true;
|
||||
}
|
||||
|
||||
off_t CFileBase::Seek(off_t distanceToMove, int moveMethod) const
|
||||
{
|
||||
return ::lseek(_handle, distanceToMove, moveMethod);
|
||||
}
|
||||
|
||||
/////////////////////////
|
||||
// CInFile
|
||||
|
||||
bool CInFile::Open(const char *name)
|
||||
{
|
||||
return CFileBase::OpenBinary(name, O_RDONLY);
|
||||
}
|
||||
|
||||
bool CInFile::OpenShared(const char *name, bool)
|
||||
{
|
||||
return Open(name);
|
||||
}
|
||||
|
||||
ssize_t CInFile::Read(void *data, size_t size)
|
||||
{
|
||||
return read(_handle, data, size);
|
||||
}
|
||||
|
||||
/////////////////////////
|
||||
// COutFile
|
||||
|
||||
bool COutFile::Create(const char *name, bool createAlways)
|
||||
{
|
||||
if (createAlways)
|
||||
{
|
||||
Close();
|
||||
_handle = ::creat(name, 0666);
|
||||
return _handle != -1;
|
||||
}
|
||||
return OpenBinary(name, O_CREAT | O_EXCL | O_WRONLY);
|
||||
}
|
||||
|
||||
bool COutFile::Open(const char *name, DWORD creationDisposition)
|
||||
{
|
||||
return Create(name, false);
|
||||
}
|
||||
|
||||
ssize_t COutFile::Write(const void *data, size_t size)
|
||||
{
|
||||
return write(_handle, data, size);
|
||||
}
|
||||
|
||||
}}}
|
47
lib/physfs-2.0.3/lzma/CPP/Common/C_FileIO.h
Normal file
47
lib/physfs-2.0.3/lzma/CPP/Common/C_FileIO.h
Normal file
|
@ -0,0 +1,47 @@
|
|||
// Common/C_FileIO.h
|
||||
|
||||
#ifndef __COMMON_C_FILEIO_H
|
||||
#define __COMMON_C_FILEIO_H
|
||||
|
||||
#include <stdio.h>
|
||||
#include <sys/types.h>
|
||||
|
||||
#include "Types.h"
|
||||
#include "MyWindows.h"
|
||||
|
||||
namespace NC {
|
||||
namespace NFile {
|
||||
namespace NIO {
|
||||
|
||||
class CFileBase
|
||||
{
|
||||
protected:
|
||||
int _handle;
|
||||
bool OpenBinary(const char *name, int flags);
|
||||
public:
|
||||
CFileBase(): _handle(-1) {};
|
||||
~CFileBase() { Close(); }
|
||||
bool Close();
|
||||
bool GetLength(UInt64 &length) const;
|
||||
off_t Seek(off_t distanceToMove, int moveMethod) const;
|
||||
};
|
||||
|
||||
class CInFile: public CFileBase
|
||||
{
|
||||
public:
|
||||
bool Open(const char *name);
|
||||
bool OpenShared(const char *name, bool shareForWrite);
|
||||
ssize_t Read(void *data, size_t size);
|
||||
};
|
||||
|
||||
class COutFile: public CFileBase
|
||||
{
|
||||
public:
|
||||
bool Create(const char *name, bool createAlways);
|
||||
bool Open(const char *name, DWORD creationDisposition);
|
||||
ssize_t Write(const void *data, size_t size);
|
||||
};
|
||||
|
||||
}}}
|
||||
|
||||
#endif
|
17
lib/physfs-2.0.3/lzma/CPP/Common/ComTry.h
Normal file
17
lib/physfs-2.0.3/lzma/CPP/Common/ComTry.h
Normal file
|
@ -0,0 +1,17 @@
|
|||
// ComTry.h
|
||||
|
||||
#ifndef __COM_TRY_H
|
||||
#define __COM_TRY_H
|
||||
|
||||
#include "MyWindows.h"
|
||||
// #include "Exception.h"
|
||||
// #include "NewHandler.h"
|
||||
|
||||
#define COM_TRY_BEGIN try {
|
||||
#define COM_TRY_END } catch(...) { return E_OUTOFMEMORY; }
|
||||
|
||||
// catch(const CNewException &) { return E_OUTOFMEMORY; }\
|
||||
// catch(const CSystemException &e) { return e.ErrorCode; }\
|
||||
// catch(...) { return E_FAIL; }
|
||||
|
||||
#endif
|
232
lib/physfs-2.0.3/lzma/CPP/Common/CommandLineParser.cpp
Normal file
232
lib/physfs-2.0.3/lzma/CPP/Common/CommandLineParser.cpp
Normal file
|
@ -0,0 +1,232 @@
|
|||
// CommandLineParser.cpp
|
||||
|
||||
#include "StdAfx.h"
|
||||
|
||||
#include "CommandLineParser.h"
|
||||
|
||||
namespace NCommandLineParser {
|
||||
|
||||
void SplitCommandLine(const UString &src, UString &dest1, UString &dest2)
|
||||
{
|
||||
dest1.Empty();
|
||||
dest2.Empty();
|
||||
bool quoteMode = false;
|
||||
int i;
|
||||
for (i = 0; i < src.Length(); i++)
|
||||
{
|
||||
wchar_t c = src[i];
|
||||
if (c == L'\"')
|
||||
quoteMode = !quoteMode;
|
||||
else if (c == L' ' && !quoteMode)
|
||||
{
|
||||
i++;
|
||||
break;
|
||||
}
|
||||
else
|
||||
dest1 += c;
|
||||
}
|
||||
dest2 = src.Mid(i);
|
||||
}
|
||||
|
||||
void SplitCommandLine(const UString &s, UStringVector &parts)
|
||||
{
|
||||
UString sTemp = s;
|
||||
sTemp.Trim();
|
||||
parts.Clear();
|
||||
for (;;)
|
||||
{
|
||||
UString s1, s2;
|
||||
SplitCommandLine(sTemp, s1, s2);
|
||||
// s1.Trim();
|
||||
// s2.Trim();
|
||||
if (!s1.IsEmpty())
|
||||
parts.Add(s1);
|
||||
if (s2.IsEmpty())
|
||||
break;
|
||||
sTemp = s2;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
static const wchar_t kSwitchID1 = '-';
|
||||
// static const wchar_t kSwitchID2 = '/';
|
||||
|
||||
static const wchar_t kSwitchMinus = '-';
|
||||
static const wchar_t *kStopSwitchParsing = L"--";
|
||||
|
||||
static bool IsItSwitchChar(wchar_t c)
|
||||
{
|
||||
return (c == kSwitchID1 /*|| c == kSwitchID2 */);
|
||||
}
|
||||
|
||||
CParser::CParser(int numSwitches):
|
||||
_numSwitches(numSwitches)
|
||||
{
|
||||
_switches = new CSwitchResult[_numSwitches];
|
||||
}
|
||||
|
||||
CParser::~CParser()
|
||||
{
|
||||
delete []_switches;
|
||||
}
|
||||
|
||||
void CParser::ParseStrings(const CSwitchForm *switchForms,
|
||||
const UStringVector &commandStrings)
|
||||
{
|
||||
int numCommandStrings = commandStrings.Size();
|
||||
bool stopSwitch = false;
|
||||
for (int i = 0; i < numCommandStrings; i++)
|
||||
{
|
||||
const UString &s = commandStrings[i];
|
||||
if (stopSwitch)
|
||||
NonSwitchStrings.Add(s);
|
||||
else
|
||||
if (s == kStopSwitchParsing)
|
||||
stopSwitch = true;
|
||||
else
|
||||
if (!ParseString(s, switchForms))
|
||||
NonSwitchStrings.Add(s);
|
||||
}
|
||||
}
|
||||
|
||||
// if string contains switch then function updates switch structures
|
||||
// out: (string is a switch)
|
||||
bool CParser::ParseString(const UString &s, const CSwitchForm *switchForms)
|
||||
{
|
||||
int len = s.Length();
|
||||
if (len == 0)
|
||||
return false;
|
||||
int pos = 0;
|
||||
if (!IsItSwitchChar(s[pos]))
|
||||
return false;
|
||||
while(pos < len)
|
||||
{
|
||||
if (IsItSwitchChar(s[pos]))
|
||||
pos++;
|
||||
const int kNoLen = -1;
|
||||
int matchedSwitchIndex = 0; // GCC Warning
|
||||
int maxLen = kNoLen;
|
||||
for(int switchIndex = 0; switchIndex < _numSwitches; switchIndex++)
|
||||
{
|
||||
int switchLen = MyStringLen(switchForms[switchIndex].IDString);
|
||||
if (switchLen <= maxLen || pos + switchLen > len)
|
||||
continue;
|
||||
|
||||
UString temp = s + pos;
|
||||
temp = temp.Left(switchLen);
|
||||
if(temp.CompareNoCase(switchForms[switchIndex].IDString) == 0)
|
||||
// if(_strnicmp(switchForms[switchIndex].IDString, LPCSTR(s) + pos, switchLen) == 0)
|
||||
{
|
||||
matchedSwitchIndex = switchIndex;
|
||||
maxLen = switchLen;
|
||||
}
|
||||
}
|
||||
if (maxLen == kNoLen)
|
||||
throw "maxLen == kNoLen";
|
||||
CSwitchResult &matchedSwitch = _switches[matchedSwitchIndex];
|
||||
const CSwitchForm &switchForm = switchForms[matchedSwitchIndex];
|
||||
if ((!switchForm.Multi) && matchedSwitch.ThereIs)
|
||||
throw "switch must be single";
|
||||
matchedSwitch.ThereIs = true;
|
||||
pos += maxLen;
|
||||
int tailSize = len - pos;
|
||||
NSwitchType::EEnum type = switchForm.Type;
|
||||
switch(type)
|
||||
{
|
||||
case NSwitchType::kPostMinus:
|
||||
{
|
||||
if (tailSize == 0)
|
||||
matchedSwitch.WithMinus = false;
|
||||
else
|
||||
{
|
||||
matchedSwitch.WithMinus = (s[pos] == kSwitchMinus);
|
||||
if (matchedSwitch.WithMinus)
|
||||
pos++;
|
||||
}
|
||||
break;
|
||||
}
|
||||
case NSwitchType::kPostChar:
|
||||
{
|
||||
if (tailSize < switchForm.MinLen)
|
||||
throw "switch is not full";
|
||||
UString set = switchForm.PostCharSet;
|
||||
const int kEmptyCharValue = -1;
|
||||
if (tailSize == 0)
|
||||
matchedSwitch.PostCharIndex = kEmptyCharValue;
|
||||
else
|
||||
{
|
||||
int index = set.Find(s[pos]);
|
||||
if (index < 0)
|
||||
matchedSwitch.PostCharIndex = kEmptyCharValue;
|
||||
else
|
||||
{
|
||||
matchedSwitch.PostCharIndex = index;
|
||||
pos++;
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
case NSwitchType::kLimitedPostString:
|
||||
case NSwitchType::kUnLimitedPostString:
|
||||
{
|
||||
int minLen = switchForm.MinLen;
|
||||
if (tailSize < minLen)
|
||||
throw "switch is not full";
|
||||
if (type == NSwitchType::kUnLimitedPostString)
|
||||
{
|
||||
matchedSwitch.PostStrings.Add(s.Mid(pos));
|
||||
return true;
|
||||
}
|
||||
int maxLen = switchForm.MaxLen;
|
||||
UString stringSwitch = s.Mid(pos, minLen);
|
||||
pos += minLen;
|
||||
for(int i = minLen; i < maxLen && pos < len; i++, pos++)
|
||||
{
|
||||
wchar_t c = s[pos];
|
||||
if (IsItSwitchChar(c))
|
||||
break;
|
||||
stringSwitch += c;
|
||||
}
|
||||
matchedSwitch.PostStrings.Add(stringSwitch);
|
||||
break;
|
||||
}
|
||||
case NSwitchType::kSimple:
|
||||
break;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
const CSwitchResult& CParser::operator[](size_t index) const
|
||||
{
|
||||
return _switches[index];
|
||||
}
|
||||
|
||||
/////////////////////////////////
|
||||
// Command parsing procedures
|
||||
|
||||
int ParseCommand(int numCommandForms, const CCommandForm *commandForms,
|
||||
const UString &commandString, UString &postString)
|
||||
{
|
||||
for(int i = 0; i < numCommandForms; i++)
|
||||
{
|
||||
const UString id = commandForms[i].IDString;
|
||||
if (commandForms[i].PostStringMode)
|
||||
{
|
||||
if(commandString.Find(id) == 0)
|
||||
{
|
||||
postString = commandString.Mid(id.Length());
|
||||
return i;
|
||||
}
|
||||
}
|
||||
else
|
||||
if (commandString == id)
|
||||
{
|
||||
postString.Empty();
|
||||
return i;
|
||||
}
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
}
|
72
lib/physfs-2.0.3/lzma/CPP/Common/CommandLineParser.h
Normal file
72
lib/physfs-2.0.3/lzma/CPP/Common/CommandLineParser.h
Normal file
|
@ -0,0 +1,72 @@
|
|||
// Common/CommandLineParser.h
|
||||
|
||||
#ifndef __COMMON_COMMANDLINEPARSER_H
|
||||
#define __COMMON_COMMANDLINEPARSER_H
|
||||
|
||||
#include "MyString.h"
|
||||
|
||||
namespace NCommandLineParser {
|
||||
|
||||
void SplitCommandLine(const UString &src, UString &dest1, UString &dest2);
|
||||
void SplitCommandLine(const UString &s, UStringVector &parts);
|
||||
|
||||
namespace NSwitchType {
|
||||
enum EEnum
|
||||
{
|
||||
kSimple,
|
||||
kPostMinus,
|
||||
kLimitedPostString,
|
||||
kUnLimitedPostString,
|
||||
kPostChar
|
||||
};
|
||||
}
|
||||
|
||||
struct CSwitchForm
|
||||
{
|
||||
const wchar_t *IDString;
|
||||
NSwitchType::EEnum Type;
|
||||
bool Multi;
|
||||
int MinLen;
|
||||
int MaxLen;
|
||||
const wchar_t *PostCharSet;
|
||||
};
|
||||
|
||||
struct CSwitchResult
|
||||
{
|
||||
bool ThereIs;
|
||||
bool WithMinus;
|
||||
UStringVector PostStrings;
|
||||
int PostCharIndex;
|
||||
CSwitchResult(): ThereIs(false) {};
|
||||
};
|
||||
|
||||
class CParser
|
||||
{
|
||||
int _numSwitches;
|
||||
CSwitchResult *_switches;
|
||||
bool ParseString(const UString &s, const CSwitchForm *switchForms);
|
||||
public:
|
||||
UStringVector NonSwitchStrings;
|
||||
CParser(int numSwitches);
|
||||
~CParser();
|
||||
void ParseStrings(const CSwitchForm *switchForms,
|
||||
const UStringVector &commandStrings);
|
||||
const CSwitchResult& operator[](size_t index) const;
|
||||
};
|
||||
|
||||
/////////////////////////////////
|
||||
// Command parsing procedures
|
||||
|
||||
struct CCommandForm
|
||||
{
|
||||
wchar_t *IDString;
|
||||
bool PostStringMode;
|
||||
};
|
||||
|
||||
// Returns: Index of form and postString; -1, if there is no match
|
||||
int ParseCommand(int numCommandForms, const CCommandForm *commandForms,
|
||||
const UString &commandString, UString &postString);
|
||||
|
||||
}
|
||||
|
||||
#endif
|
20
lib/physfs-2.0.3/lzma/CPP/Common/Defs.h
Normal file
20
lib/physfs-2.0.3/lzma/CPP/Common/Defs.h
Normal file
|
@ -0,0 +1,20 @@
|
|||
// Common/Defs.h
|
||||
|
||||
#ifndef __COMMON_DEFS_H
|
||||
#define __COMMON_DEFS_H
|
||||
|
||||
template <class T> inline T MyMin(T a, T b)
|
||||
{ return a < b ? a : b; }
|
||||
template <class T> inline T MyMax(T a, T b)
|
||||
{ return a > b ? a : b; }
|
||||
|
||||
template <class T> inline int MyCompare(T a, T b)
|
||||
{ return a < b ? -1 : (a == b ? 0 : 1); }
|
||||
|
||||
inline int BoolToInt(bool value)
|
||||
{ return (value ? 1: 0); }
|
||||
|
||||
inline bool IntToBool(int value)
|
||||
{ return (value != 0); }
|
||||
|
||||
#endif
|
47
lib/physfs-2.0.3/lzma/CPP/Common/DynamicBuffer.h
Normal file
47
lib/physfs-2.0.3/lzma/CPP/Common/DynamicBuffer.h
Normal file
|
@ -0,0 +1,47 @@
|
|||
// Common/DynamicBuffer.h
|
||||
|
||||
#ifndef __COMMON_DYNAMICBUFFER_H
|
||||
#define __COMMON_DYNAMICBUFFER_H
|
||||
|
||||
#include "Buffer.h"
|
||||
|
||||
template <class T> class CDynamicBuffer: public CBuffer<T>
|
||||
{
|
||||
void GrowLength(size_t size)
|
||||
{
|
||||
size_t delta;
|
||||
if (this->_capacity > 64)
|
||||
delta = this->_capacity / 4;
|
||||
else if (this->_capacity > 8)
|
||||
delta = 16;
|
||||
else
|
||||
delta = 4;
|
||||
delta = MyMax(delta, size);
|
||||
SetCapacity(this->_capacity + delta);
|
||||
}
|
||||
public:
|
||||
CDynamicBuffer(): CBuffer<T>() {};
|
||||
CDynamicBuffer(const CDynamicBuffer &buffer): CBuffer<T>(buffer) {};
|
||||
CDynamicBuffer(size_t size): CBuffer<T>(size) {};
|
||||
CDynamicBuffer& operator=(const CDynamicBuffer &buffer)
|
||||
{
|
||||
this->Free();
|
||||
if(buffer._capacity > 0)
|
||||
{
|
||||
SetCapacity(buffer._capacity);
|
||||
memmove(this->_items, buffer._items, buffer._capacity * sizeof(T));
|
||||
}
|
||||
return *this;
|
||||
}
|
||||
void EnsureCapacity(size_t capacity)
|
||||
{
|
||||
if (this->_capacity < capacity)
|
||||
GrowLength(capacity - this->_capacity);
|
||||
}
|
||||
};
|
||||
|
||||
typedef CDynamicBuffer<char> CCharDynamicBuffer;
|
||||
typedef CDynamicBuffer<wchar_t> CWCharDynamicBuffer;
|
||||
typedef CDynamicBuffer<unsigned char> CByteDynamicBuffer;
|
||||
|
||||
#endif
|
63
lib/physfs-2.0.3/lzma/CPP/Common/IntToString.cpp
Normal file
63
lib/physfs-2.0.3/lzma/CPP/Common/IntToString.cpp
Normal file
|
@ -0,0 +1,63 @@
|
|||
// Common/IntToString.cpp
|
||||
|
||||
#include "StdAfx.h"
|
||||
|
||||
#include "IntToString.h"
|
||||
|
||||
void ConvertUInt64ToString(UInt64 value, char *s, UInt32 base)
|
||||
{
|
||||
if (base < 2 || base > 36)
|
||||
{
|
||||
*s = '\0';
|
||||
return;
|
||||
}
|
||||
char temp[72];
|
||||
int pos = 0;
|
||||
do
|
||||
{
|
||||
int delta = (int)(value % base);
|
||||
temp[pos++] = (char)((delta < 10) ? ('0' + delta) : ('a' + (delta - 10)));
|
||||
value /= base;
|
||||
}
|
||||
while (value != 0);
|
||||
do
|
||||
*s++ = temp[--pos];
|
||||
while(pos > 0);
|
||||
*s = '\0';
|
||||
}
|
||||
|
||||
void ConvertUInt64ToString(UInt64 value, wchar_t *s)
|
||||
{
|
||||
wchar_t temp[32];
|
||||
int pos = 0;
|
||||
do
|
||||
{
|
||||
temp[pos++] = (wchar_t)(L'0' + (int)(value % 10));
|
||||
value /= 10;
|
||||
}
|
||||
while (value != 0);
|
||||
do
|
||||
*s++ = temp[--pos];
|
||||
while(pos > 0);
|
||||
*s = L'\0';
|
||||
}
|
||||
|
||||
void ConvertInt64ToString(Int64 value, char *s)
|
||||
{
|
||||
if (value < 0)
|
||||
{
|
||||
*s++ = '-';
|
||||
value = -value;
|
||||
}
|
||||
ConvertUInt64ToString(value, s);
|
||||
}
|
||||
|
||||
void ConvertInt64ToString(Int64 value, wchar_t *s)
|
||||
{
|
||||
if (value < 0)
|
||||
{
|
||||
*s++ = L'-';
|
||||
value = -value;
|
||||
}
|
||||
ConvertUInt64ToString(value, s);
|
||||
}
|
15
lib/physfs-2.0.3/lzma/CPP/Common/IntToString.h
Normal file
15
lib/physfs-2.0.3/lzma/CPP/Common/IntToString.h
Normal file
|
@ -0,0 +1,15 @@
|
|||
// Common/IntToString.h
|
||||
|
||||
#ifndef __COMMON_INTTOSTRING_H
|
||||
#define __COMMON_INTTOSTRING_H
|
||||
|
||||
#include <stddef.h>
|
||||
#include "Types.h"
|
||||
|
||||
void ConvertUInt64ToString(UInt64 value, char *s, UInt32 base = 10);
|
||||
void ConvertUInt64ToString(UInt64 value, wchar_t *s);
|
||||
|
||||
void ConvertInt64ToString(Int64 value, char *s);
|
||||
void ConvertInt64ToString(Int64 value, wchar_t *s);
|
||||
|
||||
#endif
|
74
lib/physfs-2.0.3/lzma/CPP/Common/ListFileUtils.cpp
Normal file
74
lib/physfs-2.0.3/lzma/CPP/Common/ListFileUtils.cpp
Normal file
|
@ -0,0 +1,74 @@
|
|||
// Common/ListFileUtils.cpp
|
||||
|
||||
#include "StdAfx.h"
|
||||
|
||||
#include "../Windows/FileIO.h"
|
||||
|
||||
#include "ListFileUtils.h"
|
||||
#include "StringConvert.h"
|
||||
#include "UTFConvert.h"
|
||||
|
||||
static const char kQuoteChar = '\"';
|
||||
static void RemoveQuote(UString &s)
|
||||
{
|
||||
if (s.Length() >= 2)
|
||||
if (s[0] == kQuoteChar && s[s.Length() - 1] == kQuoteChar)
|
||||
s = s.Mid(1, s.Length() - 2);
|
||||
}
|
||||
|
||||
bool ReadNamesFromListFile(LPCWSTR fileName, UStringVector &resultStrings, UINT codePage)
|
||||
{
|
||||
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;
|
||||
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)
|
||||
{
|
||||
if (!ConvertUTF8ToUnicode(s, u))
|
||||
return false;
|
||||
}
|
||||
else
|
||||
#endif
|
||||
u = MultiByteToUnicodeString(s, codePage);
|
||||
if (!u.IsEmpty())
|
||||
{
|
||||
if (u[0] == 0xFEFF)
|
||||
u.Delete(0);
|
||||
}
|
||||
|
||||
UString t;
|
||||
for(int i = 0; i < u.Length(); i++)
|
||||
{
|
||||
wchar_t c = u[i];
|
||||
if (c == L'\n' || c == 0xD)
|
||||
{
|
||||
t.Trim();
|
||||
RemoveQuote(t);
|
||||
if (!t.IsEmpty())
|
||||
resultStrings.Add(t);
|
||||
t.Empty();
|
||||
}
|
||||
else
|
||||
t += c;
|
||||
}
|
||||
t.Trim();
|
||||
RemoveQuote(t);
|
||||
if (!t.IsEmpty())
|
||||
resultStrings.Add(t);
|
||||
return true;
|
||||
}
|
11
lib/physfs-2.0.3/lzma/CPP/Common/ListFileUtils.h
Normal file
11
lib/physfs-2.0.3/lzma/CPP/Common/ListFileUtils.h
Normal file
|
@ -0,0 +1,11 @@
|
|||
// Common/ListFileUtils.h
|
||||
|
||||
#ifndef __COMMON_LISTFILEUTILS_H
|
||||
#define __COMMON_LISTFILEUTILS_H
|
||||
|
||||
#include "MyString.h"
|
||||
#include "Types.h"
|
||||
|
||||
bool ReadNamesFromListFile(LPCWSTR fileName, UStringVector &strings, UINT codePage = CP_OEMCP);
|
||||
|
||||
#endif
|
218
lib/physfs-2.0.3/lzma/CPP/Common/MyCom.h
Normal file
218
lib/physfs-2.0.3/lzma/CPP/Common/MyCom.h
Normal file
|
@ -0,0 +1,218 @@
|
|||
// MyCom.h
|
||||
|
||||
#ifndef __MYCOM_H
|
||||
#define __MYCOM_H
|
||||
|
||||
#include "MyWindows.h"
|
||||
|
||||
#ifndef RINOK
|
||||
#define RINOK(x) { HRESULT __result_ = (x); if(__result_ != S_OK) return __result_; }
|
||||
#endif
|
||||
|
||||
template <class T>
|
||||
class CMyComPtr
|
||||
{
|
||||
T* _p;
|
||||
public:
|
||||
// typedef T _PtrClass;
|
||||
CMyComPtr() { _p = NULL;}
|
||||
CMyComPtr(T* p) {if ((_p = p) != NULL) p->AddRef(); }
|
||||
CMyComPtr(const CMyComPtr<T>& lp)
|
||||
{
|
||||
if ((_p = lp._p) != NULL)
|
||||
_p->AddRef();
|
||||
}
|
||||
~CMyComPtr() { if (_p) _p->Release(); }
|
||||
void Release() { if (_p) { _p->Release(); _p = NULL; } }
|
||||
operator T*() const { return (T*)_p; }
|
||||
// T& operator*() const { return *_p; }
|
||||
T** operator&() { return &_p; }
|
||||
T* operator->() const { return _p; }
|
||||
T* operator=(T* p)
|
||||
{
|
||||
if (p != 0)
|
||||
p->AddRef();
|
||||
if (_p)
|
||||
_p->Release();
|
||||
_p = p;
|
||||
return p;
|
||||
}
|
||||
T* operator=(const CMyComPtr<T>& lp) { return (*this = lp._p); }
|
||||
bool operator!() const { return (_p == NULL); }
|
||||
// bool operator==(T* pT) const { return _p == pT; }
|
||||
// Compare two objects for equivalence
|
||||
void Attach(T* p2)
|
||||
{
|
||||
Release();
|
||||
_p = p2;
|
||||
}
|
||||
T* Detach()
|
||||
{
|
||||
T* pt = _p;
|
||||
_p = NULL;
|
||||
return pt;
|
||||
}
|
||||
#ifdef _WIN32
|
||||
HRESULT CoCreateInstance(REFCLSID rclsid, REFIID iid, LPUNKNOWN pUnkOuter = NULL, DWORD dwClsContext = CLSCTX_ALL)
|
||||
{
|
||||
return ::CoCreateInstance(rclsid, pUnkOuter, dwClsContext, iid, (void**)&_p);
|
||||
}
|
||||
#endif
|
||||
/*
|
||||
HRESULT CoCreateInstance(LPCOLESTR szProgID, LPUNKNOWN pUnkOuter = NULL, DWORD dwClsContext = CLSCTX_ALL)
|
||||
{
|
||||
CLSID clsid;
|
||||
HRESULT hr = CLSIDFromProgID(szProgID, &clsid);
|
||||
ATLASSERT(_p == NULL);
|
||||
if (SUCCEEDED(hr))
|
||||
hr = ::CoCreateInstance(clsid, pUnkOuter, dwClsContext, __uuidof(T), (void**)&_p);
|
||||
return hr;
|
||||
}
|
||||
*/
|
||||
template <class Q>
|
||||
HRESULT QueryInterface(REFGUID iid, Q** pp) const
|
||||
{
|
||||
return _p->QueryInterface(iid, (void**)pp);
|
||||
}
|
||||
};
|
||||
|
||||
//////////////////////////////////////////////////////////
|
||||
|
||||
class CMyComBSTR
|
||||
{
|
||||
public:
|
||||
BSTR m_str;
|
||||
CMyComBSTR() { m_str = NULL; }
|
||||
CMyComBSTR(LPCOLESTR pSrc) { m_str = ::SysAllocString(pSrc); }
|
||||
// CMyComBSTR(int nSize) { m_str = ::SysAllocStringLen(NULL, nSize); }
|
||||
// CMyComBSTR(int nSize, LPCOLESTR sz) { m_str = ::SysAllocStringLen(sz, nSize); }
|
||||
CMyComBSTR(const CMyComBSTR& src) { m_str = src.MyCopy(); }
|
||||
/*
|
||||
CMyComBSTR(REFGUID src)
|
||||
{
|
||||
LPOLESTR szGuid;
|
||||
StringFromCLSID(src, &szGuid);
|
||||
m_str = ::SysAllocString(szGuid);
|
||||
CoTaskMemFree(szGuid);
|
||||
}
|
||||
*/
|
||||
~CMyComBSTR() { ::SysFreeString(m_str); }
|
||||
CMyComBSTR& operator=(const CMyComBSTR& src)
|
||||
{
|
||||
if (m_str != src.m_str)
|
||||
{
|
||||
if (m_str)
|
||||
::SysFreeString(m_str);
|
||||
m_str = src.MyCopy();
|
||||
}
|
||||
return *this;
|
||||
}
|
||||
CMyComBSTR& operator=(LPCOLESTR pSrc)
|
||||
{
|
||||
::SysFreeString(m_str);
|
||||
m_str = ::SysAllocString(pSrc);
|
||||
return *this;
|
||||
}
|
||||
unsigned int Length() const { return ::SysStringLen(m_str); }
|
||||
operator BSTR() const { return m_str; }
|
||||
BSTR* operator&() { return &m_str; }
|
||||
BSTR MyCopy() const
|
||||
{
|
||||
int byteLen = ::SysStringByteLen(m_str);
|
||||
BSTR res = ::SysAllocStringByteLen(NULL, byteLen);
|
||||
memmove(res, m_str, byteLen);
|
||||
return res;
|
||||
}
|
||||
void Attach(BSTR src) { m_str = src; }
|
||||
BSTR Detach()
|
||||
{
|
||||
BSTR s = m_str;
|
||||
m_str = NULL;
|
||||
return s;
|
||||
}
|
||||
void Empty()
|
||||
{
|
||||
::SysFreeString(m_str);
|
||||
m_str = NULL;
|
||||
}
|
||||
bool operator!() const { return (m_str == NULL); }
|
||||
};
|
||||
|
||||
|
||||
//////////////////////////////////////////////////////////
|
||||
|
||||
class CMyUnknownImp
|
||||
{
|
||||
public:
|
||||
ULONG __m_RefCount;
|
||||
CMyUnknownImp(): __m_RefCount(0) {}
|
||||
};
|
||||
|
||||
#define MY_QUERYINTERFACE_BEGIN STDMETHOD(QueryInterface) \
|
||||
(REFGUID iid, void **outObject) {
|
||||
|
||||
#define MY_QUERYINTERFACE_ENTRY(i) if (iid == IID_ ## i) \
|
||||
{ *outObject = (void *)(i *)this; AddRef(); return S_OK; }
|
||||
|
||||
#define MY_QUERYINTERFACE_ENTRY_UNKNOWN(i) if (iid == IID_IUnknown) \
|
||||
{ *outObject = (void *)(IUnknown *)(i *)this; AddRef(); return S_OK; }
|
||||
|
||||
#define MY_QUERYINTERFACE_BEGIN2(i) MY_QUERYINTERFACE_BEGIN \
|
||||
MY_QUERYINTERFACE_ENTRY_UNKNOWN(i) \
|
||||
MY_QUERYINTERFACE_ENTRY(i)
|
||||
|
||||
#define MY_QUERYINTERFACE_END return E_NOINTERFACE; }
|
||||
|
||||
#define MY_ADDREF_RELEASE \
|
||||
STDMETHOD_(ULONG, AddRef)() { return ++__m_RefCount; } \
|
||||
STDMETHOD_(ULONG, Release)() { if (--__m_RefCount != 0) \
|
||||
return __m_RefCount; delete this; return 0; }
|
||||
|
||||
#define MY_UNKNOWN_IMP_SPEC(i) \
|
||||
MY_QUERYINTERFACE_BEGIN \
|
||||
i \
|
||||
MY_QUERYINTERFACE_END \
|
||||
MY_ADDREF_RELEASE
|
||||
|
||||
|
||||
#define MY_UNKNOWN_IMP MY_QUERYINTERFACE_BEGIN \
|
||||
MY_QUERYINTERFACE_ENTRY_UNKNOWN(IUnknown) \
|
||||
MY_QUERYINTERFACE_END \
|
||||
MY_ADDREF_RELEASE
|
||||
|
||||
#define MY_UNKNOWN_IMP1(i) MY_UNKNOWN_IMP_SPEC( \
|
||||
MY_QUERYINTERFACE_ENTRY_UNKNOWN(i) \
|
||||
MY_QUERYINTERFACE_ENTRY(i) \
|
||||
)
|
||||
|
||||
#define MY_UNKNOWN_IMP2(i1, i2) MY_UNKNOWN_IMP_SPEC( \
|
||||
MY_QUERYINTERFACE_ENTRY_UNKNOWN(i1) \
|
||||
MY_QUERYINTERFACE_ENTRY(i1) \
|
||||
MY_QUERYINTERFACE_ENTRY(i2) \
|
||||
)
|
||||
|
||||
#define MY_UNKNOWN_IMP3(i1, i2, i3) MY_UNKNOWN_IMP_SPEC( \
|
||||
MY_QUERYINTERFACE_ENTRY_UNKNOWN(i1) \
|
||||
MY_QUERYINTERFACE_ENTRY(i1) \
|
||||
MY_QUERYINTERFACE_ENTRY(i2) \
|
||||
MY_QUERYINTERFACE_ENTRY(i3) \
|
||||
)
|
||||
|
||||
#define MY_UNKNOWN_IMP4(i1, i2, i3, i4) MY_UNKNOWN_IMP_SPEC( \
|
||||
MY_QUERYINTERFACE_ENTRY_UNKNOWN(i1) \
|
||||
MY_QUERYINTERFACE_ENTRY(i1) \
|
||||
MY_QUERYINTERFACE_ENTRY(i2) \
|
||||
MY_QUERYINTERFACE_ENTRY(i3) \
|
||||
MY_QUERYINTERFACE_ENTRY(i4) \
|
||||
)
|
||||
|
||||
#define MY_UNKNOWN_IMP5(i1, i2, i3, i4, i5) MY_UNKNOWN_IMP_SPEC( \
|
||||
MY_QUERYINTERFACE_ENTRY_UNKNOWN(i1) \
|
||||
MY_QUERYINTERFACE_ENTRY(i1) \
|
||||
MY_QUERYINTERFACE_ENTRY(i2) \
|
||||
MY_QUERYINTERFACE_ENTRY(i3) \
|
||||
MY_QUERYINTERFACE_ENTRY(i4) \
|
||||
MY_QUERYINTERFACE_ENTRY(i5) \
|
||||
)
|
||||
|
||||
#endif
|
14
lib/physfs-2.0.3/lzma/CPP/Common/MyException.h
Normal file
14
lib/physfs-2.0.3/lzma/CPP/Common/MyException.h
Normal file
|
@ -0,0 +1,14 @@
|
|||
// Common/Exception.h
|
||||
|
||||
#ifndef __COMMON_EXCEPTION_H
|
||||
#define __COMMON_EXCEPTION_H
|
||||
|
||||
#include "MyWindows.h"
|
||||
|
||||
struct CSystemException
|
||||
{
|
||||
HRESULT ErrorCode;
|
||||
CSystemException(HRESULT errorCode): ErrorCode(errorCode) {}
|
||||
};
|
||||
|
||||
#endif
|
54
lib/physfs-2.0.3/lzma/CPP/Common/MyGuidDef.h
Normal file
54
lib/physfs-2.0.3/lzma/CPP/Common/MyGuidDef.h
Normal file
|
@ -0,0 +1,54 @@
|
|||
// Common/MyGuidDef.h
|
||||
|
||||
#ifndef GUID_DEFINED
|
||||
#define GUID_DEFINED
|
||||
|
||||
#include "Types.h"
|
||||
|
||||
typedef struct {
|
||||
UInt32 Data1;
|
||||
UInt16 Data2;
|
||||
UInt16 Data3;
|
||||
unsigned char Data4[8];
|
||||
} GUID;
|
||||
|
||||
#ifdef __cplusplus
|
||||
#define REFGUID const GUID &
|
||||
#else
|
||||
#define REFGUID const GUID *
|
||||
#endif
|
||||
|
||||
#define REFCLSID REFGUID
|
||||
#define REFIID REFGUID
|
||||
|
||||
#ifdef __cplusplus
|
||||
inline int operator==(REFGUID g1, REFGUID g2)
|
||||
{
|
||||
for (int i = 0; i < (int)sizeof(g1); i++)
|
||||
if (((unsigned char *)&g1)[i] != ((unsigned char *)&g2)[i])
|
||||
return 0;
|
||||
return 1;
|
||||
}
|
||||
inline int operator!=(REFGUID g1, REFGUID g2) { return !(g1 == g2); }
|
||||
#endif
|
||||
|
||||
#ifdef __cplusplus
|
||||
#define MY_EXTERN_C extern "C"
|
||||
#else
|
||||
#define MY_EXTERN_C extern
|
||||
#endif
|
||||
|
||||
#endif // GUID_DEFINED
|
||||
|
||||
|
||||
#ifdef DEFINE_GUID
|
||||
#undef DEFINE_GUID
|
||||
#endif
|
||||
|
||||
#ifdef INITGUID
|
||||
#define DEFINE_GUID(name, l, w1, w2, b1, b2, b3, b4, b5, b6, b7, b8) \
|
||||
MY_EXTERN_C const GUID name = { l, w1, w2, { b1, b2, b3, b4, b5, b6, b7, b8 } }
|
||||
#else
|
||||
#define DEFINE_GUID(name, l, w1, w2, b1, b2, b3, b4, b5, b6, b7, b8) \
|
||||
MY_EXTERN_C const GUID name
|
||||
#endif
|
15
lib/physfs-2.0.3/lzma/CPP/Common/MyInitGuid.h
Normal file
15
lib/physfs-2.0.3/lzma/CPP/Common/MyInitGuid.h
Normal file
|
@ -0,0 +1,15 @@
|
|||
// Common/MyInitGuid.h
|
||||
|
||||
#ifndef __COMMON_MYINITGUID_H
|
||||
#define __COMMON_MYINITGUID_H
|
||||
|
||||
#ifdef _WIN32
|
||||
#include <initguid.h>
|
||||
#else
|
||||
#define INITGUID
|
||||
#include "MyGuidDef.h"
|
||||
DEFINE_GUID(IID_IUnknown,
|
||||
0x00000000, 0x0000, 0x0000, 0xC0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x46);
|
||||
#endif
|
||||
|
||||
#endif
|
198
lib/physfs-2.0.3/lzma/CPP/Common/MyString.cpp
Normal file
198
lib/physfs-2.0.3/lzma/CPP/Common/MyString.cpp
Normal file
|
@ -0,0 +1,198 @@
|
|||
// Common/MyString.cpp
|
||||
|
||||
#include "StdAfx.h"
|
||||
|
||||
#ifdef _WIN32
|
||||
#include "StringConvert.h"
|
||||
#else
|
||||
#include <ctype.h>
|
||||
#endif
|
||||
|
||||
#include "MyString.h"
|
||||
|
||||
|
||||
#ifdef _WIN32
|
||||
|
||||
#ifndef _UNICODE
|
||||
|
||||
wchar_t MyCharUpper(wchar_t c)
|
||||
{
|
||||
if (c == 0)
|
||||
return 0;
|
||||
wchar_t *res = CharUpperW((LPWSTR)(UINT_PTR)(unsigned int)c);
|
||||
if (res != 0 || ::GetLastError() != ERROR_CALL_NOT_IMPLEMENTED)
|
||||
return (wchar_t)(unsigned int)(UINT_PTR)res;
|
||||
const int kBufferSize = 4;
|
||||
char s[kBufferSize + 1];
|
||||
int numChars = ::WideCharToMultiByte(CP_ACP, 0, &c, 1, s, kBufferSize, 0, 0);
|
||||
if (numChars == 0 || numChars > kBufferSize)
|
||||
return c;
|
||||
s[numChars] = 0;
|
||||
::CharUpperA(s);
|
||||
::MultiByteToWideChar(CP_ACP, 0, s, numChars, &c, 1);
|
||||
return c;
|
||||
}
|
||||
|
||||
wchar_t MyCharLower(wchar_t c)
|
||||
{
|
||||
if (c == 0)
|
||||
return 0;
|
||||
wchar_t *res = CharLowerW((LPWSTR)(UINT_PTR)(unsigned int)c);
|
||||
if (res != 0 || ::GetLastError() != ERROR_CALL_NOT_IMPLEMENTED)
|
||||
return (wchar_t)(unsigned int)(UINT_PTR)res;
|
||||
const int kBufferSize = 4;
|
||||
char s[kBufferSize + 1];
|
||||
int numChars = ::WideCharToMultiByte(CP_ACP, 0, &c, 1, s, kBufferSize, 0, 0);
|
||||
if (numChars == 0 || numChars > kBufferSize)
|
||||
return c;
|
||||
s[numChars] = 0;
|
||||
::CharLowerA(s);
|
||||
::MultiByteToWideChar(CP_ACP, 0, s, numChars, &c, 1);
|
||||
return c;
|
||||
}
|
||||
|
||||
wchar_t * MyStringUpper(wchar_t *s)
|
||||
{
|
||||
if (s == 0)
|
||||
return 0;
|
||||
wchar_t *res = CharUpperW(s);
|
||||
if (res != 0 || ::GetLastError() != ERROR_CALL_NOT_IMPLEMENTED)
|
||||
return res;
|
||||
AString a = UnicodeStringToMultiByte(s);
|
||||
a.MakeUpper();
|
||||
return MyStringCopy(s, (const wchar_t *)MultiByteToUnicodeString(a));
|
||||
}
|
||||
|
||||
wchar_t * MyStringLower(wchar_t *s)
|
||||
{
|
||||
if (s == 0)
|
||||
return 0;
|
||||
wchar_t *res = CharLowerW(s);
|
||||
if (res != 0 || ::GetLastError() != ERROR_CALL_NOT_IMPLEMENTED)
|
||||
return res;
|
||||
AString a = UnicodeStringToMultiByte(s);
|
||||
a.MakeLower();
|
||||
return MyStringCopy(s, (const wchar_t *)MultiByteToUnicodeString(a));
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
/*
|
||||
inline int ConvertCompareResult(int r) { return r - 2; }
|
||||
|
||||
int MyStringCollate(const wchar_t *s1, const wchar_t *s2)
|
||||
{
|
||||
int res = CompareStringW(
|
||||
LOCALE_USER_DEFAULT, SORT_STRINGSORT, s1, -1, s2, -1);
|
||||
#ifdef _UNICODE
|
||||
return ConvertCompareResult(res);
|
||||
#else
|
||||
if (res != 0 || ::GetLastError() != ERROR_CALL_NOT_IMPLEMENTED)
|
||||
return ConvertCompareResult(res);
|
||||
return MyStringCollate(UnicodeStringToMultiByte(s1),
|
||||
UnicodeStringToMultiByte(s2));
|
||||
#endif
|
||||
}
|
||||
|
||||
#ifndef _WIN32_WCE
|
||||
int MyStringCollate(const char *s1, const char *s2)
|
||||
{
|
||||
return ConvertCompareResult(CompareStringA(
|
||||
LOCALE_USER_DEFAULT, SORT_STRINGSORT, s1, -1, s2, -1));
|
||||
}
|
||||
|
||||
int MyStringCollateNoCase(const char *s1, const char *s2)
|
||||
{
|
||||
return ConvertCompareResult(CompareStringA(
|
||||
LOCALE_USER_DEFAULT, NORM_IGNORECASE | SORT_STRINGSORT, s1, -1, s2, -1));
|
||||
}
|
||||
#endif
|
||||
|
||||
int MyStringCollateNoCase(const wchar_t *s1, const wchar_t *s2)
|
||||
{
|
||||
int res = CompareStringW(
|
||||
LOCALE_USER_DEFAULT, NORM_IGNORECASE | SORT_STRINGSORT, s1, -1, s2, -1);
|
||||
#ifdef _UNICODE
|
||||
return ConvertCompareResult(res);
|
||||
#else
|
||||
if (res != 0 || ::GetLastError() != ERROR_CALL_NOT_IMPLEMENTED)
|
||||
return ConvertCompareResult(res);
|
||||
return MyStringCollateNoCase(UnicodeStringToMultiByte(s1),
|
||||
UnicodeStringToMultiByte(s2));
|
||||
#endif
|
||||
}
|
||||
*/
|
||||
|
||||
#else
|
||||
|
||||
wchar_t MyCharUpper(wchar_t c)
|
||||
{
|
||||
return toupper(c);
|
||||
}
|
||||
|
||||
/*
|
||||
int MyStringCollateNoCase(const wchar_t *s1, const wchar_t *s2)
|
||||
{
|
||||
for (;;)
|
||||
{
|
||||
wchar_t c1 = *s1++;
|
||||
wchar_t c2 = *s2++;
|
||||
wchar_t u1 = MyCharUpper(c1);
|
||||
wchar_t u2 = MyCharUpper(c2);
|
||||
|
||||
if (u1 < u2) return -1;
|
||||
if (u1 > u2) return 1;
|
||||
if (u1 == 0) return 0;
|
||||
}
|
||||
}
|
||||
*/
|
||||
|
||||
#endif
|
||||
|
||||
int MyStringCompare(const char *s1, const char *s2)
|
||||
{
|
||||
for (;;)
|
||||
{
|
||||
unsigned char c1 = (unsigned char)*s1++;
|
||||
unsigned char c2 = (unsigned char)*s2++;
|
||||
if (c1 < c2) return -1;
|
||||
if (c1 > c2) return 1;
|
||||
if (c1 == 0) return 0;
|
||||
}
|
||||
}
|
||||
|
||||
int MyStringCompare(const wchar_t *s1, const wchar_t *s2)
|
||||
{
|
||||
for (;;)
|
||||
{
|
||||
wchar_t c1 = *s1++;
|
||||
wchar_t c2 = *s2++;
|
||||
if (c1 < c2) return -1;
|
||||
if (c1 > c2) return 1;
|
||||
if (c1 == 0) return 0;
|
||||
}
|
||||
}
|
||||
|
||||
int MyStringCompareNoCase(const wchar_t *s1, const wchar_t *s2)
|
||||
{
|
||||
for (;;)
|
||||
{
|
||||
wchar_t c1 = *s1++;
|
||||
wchar_t c2 = *s2++;
|
||||
if (c1 != c2)
|
||||
{
|
||||
wchar_t u1 = MyCharUpper(c1);
|
||||
wchar_t u2 = MyCharUpper(c2);
|
||||
if (u1 < u2) return -1;
|
||||
if (u1 > u2) return 1;
|
||||
}
|
||||
if (c1 == 0) return 0;
|
||||
}
|
||||
}
|
||||
|
||||
#ifdef _WIN32
|
||||
int MyStringCompareNoCase(const char *s1, const char *s2)
|
||||
{
|
||||
return MyStringCompareNoCase(MultiByteToUnicodeString(s1), MultiByteToUnicodeString(s2));
|
||||
}
|
||||
#endif
|
636
lib/physfs-2.0.3/lzma/CPP/Common/MyString.h
Normal file
636
lib/physfs-2.0.3/lzma/CPP/Common/MyString.h
Normal file
|
@ -0,0 +1,636 @@
|
|||
// Common/String.h
|
||||
|
||||
#ifndef __COMMON_STRING_H
|
||||
#define __COMMON_STRING_H
|
||||
|
||||
#include <string.h>
|
||||
// #include <wchar.h>
|
||||
|
||||
#include "MyVector.h"
|
||||
|
||||
#ifdef _WIN32
|
||||
#include "MyWindows.h"
|
||||
#endif
|
||||
|
||||
template <class T>
|
||||
inline int MyStringLen(const T *s)
|
||||
{
|
||||
int i;
|
||||
for (i = 0; s[i] != '\0'; i++);
|
||||
return i;
|
||||
}
|
||||
|
||||
template <class T>
|
||||
inline T * MyStringCopy(T *dest, const T *src)
|
||||
{
|
||||
T *destStart = dest;
|
||||
while((*dest++ = *src++) != 0);
|
||||
return destStart;
|
||||
}
|
||||
|
||||
inline wchar_t* MyStringGetNextCharPointer(wchar_t *p)
|
||||
{ return (p + 1); }
|
||||
inline const wchar_t* MyStringGetNextCharPointer(const wchar_t *p)
|
||||
{ return (p + 1); }
|
||||
inline wchar_t* MyStringGetPrevCharPointer(const wchar_t *, wchar_t *p)
|
||||
{ return (p - 1); }
|
||||
inline const wchar_t* MyStringGetPrevCharPointer(const wchar_t *, const wchar_t *p)
|
||||
{ return (p - 1); }
|
||||
|
||||
#ifdef _WIN32
|
||||
|
||||
inline char* MyStringGetNextCharPointer(char *p)
|
||||
{ return CharNextA(p); }
|
||||
inline const char* MyStringGetNextCharPointer(const char *p)
|
||||
{ return CharNextA(p); }
|
||||
|
||||
inline char* MyStringGetPrevCharPointer(char *base, char *p)
|
||||
{ return CharPrevA(base, p); }
|
||||
inline const char* MyStringGetPrevCharPointer(const char *base, const char *p)
|
||||
{ return CharPrevA(base, p); }
|
||||
|
||||
inline char MyCharUpper(char c)
|
||||
{ return (char)(unsigned int)(UINT_PTR)CharUpperA((LPSTR)(UINT_PTR)(unsigned int)(unsigned char)c); }
|
||||
#ifdef _UNICODE
|
||||
inline wchar_t MyCharUpper(wchar_t c)
|
||||
{ return (wchar_t)(unsigned int)(UINT_PTR)CharUpperW((LPWSTR)(UINT_PTR)(unsigned int)c); }
|
||||
#else
|
||||
wchar_t MyCharUpper(wchar_t c);
|
||||
#endif
|
||||
|
||||
inline char MyCharLower(char c)
|
||||
{ return (char)(unsigned int)(UINT_PTR)CharLowerA((LPSTR)(UINT_PTR)(unsigned int)(unsigned char)c); }
|
||||
#ifdef _UNICODE
|
||||
inline wchar_t MyCharLower(wchar_t c)
|
||||
{ return (wchar_t)(unsigned int)(UINT_PTR)CharLowerW((LPWSTR)(UINT_PTR)(unsigned int)c); }
|
||||
#else
|
||||
wchar_t MyCharLower(wchar_t c);
|
||||
#endif
|
||||
|
||||
inline char * MyStringUpper(char *s) { return CharUpperA(s); }
|
||||
#ifdef _UNICODE
|
||||
inline wchar_t * MyStringUpper(wchar_t *s) { return CharUpperW(s); }
|
||||
#else
|
||||
wchar_t * MyStringUpper(wchar_t *s);
|
||||
#endif
|
||||
|
||||
inline char * MyStringLower(char *s) { return CharLowerA(s); }
|
||||
#ifdef _UNICODE
|
||||
inline wchar_t * MyStringLower(wchar_t *s) { return CharLowerW(s); }
|
||||
#else
|
||||
wchar_t * MyStringLower(wchar_t *s);
|
||||
#endif
|
||||
|
||||
#else // Standard-C
|
||||
wchar_t MyCharUpper(wchar_t c);
|
||||
#endif
|
||||
|
||||
//////////////////////////////////////
|
||||
// Compare
|
||||
|
||||
/*
|
||||
#ifndef _WIN32_WCE
|
||||
int MyStringCollate(const char *s1, const char *s2);
|
||||
int MyStringCollateNoCase(const char *s1, const char *s2);
|
||||
#endif
|
||||
int MyStringCollate(const wchar_t *s1, const wchar_t *s2);
|
||||
int MyStringCollateNoCase(const wchar_t *s1, const wchar_t *s2);
|
||||
*/
|
||||
|
||||
int MyStringCompare(const char *s1, const char *s2);
|
||||
int MyStringCompare(const wchar_t *s1, const wchar_t *s2);
|
||||
|
||||
#ifdef _WIN32
|
||||
int MyStringCompareNoCase(const char *s1, const char *s2);
|
||||
#endif
|
||||
|
||||
int MyStringCompareNoCase(const wchar_t *s1, const wchar_t *s2);
|
||||
|
||||
template <class T>
|
||||
class CStringBase
|
||||
{
|
||||
void TrimLeftWithCharSet(const CStringBase &charSet)
|
||||
{
|
||||
const T *p = _chars;
|
||||
while (charSet.Find(*p) >= 0 && (*p != 0))
|
||||
p = GetNextCharPointer(p);
|
||||
Delete(0, (int)(p - _chars));
|
||||
}
|
||||
void TrimRightWithCharSet(const CStringBase &charSet)
|
||||
{
|
||||
const T *p = _chars;
|
||||
const T *pLast = NULL;
|
||||
while (*p != 0)
|
||||
{
|
||||
if (charSet.Find(*p) >= 0)
|
||||
{
|
||||
if (pLast == NULL)
|
||||
pLast = p;
|
||||
}
|
||||
else
|
||||
pLast = NULL;
|
||||
p = GetNextCharPointer(p);
|
||||
}
|
||||
if(pLast != NULL)
|
||||
{
|
||||
int i = (int)(pLast - _chars);
|
||||
Delete(i, _length - i);
|
||||
}
|
||||
|
||||
}
|
||||
void MoveItems(int destIndex, int srcIndex)
|
||||
{
|
||||
memmove(_chars + destIndex, _chars + srcIndex,
|
||||
sizeof(T) * (_length - srcIndex + 1));
|
||||
}
|
||||
|
||||
void InsertSpace(int &index, int size)
|
||||
{
|
||||
CorrectIndex(index);
|
||||
GrowLength(size);
|
||||
MoveItems(index + size, index);
|
||||
}
|
||||
|
||||
static T *GetNextCharPointer(T *p)
|
||||
{ return MyStringGetNextCharPointer(p); }
|
||||
static const T *GetNextCharPointer(const T *p)
|
||||
{ return MyStringGetNextCharPointer(p); }
|
||||
static T *GetPrevCharPointer(T *base, T *p)
|
||||
{ return MyStringGetPrevCharPointer(base, p); }
|
||||
static const T *GetPrevCharPointer(const T *base, const T *p)
|
||||
{ return MyStringGetPrevCharPointer(base, p); }
|
||||
protected:
|
||||
T *_chars;
|
||||
int _length;
|
||||
int _capacity;
|
||||
|
||||
void SetCapacity(int newCapacity)
|
||||
{
|
||||
int realCapacity = newCapacity + 1;
|
||||
if(realCapacity == _capacity)
|
||||
return;
|
||||
/*
|
||||
const int kMaxStringSize = 0x20000000;
|
||||
#ifndef _WIN32_WCE
|
||||
if(newCapacity > kMaxStringSize || newCapacity < _length)
|
||||
throw 1052337;
|
||||
#endif
|
||||
*/
|
||||
T *newBuffer = new T[realCapacity];
|
||||
if(_capacity > 0)
|
||||
{
|
||||
for (int i = 0; i < (_length + 1); i++)
|
||||
newBuffer[i] = _chars[i];
|
||||
delete []_chars;
|
||||
_chars = newBuffer;
|
||||
}
|
||||
else
|
||||
{
|
||||
_chars = newBuffer;
|
||||
_chars[0] = 0;
|
||||
}
|
||||
_capacity = realCapacity;
|
||||
}
|
||||
|
||||
void GrowLength(int n)
|
||||
{
|
||||
int freeSize = _capacity - _length - 1;
|
||||
if (n <= freeSize)
|
||||
return;
|
||||
int delta;
|
||||
if (_capacity > 64)
|
||||
delta = _capacity / 2;
|
||||
else if (_capacity > 8)
|
||||
delta = 16;
|
||||
else
|
||||
delta = 4;
|
||||
if (freeSize + delta < n)
|
||||
delta = n - freeSize;
|
||||
SetCapacity(_capacity + delta);
|
||||
}
|
||||
|
||||
void CorrectIndex(int &index) const
|
||||
{
|
||||
if (index > _length)
|
||||
index = _length;
|
||||
}
|
||||
|
||||
public:
|
||||
CStringBase(): _chars(0), _length(0), _capacity(0)
|
||||
{ SetCapacity(16 - 1); }
|
||||
CStringBase(T c): _chars(0), _length(0), _capacity(0)
|
||||
{
|
||||
SetCapacity(1);
|
||||
_chars[0] = c;
|
||||
_chars[1] = 0;
|
||||
_length = 1;
|
||||
}
|
||||
CStringBase(const T *chars): _chars(0), _length(0), _capacity(0)
|
||||
{
|
||||
int length = MyStringLen(chars);
|
||||
SetCapacity(length);
|
||||
MyStringCopy(_chars, chars); // can be optimized by memove()
|
||||
_length = length;
|
||||
}
|
||||
CStringBase(const CStringBase &s): _chars(0), _length(0), _capacity(0)
|
||||
{
|
||||
SetCapacity(s._length);
|
||||
MyStringCopy(_chars, s._chars);
|
||||
_length = s._length;
|
||||
}
|
||||
~CStringBase() { delete []_chars; }
|
||||
|
||||
operator const T*() const { return _chars;}
|
||||
|
||||
// The minimum size of the character buffer in characters.
|
||||
// This value does not include space for a null terminator.
|
||||
T* GetBuffer(int minBufLength)
|
||||
{
|
||||
if(minBufLength >= _capacity)
|
||||
SetCapacity(minBufLength + 1);
|
||||
return _chars;
|
||||
}
|
||||
void ReleaseBuffer() { ReleaseBuffer(MyStringLen(_chars)); }
|
||||
void ReleaseBuffer(int newLength)
|
||||
{
|
||||
/*
|
||||
#ifndef _WIN32_WCE
|
||||
if(newLength >= _capacity)
|
||||
throw 282217;
|
||||
#endif
|
||||
*/
|
||||
_chars[newLength] = 0;
|
||||
_length = newLength;
|
||||
}
|
||||
|
||||
CStringBase& operator=(T c)
|
||||
{
|
||||
Empty();
|
||||
SetCapacity(1);
|
||||
_chars[0] = c;
|
||||
_chars[1] = 0;
|
||||
_length = 1;
|
||||
return *this;
|
||||
}
|
||||
CStringBase& operator=(const T *chars)
|
||||
{
|
||||
Empty();
|
||||
int length = MyStringLen(chars);
|
||||
SetCapacity(length);
|
||||
MyStringCopy(_chars, chars);
|
||||
_length = length;
|
||||
return *this;
|
||||
}
|
||||
CStringBase& operator=(const CStringBase& s)
|
||||
{
|
||||
if(&s == this)
|
||||
return *this;
|
||||
Empty();
|
||||
SetCapacity(s._length);
|
||||
MyStringCopy(_chars, s._chars);
|
||||
_length = s._length;
|
||||
return *this;
|
||||
}
|
||||
|
||||
CStringBase& operator+=(T c)
|
||||
{
|
||||
GrowLength(1);
|
||||
_chars[_length] = c;
|
||||
_chars[++_length] = 0;
|
||||
return *this;
|
||||
}
|
||||
CStringBase& operator+=(const T *s)
|
||||
{
|
||||
int len = MyStringLen(s);
|
||||
GrowLength(len);
|
||||
MyStringCopy(_chars + _length, s);
|
||||
_length += len;
|
||||
return *this;
|
||||
}
|
||||
CStringBase& operator+=(const CStringBase &s)
|
||||
{
|
||||
GrowLength(s._length);
|
||||
MyStringCopy(_chars + _length, s._chars);
|
||||
_length += s._length;
|
||||
return *this;
|
||||
}
|
||||
void Empty()
|
||||
{
|
||||
_length = 0;
|
||||
_chars[0] = 0;
|
||||
}
|
||||
int Length() const { return _length; }
|
||||
bool IsEmpty() const { return (_length == 0); }
|
||||
|
||||
CStringBase Mid(int startIndex) const
|
||||
{ return Mid(startIndex, _length - startIndex); }
|
||||
CStringBase Mid(int startIndex, int count ) const
|
||||
{
|
||||
if (startIndex + count > _length)
|
||||
count = _length - startIndex;
|
||||
|
||||
if (startIndex == 0 && startIndex + count == _length)
|
||||
return *this;
|
||||
|
||||
CStringBase<T> result;
|
||||
result.SetCapacity(count);
|
||||
// MyStringNCopy(result._chars, _chars + startIndex, count);
|
||||
for (int i = 0; i < count; i++)
|
||||
result._chars[i] = _chars[startIndex + i];
|
||||
result._chars[count] = 0;
|
||||
result._length = count;
|
||||
return result;
|
||||
}
|
||||
CStringBase Left(int count) const
|
||||
{ return Mid(0, count); }
|
||||
CStringBase Right(int count) const
|
||||
{
|
||||
if (count > _length)
|
||||
count = _length;
|
||||
return Mid(_length - count, count);
|
||||
}
|
||||
|
||||
void MakeUpper()
|
||||
{ MyStringUpper(_chars); }
|
||||
void MakeLower()
|
||||
{ MyStringLower(_chars); }
|
||||
|
||||
int Compare(const CStringBase& s) const
|
||||
{ return MyStringCompare(_chars, s._chars); }
|
||||
|
||||
int Compare(const T *s) const
|
||||
{ return MyStringCompare(_chars, s); }
|
||||
|
||||
int CompareNoCase(const CStringBase& s) const
|
||||
{ return MyStringCompareNoCase(_chars, s._chars); }
|
||||
|
||||
int CompareNoCase(const T *s) const
|
||||
{ return MyStringCompareNoCase(_chars, s); }
|
||||
|
||||
/*
|
||||
int Collate(const CStringBase& s) const
|
||||
{ return MyStringCollate(_chars, s._chars); }
|
||||
int CollateNoCase(const CStringBase& s) const
|
||||
{ return MyStringCollateNoCase(_chars, s._chars); }
|
||||
*/
|
||||
|
||||
int Find(T c) const { return Find(c, 0); }
|
||||
int Find(T c, int startIndex) const
|
||||
{
|
||||
T *p = _chars + startIndex;
|
||||
for (;;)
|
||||
{
|
||||
if (*p == c)
|
||||
return (int)(p - _chars);
|
||||
if (*p == 0)
|
||||
return -1;
|
||||
p = GetNextCharPointer(p);
|
||||
}
|
||||
}
|
||||
int Find(const CStringBase &s) const { return Find(s, 0); }
|
||||
int Find(const CStringBase &s, int startIndex) const
|
||||
{
|
||||
if (s.IsEmpty())
|
||||
return startIndex;
|
||||
for (; startIndex < _length; startIndex++)
|
||||
{
|
||||
int j;
|
||||
for (j = 0; j < s._length && startIndex + j < _length; j++)
|
||||
if (_chars[startIndex+j] != s._chars[j])
|
||||
break;
|
||||
if (j == s._length)
|
||||
return startIndex;
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
int ReverseFind(T c) const
|
||||
{
|
||||
if (_length == 0)
|
||||
return -1;
|
||||
T *p = _chars + _length - 1;
|
||||
for (;;)
|
||||
{
|
||||
if (*p == c)
|
||||
return (int)(p - _chars);
|
||||
if (p == _chars)
|
||||
return -1;
|
||||
p = GetPrevCharPointer(_chars, p);
|
||||
}
|
||||
}
|
||||
int FindOneOf(const CStringBase &s) const
|
||||
{
|
||||
for(int i = 0; i < _length; i++)
|
||||
if (s.Find(_chars[i]) >= 0)
|
||||
return i;
|
||||
return -1;
|
||||
}
|
||||
|
||||
void TrimLeft(T c)
|
||||
{
|
||||
const T *p = _chars;
|
||||
while (c == *p)
|
||||
p = GetNextCharPointer(p);
|
||||
Delete(0, p - _chars);
|
||||
}
|
||||
private:
|
||||
CStringBase GetTrimDefaultCharSet()
|
||||
{
|
||||
CStringBase<T> charSet;
|
||||
charSet += (T)' ';
|
||||
charSet += (T)'\n';
|
||||
charSet += (T)'\t';
|
||||
return charSet;
|
||||
}
|
||||
public:
|
||||
|
||||
void TrimLeft()
|
||||
{
|
||||
TrimLeftWithCharSet(GetTrimDefaultCharSet());
|
||||
}
|
||||
void TrimRight()
|
||||
{
|
||||
TrimRightWithCharSet(GetTrimDefaultCharSet());
|
||||
}
|
||||
void TrimRight(T c)
|
||||
{
|
||||
const T *p = _chars;
|
||||
const T *pLast = NULL;
|
||||
while (*p != 0)
|
||||
{
|
||||
if (*p == c)
|
||||
{
|
||||
if (pLast == NULL)
|
||||
pLast = p;
|
||||
}
|
||||
else
|
||||
pLast = NULL;
|
||||
p = GetNextCharPointer(p);
|
||||
}
|
||||
if(pLast != NULL)
|
||||
{
|
||||
int i = pLast - _chars;
|
||||
Delete(i, _length - i);
|
||||
}
|
||||
}
|
||||
void Trim()
|
||||
{
|
||||
TrimRight();
|
||||
TrimLeft();
|
||||
}
|
||||
|
||||
int Insert(int index, T c)
|
||||
{
|
||||
InsertSpace(index, 1);
|
||||
_chars[index] = c;
|
||||
_length++;
|
||||
return _length;
|
||||
}
|
||||
int Insert(int index, const CStringBase &s)
|
||||
{
|
||||
CorrectIndex(index);
|
||||
if (s.IsEmpty())
|
||||
return _length;
|
||||
int numInsertChars = s.Length();
|
||||
InsertSpace(index, numInsertChars);
|
||||
for(int i = 0; i < numInsertChars; i++)
|
||||
_chars[index + i] = s[i];
|
||||
_length += numInsertChars;
|
||||
return _length;
|
||||
}
|
||||
|
||||
// !!!!!!!!!!!!!!! test it if newChar = '\0'
|
||||
int Replace(T oldChar, T newChar)
|
||||
{
|
||||
if (oldChar == newChar)
|
||||
return 0;
|
||||
int number = 0;
|
||||
int pos = 0;
|
||||
while (pos < Length())
|
||||
{
|
||||
pos = Find(oldChar, pos);
|
||||
if (pos < 0)
|
||||
break;
|
||||
_chars[pos] = newChar;
|
||||
pos++;
|
||||
number++;
|
||||
}
|
||||
return number;
|
||||
}
|
||||
int Replace(const CStringBase &oldString, const CStringBase &newString)
|
||||
{
|
||||
if (oldString.IsEmpty())
|
||||
return 0;
|
||||
if (oldString == newString)
|
||||
return 0;
|
||||
int oldStringLength = oldString.Length();
|
||||
int newStringLength = newString.Length();
|
||||
int number = 0;
|
||||
int pos = 0;
|
||||
while (pos < _length)
|
||||
{
|
||||
pos = Find(oldString, pos);
|
||||
if (pos < 0)
|
||||
break;
|
||||
Delete(pos, oldStringLength);
|
||||
Insert(pos, newString);
|
||||
pos += newStringLength;
|
||||
number++;
|
||||
}
|
||||
return number;
|
||||
}
|
||||
int Delete(int index, int count = 1 )
|
||||
{
|
||||
if (index + count > _length)
|
||||
count = _length - index;
|
||||
if (count > 0)
|
||||
{
|
||||
MoveItems(index, index + count);
|
||||
_length -= count;
|
||||
}
|
||||
return _length;
|
||||
}
|
||||
};
|
||||
|
||||
template <class T>
|
||||
CStringBase<T> operator+(const CStringBase<T>& s1, const CStringBase<T>& s2)
|
||||
{
|
||||
CStringBase<T> result(s1);
|
||||
result += s2;
|
||||
return result;
|
||||
}
|
||||
|
||||
template <class T>
|
||||
CStringBase<T> operator+(const CStringBase<T>& s, T c)
|
||||
{
|
||||
CStringBase<T> result(s);
|
||||
result += c;
|
||||
return result;
|
||||
}
|
||||
|
||||
template <class T>
|
||||
CStringBase<T> operator+(T c, const CStringBase<T>& s)
|
||||
{
|
||||
CStringBase<T> result(c);
|
||||
result += s;
|
||||
return result;
|
||||
}
|
||||
|
||||
template <class T>
|
||||
CStringBase<T> operator+(const CStringBase<T>& s, const T * chars)
|
||||
{
|
||||
CStringBase<T> result(s);
|
||||
result += chars;
|
||||
return result;
|
||||
}
|
||||
|
||||
template <class T>
|
||||
CStringBase<T> operator+(const T * chars, const CStringBase<T>& s)
|
||||
{
|
||||
CStringBase<T> result(chars);
|
||||
result += s;
|
||||
return result;
|
||||
}
|
||||
|
||||
template <class T>
|
||||
bool operator==(const CStringBase<T>& s1, const CStringBase<T>& s2)
|
||||
{ return (s1.Compare(s2) == 0); }
|
||||
|
||||
template <class T>
|
||||
bool operator<(const CStringBase<T>& s1, const CStringBase<T>& s2)
|
||||
{ return (s1.Compare(s2) < 0); }
|
||||
|
||||
template <class T>
|
||||
bool operator==(const T *s1, const CStringBase<T>& s2)
|
||||
{ return (s2.Compare(s1) == 0); }
|
||||
|
||||
template <class T>
|
||||
bool operator==(const CStringBase<T>& s1, const T *s2)
|
||||
{ return (s1.Compare(s2) == 0); }
|
||||
|
||||
template <class T>
|
||||
bool operator!=(const CStringBase<T>& s1, const CStringBase<T>& s2)
|
||||
{ return (s1.Compare(s2) != 0); }
|
||||
|
||||
template <class T>
|
||||
bool operator!=(const T *s1, const CStringBase<T>& s2)
|
||||
{ return (s2.Compare(s1) != 0); }
|
||||
|
||||
template <class T>
|
||||
bool operator!=(const CStringBase<T>& s1, const T *s2)
|
||||
{ return (s1.Compare(s2) != 0); }
|
||||
|
||||
typedef CStringBase<char> AString;
|
||||
typedef CStringBase<wchar_t> UString;
|
||||
|
||||
typedef CObjectVector<AString> AStringVector;
|
||||
typedef CObjectVector<UString> UStringVector;
|
||||
|
||||
#ifdef _UNICODE
|
||||
typedef UString CSysString;
|
||||
#else
|
||||
typedef AString CSysString;
|
||||
#endif
|
||||
|
||||
typedef CObjectVector<CSysString> CSysStringVector;
|
||||
|
||||
#endif
|
24
lib/physfs-2.0.3/lzma/CPP/Common/MyUnknown.h
Normal file
24
lib/physfs-2.0.3/lzma/CPP/Common/MyUnknown.h
Normal file
|
@ -0,0 +1,24 @@
|
|||
// MyUnknown.h
|
||||
|
||||
#ifndef __MYUNKNOWN_H
|
||||
#define __MYUNKNOWN_H
|
||||
|
||||
#ifdef _WIN32
|
||||
|
||||
#ifdef _WIN32_WCE
|
||||
#if (_WIN32_WCE > 300)
|
||||
#include <basetyps.h>
|
||||
#else
|
||||
#define MIDL_INTERFACE(x) struct
|
||||
#endif
|
||||
#else
|
||||
#include <basetyps.h>
|
||||
#endif
|
||||
|
||||
#include <unknwn.h>
|
||||
|
||||
#else
|
||||
#include "MyWindows.h"
|
||||
#endif
|
||||
|
||||
#endif
|
78
lib/physfs-2.0.3/lzma/CPP/Common/MyVector.cpp
Normal file
78
lib/physfs-2.0.3/lzma/CPP/Common/MyVector.cpp
Normal file
|
@ -0,0 +1,78 @@
|
|||
// Common/MyVector.cpp
|
||||
|
||||
#include "StdAfx.h"
|
||||
|
||||
#include <string.h>
|
||||
|
||||
#include "MyVector.h"
|
||||
|
||||
CBaseRecordVector::~CBaseRecordVector() { Free(); }
|
||||
|
||||
void CBaseRecordVector::Free()
|
||||
{
|
||||
delete []((unsigned char *)_items);
|
||||
_capacity = 0;
|
||||
_size = 0;
|
||||
_items = 0;
|
||||
}
|
||||
|
||||
void CBaseRecordVector::Clear() { DeleteFrom(0); }
|
||||
void CBaseRecordVector::DeleteBack() { Delete(_size - 1); }
|
||||
void CBaseRecordVector::DeleteFrom(int index) { Delete(index, _size - index); }
|
||||
|
||||
void CBaseRecordVector::ReserveOnePosition()
|
||||
{
|
||||
if (_size != _capacity)
|
||||
return;
|
||||
int delta;
|
||||
if (_capacity > 64)
|
||||
delta = _capacity / 2;
|
||||
else if (_capacity > 8)
|
||||
delta = 8;
|
||||
else
|
||||
delta = 4;
|
||||
Reserve(_capacity + delta);
|
||||
}
|
||||
|
||||
void CBaseRecordVector::Reserve(int newCapacity)
|
||||
{
|
||||
if (newCapacity <= _capacity)
|
||||
return;
|
||||
if ((unsigned)newCapacity >= ((unsigned)1 << (sizeof(unsigned) * 8 - 1)))
|
||||
throw 1052353;
|
||||
size_t newSize = (size_t)(unsigned)newCapacity * _itemSize;
|
||||
if (newSize / _itemSize != (size_t)(unsigned)newCapacity)
|
||||
throw 1052354;
|
||||
unsigned char *p = new unsigned char[newSize];
|
||||
if (p == 0)
|
||||
throw 1052355;
|
||||
int numRecordsToMove = _capacity;
|
||||
memmove(p, _items, _itemSize * numRecordsToMove);
|
||||
delete [](unsigned char *)_items;
|
||||
_items = p;
|
||||
_capacity = newCapacity;
|
||||
}
|
||||
|
||||
void CBaseRecordVector::MoveItems(int destIndex, int srcIndex)
|
||||
{
|
||||
memmove(((unsigned char *)_items) + destIndex * _itemSize,
|
||||
((unsigned char *)_items) + srcIndex * _itemSize,
|
||||
_itemSize * (_size - srcIndex));
|
||||
}
|
||||
|
||||
void CBaseRecordVector::InsertOneItem(int index)
|
||||
{
|
||||
ReserveOnePosition();
|
||||
MoveItems(index + 1, index);
|
||||
_size++;
|
||||
}
|
||||
|
||||
void CBaseRecordVector::Delete(int index, int num)
|
||||
{
|
||||
TestIndexAndCorrectNum(index, num);
|
||||
if (num > 0)
|
||||
{
|
||||
MoveItems(index, index + num);
|
||||
_size -= num;
|
||||
}
|
||||
}
|
254
lib/physfs-2.0.3/lzma/CPP/Common/MyVector.h
Normal file
254
lib/physfs-2.0.3/lzma/CPP/Common/MyVector.h
Normal file
|
@ -0,0 +1,254 @@
|
|||
// Common/Vector.h
|
||||
|
||||
#ifndef __COMMON_VECTOR_H
|
||||
#define __COMMON_VECTOR_H
|
||||
|
||||
#include "Defs.h"
|
||||
|
||||
class CBaseRecordVector
|
||||
{
|
||||
void MoveItems(int destIndex, int srcIndex);
|
||||
protected:
|
||||
int _capacity;
|
||||
int _size;
|
||||
void *_items;
|
||||
size_t _itemSize;
|
||||
|
||||
void ReserveOnePosition();
|
||||
void InsertOneItem(int index);
|
||||
void TestIndexAndCorrectNum(int index, int &num) const
|
||||
{ if (index + num > _size) num = _size - index; }
|
||||
public:
|
||||
CBaseRecordVector(size_t itemSize):
|
||||
_capacity(0), _size(0), _items(0), _itemSize(itemSize) {}
|
||||
virtual ~CBaseRecordVector();
|
||||
void Free();
|
||||
int Size() const { return _size; }
|
||||
bool IsEmpty() const { return (_size == 0); }
|
||||
void Reserve(int newCapacity);
|
||||
virtual void Delete(int index, int num = 1);
|
||||
void Clear();
|
||||
void DeleteFrom(int index);
|
||||
void DeleteBack();
|
||||
};
|
||||
|
||||
template <class T>
|
||||
class CRecordVector: public CBaseRecordVector
|
||||
{
|
||||
public:
|
||||
CRecordVector():CBaseRecordVector(sizeof(T)){};
|
||||
CRecordVector(const CRecordVector &v):
|
||||
CBaseRecordVector(sizeof(T)) { *this = v;}
|
||||
CRecordVector& operator=(const CRecordVector &v)
|
||||
{
|
||||
Clear();
|
||||
return (*this += v);
|
||||
}
|
||||
CRecordVector& operator+=(const CRecordVector &v)
|
||||
{
|
||||
int size = v.Size();
|
||||
Reserve(Size() + size);
|
||||
for(int i = 0; i < size; i++)
|
||||
Add(v[i]);
|
||||
return *this;
|
||||
}
|
||||
int Add(T item)
|
||||
{
|
||||
ReserveOnePosition();
|
||||
((T *)_items)[_size] = item;
|
||||
return _size++;
|
||||
}
|
||||
void Insert(int index, T item)
|
||||
{
|
||||
InsertOneItem(index);
|
||||
((T *)_items)[index] = item;
|
||||
}
|
||||
// T* GetPointer() const { return (T*)_items; }
|
||||
// operator const T *() const { return _items; };
|
||||
const T& operator[](int index) const { return ((T *)_items)[index]; }
|
||||
T& operator[](int index) { return ((T *)_items)[index]; }
|
||||
const T& Front() const { return operator[](0); }
|
||||
T& Front() { return operator[](0); }
|
||||
const T& Back() const { return operator[](_size - 1); }
|
||||
T& Back() { return operator[](_size - 1); }
|
||||
|
||||
void Swap(int i, int j)
|
||||
{
|
||||
T temp = operator[](i);
|
||||
operator[](i) = operator[](j);
|
||||
operator[](j) = temp;
|
||||
}
|
||||
|
||||
int FindInSorted(const T& item) const
|
||||
{
|
||||
int left = 0, right = Size();
|
||||
while (left != right)
|
||||
{
|
||||
int mid = (left + right) / 2;
|
||||
const T& midValue = (*this)[mid];
|
||||
if (item == midValue)
|
||||
return mid;
|
||||
if (item < midValue)
|
||||
right = mid;
|
||||
else
|
||||
left = mid + 1;
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
int AddToUniqueSorted(const T& item)
|
||||
{
|
||||
int left = 0, right = Size();
|
||||
while (left != right)
|
||||
{
|
||||
int mid = (left + right) / 2;
|
||||
const T& midValue = (*this)[mid];
|
||||
if (item == midValue)
|
||||
return mid;
|
||||
if (item < midValue)
|
||||
right = mid;
|
||||
else
|
||||
left = mid + 1;
|
||||
}
|
||||
Insert(right, item);
|
||||
return right;
|
||||
}
|
||||
|
||||
static void SortRefDown(T* p, int k, int size, int (*compare)(const T*, const T*, void *), void *param)
|
||||
{
|
||||
T temp = p[k];
|
||||
for (;;)
|
||||
{
|
||||
int s = (k << 1);
|
||||
if (s > size)
|
||||
break;
|
||||
if (s < size && compare(p + s + 1, p + s, param) > 0)
|
||||
s++;
|
||||
if (compare(&temp, p + s, param) >= 0)
|
||||
break;
|
||||
p[k] = p[s];
|
||||
k = s;
|
||||
}
|
||||
p[k] = temp;
|
||||
}
|
||||
|
||||
void Sort(int (*compare)(const T*, const T*, void *), void *param)
|
||||
{
|
||||
int size = _size;
|
||||
if (size <= 1)
|
||||
return;
|
||||
T* p = (&Front()) - 1;
|
||||
{
|
||||
int i = size / 2;
|
||||
do
|
||||
SortRefDown(p, i, size, compare, param);
|
||||
while(--i != 0);
|
||||
}
|
||||
do
|
||||
{
|
||||
T temp = p[size];
|
||||
p[size--] = p[1];
|
||||
p[1] = temp;
|
||||
SortRefDown(p, 1, size, compare, param);
|
||||
}
|
||||
while (size > 1);
|
||||
}
|
||||
};
|
||||
|
||||
typedef CRecordVector<int> CIntVector;
|
||||
typedef CRecordVector<unsigned int> CUIntVector;
|
||||
typedef CRecordVector<bool> CBoolVector;
|
||||
typedef CRecordVector<unsigned char> CByteVector;
|
||||
typedef CRecordVector<void *> CPointerVector;
|
||||
|
||||
template <class T>
|
||||
class CObjectVector: public CPointerVector
|
||||
{
|
||||
public:
|
||||
CObjectVector(){};
|
||||
~CObjectVector() { Clear(); }
|
||||
CObjectVector(const CObjectVector &objectVector)
|
||||
{ *this = objectVector; }
|
||||
CObjectVector& operator=(const CObjectVector &objectVector)
|
||||
{
|
||||
Clear();
|
||||
return (*this += objectVector);
|
||||
}
|
||||
CObjectVector& operator+=(const CObjectVector &objectVector)
|
||||
{
|
||||
int size = objectVector.Size();
|
||||
Reserve(Size() + size);
|
||||
for(int i = 0; i < size; i++)
|
||||
Add(objectVector[i]);
|
||||
return *this;
|
||||
}
|
||||
const T& operator[](int index) const { return *((T *)CPointerVector::operator[](index)); }
|
||||
T& operator[](int index) { return *((T *)CPointerVector::operator[](index)); }
|
||||
T& Front() { return operator[](0); }
|
||||
const T& Front() const { return operator[](0); }
|
||||
T& Back() { return operator[](_size - 1); }
|
||||
const T& Back() const { return operator[](_size - 1); }
|
||||
int Add(const T& item)
|
||||
{ return CPointerVector::Add(new T(item)); }
|
||||
void Insert(int index, const T& item)
|
||||
{ CPointerVector::Insert(index, new T(item)); }
|
||||
virtual void Delete(int index, int num = 1)
|
||||
{
|
||||
TestIndexAndCorrectNum(index, num);
|
||||
for(int i = 0; i < num; i++)
|
||||
delete (T *)(((void **)_items)[index + i]);
|
||||
CPointerVector::Delete(index, num);
|
||||
}
|
||||
int Find(const T& item) const
|
||||
{
|
||||
for(int i = 0; i < Size(); i++)
|
||||
if (item == (*this)[i])
|
||||
return i;
|
||||
return -1;
|
||||
}
|
||||
int FindInSorted(const T& item) const
|
||||
{
|
||||
int left = 0, right = Size();
|
||||
while (left != right)
|
||||
{
|
||||
int mid = (left + right) / 2;
|
||||
const T& midValue = (*this)[mid];
|
||||
if (item == midValue)
|
||||
return mid;
|
||||
if (item < midValue)
|
||||
right = mid;
|
||||
else
|
||||
left = mid + 1;
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
int AddToSorted(const T& item)
|
||||
{
|
||||
int left = 0, right = Size();
|
||||
while (left != right)
|
||||
{
|
||||
int mid = (left + right) / 2;
|
||||
const T& midValue = (*this)[mid];
|
||||
if (item == midValue)
|
||||
{
|
||||
right = mid + 1;
|
||||
break;
|
||||
}
|
||||
if (item < midValue)
|
||||
right = mid;
|
||||
else
|
||||
left = mid + 1;
|
||||
}
|
||||
Insert(right, item);
|
||||
return right;
|
||||
}
|
||||
|
||||
void Sort(int (*compare)(void *const *, void *const *, void *), void *param)
|
||||
{ CPointerVector::Sort(compare, param); }
|
||||
|
||||
static int CompareObjectItems(void *const *a1, void *const *a2, void * /* param */)
|
||||
{ return MyCompare(*(*((const T **)a1)), *(*((const T **)a2))); }
|
||||
void Sort() { CPointerVector::Sort(CompareObjectItems, 0); }
|
||||
};
|
||||
|
||||
#endif
|
214
lib/physfs-2.0.3/lzma/CPP/Common/MyWindows.h
Normal file
214
lib/physfs-2.0.3/lzma/CPP/Common/MyWindows.h
Normal file
|
@ -0,0 +1,214 @@
|
|||
// MyWindows.h
|
||||
|
||||
#ifndef __MYWINDOWS_H
|
||||
#define __MYWINDOWS_H
|
||||
|
||||
#ifdef _WIN32
|
||||
|
||||
#include <windows.h>
|
||||
|
||||
#define CHAR_PATH_SEPARATOR '\\'
|
||||
#define WCHAR_PATH_SEPARATOR L'\\'
|
||||
#define STRING_PATH_SEPARATOR "\\"
|
||||
#define WSTRING_PATH_SEPARATOR L"\\"
|
||||
|
||||
#else
|
||||
|
||||
#define CHAR_PATH_SEPARATOR '/'
|
||||
#define WCHAR_PATH_SEPARATOR L'/'
|
||||
#define STRING_PATH_SEPARATOR "/"
|
||||
#define WSTRING_PATH_SEPARATOR L"/"
|
||||
|
||||
#include <stddef.h> // for wchar_t
|
||||
#include <string.h>
|
||||
|
||||
#include "MyGuidDef.h"
|
||||
|
||||
typedef char CHAR;
|
||||
typedef unsigned char UCHAR;
|
||||
|
||||
#undef BYTE
|
||||
typedef unsigned char BYTE;
|
||||
|
||||
typedef short SHORT;
|
||||
typedef unsigned short USHORT;
|
||||
|
||||
#undef WORD
|
||||
typedef unsigned short WORD;
|
||||
typedef short VARIANT_BOOL;
|
||||
|
||||
typedef int INT;
|
||||
typedef Int32 INT32;
|
||||
typedef unsigned int UINT;
|
||||
typedef UInt32 UINT32;
|
||||
typedef INT32 LONG; // LONG, ULONG and DWORD must be 32-bit
|
||||
typedef UINT32 ULONG;
|
||||
|
||||
#undef DWORD
|
||||
typedef UINT32 DWORD;
|
||||
|
||||
typedef Int64 LONGLONG;
|
||||
typedef UInt64 ULONGLONG;
|
||||
|
||||
typedef struct LARGE_INTEGER { LONGLONG QuadPart; }LARGE_INTEGER;
|
||||
typedef struct _ULARGE_INTEGER { ULONGLONG QuadPart;} ULARGE_INTEGER;
|
||||
|
||||
typedef const CHAR *LPCSTR;
|
||||
typedef CHAR TCHAR;
|
||||
typedef const TCHAR *LPCTSTR;
|
||||
typedef wchar_t WCHAR;
|
||||
typedef WCHAR OLECHAR;
|
||||
typedef const WCHAR *LPCWSTR;
|
||||
typedef OLECHAR *BSTR;
|
||||
typedef const OLECHAR *LPCOLESTR;
|
||||
typedef OLECHAR *LPOLESTR;
|
||||
|
||||
typedef struct _FILETIME
|
||||
{
|
||||
DWORD dwLowDateTime;
|
||||
DWORD dwHighDateTime;
|
||||
}FILETIME;
|
||||
|
||||
#define HRESULT LONG
|
||||
#define FAILED(Status) ((HRESULT)(Status)<0)
|
||||
typedef ULONG PROPID;
|
||||
typedef LONG SCODE;
|
||||
|
||||
#define S_OK ((HRESULT)0x00000000L)
|
||||
#define S_FALSE ((HRESULT)0x00000001L)
|
||||
#define E_NOTIMPL ((HRESULT)0x80004001L)
|
||||
#define E_NOINTERFACE ((HRESULT)0x80004002L)
|
||||
#define E_ABORT ((HRESULT)0x80004004L)
|
||||
#define E_FAIL ((HRESULT)0x80004005L)
|
||||
#define STG_E_INVALIDFUNCTION ((HRESULT)0x80030001L)
|
||||
#define E_OUTOFMEMORY ((HRESULT)0x8007000EL)
|
||||
#define E_INVALIDARG ((HRESULT)0x80070057L)
|
||||
|
||||
#ifdef _MSC_VER
|
||||
#define STDMETHODCALLTYPE __stdcall
|
||||
#else
|
||||
#define STDMETHODCALLTYPE
|
||||
#endif
|
||||
|
||||
#define STDMETHOD_(t, f) virtual t STDMETHODCALLTYPE f
|
||||
#define STDMETHOD(f) STDMETHOD_(HRESULT, f)
|
||||
#define STDMETHODIMP_(type) type STDMETHODCALLTYPE
|
||||
#define STDMETHODIMP STDMETHODIMP_(HRESULT)
|
||||
|
||||
#define PURE = 0
|
||||
|
||||
#define MIDL_INTERFACE(x) struct
|
||||
|
||||
#ifdef __cplusplus
|
||||
|
||||
DEFINE_GUID(IID_IUnknown,
|
||||
0x00000000, 0x0000, 0x0000, 0xC0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x46);
|
||||
struct IUnknown
|
||||
{
|
||||
STDMETHOD(QueryInterface) (REFIID iid, void **outObject) PURE;
|
||||
STDMETHOD_(ULONG, AddRef)() PURE;
|
||||
STDMETHOD_(ULONG, Release)() PURE;
|
||||
#ifndef _WIN32
|
||||
virtual ~IUnknown() {}
|
||||
#endif
|
||||
};
|
||||
|
||||
typedef IUnknown *LPUNKNOWN;
|
||||
|
||||
#endif
|
||||
|
||||
#define VARIANT_TRUE ((VARIANT_BOOL)-1)
|
||||
#define VARIANT_FALSE ((VARIANT_BOOL)0)
|
||||
|
||||
enum VARENUM
|
||||
{
|
||||
VT_EMPTY = 0,
|
||||
VT_NULL = 1,
|
||||
VT_I2 = 2,
|
||||
VT_I4 = 3,
|
||||
VT_R4 = 4,
|
||||
VT_R8 = 5,
|
||||
VT_CY = 6,
|
||||
VT_DATE = 7,
|
||||
VT_BSTR = 8,
|
||||
VT_DISPATCH = 9,
|
||||
VT_ERROR = 10,
|
||||
VT_BOOL = 11,
|
||||
VT_VARIANT = 12,
|
||||
VT_UNKNOWN = 13,
|
||||
VT_DECIMAL = 14,
|
||||
VT_I1 = 16,
|
||||
VT_UI1 = 17,
|
||||
VT_UI2 = 18,
|
||||
VT_UI4 = 19,
|
||||
VT_I8 = 20,
|
||||
VT_UI8 = 21,
|
||||
VT_INT = 22,
|
||||
VT_UINT = 23,
|
||||
VT_VOID = 24,
|
||||
VT_HRESULT = 25,
|
||||
VT_FILETIME = 64
|
||||
};
|
||||
|
||||
typedef unsigned short VARTYPE;
|
||||
typedef WORD PROPVAR_PAD1;
|
||||
typedef WORD PROPVAR_PAD2;
|
||||
typedef WORD PROPVAR_PAD3;
|
||||
|
||||
#ifdef __cplusplus
|
||||
|
||||
typedef struct tagPROPVARIANT
|
||||
{
|
||||
VARTYPE vt;
|
||||
PROPVAR_PAD1 wReserved1;
|
||||
PROPVAR_PAD2 wReserved2;
|
||||
PROPVAR_PAD3 wReserved3;
|
||||
union
|
||||
{
|
||||
CHAR cVal;
|
||||
UCHAR bVal;
|
||||
SHORT iVal;
|
||||
USHORT uiVal;
|
||||
LONG lVal;
|
||||
ULONG ulVal;
|
||||
INT intVal;
|
||||
UINT uintVal;
|
||||
LARGE_INTEGER hVal;
|
||||
ULARGE_INTEGER uhVal;
|
||||
VARIANT_BOOL boolVal;
|
||||
SCODE scode;
|
||||
FILETIME filetime;
|
||||
BSTR bstrVal;
|
||||
};
|
||||
} PROPVARIANT;
|
||||
|
||||
typedef PROPVARIANT tagVARIANT;
|
||||
typedef tagVARIANT VARIANT;
|
||||
typedef VARIANT VARIANTARG;
|
||||
|
||||
MY_EXTERN_C HRESULT VariantClear(VARIANTARG *prop);
|
||||
MY_EXTERN_C HRESULT VariantCopy(VARIANTARG *dest, VARIANTARG *src);
|
||||
|
||||
#endif
|
||||
|
||||
MY_EXTERN_C BSTR SysAllocStringByteLen(LPCSTR psz, UINT len);
|
||||
MY_EXTERN_C BSTR SysAllocString(const OLECHAR *sz);
|
||||
MY_EXTERN_C void SysFreeString(BSTR bstr);
|
||||
MY_EXTERN_C UINT SysStringByteLen(BSTR bstr);
|
||||
MY_EXTERN_C UINT SysStringLen(BSTR bstr);
|
||||
|
||||
MY_EXTERN_C DWORD GetLastError();
|
||||
MY_EXTERN_C LONG CompareFileTime(const FILETIME* ft1, const FILETIME* ft2);
|
||||
|
||||
#define CP_ACP 0
|
||||
#define CP_OEMCP 1
|
||||
|
||||
typedef enum tagSTREAM_SEEK
|
||||
{
|
||||
STREAM_SEEK_SET = 0,
|
||||
STREAM_SEEK_CUR = 1,
|
||||
STREAM_SEEK_END = 2
|
||||
} STREAM_SEEK;
|
||||
|
||||
#endif
|
||||
#endif
|
116
lib/physfs-2.0.3/lzma/CPP/Common/NewHandler.cpp
Normal file
116
lib/physfs-2.0.3/lzma/CPP/Common/NewHandler.cpp
Normal file
|
@ -0,0 +1,116 @@
|
|||
// NewHandler.cpp
|
||||
|
||||
#include "StdAfx.h"
|
||||
|
||||
#include <stdlib.h>
|
||||
|
||||
#include "NewHandler.h"
|
||||
|
||||
// #define DEBUG_MEMORY_LEAK
|
||||
|
||||
#ifndef DEBUG_MEMORY_LEAK
|
||||
|
||||
#ifdef _WIN32
|
||||
void *
|
||||
#ifdef _MSC_VER
|
||||
__cdecl
|
||||
#endif
|
||||
operator new(size_t size)
|
||||
{
|
||||
// void *p = ::HeapAlloc(::GetProcessHeap(), 0, size);
|
||||
void *p = ::malloc(size);
|
||||
if (p == 0)
|
||||
throw CNewException();
|
||||
return p;
|
||||
}
|
||||
|
||||
void
|
||||
#ifdef _MSC_VER
|
||||
__cdecl
|
||||
#endif
|
||||
operator delete(void *p) throw()
|
||||
{
|
||||
/*
|
||||
if (p == 0)
|
||||
return;
|
||||
::HeapFree(::GetProcessHeap(), 0, p);
|
||||
*/
|
||||
::free(p);
|
||||
}
|
||||
#endif
|
||||
|
||||
#else
|
||||
|
||||
#pragma init_seg(lib)
|
||||
const int kDebugSize = 1000000;
|
||||
static void *a[kDebugSize];
|
||||
static int index = 0;
|
||||
|
||||
static int numAllocs = 0;
|
||||
void * __cdecl operator new(size_t size)
|
||||
{
|
||||
numAllocs++;
|
||||
void *p = HeapAlloc(GetProcessHeap(), 0, size);
|
||||
if (index == 40)
|
||||
{
|
||||
int t = 1;
|
||||
}
|
||||
if (index < kDebugSize)
|
||||
{
|
||||
a[index] = p;
|
||||
index++;
|
||||
}
|
||||
if (p == 0)
|
||||
throw CNewException();
|
||||
printf("Alloc %6d, size = %8d\n", numAllocs, size);
|
||||
return p;
|
||||
}
|
||||
|
||||
class CC
|
||||
{
|
||||
public:
|
||||
CC()
|
||||
{
|
||||
for (int i = 0; i < kDebugSize; i++)
|
||||
a[i] = 0;
|
||||
}
|
||||
~CC()
|
||||
{
|
||||
for (int i = 0; i < kDebugSize; i++)
|
||||
if (a[i] != 0)
|
||||
return;
|
||||
}
|
||||
} g_CC;
|
||||
|
||||
|
||||
void __cdecl operator delete(void *p)
|
||||
{
|
||||
if (p == 0)
|
||||
return;
|
||||
/*
|
||||
for (int i = 0; i < index; i++)
|
||||
if (a[i] == p)
|
||||
a[i] = 0;
|
||||
*/
|
||||
HeapFree(GetProcessHeap(), 0, p);
|
||||
numAllocs--;
|
||||
printf("Free %d\n", numAllocs);
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
/*
|
||||
int MemErrorVC(size_t)
|
||||
{
|
||||
throw CNewException();
|
||||
// return 1;
|
||||
}
|
||||
CNewHandlerSetter::CNewHandlerSetter()
|
||||
{
|
||||
// MemErrorOldVCFunction = _set_new_handler(MemErrorVC);
|
||||
}
|
||||
CNewHandlerSetter::~CNewHandlerSetter()
|
||||
{
|
||||
// _set_new_handler(MemErrorOldVCFunction);
|
||||
}
|
||||
*/
|
16
lib/physfs-2.0.3/lzma/CPP/Common/NewHandler.h
Normal file
16
lib/physfs-2.0.3/lzma/CPP/Common/NewHandler.h
Normal file
|
@ -0,0 +1,16 @@
|
|||
// Common/NewHandler.h
|
||||
|
||||
#ifndef __COMMON_NEWHANDLER_H
|
||||
#define __COMMON_NEWHANDLER_H
|
||||
|
||||
class CNewException {};
|
||||
|
||||
#ifdef _WIN32
|
||||
void
|
||||
#ifdef _MSC_VER
|
||||
__cdecl
|
||||
#endif
|
||||
operator delete(void *p) throw();
|
||||
#endif
|
||||
|
||||
#endif
|
9
lib/physfs-2.0.3/lzma/CPP/Common/StdAfx.h
Normal file
9
lib/physfs-2.0.3/lzma/CPP/Common/StdAfx.h
Normal file
|
@ -0,0 +1,9 @@
|
|||
// StdAfx.h
|
||||
|
||||
#ifndef __STDAFX_H
|
||||
#define __STDAFX_H
|
||||
|
||||
// #include "MyWindows.h"
|
||||
#include "NewHandler.h"
|
||||
|
||||
#endif
|
84
lib/physfs-2.0.3/lzma/CPP/Common/StdInStream.cpp
Normal file
84
lib/physfs-2.0.3/lzma/CPP/Common/StdInStream.cpp
Normal file
|
@ -0,0 +1,84 @@
|
|||
// Common/StdInStream.cpp
|
||||
|
||||
#include "StdAfx.h"
|
||||
|
||||
#include <tchar.h>
|
||||
#include "StdInStream.h"
|
||||
|
||||
#ifdef _MSC_VER
|
||||
// "was declared deprecated" disabling
|
||||
#pragma warning(disable : 4996 )
|
||||
#endif
|
||||
|
||||
static const char kIllegalChar = '\0';
|
||||
static const char kNewLineChar = '\n';
|
||||
|
||||
static const char *kEOFMessage = "Unexpected end of input stream";
|
||||
static const char *kReadErrorMessage ="Error reading input stream";
|
||||
static const char *kIllegalCharMessage = "Illegal character in input stream";
|
||||
|
||||
static LPCTSTR kFileOpenMode = TEXT("r");
|
||||
|
||||
CStdInStream g_StdIn(stdin);
|
||||
|
||||
bool CStdInStream::Open(LPCTSTR fileName)
|
||||
{
|
||||
Close();
|
||||
_stream = _tfopen(fileName, kFileOpenMode);
|
||||
_streamIsOpen = (_stream != 0);
|
||||
return _streamIsOpen;
|
||||
}
|
||||
|
||||
bool CStdInStream::Close()
|
||||
{
|
||||
if(!_streamIsOpen)
|
||||
return true;
|
||||
_streamIsOpen = (fclose(_stream) != 0);
|
||||
return !_streamIsOpen;
|
||||
}
|
||||
|
||||
CStdInStream::~CStdInStream()
|
||||
{
|
||||
Close();
|
||||
}
|
||||
|
||||
AString CStdInStream::ScanStringUntilNewLine()
|
||||
{
|
||||
AString s;
|
||||
for (;;)
|
||||
{
|
||||
int intChar = GetChar();
|
||||
if(intChar == EOF)
|
||||
throw kEOFMessage;
|
||||
char c = char(intChar);
|
||||
if (c == kIllegalChar)
|
||||
throw kIllegalCharMessage;
|
||||
if(c == kNewLineChar)
|
||||
break;
|
||||
s += c;
|
||||
}
|
||||
return s;
|
||||
}
|
||||
|
||||
void CStdInStream::ReadToString(AString &resultString)
|
||||
{
|
||||
resultString.Empty();
|
||||
int c;
|
||||
while((c = GetChar()) != EOF)
|
||||
resultString += char(c);
|
||||
}
|
||||
|
||||
bool CStdInStream::Eof()
|
||||
{
|
||||
return (feof(_stream) != 0);
|
||||
}
|
||||
|
||||
int CStdInStream::GetChar()
|
||||
{
|
||||
int c = fgetc(_stream); // getc() doesn't work in BeOS?
|
||||
if(c == EOF && !Eof())
|
||||
throw kReadErrorMessage;
|
||||
return c;
|
||||
}
|
||||
|
||||
|
31
lib/physfs-2.0.3/lzma/CPP/Common/StdInStream.h
Normal file
31
lib/physfs-2.0.3/lzma/CPP/Common/StdInStream.h
Normal file
|
@ -0,0 +1,31 @@
|
|||
// Common/StdInStream.h
|
||||
|
||||
#ifndef __COMMON_STDINSTREAM_H
|
||||
#define __COMMON_STDINSTREAM_H
|
||||
|
||||
#include <stdio.h>
|
||||
|
||||
#include "MyString.h"
|
||||
#include "Types.h"
|
||||
|
||||
class CStdInStream
|
||||
{
|
||||
bool _streamIsOpen;
|
||||
FILE *_stream;
|
||||
public:
|
||||
CStdInStream(): _streamIsOpen(false) {};
|
||||
CStdInStream(FILE *stream): _streamIsOpen(false), _stream(stream) {};
|
||||
~CStdInStream();
|
||||
bool Open(LPCTSTR fileName);
|
||||
bool Close();
|
||||
|
||||
AString ScanStringUntilNewLine();
|
||||
void ReadToString(AString &resultString);
|
||||
|
||||
bool Eof();
|
||||
int GetChar();
|
||||
};
|
||||
|
||||
extern CStdInStream g_StdIn;
|
||||
|
||||
#endif
|
93
lib/physfs-2.0.3/lzma/CPP/Common/StdOutStream.cpp
Normal file
93
lib/physfs-2.0.3/lzma/CPP/Common/StdOutStream.cpp
Normal file
|
@ -0,0 +1,93 @@
|
|||
// Common/StdOutStream.cpp
|
||||
|
||||
#include "StdAfx.h"
|
||||
|
||||
#include <tchar.h>
|
||||
|
||||
#include "StdOutStream.h"
|
||||
#include "IntToString.h"
|
||||
#include "StringConvert.h"
|
||||
|
||||
#ifdef _MSC_VER
|
||||
// "was declared deprecated" disabling
|
||||
#pragma warning(disable : 4996 )
|
||||
#endif
|
||||
|
||||
static const char kNewLineChar = '\n';
|
||||
|
||||
static const char *kFileOpenMode = "wt";
|
||||
|
||||
CStdOutStream g_StdOut(stdout);
|
||||
CStdOutStream g_StdErr(stderr);
|
||||
|
||||
bool CStdOutStream::Open(const char *fileName)
|
||||
{
|
||||
Close();
|
||||
_stream = fopen(fileName, kFileOpenMode);
|
||||
_streamIsOpen = (_stream != 0);
|
||||
return _streamIsOpen;
|
||||
}
|
||||
|
||||
bool CStdOutStream::Close()
|
||||
{
|
||||
if(!_streamIsOpen)
|
||||
return true;
|
||||
if (fclose(_stream) != 0)
|
||||
return false;
|
||||
_stream = 0;
|
||||
_streamIsOpen = false;
|
||||
return true;
|
||||
}
|
||||
|
||||
bool CStdOutStream::Flush()
|
||||
{
|
||||
return (fflush(_stream) == 0);
|
||||
}
|
||||
|
||||
CStdOutStream::~CStdOutStream ()
|
||||
{
|
||||
Close();
|
||||
}
|
||||
|
||||
CStdOutStream & CStdOutStream::operator<<(CStdOutStream & (*aFunction)(CStdOutStream &))
|
||||
{
|
||||
(*aFunction)(*this);
|
||||
return *this;
|
||||
}
|
||||
|
||||
CStdOutStream & endl(CStdOutStream & outStream)
|
||||
{
|
||||
return outStream << kNewLineChar;
|
||||
}
|
||||
|
||||
CStdOutStream & CStdOutStream::operator<<(const char *string)
|
||||
{
|
||||
fputs(string, _stream);
|
||||
return *this;
|
||||
}
|
||||
|
||||
CStdOutStream & CStdOutStream::operator<<(const wchar_t *string)
|
||||
{
|
||||
*this << (const char *)UnicodeStringToMultiByte(string, CP_OEMCP);
|
||||
return *this;
|
||||
}
|
||||
|
||||
CStdOutStream & CStdOutStream::operator<<(char c)
|
||||
{
|
||||
fputc(c, _stream);
|
||||
return *this;
|
||||
}
|
||||
|
||||
CStdOutStream & CStdOutStream::operator<<(int number)
|
||||
{
|
||||
char textString[32];
|
||||
ConvertInt64ToString(number, textString);
|
||||
return operator<<(textString);
|
||||
}
|
||||
|
||||
CStdOutStream & CStdOutStream::operator<<(UInt64 number)
|
||||
{
|
||||
char textString[32];
|
||||
ConvertUInt64ToString(number, textString);
|
||||
return operator<<(textString);
|
||||
}
|
35
lib/physfs-2.0.3/lzma/CPP/Common/StdOutStream.h
Normal file
35
lib/physfs-2.0.3/lzma/CPP/Common/StdOutStream.h
Normal file
|
@ -0,0 +1,35 @@
|
|||
// Common/StdOutStream.h
|
||||
|
||||
#ifndef __COMMON_STDOUTSTREAM_H
|
||||
#define __COMMON_STDOUTSTREAM_H
|
||||
|
||||
#include <stdio.h>
|
||||
|
||||
#include "Types.h"
|
||||
|
||||
class CStdOutStream
|
||||
{
|
||||
bool _streamIsOpen;
|
||||
FILE *_stream;
|
||||
public:
|
||||
CStdOutStream (): _streamIsOpen(false), _stream(0) {};
|
||||
CStdOutStream (FILE *stream): _streamIsOpen(false), _stream(stream) {};
|
||||
~CStdOutStream ();
|
||||
operator FILE *() { return _stream; }
|
||||
bool Open(const char *fileName);
|
||||
bool Close();
|
||||
bool Flush();
|
||||
CStdOutStream & operator<<(CStdOutStream & (* aFunction)(CStdOutStream &));
|
||||
CStdOutStream & operator<<(const char *string);
|
||||
CStdOutStream & operator<<(const wchar_t *string);
|
||||
CStdOutStream & operator<<(char c);
|
||||
CStdOutStream & operator<<(int number);
|
||||
CStdOutStream & operator<<(UInt64 number);
|
||||
};
|
||||
|
||||
CStdOutStream & endl(CStdOutStream & outStream);
|
||||
|
||||
extern CStdOutStream g_StdOut;
|
||||
extern CStdOutStream g_StdErr;
|
||||
|
||||
#endif
|
94
lib/physfs-2.0.3/lzma/CPP/Common/StringConvert.cpp
Normal file
94
lib/physfs-2.0.3/lzma/CPP/Common/StringConvert.cpp
Normal file
|
@ -0,0 +1,94 @@
|
|||
// Common/StringConvert.cpp
|
||||
|
||||
#include "StdAfx.h"
|
||||
|
||||
#include "StringConvert.h"
|
||||
|
||||
#ifndef _WIN32
|
||||
#include <stdlib.h>
|
||||
#endif
|
||||
|
||||
#ifdef _WIN32
|
||||
UString MultiByteToUnicodeString(const AString &srcString, UINT codePage)
|
||||
{
|
||||
UString resultString;
|
||||
if(!srcString.IsEmpty())
|
||||
{
|
||||
int numChars = MultiByteToWideChar(codePage, 0, srcString,
|
||||
srcString.Length(), resultString.GetBuffer(srcString.Length()),
|
||||
srcString.Length() + 1);
|
||||
#ifndef _WIN32_WCE
|
||||
if(numChars == 0)
|
||||
throw 282228;
|
||||
#endif
|
||||
resultString.ReleaseBuffer(numChars);
|
||||
}
|
||||
return resultString;
|
||||
}
|
||||
|
||||
AString UnicodeStringToMultiByte(const UString &srcString, UINT codePage)
|
||||
{
|
||||
AString resultString;
|
||||
if(!srcString.IsEmpty())
|
||||
{
|
||||
int numRequiredBytes = srcString.Length() * 2;
|
||||
char defaultChar = '_';
|
||||
int numChars = WideCharToMultiByte(codePage, 0, srcString,
|
||||
srcString.Length(), resultString.GetBuffer(numRequiredBytes),
|
||||
numRequiredBytes + 1, &defaultChar, NULL);
|
||||
#ifndef _WIN32_WCE
|
||||
if(numChars == 0)
|
||||
throw 282229;
|
||||
#endif
|
||||
resultString.ReleaseBuffer(numChars);
|
||||
}
|
||||
return resultString;
|
||||
}
|
||||
|
||||
#ifndef _WIN32_WCE
|
||||
AString SystemStringToOemString(const CSysString &srcString)
|
||||
{
|
||||
AString result;
|
||||
CharToOem(srcString, result.GetBuffer(srcString.Length() * 2));
|
||||
result.ReleaseBuffer();
|
||||
return result;
|
||||
}
|
||||
#endif
|
||||
|
||||
#else
|
||||
|
||||
UString MultiByteToUnicodeString(const AString &srcString, UINT codePage)
|
||||
{
|
||||
UString resultString;
|
||||
for (int i = 0; i < srcString.Length(); i++)
|
||||
resultString += wchar_t(srcString[i]);
|
||||
/*
|
||||
if(!srcString.IsEmpty())
|
||||
{
|
||||
int numChars = mbstowcs(resultString.GetBuffer(srcString.Length()), srcString, srcString.Length() + 1);
|
||||
if (numChars < 0) throw "Your environment does not support UNICODE";
|
||||
resultString.ReleaseBuffer(numChars);
|
||||
}
|
||||
*/
|
||||
return resultString;
|
||||
}
|
||||
|
||||
AString UnicodeStringToMultiByte(const UString &srcString, UINT codePage)
|
||||
{
|
||||
AString resultString;
|
||||
for (int i = 0; i < srcString.Length(); i++)
|
||||
resultString += char(srcString[i]);
|
||||
/*
|
||||
if(!srcString.IsEmpty())
|
||||
{
|
||||
int numRequiredBytes = srcString.Length() * 6 + 1;
|
||||
int numChars = wcstombs(resultString.GetBuffer(numRequiredBytes), srcString, numRequiredBytes);
|
||||
if (numChars < 0) throw "Your environment does not support UNICODE";
|
||||
resultString.ReleaseBuffer(numChars);
|
||||
}
|
||||
*/
|
||||
return resultString;
|
||||
}
|
||||
|
||||
#endif
|
||||
|
71
lib/physfs-2.0.3/lzma/CPP/Common/StringConvert.h
Normal file
71
lib/physfs-2.0.3/lzma/CPP/Common/StringConvert.h
Normal file
|
@ -0,0 +1,71 @@
|
|||
// Common/StringConvert.h
|
||||
|
||||
#ifndef __COMMON_STRINGCONVERT_H
|
||||
#define __COMMON_STRINGCONVERT_H
|
||||
|
||||
#include "MyWindows.h"
|
||||
#include "MyString.h"
|
||||
#include "Types.h"
|
||||
|
||||
UString MultiByteToUnicodeString(const AString &srcString, UINT codePage = CP_ACP);
|
||||
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)
|
||||
{ return unicodeString; }
|
||||
inline UString GetUnicodeString(const AString &ansiString)
|
||||
{ return MultiByteToUnicodeString(ansiString); }
|
||||
inline UString GetUnicodeString(const AString &multiByteString, UINT codePage)
|
||||
{ return MultiByteToUnicodeString(multiByteString, codePage); }
|
||||
inline const wchar_t* GetUnicodeString(const wchar_t* unicodeString, UINT)
|
||||
{ return unicodeString; }
|
||||
inline const UString& GetUnicodeString(const UString &unicodeString, UINT)
|
||||
{ return unicodeString; }
|
||||
|
||||
inline const char* GetAnsiString(const char* ansiString)
|
||||
{ return ansiString; }
|
||||
inline const AString& GetAnsiString(const AString &ansiString)
|
||||
{ return ansiString; }
|
||||
inline AString GetAnsiString(const UString &unicodeString)
|
||||
{ return UnicodeStringToMultiByte(unicodeString); }
|
||||
|
||||
inline const char* GetOemString(const char* oemString)
|
||||
{ return oemString; }
|
||||
inline const AString& GetOemString(const AString &oemString)
|
||||
{ return oemString; }
|
||||
inline AString GetOemString(const UString &unicodeString)
|
||||
{ return UnicodeStringToMultiByte(unicodeString, CP_OEMCP); }
|
||||
|
||||
|
||||
#ifdef _UNICODE
|
||||
inline const wchar_t* GetSystemString(const wchar_t* unicodeString)
|
||||
{ return unicodeString;}
|
||||
inline const UString& GetSystemString(const UString &unicodeString)
|
||||
{ return unicodeString;}
|
||||
inline const wchar_t* GetSystemString(const wchar_t* unicodeString, UINT /* codePage */)
|
||||
{ return unicodeString;}
|
||||
inline const UString& GetSystemString(const UString &unicodeString, UINT /* codePage */)
|
||||
{ return unicodeString;}
|
||||
inline UString GetSystemString(const AString &multiByteString, UINT codePage)
|
||||
{ return MultiByteToUnicodeString(multiByteString, codePage);}
|
||||
inline UString GetSystemString(const AString &multiByteString)
|
||||
{ return MultiByteToUnicodeString(multiByteString);}
|
||||
#else
|
||||
inline const char* GetSystemString(const char *ansiString)
|
||||
{ return ansiString; }
|
||||
inline const AString& GetSystemString(const AString &multiByteString, UINT)
|
||||
{ return multiByteString; }
|
||||
inline const char * GetSystemString(const char *multiByteString, UINT)
|
||||
{ return multiByteString; }
|
||||
inline AString GetSystemString(const UString &unicodeString)
|
||||
{ return UnicodeStringToMultiByte(unicodeString); }
|
||||
inline AString GetSystemString(const UString &unicodeString, UINT codePage)
|
||||
{ return UnicodeStringToMultiByte(unicodeString, codePage); }
|
||||
#endif
|
||||
|
||||
#ifndef _WIN32_WCE
|
||||
AString SystemStringToOemString(const CSysString &srcString);
|
||||
#endif
|
||||
|
||||
#endif
|
68
lib/physfs-2.0.3/lzma/CPP/Common/StringToInt.cpp
Normal file
68
lib/physfs-2.0.3/lzma/CPP/Common/StringToInt.cpp
Normal file
|
@ -0,0 +1,68 @@
|
|||
// Common/StringToInt.cpp
|
||||
|
||||
#include "StdAfx.h"
|
||||
|
||||
#include "StringToInt.h"
|
||||
|
||||
UInt64 ConvertStringToUInt64(const char *s, const char **end)
|
||||
{
|
||||
UInt64 result = 0;
|
||||
for (;;)
|
||||
{
|
||||
char c = *s;
|
||||
if (c < '0' || c > '9')
|
||||
{
|
||||
if (end != NULL)
|
||||
*end = s;
|
||||
return result;
|
||||
}
|
||||
result *= 10;
|
||||
result += (c - '0');
|
||||
s++;
|
||||
}
|
||||
}
|
||||
|
||||
UInt64 ConvertOctStringToUInt64(const char *s, const char **end)
|
||||
{
|
||||
UInt64 result = 0;
|
||||
for (;;)
|
||||
{
|
||||
char c = *s;
|
||||
if (c < '0' || c > '7')
|
||||
{
|
||||
if (end != NULL)
|
||||
*end = s;
|
||||
return result;
|
||||
}
|
||||
result <<= 3;
|
||||
result += (c - '0');
|
||||
s++;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
UInt64 ConvertStringToUInt64(const wchar_t *s, const wchar_t **end)
|
||||
{
|
||||
UInt64 result = 0;
|
||||
for (;;)
|
||||
{
|
||||
wchar_t c = *s;
|
||||
if (c < '0' || c > '9')
|
||||
{
|
||||
if (end != NULL)
|
||||
*end = s;
|
||||
return result;
|
||||
}
|
||||
result *= 10;
|
||||
result += (c - '0');
|
||||
s++;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Int64 ConvertStringToInt64(const char *s, const char **end)
|
||||
{
|
||||
if (*s == '-')
|
||||
return -(Int64)ConvertStringToUInt64(s + 1, end);
|
||||
return ConvertStringToUInt64(s, end);
|
||||
}
|
17
lib/physfs-2.0.3/lzma/CPP/Common/StringToInt.h
Normal file
17
lib/physfs-2.0.3/lzma/CPP/Common/StringToInt.h
Normal file
|
@ -0,0 +1,17 @@
|
|||
// Common/StringToInt.h
|
||||
|
||||
#ifndef __COMMON_STRINGTOINT_H
|
||||
#define __COMMON_STRINGTOINT_H
|
||||
|
||||
#include <string.h>
|
||||
#include "Types.h"
|
||||
|
||||
UInt64 ConvertStringToUInt64(const char *s, const char **end);
|
||||
UInt64 ConvertOctStringToUInt64(const char *s, const char **end);
|
||||
UInt64 ConvertStringToUInt64(const wchar_t *s, const wchar_t **end);
|
||||
|
||||
Int64 ConvertStringToInt64(const char *s, const char **end);
|
||||
|
||||
#endif
|
||||
|
||||
|
57
lib/physfs-2.0.3/lzma/CPP/Common/Types.h
Normal file
57
lib/physfs-2.0.3/lzma/CPP/Common/Types.h
Normal file
|
@ -0,0 +1,57 @@
|
|||
// Common/Types.h
|
||||
|
||||
#ifndef __COMMON_TYPES_H
|
||||
#define __COMMON_TYPES_H
|
||||
|
||||
#ifndef _7ZIP_BYTE_DEFINED
|
||||
#define _7ZIP_BYTE_DEFINED
|
||||
typedef unsigned char Byte;
|
||||
#endif
|
||||
|
||||
#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
|
||||
|
||||
#endif
|
||||
|
||||
#endif
|
91
lib/physfs-2.0.3/lzma/CPP/Common/UTFConvert.cpp
Normal file
91
lib/physfs-2.0.3/lzma/CPP/Common/UTFConvert.cpp
Normal file
|
@ -0,0 +1,91 @@
|
|||
// UTFConvert.cpp
|
||||
|
||||
#include "StdAfx.h"
|
||||
|
||||
#include "UTFConvert.h"
|
||||
#include "Types.h"
|
||||
|
||||
static Byte kUtf8Limits[5] = { 0xC0, 0xE0, 0xF0, 0xF8, 0xFC };
|
||||
|
||||
// These functions are for UTF8 <-> UTF16 conversion.
|
||||
|
||||
bool ConvertUTF8ToUnicode(const AString &src, UString &dest)
|
||||
{
|
||||
dest.Empty();
|
||||
for(int i = 0; i < src.Length();)
|
||||
{
|
||||
Byte c = (Byte)src[i++];
|
||||
if (c < 0x80)
|
||||
{
|
||||
dest += (wchar_t)c;
|
||||
continue;
|
||||
}
|
||||
if(c < 0xC0)
|
||||
return false;
|
||||
int numAdds;
|
||||
for (numAdds = 1; numAdds < 5; numAdds++)
|
||||
if (c < kUtf8Limits[numAdds])
|
||||
break;
|
||||
UInt32 value = (c - kUtf8Limits[numAdds - 1]);
|
||||
do
|
||||
{
|
||||
if (i >= src.Length())
|
||||
return false;
|
||||
Byte c2 = (Byte)src[i++];
|
||||
if (c2 < 0x80 || c2 >= 0xC0)
|
||||
return false;
|
||||
value <<= 6;
|
||||
value |= (c2 - 0x80);
|
||||
numAdds--;
|
||||
}
|
||||
while(numAdds > 0);
|
||||
if (value < 0x10000)
|
||||
dest += (wchar_t)(value);
|
||||
else
|
||||
{
|
||||
value -= 0x10000;
|
||||
if (value >= 0x100000)
|
||||
return false;
|
||||
dest += (wchar_t)(0xD800 + (value >> 10));
|
||||
dest += (wchar_t)(0xDC00 + (value & 0x3FF));
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
bool ConvertUnicodeToUTF8(const UString &src, AString &dest)
|
||||
{
|
||||
dest.Empty();
|
||||
for(int i = 0; i < src.Length();)
|
||||
{
|
||||
UInt32 value = (UInt32)src[i++];
|
||||
if (value < 0x80)
|
||||
{
|
||||
dest += (char)value;
|
||||
continue;
|
||||
}
|
||||
if (value >= 0xD800 && value < 0xE000)
|
||||
{
|
||||
if (value >= 0xDC00)
|
||||
return false;
|
||||
if (i >= src.Length())
|
||||
return false;
|
||||
UInt32 c2 = (UInt32)src[i++];
|
||||
if (c2 < 0xDC00 || c2 >= 0xE000)
|
||||
return false;
|
||||
value = ((value - 0xD800) << 10) | (c2 - 0xDC00);
|
||||
}
|
||||
int numAdds;
|
||||
for (numAdds = 1; numAdds < 5; numAdds++)
|
||||
if (value < (((UInt32)1) << (numAdds * 5 + 6)))
|
||||
break;
|
||||
dest += (char)(kUtf8Limits[numAdds - 1] + (value >> (6 * numAdds)));
|
||||
do
|
||||
{
|
||||
numAdds--;
|
||||
dest += (char)(0x80 + ((value >> (6 * numAdds)) & 0x3F));
|
||||
}
|
||||
while(numAdds > 0);
|
||||
}
|
||||
return true;
|
||||
}
|
11
lib/physfs-2.0.3/lzma/CPP/Common/UTFConvert.h
Normal file
11
lib/physfs-2.0.3/lzma/CPP/Common/UTFConvert.h
Normal file
|
@ -0,0 +1,11 @@
|
|||
// Common/UTFConvert.h
|
||||
|
||||
#ifndef __COMMON_UTFCONVERT_H
|
||||
#define __COMMON_UTFCONVERT_H
|
||||
|
||||
#include "MyString.h"
|
||||
|
||||
bool ConvertUTF8ToUnicode(const AString &utfString, UString &resultString);
|
||||
bool ConvertUnicodeToUTF8(const UString &unicodeString, AString &resultString);
|
||||
|
||||
#endif
|
458
lib/physfs-2.0.3/lzma/CPP/Common/Wildcard.cpp
Normal file
458
lib/physfs-2.0.3/lzma/CPP/Common/Wildcard.cpp
Normal file
|
@ -0,0 +1,458 @@
|
|||
// Common/Wildcard.cpp
|
||||
|
||||
#include "StdAfx.h"
|
||||
|
||||
#include "Wildcard.h"
|
||||
|
||||
bool g_CaseSensitive =
|
||||
#ifdef _WIN32
|
||||
false;
|
||||
#else
|
||||
true;
|
||||
#endif
|
||||
|
||||
static const wchar_t kAnyCharsChar = L'*';
|
||||
static const wchar_t kAnyCharChar = L'?';
|
||||
|
||||
#ifdef _WIN32
|
||||
static const wchar_t kDirDelimiter1 = L'\\';
|
||||
#endif
|
||||
static const wchar_t kDirDelimiter2 = L'/';
|
||||
|
||||
static const UString kWildCardCharSet = L"?*";
|
||||
|
||||
static const UString kIllegalWildCardFileNameChars=
|
||||
L"\x1\x2\x3\x4\x5\x6\x7\x8\x9\xA\xB\xC\xD\xE\xF"
|
||||
L"\x10\x11\x12\x13\x14\x15\x16\x17\x18\x19\x1A\x1B\x1C\x1D\x1E\x1F"
|
||||
L"\"/:<>\\|";
|
||||
|
||||
|
||||
static inline bool IsCharDirLimiter(wchar_t c)
|
||||
{
|
||||
return (
|
||||
#ifdef _WIN32
|
||||
c == kDirDelimiter1 ||
|
||||
#endif
|
||||
c == kDirDelimiter2);
|
||||
}
|
||||
|
||||
int CompareFileNames(const UString &s1, const UString &s2)
|
||||
{
|
||||
if (g_CaseSensitive)
|
||||
return s1.Compare(s2);
|
||||
return s1.CompareNoCase(s2);
|
||||
}
|
||||
|
||||
// -----------------------------------------
|
||||
// this function compares name with mask
|
||||
// ? - any char
|
||||
// * - any char or empty
|
||||
|
||||
static bool EnhancedMaskTest(const wchar_t *mask, const wchar_t *name)
|
||||
{
|
||||
for (;;)
|
||||
{
|
||||
wchar_t m = *mask;
|
||||
wchar_t c = *name;
|
||||
if (m == 0)
|
||||
return (c == 0);
|
||||
if (m == kAnyCharsChar)
|
||||
{
|
||||
if (EnhancedMaskTest(mask + 1, name))
|
||||
return true;
|
||||
if (c == 0)
|
||||
return false;
|
||||
}
|
||||
else
|
||||
{
|
||||
if (m == kAnyCharChar)
|
||||
{
|
||||
if (c == 0)
|
||||
return false;
|
||||
}
|
||||
else if (m != c)
|
||||
if (g_CaseSensitive || MyCharUpper(m) != MyCharUpper(c))
|
||||
return false;
|
||||
mask++;
|
||||
}
|
||||
name++;
|
||||
}
|
||||
}
|
||||
|
||||
// --------------------------------------------------
|
||||
// Splits path to strings
|
||||
|
||||
void SplitPathToParts(const UString &path, UStringVector &pathParts)
|
||||
{
|
||||
pathParts.Clear();
|
||||
UString name;
|
||||
int len = path.Length();
|
||||
if (len == 0)
|
||||
return;
|
||||
for (int i = 0; i < len; i++)
|
||||
{
|
||||
wchar_t c = path[i];
|
||||
if (IsCharDirLimiter(c))
|
||||
{
|
||||
pathParts.Add(name);
|
||||
name.Empty();
|
||||
}
|
||||
else
|
||||
name += c;
|
||||
}
|
||||
pathParts.Add(name);
|
||||
}
|
||||
|
||||
void SplitPathToParts(const UString &path, UString &dirPrefix, UString &name)
|
||||
{
|
||||
int i;
|
||||
for(i = path.Length() - 1; i >= 0; i--)
|
||||
if(IsCharDirLimiter(path[i]))
|
||||
break;
|
||||
dirPrefix = path.Left(i + 1);
|
||||
name = path.Mid(i + 1);
|
||||
}
|
||||
|
||||
UString ExtractDirPrefixFromPath(const UString &path)
|
||||
{
|
||||
int i;
|
||||
for(i = path.Length() - 1; i >= 0; i--)
|
||||
if(IsCharDirLimiter(path[i]))
|
||||
break;
|
||||
return path.Left(i + 1);
|
||||
}
|
||||
|
||||
UString ExtractFileNameFromPath(const UString &path)
|
||||
{
|
||||
int i;
|
||||
for(i = path.Length() - 1; i >= 0; i--)
|
||||
if(IsCharDirLimiter(path[i]))
|
||||
break;
|
||||
return path.Mid(i + 1);
|
||||
}
|
||||
|
||||
|
||||
bool CompareWildCardWithName(const UString &mask, const UString &name)
|
||||
{
|
||||
return EnhancedMaskTest(mask, name);
|
||||
}
|
||||
|
||||
bool DoesNameContainWildCard(const UString &path)
|
||||
{
|
||||
return (path.FindOneOf(kWildCardCharSet) >= 0);
|
||||
}
|
||||
|
||||
|
||||
// ----------------------------------------------------------'
|
||||
// NWildcard
|
||||
|
||||
namespace NWildcard {
|
||||
|
||||
|
||||
/*
|
||||
M = MaskParts.Size();
|
||||
N = TestNameParts.Size();
|
||||
|
||||
File Dir
|
||||
ForFile req M<=N [N-M, N) -
|
||||
nonreq M=N [0, M) -
|
||||
|
||||
ForDir req M<N [0, M) ... [N-M-1, N-1) same as ForBoth-File
|
||||
nonreq [0, M) same as ForBoth-File
|
||||
|
||||
ForBoth req m<=N [0, M) ... [N-M, N) same as ForBoth-File
|
||||
nonreq [0, M) same as ForBoth-File
|
||||
|
||||
*/
|
||||
|
||||
bool CItem::CheckPath(const UStringVector &pathParts, bool isFile) const
|
||||
{
|
||||
if (!isFile && !ForDir)
|
||||
return false;
|
||||
int delta = (int)pathParts.Size() - (int)PathParts.Size();
|
||||
if (delta < 0)
|
||||
return false;
|
||||
int start = 0;
|
||||
int finish = 0;
|
||||
if (isFile)
|
||||
{
|
||||
if (!ForDir && !Recursive && delta !=0)
|
||||
return false;
|
||||
if (!ForFile && delta == 0)
|
||||
return false;
|
||||
if (!ForDir && Recursive)
|
||||
start = delta;
|
||||
}
|
||||
if (Recursive)
|
||||
{
|
||||
finish = delta;
|
||||
if (isFile && !ForFile)
|
||||
finish = delta - 1;
|
||||
}
|
||||
for (int d = start; d <= finish; d++)
|
||||
{
|
||||
int i;
|
||||
for (i = 0; i < PathParts.Size(); i++)
|
||||
if (!CompareWildCardWithName(PathParts[i], pathParts[i + d]))
|
||||
break;
|
||||
if (i == PathParts.Size())
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
int CCensorNode::FindSubNode(const UString &name) const
|
||||
{
|
||||
for (int i = 0; i < SubNodes.Size(); i++)
|
||||
if (CompareFileNames(SubNodes[i].Name, name) == 0)
|
||||
return i;
|
||||
return -1;
|
||||
}
|
||||
|
||||
void CCensorNode::AddItemSimple(bool include, CItem &item)
|
||||
{
|
||||
if (include)
|
||||
IncludeItems.Add(item);
|
||||
else
|
||||
ExcludeItems.Add(item);
|
||||
}
|
||||
|
||||
void CCensorNode::AddItem(bool include, CItem &item)
|
||||
{
|
||||
if (item.PathParts.Size() <= 1)
|
||||
{
|
||||
AddItemSimple(include, item);
|
||||
return;
|
||||
}
|
||||
const UString &front = item.PathParts.Front();
|
||||
if (DoesNameContainWildCard(front))
|
||||
{
|
||||
AddItemSimple(include, item);
|
||||
return;
|
||||
}
|
||||
int index = FindSubNode(front);
|
||||
if (index < 0)
|
||||
index = SubNodes.Add(CCensorNode(front, this));
|
||||
item.PathParts.Delete(0);
|
||||
SubNodes[index].AddItem(include, item);
|
||||
}
|
||||
|
||||
void CCensorNode::AddItem(bool include, const UString &path, bool recursive, bool forFile, bool forDir)
|
||||
{
|
||||
CItem item;
|
||||
SplitPathToParts(path, item.PathParts);
|
||||
item.Recursive = recursive;
|
||||
item.ForFile = forFile;
|
||||
item.ForDir = forDir;
|
||||
AddItem(include, item);
|
||||
}
|
||||
|
||||
bool CCensorNode::NeedCheckSubDirs() const
|
||||
{
|
||||
for (int i = 0; i < IncludeItems.Size(); i++)
|
||||
{
|
||||
const CItem &item = IncludeItems[i];
|
||||
if (item.Recursive || item.PathParts.Size() > 1)
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
bool CCensorNode::AreThereIncludeItems() const
|
||||
{
|
||||
if (IncludeItems.Size() > 0)
|
||||
return true;
|
||||
for (int i = 0; i < SubNodes.Size(); i++)
|
||||
if (SubNodes[i].AreThereIncludeItems())
|
||||
return true;
|
||||
return false;
|
||||
}
|
||||
|
||||
bool CCensorNode::CheckPathCurrent(bool include, const UStringVector &pathParts, bool isFile) const
|
||||
{
|
||||
const CObjectVector<CItem> &items = include ? IncludeItems : ExcludeItems;
|
||||
for (int i = 0; i < items.Size(); i++)
|
||||
if (items[i].CheckPath(pathParts, isFile))
|
||||
return true;
|
||||
return false;
|
||||
}
|
||||
|
||||
bool CCensorNode::CheckPath(UStringVector &pathParts, bool isFile, bool &include) const
|
||||
{
|
||||
if (CheckPathCurrent(false, pathParts, isFile))
|
||||
{
|
||||
include = false;
|
||||
return true;
|
||||
}
|
||||
include = true;
|
||||
bool finded = CheckPathCurrent(true, pathParts, isFile);
|
||||
if (pathParts.Size() == 1)
|
||||
return finded;
|
||||
int index = FindSubNode(pathParts.Front());
|
||||
if (index >= 0)
|
||||
{
|
||||
UStringVector pathParts2 = pathParts;
|
||||
pathParts2.Delete(0);
|
||||
if (SubNodes[index].CheckPath(pathParts2, isFile, include))
|
||||
return true;
|
||||
}
|
||||
return finded;
|
||||
}
|
||||
|
||||
bool CCensorNode::CheckPath(const UString &path, bool isFile, bool &include) const
|
||||
{
|
||||
UStringVector pathParts;
|
||||
SplitPathToParts(path, pathParts);
|
||||
return CheckPath(pathParts, isFile, include);
|
||||
}
|
||||
|
||||
bool CCensorNode::CheckPath(const UString &path, bool isFile) const
|
||||
{
|
||||
bool include;
|
||||
if(CheckPath(path, isFile, include))
|
||||
return include;
|
||||
return false;
|
||||
}
|
||||
|
||||
bool CCensorNode::CheckPathToRoot(bool include, UStringVector &pathParts, bool isFile) const
|
||||
{
|
||||
if (CheckPathCurrent(include, pathParts, isFile))
|
||||
return true;
|
||||
if (Parent == 0)
|
||||
return false;
|
||||
pathParts.Insert(0, Name);
|
||||
return Parent->CheckPathToRoot(include, pathParts, isFile);
|
||||
}
|
||||
|
||||
/*
|
||||
bool CCensorNode::CheckPathToRoot(bool include, const UString &path, bool isFile) const
|
||||
{
|
||||
UStringVector pathParts;
|
||||
SplitPathToParts(path, pathParts);
|
||||
return CheckPathToRoot(include, pathParts, isFile);
|
||||
}
|
||||
*/
|
||||
|
||||
void CCensorNode::AddItem2(bool include, const UString &path, bool recursive)
|
||||
{
|
||||
if (path.IsEmpty())
|
||||
return;
|
||||
bool forFile = true;
|
||||
bool forFolder = true;
|
||||
UString path2 = path;
|
||||
if (IsCharDirLimiter(path[path.Length() - 1]))
|
||||
{
|
||||
path2.Delete(path.Length() - 1);
|
||||
forFile = false;
|
||||
}
|
||||
AddItem(include, path2, recursive, forFile, forFolder);
|
||||
}
|
||||
|
||||
void CCensorNode::ExtendExclude(const CCensorNode &fromNodes)
|
||||
{
|
||||
ExcludeItems += fromNodes.ExcludeItems;
|
||||
for (int i = 0; i < fromNodes.SubNodes.Size(); i++)
|
||||
{
|
||||
const CCensorNode &node = fromNodes.SubNodes[i];
|
||||
int subNodeIndex = FindSubNode(node.Name);
|
||||
if (subNodeIndex < 0)
|
||||
subNodeIndex = SubNodes.Add(CCensorNode(node.Name, this));
|
||||
SubNodes[subNodeIndex].ExtendExclude(node);
|
||||
}
|
||||
}
|
||||
|
||||
int CCensor::FindPrefix(const UString &prefix) const
|
||||
{
|
||||
for (int i = 0; i < Pairs.Size(); i++)
|
||||
if (CompareFileNames(Pairs[i].Prefix, prefix) == 0)
|
||||
return i;
|
||||
return -1;
|
||||
}
|
||||
|
||||
void CCensor::AddItem(bool include, const UString &path, bool recursive)
|
||||
{
|
||||
UStringVector pathParts;
|
||||
SplitPathToParts(path, pathParts);
|
||||
bool forFile = true;
|
||||
if (pathParts.Back().IsEmpty())
|
||||
{
|
||||
forFile = false;
|
||||
pathParts.DeleteBack();
|
||||
}
|
||||
const UString &front = pathParts.Front();
|
||||
bool isAbs = false;
|
||||
if (front.IsEmpty())
|
||||
isAbs = true;
|
||||
else if (front.Length() == 2 && front[1] == L':')
|
||||
isAbs = true;
|
||||
else
|
||||
{
|
||||
for (int i = 0; i < pathParts.Size(); i++)
|
||||
{
|
||||
const UString &part = pathParts[i];
|
||||
if (part == L".." || part == L".")
|
||||
{
|
||||
isAbs = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
int numAbsParts = 0;
|
||||
if (isAbs)
|
||||
if (pathParts.Size() > 1)
|
||||
numAbsParts = pathParts.Size() - 1;
|
||||
else
|
||||
numAbsParts = 1;
|
||||
UString prefix;
|
||||
for (int i = 0; i < numAbsParts; i++)
|
||||
{
|
||||
const UString &front = pathParts.Front();
|
||||
if (DoesNameContainWildCard(front))
|
||||
break;
|
||||
prefix += front;
|
||||
prefix += WCHAR_PATH_SEPARATOR;
|
||||
pathParts.Delete(0);
|
||||
}
|
||||
int index = FindPrefix(prefix);
|
||||
if (index < 0)
|
||||
index = Pairs.Add(CPair(prefix));
|
||||
|
||||
CItem item;
|
||||
item.PathParts = pathParts;
|
||||
item.ForDir = true;
|
||||
item.ForFile = forFile;
|
||||
item.Recursive = recursive;
|
||||
Pairs[index].Head.AddItem(include, item);
|
||||
}
|
||||
|
||||
bool CCensor::CheckPath(const UString &path, bool isFile) const
|
||||
{
|
||||
bool finded = false;
|
||||
for (int i = 0; i < Pairs.Size(); i++)
|
||||
{
|
||||
bool include;
|
||||
if (Pairs[i].Head.CheckPath(path, isFile, include))
|
||||
{
|
||||
if (!include)
|
||||
return false;
|
||||
finded = true;
|
||||
}
|
||||
}
|
||||
return finded;
|
||||
}
|
||||
|
||||
void CCensor::ExtendExclude()
|
||||
{
|
||||
int i;
|
||||
for (i = 0; i < Pairs.Size(); i++)
|
||||
if (Pairs[i].Prefix.IsEmpty())
|
||||
break;
|
||||
if (i == Pairs.Size())
|
||||
return;
|
||||
int index = i;
|
||||
for (i = 0; i < Pairs.Size(); i++)
|
||||
if (index != i)
|
||||
Pairs[i].Head.ExtendExclude(Pairs[index].Head);
|
||||
}
|
||||
|
||||
}
|
80
lib/physfs-2.0.3/lzma/CPP/Common/Wildcard.h
Normal file
80
lib/physfs-2.0.3/lzma/CPP/Common/Wildcard.h
Normal file
|
@ -0,0 +1,80 @@
|
|||
// Common/Wildcard.h
|
||||
|
||||
#ifndef __COMMON_WILDCARD_H
|
||||
#define __COMMON_WILDCARD_H
|
||||
|
||||
#include "MyString.h"
|
||||
|
||||
int CompareFileNames(const UString &s1, const UString &s2);
|
||||
|
||||
void SplitPathToParts(const UString &path, UStringVector &pathParts);
|
||||
void SplitPathToParts(const UString &path, UString &dirPrefix, UString &name);
|
||||
UString ExtractDirPrefixFromPath(const UString &path);
|
||||
UString ExtractFileNameFromPath(const UString &path);
|
||||
bool DoesNameContainWildCard(const UString &path);
|
||||
bool CompareWildCardWithName(const UString &mask, const UString &name);
|
||||
|
||||
namespace NWildcard {
|
||||
|
||||
struct CItem
|
||||
{
|
||||
UStringVector PathParts;
|
||||
bool Recursive;
|
||||
bool ForFile;
|
||||
bool ForDir;
|
||||
bool CheckPath(const UStringVector &pathParts, bool isFile) const;
|
||||
};
|
||||
|
||||
class CCensorNode
|
||||
{
|
||||
CCensorNode *Parent;
|
||||
bool CheckPathCurrent(bool include, const UStringVector &pathParts, bool isFile) const;
|
||||
void AddItemSimple(bool include, CItem &item);
|
||||
bool CheckPath(UStringVector &pathParts, bool isFile, bool &include) const;
|
||||
public:
|
||||
CCensorNode(): Parent(0) { };
|
||||
CCensorNode(const UString &name, CCensorNode *parent): Name(name), Parent(parent) { };
|
||||
UString Name;
|
||||
CObjectVector<CCensorNode> SubNodes;
|
||||
CObjectVector<CItem> IncludeItems;
|
||||
CObjectVector<CItem> ExcludeItems;
|
||||
|
||||
int FindSubNode(const UString &path) const;
|
||||
|
||||
void AddItem(bool include, CItem &item);
|
||||
void AddItem(bool include, const UString &path, bool recursive, bool forFile, bool forDir);
|
||||
void AddItem2(bool include, const UString &path, bool recursive);
|
||||
|
||||
bool NeedCheckSubDirs() const;
|
||||
bool AreThereIncludeItems() const;
|
||||
|
||||
bool CheckPath(const UString &path, bool isFile, bool &include) const;
|
||||
bool CheckPath(const UString &path, bool isFile) const;
|
||||
|
||||
bool CheckPathToRoot(bool include, UStringVector &pathParts, bool isFile) const;
|
||||
// bool CheckPathToRoot(const UString &path, bool isFile, bool include) const;
|
||||
void ExtendExclude(const CCensorNode &fromNodes);
|
||||
};
|
||||
|
||||
struct CPair
|
||||
{
|
||||
UString Prefix;
|
||||
CCensorNode Head;
|
||||
CPair(const UString &prefix): Prefix(prefix) { };
|
||||
};
|
||||
|
||||
class CCensor
|
||||
{
|
||||
int FindPrefix(const UString &prefix) const;
|
||||
public:
|
||||
CObjectVector<CPair> Pairs;
|
||||
bool AllAreRelative() const
|
||||
{ return (Pairs.Size() == 1 && Pairs.Front().Prefix.IsEmpty()); }
|
||||
void AddItem(bool include, const UString &path, bool recursive);
|
||||
bool CheckPath(const UString &path, bool isFile) const;
|
||||
void ExtendExclude();
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
#endif
|
Loading…
Add table
Add a link
Reference in a new issue