misc.h revision ce6676db
1/* 2 3Copyright 1990, 1991, 1998 The Open Group 4 5Permission to use, copy, modify, distribute, and sell this software and its 6documentation for any purpose is hereby granted without fee, provided that 7the above copyright notice appear in all copies and that both that 8copyright notice and this permission notice appear in supporting 9documentation. 10 11The above copyright notice and this permission notice shall be included in 12all copies or substantial portions of the Software. 13 14THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17OPEN GROUP BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN 18AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 19CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 20 21Except as contained in this notice, the name of The Open Group shall not be 22used in advertising or otherwise to promote the sale, use or other dealings 23in this Software without prior written authorization from The Open Group. 24 25 * Copyright 1990, 1991 Network Computing Devices; 26 * Portions Copyright 1987 by Digital Equipment Corporation 27 * 28 * Permission to use, copy, modify, distribute, and sell this software and 29 * its documentation for any purpose is hereby granted without fee, provided 30 * that the above copyright notice appear in all copies and that both that 31 * copyright notice and this permission notice appear in supporting 32 * documentation, and that the names of Network Computing Devices, or Digital 33 * not be used in advertising or publicity pertaining to distribution 34 * of the software without specific, written prior permission. 35 * 36 * NETWORK COMPUTING DEVICES, AND DIGITAL DISCLAIM ALL WARRANTIES WITH 37 * REGARD TO THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF 38 * MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL NETWORK COMPUTING DEVICES, 39 * OR DIGITAL BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL 40 * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR 41 * PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS 42 * ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF 43 * THIS SOFTWARE. 44 */ 45 46#ifndef _MISC_H_ 47#define _MISC_H_ 48 49#include <X11/Xosdefs.h> 50#include <X11/Xfuncs.h> 51#include <X11/Xdefs.h> 52 53#include "assert.h" /* so its everywhere */ 54 55#ifndef NULL 56#include <stddef.h> 57#endif 58 59#define MAXCLIENTS 128 60 61#define MILLI_PER_SECOND (1000) 62#define MILLI_PER_MINUTE (1000 * 60) 63 64#ifndef TRUE 65#define TRUE 1 66#define FALSE 0 67#endif 68 69#define min(a, b) (((a) < (b)) ? (a) : (b)) 70#define max(a, b) (((a) > (b)) ? (a) : (b)) 71 72#include "os.h" 73 74#define lowbit(x) ((x) & (~(x) + 1)) 75 76/* byte swapping helpers */ 77 78/* byte swap a long literal */ 79#define lswapl(x) ((((x) & 0xff) << 24) |\ 80 (((x) & 0xff00) << 8) |\ 81 (((x) & 0xff0000) >> 8) |\ 82 (((x) >> 24) & 0xff)) 83 84/* byte swap a short literal */ 85#define lswaps(x) ((((x) & 0xff) << 8) | (((x) >> 8) & 0xff)) 86 87 88/* byte swap a long */ 89#define swapl(x, n) n = ((char *) (x))[0];\ 90 ((char *) (x))[0] = ((char *) (x))[3];\ 91 ((char *) (x))[3] = n;\ 92 n = ((char *) (x))[1];\ 93 ((char *) (x))[1] = ((char *) (x))[2];\ 94 ((char *) (x))[2] = n; 95 96/* byte swap a short */ 97#define swaps(x, n) n = ((char *) (x))[0];\ 98 ((char *) (x))[0] = ((char *) (x))[1];\ 99 ((char *) (x))[1] = n 100 101/* copy long from src to dst byteswapping on the way */ 102#define cpswapl(src, dst) \ 103 ((char *)&(dst))[0] = ((char *) &(src))[3];\ 104 ((char *)&(dst))[1] = ((char *) &(src))[2];\ 105 ((char *)&(dst))[2] = ((char *) &(src))[1];\ 106 ((char *)&(dst))[3] = ((char *) &(src))[0]; 107 108/* copy short from src to dst byteswapping on the way */ 109#define cpswaps(src, dst)\ 110 ((char *) &(dst))[0] = ((char *) &(src))[1];\ 111 ((char *) &(dst))[1] = ((char *) &(src))[0]; 112 113 114#if 0 115extern void NoopDDA(void); 116extern char *NameForAtom(Atom atom); 117#endif 118extern void BitOrderInvert(unsigned char *buf, int nbytes); 119 120 121#if !defined(UNIXCPP) || defined(ANSICPP) 122#define fsCat(x,y) x##_##y 123#else 124#define fsCat(x,y) x/**/_/**/y 125#endif 126 127/* copy a xCharInfo into a XCharInfo */ 128 129#define fsPack_XCharInfo(structure, packet) \ 130 fsCat(packet,left) = (structure)->leftSideBearing; \ 131 fsCat(packet,right) = (structure)->rightSideBearing; \ 132 fsCat(packet,width) = (structure)->characterWidth; \ 133 fsCat(packet,ascent) = (structure)->ascent; \ 134 fsCat(packet,descent) = (structure)->descent; \ 135 fsCat(packet,attributes) = (structure)->attributes 136 137 138/* copy a FontInfoRec into a XFontInfoHeader */ 139 140#define fsPack_XFontInfoHeader(structure, packet, clientversion) \ 141 (packet)->font_header_flags = ((structure)->allExist) ? FontInfoAllCharsExist : 0; \ 142 (packet)->font_header_draw_direction = ((structure)->drawDirection == LeftToRight) \ 143 ? LeftToRightDrawDirection : RightToLeftDrawDirection; \ 144 \ 145 if ((structure)->inkInside) \ 146 (packet)->font_header_flags |= FontInfoInkInside; \ 147 \ 148 if (clientversion > 1) { \ 149 (packet)->font_hdr_char_range_min_char_high = (structure)->firstRow; \ 150 (packet)->font_hdr_char_range_min_char_low = (structure)->firstCol; \ 151 (packet)->font_hdr_char_range_max_char_high = (structure)->lastRow; \ 152 (packet)->font_hdr_char_range_max_char_low = (structure)->lastCol; \ 153 (packet)->font_header_default_char_high = (structure)->defaultCh >> 8; \ 154 (packet)->font_header_default_char_low = (structure)->defaultCh & 0xff; \ 155 } else { \ 156 (packet)->font_hdr_char_range_min_char_high = (structure)->firstCol; \ 157 (packet)->font_hdr_char_range_min_char_low = (structure)->firstRow; \ 158 (packet)->font_hdr_char_range_max_char_high = (structure)->lastCol; \ 159 (packet)->font_hdr_char_range_max_char_low = (structure)->lastRow; \ 160 (packet)->font_header_default_char_high = (structure)->defaultCh & 0xff; \ 161 (packet)->font_header_default_char_low = (structure)->defaultCh >> 8; \ 162 } \ 163 \ 164 fsPack_XCharInfo(&(structure)->ink_minbounds, (packet)->font_header_min_bounds); \ 165 fsPack_XCharInfo(&(structure)->ink_maxbounds, (packet)->font_header_max_bounds); \ 166 \ 167 (packet)->font_header_font_ascent = (structure)->fontAscent; \ 168 (packet)->font_header_font_descent = (structure)->fontDescent 169 170 171typedef struct { /* when cloning, need old transport info */ 172 int trans_id; 173 int fd; 174 int portnum; 175} OldListenRec; 176 177/* os/connection.c */ 178extern void CreateSockets(int old_listen_count, OldListenRec *old_listen); 179 180/* os/xfstrans.c */ 181extern OldListenRec *_FontTransGetInetdListenInfo (int fd); 182 183#endif /* _MISC_H_ */ 184