Restructure repository to include all source folders

Move git root from Client/ to src/ to track all source code:
- Client: Game client source (moved to Client/Client/)
- Server: Game server source
- GameTools: Development tools
- CryptoSource: Encryption utilities
- database: Database scripts
- Script: Game scripts
- rylCoder_16.02.2008_src: Legacy coder tools
- GMFont, Game: Additional resources

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
2025-11-29 20:17:20 +09:00
parent 5d3cd64a25
commit dd97ddec92
11602 changed files with 1446576 additions and 0 deletions

View File

@@ -0,0 +1,451 @@
/* lzoconf.h -- configuration for the LZO real-time data compression library
This file is part of the LZO real-time data compression library.
Copyright (C) 2002 Markus Franz Xaver Johannes Oberhumer
Copyright (C) 2001 Markus Franz Xaver Johannes Oberhumer
Copyright (C) 2000 Markus Franz Xaver Johannes Oberhumer
Copyright (C) 1999 Markus Franz Xaver Johannes Oberhumer
Copyright (C) 1998 Markus Franz Xaver Johannes Oberhumer
Copyright (C) 1997 Markus Franz Xaver Johannes Oberhumer
Copyright (C) 1996 Markus Franz Xaver Johannes Oberhumer
All Rights Reserved.
The LZO library is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License as
published by the Free Software Foundation; either version 2 of
the License, or (at your option) any later version.
The LZO library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with the LZO library; see the file COPYING.
If not, write to the Free Software Foundation, Inc.,
59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
Markus F.X.J. Oberhumer
<markus@oberhumer.com>
http://www.oberhumer.com/opensource/lzo/
*/
#ifndef __LZOCONF_H
#define __LZOCONF_H
#define LZO_VERSION 0x1080
#define LZO_VERSION_STRING "1.08"
#define LZO_VERSION_DATE "Jul 12 2002"
/* internal Autoconf configuration file - only used when building LZO */
#if defined(LZO_HAVE_CONFIG_H)
# include <config.h>
#endif
#include <limits.h>
#ifdef __cplusplus
extern "C" {
#endif
/***********************************************************************
// LZO requires a conforming <limits.h>
************************************************************************/
#if !defined(CHAR_BIT) || (CHAR_BIT != 8)
# error "invalid CHAR_BIT"
#endif
#if !defined(UCHAR_MAX) || !defined(UINT_MAX) || !defined(ULONG_MAX)
# error "check your compiler installation"
#endif
#if (USHRT_MAX < 1) || (UINT_MAX < 1) || (ULONG_MAX < 1)
# error "your limits.h macros are broken"
#endif
/* workaround a cpp bug under hpux 10.20 */
#define LZO_0xffffffffL 4294967295ul
#if !defined(LZO_UINT32_C)
# if (UINT_MAX < LZO_0xffffffffL)
# define LZO_UINT32_C(c) c ## UL
# else
# define LZO_UINT32_C(c) c ## U
# endif
#endif
/***********************************************************************
// architecture defines
************************************************************************/
#if !defined(__LZO_WIN) && !defined(__LZO_DOS) && !defined(__LZO_OS2)
# if defined(__WINDOWS__) || defined(_WINDOWS) || defined(_Windows)
# define __LZO_WIN
# elif defined(__WIN32__) || defined(_WIN32) || defined(WIN32)
# define __LZO_WIN
# elif defined(__NT__) || defined(__NT_DLL__) || defined(__WINDOWS_386__)
# define __LZO_WIN
# elif defined(__DOS__) || defined(__MSDOS__) || defined(MSDOS)
# define __LZO_DOS
# elif defined(__OS2__) || defined(__OS2V2__) || defined(OS2)
# define __LZO_OS2
# elif defined(__palmos__)
# define __LZO_PALMOS
# elif defined(__TOS__) || defined(__atarist__)
# define __LZO_TOS
# endif
#endif
#if (UINT_MAX < LZO_0xffffffffL)
# if defined(__LZO_WIN)
# define __LZO_WIN16
# elif defined(__LZO_DOS)
# define __LZO_DOS16
# elif defined(__LZO_PALMOS)
# define __LZO_PALMOS16
# elif defined(__LZO_TOS)
# define __LZO_TOS16
# elif defined(__C166__)
# else
/* porting hint: for pure 16-bit architectures try compiling
* everything with -D__LZO_STRICT_16BIT */
# error "16-bit target not supported - contact me for porting hints"
# endif
#endif
#if !defined(__LZO_i386)
# if defined(__LZO_DOS) || defined(__LZO_WIN16)
# define __LZO_i386
# elif defined(__i386__) || defined(__386__) || defined(_M_IX86)
# define __LZO_i386
# endif
#endif
#if defined(__LZO_STRICT_16BIT)
# if (UINT_MAX < LZO_0xffffffffL)
# include <lzo16bit.h>
# endif
#endif
/* memory checkers */
#if !defined(__LZO_CHECKER)
# if defined(__BOUNDS_CHECKING_ON)
# define __LZO_CHECKER
# elif defined(__CHECKER__)
# define __LZO_CHECKER
# elif defined(__INSURE__)
# define __LZO_CHECKER
# elif defined(__PURIFY__)
# define __LZO_CHECKER
# endif
#endif
/***********************************************************************
// integral and pointer types
************************************************************************/
/* Integral types with 32 bits or more */
#if !defined(LZO_UINT32_MAX)
# if (UINT_MAX >= LZO_0xffffffffL)
typedef unsigned int lzo_uint32;
typedef int lzo_int32;
# define LZO_UINT32_MAX UINT_MAX
# define LZO_INT32_MAX INT_MAX
# define LZO_INT32_MIN INT_MIN
# elif (ULONG_MAX >= LZO_0xffffffffL)
typedef unsigned long lzo_uint32;
typedef long lzo_int32;
# define LZO_UINT32_MAX ULONG_MAX
# define LZO_INT32_MAX LONG_MAX
# define LZO_INT32_MIN LONG_MIN
# else
# error "lzo_uint32"
# endif
#endif
/* lzo_uint is used like size_t */
#if !defined(LZO_UINT_MAX)
# if (UINT_MAX >= LZO_0xffffffffL)
typedef unsigned int lzo_uint;
typedef int lzo_int;
# define LZO_UINT_MAX UINT_MAX
# define LZO_INT_MAX INT_MAX
# define LZO_INT_MIN INT_MIN
# elif (ULONG_MAX >= LZO_0xffffffffL)
typedef unsigned long lzo_uint;
typedef long lzo_int;
# define LZO_UINT_MAX ULONG_MAX
# define LZO_INT_MAX LONG_MAX
# define LZO_INT_MIN LONG_MIN
# else
# error "lzo_uint"
# endif
#endif
typedef int lzo_bool;
/***********************************************************************
// memory models
************************************************************************/
/* Memory model for the public code segment. */
#if !defined(__LZO_CMODEL)
# if defined(__LZO_DOS16) || defined(__LZO_WIN16)
# define __LZO_CMODEL __far
# elif defined(__LZO_i386) && defined(__WATCOMC__)
# define __LZO_CMODEL __near
# else
# define __LZO_CMODEL
# endif
#endif
/* Memory model for the public data segment. */
#if !defined(__LZO_DMODEL)
# if defined(__LZO_DOS16) || defined(__LZO_WIN16)
# define __LZO_DMODEL __far
# elif defined(__LZO_i386) && defined(__WATCOMC__)
# define __LZO_DMODEL __near
# else
# define __LZO_DMODEL
# endif
#endif
/* Memory model that allows to access memory at offsets of lzo_uint. */
#if !defined(__LZO_MMODEL)
# if (LZO_UINT_MAX <= UINT_MAX)
# define __LZO_MMODEL
# elif defined(__LZO_DOS16) || defined(__LZO_WIN16)
# define __LZO_MMODEL __huge
# define LZO_999_UNSUPPORTED
# elif defined(__LZO_PALMOS16) || defined(__LZO_TOS16)
# define __LZO_MMODEL
# else
# error "__LZO_MMODEL"
# endif
#endif
/* no typedef here because of const-pointer issues */
#define lzo_byte unsigned char __LZO_MMODEL
#define lzo_bytep unsigned char __LZO_MMODEL *
#define lzo_charp char __LZO_MMODEL *
#define lzo_voidp void __LZO_MMODEL *
#define lzo_shortp short __LZO_MMODEL *
#define lzo_ushortp unsigned short __LZO_MMODEL *
#define lzo_uint32p lzo_uint32 __LZO_MMODEL *
#define lzo_int32p lzo_int32 __LZO_MMODEL *
#define lzo_uintp lzo_uint __LZO_MMODEL *
#define lzo_intp lzo_int __LZO_MMODEL *
#define lzo_voidpp lzo_voidp __LZO_MMODEL *
#define lzo_bytepp lzo_bytep __LZO_MMODEL *
#ifndef lzo_sizeof_dict_t
# define lzo_sizeof_dict_t sizeof(lzo_bytep)
#endif
/***********************************************************************
// calling conventions and function types
************************************************************************/
/* linkage */
#if !defined(__LZO_EXTERN_C)
# ifdef __cplusplus
# define __LZO_EXTERN_C extern "C"
# else
# define __LZO_EXTERN_C extern
# endif
#endif
/* calling convention */
#if !defined(__LZO_CDECL)
# if defined(__LZO_DOS16) || defined(__LZO_WIN16)
# define __LZO_CDECL __LZO_CMODEL __cdecl
# elif defined(__LZO_i386) && defined(_MSC_VER)
# define __LZO_CDECL __LZO_CMODEL __cdecl
# elif defined(__LZO_i386) && defined(__WATCOMC__)
# define __LZO_CDECL __LZO_CMODEL __cdecl
# else
# define __LZO_CDECL __LZO_CMODEL
# endif
#endif
#if !defined(__LZO_ENTRY)
# define __LZO_ENTRY __LZO_CDECL
#endif
/* C++ exception specification for extern "C" function types */
#if !defined(__cplusplus)
# undef LZO_NOTHROW
# define LZO_NOTHROW
#elif !defined(LZO_NOTHROW)
# define LZO_NOTHROW
#endif
typedef int
(__LZO_ENTRY *lzo_compress_t) ( const lzo_byte *src, lzo_uint src_len,
lzo_byte *dst, lzo_uintp dst_len,
lzo_voidp wrkmem );
typedef int
(__LZO_ENTRY *lzo_decompress_t) ( const lzo_byte *src, lzo_uint src_len,
lzo_byte *dst, lzo_uintp dst_len,
lzo_voidp wrkmem );
typedef int
(__LZO_ENTRY *lzo_optimize_t) ( lzo_byte *src, lzo_uint src_len,
lzo_byte *dst, lzo_uintp dst_len,
lzo_voidp wrkmem );
typedef int
(__LZO_ENTRY *lzo_compress_dict_t)(const lzo_byte *src, lzo_uint src_len,
lzo_byte *dst, lzo_uintp dst_len,
lzo_voidp wrkmem,
const lzo_byte *dict, lzo_uint dict_len );
typedef int
(__LZO_ENTRY *lzo_decompress_dict_t)(const lzo_byte *src, lzo_uint src_len,
lzo_byte *dst, lzo_uintp dst_len,
lzo_voidp wrkmem,
const lzo_byte *dict, lzo_uint dict_len );
/* assembler versions always use __cdecl */
typedef int
(__LZO_CDECL *lzo_compress_asm_t)( const lzo_byte *src, lzo_uint src_len,
lzo_byte *dst, lzo_uintp dst_len,
lzo_voidp wrkmem );
typedef int
(__LZO_CDECL *lzo_decompress_asm_t)( const lzo_byte *src, lzo_uint src_len,
lzo_byte *dst, lzo_uintp dst_len,
lzo_voidp wrkmem );
/* a progress indicator callback function */
typedef void (__LZO_ENTRY *lzo_progress_callback_t) (lzo_uint, lzo_uint);
/***********************************************************************
// export information
************************************************************************/
/* DLL export information */
#if !defined(__LZO_EXPORT1)
# define __LZO_EXPORT1
#endif
#if !defined(__LZO_EXPORT2)
# define __LZO_EXPORT2
#endif
/* exported calling convention for C functions */
#if !defined(LZO_PUBLIC)
# define LZO_PUBLIC(_rettype) \
__LZO_EXPORT1 _rettype __LZO_EXPORT2 __LZO_ENTRY
#endif
#if !defined(LZO_EXTERN)
# define LZO_EXTERN(_rettype) __LZO_EXTERN_C LZO_PUBLIC(_rettype)
#endif
#if !defined(LZO_PRIVATE)
# define LZO_PRIVATE(_rettype) static _rettype __LZO_ENTRY
#endif
/* exported __cdecl calling convention for assembler functions */
#if !defined(LZO_PUBLIC_CDECL)
# define LZO_PUBLIC_CDECL(_rettype) \
__LZO_EXPORT1 _rettype __LZO_EXPORT2 __LZO_CDECL
#endif
#if !defined(LZO_EXTERN_CDECL)
# define LZO_EXTERN_CDECL(_rettype) __LZO_EXTERN_C LZO_PUBLIC_CDECL(_rettype)
#endif
/* exported global variables (LZO currently uses no static variables and
* is fully thread safe) */
#if !defined(LZO_PUBLIC_VAR)
# define LZO_PUBLIC_VAR(_type) \
__LZO_EXPORT1 _type __LZO_EXPORT2 __LZO_DMODEL
#endif
#if !defined(LZO_EXTERN_VAR)
# define LZO_EXTERN_VAR(_type) extern LZO_PUBLIC_VAR(_type)
#endif
/***********************************************************************
// error codes and prototypes
************************************************************************/
/* Error codes for the compression/decompression functions. Negative
* values are errors, positive values will be used for special but
* normal events.
*/
#define LZO_E_OK 0
#define LZO_E_ERROR (-1)
#define LZO_E_OUT_OF_MEMORY (-2) /* not used right now */
#define LZO_E_NOT_COMPRESSIBLE (-3) /* not used right now */
#define LZO_E_INPUT_OVERRUN (-4)
#define LZO_E_OUTPUT_OVERRUN (-5)
#define LZO_E_LOOKBEHIND_OVERRUN (-6)
#define LZO_E_EOF_NOT_FOUND (-7)
#define LZO_E_INPUT_NOT_CONSUMED (-8)
/* lzo_init() should be the first function you call.
* Check the return code !
*
* lzo_init() is a macro to allow checking that the library and the
* compiler's view of various types are consistent.
*/
#define lzo_init() __lzo_init2(LZO_VERSION,(int)sizeof(short),(int)sizeof(int),\
(int)sizeof(long),(int)sizeof(lzo_uint32),(int)sizeof(lzo_uint),\
(int)lzo_sizeof_dict_t,(int)sizeof(char *),(int)sizeof(lzo_voidp),\
(int)sizeof(lzo_compress_t))
LZO_EXTERN(int) __lzo_init2(unsigned,int,int,int,int,int,int,int,int,int);
/* version functions (useful for shared libraries) */
LZO_EXTERN(unsigned) lzo_version(void);
LZO_EXTERN(const char *) lzo_version_string(void);
LZO_EXTERN(const char *) lzo_version_date(void);
LZO_EXTERN(const lzo_charp) _lzo_version_string(void);
LZO_EXTERN(const lzo_charp) _lzo_version_date(void);
/* string functions */
LZO_EXTERN(int)
lzo_memcmp(const lzo_voidp _s1, const lzo_voidp _s2, lzo_uint _len);
LZO_EXTERN(lzo_voidp)
lzo_memcpy(lzo_voidp _dest, const lzo_voidp _src, lzo_uint _len);
LZO_EXTERN(lzo_voidp)
lzo_memmove(lzo_voidp _dest, const lzo_voidp _src, lzo_uint _len);
LZO_EXTERN(lzo_voidp)
lzo_memset(lzo_voidp _s, int _c, lzo_uint _len);
/* checksum functions */
LZO_EXTERN(lzo_uint32)
lzo_adler32(lzo_uint32 _adler, const lzo_byte *_buf, lzo_uint _len);
LZO_EXTERN(lzo_uint32)
lzo_crc32(lzo_uint32 _c, const lzo_byte *_buf, lzo_uint _len);
/* misc. */
LZO_EXTERN(lzo_bool) lzo_assert(int _expr);
LZO_EXTERN(int) _lzo_config_check(void);
typedef union { lzo_bytep p; lzo_uint u; } __lzo_pu_u;
typedef union { lzo_bytep p; lzo_uint32 u32; } __lzo_pu32_u;
typedef union { void *vp; lzo_bytep bp; lzo_uint32 u32; long l; } lzo_align_t;
/* align a char pointer on a boundary that is a multiple of `size' */
LZO_EXTERN(unsigned) __lzo_align_gap(const lzo_voidp _ptr, lzo_uint _size);
#define LZO_PTR_ALIGN_UP(_ptr,_size) \
((_ptr) + (lzo_uint) __lzo_align_gap((const lzo_voidp)(_ptr),(lzo_uint)(_size)))
/* deprecated - only for backward compatibility */
#define LZO_ALIGN(_ptr,_size) LZO_PTR_ALIGN_UP(_ptr,_size)
#ifdef __cplusplus
} /* extern "C" */
#endif
#endif /* already included */

