Add project files.

This commit is contained in:
2022-03-05 12:44:06 +02:00
parent 453a74459f
commit f4f90b2533
517 changed files with 195610 additions and 0 deletions

View File

@ -0,0 +1,57 @@
/*
* Filename: buffer.h
* Description: Buffer ó<><C3B3> <20><><EFBFBD><EFBFBD>
*
* Author: <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> (aka. <20><><EFBFBD><EFBFBD>, Cronan), <20>ۿ<EFBFBD><DBBF><EFBFBD> (aka. myevan, <20><><EFBFBD>ڷ<EFBFBD>)
*/
#ifndef __INC_LIBTHECORE_BUFFER_H__
#define __INC_LIBTHECORE_BUFFER_H__
#define SAFE_BUFFER_DELETE(buf) { if(buf != NULL) { buffer_delete(buf); buf = NULL; } }
typedef struct buffer BUFFER;
typedef struct buffer * LPBUFFER;
struct buffer
{
struct buffer * next;
char * write_point;
int write_point_pos;
const char * read_point;
int length;
char * mem_data;
int mem_size;
long flag;
};
extern LPBUFFER buffer_new(int size); // <20><> <20><><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD>
extern void buffer_delete(LPBUFFER buffer); // <20><><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD>
extern void buffer_reset(LPBUFFER buffer); // <20><><EFBFBD><EFBFBD> <20><><EFBFBD>̵<EFBFBD><CCB5><EFBFBD> <20>ʱ<EFBFBD>ȭ
extern DWORD buffer_size(LPBUFFER buffer); // <20><><EFBFBD>ۿ<EFBFBD> <20><><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD>
extern int buffer_has_space(LPBUFFER buffer); // <20><> <20><> <20>ִ<EFBFBD> <20><><EFBFBD≯<EFBFBD> <20><><EFBFBD><EFBFBD>
extern void buffer_write (LPBUFFER& buffer, const void* src, int length); // <20><><EFBFBD>ۿ<EFBFBD> <20><><EFBFBD><EFBFBD>.
extern void buffer_read(LPBUFFER buffer, void * buf, int bytes); // <20><><EFBFBD>ۿ<EFBFBD><DBBF><EFBFBD> <20>д´<D0B4>.
extern BYTE buffer_get_byte(LPBUFFER buffer);
extern WORD buffer_get_word(LPBUFFER buffer);
extern DWORD buffer_get_dword(LPBUFFER buffer);
// buffer_proceed <20>Լ<EFBFBD><D4BC><EFBFBD> buffer_peek<65><6B><EFBFBD><EFBFBD> <20>б<EFBFBD><D0B1><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD>͸<EFBFBD> <20><><EFBFBD><EFBFBD> <20>޾Ƽ<DEBE> <20><> <20>ʿ䰡
// <20><><EFBFBD><EFBFBD> <20><> ó<><C3B3><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20>󸶳<EFBFBD> ó<><C3B3><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD>ٰ<EFBFBD> <20><EFBFBD>ؾ<EFBFBD> <20><> <20><> <20><><EFBFBD><EFBFBD>.
// (buffer_read, buffer_get_* <20>ø<EFBFBD><C3B8><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><ECBFA1> <20>˾Ƽ<CBBE> ó<><C3B3><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> peek<65><6B><EFBFBD><EFBFBD> ó<><C3B3><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
// <20><><EFBFBD><EFBFBD> <20>׷<EFBFBD><D7B7><EFBFBD> <20><> <20><><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD>Ƿ<EFBFBD>)
extern const void * buffer_read_peek(LPBUFFER buffer); // <20>д<EFBFBD> <20><>ġ<EFBFBD><C4A1> <20><><EFBFBD><EFBFBD>
extern void buffer_read_proceed(LPBUFFER buffer, int length); // length<74><68>ŭ<EFBFBD><C5AD> ó<><C3B3><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD>
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> write_peek<65><6B><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD> <20><>ġ<EFBFBD><C4A1> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD> <20>󸶳<EFBFBD> <20><20><EFBFBD><EBBAB8> <20><>
// buffer_write_proceed<65><64> <20><><EFBFBD><EFBFBD><EFBFBD>Ѵ<EFBFBD>.
extern void * buffer_write_peek(LPBUFFER buffer); // <20><><EFBFBD><EFBFBD> <20><>ġ<EFBFBD><C4A1> <20><><EFBFBD><EFBFBD>
extern void buffer_write_proceed(LPBUFFER buffer, int length); // length<74><68> <20><><EFBFBD><EFBFBD> <20><>Ų<EFBFBD><C5B2>.
extern void buffer_adjust_size(LPBUFFER & buffer, int add_size); // add_size<7A><65>ŭ <20>߰<EFBFBD><DFB0><EFBFBD> ũ<>⸦ Ȯ<><C8AE>
#endif

