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