View File

@@ -0,0 +1,31 @@
#include "stdafx.h"
#include "miniLZOWrapper.h"
#include <winsock2.h>
#include <windows.h>
#include <cstdio>
bool CMiniLZOCompress::TestMiniLZO()
{
const int MAX_BUFFER = 5 * 1024 * 1024;
char* szBuffer1 = new char[MAX_BUFFER];
char* szBuffer2 = new char[MAX_BUFFER];
DWORD dwOut = 0;
DWORD dwDecompressInOut = MAX_BUFFER;
sprintf(szBuffer1, "<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>");
CMiniLZOCompress::Compress(szBuffer1, MAX_BUFFER, szBuffer2, &dwOut);
memset(szBuffer1, 0, MAX_BUFFER);
CMiniLZOCompress::Decompress(szBuffer2, dwOut, szBuffer1, &dwDecompressInOut);
MessageBox(NULL, szBuffer1, NULL, NULL);
delete [] szBuffer1;
delete [] szBuffer2;
return true;
}

View File

@@ -0,0 +1,29 @@
#ifndef _MINI_LZO_WRAPPER_H_
#define _MINI_LZO_WRAPPER_H_
#include "minilzo.h"
class CMiniLZOCompress
{
public:
inline static bool Compress(const char* in, unsigned long in_len, char* out, unsigned long* lp_out_len);
inline static bool Decompress(const char* in, unsigned long in_len, char* out, unsigned long* buffersize_in_out_len);
static bool TestMiniLZO();
};
inline bool CMiniLZOCompress::Compress(const char* in, unsigned long in_len, char* out, unsigned long* lp_out_len)
{
lzo_voidp wrkmem[LZO1X_1_MEM_COMPRESS]; // <20><><EFBFBD><EFBFBD> <20><><EFBFBD>۸<EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD>Ѵ<EFBFBD>.
return (LZO_E_OK == lzo1x_1_compress(reinterpret_cast<const lzo_byte*>(in), in_len,
reinterpret_cast<lzo_byte*>(out), reinterpret_cast<lzo_uintp>(lp_out_len), wrkmem));
}
inline bool CMiniLZOCompress::Decompress(const char* in, unsigned long in_len, char* out, unsigned long* buffersize_in_out_len)
{
return (LZO_E_OK == lzo1x_decompress_safe(reinterpret_cast<const lzo_byte*>(in), in_len,
reinterpret_cast<lzo_byte*>(out), reinterpret_cast<lzo_uintp>(buffersize_in_out_len), 0));
}
#endif

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,100 @@
/* minilzo.h -- mini subset of the LZO real-time data compression library
This file is part of the LZO real-time data compression library.
Copyright (C) 2002 Markus Franz Xaver Johannes Oberhumer
Copyright (C) 2001 Markus Franz Xaver Johannes Oberhumer
Copyright (C) 2000 Markus Franz Xaver Johannes Oberhumer
Copyright (C) 1999 Markus Franz Xaver Johannes Oberhumer
Copyright (C) 1998 Markus Franz Xaver Johannes Oberhumer
Copyright (C) 1997 Markus Franz Xaver Johannes Oberhumer
Copyright (C) 1996 Markus Franz Xaver Johannes Oberhumer
All Rights Reserved.
The LZO library is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License as
published by the Free Software Foundation; either version 2 of
the License, or (at your option) any later version.
The LZO library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with the LZO library; see the file COPYING.
If not, write to the Free Software Foundation, Inc.,
59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
Markus F.X.J. Oberhumer
<markus@oberhumer.com>
http://www.oberhumer.com/opensource/lzo/
*/
/*
* NOTE:
* the full LZO package can be found at
* http://www.oberhumer.com/opensource/lzo/
*/
#ifndef __MINILZO_H
#define __MINILZO_H
#define MINILZO_VERSION 0x1080
#ifdef __LZOCONF_H
# error "you cannot use both LZO and miniLZO"
#endif
#undef LZO_HAVE_CONFIG_H
#include "lzoconf.h"
#if !defined(LZO_VERSION) || (LZO_VERSION != MINILZO_VERSION)
# error "version mismatch in header files"
#endif
#ifdef __cplusplus
extern "C" {
#endif
/***********************************************************************
//
************************************************************************/
/* Memory required for the wrkmem parameter.
* When the required size is 0, you can also pass a NULL pointer.
*/
#define LZO1X_MEM_COMPRESS LZO1X_1_MEM_COMPRESS
#define LZO1X_1_MEM_COMPRESS ((lzo_uint32) (16384L * lzo_sizeof_dict_t))
#define LZO1X_MEM_DECOMPRESS (0)
/* compression */
LZO_EXTERN(int)
lzo1x_1_compress ( const lzo_byte *src, lzo_uint src_len,
lzo_byte *dst, lzo_uintp dst_len,
lzo_voidp wrkmem );
/* decompression */
LZO_EXTERN(int)
lzo1x_decompress ( const lzo_byte *src, lzo_uint src_len,
lzo_byte *dst, lzo_uintp dst_len,
lzo_voidp wrkmem /* NOT USED */ );
/* safe decompression with overrun testing */
LZO_EXTERN(int)
lzo1x_decompress_safe ( const lzo_byte *src, lzo_uint src_len,
lzo_byte *dst, lzo_uintp dst_len,
lzo_voidp wrkmem /* NOT USED */ );
#ifdef __cplusplus
} /* extern "C" */
#endif
#endif /* already included */