View File

@ -0,0 +1,23 @@
#ifdef __cplusplus
extern "C" {
#endif
/* TEA is a 64-bit symmetric block cipher with a 128-bit key, developed
by David J. Wheeler and Roger M. Needham, and described in their
paper at <URL:http://www.cl.cam.ac.uk/ftp/users/djw3/tea.ps>.
This implementation is based on their code in
<URL:http://www.cl.cam.ac.uk/ftp/users/djw3/xtea.ps> */
extern int TEA_Encrypt(DWORD *dest, const DWORD *src, const DWORD *key, int size);
extern int TEA_Decrypt(DWORD *dest, const DWORD *src, const DWORD *key, int size);
extern int GOST_Encrypt(DWORD * DstBuffer, const DWORD * SrcBuffer, const DWORD * KeyAddress, DWORD Length, DWORD *IVector);
extern int GOST_Decrypt(DWORD * DstBuffer, const DWORD * SrcBuffer, const DWORD * KeyAddress, DWORD Length, DWORD *IVector);
extern int DES_Encrypt(DWORD *DstBuffer, const DWORD * SrcBuffer, const DWORD *KeyAddress, DWORD Length, DWORD *IVector);
extern int DES_Decrypt(DWORD *DstBuffer, const DWORD * SrcBuffer, const DWORD *KeyAddress, DWORD Length, DWORD *IVector);
#ifdef __cplusplus
};
#endif

View File

@ -0,0 +1,95 @@
#ifndef __INC_LIBTHECORE_FDWATCH_H__
#define __INC_LIBTHECORE_FDWATCH_H__
#ifndef __WIN32__
typedef struct fdwatch FDWATCH;
typedef struct fdwatch * LPFDWATCH;
enum EFdwatch
{
FDW_NONE = 0,
FDW_READ = 1,
FDW_WRITE = 2,
FDW_WRITE_ONESHOT = 4,
FDW_EOF = 8,
};
typedef struct kevent KEVENT;
typedef struct kevent * LPKEVENT;
typedef int KQUEUE;
struct fdwatch
{
KQUEUE kq;
int nfiles;
LPKEVENT kqevents;
int nkqevents;
LPKEVENT kqrevents;
int * fd_event_idx;
void ** fd_data;
int * fd_rw;
};
#else
typedef struct fdwatch FDWATCH;
typedef struct fdwatch * LPFDWATCH;
enum EFdwatch
{
FDW_NONE = 0,
FDW_READ = 1,
FDW_WRITE = 2,
FDW_WRITE_ONESHOT = 4,
FDW_EOF = 8,
};
struct fdwatch
{
fd_set rfd_set;
fd_set wfd_set;
socket_t* select_fds;
int* select_rfdidx;
int nselect_fds;
fd_set working_rfd_set;
fd_set working_wfd_set;
int nfiles;
void** fd_data;
int* fd_rw;
};
#endif // WIN32
#ifdef __cplusplus
extern "C"
{
#endif /* __cplusplus */
extern LPFDWATCH fdwatch_new(int nfiles);
extern void fdwatch_clear_fd(LPFDWATCH fdw, socket_t fd);
extern void fdwatch_delete(LPFDWATCH fdw);
extern int fdwatch_check_fd(LPFDWATCH fdw, socket_t fd);
extern int fdwatch_check_event(LPFDWATCH fdw, socket_t fd, unsigned int event_idx);
extern void fdwatch_clear_event(LPFDWATCH fdw, socket_t fd, unsigned int event_idx);
extern void fdwatch_add_fd(LPFDWATCH fdw, socket_t fd, void* client_data, int rw, int oneshot);
extern int fdwatch(LPFDWATCH fdw, struct timeval *timeout);
extern void * fdwatch_get_client_data(LPFDWATCH fdw, unsigned int event_idx);
extern void fdwatch_del_fd(LPFDWATCH fdw, socket_t fd);
extern int fdwatch_get_buffer_size(LPFDWATCH fdw, socket_t fd);
extern int fdwatch_get_ident(LPFDWATCH fdw, unsigned int event_idx);
#ifdef __cplusplus
}
#endif
#endif

