1 /************************************************************
2 
3 Copyright (c) 1987  X Consortium
4 
5 Permission is hereby granted, free of charge, to any person obtaining a copy
6 of this software and associated documentation files (the "Software"), to deal
7 in the Software without restriction, including without limitation the rights
8 to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9 copies of the Software, and to permit persons to whom the Software is
10 furnished to do so, subject to the following conditions:
11 
12 The above copyright notice and this permission notice shall be included in
13 all copies or substantial portions of the Software.
14 
15 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL THE
18 X CONSORTIUM BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
19 AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
20 CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
21 
22 Except as contained in this notice, the name of the X Consortium shall not be
23 used in advertising or otherwise to promote the sale, use or other dealings
24 in this Software without prior written authorization from the X Consortium.
25 
26 
27 Copyright 1987 by Digital Equipment Corporation, Maynard, Massachusetts.
28 
29                         All Rights Reserved
30 
31 Permission to use, copy, modify, and distribute this software and its
32 documentation for any purpose and without fee is hereby granted,
33 provided that the above copyright notice appear in all copies and that
34 both that copyright notice and this permission notice appear in
35 supporting documentation, and that the name of Digital not be
36 used in advertising or publicity pertaining to distribution of the
37 software without specific, written prior permission.
38 
39 DIGITAL DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING
40 ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL
41 DIGITAL BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR
42 ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
43 WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,
44 ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
45 SOFTWARE.
46 
47 ********************************************************/
48 
49 /* $XConsortium: swaprep.c /main/25 1995/12/08 13:39:45 dpw $ */
50 /* $XFree86: xc/programs/Xserver/dix/swaprep.c,v 3.2 1996/04/15 11:19:58 dawes Exp $ */
51 
52 #include "X.h"
53 #define NEED_REPLIES
54 #define NEED_EVENTS
55 #include "Xproto.h"
56 #include "misc.h"
57 #include "dixstruct.h"
58 #include "fontstruct.h"
59 #include "scrnintstr.h"
60 #include "swaprep.h"
61 
62 static void SwapFontInfo(
63 #if NeedFunctionPrototypes
64     xQueryFontReply * /* pr */
65 #endif
66 );
67 
68 #ifndef LBX
69 static void SwapCharInfo(
70 #if NeedFunctionPrototypes
71     xCharInfo * /* pInfo */
72 #endif
73     );
74 
75 static void SwapFont(
76 #if NeedFunctionPrototypes
77     xQueryFontReply * /* pr */,
78     Bool /* hasGlyphs */
79 #endif
80     );
81 #endif
82 
83 /* Thanks to Jack Palevich for testing and subsequently rewriting all this */
84 void
Swap32Write(pClient,size,pbuf)85 Swap32Write(pClient, size, pbuf)
86     ClientPtr	pClient;
87     int		size;  /* in bytes */
88     register CARD32 *pbuf;
89 {
90     register int i;
91     register char n;
92 
93     size >>= 2;
94     for(i = 0; i < size; i++)
95     /* brackets are mandatory here, because "swapl" macro expands
96        to several statements */
97     {
98 	swapl(&pbuf[i], n);
99     }
100     (void)WriteToClient(pClient, size << 2, (char *) pbuf);
101 }
102 
103 void
CopySwap32Write(pClient,size,pbuf)104 CopySwap32Write(pClient, size, pbuf)
105     ClientPtr	pClient;
106     int		size;   /* in bytes */
107     CARD32	*pbuf;
108 {
109     int bufsize = size;
110     CARD32 *pbufT;
111     register CARD32 *from, *to, *fromLast, *toLast;
112     CARD32 tmpbuf[1];
113 
114     /* Allocate as big a buffer as we can... */
115     while (!(pbufT = (CARD32 *) ALLOCATE_LOCAL(bufsize)))
116     {
117         bufsize >>= 1;
118 	if (bufsize == 4)
119 	{
120 	    pbufT = tmpbuf;
121 	    break;
122 	}
123     }
124 
125     /* convert lengths from # of bytes to # of longs */
126     size >>= 2;
127     bufsize >>= 2;
128 
129     from = pbuf;
130     fromLast = from + size;
131     while (from < fromLast) {
132 	int nbytes;
133         to = pbufT;
134         toLast = to + min (bufsize, fromLast - from);
135         nbytes = (toLast - to) << 2;
136         while (to < toLast) {
137             /* can't write "cpswapl(*from++, *to++)" because cpswapl is a macro
138 	       that evaulates its args more than once */
139 	    cpswapl(*from, *to);
140             from++;
141             to++;
142 	    }
143 	(void)WriteToClient (pClient, nbytes, (char *) pbufT);
144 	}
145 
146     if (pbufT != tmpbuf)
147 	DEALLOCATE_LOCAL ((char *) pbufT);
148 }
149 
150 void
CopySwap16Write(pClient,size,pbuf)151 CopySwap16Write(pClient, size, pbuf)
152     ClientPtr	pClient;
153     int		size;   /* in bytes */
154     short	*pbuf;
155 {
156     int bufsize = size;
157     short *pbufT;
158     register short *from, *to, *fromLast, *toLast;
159     short tmpbuf[2];
160 
161     /* Allocate as big a buffer as we can... */
162     while (!(pbufT = (short *) ALLOCATE_LOCAL(bufsize)))
163     {
164         bufsize >>= 1;
165 	if (bufsize == 4)
166 	{
167 	    pbufT = tmpbuf;
168 	    break;
169 	}
170     }
171 
172     /* convert lengths from # of bytes to # of shorts */
173     size >>= 1;
174     bufsize >>= 1;
175 
176     from = pbuf;
177     fromLast = from + size;
178     while (from < fromLast) {
179 	int nbytes;
180         to = pbufT;
181         toLast = to + min (bufsize, fromLast - from);
182         nbytes = (toLast - to) << 1;
183         while (to < toLast) {
184             /* can't write "cpswaps(*from++, *to++)" because cpswaps is a macro
185 	       that evaulates its args more than once */
186 	    cpswaps(*from, *to);
187             from++;
188             to++;
189 	    }
190 	(void)WriteToClient (pClient, nbytes, (char *) pbufT);
191 	}
192 
193     if (pbufT != tmpbuf)
194 	DEALLOCATE_LOCAL ((char *) pbufT);
195 }
196 
197 
198 /* Extra-small reply */
199 void
SGenericReply(pClient,size,pRep)200 SGenericReply(pClient, size, pRep)
201     ClientPtr			pClient;
202     int				size;
203     xGenericReply		*pRep;
204 {
205     register char n;
206 
207     swaps(&pRep->sequenceNumber, n);
208     (void)WriteToClient(pClient, size, (char *) pRep);
209 }
210 
211 /* Extra-large reply */
212 void
SGetWindowAttributesReply(pClient,size,pRep)213 SGetWindowAttributesReply(pClient, size, pRep)
214     ClientPtr			pClient;
215     int				size;
216     xGetWindowAttributesReply	*pRep;
217 {
218     register char n;
219 
220     swaps(&pRep->sequenceNumber, n);
221     swapl(&pRep->length, n);
222     swapl(&pRep->visualID, n);
223     swaps(&pRep->class, n);
224     swapl(&pRep->backingBitPlanes, n);
225     swapl(&pRep->backingPixel, n);
226     swapl(&pRep->colormap, n);
227     swapl(&pRep->allEventMasks, n);
228     swapl(&pRep->yourEventMask, n);
229     swaps(&pRep->doNotPropagateMask, n);
230     (void)WriteToClient(pClient, size, (char *) pRep);
231 }
232 
233 void
SGetGeometryReply(pClient,size,pRep)234 SGetGeometryReply(pClient, size, pRep)
235     ClientPtr		pClient;
236     int			size;
237     xGetGeometryReply	*pRep;
238 {
239     register char n;
240 
241     swaps(&pRep->sequenceNumber, n);
242     swapl(&pRep->root, n);
243     swaps(&pRep->x, n);
244     swaps(&pRep->y, n);
245     swaps(&pRep->width, n);
246     swaps(&pRep->height, n);
247     swaps(&pRep->borderWidth, n);
248     (void)WriteToClient(pClient, size, (char *) pRep);
249 }
250 
251 void
SQueryTreeReply(pClient,size,pRep)252 SQueryTreeReply(pClient, size, pRep)
253     ClientPtr		pClient;
254     int			size;
255     xQueryTreeReply	*pRep;
256 {
257     register char n;
258 
259     swaps(&pRep->sequenceNumber, n);
260     swapl(&pRep->length, n);
261     swapl(&pRep->root, n);
262     swapl(&pRep->parent, n);
263     swaps(&pRep->nChildren, n);
264     (void)WriteToClient(pClient, size, (char *) pRep);
265 }
266 
267 void
SInternAtomReply(pClient,size,pRep)268 SInternAtomReply(pClient, size, pRep)
269     ClientPtr		pClient;
270     int			size;
271     xInternAtomReply	*pRep;
272 {
273     register char n;
274 
275     swaps(&pRep->sequenceNumber, n);
276     swapl(&pRep->atom, n);
277     (void)WriteToClient(pClient, size, (char *) pRep);
278 }
279 
280 void
SGetAtomNameReply(pClient,size,pRep)281 SGetAtomNameReply(pClient, size, pRep)
282     ClientPtr			pClient;
283     int				size;
284     xGetAtomNameReply	*pRep;
285 {
286     register char n;
287 
288     swaps(&pRep->sequenceNumber, n);
289     swapl(&pRep->length, n);
290     swaps(&pRep->nameLength, n);
291     (void)WriteToClient(pClient, size, (char *) pRep);
292 }
293 
294 
295 void
SGetPropertyReply(pClient,size,pRep)296 SGetPropertyReply(pClient, size, pRep)
297     ClientPtr			pClient;
298     int				size;
299     xGetPropertyReply	*pRep;
300 {
301     register char n;
302 
303     swaps(&pRep->sequenceNumber, n);
304     swapl(&pRep->length, n);
305     swapl(&pRep->propertyType, n);
306     swapl(&pRep->bytesAfter, n);
307     swapl(&pRep->nItems, n);
308     (void)WriteToClient(pClient, size, (char *) pRep);
309 }
310 
311 void
SListPropertiesReply(pClient,size,pRep)312 SListPropertiesReply(pClient, size, pRep)
313     ClientPtr			pClient;
314     int				size;
315     xListPropertiesReply	*pRep;
316 {
317     register char n;
318 
319     swaps(&pRep->sequenceNumber, n);
320     swapl(&pRep->length, n);
321     swaps(&pRep->nProperties, n);
322     (void)WriteToClient(pClient, size, (char *) pRep);
323 }
324 
325 void
SGetSelectionOwnerReply(pClient,size,pRep)326 SGetSelectionOwnerReply(pClient, size, pRep)
327     ClientPtr			pClient;
328     int				size;
329     xGetSelectionOwnerReply	*pRep;
330 {
331     register char n;
332 
333     swaps(&pRep->sequenceNumber, n);
334     swapl(&pRep->owner, n);
335     (void)WriteToClient(pClient, size, (char *) pRep);
336 }
337 
338 
339 void
SQueryPointerReply(pClient,size,pRep)340 SQueryPointerReply(pClient, size, pRep)
341     ClientPtr		pClient;
342     int			size;
343     xQueryPointerReply	*pRep;
344 {
345     register char n;
346 
347     swaps(&pRep->sequenceNumber, n);
348     swapl(&pRep->root, n);
349     swapl(&pRep->child, n);
350     swaps(&pRep->rootX, n);
351     swaps(&pRep->rootY, n);
352     swaps(&pRep->winX, n);
353     swaps(&pRep->winY, n);
354     swaps(&pRep->mask, n);
355     (void)WriteToClient(pClient, size, (char *) pRep);
356 }
357 
358 void
SwapTimecoord(pCoord)359 SwapTimecoord(pCoord)
360     xTimecoord *pCoord;
361 {
362     register char n;
363 
364     swapl(&pCoord->time, n);
365     swaps(&pCoord->x, n);
366     swaps(&pCoord->y, n);
367 }
368 
369 void
SwapTimeCoordWrite(pClient,size,pRep)370 SwapTimeCoordWrite(pClient, size, pRep)
371     ClientPtr			pClient;
372     int				size;
373     xTimecoord			*pRep;
374 {
375     int	i, n;
376     xTimecoord			*pRepT;
377 
378     n = size / sizeof(xTimecoord);
379     pRepT = pRep;
380     for(i = 0; i < n; i++)
381     {
382 	SwapTimecoord(pRepT);
383 	pRepT++;
384     }
385     (void)WriteToClient(pClient, size, (char *) pRep);
386 
387 }
388 void
SGetMotionEventsReply(pClient,size,pRep)389 SGetMotionEventsReply(pClient, size, pRep)
390     ClientPtr			pClient;
391     int				size;
392     xGetMotionEventsReply	*pRep;
393 {
394     register char n;
395 
396     swaps(&pRep->sequenceNumber, n);
397     swapl(&pRep->length, n);
398     swapl(&pRep->nEvents, n);
399     (void)WriteToClient(pClient, size, (char *) pRep);
400 }
401 
402 void
STranslateCoordsReply(pClient,size,pRep)403 STranslateCoordsReply(pClient, size, pRep)
404     ClientPtr			pClient;
405     int				size;
406     xTranslateCoordsReply	*pRep;
407 {
408     register char n;
409 
410     swaps(&pRep->sequenceNumber, n);
411     swapl(&pRep->child, n);
412     swaps(&pRep->dstX, n);
413     swaps(&pRep->dstY, n);
414     (void)WriteToClient(pClient, size, (char *) pRep);
415 }
416 
417 void
SGetInputFocusReply(pClient,size,pRep)418 SGetInputFocusReply(pClient, size, pRep)
419     ClientPtr		pClient;
420     int			size;
421     xGetInputFocusReply	*pRep;
422 {
423     register char n;
424 
425     swaps(&pRep->sequenceNumber, n);
426     swapl(&pRep->focus, n);
427     (void)WriteToClient(pClient, size, (char *) pRep);
428 }
429 
430 /* extra long reply */
431 void
SQueryKeymapReply(pClient,size,pRep)432 SQueryKeymapReply(pClient, size, pRep)
433     ClientPtr			pClient;
434     int				size;
435     xQueryKeymapReply	*pRep;
436 {
437     register char n;
438 
439     swaps(&pRep->sequenceNumber, n);
440     swapl(&pRep->length, n);
441     (void)WriteToClient(pClient, size, (char *) pRep);
442 }
443 
444 #ifndef LBX
445 static
446 #endif
447 void
SwapCharInfo(pInfo)448 SwapCharInfo(pInfo)
449     xCharInfo	*pInfo;
450 {
451     register char n;
452 
453     swaps(&pInfo->leftSideBearing, n);
454     swaps(&pInfo->rightSideBearing, n);
455     swaps(&pInfo->characterWidth, n);
456     swaps(&pInfo->ascent, n);
457     swaps(&pInfo->descent, n);
458     swaps(&pInfo->attributes, n);
459 }
460 
461 static void
SwapFontInfo(pr)462 SwapFontInfo(pr)
463     xQueryFontReply *pr;
464 {
465     register char		n;
466 
467     swaps(&pr->minCharOrByte2, n);
468     swaps(&pr->maxCharOrByte2, n);
469     swaps(&pr->defaultChar, n);
470     swaps(&pr->nFontProps, n);
471     swaps(&pr->fontAscent, n);
472     swaps(&pr->fontDescent, n);
473     SwapCharInfo( &pr->minBounds);
474     SwapCharInfo( &pr->maxBounds);
475     swapl(&pr->nCharInfos, n);
476 }
477 
478 #ifndef LBX
479 static
480 #endif
481 void
SwapFont(pr,hasGlyphs)482 SwapFont( pr, hasGlyphs)
483     xQueryFontReply *	pr;
484     Bool hasGlyphs;
485 {
486     unsigned	i;
487     xCharInfo *	pxci;
488     unsigned	nchars, nprops;
489     char	*pby;
490     register char n;
491 
492     swaps(&pr->sequenceNumber, n);
493     swapl(&pr->length, n);
494     nchars = pr->nCharInfos;
495     nprops = pr->nFontProps;
496     SwapFontInfo(pr);
497     pby = (char *) &pr[1];
498     /* Font properties are an atom and either an int32 or a CARD32, so
499      * they are always 2 4 byte values */
500     for(i = 0; i < nprops; i++)
501     {
502 	swapl(pby, n);
503 	pby += 4;
504 	swapl(pby, n);
505 	pby += 4;
506     }
507     if (hasGlyphs)
508     {
509 	pxci = (xCharInfo *)pby;
510 	for(i = 0; i< nchars; i++, pxci++)
511 	    SwapCharInfo(pxci);
512     }
513 }
514 
515 void
SQueryFontReply(pClient,size,pRep)516 SQueryFontReply(pClient, size, pRep)
517     ClientPtr		pClient;
518     int			size;
519     xQueryFontReply	*pRep;
520 {
521     SwapFont(pRep, TRUE);
522     (void)WriteToClient(pClient, size, (char *) pRep);
523 }
524 
525 void
SQueryTextExtentsReply(pClient,size,pRep)526 SQueryTextExtentsReply(pClient, size, pRep)
527     ClientPtr			pClient;
528     int				size;
529     xQueryTextExtentsReply	*pRep;
530 {
531     register char n;
532 
533     swaps(&pRep->sequenceNumber, n);
534     swaps(&pRep->fontAscent, n);
535     swaps(&pRep->fontDescent, n);
536     swaps(&pRep->overallAscent, n);
537     swaps(&pRep->overallDescent, n);
538     swapl(&pRep->overallWidth, n);
539     swapl(&pRep->overallLeft, n);
540     swapl(&pRep->overallRight, n);
541     (void)WriteToClient(pClient, size, (char *) pRep);
542 }
543 
544 void
SListFontsReply(pClient,size,pRep)545 SListFontsReply(pClient, size, pRep)
546     ClientPtr		pClient;
547     int			size;
548     xListFontsReply	*pRep;
549 {
550     register char n;
551 
552     swaps(&pRep->sequenceNumber, n);
553     swapl(&pRep->length, n);
554     swaps(&pRep->nFonts, n);
555     (void)WriteToClient(pClient, size, (char *) pRep);
556 }
557 
558 void
SListFontsWithInfoReply(pClient,size,pRep)559 SListFontsWithInfoReply(pClient, size, pRep)
560     ClientPtr			pClient;
561     int				size;
562     xListFontsWithInfoReply	*pRep;
563 {
564     SwapFont((xQueryFontReply *)pRep, FALSE);
565     (void)WriteToClient(pClient, size, (char *) pRep);
566 }
567 
568 void
SGetFontPathReply(pClient,size,pRep)569 SGetFontPathReply(pClient, size, pRep)
570     ClientPtr		pClient;
571     int			size;
572     xGetFontPathReply	*pRep;
573 {
574     register char n;
575 
576     swaps(&pRep->sequenceNumber, n);
577     swapl(&pRep->length, n);
578     swaps(&pRep->nPaths, n);
579     (void)WriteToClient(pClient, size, (char *) pRep);
580 }
581 
582 void
SGetImageReply(pClient,size,pRep)583 SGetImageReply(pClient, size, pRep)
584     ClientPtr		pClient;
585     int			size;
586     xGetImageReply	*pRep;
587 {
588     register char n;
589 
590     swaps(&pRep->sequenceNumber, n);
591     swapl(&pRep->length, n);
592     swapl(&pRep->visual, n);
593     (void)WriteToClient(pClient, size, (char *) pRep);
594     /* Fortunately, image doesn't need swapping */
595 }
596 
597 void
SListInstalledColormapsReply(pClient,size,pRep)598 SListInstalledColormapsReply(pClient, size, pRep)
599     ClientPtr				pClient;
600     int					size;
601     xListInstalledColormapsReply	*pRep;
602 {
603     register char n;
604 
605     swaps(&pRep->sequenceNumber, n);
606     swapl(&pRep->length, n);
607     swaps(&pRep->nColormaps, n);
608     (void)WriteToClient(pClient, size, (char *) pRep);
609 }
610 
611 void
SAllocColorReply(pClient,size,pRep)612 SAllocColorReply(pClient, size, pRep)
613     ClientPtr		pClient;
614     int			size;
615     xAllocColorReply	*pRep;
616 {
617     register char n;
618 
619     swaps(&pRep->sequenceNumber, n);
620     swaps(&pRep->red, n);
621     swaps(&pRep->green, n);
622     swaps(&pRep->blue, n);
623     swapl(&pRep->pixel, n);
624     (void)WriteToClient(pClient, size, (char *) pRep);
625 }
626 
627 void
SAllocNamedColorReply(pClient,size,pRep)628 SAllocNamedColorReply(pClient, size, pRep)
629     ClientPtr			pClient;
630     int				size;
631     xAllocNamedColorReply	*pRep;
632 {
633     register char n;
634 
635     swaps(&pRep->sequenceNumber, n);
636     swapl(&pRep->pixel, n);
637     swaps(&pRep->exactRed, n);
638     swaps(&pRep->exactGreen, n);
639     swaps(&pRep->exactBlue, n);
640     swaps(&pRep->screenRed, n);
641     swaps(&pRep->screenGreen, n);
642     swaps(&pRep->screenBlue, n);
643     (void)WriteToClient(pClient, size, (char *) pRep);
644 }
645 
646 void
SAllocColorCellsReply(pClient,size,pRep)647 SAllocColorCellsReply(pClient, size, pRep)
648     ClientPtr			pClient;
649     int				size;
650     xAllocColorCellsReply	*pRep;
651 {
652     register char n;
653 
654     swaps(&pRep->sequenceNumber, n);
655     swapl(&pRep->length, n);
656     swaps(&pRep->nPixels, n);
657     swaps(&pRep->nMasks, n);
658     (void)WriteToClient(pClient, size, (char *) pRep);
659 }
660 
661 
662 void
SAllocColorPlanesReply(pClient,size,pRep)663 SAllocColorPlanesReply(pClient, size, pRep)
664     ClientPtr			pClient;
665     int				size;
666     xAllocColorPlanesReply	*pRep;
667 {
668     register char n;
669 
670     swaps(&pRep->sequenceNumber, n);
671     swapl(&pRep->length, n);
672     swaps(&pRep->nPixels, n);
673     swapl(&pRep->redMask, n);
674     swapl(&pRep->greenMask, n);
675     swapl(&pRep->blueMask, n);
676     (void)WriteToClient(pClient, size, (char *) pRep);
677 }
678 
679 void
SwapRGB(prgb)680 SwapRGB(prgb)
681     xrgb	*prgb;
682 {
683     register char n;
684 
685     swaps(&prgb->red, n);
686     swaps(&prgb->green, n);
687     swaps(&prgb->blue, n);
688 }
689 
690 void
SQColorsExtend(pClient,size,prgb)691 SQColorsExtend(pClient, size, prgb)
692     ClientPtr	pClient;
693     int		size;
694     xrgb	*prgb;
695 {
696     int		i, n;
697     xrgb	*prgbT;
698 
699     n = size / sizeof(xrgb);
700     prgbT = prgb;
701     for(i = 0; i < n; i++)
702     {
703 	SwapRGB(prgbT);
704 	prgbT++;
705     }
706     (void)WriteToClient(pClient, size, (char *) prgb);
707 }
708 
709 void
SQueryColorsReply(pClient,size,pRep)710 SQueryColorsReply(pClient, size, pRep)
711     ClientPtr		pClient;
712     int			size;
713     xQueryColorsReply	*pRep;
714 {
715     register char n;
716 
717     swaps(&pRep->sequenceNumber, n);
718     swapl(&pRep->length, n);
719     swaps(&pRep->nColors, n);
720     (void)WriteToClient(pClient, size, (char *) pRep);
721 }
722 
723 void
SLookupColorReply(pClient,size,pRep)724 SLookupColorReply(pClient, size, pRep)
725     ClientPtr		pClient;
726     int			size;
727     xLookupColorReply	*pRep;
728 {
729     register char n;
730 
731     swaps(&pRep->sequenceNumber, n);
732     swaps(&pRep->exactRed, n);
733     swaps(&pRep->exactGreen, n);
734     swaps(&pRep->exactBlue, n);
735     swaps(&pRep->screenRed, n);
736     swaps(&pRep->screenGreen, n);
737     swaps(&pRep->screenBlue, n);
738     (void)WriteToClient(pClient, size, (char *) pRep);
739 }
740 
741 void
SQueryBestSizeReply(pClient,size,pRep)742 SQueryBestSizeReply(pClient, size, pRep)
743     ClientPtr		pClient;
744     int			size;
745     xQueryBestSizeReply	*pRep;
746 {
747     register char n;
748 
749     swaps(&pRep->sequenceNumber, n);
750     swaps(&pRep->width, n);
751     swaps(&pRep->height, n);
752     (void)WriteToClient(pClient, size, (char *) pRep);
753 }
754 
755 void
SListExtensionsReply(pClient,size,pRep)756 SListExtensionsReply(pClient, size, pRep)
757     ClientPtr			pClient;
758     int				size;
759     xListExtensionsReply	*pRep;
760 {
761     register char n;
762 
763     swaps(&pRep->sequenceNumber, n);
764     swapl(&pRep->length, n);
765     (void)WriteToClient(pClient, size, (char *) pRep);
766 }
767 
768 void
SGetKeyboardMappingReply(pClient,size,pRep)769 SGetKeyboardMappingReply(pClient, size, pRep)
770     ClientPtr			pClient;
771     int				size;
772     xGetKeyboardMappingReply	*pRep;
773 {
774     register char n;
775 
776     swaps(&pRep->sequenceNumber, n);
777     swapl(&pRep->length, n);
778     (void)WriteToClient(pClient, size, (char *) pRep);
779 }
780 
781 void
SGetPointerMappingReply(pClient,size,pRep)782 SGetPointerMappingReply(pClient, size, pRep)
783     ClientPtr			pClient;
784     int				size;
785     xGetPointerMappingReply	*pRep;
786 {
787     register char n;
788 
789     swaps(&pRep->sequenceNumber, n);
790     swapl(&pRep->length, n);
791     (void)WriteToClient(pClient, size, (char *) pRep);
792 }
793 
794 void
SGetModifierMappingReply(pClient,size,pRep)795 SGetModifierMappingReply(pClient, size, pRep)
796     ClientPtr			pClient;
797     int				size;
798     xGetModifierMappingReply	*pRep;
799 {
800     register char n;
801 
802     swaps(&pRep->sequenceNumber, n);
803     swapl(&pRep->length, n);
804     (void)WriteToClient(pClient, size, (char *) pRep);
805 }
806 
807 void
SGetKeyboardControlReply(pClient,size,pRep)808 SGetKeyboardControlReply(pClient, size, pRep)
809     ClientPtr			pClient;
810     int				size;
811     xGetKeyboardControlReply	*pRep;
812 {
813     register char n;
814 
815     swaps(&pRep->sequenceNumber, n);
816     swapl(&pRep->length, n);
817     swapl(&pRep->ledMask, n);
818     swaps(&pRep->bellPitch, n);
819     swaps(&pRep->bellDuration, n);
820     (void)WriteToClient(pClient, size, (char *) pRep);
821 }
822 
823 void
SGetPointerControlReply(pClient,size,pRep)824 SGetPointerControlReply(pClient, size, pRep)
825     ClientPtr			pClient;
826     int				size;
827     xGetPointerControlReply	*pRep;
828 {
829     register char n;
830 
831     swaps(&pRep->sequenceNumber, n);
832     swaps(&pRep->accelNumerator, n);
833     swaps(&pRep->accelDenominator, n);
834     swaps(&pRep->threshold, n);
835     (void)WriteToClient(pClient, size, (char *) pRep);
836 }
837 
838 void
SGetScreenSaverReply(pClient,size,pRep)839 SGetScreenSaverReply(pClient, size, pRep)
840     ClientPtr			pClient;
841     int				size;
842     xGetScreenSaverReply	*pRep;
843 {
844     register char n;
845 
846     swaps(&pRep->sequenceNumber, n);
847     swaps(&pRep->timeout, n);
848     swaps(&pRep->interval, n);
849     (void)WriteToClient(pClient, size, (char *) pRep);
850 }
851 
852 void
SLHostsExtend(pClient,size,buf)853 SLHostsExtend(pClient, size, buf)
854     ClientPtr		pClient;
855     int			size;
856     char		*buf;
857 {
858     char *bufT = buf;
859     char *endbuf = buf + size;
860     while (bufT < endbuf) {
861 	xHostEntry *host = (xHostEntry *) bufT;
862 	int len = host->length;
863         register char n;
864 	swaps (&host->length, n);
865 	bufT += sizeof (xHostEntry) + (((len + 3) >> 2) << 2);
866 	}
867     (void)WriteToClient (pClient, size, buf);
868 }
869 
870 void
SListHostsReply(pClient,size,pRep)871 SListHostsReply(pClient, size, pRep)
872     ClientPtr		pClient;
873     int			size;
874     xListHostsReply	*pRep;
875 {
876     register char n;
877 
878     swaps(&pRep->sequenceNumber, n);
879     swapl(&pRep->length, n);
880     swaps(&pRep->nHosts, n);
881     (void)WriteToClient(pClient, size, (char *) pRep);
882 }
883 
884 
885 
886 void
SErrorEvent(from,to)887 SErrorEvent(from, to)
888     xError	*from, *to;
889 {
890     to->type = X_Error;
891     to->errorCode = from->errorCode;
892     cpswaps(from->sequenceNumber, to->sequenceNumber);
893     cpswapl(from->resourceID, to->resourceID);
894     cpswaps(from->minorCode, to->minorCode);
895     to->majorCode = from->majorCode;
896 }
897 
898 void
SKeyButtonPtrEvent(from,to)899 SKeyButtonPtrEvent(from, to)
900     xEvent	*from, *to;
901 {
902     to->u.u.type = from->u.u.type;
903     to->u.u.detail = from->u.u.detail;
904     cpswaps(from->u.u.sequenceNumber, to->u.u.sequenceNumber);
905     cpswapl(from->u.keyButtonPointer.time,
906         to->u.keyButtonPointer.time);
907     cpswapl(from->u.keyButtonPointer.root,
908         to->u.keyButtonPointer.root);
909     cpswapl(from->u.keyButtonPointer.event,
910         to->u.keyButtonPointer.event);
911     cpswapl(from->u.keyButtonPointer.child,
912         to->u.keyButtonPointer.child);
913     cpswaps(from->u.keyButtonPointer.rootX,
914         to->u.keyButtonPointer.rootX);
915     cpswaps(from->u.keyButtonPointer.rootY,
916 	to->u.keyButtonPointer.rootY);
917     cpswaps(from->u.keyButtonPointer.eventX,
918         to->u.keyButtonPointer.eventX);
919     cpswaps(from->u.keyButtonPointer.eventY,
920         to->u.keyButtonPointer.eventY);
921     cpswaps(from->u.keyButtonPointer.state,
922         to->u.keyButtonPointer.state);
923     to->u.keyButtonPointer.sameScreen =
924 	from->u.keyButtonPointer.sameScreen;
925 }
926 
927 void
SEnterLeaveEvent(from,to)928 SEnterLeaveEvent(from, to)
929     xEvent	*from, *to;
930 {
931     to->u.u.type = from->u.u.type;
932     to->u.u.detail = from->u.u.detail;
933     cpswaps(from->u.u.sequenceNumber, to->u.u.sequenceNumber);
934     cpswapl(from->u.enterLeave.time, to->u.enterLeave.time);
935     cpswapl(from->u.enterLeave.root, to->u.enterLeave.root);
936     cpswapl(from->u.enterLeave.event, to->u.enterLeave.event);
937     cpswapl(from->u.enterLeave.child, to->u.enterLeave.child);
938     cpswaps(from->u.enterLeave.rootX, to->u.enterLeave.rootX);
939     cpswaps(from->u.enterLeave.rootY, to->u.enterLeave.rootY);
940     cpswaps(from->u.enterLeave.eventX, to->u.enterLeave.eventX);
941     cpswaps(from->u.enterLeave.eventY, to->u.enterLeave.eventY);
942     cpswaps(from->u.enterLeave.state, to->u.enterLeave.state);
943     to->u.enterLeave.mode = from->u.enterLeave.mode;
944     to->u.enterLeave.flags = from->u.enterLeave.flags;
945 }
946 
947 void
SFocusEvent(from,to)948 SFocusEvent(from, to)
949     xEvent	*from, *to;
950 {
951     to->u.u.type = from->u.u.type;
952     to->u.u.detail = from->u.u.detail;
953     cpswaps(from->u.u.sequenceNumber, to->u.u.sequenceNumber);
954     cpswapl(from->u.focus.window, to->u.focus.window);
955     to->u.focus.mode = from->u.focus.mode;
956 }
957 
958 void
SExposeEvent(from,to)959 SExposeEvent(from, to)
960     xEvent	*from, *to;
961 {
962     to->u.u.type = from->u.u.type;
963     cpswaps(from->u.u.sequenceNumber, to->u.u.sequenceNumber);
964     cpswapl(from->u.expose.window, to->u.expose.window);
965     cpswaps(from->u.expose.x, to->u.expose.x);
966     cpswaps(from->u.expose.y, to->u.expose.y);
967     cpswaps(from->u.expose.width, to->u.expose.width);
968     cpswaps(from->u.expose.height, to->u.expose.height);
969     cpswaps(from->u.expose.count, to->u.expose.count);
970 }
971 
972 void
SGraphicsExposureEvent(from,to)973 SGraphicsExposureEvent(from, to)
974     xEvent	*from, *to;
975 {
976     to->u.u.type = from->u.u.type;
977     cpswaps(from->u.u.sequenceNumber, to->u.u.sequenceNumber);
978     cpswapl(from->u.graphicsExposure.drawable,
979         to->u.graphicsExposure.drawable);
980     cpswaps(from->u.graphicsExposure.x,
981 	to->u.graphicsExposure.x);
982     cpswaps(from->u.graphicsExposure.y,
983 	to->u.graphicsExposure.y);
984     cpswaps(from->u.graphicsExposure.width,
985 	to->u.graphicsExposure.width);
986     cpswaps(from->u.graphicsExposure.height,
987 	to->u.graphicsExposure.height);
988     cpswaps(from->u.graphicsExposure.minorEvent,
989         to->u.graphicsExposure.minorEvent);
990     cpswaps(from->u.graphicsExposure.count,
991 	to->u.graphicsExposure.count);
992     to->u.graphicsExposure.majorEvent =
993     	from->u.graphicsExposure.majorEvent;
994 }
995 
996 void
SNoExposureEvent(from,to)997 SNoExposureEvent(from, to)
998     xEvent	*from, *to;
999 {
1000     to->u.u.type = from->u.u.type;
1001     cpswaps(from->u.u.sequenceNumber, to->u.u.sequenceNumber);
1002     cpswapl(from->u.noExposure.drawable, to->u.noExposure.drawable);
1003     cpswaps(from->u.noExposure.minorEvent, to->u.noExposure.minorEvent);
1004     to->u.noExposure.majorEvent = from->u.noExposure.majorEvent;
1005 }
1006 
1007 void
SVisibilityEvent(from,to)1008 SVisibilityEvent(from, to)
1009     xEvent	*from, *to;
1010 {
1011     to->u.u.type = from->u.u.type;
1012     cpswaps(from->u.u.sequenceNumber, to->u.u.sequenceNumber);
1013     cpswapl(from->u.visibility.window, to->u.visibility.window);
1014     to->u.visibility.state = from->u.visibility.state;
1015 }
1016 
1017 void
SCreateNotifyEvent(from,to)1018 SCreateNotifyEvent(from, to)
1019     xEvent	*from, *to;
1020 {
1021     to->u.u.type = from->u.u.type;
1022     cpswaps(from->u.u.sequenceNumber, to->u.u.sequenceNumber);
1023     cpswapl(from->u.createNotify.window, to->u.createNotify.window);
1024     cpswapl(from->u.createNotify.parent, to->u.createNotify.parent);
1025     cpswaps(from->u.createNotify.x, to->u.createNotify.x);
1026     cpswaps(from->u.createNotify.y, to->u.createNotify.y);
1027     cpswaps(from->u.createNotify.width, to->u.createNotify.width);
1028     cpswaps(from->u.createNotify.height, to->u.createNotify.height);
1029     cpswaps(from->u.createNotify.borderWidth,
1030         to->u.createNotify.borderWidth);
1031     to->u.createNotify.override = from->u.createNotify.override;
1032 }
1033 
1034 void
SDestroyNotifyEvent(from,to)1035 SDestroyNotifyEvent(from, to)
1036     xEvent	*from, *to;
1037 {
1038     to->u.u.type = from->u.u.type;
1039     cpswaps(from->u.u.sequenceNumber, to->u.u.sequenceNumber);
1040     cpswapl(from->u.destroyNotify.event, to->u.destroyNotify.event);
1041     cpswapl(from->u.destroyNotify.window, to->u.destroyNotify.window);
1042 }
1043 
1044 void
SUnmapNotifyEvent(from,to)1045 SUnmapNotifyEvent(from, to)
1046     xEvent	*from, *to;
1047 {
1048     to->u.u.type = from->u.u.type;
1049     cpswaps(from->u.u.sequenceNumber, to->u.u.sequenceNumber);
1050     cpswapl(from->u.unmapNotify.event, to->u.unmapNotify.event);
1051     cpswapl(from->u.unmapNotify.window, to->u.unmapNotify.window);
1052     to->u.unmapNotify.fromConfigure = from->u.unmapNotify.fromConfigure;
1053 }
1054 
1055 void
SMapNotifyEvent(from,to)1056 SMapNotifyEvent(from, to)
1057     xEvent	*from, *to;
1058 {
1059     to->u.u.type = from->u.u.type;
1060     cpswaps(from->u.u.sequenceNumber, to->u.u.sequenceNumber);
1061     cpswapl(from->u.mapNotify.event, to->u.mapNotify.event);
1062     cpswapl(from->u.mapNotify.window, to->u.mapNotify.window);
1063     to->u.mapNotify.override = from->u.mapNotify.override;
1064 }
1065 
1066 void
SMapRequestEvent(from,to)1067 SMapRequestEvent(from, to)
1068     xEvent	*from, *to;
1069 {
1070     to->u.u.type = from->u.u.type;
1071     cpswaps(from->u.u.sequenceNumber, to->u.u.sequenceNumber);
1072     cpswapl(from->u.mapRequest.parent, to->u.mapRequest.parent);
1073     cpswapl(from->u.mapRequest.window, to->u.mapRequest.window);
1074 }
1075 
1076 void
SReparentEvent(from,to)1077 SReparentEvent(from, to)
1078     xEvent	*from, *to;
1079 {
1080     to->u.u.type = from->u.u.type;
1081     cpswaps(from->u.u.sequenceNumber, to->u.u.sequenceNumber);
1082     cpswapl(from->u.reparent.event, to->u.reparent.event);
1083     cpswapl(from->u.reparent.window, to->u.reparent.window);
1084     cpswapl(from->u.reparent.parent, to->u.reparent.parent);
1085     cpswaps(from->u.reparent.x, to->u.reparent.x);
1086     cpswaps(from->u.reparent.y, to->u.reparent.y);
1087     to->u.reparent.override = from->u.reparent.override;
1088 }
1089 
1090 void
SConfigureNotifyEvent(from,to)1091 SConfigureNotifyEvent(from, to)
1092     xEvent	*from, *to;
1093 {
1094     to->u.u.type = from->u.u.type;
1095     cpswaps(from->u.u.sequenceNumber, to->u.u.sequenceNumber);
1096     cpswapl(from->u.configureNotify.event,
1097         to->u.configureNotify.event);
1098     cpswapl(from->u.configureNotify.window,
1099         to->u.configureNotify.window);
1100     cpswapl(from->u.configureNotify.aboveSibling,
1101         to->u.configureNotify.aboveSibling);
1102     cpswaps(from->u.configureNotify.x, to->u.configureNotify.x);
1103     cpswaps(from->u.configureNotify.y, to->u.configureNotify.y);
1104     cpswaps(from->u.configureNotify.width, to->u.configureNotify.width);
1105     cpswaps(from->u.configureNotify.height,
1106         to->u.configureNotify.height);
1107     cpswaps(from->u.configureNotify.borderWidth,
1108         to->u.configureNotify.borderWidth);
1109     to->u.configureNotify.override = from->u.configureNotify.override;
1110 }
1111 
1112 void
SConfigureRequestEvent(from,to)1113 SConfigureRequestEvent(from, to)
1114     xEvent	*from, *to;
1115 {
1116     to->u.u.type = from->u.u.type;
1117     to->u.u.detail = from->u.u.detail;  /* actually stack-mode */
1118     cpswaps(from->u.u.sequenceNumber, to->u.u.sequenceNumber);
1119     cpswapl(from->u.configureRequest.parent,
1120         to->u.configureRequest.parent);
1121     cpswapl(from->u.configureRequest.window,
1122         to->u.configureRequest.window);
1123     cpswapl(from->u.configureRequest.sibling,
1124         to->u.configureRequest.sibling);
1125     cpswaps(from->u.configureRequest.x, to->u.configureRequest.x);
1126     cpswaps(from->u.configureRequest.y, to->u.configureRequest.y);
1127     cpswaps(from->u.configureRequest.width,
1128         to->u.configureRequest.width);
1129     cpswaps(from->u.configureRequest.height,
1130         to->u.configureRequest.height);
1131     cpswaps(from->u.configureRequest.borderWidth,
1132         to->u.configureRequest.borderWidth);
1133     cpswaps(from->u.configureRequest.valueMask,
1134         to->u.configureRequest.valueMask);
1135 }
1136 
1137 
1138 void
SGravityEvent(from,to)1139 SGravityEvent(from, to)
1140     xEvent	*from, *to;
1141 {
1142     to->u.u.type = from->u.u.type;
1143     cpswaps(from->u.u.sequenceNumber, to->u.u.sequenceNumber);
1144     cpswapl(from->u.gravity.event, to->u.gravity.event);
1145     cpswapl(from->u.gravity.window, to->u.gravity.window);
1146     cpswaps(from->u.gravity.x, to->u.gravity.x);
1147     cpswaps(from->u.gravity.y, to->u.gravity.y);
1148 }
1149 
1150 void
SResizeRequestEvent(from,to)1151 SResizeRequestEvent(from, to)
1152     xEvent	*from, *to;
1153 {
1154     to->u.u.type = from->u.u.type;
1155     cpswaps(from->u.u.sequenceNumber, to->u.u.sequenceNumber);
1156     cpswapl(from->u.resizeRequest.window, to->u.resizeRequest.window);
1157     cpswaps(from->u.resizeRequest.width, to->u.resizeRequest.width);
1158     cpswaps(from->u.resizeRequest.height, to->u.resizeRequest.height);
1159 }
1160 
1161 void
SCirculateEvent(from,to)1162 SCirculateEvent(from, to)
1163     xEvent	*from, *to;
1164 {
1165     to->u.u.type = from->u.u.type;
1166     to->u.u.detail = from->u.u.detail;
1167     cpswaps(from->u.u.sequenceNumber, to->u.u.sequenceNumber);
1168     cpswapl(from->u.circulate.event, to->u.circulate.event);
1169     cpswapl(from->u.circulate.window, to->u.circulate.window);
1170     cpswapl(from->u.circulate.parent, to->u.circulate.parent);
1171     to->u.circulate.place = from->u.circulate.place;
1172 }
1173 
1174 void
SPropertyEvent(from,to)1175 SPropertyEvent(from, to)
1176     xEvent	*from, *to;
1177 {
1178     to->u.u.type = from->u.u.type;
1179     cpswaps(from->u.u.sequenceNumber, to->u.u.sequenceNumber);
1180     cpswapl(from->u.property.window, to->u.property.window);
1181     cpswapl(from->u.property.atom, to->u.property.atom);
1182     cpswapl(from->u.property.time, to->u.property.time);
1183     to->u.property.state = from->u.property.state;
1184 }
1185 
1186 void
SSelectionClearEvent(from,to)1187 SSelectionClearEvent(from, to)
1188     xEvent	*from, *to;
1189 {
1190     to->u.u.type = from->u.u.type;
1191     cpswaps(from->u.u.sequenceNumber, to->u.u.sequenceNumber);
1192     cpswapl(from->u.selectionClear.time, to->u.selectionClear.time);
1193     cpswapl(from->u.selectionClear.window, to->u.selectionClear.window);
1194     cpswapl(from->u.selectionClear.atom, to->u.selectionClear.atom);
1195 }
1196 
1197 void
SSelectionRequestEvent(from,to)1198 SSelectionRequestEvent(from, to)
1199     xEvent	*from, *to;
1200 {
1201     to->u.u.type = from->u.u.type;
1202     cpswaps(from->u.u.sequenceNumber, to->u.u.sequenceNumber);
1203     cpswapl(from->u.selectionRequest.time, to->u.selectionRequest.time);
1204     cpswapl(from->u.selectionRequest.owner,
1205         to->u.selectionRequest.owner);
1206     cpswapl(from->u.selectionRequest.requestor,
1207 	to->u.selectionRequest.requestor);
1208     cpswapl(from->u.selectionRequest.selection,
1209 	to->u.selectionRequest.selection);
1210     cpswapl(from->u.selectionRequest.target,
1211         to->u.selectionRequest.target);
1212     cpswapl(from->u.selectionRequest.property,
1213 	to->u.selectionRequest.property);
1214 }
1215 
1216 void
SSelectionNotifyEvent(from,to)1217 SSelectionNotifyEvent(from, to)
1218     xEvent	*from, *to;
1219 {
1220     to->u.u.type = from->u.u.type;
1221     cpswaps(from->u.u.sequenceNumber, to->u.u.sequenceNumber);
1222     cpswapl(from->u.selectionNotify.time, to->u.selectionNotify.time);
1223     cpswapl(from->u.selectionNotify.requestor,
1224 	to->u.selectionNotify.requestor);
1225     cpswapl(from->u.selectionNotify.selection,
1226 	to->u.selectionNotify.selection);
1227     cpswapl(from->u.selectionNotify.target,
1228 	to->u.selectionNotify.target);
1229     cpswapl(from->u.selectionNotify.property,
1230         to->u.selectionNotify.property);
1231 }
1232 
1233 void
SColormapEvent(from,to)1234 SColormapEvent(from, to)
1235     xEvent	*from, *to;
1236 {
1237     to->u.u.type = from->u.u.type;
1238     cpswaps(from->u.u.sequenceNumber, to->u.u.sequenceNumber);
1239     cpswapl(from->u.colormap.window, to->u.colormap.window);
1240     cpswapl(from->u.colormap.colormap, to->u.colormap.colormap);
1241     to->u.colormap.new = from->u.colormap.new;
1242     to->u.colormap.state = from->u.colormap.state;
1243 }
1244 
1245 void
SMappingEvent(from,to)1246 SMappingEvent(from, to)
1247     xEvent	*from, *to;
1248 {
1249     to->u.u.type = from->u.u.type;
1250     cpswaps(from->u.u.sequenceNumber, to->u.u.sequenceNumber);
1251     to->u.mappingNotify.request = from->u.mappingNotify.request;
1252     to->u.mappingNotify.firstKeyCode =
1253 	from->u.mappingNotify.firstKeyCode;
1254     to->u.mappingNotify.count = from->u.mappingNotify.count;
1255 }
1256 
1257 void
SClientMessageEvent(from,to)1258 SClientMessageEvent(from, to)
1259     xEvent	*from, *to;
1260 {
1261     to->u.u.type = from->u.u.type;
1262     to->u.u.detail = from->u.u.detail;  /* actually format */
1263     cpswaps(from->u.u.sequenceNumber, to->u.u.sequenceNumber);
1264     cpswapl(from->u.clientMessage.window, to->u.clientMessage.window);
1265     cpswapl(from->u.clientMessage.u.l.type,
1266 	    to->u.clientMessage.u.l.type);
1267     switch (from->u.u.detail) {
1268        case 8:
1269           memmove(to->u.clientMessage.u.b.bytes,
1270 		  from->u.clientMessage.u.b.bytes,20);
1271 	  break;
1272        case 16:
1273 	  cpswaps(from->u.clientMessage.u.s.shorts0,
1274 	     to->u.clientMessage.u.s.shorts0);
1275 	  cpswaps(from->u.clientMessage.u.s.shorts1,
1276 	     to->u.clientMessage.u.s.shorts1);
1277 	  cpswaps(from->u.clientMessage.u.s.shorts2,
1278 	     to->u.clientMessage.u.s.shorts2);
1279 	  cpswaps(from->u.clientMessage.u.s.shorts3,
1280 	     to->u.clientMessage.u.s.shorts3);
1281 	  cpswaps(from->u.clientMessage.u.s.shorts4,
1282 	     to->u.clientMessage.u.s.shorts4);
1283 	  cpswaps(from->u.clientMessage.u.s.shorts5,
1284 	     to->u.clientMessage.u.s.shorts5);
1285 	  cpswaps(from->u.clientMessage.u.s.shorts6,
1286 	     to->u.clientMessage.u.s.shorts6);
1287 	  cpswaps(from->u.clientMessage.u.s.shorts7,
1288 	     to->u.clientMessage.u.s.shorts7);
1289 	  cpswaps(from->u.clientMessage.u.s.shorts8,
1290 	     to->u.clientMessage.u.s.shorts8);
1291 	  cpswaps(from->u.clientMessage.u.s.shorts9,
1292 	     to->u.clientMessage.u.s.shorts9);
1293 	  break;
1294        case 32:
1295 	  cpswapl(from->u.clientMessage.u.l.longs0,
1296 	     to->u.clientMessage.u.l.longs0);
1297 	  cpswapl(from->u.clientMessage.u.l.longs1,
1298 	     to->u.clientMessage.u.l.longs1);
1299 	  cpswapl(from->u.clientMessage.u.l.longs2,
1300 	     to->u.clientMessage.u.l.longs2);
1301 	  cpswapl(from->u.clientMessage.u.l.longs3,
1302 	     to->u.clientMessage.u.l.longs3);
1303 	  cpswapl(from->u.clientMessage.u.l.longs4,
1304 	     to->u.clientMessage.u.l.longs4);
1305 	  break;
1306        }
1307 }
1308 
1309 void
SKeymapNotifyEvent(from,to)1310 SKeymapNotifyEvent(from, to)
1311     xEvent	*from, *to;
1312 {
1313     /* Keymap notify events are special; they have no
1314        sequence number field, and contain entirely 8-bit data */
1315     *to = *from;
1316 }
1317 
1318 void
SwapConnSetupInfo(pInfo,pInfoTBase)1319 SwapConnSetupInfo(pInfo, pInfoTBase)
1320     char 		*pInfo;
1321     char 		*pInfoTBase;
1322 {
1323     int		i, j, k;
1324     ScreenPtr	pScreen;
1325     DepthPtr	pDepth;
1326     char	*pInfoT;
1327     xConnSetup	*pConnSetup = (xConnSetup *)pInfo;
1328 
1329     pInfoT = pInfoTBase;
1330     SwapConnSetup(pConnSetup, (xConnSetup *)pInfoT);
1331     pInfo += sizeof(xConnSetup);
1332     pInfoT += sizeof(xConnSetup);
1333 
1334     /* Copy the vendor string */
1335     i = (pConnSetup->nbytesVendor + 3) & ~3;
1336     memmove(pInfoT, pInfo, i);
1337     pInfo += i;
1338     pInfoT += i;
1339 
1340     /* The Pixmap formats don't need to be swapped, just copied. */
1341     i = sizeof(xPixmapFormat) * screenInfo.numPixmapFormats;
1342     memmove(pInfoT, pInfo, i);
1343     pInfo += i;
1344     pInfoT += i;
1345 
1346     for(i = 0; i < screenInfo.numScreens; i++)
1347     {
1348 	pScreen = screenInfo.screens[i];
1349 	SwapWinRoot((xWindowRoot *)pInfo, (xWindowRoot *)pInfoT);
1350 	pInfo += sizeof(xWindowRoot);
1351 	pInfoT += sizeof(xWindowRoot);
1352 	pDepth = pScreen->allowedDepths;
1353 	for(j = 0; j < pScreen->numDepths; j++, pDepth++)
1354 	{
1355             ((xDepth *)pInfoT)->depth = ((xDepth *)pInfo)->depth;
1356 	    cpswaps(((xDepth *)pInfo)->nVisuals, ((xDepth *)pInfoT)->nVisuals);
1357 	    pInfo += sizeof(xDepth);
1358 	    pInfoT += sizeof(xDepth);
1359 	    for(k = 0; k < pDepth->numVids; k++)
1360 	    {
1361 		SwapVisual((xVisualType *)pInfo, (xVisualType *)pInfoT);
1362 		pInfo += sizeof(xVisualType);
1363 		pInfoT += sizeof(xVisualType);
1364 	    }
1365 	}
1366     }
1367 }
1368 
1369 
1370 void
WriteSConnectionInfo(pClient,size,pInfo)1371 WriteSConnectionInfo(pClient, size, pInfo)
1372     ClientPtr		pClient;
1373     unsigned long	size;
1374     char 		*pInfo;
1375 {
1376     char	*pInfoTBase;
1377 
1378     pInfoTBase = (char *) ALLOCATE_LOCAL(size);
1379     if (!pInfoTBase)
1380     {
1381 	pClient->noClientException = -1;
1382 	return;
1383     }
1384     SwapConnSetupInfo(pInfo, pInfoTBase);
1385     (void)WriteToClient(pClient, (int)size, (char *) pInfoTBase);
1386     DEALLOCATE_LOCAL(pInfoTBase);
1387 }
1388 
1389 void
SwapConnSetup(pConnSetup,pConnSetupT)1390 SwapConnSetup(pConnSetup, pConnSetupT)
1391     xConnSetup 	*pConnSetup, *pConnSetupT;
1392 {
1393     cpswapl(pConnSetup->release, pConnSetupT->release);
1394     cpswapl(pConnSetup->ridBase, pConnSetupT->ridBase);
1395     cpswapl(pConnSetup->ridMask, pConnSetupT->ridMask);
1396     cpswapl(pConnSetup->motionBufferSize, pConnSetupT->motionBufferSize);
1397     cpswaps(pConnSetup->nbytesVendor, pConnSetupT->nbytesVendor);
1398     cpswaps(pConnSetup->maxRequestSize, pConnSetupT->maxRequestSize);
1399     pConnSetupT->minKeyCode = pConnSetup->minKeyCode;
1400     pConnSetupT->maxKeyCode = pConnSetup->maxKeyCode;
1401     pConnSetupT->numRoots = pConnSetup->numRoots;
1402     pConnSetupT->numFormats = pConnSetup->numFormats;
1403     pConnSetupT->imageByteOrder = pConnSetup->imageByteOrder;
1404     pConnSetupT->bitmapBitOrder = pConnSetup->bitmapBitOrder;
1405     pConnSetupT->bitmapScanlineUnit = pConnSetup->bitmapScanlineUnit;
1406     pConnSetupT->bitmapScanlinePad = pConnSetup->bitmapScanlinePad;
1407 }
1408 
1409 void
SwapWinRoot(pRoot,pRootT)1410 SwapWinRoot(pRoot, pRootT)
1411     xWindowRoot	*pRoot, *pRootT;
1412 {
1413     cpswapl(pRoot->windowId, pRootT->windowId);
1414     cpswapl(pRoot->defaultColormap, pRootT->defaultColormap);
1415     cpswapl(pRoot->whitePixel, pRootT->whitePixel);
1416     cpswapl(pRoot->blackPixel, pRootT->blackPixel);
1417     cpswapl(pRoot->currentInputMask, pRootT->currentInputMask);
1418     cpswaps(pRoot->pixWidth, pRootT->pixWidth);
1419     cpswaps(pRoot->pixHeight, pRootT->pixHeight);
1420     cpswaps(pRoot->mmWidth, pRootT->mmWidth);
1421     cpswaps(pRoot->mmHeight, pRootT->mmHeight);
1422     cpswaps(pRoot->minInstalledMaps, pRootT->minInstalledMaps);
1423     cpswaps(pRoot->maxInstalledMaps, pRootT->maxInstalledMaps);
1424     cpswapl(pRoot->rootVisualID, pRootT->rootVisualID);
1425     pRootT->backingStore = pRoot->backingStore;
1426     pRootT->saveUnders = pRoot->saveUnders;
1427     pRootT->rootDepth = pRoot->rootDepth;
1428     pRootT->nDepths = pRoot->nDepths;
1429 }
1430 
1431 void
SwapVisual(pVis,pVisT)1432 SwapVisual(pVis, pVisT)
1433     xVisualType 	*pVis, *pVisT;
1434 {
1435     cpswapl(pVis->visualID, pVisT->visualID);
1436     pVisT->class = pVis->class;
1437     pVisT->bitsPerRGB = pVis->bitsPerRGB;
1438     cpswaps(pVis->colormapEntries, pVisT->colormapEntries);
1439     cpswapl(pVis->redMask, pVisT->redMask);
1440     cpswapl(pVis->greenMask, pVisT->greenMask);
1441     cpswapl(pVis->blueMask, pVisT->blueMask);
1442 }
1443 
1444 void
SwapConnSetupPrefix(pcspFrom,pcspTo)1445 SwapConnSetupPrefix(pcspFrom, pcspTo)
1446     xConnSetupPrefix	*pcspFrom;
1447     xConnSetupPrefix	*pcspTo;
1448 {
1449     pcspTo->success = pcspFrom->success;
1450     pcspTo->lengthReason = pcspFrom->lengthReason;
1451     cpswaps(pcspFrom->majorVersion, pcspTo->majorVersion);
1452     cpswaps(pcspFrom->minorVersion, pcspTo->minorVersion);
1453     cpswaps(pcspFrom->length, pcspTo->length);
1454 }
1455 
1456 void
WriteSConnSetupPrefix(pClient,pcsp)1457 WriteSConnSetupPrefix(pClient, pcsp)
1458     ClientPtr		pClient;
1459     xConnSetupPrefix	*pcsp;
1460 {
1461     xConnSetupPrefix	cspT;
1462 
1463     SwapConnSetupPrefix(pcsp, &cspT);
1464     (void)WriteToClient(pClient, sizeof(cspT), (char *) &cspT);
1465 }
1466