View File

@@ -0,0 +1,381 @@
#include "stdafx.h"
#include "DelimitedFile.h"
// TODO: CDelimitedFile::Write <20><20><><EFBFBD><EFBFBD>
CDelimitedFile::CDelimitedFile(const char* pszDelimiter)
: m_fpFile(0), m_dwColumn(0), m_dwColumnCount(0)
{
m_ColumnNames.reserve(DEFAULT_COLUMN_NUM);
strncpy(m_szDelimiter, pszDelimiter, MAX_DELIMITER_NUM);
}
CDelimitedFile::~CDelimitedFile()
{
Close();
}
BOOL CDelimitedFile::Open( LPCSTR szFilename, int nHeadLine, UINT nOpenFlags )
{
m_fpFile = ::fopen( szFilename, (nOpenFlags & modeCreate) ? "wt" : "rt" );
if (NULL == m_fpFile)
{
#ifdef ERRLOG2
DWORD dwError = ::GetLastError();
ERRLOG2(g_Log, "<EFBFBD><EFBFBD><EFBFBD><EFBFBD> %s<><73> <20><> <20><> <20><><EFBFBD><EFBFBD><EFBFBD>ϴ<EFBFBD>. Error Code : %d", szFilename, dwError);
#endif
return FALSE;
}
if (nHeadLine > -1)
{
for (int i=0; i<nHeadLine; ++i)
{
ReadLine();
}
for(m_dwColumnCount = 0; true; ++m_dwColumnCount)
{
char* szColumnName = new char[MAX_COLUMN_LENGHT];
if(0 == szColumnName)
{
return FALSE;
}
if(false == ReadString(szColumnName, MAX_COLUMN_LENGHT - 1))
{
delete szColumnName;
break;
}
size_t nLength = strlen(szColumnName);
while(nLength-- > 0)
{
if(szColumnName[nLength] == '\r' || szColumnName[nLength] == '\n')
{
szColumnName[nLength] = 0;
}
}
szColumnName[MAX_COLUMN_LENGHT - 1] = 0;
m_ColumnNames.push_back(szColumnName);
}
}
return TRUE;
}
void CDelimitedFile::Close( void )
{
if( m_fpFile )
{
::fclose( m_fpFile );
m_fpFile = 0;
}
ColumnArray::size_type nTotalSize = m_ColumnNames.size();
for(ColumnArray::size_type nCount = 0; nCount < nTotalSize; ++nCount)
{
delete [] m_ColumnNames[nCount];
}
m_ColumnNames.clear();
}
BOOL CDelimitedFile::ReadLine( void )
{
while( ::fgets( m_szLine, MAX_LINE_LENGTH, m_fpFile ) ) {
if( (m_szLine[0]) && (m_szLine[0] != ';') ) {
m_dwColumn = 0;
memcpy(m_szBackupLine, m_szLine, MAX_LINE_LENGTH);
return TRUE;
}
}
return FALSE;
}
BOOL CDelimitedFile::ReadData( bool &bNumber )
{
CHAR *pszData = ::strtok( (m_dwColumn++) ? NULL : m_szLine, m_szDelimiter );
if( !pszData || !(*pszData) )
return FALSE;
bNumber = false;
if (atoi(pszData) == 1)
bNumber = true;
char szString[2];
strncpy(szString, pszData, 1);
if (NULL == ::strcmp(szString, "O"))
bNumber = true;
return TRUE;
}
BOOL CDelimitedFile::ReadData( double &dNumber )
{
CHAR *pszData = ::strtok( (m_dwColumn++) ? NULL : m_szLine, m_szDelimiter );
if( !pszData || !(*pszData) )
return FALSE;
dNumber = atof( pszData );
return TRUE;
}
BOOL CDelimitedFile::ReadData( float &fNumber )
{
CHAR *pszData = ::strtok( (m_dwColumn++) ? NULL : m_szLine, m_szDelimiter );
if( !pszData || !(*pszData) )
return FALSE;
fNumber = (float) atof( pszData );
return TRUE;
}
BOOL CDelimitedFile::ReadData( unsigned long &fNumber )
{
CHAR *pszData = ::strtok( (m_dwColumn++) ? NULL : m_szLine, m_szDelimiter );
if( !pszData || !(*pszData) )
return FALSE;
fNumber = (unsigned long) atol( pszData );
return TRUE;
}
BOOL CDelimitedFile::ReadData( int &iNumber )
{
CHAR *pszData = ::strtok( (m_dwColumn++) ? NULL : m_szLine, m_szDelimiter );
if( !pszData || !(*pszData) )
return FALSE;
iNumber = atoi( pszData );
return TRUE;
}
BOOL CDelimitedFile::ReadData( unsigned short &iNumber )
{
CHAR *pszData = ::strtok( (m_dwColumn++) ? NULL : m_szLine, m_szDelimiter );
if( !pszData || !(*pszData) )
return FALSE;
iNumber = (unsigned short)atoi( pszData );
return TRUE;
}
BOOL CDelimitedFile::ReadData( short &iNumber )
{
CHAR *pszData = ::strtok( (m_dwColumn++) ? NULL : m_szLine, m_szDelimiter );
if( !pszData || !(*pszData) )
return FALSE;
iNumber = (short)atoi( pszData );
return TRUE;
}
BOOL CDelimitedFile::ReadData( unsigned char &iNumber )
{
CHAR *pszData = ::strtok( (m_dwColumn++) ? NULL : m_szLine, m_szDelimiter );
if( !pszData || !(*pszData) )
return FALSE;
iNumber = (unsigned char)atoi( pszData );
return TRUE;
}
BOOL CDelimitedFile::ReadData( char &iNumber )
{
CHAR *pszData = ::strtok( (m_dwColumn++) ? NULL : m_szLine, m_szDelimiter );
if( !pszData || !(*pszData) )
return FALSE;
iNumber = (char)atoi( pszData );
return TRUE;
}
BOOL CDelimitedFile::ReadData( __int64 &i64Number )
{
CHAR *pszData = ::strtok( (m_dwColumn++) ? NULL : m_szLine, m_szDelimiter );
if( !pszData || !(*pszData) )
return FALSE;
i64Number = _atoi64( pszData );
return TRUE;
}
BOOL CDelimitedFile::ReadData( DWORD64 &i64Number )
{
CHAR *pszData = ::strtok( (m_dwColumn++) ? NULL : m_szLine, m_szDelimiter );
if( !pszData || !(*pszData) )
return FALSE;
i64Number = (DWORD)_atoi64( pszData );
return TRUE;
}
BOOL CDelimitedFile::ReadString( char *szString, DWORD dwSize )
{
CHAR *pszData = ::strtok( (m_dwColumn++) ? NULL : m_szLine, m_szDelimiter );
if( !pszData || !(*pszData) )
return FALSE;
strncpy(szString, pszData, dwSize);
return TRUE;
}
BOOL CDelimitedFile::ReadData(const char *szField, double &dNumber )
{
int nSearch;
if( ((nSearch = FindColumn( szField )) == -1) )
return FALSE;
GotoColumn( nSearch );
return ReadData( dNumber );
}
BOOL CDelimitedFile::ReadData(const char *szField, float &fNumber )
{
int nSearch;
if( ((nSearch = FindColumn( szField )) == -1) )
return FALSE;
GotoColumn( nSearch );
return ReadData( fNumber );
}
BOOL CDelimitedFile::ReadData(const char *szField, unsigned long &fNumber )
{
int nSearch;
if( ((nSearch = FindColumn( szField )) == -1) )
return FALSE;
GotoColumn( nSearch );
return ReadData( fNumber );
}
BOOL CDelimitedFile::ReadData(const char *szField, int &iNumber )
{
int nSearch;
if( ((nSearch = FindColumn( szField )) == -1) )
return FALSE;
GotoColumn( nSearch );
return ReadData( iNumber );
}
BOOL CDelimitedFile::ReadData(const char *szField, unsigned short &iNumber )
{
int nSearch;
if( ((nSearch = FindColumn( szField )) == -1) )
return FALSE;
GotoColumn( nSearch );
return ReadData( iNumber );
}
BOOL CDelimitedFile::ReadData(const char *szField, short &iNumber )
{
int nSearch;
if( ((nSearch = FindColumn( szField )) == -1) )
return FALSE;
GotoColumn( nSearch );
return ReadData( iNumber );
}
BOOL CDelimitedFile::ReadData(const char *szField, unsigned char &iNumber )
{
int nSearch;
if( ((nSearch = FindColumn( szField )) == -1) )
return FALSE;
GotoColumn( nSearch );
return ReadData( iNumber );
}
BOOL CDelimitedFile::ReadData(const char *szField, char &iNumber )
{
int nSearch;
if( ((nSearch = FindColumn( szField )) == -1) )
return FALSE;
GotoColumn( nSearch );
return ReadData( iNumber );
}
BOOL CDelimitedFile::ReadData(const char *szField, __int64 &i64Number )
{
int nSearch;
if( ((nSearch = FindColumn( szField )) == -1) )
return FALSE;
GotoColumn( nSearch );
return ReadData( i64Number );
}
BOOL CDelimitedFile::ReadData(const char *szField, DWORD64 &i64Number )
{
int nSearch;
if( ((nSearch = FindColumn( szField )) == -1) )
return FALSE;
GotoColumn( nSearch );
return ReadData( i64Number );
}
BOOL CDelimitedFile::ReadString(const char *szField, char *szString, DWORD dwSize )
{
int nSearch;
if( ((nSearch = FindColumn( szField )) == -1) )
return FALSE;
GotoColumn( nSearch );
return ReadString( szString, dwSize );
}
BOOL CDelimitedFile::GotoColumn( int nColumn )
{
CHAR* pszPos = 0;
if(nColumn < 0 || (DWORD)nColumn > m_dwColumnCount) {
return FALSE;
}
if((m_dwColumn == (DWORD) nColumn)) {
return TRUE;
}
if( nColumn == 0 ) {
m_dwColumn = 0;
strtok(m_szLine, m_szDelimiter);
}
else {
for(;m_dwColumn < m_dwColumnCount && nColumn != m_dwColumn; ++m_dwColumn )
pszPos = strtok(0, m_szDelimiter);
if(m_dwColumn == m_dwColumnCount) {
memcpy(m_szLine, m_szBackupLine, MAX_LINE_LENGTH);
pszPos = strtok(m_szLine, m_szDelimiter);
for(m_dwColumn = 1; m_dwColumn < (DWORD)nColumn && nColumn != m_dwColumn; ++m_dwColumn ) {
pszPos = strtok(NULL, m_szDelimiter );
}
}
}
return TRUE;
}
int CDelimitedFile::FindColumn(const char *szField)
{
for(ColumnArray::size_type nCount = 0; nCount < m_ColumnNames.size(); ++nCount)
{
const char* szColumnName = m_ColumnNames[nCount];
if(0 == strcmp(szField, szColumnName))
{
return static_cast<int>(nCount);
}
}
return -1;
}