View File

@ -0,0 +1,31 @@
#ifndef __INC_LIBTHECORE_HANGUL_H__
#define __INC_LIBTHECORE_HANGUL_H__
#ifdef __cplusplus
extern "C"
{
#endif /* __cplusplus */
#ifdef __WIN32__
#define isdigit iswdigit
#define isspace iswspace
#endif
#define ishan(ch) (((ch) & 0xE0) > 0x90)
#define ishanasc(ch) (isascii(ch) || ishan(ch))
#define ishanalp(ch) (isalpha(ch) || ishan(ch))
#define isnhdigit(ch) (!ishan(ch) && isdigit(ch))
#define isnhspace(ch) (!ishan(ch) && isspace(ch))
extern const char * first_han(const BYTE * str); // ù<><C3B9>° <20><> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD>(<28><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>)<29><> <20>̾<EFBFBD> <20><>/<2F><>/<2F><>/..<2E><> <20><><EFBFBD><EFBFBD><EFBFBD>Ѵ<EFBFBD>.
extern int check_han(const char * str); // <20>ѱ<EFBFBD><D1B1≯<EFBFBD> true <20><>Ʈ<EFBFBD><C6AE> <20><><EFBFBD><EFBFBD> üũ
extern int is_hangul(const BYTE * str); // <20>ѱ<EFBFBD><D1B1≯<EFBFBD> true (2<><32><EFBFBD><EFBFBD>Ʈ<EFBFBD><C6AE> üũ)
extern int under_han(const void * orig); // <20><>ħ<EFBFBD><C4A7> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> true
#define UNDER(str) under_han(str)
#ifdef __cplusplus
};
#endif
#endif

View File

@ -0,0 +1,26 @@
#ifndef __INC_LIBTHECORE_HEART_H__
#define __INC_LIBTHECORE_HEART_H__
typedef struct heart HEART;
typedef struct heart * LPHEART;
typedef void (*HEARTFUNC) (LPHEART heart, int pulse);
struct heart
{
HEARTFUNC func;
struct timeval before_sleep;
struct timeval opt_time;
struct timeval last_time;
int passes_per_sec;
int pulse;
};
extern LPHEART heart_new(int opt_usec, HEARTFUNC func);
extern void heart_delete(LPHEART ht);
extern int heart_idle(LPHEART ht); // <20><> pulse<73><65> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD>Ѵ<EFBFBD>.
extern void heart_beat(LPHEART ht, int pulses);
#endif

View File

@ -0,0 +1,10 @@
/*
* Filename: kstbl.h
* Description: KS <20>ϼ<EFBFBD><CFBC><EFBFBD> 2350<35><30><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20>ڵ<EFBFBD>
*
* Author: <20><><EFBFBD><EFBFBD> (server), myevan (Client)
*/
#ifndef __KSTBL_H__
#define __KSTBL_H__
extern unsigned KStbl[2350];
#endif

39
libthecore/include/log.h Normal file
View File

@ -0,0 +1,39 @@
#ifndef __INC_LIBTHECORE_LOG_H__
#define __INC_LIBTHECORE_LOG_H__
#ifdef __cplusplus
extern "C"
{
#endif /* __cplusplus */
extern int log_init(void);
extern void log_destroy(void);
extern void log_rotate(void);
// <20>α<EFBFBD> <20><><EFBFBD><EFBFBD> ó<><C3B3> (<28><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> bitvector<6F><72> ó<><C3B3><EFBFBD>ȴ<EFBFBD>)
extern void log_set_level(unsigned int level);
extern void log_unset_level(unsigned int level);
// <20>α<EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD>ŭ <20><><EFBFBD><EFBFBD><EFBFBD>ϴ°<CFB4><C2B0><EFBFBD> <20><><EFBFBD><EFBFBD> <20>Լ<EFBFBD>
extern void log_set_expiration_days(unsigned int days);
extern int log_get_expiration_days(void);
#ifndef __WIN32__
extern void _sys_err(const char *func, int line, const char *format, ...);
#else
extern void _sys_err(const char *func, int line, const char *format, ...);
#endif
extern void sys_log_header(const char *header);
extern void sys_log(unsigned int lv, const char *format, ...);
extern void pt_log(const char *format, ...);
#ifndef __WIN32__
#define sys_err(fmt, args...) _sys_err(__FUNCTION__, __LINE__, fmt, ##args)
#else
#define sys_err(fmt, ...) _sys_err(__FUNCTION__, __LINE__, fmt, __VA_ARGS__)
#endif // __WIN32__
#ifdef __cplusplus
}
#endif // __cplusplus
#endif // __INC_LOG_H__

