Debian Codegraph @

texk/web2c/xetexdir/XeTeXswap.h

raw
1 /****************************************************************************\
2 Part of the XeTeX typesetting system
3 Copyright (c) 1994-2008 by SIL International
4 Copyright (c) 2009 by Jonathan Kew
5
6 SIL Author(s): Jonathan Kew
7
8 Permission is hereby granted, free of charge, to any person obtaining
9 a copy of this software and associated documentation files (the
10 "Software"), to deal in the Software without restriction, including
11 without limitation the rights to use, copy, modify, merge, publish,
12 distribute, sublicense, and/or sell copies of the Software, and to
13 permit persons to whom the Software is furnished to do so, subject to
14 the following conditions:
15
16 The above copyright notice and this permission notice shall be
17 included in all copies or substantial portions of the Software.
18
19 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
20 EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
21 MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
22 NONINFRINGEMENT. IN NO EVENT SHALL THE COPYRIGHT HOLDERS BE LIABLE
23 FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF
24 CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
25 WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
26
27 Except as contained in this notice, the name of the copyright holders
28 shall not be used in advertising or otherwise to promote the sale,
29 use or other dealings in this Software without prior written
30 authorization from the copyright holders.
31 \****************************************************************************/
32
33 #ifndef __XeTeXswap_H
34 #define __XeTeXswap_H
35
36 #include <unicode/platform.h> // ICU's platform.h defines U_IS_BIG_ENDIAN for us
37
38 static inline uint16_t
39 SWAP16(const uint16_t p)
40 {
41 #if U_IS_BIG_ENDIAN
42 return p;
43 #else
44 return (p >> 8) + (p << 8);
45 #endif
46 }
47
48 static inline uint32_t
49 SWAP32(const uint32_t p)
50 {
51 #if U_IS_BIG_ENDIAN
52 return p;
53 #else
54 return (p >> 24) + ((p >> 8) & 0x0000ff00) + ((p << 8) & 0x00ff0000) + (p << 24);
55 #endif
56 }
57
58 #ifdef __cplusplus
59 static inline uint16_t
60 SWAP(uint16_t p)
61 {
62 return SWAP16(p);
63 }
64
65 static inline uint32_t
66 SWAP(uint32_t p)
67 {
68 return SWAP32(p);
69 }
70
71 static inline int16_t
72 SWAP(int16_t p)
73 {
74 return (int16_t)SWAP16((uint16_t)p);
75 }
76
77 static inline int32_t
78 SWAP(int32_t p)
79 {
80 return (int32_t)SWAP32((uint32_t)p);
81 }
82 #endif
83
84 #endif