View File

@@ -0,0 +1,92 @@
#ifndef _DELIMITED_FILE_H_
#define _DELIMITED_FILE_H_
#pragma once
#include <winsock2.h>
#include <windows.h>
#include <vector>
class CDelimitedFile
{
public:
// MAX Delimiter num is 32;
CDelimitedFile(const char* pszDelimiter = "\t");
~CDelimitedFile();
enum {
MAX_LINE_LENGTH = 8192,
MAX_DELIMITER_NUM = 32,
MAX_COLUMN_LENGHT = 64,
DEFAULT_COLUMN_NUM = 32
};
enum OpenFlags {
modeRead = (int) 0x00000,
modeCreate = (int) 0x01000
};
private:
FILE *m_fpFile;
DWORD m_dwColumn;
DWORD m_dwColumnCount;
CHAR m_szLine[MAX_LINE_LENGTH];
CHAR m_szBackupLine[MAX_LINE_LENGTH];
char m_szDelimiter[MAX_DELIMITER_NUM];
typedef std::vector<char*> ColumnArray;
ColumnArray m_ColumnNames;
private:
int FindColumn(const char *szField );
BOOL GotoColumn( int nColumn );
public:
BOOL Open(LPCSTR szFilename, int nHeadLine = -1, UINT nOpenFlags = modeRead );
BOOL ReadLine();
BOOL ReadData(bool &bNumber);
BOOL ReadData(double &dNumber);
BOOL ReadData(float &fNumber);
BOOL ReadData(unsigned long &fNumber);
BOOL ReadData(int &iNumber);
BOOL ReadData(unsigned short &iNumber);
BOOL ReadData(short &iNumber);
BOOL ReadData(unsigned char &iNumber);
BOOL ReadData(char &iNumber);
BOOL ReadData(__int64 &i64Number);
BOOL ReadData(DWORD64 &i64Number);
BOOL ReadString(char *szString, DWORD dwSize);
BOOL ReadData(const char *szField, double &dNumber);
BOOL ReadData(const char *szField, float &fNumber);
BOOL ReadData(const char *szField, unsigned long &fNumber);
BOOL ReadData(const char *szField, int &iNumber);
BOOL ReadData(const char *szField, unsigned short &iNumber);
BOOL ReadData(const char *szField, short &iNumber);
BOOL ReadData(const char *szField, unsigned char &iNumber);
BOOL ReadData(const char *szField, char &iNumber);
BOOL ReadData(const char *szField, __int64 &i64Number);
BOOL ReadData(const char *szField, DWORD64 &i64Number);
BOOL ReadString(const char *szField, char *szString, DWORD dwSize);
void Close();
};
#endif

