1 /* This file is part of the wvWare 2 project
2 Copyright (C) 2001-2003 Werner Trobin <trobin@kde.org>
3
4 This library is free software; you can redistribute it and/or
5 modify it under the terms of the GNU Library General Public
6 License version 2 as published by the Free Software Foundation.
7
8 This library is distributed in the hope that it will be useful,
9 but WITHOUT ANY WARRANTY; without even the implied warranty of
10 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11 Library General Public License for more details.
12
13 You should have received a copy of the GNU Library General Public License
14 along with this library; see the file COPYING.LIB. If not, write to
15 the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
16 Boston, MA 02111-1307, USA.
17 */
18
19 #ifndef GLOBAL_H
20 #define GLOBAL_H
21
22 #include "dllmagic.h"
23 #include "wv2version.h" // ###### WV2 0.3: Remove this #include
24
25 /** @file
26 * We use this typedefs to be compatible with the types from
27 * the MS HTML specifications.
28 */
29
30 // A few defines used for "inline" debugging
31 #define WV2_DUMP_PIECE_TABLE 0 // has to be defined as we just #if it
32 //#define WV2_DUMP_FIB 1
33
34 #define WV2_DEBUG_STYLESHEET 1
35 #define WV2_DEBUG_SPRMS 1
36
37 //#define WV2_DEBUG_LIST_READING 1
38 //#define WV2_DEBUG_LIST_PROCESSING 1
39
40 //#define WV2_DEBUG_FIELDS 1
41
42 //#define WV2_DEBUG_FOOTNOTES 1
43
44 //#define WV2_DEBUG_HEADERS 1
45
46 //#define WV2_DEBUG_TABLES 1
47
48 //#define WV2_DEBUG_PICTURES 1
49
50 // This define should only be commented out for releases (if at all)
51 #define WV2_CHECKING 1
52
53 namespace wvWare
54 {
55
56 typedef signed char S8;
57 typedef unsigned char U8;
58 typedef signed short S16;
59 typedef unsigned short U16;
60 typedef signed int S32;
61 typedef unsigned int U32;
62 typedef U16 XCHAR;
63 typedef U32 FC;
64
65 /**
66 * This enum tells the apply* methods in the PAP/CHP/... structs what grpprls to
67 * expect. Unfortunately the size of the SPRMs changed for Word 8.
68 */
69 enum WordVersion { Word67, Word8 };
70 const int Word8nFib = 193;
71
readU8(const U8 * in)72 inline U8 readU8( const U8* in )
73 {
74 return *in;
75 }
76
readS8(const U8 * in)77 inline S8 readS8( const U8* in )
78 {
79 return static_cast<S8>( *in );
80 }
81
82 // reads a U16/S16 or U32/S32 from a little-endian byte
83 // "array" in an endian-correct way
readU16(const U8 * in)84 inline U16 readU16( const U8* in )
85 {
86 return static_cast<U16>( in[0] ) | ( static_cast<U16>( in[1] ) << 8 );
87 }
88
readS16(const U8 * in)89 inline S16 readS16( const U8* in )
90 {
91 return static_cast<S16>( readU16( in ) );
92 }
93
94 // writes a U16 to a little-endian byte "array" in an endian-correct way
write(U8 * out,U16 data)95 inline void write( U8* out, U16 data )
96 {
97 out[ 0 ] = data & 0x00ff;
98 out[ 1 ] = data >> 8;
99 }
100
readU32(const U8 * in)101 inline U32 readU32( const U8* in )
102 {
103 return static_cast<U32>( in[0] ) | ( static_cast<U32>( in[1] ) << 8 ) |
104 ( static_cast<U32>( in[2] ) << 16 ) | ( static_cast<U32>( in[3] ) << 24 );
105 }
106
readS32(const U8 * in)107 inline S32 readS32(const U8* in)
108 {
109 return static_cast<S32>( readU32( in ) );
110 }
111
112 // Endianness fun
113 U16 toLittleEndian( U16 data );
114
toLittleEndian(S16 data)115 inline S16 toLittleEndian( S16 data )
116 {
117 return static_cast<S16>( toLittleEndian( static_cast<U16>( data ) ) );
118 }
119
120 U16 toBigEndian( U16 data );
121
toBigEndian(S16 data)122 inline S16 toBigEndian( S16 data )
123 {
124 return static_cast<S16>( toBigEndian( static_cast<U16>( data ) ) );
125 }
126
swapEndianness(U16 data)127 inline U16 swapEndianness( U16 data )
128 {
129 return ( ( data & 0x00ffU ) << 8 ) | ( ( data & 0xff00U ) >> 8 );
130 }
131
swapEndianness(S16 data)132 inline S16 swapEndianness( S16 data )
133 {
134 return ( ( data & 0x00ffU ) << 8 ) | ( ( data & 0xff00U ) >> 8 );
135 }
136
137 U32 toLittleEndian( U32 data );
138
toLittleEndian(S32 data)139 inline S32 toLittleEndian( S32 data )
140 {
141 return static_cast<S32>( toLittleEndian( static_cast<U32>( data ) ) );
142 }
143
144 U32 toBigEndian( U32 data );
145
toBigEndian(S32 data)146 inline S32 toBigEndian( S32 data )
147 {
148 return static_cast<S32>( toBigEndian( static_cast<U32>( data ) ) );
149 }
150
swapEndianness(U32 data)151 inline U32 swapEndianness( U32 data )
152 {
153 return ( ( data & 0x000000ffU ) << 24 ) | ( ( data & 0x0000ff00U ) << 8 ) |
154 ( ( data & 0x00ff0000U ) >> 8 ) | ( ( data & 0xff000000U ) >> 24 );
155 }
156
swapEndianness(S32 data)157 inline S32 swapEndianness( S32 data )
158 {
159 return ( ( data & 0x000000ffU ) << 24 ) | ( ( data & 0x0000ff00U ) << 8 ) |
160 ( ( data & 0x00ff0000U ) >> 8 ) | ( ( data & 0xff000000U ) >> 24 );
161 }
162
163 } // namespace wvWare
164
165 #endif // GLOBAL_H
166