1 | /**********************************************************************
|
---|
2 | *
|
---|
3 | * Compat.h
|
---|
4 | * Copyright (C) 2003 UNESCO
|
---|
5 | *
|
---|
6 | * A component of the Greenstone digital library software
|
---|
7 | * from the New Zealand Digital Library Project at the
|
---|
8 | * University of Waikato, New Zealand.
|
---|
9 | *
|
---|
10 | * This program is free software; you can redistribute it and/or modify
|
---|
11 | * it under the terms of the GNU General Public License as published by
|
---|
12 | * the Free Software Foundation; either version 2 of the License, or
|
---|
13 | * (at your option) any later version.
|
---|
14 | *
|
---|
15 | * This program is distributed in the hope that it will be useful,
|
---|
16 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
|
---|
17 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
---|
18 | * GNU General Public License for more details.
|
---|
19 | *
|
---|
20 | * You should have received a copy of the GNU General Public License
|
---|
21 | * along with this program; if not, write to the Free Software
|
---|
22 | * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
|
---|
23 | *
|
---|
24 | *********************************************************************/
|
---|
25 |
|
---|
26 | #ifndef _WIN32
|
---|
27 |
|
---|
28 | #include <string>
|
---|
29 | #include <algorithm>
|
---|
30 | #include <iostream>
|
---|
31 | #include <sstream>
|
---|
32 | #include <stdio.h>
|
---|
33 | #include <sys/stat.h>
|
---|
34 |
|
---|
35 | #define TCHAR char
|
---|
36 | #define BOOL bool
|
---|
37 | #define WORD unsigned short
|
---|
38 | #define DWORD unsigned long
|
---|
39 | #define INT32 int
|
---|
40 | #define UINT32 unsigned int
|
---|
41 | #define LONG long int
|
---|
42 | #define TRUE true
|
---|
43 | #define FALSE false
|
---|
44 |
|
---|
45 | #define _MAX_PATH 512
|
---|
46 | // #define SHRT_MAX 32732
|
---|
47 |
|
---|
48 | /* Formatted i/o */
|
---|
49 |
|
---|
50 | #define _tprintf printf
|
---|
51 | #define _ftprintf fprintf
|
---|
52 | #define _stprintf sprintf
|
---|
53 | #define _sntprintf _snprintf
|
---|
54 | #define _vtprintf vprintf
|
---|
55 | #define _vftprintf vfprintf
|
---|
56 | #define _vstprintf vsprintf
|
---|
57 | #define _vsntprintf _vsnprintf
|
---|
58 | #define _tscanf scanf
|
---|
59 | #define _ftscanf fscanf
|
---|
60 | #define _stscanf sscanf
|
---|
61 | /* String conversion functions */
|
---|
62 |
|
---|
63 | #define _tcstod strtod
|
---|
64 | #define _tcstol strtol
|
---|
65 | #define _tcstoul strtoul
|
---|
66 |
|
---|
67 | #define _itot _itoa
|
---|
68 | #define _ltot _ltoa
|
---|
69 | #define _ultot _ultoa
|
---|
70 | #define _ttoi atoi
|
---|
71 | #define _ttol atol
|
---|
72 |
|
---|
73 | #define _ttoi64 _atoi64
|
---|
74 | #define _i64tot _i64toa
|
---|
75 | #define _ui64tot _ui64toa
|
---|
76 | /* String functions */
|
---|
77 |
|
---|
78 | /* Note that _mbscat, _mbscpy and _mbsdup are functionally equivalent to
|
---|
79 | strcat, strcpy and strdup, respectively. */
|
---|
80 |
|
---|
81 | #define _tcscat strcat
|
---|
82 | #define _tcscpy strcpy
|
---|
83 | #define _tcsdup _strdup
|
---|
84 |
|
---|
85 | #define _tcslen strlen
|
---|
86 | #define _tcsxfrm strxfrm
|
---|
87 |
|
---|
88 |
|
---|
89 | // #define assert
|
---|
90 | #define ASSERT
|
---|
91 | #define AssertFailed
|
---|
92 |
|
---|
93 | // #define _T(par) par
|
---|
94 | #define LPCTSTR const char *
|
---|
95 | #define LPTSTR char *
|
---|
96 | #define FAR
|
---|
97 | #define TRACE
|
---|
98 | #define PRECONDITION
|
---|
99 | #define SIZE_T size_t
|
---|
100 |
|
---|
101 |
|
---|
102 |
|
---|
103 | #endif
|
---|
104 | #define MoveMemory memmove
|
---|
105 | #define ZeroMemory(p,size) memset(p,0,size)
|
---|
106 |
|
---|
107 |
|
---|
108 | inline void fix_endianness(short int& x)
|
---|
109 | {
|
---|
110 | #if !defined(LITTLE_ENDIAN)
|
---|
111 | if (x < 0) {
|
---|
112 | unsigned short int ux = (unsigned short int) x;
|
---|
113 | x = (ux>>8) |
|
---|
114 | (ux<<8);
|
---|
115 | }
|
---|
116 | else {
|
---|
117 | x = (x>>8) |
|
---|
118 | (x<<8);
|
---|
119 | }
|
---|
120 | #endif
|
---|
121 | }
|
---|
122 |
|
---|
123 | inline void fix_endianness(long int& x)
|
---|
124 | {
|
---|
125 | #if !defined(LITTLE_ENDIAN)
|
---|
126 | if (x < 0) {
|
---|
127 | unsigned long ux = (unsigned long) x;
|
---|
128 | x = (ux>>24) |
|
---|
129 | ((ux<<8) & 0x00FF0000) |
|
---|
130 | ((ux>>8) & 0x0000FF00) |
|
---|
131 | (ux<<24);
|
---|
132 | }
|
---|
133 | else {
|
---|
134 | x = (x>>24) |
|
---|
135 | ((x<<8) & 0x00FF0000) |
|
---|
136 | ((x>>8) & 0x0000FF00) |
|
---|
137 | (x<<24);
|
---|
138 | }
|
---|
139 | #endif
|
---|
140 | }
|
---|