This commit is contained in:
Igor Pavlov
2005-05-30 00:00:00 +00:00
committed by Kornel Lesiński
parent 8c1b5c7b7e
commit 3c510ba80b
926 changed files with 40559 additions and 23519 deletions

View File

@@ -3,14 +3,14 @@
#include "StdAfx.h"
#include "AlignedBuffer.h"
#include "Types.h"
void *CAlignedBuffer::Allocate(size_t numItems, size_t itemSize, size_t alignValue)
void *CAlignedBuffer::Allocate(size_t size, size_t mask)
{
Free();
m_Buffer = new unsigned char[numItems * itemSize + alignValue - 1];
UINT_PTR p = UINT_PTR(m_Buffer) + (alignValue - 1);
p -= (p % alignValue);
m_Buffer = new unsigned char[size + mask];
unsigned char *p = m_Buffer;
while(((size_t)p & mask) != 0)
p++;
return (void *)p;
}

View File

@@ -1,7 +1,9 @@
// AlignedBuffer.h
// Common/AlignedBuffer.h
#ifndef __ALIGNBUFFER_H
#define __ALIGNBUFFER_H
#ifndef __COMMON_ALIGNEDBUFFER_H
#define __COMMON_ALIGNEDBUFFER_H
#include <stddef.h>
class CAlignedBuffer
{
@@ -9,7 +11,7 @@ class CAlignedBuffer
public:
CAlignedBuffer(): m_Buffer(0) {};
~CAlignedBuffer() { Free(); }
void *Allocate(size_t numItems, size_t itemSize, size_t alignValue);
void *Allocate(size_t size, size_t mask);
void Free();
};

79
Common/Alloc.cpp Executable file
View File

@@ -0,0 +1,79 @@
// Common/Alloc.cpp
#include "StdAfx.h"
#ifdef _WIN32
#include "MyWindows.h"
#else
#include <stdlib.h>
#endif
#include "Alloc.h"
/* #define _SZ_ALLOC_DEBUG */
/* use _SZ_ALLOC_DEBUG to debug alloc/free operations */
#ifdef _SZ_ALLOC_DEBUG
#include <stdio.h>
int g_allocCount = 0;
int g_allocCountBig = 0;
#endif
void *MyAlloc(size_t size)
{
#ifdef _SZ_ALLOC_DEBUG
fprintf(stderr, "\nAlloc %10d bytes; count = %10d", size, g_allocCount++);
#endif
return ::malloc(size);
}
void MyFree(void *address)
{
#ifdef _SZ_ALLOC_DEBUG
if (address != 0)
fprintf(stderr, "\nFree; count = %10d", --g_allocCount);
#endif
::free(address);
}
void *BigAlloc(size_t size)
{
#ifdef _SZ_ALLOC_DEBUG
fprintf(stderr, "\nAlloc_Big %10d bytes; count = %10d", size, g_allocCountBig++);
#endif
#ifdef _WIN32
return ::VirtualAlloc(0, size, MEM_COMMIT, PAGE_READWRITE);
#else
return ::malloc(size);
#endif
}
void BigFree(void *address)
{
#ifdef _SZ_ALLOC_DEBUG
if (address != 0)
fprintf(stderr, "\nFree_Big; count = %10d", --g_allocCountBig);
#endif
if (address == 0)
return;
#ifdef _WIN32
::VirtualFree(address, 0, MEM_RELEASE);
#else
::free(address);
#endif
}
/*
void *BigAllocE(size_t size)
{
void *res = BigAlloc(size);
#ifndef _NO_EXCEPTIONS
if (res == 0)
throw CNewException();
#endif
return res;
}
*/

14
Common/Alloc.h Executable file
View File

@@ -0,0 +1,14 @@
// Common/Alloc.h
#ifndef __COMMON_ALLOC_H
#define __COMMON_ALLOC_H
#include <stddef.h>
void *MyAlloc(size_t size);
void MyFree(void *address);
void *BigAlloc(size_t size);
void BigFree(void *address);
// void *BigAllocE(size_t size);
#endif

35
Common/AutoPtr.h Executable file
View 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

View File