40
libthecore/include/main.h Normal file
View File

@ -0,0 +1,40 @@
#ifndef __INC_LIBTHECORE_MAIN_H__
#define __INC_LIBTHECORE_MAIN_H__
#ifdef __cplusplus
extern "C"
{
#endif /* __cplusplus */
#ifdef __LIBTHECORE__
extern volatile int tics;
extern volatile int shutdowned;
#endif
#include "heart.h"
extern LPHEART thecore_heart;
enum ENUM_PROFILER
{
PF_IDLE,
PF_HEARTBEAT,
NUM_PF
};
extern unsigned int thecore_profiler[NUM_PF];
extern int thecore_init(int fps, HEARTFUNC heartbeat_func);
extern int thecore_idle(void);
extern void thecore_shutdown(void);
extern void thecore_destroy(void);
extern int thecore_pulse(void);
extern float thecore_time(void);
extern float thecore_pulse_per_second(void);
extern int thecore_is_shutdowned(void);
extern void thecore_tick(void); // tics <20><><EFBFBD><EFBFBD>
#ifdef __cplusplus
}
#endif
#endif

View File

@ -0,0 +1,23 @@
#ifndef __INC_LIBTHECORE_MEMCPY_H__
#define __INC_LIBTHECORE_MEMCPY_H__
#ifdef __cplusplus
extern "C"
{
#endif
#ifdef __LIBTHECORE__
void thecore_find_best_memcpy();
#endif
#ifndef __WIN32__
extern void *(*thecore_memcpy) (void * to, const void * from, size_t len);
#else
#include <cstring>
#define thecore_memcpy memcpy
#endif
#ifdef __cplusplus
};
#endif
#endif

View File

@ -0,0 +1,16 @@
#ifndef __INC_LIBTHECORE_SIGNAL_H__
#define __INC_LIBTHECORE_SIGNAL_H__
#ifdef __cplusplus
extern "C"
{
#endif
extern void signal_setup();
extern void signal_timer_disable();
extern void signal_timer_enable(int timeout_seconds);
#ifdef __cplusplus
};
#endif
#endif

View File

@ -0,0 +1,45 @@
/*
* Filename: socket.c
* Description: <20><><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD> <20>Լ<EFBFBD> <20><><EFBFBD><EFBFBD>.
*
* Author: <20><><EFBFBD><EFBFBD> (server), myevan (Client)
*/
#ifndef __INC_LIBTHECORE_SOCKET_H__
#define __INC_LIBTHECORE_SOCKET_H__
#ifdef __cplusplus
extern "C"
{
#endif /* __cplusplus */
#ifdef __WIN32__
typedef int socklen_t;
#else
#define INVALID_SOCKET -1
#endif
extern int socket_read(socket_t desc, char* read_point, size_t space_left);
extern int socket_write(socket_t desc, const char *data, size_t length);
extern int socket_udp_read(socket_t desc, char * read_point, size_t space_left, struct sockaddr * from, socklen_t * fromlen);
extern int socket_tcp_bind(const char * ip, int port);
extern int socket_udp_bind(const char * ip, int port);
extern socket_t socket_accept(socket_t s, struct sockaddr_in *peer);
extern void socket_close(socket_t s);
extern socket_t socket_connect(const char* host, WORD port);
extern void socket_nonblock(socket_t s);
extern void socket_block(socket_t s);
extern void socket_dontroute(socket_t s);
extern void socket_lingeroff(socket_t s);
extern void socket_lingeron(socket_t s);
extern void socket_sndbuf(socket_t s, unsigned int opt);
extern void socket_rcvbuf(socket_t s, unsigned int opt);
#ifdef __cplusplus
};
#endif
#endif