View File

@@ -0,0 +1,220 @@
#ifndef _MATH_CONVERT_INLINE_H_
#define _MATH_CONVERT_INLINE_H_
#include <cstdlib>
#include <tchar.h>
inline void Math::Convert::Hex08ToStr( char *szDest, BYTE hex )
{
*((WORD *) szDest) = m_FastHeToBi[ hex ]; szDest += 2;
*(szDest) = '\0';
}
inline void Math::Convert::Hex16ToStr( char *szDest, WORD hex )
{
LPBYTE pSrc = (LPBYTE) &hex;
#ifdef BIG_ENDIAN
*((WORD *) (szDest + 0)) = m_FastHeToBi[ *(pSrc++) ];
*((WORD *) (szDest + 2)) = m_FastHeToBi[ *(pSrc++) ];
#else
*((WORD *) (szDest + 2)) = m_FastHeToBi[ *(pSrc++) ];
*((WORD *) (szDest + 0)) = m_FastHeToBi[ *(pSrc++) ];
#endif
*(szDest + 4) = '\0';
}
inline void Math::Convert::Hex32ToStr( char *szDest, DWORD hex )
{
LPBYTE pSrc = (LPBYTE) &hex;
#ifdef BIG_ENDIAN
*((WORD *) (szDest + 0)) = m_FastHeToBi[ *(pSrc++) ];
*((WORD *) (szDest + 2)) = m_FastHeToBi[ *(pSrc++) ];
*((WORD *) (szDest + 4)) = m_FastHeToBi[ *(pSrc++) ];
*((WORD *) (szDest + 6)) = m_FastHeToBi[ *(pSrc++) ];
#else
*((WORD *) (szDest + 6)) = m_FastHeToBi[ *(pSrc++) ];
*((WORD *) (szDest + 4)) = m_FastHeToBi[ *(pSrc++) ];
*((WORD *) (szDest + 2)) = m_FastHeToBi[ *(pSrc++) ];
*((WORD *) (szDest + 0)) = m_FastHeToBi[ *(pSrc++) ];
#endif
*(szDest + 8) = '\0';
}
inline void Math::Convert::Hex64ToStr( char *szDest, DWORD64 hex )
{
LPBYTE pSrc = (LPBYTE) &hex;
#ifdef BIG_ENDIAN
*((WORD *) (szDest + 0)) = m_FastHeToBi[ *(pSrc++) ];
*((WORD *) (szDest + 2)) = m_FastHeToBi[ *(pSrc++) ];
*((WORD *) (szDest + 4)) = m_FastHeToBi[ *(pSrc++) ];
*((WORD *) (szDest + 6)) = m_FastHeToBi[ *(pSrc++) ];
*((WORD *) (szDest + 8)) = m_FastHeToBi[ *(pSrc++) ];
*((WORD *) (szDest + 10)) = m_FastHeToBi[ *(pSrc++) ];
*((WORD *) (szDest + 12)) = m_FastHeToBi[ *(pSrc++) ];
*((WORD *) (szDest + 14)) = m_FastHeToBi[ *(pSrc++) ];
#else
*((WORD *) (szDest + 14)) = m_FastHeToBi[ *(pSrc++) ];
*((WORD *) (szDest + 12)) = m_FastHeToBi[ *(pSrc++) ];
*((WORD *) (szDest + 10)) = m_FastHeToBi[ *(pSrc++) ];
*((WORD *) (szDest + 8)) = m_FastHeToBi[ *(pSrc++) ];
*((WORD *) (szDest + 6)) = m_FastHeToBi[ *(pSrc++) ];
*((WORD *) (szDest + 4)) = m_FastHeToBi[ *(pSrc++) ];
*((WORD *) (szDest + 2)) = m_FastHeToBi[ *(pSrc++) ];
*((WORD *) (szDest + 0)) = m_FastHeToBi[ *(pSrc++) ];
#endif
*(szDest + 16) = '\0';
}
//
// this function returns the equivalent binary value for an individual character specified in the ascii format
inline UCHAR Math::Convert::BiToHe(char cBin)
{
if((cBin >= '0') && (cBin <= '9'))
{
return (cBin - '0');
}
else if((cBin >= 'A') && (cBin <= 'F'))
{
return (cBin - 'A' + 0xA);
}
if((cBin >= 'a') && (cBin <= 'f'))
{
return (cBin -'a' + 0xA);
}
return cBin;
}
inline void Math::Convert::AcToHe(char *szDst, char *szSrc, int iCount)
{
while(iCount--)
{
*szDst = BiToHe(*szSrc) << 4;
*szSrc++;
*szDst += BiToHe(*szSrc);
*szSrc++;
*szDst++;
}
}
inline BYTE Math::Convert::StrToHex08(const char *szSrc)
{
const char* pStart = szSrc + 2;
BYTE cHex = 0;
unsigned char c1, c2;
for (int i=0; i<1; ++i)
{
c1 = BiToHe(*pStart++);
c1 <<= (8*(7-i)+4);
c2 = BiToHe(*pStart++);
c2 <<= (8*(7-i));
cHex += (c1 + c2);
}
return cHex;
}
inline WORD Math::Convert::StrToHex16(const char *szSrc)
{
const char* pStart = szSrc + 2;
WORD sHex = 0;
for (int i=0; i<2; i++)
{
WORD s1 = BiToHe(*pStart++);
s1 <<= (8*(1-i)+4);
WORD s2 = BiToHe(*pStart++);
s2 <<= (8*(1-i));
WORD sRet = s1 + s2;
sHex += sRet;
}
return sHex;
}
// convert string to hexadecimal value
inline DWORD Math::Convert::StrToHex32(const char *szSrc)
{
const char* pStart = szSrc + 2;
DWORD nHex = 0;
for (int i=0; i<4; i++)
{
DWORD n1 = BiToHe(*pStart++);
n1 <<= (8*(3-i)+4);
DWORD n2 = BiToHe(*pStart++);
n2 <<= (8*(3-i));
DWORD nRet = n1 + n2;
nHex += nRet;
}
return nHex;
}
// convert string to hexadecimal value
inline DWORD64 Math::Convert::StrToHex64(const char *szSrc)
{
const char* pStart = szSrc + 2;
DWORD64 dlHex = 0;
for (int i=0; i<8; i++)
{
DWORD64 dl1 = BiToHe(*pStart++);
dl1 <<= (8*(7-i)+4);
DWORD64 dl2 = BiToHe(*pStart++);
dl2 <<= (8*(7-i));
DWORD64 dlRet = dl1 + dl2;
dlHex += dlRet;
}
return dlHex;
}
inline BYTE Math::Convert::Atoc(char *szSrc)
{
return (0 == strncmp(szSrc, "0x", 2)) ? StrToHex08(szSrc) : (BYTE) _ttol(szSrc);
}
//
// TCHAR *<2A><> <20><>Ĩ<EFBFBD>ô<EFBFBD>! (By Standil)
//
inline WORD Math::Convert::Atos(char *szSrc)
{
return (0 == strncmp(szSrc, "0x", 2)) ? StrToHex16(szSrc) : _ttoi(szSrc);
}
//
// TCHAR *<2A><> <20><>Ĩ<EFBFBD>ô<EFBFBD>! (By Standil)
//
inline DWORD Math::Convert::Atoi(char *szSrc)
{
return (0 == strncmp(szSrc, "0x", 2)) ? StrToHex32(szSrc) : _ttol(szSrc);
}
//
// TCHAR *<2A><> <20><>Ĩ<EFBFBD>ô<EFBFBD>! (By Standil)
//
inline DWORD64 Math::Convert::Atol64( char *szSrc )
{
return (0 == strncmp(szSrc, "0x", 2)) ? StrToHex64(szSrc) : _ttoi64(szSrc);
}
#endif

