home *** CD-ROM | disk | FTP | other *** search
/ Personal Computer World 2009 February / PCWFEB09.iso / Software / Linux / SLAX 6.0.8 / slax-6.0.8.iso / slax / base / 006-devel.lzm / usr / include / wv2 / global.h < prev    next >
Encoding:
C/C++ Source or Header  |  2006-06-12  |  4.0 KB  |  167 lines

  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.  
  24. /** @file
  25.  * We use this typedefs to be compatible with the types from
  26.  * the MS HTML specifications.
  27.  */
  28.  
  29. // A few defines used for "inline" debugging
  30. #define WV2_DUMP_PIECE_TABLE 0 // has to be defined as we just #if it
  31. //#define WV2_DUMP_FIB 1
  32.  
  33. //#define WV2_DEBUG_STYLESHEET 1
  34. //#define WV2_DEBUG_SPRMS 1
  35.  
  36. //#define WV2_DEBUG_LIST_READING 1
  37. //#define WV2_DEBUG_LIST_PROCESSING 1
  38.  
  39. //#define WV2_DEBUG_FIELDS 1
  40.  
  41. //#define WV2_DEBUG_FOOTNOTES 1
  42.  
  43. //#define WV2_DEBUG_HEADERS 1
  44.  
  45. //#define WV2_DEBUG_TABLES 1
  46.  
  47. //#define WV2_DEBUG_PICTURES 1
  48.  
  49. // This define should only be commented out for releases (if at all)
  50. #define WV2_CHECKING 1
  51.  
  52. extern const char* const libwv2_version;
  53.  
  54. namespace wvWare
  55. {
  56.  
  57. typedef signed char S8;
  58. typedef unsigned char U8;
  59. typedef signed short S16;
  60. typedef unsigned short U16;
  61. typedef signed int S32;
  62. typedef unsigned int U32;
  63. typedef U16 XCHAR;
  64. typedef U32 FC;
  65.  
  66. /**
  67.  * This enum tells the apply* methods in the PAP/CHP/... structs what grpprls to
  68.  * expect. Unfortunately the size of the SPRMs changed for Word 8.
  69.  */
  70. enum WordVersion { Word67, Word8 };
  71. const int Word8nFib = 193;
  72.  
  73. inline U8 readU8( const U8* in )
  74. {
  75.     return *in;
  76. }
  77.  
  78. inline S8 readS8( const U8* in )
  79. {
  80.     return static_cast<S8>( *in );
  81. }
  82.  
  83. // reads a U16/S16 or U32/S32 from a little-endian byte
  84. // "array" in an endian-correct way
  85. inline U16 readU16( const U8* in )
  86. {
  87.     return static_cast<U16>( in[0] ) | ( static_cast<U16>( in[1] ) << 8 );
  88. }
  89.  
  90. inline S16 readS16( const U8* in )
  91. {
  92.     return static_cast<S16>( readU16( in ) );
  93. }
  94.  
  95. // writes a U16 to a little-endian byte "array" in an endian-correct way
  96. inline void write( U8* out, U16 data )
  97. {
  98.     out[ 0 ] = data & 0x00ff;
  99.     out[ 1 ] = data >> 8;
  100. }
  101.  
  102. inline U32 readU32( const U8* in )
  103. {
  104.     return static_cast<U32>( in[0] ) | ( static_cast<U32>( in[1] ) << 8 ) |
  105.         ( static_cast<U32>( in[2] ) << 16 ) | ( static_cast<U32>( in[3] ) << 24 );
  106. }
  107.  
  108. inline S32 readS32(const U8* in)
  109. {
  110.     return static_cast<S32>( readU32( in ) );
  111. }
  112.  
  113. // Endianness fun
  114. U16 toLittleEndian( U16 data );
  115.  
  116. inline S16 toLittleEndian( S16 data )
  117. {
  118.     return static_cast<S16>( toLittleEndian( static_cast<U16>( data ) ) );
  119. }
  120.  
  121. U16 toBigEndian( U16 data );
  122.  
  123. inline S16 toBigEndian( S16 data )
  124. {
  125.     return static_cast<S16>( toBigEndian( static_cast<U16>( data ) ) );
  126. }
  127.  
  128. inline U16 swapEndianness( U16 data )
  129. {
  130.     return ( ( data & 0x00ffU ) << 8 ) | ( ( data & 0xff00U ) >> 8 );
  131. }
  132.  
  133. inline S16 swapEndianness( S16 data )
  134. {
  135.     return ( ( data & 0x00ffU ) << 8 ) | ( ( data & 0xff00U ) >> 8 );
  136. }
  137.  
  138. U32 toLittleEndian( U32 data );
  139.  
  140. inline S32 toLittleEndian( S32 data )
  141. {
  142.     return static_cast<S32>( toLittleEndian( static_cast<U32>( data ) ) );
  143. }
  144.  
  145. U32 toBigEndian( U32 data );
  146.  
  147. inline S32 toBigEndian( S32 data )
  148. {
  149.     return static_cast<S32>( toBigEndian( static_cast<U32>( data ) ) );
  150. }
  151.  
  152. inline U32 swapEndianness( U32 data )
  153. {
  154.     return ( ( data & 0x000000ffU ) << 24 ) | ( ( data & 0x0000ff00U ) <<  8 ) |
  155.         ( ( data & 0x00ff0000U ) >>  8 ) | ( ( data & 0xff000000U ) >> 24 );
  156. }
  157.  
  158. inline S32 swapEndianness( S32 data )
  159. {
  160.     return ( ( data & 0x000000ffU ) << 24 ) | ( ( data & 0x0000ff00U ) <<  8 ) |
  161.         ( ( data & 0x00ff0000U ) >>  8 ) | ( ( data & 0xff000000U ) >> 24 );
  162. }
  163.  
  164. } // namespace wvWare
  165.  
  166. #endif // GLOBAL_H
  167.