145
libthecore/include/stdafx.h Normal file
View File

@ -0,0 +1,145 @@
#ifndef __INC_LIBTHECORE_STDAFX_H__
#define __INC_LIBTHECORE_STDAFX_H__
#if defined(__GNUC__)
#define INLINE __inline__
#elif defined(_MSC_VER)
#define INLINE inline
#endif
#ifdef __WIN32__
#define WIN32_LEAN_AND_MEAN
#include <windows.h>
#include <winsock2.h>
#include <tchar.h>
#include <errno.h>
#include <time.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <stdio.h>
#include <stdlib.h>
#include <assert.h>
#include <conio.h>
#include <process.h>
#include <limits.h>
#include <math.h>
#include <locale.h>
#include <io.h>
#include <direct.h>
#include <fcntl.h>
#include "xdirent.h"
#include "xgetopt.h"
#define S_ISDIR(m) (m & _S_IFDIR)
#define snprintf _snprintf
struct timespec
{
time_t tv_sec; /* seconds */
long tv_nsec; /* and nanoseconds */
};
#define __USE_SELECT__
#define PATH_MAX _MAX_PATH
// C runtime library adjustments
#define strlcat(dst, src, size) strcat_s(dst, size, src)
#define strlcpy(dst, src, size) strncpy_s(dst, size, src, _TRUNCATE)
#define strtoull(str, endptr, base) _strtoui64(str, endptr, base)
#define strtof(str, endptr) (float)strtod(str, endptr)
#define strcasecmp(s1, s2) stricmp(s1, s2)
#define strncasecmp(s1, s2, n) strnicmp(s1, s2, n)
#define atoll(str) _atoi64(str)
#define localtime_r(timet, result) localtime_s(result, timet)
#define strtok_r(s, delim, ptrptr) strtok_s(s, delim, ptrptr)
#include <boost/typeof/typeof.hpp>
#define typeof(t) BOOST_TYPEOF(t)
// dummy declaration of non-supported signals
#define SIGUSR1 30 /* user defined signal 1 */
#define SIGUSR2 31 /* user defined signal 2 */
inline void usleep(unsigned long usec) {
::Sleep(usec / 1000);
}
inline unsigned sleep(unsigned sec) {
::Sleep(sec * 1000);
return 0;
}
inline double rint(double x)
{
return ::floor(x+.5);
}
#else
#ifndef __FreeBSD__
#define __USE_SELECT__
#ifdef __CYGWIN__
#define _POSIX_SOURCE 1
#endif
#endif
#include <stdio.h>
#include <string.h>
#include <stdarg.h>
#include <errno.h>
#include <stdlib.h>
#include <unistd.h>
#include <fcntl.h>
#include <assert.h>
#include <ctype.h>
#include <limits.h>
#include <dirent.h>
#include <sys/time.h>
#include <sys/stat.h>
#include <sys/types.h>
#include <netinet/in.h>
#include <arpa/inet.h>
#include <netdb.h>
#include <sys/socket.h>
#include <sys/signal.h>
#include <sys/wait.h>
#include <pthread.h>
#include <semaphore.h>
#ifdef __FreeBSD__
#include <sys/event.h>
#endif
#endif
#ifndef false
#define false 0
#define true (!false)
#endif
#ifndef FALSE
#define FALSE false
#define TRUE (!FALSE)
#endif
#include "typedef.h"
#include "heart.h"
#include "fdwatch.h"
#include "socket.h"
#include "kstbl.h"
#include "hangul.h"
#include "buffer.h"
#include "signal.h"
#include "log.h"
#include "main.h"
#include "utils.h"
#include "crypt.h"
#include "memcpy.h"
#endif // __INC_LIBTHECORE_STDAFX_H__

View File