View File

@@ -0,0 +1,83 @@
// FastMath.cpp: implementation of the CFastMath class.
//
//////////////////////////////////////////////////////////////////////
#include "stdafx.h"
#include "Math.h"
///////////////////////////////////////////////////////////////////////////////////////////////
// utility functions
// 0 -0x7FFFFFFF.
unsigned long Math::Random::ComplexRandom(int nExtent)
{
if (nExtent < 1)
{
return 1;
}
static unsigned long x = 1;
static unsigned long c = 0;
static unsigned long a = 2083801278UL;
#define addto(rh,rl,ah,al) (rl) = ((rl) + (al)) & 0xFFFFFFFFUL; \
(rh) = ((rh) + (ah) + (((rl) < (al)) ? 1 : 0)) & 0xFFFFFFFFUL
unsigned long xl = (x & 0xFFFFUL);
unsigned long xh = (x >> 16) & 0xFFFFUL;
unsigned long al = (a & 0xFFFFUL);
unsigned long ah = (a >> 16) & 0xFFFFUL;
unsigned long tmp;
x = c;
c = 0;
tmp = xl * al;
addto(c, x, 0, tmp);
tmp = xl * ah;
addto(c, x, (tmp >> 16), (tmp & 0xFFFFUL) << 16);
tmp = xh * ah;
addto(c, x, tmp, 1);
tmp = xh * al;
addto(c, x, (tmp >> 16), (tmp & 0xFFFFUL) << 16);
return (x % nExtent); // return x & 0x7FFFFFFFUL;
}
// This table only works on Little Endian(Byte Order) machine.
const unsigned short Math::Convert::m_FastHeToBi[0x100] =
{
0x3030, 0x3130, 0x3230, 0x3330, 0x3430, 0x3530, 0x3630, 0x3730,
0x3830, 0x3930, 0x4130, 0x4230, 0x4330, 0x4430, 0x4530, 0x4630,
0x3031, 0x3131, 0x3231, 0x3331, 0x3431, 0x3531, 0x3631, 0x3731,
0x3831, 0x3931, 0x4131, 0x4231, 0x4331, 0x4431, 0x4531, 0x4631,
0x3032, 0x3132, 0x3232, 0x3332, 0x3432, 0x3532, 0x3632, 0x3732,
0x3832, 0x3932, 0x4132, 0x4232, 0x4332, 0x4432, 0x4532, 0x4632,
0x3033, 0x3133, 0x3233, 0x3333, 0x3433, 0x3533, 0x3633, 0x3733,
0x3833, 0x3933, 0x4133, 0x4233, 0x4333, 0x4433, 0x4533, 0x4633,
0x3034, 0x3134, 0x3234, 0x3334, 0x3434, 0x3534, 0x3634, 0x3734,
0x3834, 0x3934, 0x4134, 0x4234, 0x4334, 0x4434, 0x4534, 0x4634,
0x3035, 0x3135, 0x3235, 0x3335, 0x3435, 0x3535, 0x3635, 0x3735,
0x3835, 0x3935, 0x4135, 0x4235, 0x4335, 0x4435, 0x4535, 0x4635,
0x3036, 0x3136, 0x3236, 0x3336, 0x3436, 0x3536, 0x3636, 0x3736,
0x3836, 0x3936, 0x4136, 0x4236, 0x4336, 0x4436, 0x4536, 0x4636,
0x3037, 0x3137, 0x3237, 0x3337, 0x3437, 0x3537, 0x3637, 0x3737,
0x3837, 0x3937, 0x4137, 0x4237, 0x4337, 0x4437, 0x4537, 0x4637,
0x3038, 0x3138, 0x3238, 0x3338, 0x3438, 0x3538, 0x3638, 0x3738,
0x3838, 0x3938, 0x4138, 0x4238, 0x4338, 0x4438, 0x4538, 0x4638,
0x3039, 0x3139, 0x3239, 0x3339, 0x3439, 0x3539, 0x3639, 0x3739,
0x3839, 0x3939, 0x4139, 0x4239, 0x4339, 0x4439, 0x4539, 0x4639,
0x3041, 0x3141, 0x3241, 0x3341, 0x3441, 0x3541, 0x3641, 0x3741,
0x3841, 0x3941, 0x4141, 0x4241, 0x4341, 0x4441, 0x4541, 0x4641,
0x3042, 0x3142, 0x3242, 0x3342, 0x3442, 0x3542, 0x3642, 0x3742,
0x3842, 0x3942, 0x4142, 0x4242, 0x4342, 0x4442, 0x4542, 0x4642,
0x3043, 0x3143, 0x3243, 0x3343, 0x3443, 0x3543, 0x3643, 0x3743,
0x3843, 0x3943, 0x4143, 0x4243, 0x4343, 0x4443, 0x4543, 0x4643,
0x3044, 0x3144, 0x3244, 0x3344, 0x3444, 0x3544, 0x3644, 0x3744,
0x3844, 0x3944, 0x4144, 0x4244, 0x4344, 0x4444, 0x4544, 0x4644,
0x3045, 0x3145, 0x3245, 0x3345, 0x3445, 0x3545, 0x3645, 0x3745,
0x3845, 0x3945, 0x4145, 0x4245, 0x4345, 0x4445, 0x4545, 0x4645,
0x3046, 0x3146, 0x3246, 0x3346, 0x3446, 0x3546, 0x3646, 0x3746,
0x3846, 0x3946, 0x4146, 0x4246, 0x4346, 0x4446, 0x4546, 0x4646,
};

View File

