Home | History | Annotate | Download | only in fxcrt
      1 // Copyright 2014 PDFium Authors. All rights reserved.
      2 // Use of this source code is governed by a BSD-style license that can be
      3 // found in the LICENSE file.
      4 
      5 // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com
      6 
      7 #ifndef _FX_SYSTEM_H_
      8 #define _FX_SYSTEM_H_
      9 #define _FX_WIN32_DESKTOP_		1
     10 #define _FX_LINUX_DESKTOP_		4
     11 #define _FX_MACOSX_				7
     12 #define _FX_ANDROID_			12
     13 #define _FXM_PLATFORM_WINDOWS_		1
     14 #define _FXM_PLATFORM_LINUX_		2
     15 #define _FXM_PLATFORM_APPLE_		3
     16 #define _FXM_PLATFORM_ANDROID_		4
     17 #ifndef _FX_OS_
     18 #if defined(__ANDROID__)
     19 #define _FX_OS_ _FX_ANDROID_
     20 #define _FXM_PLATFORM_ _FXM_PLATFORM_ANDROID_
     21 #elif defined(_WIN32) || defined(_WIN64)
     22 #define _FX_OS_ _FX_WIN32_DESKTOP_
     23 #define _FXM_PLATFORM_ _FXM_PLATFORM_WINDOWS_
     24 #elif defined(__linux__)
     25 #define _FX_OS_ _FX_LINUX_DESKTOP_
     26 #define _FXM_PLATFORM_ _FXM_PLATFORM_LINUX_
     27 #elif defined(__APPLE__)
     28 #define _FX_OS_ _FX_MACOSX_
     29 #define _FXM_PLATFORM_ _FXM_PLATFORM_APPLE_
     30 #endif
     31 #endif
     32 #if !defined(_FX_OS_) || _FX_OS_ == 0
     33 #error Sorry, can not figure out what OS you are targeting to. Please specify _FX_OS_ macro.
     34 #endif
     35 #if _FXM_PLATFORM_ == _FXM_PLATFORM_WINDOWS_
     36 #define _CRT_SECURE_NO_WARNINGS
     37 #include <windows.h>
     38 #endif
     39 #define _FX_W32_		1
     40 #define _FX_W64_		2
     41 #ifndef _FX_WORDSIZE_
     42 #if defined(_WIN64) || defined(__arm64) || defined(__arm64__) || defined(_M_AMD64) || defined(_M_X64) || defined(_M_IA64) || defined(__powerpc64__) || defined(__x86_64__) || __WORDSIZE == 64 || defined(__LP64__)
     43 #define _FX_WORDSIZE_	_FX_W64_
     44 #else
     45 #define _FX_WORDSIZE_	_FX_W32_
     46 #endif
     47 #endif
     48 #include <stddef.h>
     49 #include <stdarg.h>
     50 #include <setjmp.h>
     51 #include <stdlib.h>
     52 #include <stdio.h>
     53 #include <string.h>
     54 #include <assert.h>
     55 #include <wchar.h>
     56 #if _FXM_PLATFORM_ == _FXM_PLATFORM_APPLE_
     57 #include <libkern/OSAtomic.h>
     58 #if _FX_OS_ == _FX_MACOSX_
     59 #include <Carbon/Carbon.h>
     60 #elif _FX_OS_ == _FX_IOS_
     61 #include <CoreText/CoreText.h>
     62 #include <CoreGraphics/CoreGraphics.h>
     63 #endif
     64 #endif
     65 #ifdef __cplusplus
     66 extern "C" {
     67 #endif
     68 typedef void*					FX_LPVOID;
     69 typedef void const*				FX_LPCVOID;
     70 typedef void*					FX_POSITION;
     71 typedef signed char				FX_INT8;
     72 typedef unsigned char			FX_UINT8;
     73 typedef unsigned char			FX_BYTE;
     74 typedef unsigned char*			FX_LPBYTE;
     75 typedef unsigned char const*	FX_LPCBYTE;
     76 typedef short					FX_INT16;
     77 typedef unsigned short			FX_UINT16;
     78 typedef short					FX_SHORT;
     79 typedef unsigned short			FX_WORD;
     80 typedef unsigned short*			FX_LPWORD;
     81 typedef unsigned short const*	FX_LPCWORD;
     82 typedef int						FX_INT32;
     83 typedef float					FX_FLOAT;
     84 typedef int						FX_BOOL;
     85 typedef int						FX_ERR;
     86 #define FX_SUCCEEDED(Status)	((FX_ERR)(Status) >= 0)
     87 #define FX_FAILED(Status)		((FX_ERR)(Status) < 0)
     88 typedef char					FX_CHAR;
     89 typedef char*					FX_LPSTR;
     90 typedef char const*				FX_LPCSTR;
     91 typedef unsigned int		FX_DWORD;
     92 typedef unsigned int*		FX_LPDWORD;
     93 #if _FXM_PLATFORM_ == _FXM_PLATFORM_WINDOWS_
     94 typedef __int64				FX_INT64;
     95 typedef unsigned __int64	FX_UINT64;
     96 #else
     97 typedef long long int		FX_INT64;
     98 typedef unsigned long long	FX_UINT64;
     99 #endif
    100 #if _FX_WORDSIZE_ == _FX_W64_
    101 typedef FX_INT64			FX_INTPTR;
    102 typedef FX_UINT64			FX_UINTPTR;
    103 #else
    104 typedef int					FX_INTPTR;
    105 typedef unsigned int		FX_UINTPTR;
    106 #endif
    107 typedef wchar_t					FX_WCHAR;
    108 typedef wchar_t*				FX_LPWSTR;
    109 typedef wchar_t const*			FX_LPCWSTR;
    110 typedef FX_DWORD				FX_UINT32;
    111 typedef FX_UINT64				FX_QWORD;
    112 #define FX_DEFINEHANDLE(name)	typedef struct _##name {FX_LPVOID pData;} * name;
    113 #if defined(DEBUG) && !defined(_DEBUG)
    114 #define _DEBUG
    115 #endif
    116 #ifndef TRUE
    117 
    118 #define TRUE	1
    119 #endif
    120 #ifndef FALSE
    121 
    122 #define FALSE	0
    123 #endif
    124 #ifndef NULL
    125 
    126 #define NULL	0
    127 #endif
    128 #define FXSYS_assert assert
    129 #ifndef ASSERT
    130 #ifdef _DEBUG
    131 #define ASSERT FXSYS_assert
    132 #else
    133 
    134 #define ASSERT(a)
    135 #endif
    136 #endif
    137 #define FX_MAX(a, b) (((a) > (b)) ? (a) : (b))
    138 #define FX_MIN(a, b) (((a) < (b)) ? (a) : (b))
    139 #define FX_PI	3.1415926535897932384626433832795f
    140 #if _FXM_PLATFORM_ == _FXM_PLATFORM_WINDOWS_
    141 #define FXSYS_snprintf	_snprintf
    142 #else
    143 #define FXSYS_snprintf	snprintf
    144 #endif
    145 #define FXSYS_sprintf	sprintf
    146 #define FXSYS_vsprintf	vsprintf
    147 #define FXSYS_strchr	strchr
    148 #define FXSYS_strlen	strlen
    149 #define FXSYS_strncmp	strncmp
    150 #define FXSYS_strcmp	strcmp
    151 #define FXSYS_strcpy	strcpy
    152 #define FXSYS_strncpy	strncpy
    153 #define FXSYS_strstr	strstr
    154 #define FXSYS_FILE		FILE
    155 #define FXSYS_fopen		fopen
    156 #define FXSYS_fclose	fclose
    157 #define FXSYS_SEEK_END	SEEK_END
    158 #define FXSYS_SEEK_SET	SEEK_SET
    159 #define FXSYS_fseek		fseek
    160 #define FXSYS_ftell		ftell
    161 #define FXSYS_fread		fread
    162 #define FXSYS_fwrite	fwrite
    163 #define FXSYS_fprintf	fprintf
    164 #define FXSYS_fflush	fflush
    165 #if _FXM_PLATFORM_ == _FXM_PLATFORM_WINDOWS_
    166 #ifdef _NATIVE_WCHAR_T_DEFINED
    167 #define FXSYS_wfopen(f, m) _wfopen((const wchar_t*)(f), (const wchar_t*)(m))
    168 #else
    169 #define FXSYS_wfopen _wfopen
    170 #endif
    171 #else
    172 FXSYS_FILE* FXSYS_wfopen(FX_LPCWSTR filename, FX_LPCWSTR mode);
    173 #endif
    174 
    175 #define FXSYS_wcslen	wcslen
    176 #define FXSYS_wcscmp	wcscmp
    177 #define FXSYS_wcschr	wcschr
    178 #define FXSYS_wcsstr	wcsstr
    179 #define FXSYS_wcsncmp	wcsncmp
    180 #define FXSYS_vswprintf	vswprintf
    181 #define FXSYS_mbstowcs	mbstowcs
    182 #define FXSYS_wcstombs	wcstombs
    183 #define FXSYS_memcmp	memcmp
    184 #define FXSYS_memcpy	memcpy
    185 #define FXSYS_memmove	memmove
    186 #define FXSYS_memset	memset
    187 #define FXSYS_memchr	memchr
    188 #define FXSYS_qsort		qsort
    189 #define FXSYS_bsearch	bsearch
    190 #if _FXM_PLATFORM_ == _FXM_PLATFORM_WINDOWS_
    191 #define FXSYS_GetACP GetACP
    192 #define FXSYS_itoa _itoa
    193 #define FXSYS_strlwr _strlwr
    194 #define FXSYS_strupr _strupr
    195 #define FXSYS_stricmp _stricmp
    196 #ifdef _NATIVE_WCHAR_T_DEFINED
    197 #define FXSYS_wcsicmp(str1, str2) _wcsicmp((wchar_t*)(str1), (wchar_t*)(str2))
    198 #define FXSYS_WideCharToMultiByte(p1, p2, p3, p4, p5, p6, p7, p8) WideCharToMultiByte(p1, p2, (const wchar_t*)(p3), p4, p5, p6, p7, p8)
    199 #define FXSYS_MultiByteToWideChar(p1, p2, p3, p4, p5, p6) MultiByteToWideChar(p1, p2, p3, p4, (wchar_t*)(p5), p6)
    200 #define FXSYS_wcslwr(str) _wcslwr((wchar_t*)(str))
    201 #define FXSYS_wcsupr(str) _wcsupr((wchar_t*)(str))
    202 #else
    203 #define FXSYS_wcsicmp _wcsicmp
    204 #define FXSYS_WideCharToMultiByte WideCharToMultiByte
    205 #define FXSYS_MultiByteToWideChar MultiByteToWideChar
    206 #define FXSYS_wcslwr _wcslwr
    207 #define FXSYS_wcsupr _wcsupr
    208 #endif
    209 #define FXSYS_GetFullPathName GetFullPathName
    210 #define FXSYS_GetModuleFileName GetModuleFileName
    211 #else
    212 int			FXSYS_GetACP(void);
    213 char*		FXSYS_itoa(int value, char* string, int radix);
    214 int			FXSYS_WideCharToMultiByte(FX_DWORD codepage, FX_DWORD dwFlags, const wchar_t* wstr, int wlen,
    215                                       char* buf, int buflen, const char* default_str, int* pUseDefault);
    216 int			FXSYS_MultiByteToWideChar(FX_DWORD codepage, FX_DWORD dwFlags, const char* bstr, int blen,
    217                                       wchar_t* buf, int buflen);
    218 FX_DWORD	FXSYS_GetFullPathName(const char* filename, FX_DWORD buflen, char* buf, char** filepart);
    219 FX_DWORD	FXSYS_GetModuleFileName(void* hModule, char* buf, FX_DWORD bufsize);
    220 char*		FXSYS_strlwr(char* str);
    221 char*		FXSYS_strupr(char* str);
    222 int			FXSYS_stricmp(const char*, const char*);
    223 int			FXSYS_wcsicmp(const wchar_t *string1, const wchar_t *string2);
    224 wchar_t*	FXSYS_wcslwr(wchar_t* str);
    225 wchar_t*	FXSYS_wcsupr(wchar_t* str);
    226 #endif
    227 #define FXSYS_memcpy32		FXSYS_memcpy
    228 #define FXSYS_memcmp32		FXSYS_memcmp
    229 #define FXSYS_memset32		FXSYS_memset
    230 #define FXSYS_memset8		FXSYS_memset
    231 #define FXSYS_memmove32		FXSYS_memmove
    232 #ifdef __cplusplus
    233 }
    234 #endif
    235 #include <math.h>
    236 #if _FXM_PLATFORM_ == _FXM_PLATFORM_WINDOWS_
    237 #define FXSYS_pow(a, b)		(FX_FLOAT)powf(a, b)
    238 #else
    239 #define FXSYS_pow(a, b)		(FX_FLOAT)pow(a, b)
    240 #endif
    241 #define FXSYS_sqrt(a)		(FX_FLOAT)sqrt(a)
    242 #define FXSYS_fabs(a)		(FX_FLOAT)fabs(a)
    243 #define FXSYS_atan2(a, b)	(FX_FLOAT)atan2(a, b)
    244 #define FXSYS_ceil(a)		(FX_FLOAT)ceil(a)
    245 #define FXSYS_floor(a)		(FX_FLOAT)floor(a)
    246 #define FXSYS_cos(a)		(FX_FLOAT)cos(a)
    247 #define FXSYS_acos(a)		(FX_FLOAT)acos(a)
    248 #define FXSYS_sin(a)		(FX_FLOAT)sin(a)
    249 #define FXSYS_log(a)		(FX_FLOAT)log(a)
    250 #define FXSYS_log10(a)		(FX_FLOAT)log10(a)
    251 #define FXSYS_fmod(a, b)	(FX_FLOAT)fmod(a, b)
    252 #define FXSYS_abs			abs
    253 #ifdef __cplusplus
    254 extern "C" {
    255 #endif
    256 #define _FX_LSB_FIRST_
    257 #define FXDWORD_FROM_LSBFIRST(i)	(i)
    258 #define FXDWORD_FROM_MSBFIRST(i)	(((FX_BYTE)(i) << 24) | ((FX_BYTE)((i) >> 8) << 16) | ((FX_BYTE)((i) >> 16) << 8) | (FX_BYTE)((i) >> 24))
    259 #define FXDWORD_GET_LSBFIRST(p)		((((FX_LPBYTE)(p))[3] << 24) | (((FX_LPBYTE)(p))[2] << 16) | (((FX_LPBYTE)(p))[1] << 8) | (((FX_LPBYTE)(p))[0]))
    260 #define FXDWORD_GET_MSBFIRST(p) ((((FX_LPBYTE)(p))[0] << 24) | (((FX_LPBYTE)(p))[1] << 16) | (((FX_LPBYTE)(p))[2] << 8) | (((FX_LPBYTE)(p))[3]))
    261 #define FXSYS_HIBYTE(word)	((FX_BYTE)((word) >> 8))
    262 #define FXSYS_LOBYTE(word)	((FX_BYTE)(word))
    263 #define FXSYS_HIWORD(dword)	((FX_WORD)((dword) >> 16))
    264 #define FXSYS_LOWORD(dword)	((FX_WORD)(dword))
    265 FX_INT32	FXSYS_atoi(FX_LPCSTR str);
    266 FX_INT32	FXSYS_wtoi(FX_LPCWSTR str);
    267 FX_INT64	FXSYS_atoi64(FX_LPCSTR str);
    268 FX_INT64	FXSYS_wtoi64(FX_LPCWSTR str);
    269 FX_LPCSTR	FXSYS_i64toa(FX_INT64 value, FX_LPSTR str, int radix);
    270 FX_LPCWSTR	FXSYS_i64tow(FX_INT64 value, FX_LPWSTR str, int radix);
    271 int			FXSYS_round(FX_FLOAT f);
    272 #define		FXSYS_Mul(a, b) ((a) * (b))
    273 #define		FXSYS_Div(a, b) ((a) / (b))
    274 #define		FXSYS_MulDiv(a, b, c) ((a) * (b) / (c))
    275 #define		FXSYS_sqrt2(a, b) (FX_FLOAT)FXSYS_sqrt((a)*(a) + (b)*(b))
    276 #ifdef __cplusplus
    277 };
    278 #endif
    279 #endif
    280