1 /* # skkinput (Simple Kana-Kanji Input)
2 *
3 * This file is part of skkinput.
4 * Copyright (C) 2002
5 * Takashi SAKAMOTO (PXG01715@nifty.ne.jp)
6 *
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 2, or (at your option)
10 * any later version.
11 *
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with skkinput; see the file COPYING. If not, write to
19 * the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
20 */
21 #if !defined (XIMData_h)
22 #define XIMData_h
23
24 #include "XIMProtocol.h"
25
26 typedef struct {
27 const CARD8* m_pData ;
28 const CARD8* m_pHead ;
29 Boolean m_fBigEndian ;
30 } XIMData ;
31
32 static inline void
XIMData_Initialize(register XIMData * pThis,register const CARD8 * pData,register Boolean fEndian)33 XIMData_Initialize (
34 register XIMData* pThis,
35 register const CARD8* pData,
36 register Boolean fEndian)
37 {
38 assert (pThis != NULL) ;
39 pThis->m_pData = pData ;
40 pThis->m_pHead = pData ;
41 pThis->m_fBigEndian = fEndian ;
42 return ;
43 }
44
45 static inline void
XIMData_SetEndian(register XIMData * pThis,register Boolean fEndian)46 XIMData_SetEndian (
47 register XIMData* pThis,
48 register Boolean fEndian)
49 {
50 assert (pThis != NULL) ;
51 pThis->m_fBigEndian = fEndian ;
52 return ;
53 }
54
55 static inline const CARD8*
XIMData_GetHead(register XIMData * pThis)56 XIMData_GetHead (
57 register XIMData* pThis)
58 {
59 assert (pThis != NULL) ;
60 return pThis->m_pHead ;
61 }
62
63 static inline CARD8
XIMData_GetCard8(register XIMData * pThis)64 XIMData_GetCard8 (
65 register XIMData* pThis)
66 {
67 register CARD8 c8Value ;
68
69 c8Value = pThis->m_pHead [0] ;
70 pThis->m_pHead ++ ;
71 return c8Value ;
72 }
73
74 static inline CARD16
XIMData_GetCard16(register XIMData * pThis)75 XIMData_GetCard16 (
76 register XIMData* pThis)
77 {
78 register CARD16 c16Value ;
79
80 if (pThis->m_fBigEndian){
81 c16Value = ((CARD16)pThis->m_pHead [0] << 8) | pThis->m_pHead [1] ;
82 } else {
83 c16Value = ((CARD16)pThis->m_pHead [1] << 8) | pThis->m_pHead [0] ;
84 }
85 pThis->m_pHead += sizeof (CARD16) / sizeof (CARD8) ;
86 return c16Value ;
87 }
88
89 static inline CARD32
XIMData_GetCard32(register XIMData * pThis)90 XIMData_GetCard32 (
91 register XIMData* pThis)
92 {
93 register CARD32 c32Value ;
94
95 if (pThis->m_fBigEndian){
96 c32Value = (((CARD32)pThis->m_pHead [0] << 24) |
97 ((CARD32)pThis->m_pHead [1] << 16) |
98 ((CARD32)pThis->m_pHead [2] << 8) |
99 ((CARD32)pThis->m_pHead [3] << 0)) ;
100 } else {
101 c32Value = (((CARD32)pThis->m_pHead [3] << 24) |
102 ((CARD32)pThis->m_pHead [2] << 16) |
103 ((CARD32)pThis->m_pHead [1] << 8) |
104 ((CARD32)pThis->m_pHead [0] << 0)) ;
105 }
106 pThis->m_pHead += sizeof (CARD32) / sizeof (CARD8) ;
107 return c32Value ;
108 }
109
110 static inline void
XIMData_Forward8(register XIMData * pThis,register int nCount)111 XIMData_Forward8 (
112 register XIMData* pThis,
113 register int nCount)
114 {
115 pThis->m_pHead += nCount ;
116 }
117
118 static inline void
XIMData_Forward16(register XIMData * pThis,register int nCount)119 XIMData_Forward16 (
120 register XIMData* pThis,
121 register int nCount)
122 {
123 pThis->m_pHead += nCount * sizeof (CARD16) / sizeof (CARD8) ;
124 }
125
126 static inline void
XIMData_Forward32(register XIMData * pThis,register int nCount)127 XIMData_Forward32 (
128 register XIMData* pThis,
129 register int nCount)
130 {
131 pThis->m_pHead += nCount * sizeof (CARD32) / sizeof (CARD8) ;
132 }
133
134 static inline void
XIMData_Rewind(register XIMData * pThis)135 XIMData_Rewind (
136 register XIMData* pThis)
137 {
138 pThis->m_pHead = pThis->m_pData ;
139 }
140
141 #endif
142
143