@@ -0,0 +1,92 @@
// FastMath.h: interface for the CFastMath class.
//
//////////////////////////////////////////////////////////////////////
#ifndef _CUSTOM_MATH_FUNCTIONS_H_
#define _CUSTOM_MATH_FUNCTIONS_H_
#include <winsock2.h>
#include <windows.h>
#include <cmath>
namespace Math
{
namespace Convert
{
extern const unsigned short m_FastHeToBi[0x100];
// SPX, IPX <20>ּ<EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD>ϴ<EFBFBD> <20>Լ<EFBFBD>
inline unsigned char BiToHe(char cBin);
inline void AcToHe(char *szDst, char *szSrc, int iCount);
// String<6E><67> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20>ٲ<EFBFBD>(String<6E><67> 0x<30><78> <20><><EFBFBD><EFBFBD> Hex string<6E>̴<EFBFBD>.)
inline BYTE StrToHex08(const char *szSrc);
inline WORD StrToHex16(const char *szSrc);
inline DWORD StrToHex32(const char *szSrc);
inline DWORD64 StrToHex64(const char *szSrc);
// String<6E><67> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20>ٲ<EFBFBD>(0x<30><78> <20>ٴ<EFBFBD><D9B4><EFBFBD>, <20><><EFBFBD><EFBFBD> <20>ʴ<EFBFBD><CAB4><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD> <20>ٲ<EFBFBD> <20><> <20>ִ<EFBFBD>)
inline BYTE Atoc(char *szSrc);
inline WORD Atos(char *szSrc);
inline DWORD Atoi(char *szSrc);
inline DWORD64 Atol64(char *szSrc);
// <20><><EFBFBD><EFBFBD> Hex String<6E><67><EFBFBD><EFBFBD> <20>ٲ<EFBFBD>
inline void Hex08ToStr(char *szDest, BYTE hex);
inline void Hex16ToStr(char *szDest, WORD hex);
inline void Hex32ToStr(char *szDest, DWORD hex);
inline void Hex64ToStr(char *szDest, DWORD64 hex);
};
namespace Random
{
// <20><><EFBFBD>ϰ<EFBFBD><CFB0><EFBFBD> 0 ~ nExtent - 1<><31> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD>´<EFBFBD>.
unsigned long ComplexRandom(int nExtent); // <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD>.
};
namespace HashFunc
{
// -------------------------------------------------------------------------------------------------
// String-to-Hash <20>Լ<EFBFBD><D4BC><EFBFBD> : http://www.cs.yorku.ca/~oz/hash.html <20><><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD>
inline unsigned long djb2Hash(const unsigned char *str); // first reported by dan bernstein
inline unsigned long sdbmHash(const unsigned char *str); // this is one of the algorithms used in berkeley db
inline unsigned long looseHash(const unsigned char *str); // <20><><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20>ؽ<EFBFBD>. <20>׳<EFBFBD> <20><><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD>.
};
};
#include "Convert.inl"
inline unsigned long Math::HashFunc::djb2Hash(const unsigned char *str)
{
unsigned long hash = 5381;
int c;
while (c = *str++) { hash = ((hash << 5) + hash) + c; /* hash * 33 + c */ }
return hash;
}
inline unsigned long Math::HashFunc::sdbmHash(const unsigned char *str)
{
unsigned long hash = 0;
int c;
while (c = *str++) { hash = c + (hash << 6) + (hash << 16) - hash; }
return hash;
}
inline unsigned long Math::HashFunc::looseHash(const unsigned char *str)
{
unsigned int hash = 0;
int c;
while (c = *str++) { hash += c; }
return hash;
}
#endif // !defined(AFX_FASTMATH_H__ED69578B_18C1_42EA_9C5E_888DC38101C2__INCLUDED_)

View File

@@ -0,0 +1,225 @@
/******************************************************************************
Module: EnsureCleanup.h
Notices: Copyright (c) 2000 Jeffrey Richter
Purpose: These classes ensure object cleanup when an object goes out of scope.
See Appendix B.
******************************************************************************/
#ifndef _ENSURE_CLEAN_UP_BY_JEFFERY_RICHTER
#define _ENSURE_CLEAN_UP_BY_JEFFERY_RICHTER
#pragma once // Include this header file once per compilation unit
#include <winsock2.h>
#include <windows.h>
// Data type representing the address of the object's cleanup function.
// I used UINT_PTR so that this class works properly in 64-bit Windows.
typedef VOID (WINAPI* PFNENSURECLEANUP)(UINT_PTR);
// Each template instantiation requires a data type, address of cleanup
// function, and a value that indicates an invalid value.
template<class TYPE, PFNENSURECLEANUP pfn, UINT_PTR tInvalid = NULL>
class CEnsureCleanup
{
public:
// Default constructor assumes an invalid value (nothing to cleanup)
CEnsureCleanup() { m_t = tInvalid; }
// This constructor sets the value to the specified value
CEnsureCleanup(TYPE t) : m_t((UINT_PTR) t) { }
// The destructor performs the cleanup.
~CEnsureCleanup() { Cleanup(); }
// Helper methods to tell if the value represents a valid object or not..
BOOL IsValid() { return(m_t != tInvalid); }
BOOL IsInvalid() { return(!IsValid()); }
// Re-assigning the object forces the current object to be cleaned-up.
TYPE operator=(TYPE t)
{
Cleanup();
m_t = (UINT_PTR) t;
return(*this);
}
// Returns the value (supports both 32-bit and 64-bit Windows).
operator TYPE()
{
// If TYPE is a 32-bit value, cast m_t to 32-bit TYPE
// If TYPE is a 64-bit value, case m_t to 64-bit TYPE
return((sizeof(TYPE) == 4) ? (TYPE) PtrToUint(m_t) : (TYPE) m_t);
}
// Cleanup the object if the value represents a valid object
void Cleanup()
{
if (IsValid())
{
// In 64-bit Windows, all parameters are 64-bits,
// so no casting is required
pfn(m_t); // Close the object.
m_t = tInvalid; // We no longer represent a valid object.
}
}
private:
UINT_PTR m_t; // The member representing the object
};
///////////////////////////////////////////////////////////////////////////////
// Macros to make it easier to declare instances of the template
// class for specific data types.
#define MakeCleanupClass(className, tData, pfnCleanup) \
typedef CEnsureCleanup<tData, (PFNENSURECLEANUP) pfnCleanup> className;
#define MakeCleanupClassX(className, tData, pfnCleanup, tInvalid) \
typedef CEnsureCleanup<tData, (PFNENSURECLEANUP) pfnCleanup, \
(INT_PTR) tInvalid> className;
///////////////////////////////////////////////////////////////////////////////
// Instances of the template C++ class for common data types.
MakeCleanupClass(CEnsureCloseHandle, HANDLE, CloseHandle);
MakeCleanupClassX(CEnsureCloseFile, HANDLE, CloseHandle, INVALID_HANDLE_VALUE);
MakeCleanupClass(CEnsureLocalFree, HLOCAL, LocalFree);
MakeCleanupClass(CEnsureGlobalFree, HGLOBAL, GlobalFree);
MakeCleanupClass(CEnsureRegCloseKey, HKEY, RegCloseKey);
MakeCleanupClass(CEnsureCloseServiceHandle, SC_HANDLE, CloseServiceHandle);
MakeCleanupClass(CEnsureCloseWindowStation, HWINSTA, CloseWindowStation);
MakeCleanupClass(CEnsureCloseDesktop, HDESK, CloseDesktop);
MakeCleanupClass(CEnsureUnmapViewOfFile, PVOID, UnmapViewOfFile);
MakeCleanupClass(CEnsureFreeLibrary, HMODULE, FreeLibrary);
///////////////////////////////////////////////////////////////////////////////
// Special class for releasing a reserved region.
// Special class is required because VirtualFree requires 3 parameters
class CEnsureReleaseRegion
{
public:
CEnsureReleaseRegion(PVOID pv = NULL) : m_pv(pv) { }
~CEnsureReleaseRegion() { Cleanup(); }
PVOID operator=(PVOID pv)
{
Cleanup();
m_pv = pv;
return(m_pv);
}
operator PVOID() { return(m_pv); }
void Cleanup()
{
if (m_pv != NULL)
{
VirtualFree(m_pv, 0, MEM_RELEASE);
m_pv = NULL;
}
}
private:
PVOID m_pv;
};
///////////////////////////////////////////////////////////////////////////////
// Special class for freeing a block from a heap
// Special class is required because HeapFree requires 3 parameters
class CEnsureHeapFree
{
public:
CEnsureHeapFree(PVOID pv = NULL, HANDLE hHeap = GetProcessHeap())
: m_pv(pv), m_hHeap(hHeap) { }
~CEnsureHeapFree() { Cleanup(); }
PVOID operator=(PVOID pv)
{
Cleanup();
m_pv = pv;
return(m_pv);
}
operator PVOID() { return(m_pv); }
void Cleanup()
{
if (m_pv != NULL)
{
HeapFree(m_hHeap, 0, m_pv);
m_pv = NULL;
}
}
private:
HANDLE m_hHeap;
PVOID m_pv;
};
template<typename T>
class CEnsureDelete
{
public:
CEnsureDelete(T* ptr) : m_ptr(ptr) { }
~CEnsureDelete() { if(NULL != m_ptr) { delete m_ptr; } }
private:
// <20><><EFBFBD><20><> <20><> <20><><EFBFBD><EFBFBD> <20><>.
CEnsureDelete& operator =(const CEnsureDelete& ensureDelete);
CEnsureDelete(const CEnsureDelete& ensureDelete);
T* m_ptr;
};
template<typename T>
class CEnsureDeleteArray
{
public:
CEnsureDeleteArray(T* ptrArray) : m_ptrArray(ptrArray) { }
~CEnsureDeleteArray() { if(NULL != m_ptrArray) { delete [] m_ptrArray; } }
private:
// <20><><EFBFBD><20><> <20><> <20><><EFBFBD><EFBFBD> <20><>.
CEnsureDeleteArray& operator =(const CEnsureDeleteArray& ensureDeleteArray);
CEnsureDeleteArray(const CEnsureDeleteArray& ensureDeleteArray);
T* m_ptrArray;
};
template<typename T>
class CEnsureRelease
{
public:
CEnsureRelease(T& t) : m_t(&t) { }
CEnsureRelease(T* t) : m_t(t) { }
~CEnsureRelease() { if(NULL != m_t) { m_t->Release(); } }
private:
// <20><><EFBFBD><20><> <20><> <20><><EFBFBD><EFBFBD> <20><>.
CEnsureRelease& operator =(const CEnsureRelease& ensureRelease);
CEnsureRelease(const CEnsureRelease& ensureRelease);
T* m_t;
};
#endif