@ -0,0 +1,62 @@
#ifndef __INC_LIBTHECORE_TYPEDEF_H__
#define __INC_LIBTHECORE_TYPEDEF_H__
typedef unsigned long int QWORD;
typedef unsigned char UBYTE;
typedef signed char sbyte;
typedef unsigned short sh_int;
#ifndef __WIN32__
#ifndef __cplusplus
typedef unsigned char bool;
#endif
typedef unsigned int DWORD;
typedef int BOOL;
typedef unsigned char BYTE;
typedef unsigned short WORD;
typedef long LONG;
typedef unsigned long ULONG;
typedef int INT;
typedef unsigned int UINT;
typedef int socket_t;
#else
struct timezone
{
int tz_minuteswest; /* minutes west of Greenwich */
int tz_dsttime; /* type of dst correction */
};
typedef SOCKET socket_t;
#if !defined(_W64)
#if !defined(__midl) && (defined(_X86_) || defined(_M_IX86)) && _MSC_VER >= 1300
#define _W64 __w64
#else
#define _W64
#endif
#endif
#ifdef _WIN64
typedef __int64 ssize_t;
#else
typedef _W64 int ssize_t;
#endif
// Fixed-size integer types
#if defined(_MSC_VER) && (_MSC_VER >= 1300)
typedef __int32 int32_t;
typedef unsigned __int32 uint32_t;
typedef __int64 int64_t;
typedef unsigned __int64 uint64_t;
#endif
typedef unsigned int uint;
#endif
#endif // __INC_LIBTHECORE_TYPEDEF_H__

152
libthecore/include/utils.h Normal file
View File

