home *** CD-ROM | disk | FTP | other *** search
/ InfoMagic Source Code 1993 July / THE_SOURCE_CODE_CD_ROM.iso / X / mit / fonts / lib / fs / FSlibint.h < prev    next >
Encoding:
C/C++ Source or Header  |  1991-05-13  |  8.8 KB  |  297 lines

  1. /* $XConsortium: FSlibint.h,v 1.6 91/05/13 15:12:01 gildea Exp $ */
  2.  
  3. /* @(#)FSlibint.h    4.1    91/05/02
  4.  * Copyright 1990 Network Computing Devices;
  5.  * Portions Copyright 1987 by Digital Equipment Corporation and the
  6.  * Massachusetts Institute of Technology
  7.  *
  8.  * Permission to use, copy, modify, and distribute this protoype software
  9.  * and its documentation to Members and Affiliates of the MIT X Consortium
  10.  * any purpose and without fee is hereby granted, provided
  11.  * that the above copyright notice appear in all copies and that both that
  12.  * copyright notice and this permission notice appear in supporting
  13.  * documentation, and that the names of Network Computing Devices, Digital or
  14.  * MIT not be used in advertising or publicity pertaining to distribution of
  15.  * the software without specific, written prior permission.
  16.  *
  17.  * NETWORK COMPUTING DEVICES, DIGITAL AND MIT DISCLAIM ALL WARRANTIES WITH
  18.  * REGARD TO THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
  19.  * AND FITNESS, IN NO EVENT SHALL NETWORK COMPUTING DEVICES, DIGITAL OR MIT BE
  20.  * LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
  21.  * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION
  22.  * OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
  23.  * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
  24.  */
  25.  
  26. /*
  27.  * FSlib internal decls
  28.  */
  29.  
  30. #ifdef USG
  31. #ifndef __TYPES__
  32. #include <sys/types.h>            /* forgot to protect it... */
  33. #define __TYPES__
  34. #endif /* __TYPES__ */
  35. #else
  36. #if defined(_POSIX_SOURCE) && defined(MOTOROLA)
  37. #undef _POSIX_SOURCE
  38. #include <sys/types.h>
  39. #define _POSIX_SOURCE
  40. #else
  41. #include <sys/types.h>
  42. #endif
  43. #endif /* USG */
  44.  
  45. #include    "FSlib.h"
  46. #include    "FSproto.h"
  47. #include    "FSlibos.h"
  48. #include    <errno.h>
  49.  
  50. #ifndef NULL
  51. #define NULL 0
  52. #endif
  53.  
  54. extern int  errno;        /* Internal system error number. */
  55.  
  56. extern      (*_FSIOErrorFunction) ();
  57. extern      (*_FSErrorFunction) ();
  58.  
  59. extern int  _FGetHostname();
  60.  
  61. extern void    _FSEatData();
  62.  
  63. #ifndef BUFSIZE
  64. #define BUFSIZE 2048        /* FS output buffer size. */
  65. #endif
  66.  
  67. /*
  68.  * server flags 
  69.  */
  70. #define    FSlibServerIOError    (1L << 0)
  71. #define    FSlibServerClosing    (1L << 1)
  72.  
  73. /*   Need to start requests on 64 bit word boundries
  74.  *   on a CRAY computer so add a NoOp (127) if needed.
  75.  *   A character pointer on a CRAY computer will be non-zero
  76.  *   after shifting right 61 bits of it is not pointing to
  77.  *   a word boundary.
  78.  */
  79.  
  80. #ifdef WORD64
  81. #define WORD64ALIGN if ((long)svr->bufptr >> 61) {\
  82.            svr->last_req = svr->bufptr;\
  83.            *(svr->bufptr)   = FS_Noop;\
  84.            *(svr->bufptr+1) =  0;\
  85.            *(svr->bufptr+2) =  0;\
  86.            *(svr->bufptr+3) =  1;\
  87.              svr->request += 1;\
  88.              svr->bufptr += 4;\
  89.          }
  90. #else                /* else does not require alignment on 64-bit
  91.                  * boundaries */
  92. #define WORD64ALIGN
  93. #endif                /* WORD64 */
  94.  
  95. /*
  96.  * GetReq - Get the next avilable FS request packet in the buffer and
  97.  * return it.
  98.  *
  99.  * "name" is the name of the request, e.g. InternAtom, OpenFont, etc.
  100.  * "req" is the name of the request pointer.
  101.  *
  102.  */
  103.  
  104. #if defined(__STDC__) && !defined(UNIXCPP)
  105. #define GetReq(name, req) \
  106.         WORD64ALIGN\
  107.     if ((svr->bufptr + SIZEOF(fs##name##Req)) > svr->bufmax)\
  108.         _FSFlush(svr);\
  109.     req = (fs##name##Req *)(svr->last_req = svr->bufptr);\
  110.     req->reqType = FS_##name;\
  111.     req->length = (SIZEOF(fs##name##Req))>>2;\
  112.     svr->bufptr += SIZEOF(fs##name##Req);\
  113.     svr->request++
  114.  
  115. #else                /* non-ANSI C uses empty comment instead of
  116.                  * "##" for token concatenation */
  117. #define GetReq(name, req) \
  118.         WORD64ALIGN\
  119.     if ((svr->bufptr + SIZEOF(fs/**/name/**/Req)) > svr->bufmax)\
  120.         _FSFlush(svr);\
  121.     req = (fs/**/name/**/Req *)(svr->last_req = svr->bufptr);\
  122.     req->reqType = FS_/**/name;\
  123.     req->length = (SIZEOF(fs/**/name/**/Req))>>2;\
  124.     svr->bufptr += SIZEOF(fs/**/name/**/Req);\
  125.     svr->request++
  126. #endif
  127.  
  128. /* GetReqExtra is the same as GetReq, but allocates "n" additional
  129.    bytes after the request. "n" must be a multiple of 4!  */
  130.  
  131. #if defined(__STDC__) && !defined(UNIXCPP)
  132. #define GetReqExtra(name, n, req) \
  133.         WORD64ALIGN\
  134.     if ((svr->bufptr + SIZEOF(fs##name##Req) + n) > svr->bufmax)\
  135.         _FSFlush(svr);\
  136.     req = (fs##name##Req *)(svr->last_req = svr->bufptr);\
  137.     req->reqType = FS_##name;\
  138.     req->length = (SIZEOF(fs##name##Req) + n)>>2;\
  139.     svr->bufptr += SIZEOF(fs##name##Req) + n;\
  140.     svr->request++
  141. #else
  142. #define GetReqExtra(name, n, req) \
  143.         WORD64ALIGN\
  144.     if ((svr->bufptr + SIZEOF(fs/**/name/**/Req) + n) > svr->bufmax)\
  145.         _FSFlush(svr);\
  146.     req = (fs/**/name/**/Req *)(svr->last_req = svr->bufptr);\
  147.     req->reqType = FS_/**/name;\
  148.     req->length = (SIZEOF(fs/**/name/**/Req) + n)>>2;\
  149.     svr->bufptr += SIZEOF(fs/**/name/**/Req) + n;\
  150.     svr->request++
  151. #endif
  152.  
  153.  
  154. /*
  155.  * GetResReq is for those requests that have a resource ID
  156.  * (Window, Pixmap, GContext, etc.) as their single argument.
  157.  * "rid" is the name of the resource.
  158.  */
  159.  
  160. #if defined(__STDC__) && !defined(UNIXCPP)
  161. #define GetResReq(name, rid, req) \
  162.         WORD64ALIGN\
  163.     if ((svr->bufptr + SIZEOF(fsResourceReq)) > svr->bufmax)\
  164.         _FSFlush(svr);\
  165.     req = (fsResourceReq *) (svr->last_req = svr->bufptr);\
  166.     req->reqType = FS_##name;\
  167.     req->length = 2;\
  168.     req->id = (rid);\
  169.     svr->bufptr += SIZEOF(fsResourceReq);\
  170.     svr->request++
  171. #else
  172. #define GetResReq(name, rid, req) \
  173.         WORD64ALIGN\
  174.     if ((svr->bufptr + SIZEOF(fsResourceReq)) > svr->bufmax)\
  175.         _FSFlush(svr);\
  176.     req = (fsResourceReq *) (svr->last_req = svr->bufptr);\
  177.     req->reqType = FS_/**/name;\
  178.     req->length = 2;\
  179.     req->id = (rid);\
  180.     svr->bufptr += SIZEOF(fsResourceReq);\
  181.     svr->request++
  182. #endif
  183.  
  184. /*
  185.  * GetEmptyReq is for those requests that have no arguments
  186.  * at all.
  187.  */
  188.  
  189. #if defined(__STDC__) && !defined(UNIXCPP)
  190. #define GetEmptyReq(name, req) \
  191.         WORD64ALIGN\
  192.     if ((svr->bufptr + SIZEOF(fsReq)) > svr->bufmax)\
  193.         _FSFlush(svr);\
  194.     req = (fsReq *) (svr->last_req = svr->bufptr);\
  195.     req->reqType = FS_##name;\
  196.     req->length = 1;\
  197.     svr->bufptr += SIZEOF(fsReq);\
  198.     svr->request++
  199. #else
  200. #define GetEmptyReq(name, req) \
  201.         WORD64ALIGN\
  202.     if ((svr->bufptr + SIZEOF(fsReq)) > svr->bufmax)\
  203.         _FSFlush(svr);\
  204.     req = (fsReq *) (svr->last_req = svr->bufptr);\
  205.     req->reqType = FS_/**/name;\
  206.     req->length = 1;\
  207.     svr->bufptr += SIZEOF(fsReq);\
  208.     svr->request++
  209. #endif
  210.  
  211. #define    SyncHandle()    \
  212.     if (svr->synchandler) (*svr->synchandler)(svr)
  213.  
  214. /*
  215.  * Data - Place data in the buffer and pad the end to provide
  216.  * 32 bit word alignment.  Transmit if the buffer fills.
  217.  *
  218.  * "svr" is a pointer to a Display.
  219.  * "data" is a pinter to a data buffer.
  220.  * "len" is the length of the data buffer.
  221.  * we can presume buffer less than 2^16 bytes, so bcopy can be used safely.
  222.  */
  223.  
  224. #ifdef DataRoutineIsProcedure
  225. extern void Data();
  226.  
  227. #else
  228. #define Data(svr, data, len) \
  229.     if (svr->bufptr + (len) <= svr->bufmax) {\
  230.         bcopy(data, svr->bufptr, (int)len);\
  231.         svr->bufptr += ((len) + 3) & ~3;\
  232.     } else\
  233.         _FSSend(svr, data, len)
  234. #endif                /* DataRoutineIsProcedure */
  235.  
  236.  
  237. /* Allocate bytes from the buffer.  No padding is done, so if
  238.  * the length is not a multiple of 4, the caller must be
  239.  * careful to leave the buffer aligned after sending the
  240.  * current request.
  241.  *
  242.  * "type" is the type of the pointer being assigned to.
  243.  * "ptr" is the pointer being assigned to.
  244.  * "n" is the number of bytes to allocate.
  245.  *
  246.  * Example:
  247.  *    xTextElt *elt;
  248.  *    BufAlloc (xTextElt *, elt, nbytes)
  249.  */
  250.  
  251. #define BufAlloc(type, ptr, n) \
  252.     if (svr->bufptr + (n) > svr->bufmax) \
  253.         _FSFlush (svr); \
  254.     ptr = (type) svr->bufptr; \
  255.     svr->bufptr += (n);
  256.  
  257. /*
  258.  * provide emulation routines for smaller architectures
  259.  */
  260. #ifndef WORD64
  261. #define Data16(dpy, data, len) Data((dpy), (char *)(data), (len))
  262. #define Data32(dpy, data, len) Data((dpy), (char *)(data), (len))
  263. #define _FSRead16Pad(dpy, data, len) _FSReadPad((dpy), (char *)(data), (len))
  264. #define _FSRead16(dpy, data, len) _FSRead((dpy), (char *)(data), (len))
  265. #define _FSRead32(dpy, data, len) _FSRead((dpy), (char *)(data), (len))
  266. #endif /* not WORD64 */
  267.  
  268. #define PackData16(dpy,data,len) Data16 (dpy, data, len)
  269. #define PackData32(dpy,data,len) Data32 (dpy, data, len)
  270.  
  271. #define min(a,b) (((a) < (b)) ? (a) : (b))
  272. #define max(a,b) (((a) > (b)) ? (a) : (b))
  273.  
  274. #ifdef MUSTCOPY
  275. /* a little bit of magic */
  276. #define OneDataCard32(svr,dstaddr,srcvar) \
  277.   { svr->bufptr -= 4; Data32 (svr, (char *) &(srcvar), 4); }
  278.  
  279. #define STARTITERATE(tpvar,type,start,endcond,decr) \
  280.   { register char *cpvar; \
  281.   for (cpvar = (char *) start; endcond; cpvar = NEXTPTR(cpvar,type), decr) { \
  282.     type dummy; bcopy (cpvar, (char *) &dummy, SIZEOF(type)); \
  283.     tpvar = (type *) cpvar;
  284. #define ENDITERATE }}
  285.  
  286. #else
  287.  
  288. /* srcvar must be a variable for large architecture version */
  289. #define OneDataCard32(svr,dstaddr,srcvar) \
  290.   { *(unsigned long *)(dstaddr) = (srcvar); }
  291.  
  292. #define STARTITERATE(tpvar,type,start,endcond,decr) \
  293.   for (tpvar = (type *) start; endcond; tpvar++, decr) {
  294. #define ENDITERATE }
  295. #endif                /* MUSTCOPY - used machines whose C structs
  296.                  * don't line up with proto */
  297.