View File

@@ -0,0 +1,139 @@
#include "stdafx.h"
#include "TokenlizedFile.h"
#include <Utility/Math/Math.h>
inline std::string& Trim(std::string& str)
{
const size_t nBeginPos = str.find_first_not_of(" \t\r\n");
if (nBeginPos != std::string::npos) { str.erase(str.begin(), str.begin() + nBeginPos); }
const size_t nEndPos = str.find_last_not_of(" \t\r\n");
if (nEndPos != std::string::npos && nEndPos != str.size()) { str.erase(str.begin() + nEndPos + 1, str.end()); }
return str;
}
CTokenlizedFile::ColumnInfo::ColumnInfo(const char* szColumnName)
: m_dwHashKey(Math::HashFunc::sdbmHash(reinterpret_cast<const unsigned char*>(szColumnName))),
m_szColumnName(szColumnName)
{
}
CTokenlizedFile::ColumnInfo::ColumnInfo(std::string& szColumnName)
: m_dwHashKey(Math::HashFunc::sdbmHash(reinterpret_cast<const unsigned char*>(szColumnName.c_str()))),
m_szColumnName(szColumnName)
{
}
CTokenlizedFile::CTokenlizedFile(const char* lpszDelimiter)
: m_lpFile(NULL), m_nLine(0)
{
strncpy(m_szDelimiter, lpszDelimiter, MAX_DELIMITER_NUM - 1);
m_szDelimiter[MAX_DELIMITER_NUM - 1] = '\0';
m_ColumnInfo.reserve(DEFAULT_COLUMN_NUM);
m_ColumnValues.reserve(DEFAULT_COLUMN_NUM);
}
CTokenlizedFile::~CTokenlizedFile()
{
}
void CTokenlizedFile::Close()
{
if(NULL != m_lpFile)
{
fclose(m_lpFile);
}
m_ColumnInfo.clear();
m_ColumnValues.clear();
}
bool CTokenlizedFile::Open(const char* szFilename, const char* szOpenMode)
{
Close();
m_nLine = 0;
m_lpFile = fopen(szFilename, szOpenMode);
return (NULL != m_lpFile) ? true : false;
}
bool CTokenlizedFile::ReadColumn()
{
char szBuffer[MAX_LINE_BUFFER];
m_ColumnInfo.clear();
if(NULL != fgets(szBuffer, MAX_LINE_BUFFER, m_lpFile))
{
char* szToken = strtok(szBuffer, m_szDelimiter);
do
{
m_ColumnInfo.push_back(ColumnInfo(Trim(std::string(szToken))));
} while(NULL != (szToken = strtok(NULL, m_szDelimiter)));
++m_nLine;
return true;
}
return false;
}
bool CTokenlizedFile::ReadLine()
{
char szBuffer[MAX_LINE_BUFFER];
m_ColumnValues.clear();
if(NULL != fgets(szBuffer, MAX_LINE_BUFFER, m_lpFile))
{
char* szToken = strtok(szBuffer, m_szDelimiter);
do
{
m_ColumnValues.push_back(Trim(std::string(szToken)));
} while(NULL != (szToken = strtok(NULL, m_szDelimiter)));
++m_nLine;
return true;
}
return false;
}
const char* CTokenlizedFile::GetStringValue(const char* szColumnName)
{
DWORD dwHashkey = Math::HashFunc::sdbmHash(reinterpret_cast<const unsigned char*>(szColumnName));
for(ColumnArray::iterator itr = m_ColumnInfo.begin();
itr != m_ColumnInfo.end(); ++itr)
{
const ColumnInfo& columnInfo = *itr;
if(dwHashkey == columnInfo.m_dwHashKey)
{
if(0 == strcmp(szColumnName, columnInfo.m_szColumnName.c_str()))
{
size_t nDistance = itr - m_ColumnInfo.begin();
return GetStringValue(nDistance);
}
}
}
return NULL;
}

View File

@@ -0,0 +1,74 @@
#ifndef _DELIMITED_FILE_H_
#define _DELIMITED_FILE_H_
#include <cstdio>
#include <string>
#include <vector>
class CTokenlizedFile
{
public:
CTokenlizedFile(const char* lpszDelimiter = "\t");
~CTokenlizedFile();
enum
{
MAX_DELIMITER_NUM = 16,
MAX_LINE_BUFFER = 16384,
DEFAULT_COLUMN_NUM = 64
};
bool Open(const char* szFilename, const char* szOpenMode = "rt");
void Close();
bool ReadColumn(); // <20>÷<EFBFBD> <20≯<EFBFBD><CCB8><EFBFBD> <20>д´<D0B4>.
bool ReadLine(); // <20><> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20>д´<D0B4>.
bool IsEOF() { return (NULL != m_lpFile) ? (0 != feof(m_lpFile)) : false; }
size_t GetColumnNum() { return m_ColumnInfo.size(); }
size_t GetCurrentLine() { return m_nLine; }
size_t GetValueNum() { return m_ColumnValues.size(); }
const char* GetColumnName(size_t nIndex);
const char* GetStringValue(size_t nIndex);
const char* GetStringValue(const char* szColumnName);
private:
struct ColumnInfo
{
unsigned long m_dwHashKey;
std::string m_szColumnName;
ColumnInfo() : m_dwHashKey(0) { m_szColumnName.assign(""); }
ColumnInfo(const char* szColumnName);
ColumnInfo(std::string& szColumnName);
};
FILE* m_lpFile;
size_t m_nLine;
char m_szDelimiter[MAX_DELIMITER_NUM];
typedef std::vector<ColumnInfo> ColumnArray;
typedef std::vector<std::string> ValueArray;
ColumnArray m_ColumnInfo;
ValueArray m_ColumnValues;
};
inline const char* CTokenlizedFile::GetColumnName(size_t nIndex)
{
return (nIndex < m_ColumnInfo.size()) ?
m_ColumnInfo[nIndex].m_szColumnName.c_str() : NULL;
}
inline const char* CTokenlizedFile::GetStringValue(size_t nIndex)
{
return (nIndex < m_ColumnValues.size()) ?
m_ColumnValues[nIndex].c_str() : NULL;
}
#endif

View File

@@ -0,0 +1,18 @@
#include "stdafx.h"
#include "TypeArray.h"
#include <Log/ServerLog.h>
bool CTypeName::Test(const CTypeName* lpTypeArray, int nArrayNum, const char* lpTypeArrayName)
{
for(int nCount = 0; nCount < nArrayNum; ++nCount)
{
if(lpTypeArray[nCount].m_nType != nCount)
{
ERRLOG2(g_Log, "<EFBFBD>˻<EFBFBD><EFBFBD><EFBFBD> Ÿ<>Ե<EFBFBD><D4B5><EFBFBD> <20><20>ε<EFBFBD><CEB5><EFBFBD><EFBFBD><EFBFBD> Ÿ<><C5B8> <20><><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD> <20>ʽ<EFBFBD><CABD>ϴ<EFBFBD>."
"Ÿ<EFBFBD><EFBFBD> <20><><EFBFBD>̺<EFBFBD> <20≯<EFBFBD><CCB8><EFBFBD> %s<>̰<EFBFBD>, <20><><EFBFBD><EFBFBD> <20>ʴ<EFBFBD> Ŀ<>ǵ<EFBFBD> <20><>ȣ<EFBFBD><C8A3> %d<>Դϴ<D4B4>.", lpTypeArrayName, nCount);
return false;
}
}
return true;
}

View File

@@ -0,0 +1,22 @@
#ifndef _TYPE_ARRAY_H_
#define _TYPE_ARRAY_H_
class CTypeName
{
public:
CTypeName() : m_nType(0), m_lpszName(0) { }
CTypeName(unsigned char nType, char* lpszName) : m_nType(nType), m_lpszName(lpszName) { }
unsigned char GetTypeValue() const { return m_nType; }
const char* GetTypeName() const { return m_lpszName; }
static bool Test(const CTypeName* lpTypeArray, int nArrayNum, const char* lpTypeArrayName);
private:
unsigned char m_nType;
char* m_lpszName;
};
#endif