@@ -1,11 +1,9 @@
// Common/Buffer.h
#pragma once
#ifndef __COMMON_BUFFER_H
#define __COMMON_BUFFER_H
// #include "Common/Defs.h"
#include "Defs.h"
template <class T> class CBuffer
{
@@ -28,9 +26,15 @@ public:
size_t GetCapacity() const { return _capacity; }
void SetCapacity(size_t newCapacity)
{
T *newBuffer = new T[newCapacity];
if(_capacity > 0)
memmove(newBuffer, _items, MyMin(_capacity, newCapacity) * sizeof(T));
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;

View File

@@ -4,18 +4,15 @@
#include "CRC.h"
static const UINT32 kCRCPoly = 0xEDB88320;
static const UInt32 kCRCPoly = 0xEDB88320;
UINT32 CCRC::Table[256];
UInt32 CCRC::Table[256];
class CCRCTableInit
void CCRC::InitTable()
{
public:
CCRCTableInit()
{
for (UINT32 i = 0; i < 256; i++)
for (UInt32 i = 0; i < 256; i++)
{
UINT32 r = i;
UInt32 r = i;
for (int j = 0; j < 8; j++)
if (r & 1)
r = (r >> 1) ^ kCRCPoly;
@@ -24,87 +21,41 @@ CCRCTableInit()
CCRC::Table[i] = r;
}
}
class CCRCTableInit
{
public:
CCRCTableInit() { CCRC::InitTable(); }
} g_CRCTableInit;
/*
const UINT32 CCRC::Table[] = {
0x00000000L, 0x77073096L, 0xee0e612cL, 0x990951baL, 0x076dc419L,
0x706af48fL, 0xe963a535L, 0x9e6495a3L, 0x0edb8832L, 0x79dcb8a4L,
0xe0d5e91eL, 0x97d2d988L, 0x09b64c2bL, 0x7eb17cbdL, 0xe7b82d07L,
0x90bf1d91L, 0x1db71064L, 0x6ab020f2L, 0xf3b97148L, 0x84be41deL,
0x1adad47dL, 0x6ddde4ebL, 0xf4d4b551L, 0x83d385c7L, 0x136c9856L,
0x646ba8c0L, 0xfd62f97aL, 0x8a65c9ecL, 0x14015c4fL, 0x63066cd9L,
0xfa0f3d63L, 0x8d080df5L, 0x3b6e20c8L, 0x4c69105eL, 0xd56041e4L,
0xa2677172L, 0x3c03e4d1L, 0x4b04d447L, 0xd20d85fdL, 0xa50ab56bL,
0x35b5a8faL, 0x42b2986cL, 0xdbbbc9d6L, 0xacbcf940L, 0x32d86ce3L,
0x45df5c75L, 0xdcd60dcfL, 0xabd13d59L, 0x26d930acL, 0x51de003aL,
0xc8d75180L, 0xbfd06116L, 0x21b4f4b5L, 0x56b3c423L, 0xcfba9599L,
0xb8bda50fL, 0x2802b89eL, 0x5f058808L, 0xc60cd9b2L, 0xb10be924L,
0x2f6f7c87L, 0x58684c11L, 0xc1611dabL, 0xb6662d3dL, 0x76dc4190L,
0x01db7106L, 0x98d220bcL, 0xefd5102aL, 0x71b18589L, 0x06b6b51fL,
0x9fbfe4a5L, 0xe8b8d433L, 0x7807c9a2L, 0x0f00f934L, 0x9609a88eL,
0xe10e9818L, 0x7f6a0dbbL, 0x086d3d2dL, 0x91646c97L, 0xe6635c01L,
0x6b6b51f4L, 0x1c6c6162L, 0x856530d8L, 0xf262004eL, 0x6c0695edL,
0x1b01a57bL, 0x8208f4c1L, 0xf50fc457L, 0x65b0d9c6L, 0x12b7e950L,
0x8bbeb8eaL, 0xfcb9887cL, 0x62dd1ddfL, 0x15da2d49L, 0x8cd37cf3L,
0xfbd44c65L, 0x4db26158L, 0x3ab551ceL, 0xa3bc0074L, 0xd4bb30e2L,
0x4adfa541L, 0x3dd895d7L, 0xa4d1c46dL, 0xd3d6f4fbL, 0x4369e96aL,
0x346ed9fcL, 0xad678846L, 0xda60b8d0L, 0x44042d73L, 0x33031de5L,
0xaa0a4c5fL, 0xdd0d7cc9L, 0x5005713cL, 0x270241aaL, 0xbe0b1010L,
0xc90c2086L, 0x5768b525L, 0x206f85b3L, 0xb966d409L, 0xce61e49fL,
0x5edef90eL, 0x29d9c998L, 0xb0d09822L, 0xc7d7a8b4L, 0x59b33d17L,
0x2eb40d81L, 0xb7bd5c3bL, 0xc0ba6cadL, 0xedb88320L, 0x9abfb3b6L,
0x03b6e20cL, 0x74b1d29aL, 0xead54739L, 0x9dd277afL, 0x04db2615L,
0x73dc1683L, 0xe3630b12L, 0x94643b84L, 0x0d6d6a3eL, 0x7a6a5aa8L,
0xe40ecf0bL, 0x9309ff9dL, 0x0a00ae27L, 0x7d079eb1L, 0xf00f9344L,
0x8708a3d2L, 0x1e01f268L, 0x6906c2feL, 0xf762575dL, 0x806567cbL,
0x196c3671L, 0x6e6b06e7L, 0xfed41b76L, 0x89d32be0L, 0x10da7a5aL,
0x67dd4accL, 0xf9b9df6fL, 0x8ebeeff9L, 0x17b7be43L, 0x60b08ed5L,
0xd6d6a3e8L, 0xa1d1937eL, 0x38d8c2c4L, 0x4fdff252L, 0xd1bb67f1L,
0xa6bc5767L, 0x3fb506ddL, 0x48b2364bL, 0xd80d2bdaL, 0xaf0a1b4cL,
0x36034af6L, 0x41047a60L, 0xdf60efc3L, 0xa867df55L, 0x316e8eefL,
0x4669be79L, 0xcb61b38cL, 0xbc66831aL, 0x256fd2a0L, 0x5268e236L,
0xcc0c7795L, 0xbb0b4703L, 0x220216b9L, 0x5505262fL, 0xc5ba3bbeL,
0xb2bd0b28L, 0x2bb45a92L, 0x5cb36a04L, 0xc2d7ffa7L, 0xb5d0cf31L,
0x2cd99e8bL, 0x5bdeae1dL, 0x9b64c2b0L, 0xec63f226L, 0x756aa39cL,
0x026d930aL, 0x9c0906a9L, 0xeb0e363fL, 0x72076785L, 0x05005713L,
0x95bf4a82L, 0xe2b87a14L, 0x7bb12baeL, 0x0cb61b38L, 0x92d28e9bL,
0xe5d5be0dL, 0x7cdcefb7L, 0x0bdbdf21L, 0x86d3d2d4L, 0xf1d4e242L,
0x68ddb3f8L, 0x1fda836eL, 0x81be16cdL, 0xf6b9265bL, 0x6fb077e1L,
0x18b74777L, 0x88085ae6L, 0xff0f6a70L, 0x66063bcaL, 0x11010b5cL,
0x8f659effL, 0xf862ae69L, 0x616bffd3L, 0x166ccf45L, 0xa00ae278L,
0xd70dd2eeL, 0x4e048354L, 0x3903b3c2L, 0xa7672661L, 0xd06016f7L,
0x4969474dL, 0x3e6e77dbL, 0xaed16a4aL, 0xd9d65adcL, 0x40df0b66L,
0x37d83bf0L, 0xa9bcae53L, 0xdebb9ec5L, 0x47b2cf7fL, 0x30b5ffe9L,
0xbdbdf21cL, 0xcabac28aL, 0x53b39330L, 0x24b4a3a6L, 0xbad03605L,
0xcdd70693L, 0x54de5729L, 0x23d967bfL, 0xb3667a2eL, 0xc4614ab8L,
0x5d681b02L, 0x2a6f2b94L, 0xb40bbe37L, 0xc30c8ea1L, 0x5a05df1bL,
0x2d02ef8dL
};
*/
#define UPDATE valueLoc = Table[(BYTE)valueLoc] ^ (valueLoc >> 8)
#define UPDATE4 UPDATE; UPDATE; UPDATE; UPDATE;
void CCRC::Update(const void *data, UINT32 size)
void CCRC::UpdateByte(Byte b)
{
UINT32 valueLoc = _value;
const BYTE *byteBuffer = (const BYTE *)data;
for(; (UINT_PTR(byteBuffer) & 3) != 0 && size > 0; size--, byteBuffer++)
valueLoc = Table[(((BYTE)(valueLoc)) ^ (*byteBuffer))] ^
(valueLoc >> 8);
const UINT32 kBlockSize = 4;
while (size >= kBlockSize)
{
size -= kBlockSize;
valueLoc ^= *(const UINT32 *)byteBuffer;
UPDATE4
byteBuffer += kBlockSize;
}
for(UINT32 i = 0; i < size; i++)
valueLoc = Table[(((BYTE)(valueLoc)) ^ (byteBuffer)[i])] ^
(valueLoc >> 8);
_value = valueLoc;
_value = Table[((Byte)(_value)) ^ b] ^ (_value >> 8);
}
void CCRC::UpdateUInt16(UInt16 v)
{
UpdateByte(Byte(v));
UpdateByte(Byte(v >> 8));
}
void CCRC::UpdateUInt32(UInt32 v)
{
for (int i = 0; i < 4; i++)
UpdateByte((Byte)(v >> (8 * i)));
}
void CCRC::UpdateUInt64(UInt64 v)
{
for (int i = 0; i < 8; i++)
UpdateByte((Byte)(v >> (8 * i)));
}
void CCRC::Update(const void *data, UInt32 size)
{
UInt32 v = _value;
const Byte *p = (const Byte *)data;
for (; size > 0 ; size--, p++)
v = Table[((Byte)(v)) ^ *p] ^ (v >> 8);
_value = v;
}

View File

@@ -1,7 +1,5 @@
// Common/CRC.h
// #pragma once
#ifndef __COMMON_CRC_H
#define __COMMON_CRC_H
@@ -9,20 +7,26 @@
class CCRC
{
UINT32 _value;
UInt32 _value;
public:
static UINT32 Table[256];
static UInt32 Table[256];
static void InitTable();
CCRC(): _value(0xFFFFFFFF){};
void Init() { _value = 0xFFFFFFFF; }
void Update(const void *data, UINT32 size);
UINT32 GetDigest() const { return _value ^ 0xFFFFFFFF; }
static UINT32 CalculateDigest(const void *data, UINT32 size)
void UpdateByte(Byte v);
void UpdateUInt16(UInt16 v);
void UpdateUInt32(UInt32 v);
void UpdateUInt64(UInt64 v);
void Update(const void *data, UInt32 size);
UInt32 GetDigest() const { return _value ^ 0xFFFFFFFF; }
static UInt32 CalculateDigest(const void *data, UInt32 size)
{
CCRC crc;
crc.Update(data, size);
return crc.GetDigest();
}
static bool VerifyDigest(UINT32 digest, const void *data, UINT32 size)
static bool VerifyDigest(UInt32 digest, const void *data, UInt32 size)
{
return (CalculateDigest(data, size) == digest);
}

78
Common/C_FileIO.cpp Executable file
View File

@@ -0,0 +1,78 @@
// 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);
}
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);
}
ssize_t COutFile::Write(const void *data, size_t size)
{
return write(_handle, data, size);
}
}}}

45
Common/C_FileIO.h Executable file
View File

@@ -0,0 +1,45 @@
// 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);
ssize_t Read(void *data, size_t size);
};
class COutFile: public CFileBase
{
public:
bool Create(const char *name, bool createAlways);
ssize_t Write(const void *data, size_t size);
};
}}}
#endif

View File

@@ -1,9 +1,7 @@
// ComTry.h
// #pragma once
#ifndef __Com_Try_H
#define __Com_Try_H
#ifndef __COM_TRY_H
#define __COM_TRY_H
#include "Exception.h"

View File