@ -0,0 +1,152 @@
#ifndef __INC_LIBTHECORE_UTILS_H__
#define __INC_LIBTHECORE_UTILS_H__
#ifdef __cplusplus
extern "C"
{
#endif /* __cplusplus */
#define SAFE_FREE(p) { if (p) { free( (void *) p); (p) = NULL; } }
#define SAFE_DELETE(p) { if (p) { delete (p); (p) = NULL; } }
#define SAFE_DELETE_ARRAY(p) { if (p) { delete[] (p); (p) = NULL; } }
#define SAFE_RELEASE(p) { if (p) { (p)->Release(); (p) = NULL; } }
#define LOWER(c) (((c)>='A' && (c) <= 'Z') ? ((c)+('a'-'A')) : (c))
#define UPPER(c) (((c)>='a' && (c) <= 'z') ? ((c)+('A'-'a')) : (c))
#define str_cmp strcasecmp
#define STRNCPY(dst, src, len) do {strncpy(dst, src, len); dst[len] = '\0'; } while(0)
extern char * str_dup(const char * source); // <20>޸<EFBFBD><DEB8><EFBFBD> <20>Ҵ<EFBFBD> <20>ؼ<EFBFBD> source <20><><EFBFBD><EFBFBD> <20>Ѱ<EFBFBD> <20><><EFBFBD><EFBFBD>
extern void printdata(const unsigned char * data, int bytes); // data<74><61> hex<65><78> ascii<69><69> <20><><EFBFBD><EFBFBD> (<28><>Ŷ <20>м<EFBFBD> <20><20><><EFBFBD><EFBFBD>)
extern int filesize(FILE * fp); // <20><><EFBFBD><EFBFBD> ũ<><C5A9> <20><><EFBFBD><EFBFBD>
#define core_dump() core_dump_unix(__FILE__, __LINE__)
extern void core_dump_unix(const char *who, WORD line); // <20>ھ<20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD>
#define TOKEN(string) if (!str_cmp(token_string, string))
// src = <20><>ū : <20><>
extern void parse_token(char * src, char * token, char * value);
extern void trim_and_lower(const char * src, char * dest, size_t dest_size);
// <20><><EFBFBD>ڿ<EFBFBD><DABF><EFBFBD> <20>ҹ<EFBFBD><D2B9>ڷ<EFBFBD>
extern void lower_string(const char * src, char * dest, size_t dest_len);
// arg1<67><31> arg2<67><32> <20><><EFBFBD><EFBFBD><EFBFBD>ϴ°<CFB4>? (<28><><EFBFBD>ҹ<EFBFBD><D2B9><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD>)
extern int is_abbrev(char *arg1, char *arg2);
// a<><61> b<><62> <20>ð<EFBFBD><C3B0><EFBFBD> <20>󸶳<EFBFBD> <20><><EFBFBD>̳<EFBFBD><CCB3><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD>
extern struct timeval * timediff(const struct timeval *a, const struct timeval *b);
// a<><61> <20>ð<EFBFBD><C3B0><EFBFBD> b<><62> <20>ð<EFBFBD><C3B0><EFBFBD> <20><><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD>
extern struct timeval * timeadd(struct timeval *a, struct timeval *b);
// <20><><EFBFBD><EFBFBD> <20>ð<EFBFBD> curr_tm<74><6D><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD> days<79><73> <20><><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD>
extern struct tm * tm_calc(const struct tm *curr_tm, int days);
extern int MAX(int a, int b); // <20><><EFBFBD>߿<EFBFBD> ū <20><><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD>
extern int MIN(int a, int b); // <20><><EFBFBD>߿<EFBFBD> <20><><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD>
extern int MINMAX(int min, int value, int max); // <20>ּ<EFBFBD> <20>ִ<EFBFBD> <20><><EFBFBD><EFBFBD> <20>Բ<EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD>ؼ<EFBFBD> <20><><EFBFBD><EFBFBD>
extern int number_ex(int from, int to, const char *file, int line); // from<6F><6D><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD> to<74><6F><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD> <20><> <20><><EFBFBD><EFBFBD>
#define number(from, to) number_ex(from, to, __FILE__, __LINE__)
float fnumber(float from, float to);
extern void thecore_sleep(struct timeval * timeout); // timeout<75><74>ŭ <20><><EFBFBD>μ<EFBFBD><CEBC><EFBFBD> <20><><EFBFBD><EFBFBD>
extern DWORD thecore_random(); // <20><><EFBFBD><EFBFBD> <20>Լ<EFBFBD>
extern float get_float_time();
extern DWORD get_dword_time();
extern char * time_str(time_t ct);
#define CREATE(result, type, number) do { \
if (!((result) = (type *) calloc ((number), sizeof(type)))) { \
sys_err("calloc failed [%d] %s", errno, strerror(errno)); \
abort(); } } while(0)
#define RECREATE(result,type,number) do { \
if (!((result) = (type *) realloc ((result), sizeof(type) * (number)))) { \
sys_err("realloc failed [%d] %s", errno, strerror(errno)); \
abort(); } } while(0)
// Next <20><> Prev <20><> <20>ִ<EFBFBD> <20><><EFBFBD><EFBFBD>Ʈ<EFBFBD><C6AE> <20>߰<EFBFBD>
#define INSERT_TO_TW_LIST(item, head, prev, next) \
if (!(head)) \
{ \
head = item; \
(head)->prev = (head)->next = NULL; \
} \
else \
{ \
(head)->prev = item; \
(item)->next = head; \
(item)->prev = NULL; \
head = item; \
}
#define REMOVE_FROM_TW_LIST(item, head, prev, next) \
if ((item) == (head)) \
{ \
if (((head) = (item)->next)) \
(head)->prev = NULL; \
} \
else \
{ \
if ((item)->next) \
(item)->next->prev = (item)->prev; \
\
if ((item)->prev) \
(item)->prev->next = (item)->next; \
}
#define INSERT_TO_LIST(item, head, next) \
(item)->next = (head); \
(head) = (item); \
#define REMOVE_FROM_LIST(item, head, next) \
if ((item) == (head)) \
head = (item)->next; \
else \
{ \
temp = head; \
\
while (temp && (temp->next != (item))) \
temp = temp->next; \
\
if (temp) \
temp->next = (item)->next; \
} \
#ifndef MAKEFOURCC
#define MAKEFOURCC(ch0, ch1, ch2, ch3) \
((DWORD)(BYTE) (ch0 ) | ((DWORD)(BYTE) (ch1) << 8) | \
((DWORD)(BYTE) (ch2) << 16) | ((DWORD)(BYTE) (ch3) << 24))
#endif // defined(MAKEFOURCC)
#ifdef __cplusplus
}
#endif // __cplusplus
// _countof for gcc/g++
#if !defined(_countof)
#if !defined(__cplusplus)
#define _countof(_Array) (sizeof(_Array) / sizeof(_Array[0]))
#else
extern "C++"
{
template <typename _CountofType, size_t _SizeOfArray>
char (*__countof_helper(_CountofType (&_Array)[_SizeOfArray]))[_SizeOfArray];
#define _countof(_Array) sizeof(*__countof_helper(_Array))
}
#endif
#endif
#ifdef __WIN32__
extern void gettimeofday(struct timeval* t, struct timezone* dummy);
#endif
#endif // __INC_UTILS_H__

View File

