1
/* $Xorg: FSlibint.h,v 1.4 2001/02/09 02:03:25 xorgcvs Exp $ */
4
* Copyright 1990 Network Computing Devices;
5
* Portions Copyright 1987 by Digital Equipment Corporation
7
* Permission to use, copy, modify, distribute, and sell this software
8
* and its documentation for any purpose is hereby granted without fee,
9
* provided that the above copyright notice appear in all copies and
10
* that both that copyright notice and this permission notice appear
11
* in supporting documentation, and that the names of Network Computing
12
* Devices or Digital not be used in advertising or publicity pertaining
13
* to distribution of the software without specific, written prior
14
* permission. Network Computing Devices or Digital make no representations
15
* about the suitability of this software for any purpose. It is provided
16
* "as is" without express or implied warranty.
18
* NETWORK COMPUTING DEVICES AND DIGITAL DISCLAIM ALL WARRANTIES WITH
19
* REGARD TO THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF
20
* MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL NETWORK COMPUTING DEVICES
21
* OR DIGITAL BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES
22
* OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
23
* WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,
24
* ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
30
Copyright 1987, 1994, 1998 The Open Group
32
Permission to use, copy, modify, distribute, and sell this software and its
33
documentation for any purpose is hereby granted without fee, provided that
34
the above copyright notice appear in all copies and that both that
35
copyright notice and this permission notice appear in supporting
38
The above copyright notice and this permission notice shall be included in
39
all copies or substantial portions of the Software.
41
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
42
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
43
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
44
OPEN GROUP BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
45
AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
46
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
48
Except as contained in this notice, the name of The Open Group shall not be
49
used in advertising or otherwise to promote the sale, use or other dealings
50
in this Software without prior written authorization from The Open Group.
53
/* $XFree86: xc/lib/FS/FSlibint.h,v 3.8 2003/08/29 18:01:12 herrb Exp $ */
56
* FSlib internal decls
61
/* This is all probably superfluous given Xos.h above */
64
#include <sys/types.h> /* forgot to protect it... */
66
#endif /* __TYPES__ */
68
#if defined(_POSIX_SOURCE) && defined(MOTOROLA)
70
#include <sys/types.h>
73
#include <sys/types.h>
82
typedef int (* FSIOErrorHandler)(FSServer *);
83
typedef int (* FSErrorHandler)(FSServer *, FSErrorEvent *);
85
extern FSIOErrorHandler _FSIOErrorFunction;
86
extern FSErrorHandler _FSErrorFunction;
88
extern void _FSEatData ( FSServer *svr, unsigned long n );
89
extern void _FSWaitForWritable ( FSServer *svr );
90
extern void _FSWaitForReadable ( FSServer *svr );
91
extern void _FSFlush ( FSServer *svr );
92
extern void _FSRead ( FSServer *svr, char *data, long size );
93
extern void _FSReadEvents ( FSServer *svr );
94
extern void _FSReadPad ( FSServer *svr, char *data, long size );
95
extern void _FSSend ( FSServer *svr, char *data, long size );
96
extern void _FSEnq ( FSServer *svr, fsEvent *event );
97
extern void _FSFreeServerStructure ( FSServer *svr );
98
extern int _FSError ( FSServer *svr, fsError *rep );
99
extern int _FSReply ( FSServer *svr, fsReply *rep, int extra, int discard );
100
extern XtransConnInfo _FSConnectServer ( char *server_name );
101
extern void _FSDisconnectServer ( XtransConnInfo trans_conn );
102
extern void _FSSendClientPrefix ( FSServer *svr, fsConnClientPrefix *client );
103
extern int _FSEventsQueued ( FSServer *svr, int mode );
104
extern unsigned long _FSSetLastRequestRead ( FSServer *svr,
105
fsGenericReply *rep );
106
extern int _FSUnknownWireEvent ( FSServer *svr, FSEvent *re, fsEvent *event );
107
extern int _FSUnknownNativeEvent ( FSServer *svr, FSEvent *re,
109
extern int _FSWireToEvent ( FSServer *svr, FSEvent *re, fsEvent *event );
110
extern int _FSDefaultIOError ( FSServer *svr );
111
extern int _FSPrintDefaultError ( FSServer *svr, FSErrorEvent *event,
113
extern int _FSDefaultError ( FSServer *svr, FSErrorEvent *event );
114
extern char * _FSAllocScratch ( FSServer *svr, unsigned long nbytes );
115
extern void _FSFreeQ ( void );
116
extern int _FSGetHostname ( char *buf, int maxlen );
118
extern FSErrorHandler FSSetErrorHandler ( FSErrorHandler handler );
119
extern FSIOErrorHandler FSSetIOErrorHandler ( FSIOErrorHandler handler );
122
#define BUFSIZE 2048 /* FS output buffer size. */
128
#define FSlibServerIOError (1L << 0)
129
#define FSlibServerClosing (1L << 1)
131
/* Need to start requests on 64 bit word boundries
132
* on a CRAY computer so add a NoOp (127) if needed.
133
* A character pointer on a CRAY computer will be non-zero
134
* after shifting right 61 bits of it is not pointing to
139
#define WORD64ALIGN if ((long)svr->bufptr >> 61) {\
140
svr->last_req = svr->bufptr;\
141
*(svr->bufptr) = FS_Noop;\
142
*(svr->bufptr+1) = 0;\
143
*(svr->bufptr+2) = 0;\
144
*(svr->bufptr+3) = 1;\
148
#else /* else does not require alignment on 64-bit
154
* GetReq - Get the next avilable FS request packet in the buffer and
157
* "name" is the name of the request, e.g. InternAtom, OpenFont, etc.
158
* "req" is the name of the request pointer.
162
#if !defined(UNIXCPP) || defined(ANSICPP)
163
#define GetReq(name, req) \
165
if ((svr->bufptr + SIZEOF(fs##name##Req)) > svr->bufmax)\
167
req = (fs##name##Req *)(svr->last_req = svr->bufptr);\
168
req->reqType = FS_##name;\
169
req->length = (SIZEOF(fs##name##Req))>>2;\
170
svr->bufptr += SIZEOF(fs##name##Req);\
173
#else /* non-ANSI C uses empty comment instead of
174
* "##" for token concatenation */
175
#define GetReq(name, req) \
177
if ((svr->bufptr + SIZEOF(fs/**/name/**/Req)) > svr->bufmax)\
179
req = (fs/**/name/**/Req *)(svr->last_req = svr->bufptr);\
180
req->reqType = FS_/**/name;\
181
req->length = (SIZEOF(fs/**/name/**/Req))>>2;\
182
svr->bufptr += SIZEOF(fs/**/name/**/Req);\
186
/* GetReqExtra is the same as GetReq, but allocates "n" additional
187
bytes after the request. "n" must be a multiple of 4! */
189
#if !defined(UNIXCPP) || defined(ANSICPP)
190
#define GetReqExtra(name, n, req) \
192
if ((svr->bufptr + SIZEOF(fs##name##Req) + n) > svr->bufmax)\
194
req = (fs##name##Req *)(svr->last_req = svr->bufptr);\
195
req->reqType = FS_##name;\
196
req->length = (SIZEOF(fs##name##Req) + n)>>2;\
197
svr->bufptr += SIZEOF(fs##name##Req) + n;\
200
#define GetReqExtra(name, n, req) \
202
if ((svr->bufptr + SIZEOF(fs/**/name/**/Req) + n) > svr->bufmax)\
204
req = (fs/**/name/**/Req *)(svr->last_req = svr->bufptr);\
205
req->reqType = FS_/**/name;\
206
req->length = (SIZEOF(fs/**/name/**/Req) + n)>>2;\
207
svr->bufptr += SIZEOF(fs/**/name/**/Req) + n;\
213
* GetResReq is for those requests that have a resource ID
214
* (Window, Pixmap, GContext, etc.) as their single argument.
215
* "rid" is the name of the resource.
218
#if !defined(UNIXCPP) || defined(ANSICPP)
219
#define GetResReq(name, rid, req) \
221
if ((svr->bufptr + SIZEOF(fsResourceReq)) > svr->bufmax)\
223
req = (fsResourceReq *) (svr->last_req = svr->bufptr);\
224
req->reqType = FS_##name;\
227
svr->bufptr += SIZEOF(fsResourceReq);\
230
#define GetResReq(name, rid, req) \
232
if ((svr->bufptr + SIZEOF(fsResourceReq)) > svr->bufmax)\
234
req = (fsResourceReq *) (svr->last_req = svr->bufptr);\
235
req->reqType = FS_/**/name;\
238
svr->bufptr += SIZEOF(fsResourceReq);\
243
* GetEmptyReq is for those requests that have no arguments
247
#if !defined(UNIXCPP) || defined(ANSICPP)
248
#define GetEmptyReq(name, req) \
250
if ((svr->bufptr + SIZEOF(fsReq)) > svr->bufmax)\
252
req = (fsReq *) (svr->last_req = svr->bufptr);\
253
req->reqType = FS_##name;\
255
svr->bufptr += SIZEOF(fsReq);\
258
#define GetEmptyReq(name, req) \
260
if ((svr->bufptr + SIZEOF(fsReq)) > svr->bufmax)\
262
req = (fsReq *) (svr->last_req = svr->bufptr);\
263
req->reqType = FS_/**/name;\
265
svr->bufptr += SIZEOF(fsReq);\
269
#define SyncHandle() \
270
if (svr->synchandler) (*svr->synchandler)(svr)
273
* Data - Place data in the buffer and pad the end to provide
274
* 32 bit word alignment. Transmit if the buffer fills.
276
* "svr" is a pointer to a Display.
277
* "data" is a pinter to a data buffer.
278
* "len" is the length of the data buffer.
279
* we can presume buffer less than 2^16 bytes, so bcopy can be used safely.
282
#ifdef DataRoutineIsProcedure
286
#define Data(svr, data, len) \
287
if (svr->bufptr + (len) <= svr->bufmax) {\
288
bcopy(data, svr->bufptr, (int)len);\
289
svr->bufptr += ((len) + 3) & ~3;\
291
_FSSend(svr, data, len)
292
#endif /* DataRoutineIsProcedure */
295
/* Allocate bytes from the buffer. No padding is done, so if
296
* the length is not a multiple of 4, the caller must be
297
* careful to leave the buffer aligned after sending the
300
* "type" is the type of the pointer being assigned to.
301
* "ptr" is the pointer being assigned to.
302
* "n" is the number of bytes to allocate.
306
* BufAlloc (xTextElt *, elt, nbytes)
309
#define BufAlloc(type, ptr, n) \
310
if (svr->bufptr + (n) > svr->bufmax) \
312
ptr = (type) svr->bufptr; \
316
* provide emulation routines for smaller architectures
319
#define Data16(dpy, data, len) Data((dpy), (char *)(data), (len))
320
#define Data32(dpy, data, len) Data((dpy), (char *)(data), (len))
321
#define _FSRead16Pad(dpy, data, len) _FSReadPad((dpy), (char *)(data), (len))
322
#define _FSRead16(dpy, data, len) _FSRead((dpy), (char *)(data), (len))
323
#define _FSRead32(dpy, data, len) _FSRead((dpy), (char *)(data), (len))
324
#endif /* not WORD64 */
326
#define PackData16(dpy,data,len) Data16 (dpy, data, len)
327
#define PackData32(dpy,data,len) Data32 (dpy, data, len)
329
#define min(a,b) (((a) < (b)) ? (a) : (b))
330
#define max(a,b) (((a) > (b)) ? (a) : (b))
333
/* a little bit of magic */
334
#define OneDataCard32(svr,dstaddr,srcvar) \
335
{ svr->bufptr -= 4; Data32 (svr, (char *) &(srcvar), 4); }
337
#define STARTITERATE(tpvar,type,start,endcond,decr) \
338
{ register char *cpvar; \
339
for (cpvar = (char *) start; endcond; cpvar = NEXTPTR(cpvar,type), decr) { \
340
type dummy; bcopy (cpvar, (char *) &dummy, SIZEOF(type)); \
341
tpvar = (type *) cpvar;
342
#define ENDITERATE }}
346
/* srcvar must be a variable for large architecture version */
347
#define OneDataCard32(svr,dstaddr,srcvar) \
348
{ *(unsigned long *)(dstaddr) = (srcvar); }
350
#define STARTITERATE(tpvar,type,start,endcond,decr) \
351
for (tpvar = (type *) start; endcond; tpvar++, decr) {
353
#endif /* MUSTCOPY - used machines whose C structs
354
* don't line up with proto */
357
#if !defined(UNIXCPP) || defined(ANSICPP)
358
#define FSCat(x,y) x##_##y
360
#define FSCat(x,y) x/**/_/**/y
363
/* copy XCharInfo parts of a protocol reply into a FSXCharInfo */
365
#define FSUnpack_XCharInfo(packet, structure) \
366
(structure)->left = FSCat(packet,left); \
367
(structure)->right = FSCat(packet,right); \
368
(structure)->width = FSCat(packet,width); \
369
(structure)->ascent = FSCat(packet,ascent); \
370
(structure)->descent = FSCat(packet,descent); \
371
(structure)->attributes = FSCat(packet,attributes)
374
/* copy XFontInfoHeader parts of a protocol reply into a FSXFontInfoHeader */
376
#define FSUnpack_XFontInfoHeader(packet, structure, serverversion) \
377
(structure)->flags = (packet)->font_header_flags; \
378
(structure)->draw_direction = (packet)->font_header_draw_direction; \
380
if (serverversion > 1) { \
381
(structure)->char_range.min_char.high = (packet)->font_hdr_char_range_min_char_high; \
382
(structure)->char_range.min_char.low = (packet)->font_hdr_char_range_min_char_low; \
383
(structure)->char_range.max_char.high = (packet)->font_hdr_char_range_max_char_high; \
384
(structure)->char_range.max_char.low = (packet)->font_hdr_char_range_max_char_low; \
385
(structure)->default_char.high = (packet)->font_header_default_char_high; \
386
(structure)->default_char.low = (packet)->font_header_default_char_low; \
388
(structure)->char_range.min_char.high = (packet)->font_hdr_char_range_min_char_low; \
389
(structure)->char_range.min_char.low = (packet)->font_hdr_char_range_min_char_high; \
390
(structure)->char_range.max_char.high = (packet)->font_hdr_char_range_max_char_low; \
391
(structure)->char_range.max_char.low = (packet)->font_hdr_char_range_max_char_high; \
392
(structure)->default_char.high = (packet)->font_header_default_char_low; \
393
(structure)->default_char.low = (packet)->font_header_default_char_high; \
396
(structure)->font_ascent = (packet)->font_header_font_ascent; \
397
(structure)->font_descent = (packet)->font_header_font_descent; \
399
FSUnpack_XCharInfo((packet)->font_header_min_bounds, &(structure)->min_bounds); \
400
FSUnpack_XCharInfo((packet)->font_header_max_bounds, &(structure)->max_bounds)