@@ -37,8 +37,8 @@ void SplitCommandLine(const UString &s, UStringVector &parts)
{
UString s1, s2;
SplitCommandLine(sTemp, s1, s2);
s1.Trim();
s2.Trim();
// s1.Trim();
// s2.Trim();
if (!s1.IsEmpty())
parts.Add(s1);
if (s2.IsEmpty())
@@ -49,13 +49,14 @@ void SplitCommandLine(const UString &s, UStringVector &parts)
static const wchar_t kSwitchID1 = '-';
static const wchar_t kSwitchID2 = '/';
// 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);
return (c == kSwitchID1 /*|| c == kSwitchID2 */);
}
CParser::CParser(int numSwitches):
@@ -73,9 +74,19 @@ void CParser::ParseStrings(const CSwitchForm *switchForms,
const UStringVector &commandStrings)
{
int numCommandStrings = commandStrings.Size();
bool stopSwitch = false;
for (int i = 0; i < numCommandStrings; i++)
if (!ParseString(commandStrings[i], switchForms))
NonSwitchStrings.Add(commandStrings[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
@@ -93,11 +104,11 @@ bool CParser::ParseString(const UString &s, const CSwitchForm *switchForms)
if (IsItSwitchChar(s[pos]))
pos++;
const int kNoLen = -1;
int matchedSwitchIndex;
int matchedSwitchIndex = 0; // GCC Warning
int maxLen = kNoLen;
for(int switchIndex = 0; switchIndex < _numSwitches; switchIndex++)
{
int switchLen = wcslen(switchForms[switchIndex].IDString);
int switchLen = MyStringLen(switchForms[switchIndex].IDString);
if (switchLen <= maxLen || pos + switchLen > len)
continue;
@@ -122,7 +133,7 @@ bool CParser::ParseString(const UString &s, const CSwitchForm *switchForms)
NSwitchType::EEnum type = switchForm.Type;
switch(type)
{
case (NSwitchType::kPostMinus):
case NSwitchType::kPostMinus:
{
if (tailSize == 0)
matchedSwitch.WithMinus = false;
@@ -134,7 +145,7 @@ bool CParser::ParseString(const UString &s, const CSwitchForm *switchForms)
}
break;
}
case (NSwitchType::kPostChar):
case NSwitchType::kPostChar:
{
if (tailSize < switchForm.MinLen)
throw "switch is not full";
@@ -155,7 +166,8 @@ bool CParser::ParseString(const UString &s, const CSwitchForm *switchForms)
}
break;
}
case NSwitchType::kLimitedPostString: case NSwitchType::kUnLimitedPostString:
case NSwitchType::kLimitedPostString:
case NSwitchType::kUnLimitedPostString:
{
int minLen = switchForm.MinLen;
if (tailSize < minLen)
@@ -176,7 +188,10 @@ bool CParser::ParseString(const UString &s, const CSwitchForm *switchForms)
stringSwitch += c;
}
matchedSwitch.PostStrings.Add(stringSwitch);
break;
}
case NSwitchType::kSimple:
break;
}
}
return true;
@@ -223,7 +238,7 @@ bool ParseSubCharsCommand(int numForms, const CCommandSubCharsSet *forms,
{
const CCommandSubCharsSet &set = forms[i];
int currentIndex = -1;
int len = wcslen(set.Chars);
int len = MyStringLen(set.Chars);
for(int j = 0; j < len; j++)
{
wchar_t c = set.Chars[j];

View File

@@ -1,7 +1,5 @@
// Common/CommandLineParser.h
#pragma once
#ifndef __COMMON_COMMANDLINEPARSER_H
#define __COMMON_COMMANDLINEPARSER_H

View File

@@ -0,0 +1,93 @@
// 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;
int numChars = WideCharToMultiByte(codePage, 0, srcString,
srcString.Length(), resultString.GetBuffer(numRequiredBytes),
numRequiredBytes + 1, NULL, 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
Common/Copy of StringConvert.h Executable file
View File

@@ -0,0 +1,71 @@
// Common/StringConvert.h
#ifndef __COMMON_STRINGCONVERT_H
#define __COMMON_STRINGCONVERT_H
#include "MyWindows.h"
#include "Common/String.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 codePage)
{ return unicodeString; }
inline const UString& GetUnicodeString(const UString &unicodeString, UINT codePage)
{ 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 codePage)
{ return multiByteString; }
inline const char * GetSystemString(const char *multiByteString, UINT codePage)
{ 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

91
Common/Copy of UTFConvert.cpp Executable file
View 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
Common/Copy of UTFConvert.h Executable file
View File

@@ -0,0 +1,11 @@
// Common/UTFConvert.h
#ifndef __COMMON_UTFCONVERT_H
#define __COMMON_UTFCONVERT_H
#include "Common/String.h"
bool ConvertUTF8ToUnicode(const AString &utfString, UString &resultString);
bool ConvertUnicodeToUTF8(const UString &unicodeString, AString &resultString);
#endif

View File

@@ -1,7 +1,5 @@
// Common/Defs.h
// #pragma once
#ifndef __COMMON_DEFS_H
#define __COMMON_DEFS_H

View File

@@ -1,7 +1,5 @@
// Common/DynamicBuffer.h
#pragma once
#ifndef __COMMON_DYNAMICBUFFER_H
#define __COMMON_DYNAMICBUFFER_H
@@ -12,14 +10,14 @@ template <class T> class CDynamicBuffer: public CBuffer<T>
void GrowLength(size_t size)
{
size_t delta;
if (_capacity > 64)
delta = _capacity / 4;
else if (_capacity > 8)
if (this->_capacity > 64)
delta = this->_capacity / 4;
else if (this->_capacity > 8)
delta = 16;
else
delta = 4;
delta = MyMax(delta, size);
SetCapacity(_capacity + delta);
SetCapacity(this->_capacity + delta);
}
public:
CDynamicBuffer(): CBuffer<T>() {};
@@ -27,18 +25,18 @@ public:
CDynamicBuffer(size_t size): CBuffer<T>(size) {};
CDynamicBuffer& operator=(const CDynamicBuffer &buffer)
{
Free();
this->Free();
if(buffer._capacity > 0)
{
SetCapacity(buffer._capacity);
memmove(_items, buffer._items, buffer._capacity * sizeof(T));
memmove(this->_items, buffer._items, buffer._capacity * sizeof(T));
}
return *this;
}
void EnsureCapacity(size_t capacity)
{
if (_capacity < capacity)
GrowLength(capacity - _capacity);
if (this->_capacity < capacity)
GrowLength(capacity - this->_capacity);
}
};

View File

@@ -1,18 +1,8 @@
// Common/Exception.h
// #pragma once
#ifndef __COMMON_EXCEPTION_H
#define __COMMON_EXCEPTION_H
/*
struct CCException
{
CCException() {}
virtual ~CCException() {}
};
*/
struct CSystemException
{
DWORD ErrorCode;
@@ -21,4 +11,3 @@ struct CSystemException
};
#endif

View File

@@ -4,54 +4,60 @@
#include "IntToString.h"
void ConvertUINT64ToString(UINT64 value, char *s)
void ConvertUInt64ToString(UInt64 value, char *s, UInt32 base)
{
char temp[32];
if (base < 2 || base > 36)
{
*s = L'\0';
return;
}
char temp[72];
int pos = 0;
do
{
temp[pos++] = '0' + int(value % 10);
value /= 10;
int delta = (int)(value % base);
temp[pos++] = (delta < 10) ? ('0' + delta) : ('a' + (delta - 10));
value /= base;
}
while (value != 0);
while(pos > 0)
do
*s++ = temp[--pos];
*s = L'\0';
while(pos > 0);
*s = '\0';
}
void ConvertUINT64ToString(UINT64 value, wchar_t *s)
void ConvertUInt64ToString(UInt64 value, wchar_t *s)
{
wchar_t temp[32];
int pos = 0;
do
{
temp[pos++] = L'0' + int(value % 10);
temp[pos++] = L'0' + (int)(value % 10);
value /= 10;
}
while (value != 0);
while(pos > 0)
do
*s++ = temp[--pos];
while(pos > 0);
*s = L'\0';
}
void ConvertINT64ToString(INT64 value, char *s)
void ConvertInt64ToString(Int64 value, char *s)
{
if (value >= 0)
ConvertUINT64ToString(value, s);
else
if (value < 0)
{
*s++ = '-';
ConvertUINT64ToString(-value, s);
value = -value;
}
ConvertUInt64ToString(value, s);
}
void ConvertINT64ToString(INT64 value, wchar_t *s)
void ConvertInt64ToString(Int64 value, wchar_t *s)
{
if (value >= 0)
ConvertUINT64ToString(value, s);
else
if (value < 0)
{
*s++ = L'-';
ConvertUINT64ToString(-value, s);
value = -value;
}
ConvertUInt64ToString(value, s);
}

View File

@@ -1,18 +1,15 @@
// Common/IntToString.h
#pragma once
#ifndef __COMMON_INTTOSTRING_H
#define __COMMON_INTTOSTRING_H
#include "types.h"
#include <stddef.h>
#include "Types.h"
void ConvertUINT64ToString(UINT64 value, char *s);
void ConvertUINT64ToString(UINT64 value, wchar_t *s);
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);
void ConvertInt64ToString(Int64 value, char *s);
void ConvertInt64ToString(Int64 value, wchar_t *s);
#endif

View File

@@ -10,9 +10,9 @@
#include "Defs.h"
/*
static UINT32 HexStringToNumber(const char *string, int &finishPos)
static UInt32 HexStringToNumber(const char *string, int &finishPos)
{
UINT32 number = 0;
UInt32 number = 0;
for (finishPos = 0; finishPos < 8; finishPos++)
{
char c = string[finishPos];
@@ -31,7 +31,7 @@ static UINT32 HexStringToNumber(const char *string, int &finishPos)
return number;
}
*/
static bool HexStringToNumber(const UString &string, UINT32 &aResultValue)
static bool HexStringToNumber(const UString &string, UInt32 &aResultValue)
{
aResultValue = 0;
if (string.IsEmpty())
@@ -82,7 +82,7 @@ bool CLang::Open(LPCTSTR fileName)
int pos = 0;
if (string.Length() >= 3)
{
if (BYTE(string[0]) == 0xEF && BYTE(string[1]) == 0xBB && BYTE(string[2]) == 0xBF)
if (Byte(string[0]) == 0xEF && Byte(string[1]) == 0xBB && Byte(string[2]) == 0xBF)
pos += 3;
}
@@ -117,13 +117,13 @@ bool CLang::Open(LPCTSTR fileName)
return true;
}
int CLang::FindItem(UINT32 value) const
int CLang::FindItem(UInt32 value) const
{
int left = 0, right = _langPairs.Size();
while (left != right)
{
UINT32 mid = (left + right) / 2;
UINT32 midValue = _langPairs[mid].Value;
UInt32 mid = (left + right) / 2;
UInt32 midValue = _langPairs[mid].Value;
if (value == midValue)
return mid;
if (value < midValue)
@@ -134,7 +134,7 @@ int CLang::FindItem(UINT32 value) const
return -1;
}
bool CLang::GetMessage(UINT32 value, UString &message) const
bool CLang::GetMessage(UInt32 value, UString &message) const
{
int index = FindItem(value);
if (index < 0)

View File

@@ -1,16 +1,15 @@
// Common/Lang.h
#pragma once
#ifndef __COMMON_LANG_H
#define __COMMON_LANG_H
#include "Common/Vector.h"
#include "Common/String.h"
#include "Common/Types.h"
struct CLangPair
{
UINT32 Value;
UInt32 Value;
UString String;
};
@@ -20,8 +19,8 @@ class CLang
public:
bool Open(LPCTSTR fileName);
void Clear() { _langPairs.Clear(); }
int FindItem(UINT32 value) const;
bool GetMessage(UINT32 value, UString &message) const;
int FindItem(UInt32 value) const;
bool GetMessage(UInt32 value, UString &message) const;
};
#endif

View File

@@ -1,7 +1,5 @@
// Common/ListFileUtils.h
#pragma once
#ifndef __COMMON_LISTFILEUTILS_H
#define __COMMON_LISTFILEUTILS_H

View File

@@ -1,10 +1,10 @@
// MyCom.h
// #pragma once
#ifndef __MYCOM_H
#define __MYCOM_H
#include "MyWindows.h"
#define RINOK(x) { HRESULT __result_ = (x); if(__result_ != S_OK) return __result_; }
template <class T>
@@ -50,10 +50,12 @@ public:
_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)
{
@@ -146,8 +148,10 @@ public:
#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_END return E_NOINTERFACE; }
#define MY_ADDREF_RELEASE \
@@ -172,11 +176,13 @@ STDMETHOD_(ULONG, Release)() { if (--__m_RefCount != 0) \
MY_QUERYINTERFACE_ENTRY(i1) \
MY_QUERYINTERFACE_ENTRY(i2) \
)
#define MY_UNKNOWN_IMP3(i1, i2, i3) MY_UNKNOWN_IMP_SPEC( \
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(i1) \
MY_QUERYINTERFACE_ENTRY(i2) \
@@ -184,4 +190,12 @@ STDMETHOD_(ULONG, Release)() { if (--__m_RefCount != 0) \
MY_QUERYINTERFACE_ENTRY(i4) \
)
#define MY_UNKNOWN_IMP5(i1, i2, i3, i4, i5) MY_UNKNOWN_IMP_SPEC( \
MY_QUERYINTERFACE_ENTRY(i1) \
MY_QUERYINTERFACE_ENTRY(i2) \
MY_QUERYINTERFACE_ENTRY(i3) \
MY_QUERYINTERFACE_ENTRY(i4) \
MY_QUERYINTERFACE_ENTRY(i5) \
)
#endif

52
Common/MyGuidDef.h Executable file
View File

@@ -0,0 +1,52 @@
// Common/MyGuidDef.h
#ifndef GUID_DEFINED
#define GUID_DEFINED
typedef struct {
unsigned long Data1;
unsigned short Data2;
unsigned short 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 bool operator==(REFGUID g1, REFGUID g2)
{
for (int i = 0; i < (int)sizeof(g1); i++)
if (((unsigned char *)&g1)[i] != ((unsigned char *)&g2)[i])
return false;
return true;
}
inline bool 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

13
Common/MyInitGuid.h Executable file
View File

@@ -0,0 +1,13 @@
// Common/MyInitGuid.h
#ifndef __COMMON_MYINITGUID_H
#define __COMMON_MYINITGUID_H
#ifdef _WIN32
#include <initguid.h>
#else
#define INITGUID
#include "MyGuidDef.h"
#endif
#endif

24
Common/MyUnknown.h Executable file
View 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

113
Common/MyWindows.cpp Executable file
View File

@@ -0,0 +1,113 @@
// MyWindows.cpp
#include "StdAfx.h"
#ifndef _WIN32
#include "MyWindows.h"
#include "Types.h"
#include <malloc.h>
static inline void *AllocateForBSTR(size_t cb) { return ::malloc(cb); }
static inline void FreeForBSTR(void *pv) { ::free(pv);}
static UINT MyStringLen(const wchar_t *s)
{
UINT i;
for (i = 0; s[i] != '\0'; i++);
return i;
}
BSTR SysAllocStringByteLen(LPCSTR psz, UINT len)
{
int realLen = len + sizeof(UINT) + sizeof(OLECHAR) + sizeof(OLECHAR);
void *p = AllocateForBSTR(realLen);
if (p == 0)
return 0;
*(UINT *)p = len;
BSTR bstr = (BSTR)((UINT *)p + 1);
memmove(bstr, psz, len);
Byte *pb = ((Byte *)bstr) + len;
for (int i = 0; i < sizeof(OLECHAR) * 2; i++)
pb[i] = 0;
return bstr;
}
BSTR SysAllocString(const OLECHAR *sz)
{
if (sz == 0)
return 0;
UINT strLen = MyStringLen(sz);
UINT len = (strLen + 1) * sizeof(OLECHAR);
void *p = AllocateForBSTR(len + sizeof(UINT));
if (p == 0)
return 0;
*(UINT *)p = strLen;
BSTR bstr = (BSTR)((UINT *)p + 1);
memmove(bstr, sz, len);
return bstr;
}
void SysFreeString(BSTR bstr)
{
if (bstr != 0)
FreeForBSTR((UINT *)bstr - 1);
}
UINT SysStringByteLen(BSTR bstr)
{
if (bstr == 0)
return 0;
return *((UINT *)bstr - 1);
}
UINT SysStringLen(BSTR bstr)
{
return SysStringByteLen(bstr) / sizeof(OLECHAR);
}
HRESULT VariantClear(VARIANTARG *prop)
{
if (prop->vt == VT_BSTR)
SysFreeString(prop->bstrVal);
prop->vt = VT_EMPTY;
return S_OK;
}
HRESULT VariantCopy(VARIANTARG *dest, VARIANTARG *src)
{
HRESULT res = ::VariantClear(dest);
if (res != S_OK)
return res;
if (src->vt == VT_BSTR)
{
dest->bstrVal = SysAllocStringByteLen((LPCSTR)src->bstrVal,
SysStringByteLen(src->bstrVal));
if (dest->bstrVal == 0)
return E_OUTOFMEMORY;
dest->vt = VT_BSTR;
}
else
*dest = *src;
return S_OK;
}
LONG CompareFileTime(const FILETIME* ft1, const FILETIME* ft2)
{
if(ft1->dwHighDateTime < ft2->dwHighDateTime)
return -1;
if(ft1->dwHighDateTime > ft2->dwHighDateTime)
return 1;
if(ft1->dwLowDateTime < ft2->dwLowDateTime)
return -1;
if(ft1->dwLowDateTime > ft2->dwLowDateTime)
return 1;
return 0;
}
DWORD GetLastError()
{
return 0;
}
#endif

184
Common/MyWindows.h Executable file
View File

@@ -0,0 +1,184 @@
// MyWindows.h
#ifndef __MYWINDOWS_H
#define __MYWINDOWS_H
#ifdef _WIN32
#include <windows.h>
#else
#include <stddef.h> // for wchar_t
#include <string.h>
#include "Types.h"
#include "MyGuidDef.h"
typedef char CHAR;
typedef unsigned char UCHAR;
typedef unsigned char BYTE;
typedef short SHORT;
typedef unsigned short USHORT;
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;
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_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
struct IUnknown
{
STDMETHOD(QueryInterface) (REFIID iid, void **outObject) PURE;
STDMETHOD_(ULONG, AddRef)() PURE;
STDMETHOD_(ULONG, Release)() PURE;
};
typedef IUnknown *LPUNKNOWN;
#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;
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 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 HRESULT VariantClear(VARIANTARG *prop);
MY_EXTERN_C HRESULT VariantCopy(VARIANTARG *dest, VARIANTARG *src);
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

View File

@@ -8,6 +8,7 @@
#ifndef DEBUG_MEMORY_LEAK
#include <stdlib.h>
void * __cdecl operator new(size_t size)
{

View File

@@ -1,12 +1,8 @@
// Common/NewHandler.h
#pragma once
#ifndef __COMMON_NEWHANDLER_H
#define __COMMON_NEWHANDLER_H
#include "Exception.h"
class CNewException: public CSystemException{};
class CNewException {};
#endif

View File

@@ -3,6 +3,7 @@
#include "StdAfx.h"
#include <time.h>
#include <stdlib.h>
#include "Common/Random.h"

View File

@@ -1,7 +1,5 @@
// Common/Random.h
#pragma once
#ifndef __COMMON_RANDOM_H
#define __COMMON_RANDOM_H

View File

@@ -1,8 +1,8 @@
// stdafx.h
// StdAfx.h
#ifndef __STDAFX_H
#define __STDAFX_H
#include <windows.h>
// #include "MyWindows.h"
#endif

View File

@@ -39,18 +39,18 @@ CStdInStream::~CStdInStream()
AString CStdInStream::ScanStringUntilNewLine()
{
AString string;
AString s;
while(true)
{
int aIntChar = GetChar();
if(aIntChar == EOF)
int intChar = GetChar();
if(intChar == EOF)
throw kEOFMessage;
char aChar = char(aIntChar);
if (aChar == kIllegalChar)
char c = char(intChar);
if (c == kIllegalChar)
throw kIllegalCharMessage;
if(aChar == kNewLineChar)
return string;
string += aChar;
if(c == kNewLineChar)
return s;
s += c;
}
}

View File

@@ -1,13 +1,11 @@
// Common/StdInStream.h
#pragma once
#ifndef __COMMON_STDINSTREAM_H
#define __COMMON_STDINSTREAM_H
#include <stdio.h>
#include "String.h"
#include "Common/String.h"
#include "Types.h"
class CStdInStream

View File

@@ -10,15 +10,15 @@
static const char kNewLineChar = '\n';
static LPCTSTR kFileOpenMode = TEXT("wt");
static const char *kFileOpenMode = "wt";
CStdOutStream g_StdOut(stdout);
CStdOutStream g_StdErr(stderr);
bool CStdOutStream::Open(LPCTSTR fileName)
bool CStdOutStream::Open(const char *fileName)
{
Close();
_stream = _tfopen(fileName, kFileOpenMode);
_stream = fopen(fileName, kFileOpenMode);
_streamIsOpen = (_stream != 0);
return _streamIsOpen;
}
@@ -67,14 +67,14 @@ CStdOutStream & CStdOutStream::operator<<(char c)
CStdOutStream & CStdOutStream::operator<<(int number)
{
char textString[16];
ConvertINT64ToString(number, textString);
char textString[32];
ConvertInt64ToString(number, textString);
return operator<<(textString);
}
CStdOutStream & CStdOutStream::operator<<(UINT64 number)
CStdOutStream & CStdOutStream::operator<<(UInt64 number)
{
char textString[32];
ConvertUINT64ToString(number, textString);
ConvertUInt64ToString(number, textString);
return operator<<(textString);
}

View File

@@ -1,7 +1,5 @@
// Common/StdOutStream.h
#pragma once
#ifndef __COMMON_STDOUTSTREAM_H
#define __COMMON_STDOUTSTREAM_H
@@ -17,7 +15,7 @@ public:
CStdOutStream (): _streamIsOpen(false) {};
CStdOutStream (FILE *stream): _streamIsOpen(false), _stream(stream) {};
~CStdOutStream ();
bool Open(LPCTSTR fileName);
bool Open(const char *fileName);
bool Close();
CStdOutStream & operator<<(CStdOutStream & (* aFunction)(CStdOutStream &));
@@ -25,7 +23,7 @@ public:
CStdOutStream & operator<<(const wchar_t *string);
CStdOutStream & operator<<(char c);
CStdOutStream & operator<<(int number);
CStdOutStream & operator<<(UINT64 number);
CStdOutStream & operator<<(UInt64 number);
};
CStdOutStream & endl(CStdOutStream & outStream);

View File

@@ -2,8 +2,16 @@
#include "StdAfx.h"
#include "String.h"
#ifdef _WIN32
#include "StringConvert.h"
#else
#include <ctype.h>
#endif
#include "Common/String.h"
#ifdef _WIN32
#ifndef _UNICODE
@@ -11,9 +19,9 @@ wchar_t MyCharUpper(wchar_t c)
{
if (c == 0)
return 0;
wchar_t *res = CharUpperW((LPWSTR)c);
wchar_t *res = CharUpperW((LPWSTR)(unsigned int)c);
if (res != 0 || ::GetLastError() != ERROR_CALL_NOT_IMPLEMENTED)
return (wchar_t)res;
return (wchar_t)(unsigned int)res;
const int kBufferSize = 4;
char s[kBufferSize];
int numChars = ::WideCharToMultiByte(CP_ACP, 0, &c, 1, s, kBufferSize, 0, 0);
@@ -26,9 +34,9 @@ wchar_t MyCharLower(wchar_t c)
{
if (c == 0)
return 0;
wchar_t *res = CharLowerW((LPWSTR)c);
wchar_t *res = CharLowerW((LPWSTR)(unsigned int)c);
if (res != 0 || ::GetLastError() != ERROR_CALL_NOT_IMPLEMENTED)
return (wchar_t)res;
return (wchar_t)(unsigned int)res;
const int kBufferSize = 4;
char s[kBufferSize];
int numChars = ::WideCharToMultiByte(CP_ACP, 0, &c, 1, s, kBufferSize, 0, 0);
@@ -61,24 +69,107 @@ wchar_t * MyStringLower(wchar_t *s)
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
inline int NormalizeCompareResult(int res)
{
if (res < 0) return -1;
if (res > 0) return 1;
return 0;
}
/*
inline wchar_t MyCharUpper(wchar_t c)
{ return towupper(c); }
*/
wchar_t MyCharUpper(wchar_t c)
{
return toupper(c);
}
int MyStringCollateNoCase(const wchar_t *s1, const wchar_t *s2)
{
while (true)
{
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)
{
while (true)
{
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)
{
while (true)
{
wchar_t c1 = *s1++;
wchar_t c2 = *s2++;
if (c1 < c2) return -1;
if (c1 > c2) return 1;
if (c1 == 0) return 0;
}
}

View File

@@ -1,13 +1,16 @@
// Common/String.h
#pragma once
#ifndef __COMMON_STRING_H
#define __COMMON_STRING_H
#include <string.h>
// #include <wchar.h>
#include "Vector.h"
extern bool g_IsNT;
#ifdef _WIN32
#include "MyWindows.h"
#endif
static const char *kTrimDefaultCharSet = " \n\t";
@@ -36,7 +39,7 @@ inline wchar_t* MyStringGetPrevCharPointer(const wchar_t *base, wchar_t *p)
inline const wchar_t* MyStringGetPrevCharPointer(const wchar_t *base, const wchar_t *p)
{ return (p - 1); }
#ifdef WIN32
#ifdef _WIN32
inline char* MyStringGetNextCharPointer(char *p)
{ return CharNextA(p); }
@@ -49,7 +52,7 @@ inline const char* MyStringGetPrevCharPointer(const char *base, const char *p)
{ return CharPrevA(base, p); }
inline char MyCharUpper(char c)
{ return (char)CharUpperA((LPSTR)(unsigned char)c); }
{ return (char)(unsigned int)CharUpperA((LPSTR)(unsigned int)(unsigned char)c); }
#ifdef _UNICODE
inline wchar_t MyCharUpper(wchar_t c)
{ return (wchar_t)CharUpperW((LPWSTR)c); }
@@ -58,7 +61,7 @@ wchar_t MyCharUpper(wchar_t c);
#endif
inline char MyCharLower(char c)
{ return (char)CharLowerA((LPSTR)(unsigned char)c); }
{ return (char)(unsigned int)CharLowerA((LPSTR)(unsigned int)(unsigned char)c); }
#ifdef _UNICODE
inline wchar_t MyCharLower(wchar_t c)
{ return (wchar_t)CharLowerW((LPWSTR)c); }
@@ -66,89 +69,36 @@ inline wchar_t MyCharLower(wchar_t c)
wchar_t MyCharLower(wchar_t c);
#endif
inline char * MyStringUpper(char *s)
{ return CharUpperA(s); }
inline char * MyStringUpper(char *s) { return CharUpperA(s); }
#ifdef _UNICODE
inline wchar_t * MyStringUpper(wchar_t *s)
{ return CharUpperW(s); }
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); }
inline char * MyStringLower(char *s) { return CharLowerA(s); }
#ifdef _UNICODE
inline wchar_t * MyStringLower(wchar_t *s)
{ return CharLowerW(s); }
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
inline int ConvertCompareResult(int r)
{ return r - 2; }
inline int MyStringCollate(const char *s1, const char *s2)
{ return ConvertCompareResult(CompareStringA(
LOCALE_USER_DEFAULT, SORT_STRINGSORT, s1, -1, s2, -1)); }
#ifdef _UNICODE
inline int MyStringCollate(const wchar_t *s1, const wchar_t *s2)
{ return ConvertCompareResult(CompareStringW(
LOCALE_USER_DEFAULT, SORT_STRINGSORT, s1, -1, s2, -1)); }
#else
#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);
#endif
inline int MyStringCollateNoCase(const char *s1, const char *s2)
{ return ConvertCompareResult(CompareStringA(
LOCALE_USER_DEFAULT, NORM_IGNORECASE | SORT_STRINGSORT, s1, -1, s2, -1)); }
#ifdef _UNICODE
inline int MyStringCollateNoCase(const wchar_t *s1, const wchar_t *s2)
{ return ConvertCompareResult(CompareStringW(
LOCALE_USER_DEFAULT, NORM_IGNORECASE | SORT_STRINGSORT, s1, -1, s2, -1)); }
#else
int MyStringCollateNoCase(const wchar_t *s1, const wchar_t *s2);
#endif
#else // Standard-C
inline NormalizeCompareResult(int res)
{
if (res < 0)
return -1;
if (res > 0)
return 1;
return 0;
}
inline wchar_t MyCharUpper(wchar_t c)
{ return towupper(c); }
inline int MyStringCollateNoCase(const wchar_t *s1, const wchar_t *s2)
{ return NormalizeCompareResult(wcscoll(s1, s2)); }
#endif
template <class T>
inline int MyStringCompare(const T *s1, const T *s2)
{
while (true)
{
unsigned int c1 = (unsigned int)*s1++;
unsigned int c2 = (unsigned int)*s2++;
if (c1 < c2)
return -1;
if (c1 > c2)
return 1;
if (c1 == 0)
return 0;
}
}
int MyStringCompare(const char *s1, const char *s2);
int MyStringCompare(const wchar_t *s1, const wchar_t *s2);
template <class T>
inline int MyStringCompareNoCase(const T *s1, const T *s2)
@@ -471,21 +421,24 @@ public:
p = GetNextCharPointer(p);
Delete(0, p - _chars);
}
void TrimLeft()
private:
CStringBase GetTrimDefaultCharSet()
{
CStringBase<T> charSet;
for(int i = 0; i < sizeof(kTrimDefaultCharSet) /
sizeof(kTrimDefaultCharSet[0]); i++)
charSet += kTrimDefaultCharSet[i];
TrimLeftWithCharSet(charSet);
for(int i = 0; i < (int)(sizeof(kTrimDefaultCharSet) /
sizeof(kTrimDefaultCharSet[0])); i++)
charSet += (T)kTrimDefaultCharSet[i];
return charSet;
}
public:
void TrimLeft()
{
TrimLeftWithCharSet(GetTrimDefaultCharSet());
}
void TrimRight()
{
CStringBase<T> charSet;
for(int i = 0; i < sizeof(kTrimDefaultCharSet) /
sizeof(kTrimDefaultCharSet[0]); i++)
charSet += kTrimDefaultCharSet[i];
TrimRightWithCharSet(charSet);
TrimRightWithCharSet(GetTrimDefaultCharSet());
}
void TrimRight(T c)
{

View File

@@ -4,7 +4,11 @@
#include "StringConvert.h"
#ifdef WIN32
#ifndef _WIN32
#include <stdlib.h>
#endif
#ifdef _WIN32
UString MultiByteToUnicodeString(const AString &srcString, UINT codePage)
{
UString resultString;
@@ -57,6 +61,14 @@ 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;
}
@@ -65,7 +77,17 @@ 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
#endif

View File

@@ -1,11 +1,10 @@
// Common/StringConvert.h
#pragma once
#ifndef __COMMON_STRINGCONVERT_H
#define __COMMON_STRINGCONVERT_H
#include "String.h"
#include "MyWindows.h"
#include "Common/String.h"
#include "Types.h"
UString MultiByteToUnicodeString(const AString &srcString, UINT codePage = CP_ACP);

View File

@@ -4,9 +4,9 @@
#include "StringToInt.h"
UINT64 ConvertStringToUINT64(const char *s, const char **end)
UInt64 ConvertStringToUInt64(const char *s, const char **end)
{
UINT64 result = 0;
UInt64 result = 0;
while(true)
{
char c = *s;
@@ -22,9 +22,9 @@ UINT64 ConvertStringToUINT64(const char *s, const char **end)
}
}
UINT64 ConvertStringToUINT64(const wchar_t *s, const wchar_t **end)
UInt64 ConvertStringToUInt64(const wchar_t *s, const wchar_t **end)
{
UINT64 result = 0;
UInt64 result = 0;
while(true)
{
wchar_t c = *s;
@@ -41,10 +41,9 @@ UINT64 ConvertStringToUINT64(const wchar_t *s, const wchar_t **end)
}
INT64 ConvertStringToINT64(const char *s, const char **end)
Int64 ConvertStringToInt64(const char *s, const char **end)
{
INT64 result = 0;
if (*s == '-')
return -(INT64)ConvertStringToUINT64(s + 1, end);
return ConvertStringToUINT64(s, end);
return -(Int64)ConvertStringToUInt64(s + 1, end);
return ConvertStringToUInt64(s, end);
}

View File

@@ -1,14 +1,15 @@
// Common/StringToInt.h
#pragma once
#ifndef __COMMON_STRINGTOINT_H
#define __COMMON_STRINGTOINT_H
UINT64 ConvertStringToUINT64(const char *s, const char **end);
UINT64 ConvertStringToUINT64(const wchar_t *s, const wchar_t **end);
#include <string.h>
#include "Types.h"
INT64 ConvertStringToINT64(const char *s, const char **end);
UInt64 ConvertStringToUInt64(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

View File

@@ -1,7 +1,5 @@
// Common/TextConfig.h
#pragma once
#ifndef __COMMON_TEXTCONFIG_H
#define __COMMON_TEXTCONFIG_H

View File

@@ -1,19 +1,19 @@
// Common/Types.h
// #pragma once
#ifndef __COMMON_TYPES_H
#define __COMMON_TYPES_H
#include <basetsd.h>
typedef unsigned char UINT8;
typedef unsigned short UINT16;
typedef short INT16;
#ifndef _WINDOWS_
// typedef unsigned long UINT32;
typedef UINT8 BYTE;
typedef unsigned char Byte;
typedef short Int16;
typedef unsigned short UInt16;
typedef int Int32;
typedef unsigned int UInt32;
#ifdef _MSC_VER
typedef __int64 Int64;
typedef unsigned __int64 UInt64;
#else
typedef long long int Int64;
typedef unsigned long long int UInt64;
#endif
#endif

View File

@@ -5,66 +5,87 @@
#include "UTFConvert.h"
#include "Types.h"
bool ConvertUTF8ToUnicode(const AString &utfString, UString &resultString)
static Byte kUtf8Limits[5] = { 0xC0, 0xE0, 0xF0, 0xF8, 0xFC };
// These functions are for UTF8 <-> UTF16 conversion.
bool ConvertUTF8ToUnicode(const AString &src, UString &dest)
{
resultString.Empty();
for(int i = 0; i < utfString.Length(); i++)
dest.Empty();
for(int i = 0; i < src.Length();)
{
BYTE c = utfString[i];
Byte c = (Byte)src[i++];
if (c < 0x80)
{
resultString += c;
dest += (wchar_t)c;
continue;
}
if(c < 0xC0 || c >= 0xF0)
if(c < 0xC0)
return false;
i++;
if (i >= utfString.Length())
return false;
BYTE c2 = utfString[i];
if (c2 < 0x80)
return false;
c2 -= 0x80;
if (c2 >= 0x40)
return false;
if (c < 0xE0)
int numAdds;
for (numAdds = 1; numAdds < 5; numAdds++)
if (c < kUtf8Limits[numAdds])
break;
UInt32 value = (c - kUtf8Limits[numAdds - 1]);
do
{
resultString += wchar_t( ((wchar_t(c - 0xC0)) << 6) + c2);
continue;
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));
}
i++;
if (i >= utfString.Length())
return false;
BYTE c3 = utfString[i];
c3 -= 0x80;
if (c3 >= 0x40)
return false;
resultString += wchar_t(((wchar_t(c - 0xE0)) << 12) +
((wchar_t(c2)) << 6) + c3);
}
return true;
}
void ConvertUnicodeToUTF8(const UString &unicodeString, AString &resultString)
bool ConvertUnicodeToUTF8(const UString &src, AString &dest)
{
resultString.Empty();
for(int i = 0; i < unicodeString.Length(); i++)
dest.Empty();
for(int i = 0; i < src.Length();)
{
wchar_t c = unicodeString[i];
if (c < 0x80)
UInt32 value = (UInt32)src[i++];
if (value < 0x80)
{
resultString += char(c);
dest += (char)value;
continue;
}
if (c < 0x07FF)
if (value >= 0xD800 && value < 0xE000)
{
resultString += char(0xC0 + (c >> 6));
resultString += char(0x80 + (c & 0x003F));
continue;
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);
}
resultString += char(0xE0 + (c >> 12));
resultString += char(0x80 + ((c >> 6) & 0x003F));
resultString += char(0x80 + (c & 0x003F));
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;
}

View File

@@ -1,13 +1,11 @@
// Common/UTFConvert.h
#pragma once
#ifndef __COMMON_UTFCONVERT_H
#define __COMMON_UTFCONVERT_H
#include "Common/String.h"
bool ConvertUTF8ToUnicode(const AString &utfString, UString &resultString);
void ConvertUnicodeToUTF8(const UString &unicodeString, AString &resultString);
bool ConvertUnicodeToUTF8(const UString &unicodeString, AString &resultString);
#endif

View File

@@ -2,6 +2,8 @@
#include "StdAfx.h"
#include <string.h>
#include "Vector.h"
CBaseRecordVector::~CBaseRecordVector()
@@ -42,7 +44,7 @@ void CBaseRecordVector::Reserve(int newCapacity)
unsigned char *p = new unsigned char[newCapacity * _itemSize];
int numRecordsToMove = _capacity;
memmove(p, _items, _itemSize * numRecordsToMove);
delete []_items;
delete [](unsigned char *)_items;
_items = p;
_capacity = newCapacity;
}

View File

@@ -1,7 +1,5 @@
// Common/Vector.h
#pragma once
#ifndef __COMMON_VECTOR_H
#define __COMMON_VECTOR_H
@@ -22,7 +20,7 @@ protected:
{ if (index + num > _size) num = _size - index; }
public:
CBaseRecordVector(size_t itemSize):
_size(0), _capacity(0), _items(0), _itemSize(itemSize) {}
_capacity(0), _size(0), _items(0), _itemSize(itemSize) {}
virtual ~CBaseRecordVector();
int Size() const { return _size; }
bool IsEmpty() const { return (_size == 0); }
@@ -72,7 +70,11 @@ public:
T& Front() { return operator[](0); }
const T& Back() const { return operator[](_size - 1); }
T& Back() { return operator[](_size - 1); }
static int __cdecl CompareRecordItems(const void *a1, const void *a2)
static int
#ifdef _MSC_VER
__cdecl
#endif
CompareRecordItems(const void *a1, const void *a2)
{ return MyCompare(*((const T *)a1), *((const T *)a2)); }
void Sort()
{ qsort(&Front(), Size(), _itemSize, CompareRecordItems); }
@@ -125,7 +127,7 @@ public:
int Find(const T& item) const
{
for(int i = 0; i < Size(); i++)
if (item == (*this)[mid])
if (item == (*this)[i])
return i;
return -1;
}
@@ -165,7 +167,11 @@ public:
Insert(right, item);
return right;
}
static int __cdecl CompareObjectItems(const void *a1, const void *a2)
static int
#ifdef _MSC_VER
__cdecl
#endif
CompareObjectItems(const void *a1, const void *a2)
{ return MyCompare(*(*((const T **)a1)), *(*((const T **)a2))); }
void Sort()
{

View File

@@ -2,7 +2,7 @@
#include "StdAfx.h"
#include "WildCard.h"
#include "Wildcard.h"
static const wchar_t kPeriodChar = L'.';
static const wchar_t kAnyCharsChar = L'*';
@@ -11,12 +11,6 @@ static const wchar_t kAnyCharChar = L'?';
static const wchar_t kDirDelimiter1 = L'\\';
static const wchar_t kDirDelimiter2 = L'/';
static const wchar_t kDiskNameDelimiterChar = ':';
static const UString kRootDirName = L"";
static const wchar_t kSpaceChar = L' ';
static const UString kWildCardCharSet = L"?*";
static const UString kIllegalWildCardFileNameChars=
@@ -50,8 +44,10 @@ static bool EnhancedMaskTest(const UString &mask, int maskPos,
wchar_t maskChar = mask[maskPos];
if(maskChar == kAnyCharChar)
{
/*
if (EnhancedMaskTest(mask, maskPos + 1, name, namePos))
return true;
*/
if (nameLen == 0)
return false;
return EnhancedMaskTest(mask, maskPos + 1, name, namePos + 1);
@@ -68,7 +64,9 @@ static bool EnhancedMaskTest(const UString &mask, int maskPos,
{
wchar_t c = name[namePos];
if (maskChar != c)
#ifdef _WIN32
if (MyCharUpper(maskChar) != MyCharUpper(c))
#endif
return false;
return EnhancedMaskTest(mask, maskPos + 1, name, namePos + 1);
}
@@ -98,50 +96,43 @@ void SplitPathToParts(const UString &path, UStringVector &pathParts)
pathParts.Add(name);
}
/*
void SplitPathToParts(const AString &path, AStringVector &pathParts)
void SplitPathToParts(const UString &path, UString &dirPrefix, UString &name)
{
pathParts.Clear();
AString 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 += path[i];
}
pathParts.Add(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);
}
*/
// --------------------------------------------------
// ExtractFileNameFromPath
UString ExtractFileNameFromPath(const UString &pathName)
UString ExtractDirPrefixFromPath(const UString &path)
{
UString result;
int len = pathName.Length();
for(int i = len - 1; i >= 0; i--)
if(IsCharDirLimiter(pathName[i]))
return pathName.Mid(i + 1);
return pathName;
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, 0, name, 0);
}
bool DoesNameContainWildCard(const UString &pathName)
bool DoesNameContainWildCard(const UString &path)
{
return (pathName.FindOneOf(kWildCardCharSet) >= 0);
return (path.FindOneOf(kWildCardCharSet) >= 0);
}
@@ -155,182 +146,286 @@ static inline int BoolToIndex(bool value)
return value ? 1: 0;
}
const UStringVector& CCensorNode::GetNamesVector(bool allowed, bool recursed, bool wildCard) const
/*
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
{
return _names[BoolToIndex(allowed)][BoolToIndex(recursed)][BoolToIndex(wildCard)];
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;
}
void CCensorNode::AddItem(const UString &name, bool allowed, bool recursed, bool wildCard)
{
_names[BoolToIndex(allowed)][BoolToIndex(recursed)][BoolToIndex(wildCard)].Add(name);
}
CCensorNode *CCensorNode::FindSubNode(const UString &name)
int CCensorNode::FindSubNode(const UString &name) const
{
for (int i = 0; i < SubNodes.Size(); i++)
if (name.CollateNoCase(SubNodes[i].Name) == 0)
return &SubNodes[i];
return NULL;
}
CCensorNode *CCensorNode::AddSubNode(const UString &name)
{
CCensorNode *subNode = FindSubNode(name);
if (subNode != NULL)
return subNode;
SubNodes.Add(CCensorNode(this, name));
return &SubNodes.Back();
}
int FindString(const UStringVector &strings, const UString &string)
{
for (int i = 0; i < strings.Size(); i++)
if (string.CollateNoCase(strings[i]) == 0)
if (SubNodes[i].Name.CollateNoCase(name) == 0)
return i;
return -1;
}
int FindInWildcardVector(const UStringVector &strings, const UString &string)
void CCensorNode::AddItem(CItem &item)
{
for (int i = 0; i < strings.Size(); i++)
if (CompareWildCardWithName(strings[i], string))
return i;
return -1;
}
bool CCensorNode::CheckName(const UString &name, bool allowed, bool recursed) const
{
if (FindString(_names[BoolToIndex(allowed)][BoolToIndex(recursed)][0], name) >= 0)
return true;
if (FindInWildcardVector(_names[BoolToIndex(allowed)][BoolToIndex(recursed)][1], name) >= 0)
return true;
return false;
}
bool CCensorNode::CheckNameRecursive(const UString &name, bool allowed) const
{
const CCensorNode *curItem = this;
while (curItem != NULL)
if (item.PathParts.Size() <= 1)
{
if (curItem->CheckName(name, allowed, true))
Items.Add(item);
return;
}
const UString &front = item.PathParts.Front();
if (DoesNameContainWildCard(front))
{
Items.Add(item);
return;
}
int index = FindSubNode(front);
if (index < 0)
index = SubNodes.Add(CCensorNode(front, this));
item.PathParts.Delete(0);
SubNodes[index].AddItem(item);
}
void CCensorNode::AddItem(const UString &path, bool include, bool recursive, bool forFile, bool forDir)
{
CItem item;
SplitPathToParts(path, item.PathParts);
item.Include = include;
item.Recursive = recursive;
item.ForFile = forFile;
item.ForDir = forDir;
AddItem(item);
}
bool CCensorNode::NeedCheckSubDirs() const
{
for (int i = 0; i < Items.Size(); i++)
{
const CItem &item = Items[i];
if (!item.Include)
continue;
if (item.Recursive || item.PathParts.Size() > 1)
return true;
curItem = curItem->_parent;
}
return false;
}
bool CCensorNode::CheckNameRecursive(const UString &name) const
bool CCensorNode::CheckPathCurrent(const UStringVector &pathParts, bool isFile, bool &include) const
{
if (!CheckNameRecursive(name, true))
return false;
return !CheckNameRecursive(name, false);
}
bool CCensorNode::CheckNameFull(const UString &name, bool allowed) const
{
if (CheckName(name, allowed, false))
return true;
return CheckNameRecursive(name, allowed);
}
bool CCensorNode::CheckNameFull(const UString &name) const
{
if (!CheckNameFull(name, true))
return false;
return !CheckNameFull(name, false);
}
////////////////////////////////////
// CCensor
void CCensor::AddItem(const UString &path, bool allowed, bool recursed, bool wildCard)
{
UStringVector pathParts;
SplitPathToParts(path, pathParts);
int numParts = pathParts.Size();
if (numParts == 0)
throw "Empty path";
CCensorNode *curItem = &_head;
int i;
for(i = 0; i < numParts - 1; i++)
curItem = curItem->AddSubNode(pathParts[i]);
curItem->AddItem(pathParts[i], allowed, recursed, wildCard);
}
bool CCensor::CheckName(const UString &path) const
{
UStringVector pathParts;
SplitPathToParts(path, pathParts);
int numParts = pathParts.Size();
if (numParts == 0)
throw "Empty path";
const CCensorNode *curItem = &_head;
const UString &name = pathParts[numParts - 1];
for(int i = 0; i < numParts - 1; i++)
bool finded = false;
for (int i = 0; i < Items.Size(); i++)
{
const CCensorNode *nextItem = ((CCensorNode *)curItem)->FindSubNode(pathParts[i]);
if (nextItem == NULL)
return curItem->CheckNameRecursive(name);
curItem = nextItem;
const CItem &item = Items[i];
if (item.CheckPath(pathParts, isFile))
{
finded = true;
include = item.Include;
if (!include)
return true;
}
}
return curItem->CheckNameFull(name);
return finded;
}
}
////////////////////////////////////
// Filename and WildCard function
static bool TestStringLengthAndBounds(const UString &string)
bool CCensorNode::CheckPath(UStringVector &pathParts, bool isFile, bool &include) const
{
if (string.Length() <= 0)
return false;
return (string.ReverseFind(kSpaceChar) != string.Length() - 1);
}
bool IsFileNameLegal(const UString &name)
{
if (!TestStringLengthAndBounds(name))
return false;
return (name.FindOneOf(kIllegalFileNameChars) < 0);
bool finded = CheckPathCurrent(pathParts, isFile, include);
if (finded && !include)
return true;
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))
finded = true;
}
return finded;
}
bool IsWildCardFileNameLegal(const UString &name)
{
if (!TestStringLengthAndBounds(name))
return false;
return (name.FindOneOf(kIllegalWildCardFileNameChars) < 0);
}
bool IsFilePathLegal(const UString &path)
bool CCensorNode::CheckPath(const UString &path, bool isFile, bool &include) const
{
UStringVector pathParts;
SplitPathToParts(path, pathParts);
int count = pathParts.Size();
if (count == 0)
return false;
for(int i = 0; i < count; i++)
if (!IsFileNameLegal(pathParts[i]))
return false;
return true;
return CheckPath(pathParts, isFile, include);
}
bool IsWildCardFilePathLegal(const UString &path)
bool CCensorNode::CheckPath(const UString &path, bool isFile) const
{
bool include;
if(CheckPath(path, isFile, include))
return include;
return false;
}
bool CCensorNode::CheckPathToRoot(UStringVector &pathParts, bool isFile, bool &include) const
{
bool finded = CheckPathCurrent(pathParts, isFile, include);
if (finded && !include)
return true;
if (Parent == 0)
return finded;
pathParts.Insert(0, Name);
if (Parent->CheckPathToRoot(pathParts, isFile, include))
finded = true;
return finded;
}
bool CCensorNode::CheckPathToRoot(UStringVector &pathParts, bool isFile) const
{
bool include;
if(CheckPathToRoot(pathParts, isFile, include))
return include;
return false;
}
bool CCensorNode::CheckPathToRoot(const UString &path, bool isFile) const
{
UStringVector pathParts;
SplitPathToParts(path, pathParts);
int count = pathParts.Size();
if (count == 0)
return false;
for(int i = 0; i < count - 1; i++)
if (!IsFileNameLegal(pathParts[i]))
return false;
return IsWildCardFileNameLegal(pathParts[count - 1]);
return CheckPathToRoot(pathParts, isFile);
}
static bool IsCharAPrefixDelimiter(wchar_t c)
void CCensorNode::AddItem2(const UString &path, bool include, bool recursive)
{
return (IsCharDirLimiter(c) || c == kDiskNameDelimiterChar);
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(path2, include, recursive, forFile, forFolder);
}
int CCensor::FindPrefix(const UString &prefix) const
{
for (int i = 0; i < Pairs.Size(); i++)
if (Pairs[i].Prefix.CollateNoCase(prefix) == 0)
return i;
return -1;
}
void CCensor::AddItem(const UString &path, bool include, 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 += L'\\';
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.Include = include;
item.Recursive = recursive;
Pairs[index].Head.AddItem(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;
}
}
bool AreTheFileNamesDirDelimiterEqual(const UString &name1, const UString &name2)
@@ -348,4 +443,3 @@ bool AreTheFileNamesDirDelimiterEqual(const UString &name1, const UString &name2
}
return true;
}

View File

@@ -1,55 +1,75 @@
// Common/Wildcard.h
#pragma once
#ifndef __COMMON_WILDCARD_H
#define __COMMON_WILDCARD_H
#include "Common/String.h"
void SplitPathToParts(const UString &path, UStringVector &aPathParts);
// void SplitPathToParts(const AString &path, AStringVector &aPathParts);
UString ExtractFileNameFromPath(const UString &pathName);
bool DoesNameContainWildCard(const UString &pathName);
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 Include;
bool Recursive;
bool ForFile;
bool ForDir;
bool CheckPath(const UStringVector &pathParts, bool isFile) const;
};
class CCensorNode
{
CCensorNode *_parent;
UStringVector _names[2][2][2];
bool CheckNameRecursive(const UString &name, bool allowed) const;
bool CheckNameFull(const UString &name, bool allowed) const;
public:
UString Name;
CCensorNode *Parent;
bool CheckPathCurrent(const UStringVector &pathParts, bool isFile, bool &include) const;
public:
CCensorNode(): Parent(0) { };
CCensorNode(const UString &name, CCensorNode *parent):
Name(name), Parent(parent) { };
CObjectVector<CCensorNode> SubNodes;
CCensorNode(CCensorNode *parent, const UString &name):
_parent(parent), Name(name) {};
CCensorNode *FindSubNode(const UString &name);
CCensorNode *AddSubNode(const UString &name);
void AddItem(const UString &name, bool allowed, bool recursed, bool wildCard);
bool CheckName(const UString &name, bool allowed, bool recursed) const;
bool CheckNameRecursive(const UString &name) const;
bool CheckNameFull(const UString &name) const;
CObjectVector<CItem> Items;
const UStringVector&GetNamesVector(bool allowed, bool recursed, bool wildCard) const;
const UStringVector&GetAllowedNamesVector(bool recursed, bool wildCard) const
{ return GetNamesVector(true, recursed, wildCard); }
const UStringVector&GetRecursedNamesVector(bool allowed, bool wildCard) const
{ return GetNamesVector(allowed, true, wildCard); }
const UStringVector&GetAllowedRecursedNamesVector(bool wildCard) const
{ return GetRecursedNamesVector(true, wildCard); }
int FindSubNode(const UString &path) const;
void AddItem(CItem &item);
void AddItem(const UString &path, bool include, bool recursive, bool forFile, bool forDir);
void AddItem2(const UString &path, bool include, bool recursive);
bool NeedCheckSubDirs() const;
bool CheckPath(UStringVector &pathParts, bool isFile, bool &include) const;
bool CheckPath(const UString &path, bool isFile, bool &include) const;
bool CheckPath(const UString &path, bool isFile) const;
bool CheckPathToRoot(UStringVector &pathParts, bool isFile, bool &include) const;
bool CheckPathToRoot(UStringVector &pathParts, bool isFile) const;
bool CheckPathToRoot(const UString &path, bool isFile) const;
};
struct CPair
{
UString Prefix;
CCensorNode Head;
CPair(const UString &prefix): Prefix(prefix) { };
};
class CCensor
{
int FindPrefix(const UString &prefix) const;
public:
CCensorNode _head;
CCensor(): _head(NULL, L"") {}
void AddItem(const UString &path, bool allowed, bool recursed, bool wildCard);
bool CheckName(const UString &path) const;
CObjectVector<CPair> Pairs;
bool AllAreRelative() const
{ return (Pairs.Size() == 1 && Pairs.Front().Prefix.IsEmpty()); }
void AddItem(const UString &path, bool include, bool recursive);
bool CheckPath(const UString &path, bool isFile) const;
};
}

View File

@@ -1,75 +0,0 @@
// Common/WindowsTypes.h
// #pragma once
#ifndef __COMMON_WindowsTypes_H
#define __COMMON_WindowsTypes_H
// typedef unsigned long UINT32;
typedef unsigned __int64 UINT64;
typedef UINT32 UINT;
typedef UINT32 DWORD;
#define CP_ACP 0
#define CP_OEMCP 1
#define CP_UTF8 65001
typedef const char *LPCTSTR;
typedef const wchar_t *LPCWSTR;
#define TEXT
typedef struct {
unsigned long Data1;
unsigned short Data2;
unsigned short Data3;
unsigned char Data4[ 8 ];
} GUID;
typedef GUID CLSID;
typedef char TCHAR;
typedef char CHAR;
typedef unsigned char UCHAR;
typedef short SHORT;
typedef unsigned short USHORT;
typedef int INT;
typedef UINT UINT_PTR;
typedef long BOOL;
typedef long LONG;
typedef unsigned long ULONG;
#define FALSE 0
#define TRUE 1
typedef short VARIANT_BOOL;
#define VARIANT_TRUE ((VARIANT_BOOL)-1)
#define VARIANT_FALSE ((VARIANT_BOOL)0)
#define FILE_ATTRIBUTE_READONLY 0x00000001
#define FILE_ATTRIBUTE_HIDDEN 0x00000002
#define FILE_ATTRIBUTE_SYSTEM 0x00000004
#define FILE_ATTRIBUTE_DIRECTORY 0x00000010
#define FILE_ATTRIBUTE_ARCHIVE 0x00000020
#define FILE_ATTRIBUTE_DEVICE 0x00000040
#define FILE_ATTRIBUTE_NORMAL 0x00000080
#define FILE_ATTRIBUTE_TEMPORARY 0x00000100
#define FILE_ATTRIBUTE_SPARSE_FILE 0x00000200
#define FILE_ATTRIBUTE_REPARSE_POINT 0x00000400
#define FILE_ATTRIBUTE_COMPRESSED 0x00000800
#define FILE_ATTRIBUTE_OFFLINE 0x00001000
#define FILE_ATTRIBUTE_NOT_CONTENT_INDEXED 0x00002000
#define FILE_ATTRIBUTE_ENCRYPTED 0x00004000
typedef struct _FILETIME {
DWORD dwLowDateTime;
DWORD dwHighDateTime;
} FILETIME, *PFILETIME, *LPFILETIME;
typedef void *HANDLE;
typedef __int64 LONGLONG;
typedef unsigned __int64 ULONGLONG;
struct LARGE_INTEGER { LONGLONG QuadPart; };
struct ULARGE_INTEGER { ULONGLONG QuadPart; };
typedef float FLOAT;
typedef double DOUBLE;
typedef VARIANT_BOOL _VARIANT_BOOL;
typedef LONG SCODE;
struct CY { LONGLONG int64; };
typedef double DATE;
typedef wchar_t *BSTR;
#endif