@ -0,0 +1,50 @@
#ifndef DIRENT_INCLUDED
#define DIRENT_INCLUDED
/*
Declaration of POSIX directory browsing functions and types for Win32.
Author: Kevlin Henney (kevlin@acm.org, kevlin@curbralan.com)
History: Created March 1997. Updated June 2003.
Rights: See end of file.
*/
#ifdef __cplusplus
extern "C"
{
#endif
typedef struct DIR DIR;
struct dirent
{
char *d_name;
};
DIR *opendir(const char *);
int closedir(DIR *);
struct dirent *readdir(DIR *);
void rewinddir(DIR *);
/*
Copyright Kevlin Henney, 1997, 2003. All rights reserved.
Permission to use, copy, modify, and distribute this software and its
documentation for any purpose is hereby granted without fee, provided
that this copyright and permissions notice appear in all copies and
derivatives.
This software is supplied "as is" without express or implied warranty.
But that said, if there are any problems please get in touch.
*/
#ifdef __cplusplus
}
#endif
#endif

View File

@ -0,0 +1,23 @@
// XGetopt.h Version 1.2
//
// Author: Hans Dietrich
// hdietrich2@hotmail.com
//
// This software is released into the public domain.
// You are free to use it in any way you like.
//
// This software is provided "as is" with no expressed
// or implied warranty. I accept no liability for any
// damage or loss of business that this software may cause.
//
///////////////////////////////////////////////////////////////////////////////
#ifndef XGETOPT_H
#define XGETOPT_H
extern int optind, opterr, optreset;
extern TCHAR *optarg;
int getopt(int argc, TCHAR *argv[], TCHAR *optstring);
#endif //XGETOPT_H

82
libthecore/include/xmd5.h Normal file
View File

@ -0,0 +1,82 @@
#ifndef __FreeBSD__
/*
* luau (Lib Update/Auto-Update): Simple Update Library
* Copyright (C) 2003 David Eklund
*
* - This library is free software; you can redistribute it and/or -
* - modify it under the terms of the GNU Lesser General Public -
* - License as published by the Free Software Foundation; either -
* - version 2.1 of the License, or (at your option) any later version. -
* - -
* - This 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 -
* - Lesser General Public License for more details. -
* - -
* - You should have received a copy of the GNU Lesser General Public -
* - License along with this library; if not, write to the Free Software -
* - Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA -
*/
/*
* md5.h and md5.c are based off of md5hl.c, md5c.c, and md5.h from libmd, which in turn are
* based off the FreeBSD libmd library. Their respective copyright notices follow:
*/
/*
* This code implements the MD5 message-digest algorithm.
* The algorithm is due to Ron Rivest. This code was
* written by Colin Plumb in 1993, no copyright is claimed.
* This code is in the public domain; do with it what you wish.
*
* Equivalent code is available from RSA Data Security, Inc.
* This code has been tested against that, and is equivalent,
* except that you don't need to include two pages of legalese
* with every copy.
*/
/* ----------------------------------------------------------------------------
* "THE BEER-WARE LICENSE" (Revision 42):
* <phk@login.dkuug.dk> wrote this file. As long as you retain this notice you
* can do whatever you want with this stuff. If we meet some day, and you think
* this stuff is worth it, you can buy me a beer in return. Poul-Henning Kamp
* ----------------------------------------------------------------------------
*
* $Id: md5.h,v 1.1.1.1 2004/04/02 05:11:38 deklund2 Exp $
*
*/
#ifndef MD5_H
#define MD5_H
#include <sys/types.h>
#define MD5_HASHBYTES 16
typedef struct MD5Context {
uint32_t buf[4];
uint32_t bits[2];
unsigned char in[64];
} MD5_CTX;
#ifdef __cplusplus
extern "C" {
#endif
void MD5Init(MD5_CTX *context);
void MD5Update(MD5_CTX *context, unsigned char const *buf, unsigned len);
void MD5Final(unsigned char digest[MD5_HASHBYTES], MD5_CTX *context);
void MD5Transform(uint32_t buf[4], uint32_t const in[16]);
char* MD5End(MD5_CTX *, char *);
char* lutil_md5_file(const char *filename, char *buf);
char* lutil_md5_data(const unsigned char *data, unsigned int len, char *buf);
#ifdef __cplusplus
}
#endif
#endif /* MD5_H */
#endif // #ifndef __FreeBSD__