1 /*
2  * $Id: byte_swap.c,v 1.2 2001/06/14 18:16:14 ura Exp $
3  */
4 
5 /*
6  * FreeWnn is a network-extensible Kana-to-Kanji conversion system.
7  * This file is part of FreeWnn.
8  *
9  * Copyright OMRON Corporation. 1987, 1988, 1989, 1990, 1991, 1992, 1999
10  * Copyright 1991, 1992 by Massachusetts Institute of Technology
11  *
12  * Author: OMRON SOFTWARE Co., Ltd. <freewnn@rd.kyoto.omronsoft.co.jp>
13  *
14  * This program is free software; you can redistribute it and/or modify
15  * it under the terms of the GNU General Public License as published by
16  * the Free Software Foundation; either version 2, or (at your option)
17  * any later version.
18  *
19  * This program is distributed in the hope that it will be useful,
20  * but WITHOUT ANY WARRANTY; without even the implied warranty of
21  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
22  * GNU General Public License for more details.
23  *
24  * You should have received a copy of the GNU General Public License
25  * along with GNU Emacs; see the file COPYING.  If not, write to the
26  * Free Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
27  *
28  * Commentary:
29  *
30  * Change log:
31  *
32  * Last modified date: 8,Feb.1999
33  *
34  * Code:
35  *
36  */
37 
38 #include "commonhd.h"
39 #include "sdefine.h"
40 #include "xim.h"
41 #include "sheader.h"
42 #include "proto.h"
43 #include "ext.h"
44 
45 unsigned long
byteswap_l(l)46 byteswap_l (l)
47      unsigned long l;
48 {
49   return (((l & 0xff) << 24) | ((l & 0xff00) << 8) | ((l & 0xff0000) >> 8) | ((l >> 24) & 0xff));
50 }
51 
52 unsigned short
byteswap_s(s)53 byteswap_s (s)
54      unsigned short s;
55 {
56   return (((s & 0xff) << 8) | ((s >> 8) & 0xff));
57 }
58 
59 void
byteswap_xevent(ev)60 byteswap_xevent (ev)
61      register XKeyEvent *ev;
62 {
63   ev->type = byteswap_l (ev->type);
64   ev->serial = byteswap_l (ev->serial);
65   ev->window = byteswap_l (ev->window);
66   ev->root = byteswap_l (ev->root);
67   ev->subwindow = byteswap_l (ev->subwindow);
68   ev->time = byteswap_l (ev->time);
69   ev->x_root = byteswap_l (ev->x_root);
70   ev->y_root = byteswap_l (ev->y_root);
71   ev->x = byteswap_l (ev->x);
72   ev->y = byteswap_l (ev->y);
73   ev->state = byteswap_l (ev->state);
74   ev->keycode = byteswap_l (ev->keycode);
75 }
76 
77 void
byteswap_GetIMReply(p)78 byteswap_GetIMReply (p)
79      register ximGetIMReply *p;
80 {
81   p->state = byteswap_s (p->state);
82   p->num_styles = byteswap_s (p->num_styles);
83   p->nbytes = byteswap_s (p->nbytes);
84 }
85 
86 void
byteswap_CreateICReply(p)87 byteswap_CreateICReply (p)
88      register ximCreateICReply *p;
89 {
90   p->state = byteswap_s (p->state);
91   p->detail = byteswap_s (p->detail);
92   p->xic = byteswap_l (p->xic);
93 }
94 
95 void
byteswap_NormalReply(p)96 byteswap_NormalReply (p)
97      register ximNormalReply *p;
98 {
99   p->state = byteswap_s (p->state);
100   p->detail = byteswap_s (p->detail);
101 }
102 
103 void
byteswap_GetICReply(p)104 byteswap_GetICReply (p)
105      register ximGetICReply *p;
106 {
107   p->state = byteswap_s (p->state);
108   p->detail = byteswap_s (p->detail);
109 }
110 
111 void
byteswap_ICValuesReq(p)112 byteswap_ICValuesReq (p)
113      register ximICValuesReq *p;
114 {
115   p->mask = byteswap_l (p->mask);
116   p->input_style = byteswap_l (p->input_style);
117   p->c_window = byteswap_l (p->c_window);
118   p->focus_window = byteswap_l (p->focus_window);
119   p->filter_events = byteswap_l (p->filter_events);
120   p->max_keycode = byteswap_l (p->max_keycode);
121   p->nbytes = byteswap_s (p->nbytes);
122   p->nbytes2 = byteswap_s (p->nbytes2);
123 }
124 
125 void
byteswap_ICAttributesReq(p)126 byteswap_ICAttributesReq (p)
127      register ximICAttributesReq *p;
128 {
129   p->area_x = byteswap_s (p->area_x);
130   p->area_y = byteswap_s (p->area_y);
131   p->area_width = byteswap_s (p->area_width);
132   p->area_height = byteswap_s (p->area_height);
133   p->areaneeded_width = byteswap_s (p->areaneeded_width);
134   p->areaneeded_height = byteswap_s (p->areaneeded_height);
135   p->spot_x = byteswap_s (p->spot_x);
136   p->spot_y = byteswap_s (p->spot_y);
137   p->colormap = byteswap_l (p->colormap);
138   p->std_colormap = byteswap_l (p->std_colormap);
139   p->foreground = byteswap_l (p->foreground);
140   p->background = byteswap_l (p->background);
141   p->pixmap = byteswap_l (p->pixmap);
142   p->line_space = byteswap_s (p->line_space);
143   p->cursor = byteswap_l (p->cursor);
144   p->nfonts = byteswap_s (p->nfonts);
145   p->nbytes = byteswap_s (p->nbytes);
146 }
147 
148 void
byteswap_EventReply(p)149 byteswap_EventReply (p)
150      register ximEventReply *p;
151 {
152   p->state = byteswap_s (p->state);
153   p->detail = byteswap_s (p->detail);
154   p->number = byteswap_s (p->number);
155 }
156 
157 void
byteswap_ReturnReply(p)158 byteswap_ReturnReply (p)
159      register ximReturnReply *p;
160 {
161   p->type = byteswap_s (p->type);
162   p->length = byteswap_s (p->length);
163   p->keysym = byteswap_l (p->keysym);
164 }
165 
166 #ifdef  CALLBACKS
167 void
byteswap_StatusDrawReply(p)168 byteswap_StatusDrawReply (p)
169      register ximStatusDrawReply *p;
170 {
171   p->type = byteswap_s (p->type);
172   p->encoding_is_wchar = byteswap_s (p->encoding_is_wchar);
173   p->length = byteswap_s (p->length);
174   p->feedback = byteswap_s (p->feedback);
175   p->bitmap = byteswap_l (p->bitmap);
176 }
177 
178 void
byteswap_PreDrawReply(p)179 byteswap_PreDrawReply (p)
180      register ximPreDrawReply *p;
181 {
182   p->caret = byteswap_s (p->caret);
183   p->chg_first = byteswap_s (p->chg_first);
184   p->chg_length = byteswap_s (p->chg_length);
185   p->encoding_is_wchar = byteswap_s (p->encoding_is_wchar);
186   p->length = byteswap_s (p->length);
187   p->feedback = byteswap_l (p->feedback);
188 }
189 
190 void
byteswap_PreCaretReply(p)191 byteswap_PreCaretReply (p)
192      register ximPreCaretReply *p;
193 {
194   p->position = byteswap_s (p->position);
195   p->direction = byteswap_s (p->direction);
196   p->style = byteswap_s (p->style);
197 }
198 #endif /* CALLBACKS */
199