Mercurial > vba-clojure
diff src/Port.h @ 1:f9f4f1b99eed
importing src directory
author | Robert McIntyre <rlm@mit.edu> |
---|---|
date | Sat, 03 Mar 2012 10:31:27 -0600 |
parents | |
children | 48369c6aeaa0 |
line wrap: on
line diff
1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/src/Port.h Sat Mar 03 10:31:27 2012 -0600 1.3 @@ -0,0 +1,178 @@ 1.4 +#ifndef VBA_PORT_H 1.5 +#define VBA_PORT_H 1.6 + 1.7 +#if _MSC_VER > 1000 1.8 +#pragma once 1.9 +#endif // _MSC_VER > 1000 1.10 + 1.11 +#include <ctime> 1.12 + 1.13 +#ifndef NULL 1.14 +#define NULL 0 1.15 +#endif 1.16 + 1.17 +typedef unsigned char bool8; 1.18 + 1.19 +#ifdef HAVE_STDINT_H 1.20 +#include <stdint.h> 1.21 + 1.22 +typedef int8_t int8; 1.23 +typedef uint8_t uint8; 1.24 +typedef int16_t int16; 1.25 +typedef uint16_t uint16; 1.26 +typedef int32_t int32; 1.27 +typedef uint32_t uint32; 1.28 +typedef int64_t int64; 1.29 +typedef uint64_t uint64; 1.30 +typedef intptr_t pint; 1.31 + 1.32 +#else /* Don't have stdint.h */ 1.33 + 1.34 +#ifdef PTR_NOT_INT 1.35 +typedef long pint; 1.36 +#else /* pointer is int */ 1.37 +typedef int pint; 1.38 +#endif /* PTR_NOT_INT */ 1.39 + 1.40 +/* FIXME: Refactor this by moving out the BORLAND part and unifying typedefs */ 1.41 +#ifndef WIN32 1.42 +typedef unsigned char uint8; 1.43 +typedef unsigned short uint16; 1.44 +typedef signed char int8; 1.45 +typedef short int16; 1.46 +typedef int int32; 1.47 +typedef unsigned int uint32; 1.48 +# ifdef __GNUC__ /* long long is not part of ISO C++ */ 1.49 +__extension__ typedef long long int64; 1.50 +__extension__ typedef unsigned long long uint64; 1.51 +# else 1.52 +typedef long long int64; 1.53 +typedef unsigned long long uint64; 1.54 +# endif 1.55 +#else /* WIN32 */ 1.56 + 1.57 +# ifdef __BORLANDC__ 1.58 +# include <systypes.h> 1.59 +# else 1.60 + 1.61 +typedef unsigned char uint8; 1.62 +typedef unsigned short uint16; 1.63 +typedef signed char int8; 1.64 +typedef short int16; 1.65 + 1.66 +# ifndef WSAAPI 1.67 +/* winsock2.h typedefs int32 as well. */ 1.68 +typedef long int32; 1.69 +# endif 1.70 + 1.71 +typedef unsigned int uint32; 1.72 + 1.73 +# endif /* __BORLANDC__ */ 1.74 + 1.75 +typedef __int64 int64; 1.76 +typedef unsigned __int64 uint64; 1.77 + 1.78 +#endif /* WIN32 */ 1.79 +#endif /* HAVE_STDINT_H */ 1.80 + 1.81 +#ifndef WIN32 1.82 + 1.83 +#ifndef PATH_MAX 1.84 +#define PATH_MAX 1024 1.85 +#endif 1.86 + 1.87 +#define _MAX_DIR PATH_MAX 1.88 +#define _MAX_DRIVE 1 1.89 +#define _MAX_FNAME PATH_MAX 1.90 +#define _MAX_EXT PATH_MAX 1.91 +#define _MAX_PATH PATH_MAX 1.92 + 1.93 +#define ZeroMemory(a, b) memset((a), 0, (b)) 1.94 + 1.95 +void _makepath(char *path, const char *drive, const char *dir, 1.96 + const char *fname, const char *ext); 1.97 +void _splitpath(const char *path, char *drive, char *dir, char *fname, 1.98 + char *ext); 1.99 +#else /* WIN32 */ 1.100 +#define strcasecmp stricmp 1.101 +#define strncasecmp strnicmp 1.102 +#endif 1.103 + 1.104 +typedef uint8 u8; 1.105 +typedef uint16 u16; 1.106 +typedef uint32 u32; 1.107 +typedef uint64 u64; 1.108 +typedef int8 s8; 1.109 +typedef int16 s16; 1.110 +typedef int32 s32; 1.111 +typedef int64 s64; 1.112 + 1.113 +// for consistency 1.114 +static inline u8 swap8(u8 v) 1.115 +{ 1.116 + return v; 1.117 +} 1.118 + 1.119 +// swaps a 16-bit value 1.120 +static inline u16 swap16(u16 v) 1.121 +{ 1.122 + return (v<<8)|(v>>8); 1.123 +} 1.124 + 1.125 +// swaps a 32-bit value 1.126 +static inline u32 swap32(u32 v) 1.127 +{ 1.128 + return (v<<24)|((v<<8)&0xff0000)|((v>>8)&0xff00)|(v>>24); 1.129 +} 1.130 + 1.131 +#define READ8LE(x) \ 1.132 + *((u8 *)x) 1.133 + 1.134 +#define WRITE8LE(x, v) \ 1.135 + *((u8 *)x) = (v) 1.136 + 1.137 +#ifdef WORDS_BIGENDIAN 1.138 +#if defined(__GNUC__) && defined(__ppc__) 1.139 + 1.140 +#define READ16LE(base) \ 1.141 + ({ unsigned short lhbrxResult; \ 1.142 + __asm__("lhbrx %0, 0, %1" : "=r" (lhbrxResult) : "r" (base) : "memory"); \ 1.143 + lhbrxResult; }) 1.144 + 1.145 +#define READ32LE(base) \ 1.146 + ({ unsigned long lwbrxResult; \ 1.147 + __asm__("lwbrx %0, 0, %1" : "=r" (lwbrxResult) : "r" (base) : "memory"); \ 1.148 + lwbrxResult; }) 1.149 + 1.150 +#define WRITE16LE(base, value) \ 1.151 + __asm__("sthbrx %0, 0, %1" : : "r" (value), "r" (base) : "memory") 1.152 + 1.153 +#define WRITE32LE(base, value) \ 1.154 + __asm__("stwbrx %0, 0, %1" : : "r" (value), "r" (base) : "memory") 1.155 + 1.156 +#else 1.157 +#define READ16LE(x) \ 1.158 + swap16(*((u16 *)(x))) 1.159 +#define READ32LE(x) \ 1.160 + swap32(*((u32 *)(x))) 1.161 +#define WRITE16LE(x, v) \ 1.162 + *((u16 *)x) = swap16((v)) 1.163 +#define WRITE32LE(x, v) \ 1.164 + *((u32 *)x) = swap32((v)) 1.165 +#endif 1.166 +#else 1.167 +#define READ16LE(x) \ 1.168 + *((u16 *)x) 1.169 +#define READ32LE(x) \ 1.170 + *((u32 *)x) 1.171 +#define WRITE16LE(x, v) \ 1.172 + *((u16 *)x) = (v) 1.173 +#define WRITE32LE(x, v) \ 1.174 + *((u32 *)x) = (v) 1.175 +#endif 1.176 + 1.177 +#ifndef CTASSERT 1.178 +#define CTASSERT(x) typedef char __assert ## y[(x) ? 1 : -1]; 1.179 +#endif 1.180 + 1.181 +#endif // VBA_PORT_H